From 1970a65bf8daed6ed73790a5dc3432ac1bcc4517 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 11:44:21 +0200 Subject: [PATCH 01/24] fix of inheritance error -> uninitialized constant TissCrawlerController --- app/controllers/crawlers/courses_crawler_controller.rb | 2 +- app/controllers/crawlers/people_crawler_controller.rb | 2 +- app/controllers/crawlers/projects_crawler_controller.rb | 2 +- app/controllers/crawlers/theses_crawler_controller.rb | 2 +- app/controllers/crawlers/tiss_crawler_controller.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 69f47ea..a590ced 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::CoursesCrawlerController < TissCrawlerController +class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController def show_basic params[:api] = '/api/search/course/v1.0/quickSearch' diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index a9de30a..4de86da 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::PeopleCrawlerController < TissCrawlerController +class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController def show_basic params[:api] = '/api/person/v22/psuche' diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index d5f9089..13688c9 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::ProjectsCrawlerController < TissCrawlerController +class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController def show_basic end diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 9e2df8e..409a5e4 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::ThesesCrawlerController < TissCrawlerController +class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController def show_basic end diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index fac3647..50a6b86 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::TissCrawlerController < ApplicationController +class Crawlers::TissCrawlerController < Crawlers::ApplicationController # self designed lib to call the Tiss API require 'tiss/tiss_crawler' From 5bb0bae8588b48b4c8ffe71e29341d6d8518b4bb Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 11:45:05 +0200 Subject: [PATCH 02/24] fix of inheritance error -> uninitialized constant Crawlers::ApplicationController --- app/controllers/crawlers/tiss_crawler_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index 50a6b86..fac3647 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::TissCrawlerController < Crawlers::ApplicationController +class Crawlers::TissCrawlerController < ApplicationController # self designed lib to call the Tiss API require 'tiss/tiss_crawler' From 9dcb2994e16b57772e2af130bca941e99db0bf7b Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 11:58:25 +0200 Subject: [PATCH 03/24] create a hash of favorite details and reuse it; move redirect_back out of conditional scope --- .../crawlers/people_crawler_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 4de86da..2b5be29 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -27,14 +27,17 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController @person = TissCrawler.get_details(params) # create stores the object to the db after creation - if FavoritePerson.create(tiss_id: @person['tiss_id'], first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri']).valid? - FavoritePerson.create(tiss_id: @person['tiss_id'], first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri']) - flash[:alert] = "Person added to your favorites!" - redirect_back(fallback_location: search) + favorite_hash = { tiss_id: @person['tiss_id'], + first_name: @person['first_name'], + last_name: @person['last_name'], + picture_uri: @person['picture_uri'] } + if FavoritePerson.create(favorite_hash).valid? + FavoritePerson.create(favorite_hash) + flash[:alert] = 'Person added to your favorites!' else - flash[:alert] = "Person is already favorited!" - redirect_back(fallback_location: search) + flash[:alert] = 'Person is already favorited!' end + redirect_back(fallback_location: search) end end From 8ca0f742761a28844c9092f3d35b4d5cd193734d Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 12:21:48 +0200 Subject: [PATCH 04/24] added user_id to favorite_people model --- db/migrate/20200421152314_create_favorite_people.rb | 4 ++-- db/schema.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/db/migrate/20200421152314_create_favorite_people.rb b/db/migrate/20200421152314_create_favorite_people.rb index 6dd479a..d1a00b0 100644 --- a/db/migrate/20200421152314_create_favorite_people.rb +++ b/db/migrate/20200421152314_create_favorite_people.rb @@ -1,10 +1,10 @@ class CreateFavoritePeople < ActiveRecord::Migration[6.0] def change create_table :favorite_people, id: false do |t| - t.string :tiss_id, null: false + t.integer :tiss_id, null: false + t.integer :user_id, null: false t.string :first_name t.string :last_name - t.string :picture_uri t.timestamps diff --git a/db/schema.rb b/db/schema.rb index 5425113..03758f8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,7 +13,8 @@ ActiveRecord::Schema.define(version: 2020_04_21_152314) do create_table "favorite_people", id: false, force: :cascade do |t| - t.string "tiss_id", null: false + t.integer "tiss_id", null: false + t.integer "user_id", null: false t.string "first_name" t.string "last_name" t.string "picture_uri" From 72be2d07f3158ed0ba86529fbdf383db98fc0eba Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 12:22:09 +0200 Subject: [PATCH 05/24] store also the user_id when adding to favorite --- app/controllers/crawlers/people_crawler_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 2b5be29..4117991 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -28,6 +28,8 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController # create stores the object to the db after creation favorite_hash = { tiss_id: @person['tiss_id'], + # the user who is currently active + user_id: current_user.id, first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri'] } From dd7ac8e64fba2377edf7313d96a33b86e20e0904 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 12:26:21 +0200 Subject: [PATCH 06/24] only select favorites which match the current user id --- app/controllers/favorites_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 0a426dc..f53bef6 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -1,7 +1,7 @@ class FavoritesController < ApplicationController def people - @favoritePeople = FavoritePerson.all + @favoritePeople = FavoritePerson.where('user_id': current_user.id) @host = 'https://tiss.tuwien.ac.at' end From 83d4368af7d398eff97847e2d07f283a5019d64f Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 13:30:00 +0200 Subject: [PATCH 07/24] first attempt of making favorite people view sortable --- app/assets/stylesheets/favorites.scss | 4 ++ app/controllers/favorites_controller.rb | 3 +- app/views/favorites/people.html.erb | 65 ++++++++++++++++++------- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index 2baf7cb..c3f5840 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -22,4 +22,8 @@ a:hover, a:active { background-color: #009688; } +} + +.thumb { + width: 3em; } \ No newline at end of file diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index f53bef6..a6de6a3 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -1,7 +1,8 @@ class FavoritesController < ApplicationController def people - @favoritePeople = FavoritePerson.where('user_id': current_user.id) + @favorite_people = FavoritePerson.where('user_id': current_user.id) + .order(params[:sort]) @host = 'https://tiss.tuwien.ac.at' end diff --git a/app/views/favorites/people.html.erb b/app/views/favorites/people.html.erb index eeadd54..edfa364 100644 --- a/app/views/favorites/people.html.erb +++ b/app/views/favorites/people.html.erb @@ -1,25 +1,56 @@ -<%= render(:partial => "nav")%> +<%= render(:partial => "nav") %>

Favorite People

-
    - <% @favoritePeople.each do |person| %> -
  • - <%= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %> - - + + <%# @favorite_people.each do |person| %> + + <%#= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %> + + + <%# if person['picture_uri'] != nil %> + <%#= image_tag @host + person['picture_uri'] %> + <%# else %> + <%#= show_svg('account_circle-black-48dp.svg') %> + <%# end %> + + + <%#= person['first_name'] %> + <%#= person['last_name'] %> + + + <%# end %> + + <%# end %> + + + + + + + + + + <% for person in @favorite_people %> + + + + + + <% end %> - +
    Thumb<%= link_to "First Name", :sort => "first_name" %><%= link_to "Last Name", :sort => "last_name" %><%= link_to "Registration Date", :sort => "created_at" %>
    + <% if person['picture_uri'] != nil %> - <%= image_tag @host + person['picture_uri'] %> + <%= image_tag @host + person['picture_uri'], class: 'thumb'%> <% else %> - <%= show_svg('account_circle-black-48dp.svg') %> + <%= show_svg('account_circle-black-48dp.svg')%> <% end %> - - <%= person['first_name'] %> - <%= person['last_name'] %> - - - <% end %> - + + <%= person['first_name'] %> + + <%= person['last_name'] %> + + <%= person['created_at'] %> +
    From f2686288b7a85b2ad126d4db886d784c5fed2e0f Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 14:09:11 +0200 Subject: [PATCH 08/24] moved into proper folder location --- app/helpers/{ => crawlers}/courses_crawler_helper.rb | 0 app/helpers/{ => crawlers}/people_crawler_helper.rb | 0 app/helpers/{ => crawlers}/projects_crawler_helper.rb | 0 app/helpers/{ => crawlers}/theses_crawler_helper.rb | 0 app/helpers/{ => crawlers}/tiss_crawler_helper.rb | 0 app/helpers/favorites_helper.rb | 6 ++++++ 6 files changed, 6 insertions(+) rename app/helpers/{ => crawlers}/courses_crawler_helper.rb (100%) rename app/helpers/{ => crawlers}/people_crawler_helper.rb (100%) rename app/helpers/{ => crawlers}/projects_crawler_helper.rb (100%) rename app/helpers/{ => crawlers}/theses_crawler_helper.rb (100%) rename app/helpers/{ => crawlers}/tiss_crawler_helper.rb (100%) diff --git a/app/helpers/courses_crawler_helper.rb b/app/helpers/crawlers/courses_crawler_helper.rb similarity index 100% rename from app/helpers/courses_crawler_helper.rb rename to app/helpers/crawlers/courses_crawler_helper.rb diff --git a/app/helpers/people_crawler_helper.rb b/app/helpers/crawlers/people_crawler_helper.rb similarity index 100% rename from app/helpers/people_crawler_helper.rb rename to app/helpers/crawlers/people_crawler_helper.rb diff --git a/app/helpers/projects_crawler_helper.rb b/app/helpers/crawlers/projects_crawler_helper.rb similarity index 100% rename from app/helpers/projects_crawler_helper.rb rename to app/helpers/crawlers/projects_crawler_helper.rb diff --git a/app/helpers/theses_crawler_helper.rb b/app/helpers/crawlers/theses_crawler_helper.rb similarity index 100% rename from app/helpers/theses_crawler_helper.rb rename to app/helpers/crawlers/theses_crawler_helper.rb diff --git a/app/helpers/tiss_crawler_helper.rb b/app/helpers/crawlers/tiss_crawler_helper.rb similarity index 100% rename from app/helpers/tiss_crawler_helper.rb rename to app/helpers/crawlers/tiss_crawler_helper.rb diff --git a/app/helpers/favorites_helper.rb b/app/helpers/favorites_helper.rb index 4e9a950..fae53e7 100644 --- a/app/helpers/favorites_helper.rb +++ b/app/helpers/favorites_helper.rb @@ -1,2 +1,8 @@ module FavoritesHelper + def sortable(title, column) + title ||= column.titelize + puts title + direction = column == sort_column && sort_direction == 'asc' ? 'desc' : 'asc' + link_to title, :sort => column, :direction => direction + end end From 2f6d638cd1d6df427bffb5d8f4e1118759e31d27 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 14:09:33 +0200 Subject: [PATCH 09/24] second attempt of making favorite people view sortable --- app/controllers/favorites_controller.rb | 18 +++++++++++++++++- app/views/favorites/people.html.erb | 10 +++++++--- config/routes.rb | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index a6de6a3..54e4275 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -1,11 +1,17 @@ class FavoritesController < ApplicationController + helper_method :sort_column, :sort_direction def people @favorite_people = FavoritePerson.where('user_id': current_user.id) - .order(params[:sort]) + .order(sort_column + " " + sort_direction) @host = 'https://tiss.tuwien.ac.at' end + def delete_person + FavoritePerson.find_by_tiss_id(params[:tiss_id]).destroy + redirect_back(fallback_location: people) + end + def courses end @@ -17,4 +23,14 @@ class FavoritesController < ApplicationController def projects end + + private + + def sort_column + params[:sort] || 'first_name' + end + + def sort_direction + params[:direction] || 'asc' + end end diff --git a/app/views/favorites/people.html.erb b/app/views/favorites/people.html.erb index edfa364..5e5de03 100644 --- a/app/views/favorites/people.html.erb +++ b/app/views/favorites/people.html.erb @@ -27,9 +27,10 @@ - - - + + + + <% for person in @favorite_people %> @@ -51,6 +52,9 @@ + <% end %>
    Thumb<%= link_to "First Name", :sort => "first_name" %><%= link_to "Last Name", :sort => "last_name" %><%= link_to "Registration Date", :sort => "created_at" %><%= sortable "First Name", "first_name" %><%= sortable "Last Name", "last_name" %><%= sortable "Registration Date", "created_at" %>Del
    <%= person['created_at'] %> + <%= link_to "X", {:action => "delete_person", :tiss_id => person['tiss_id']}, :method => 'delete' %> +
    diff --git a/config/routes.rb b/config/routes.rb index 2becac5..81f9e4c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,7 @@ Rails.application.routes.draw do namespace :favorites do get 'people' + delete 'delete_person' get 'courses' get 'theses' get 'projects' From 6922f31bc5b17350e874282f18d6a8fc2b3778c1 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 14:29:30 +0200 Subject: [PATCH 10/24] remove unnecessary bloat --- app/helpers/favorites_helper.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/helpers/favorites_helper.rb b/app/helpers/favorites_helper.rb index fae53e7..d8e38d2 100644 --- a/app/helpers/favorites_helper.rb +++ b/app/helpers/favorites_helper.rb @@ -1,7 +1,5 @@ module FavoritesHelper def sortable(title, column) - title ||= column.titelize - puts title direction = column == sort_column && sort_direction == 'asc' ? 'desc' : 'asc' link_to title, :sort => column, :direction => direction end From b11ef548b652db54c7b1e11f3d7a9511c9522c81 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 15:06:42 +0200 Subject: [PATCH 11/24] style the table --- app/assets/stylesheets/favorites.scss | 21 +++++++ app/views/favorites/people.html.erb | 80 +++++++++++++++------------ 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index c3f5840..f500a8d 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -26,4 +26,25 @@ .thumb { width: 3em; +} + +.table_wrapper { + table { + border-collapse: collapse; + width: 100%; + } + + th, td { + padding: 8px; + text-align: left; + border-bottom: 1px solid #ddd; + } + + th .asc { + background-image: url("app/assets/images/up.png"); + } + + th .desc { + background-image: url("app/assets/images/down.png"); + } } \ No newline at end of file diff --git a/app/views/favorites/people.html.erb b/app/views/favorites/people.html.erb index 5e5de03..c0db7db 100644 --- a/app/views/favorites/people.html.erb +++ b/app/views/favorites/people.html.erb @@ -24,37 +24,49 @@ <%# end %> - - - - - - - - - <% for person in @favorite_people %> - - - - - - - - <% end %> -
    Thumb<%= sortable "First Name", "first_name" %><%= sortable "Last Name", "last_name" %><%= sortable "Registration Date", "created_at" %>Del
    - - <% if person['picture_uri'] != nil %> - <%= image_tag @host + person['picture_uri'], class: 'thumb'%> - <% else %> - <%= show_svg('account_circle-black-48dp.svg')%> - <% end %> - - - <%= person['first_name'] %> - - <%= person['last_name'] %> - - <%= person['created_at'] %> - - <%= link_to "X", {:action => "delete_person", :tiss_id => person['tiss_id']}, :method => 'delete' %> -
    +<% if !@favorite_people[0].blank? %> +
    + + + + + + + + + + <% for person in @favorite_people %> + + + + + + + + + <% end %> +
    <%= sortable "First Name", "first_name" %><%= sortable "Last Name", "last_name" %><%= sortable "Registration Date", "created_at" %>
    + <%= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %> + + <% if person['picture_uri'] != nil %> + <%= image_tag @host + person['picture_uri'], class: 'thumb'%> + <% else %> + <%= show_svg('account_circle-black-48dp.svg')%> + <% end %> + + <% end %> + + <%= person['first_name'] %> + + <%= person['last_name'] %> + + <%= person['created_at'] %> + + <%= button_to 'Details', crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) %> + + <%= button_to "Delete", {:action => "delete_person", :tiss_id => person['tiss_id']}, :method => 'delete' %> +
    +
    +<% else %> + No favorite people added yet! +<% end %> \ No newline at end of file From 1a4370c90e3d3b5e32831f38f8999054931407a8 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 15:07:12 +0200 Subject: [PATCH 12/24] doesn't work yet --- app/assets/stylesheets/favorites.scss | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index f500a8d..908b25c 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -40,11 +40,5 @@ border-bottom: 1px solid #ddd; } - th .asc { - background-image: url("app/assets/images/up.png"); - } - th .desc { - background-image: url("app/assets/images/down.png"); - } } \ No newline at end of file From 52515549ee5ba1a63b9d8a48af17ccf0b48067d9 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Thu, 21 May 2020 10:51:51 +0200 Subject: [PATCH 13/24] Hotfix: change inheritance to reflect new routes --- app/controllers/crawlers/courses_crawler_controller.rb | 2 +- app/controllers/crawlers/people_crawler_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 69f47ea..a590ced 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::CoursesCrawlerController < TissCrawlerController +class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController def show_basic params[:api] = '/api/search/course/v1.0/quickSearch' diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index a9de30a..4de86da 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -1,4 +1,4 @@ -class Crawlers::PeopleCrawlerController < TissCrawlerController +class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController def show_basic params[:api] = '/api/person/v22/psuche' From b8cc0d5b61a40130c0924312518c47b12fd31f36 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Thu, 21 May 2020 13:31:54 +0200 Subject: [PATCH 14/24] Implement favoriting of courses --- .../crawlers/courses_crawler_controller.rb | 21 +++++++++++++++++++ app/models/favorite_course.rb | 4 ++++ .../20200521091231_create_favorite_courses.rb | 13 ++++++++++++ db/schema.rb | 12 ++++++++++- test/fixtures/favorite_courses.yml | 11 ++++++++++ test/models/favorite_course_test.rb | 7 +++++++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 app/models/favorite_course.rb create mode 100644 db/migrate/20200521091231_create_favorite_courses.rb create mode 100644 test/fixtures/favorite_courses.yml create mode 100644 test/models/favorite_course_test.rb diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index a590ced..8b52363 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -40,6 +40,27 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController end def add_to_fav + params[:api] = '/api/course/' + regex = params[:detail_url].match(/courseNr=(?\S{6})/) + params[:number] = regex[:number] + regex = params[:detail_url].match(/semester=(?\d{4}[SW])/) + params[:semester] = regex[:semester] + + @course = TissCrawler.get_course_details(params) + + # create stores the object to the db after creation + favorite_hash = {number: @course['courseNumber'], + semester: @course['semesterCode'], + title: @course['title']['de'], + # the user who is currently active + user_id: current_user.id} + if FavoriteCourse.create(favorite_hash).valid? + FavoriteCourse.create(favorite_hash) + flash[:alert] = 'Course added to your favorites!' + else + flash[:alert] = 'Course is already favorited!' + end + redirect_back(fallback_location: search) end end diff --git a/app/models/favorite_course.rb b/app/models/favorite_course.rb new file mode 100644 index 0000000..60d0d1f --- /dev/null +++ b/app/models/favorite_course.rb @@ -0,0 +1,4 @@ +class FavoriteCourse < ApplicationRecord + validates :title, :semester, :number, presence: true + validates :semester, :number, uniqueness: {scope: [:semester, :number]} +end diff --git a/db/migrate/20200521091231_create_favorite_courses.rb b/db/migrate/20200521091231_create_favorite_courses.rb new file mode 100644 index 0000000..4937ab0 --- /dev/null +++ b/db/migrate/20200521091231_create_favorite_courses.rb @@ -0,0 +1,13 @@ +class CreateFavoriteCourses < ActiveRecord::Migration[6.0] + def change + create_table :favorite_courses do |t| + t.string :number, null: false + t.string :semester, null: false + t.string :title, null: false + t.integer :user_id, null: false + + t.timestamps + end + add_index :favorite_courses, [:number, :semester], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 03758f8..2ea4a22 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_04_21_152314) do +ActiveRecord::Schema.define(version: 2020_05_21_091231) do + + create_table "favorite_courses", force: :cascade do |t| + t.string "number", null: false + t.string "semester", null: false + t.string "title", null: false + t.integer "user_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["number", "semester"], name: "index_favorite_courses_on_number_and_semester", unique: true + end create_table "favorite_people", id: false, force: :cascade do |t| t.integer "tiss_id", null: false diff --git a/test/fixtures/favorite_courses.yml b/test/fixtures/favorite_courses.yml new file mode 100644 index 0000000..5181636 --- /dev/null +++ b/test/fixtures/favorite_courses.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/favorite_course_test.rb b/test/models/favorite_course_test.rb new file mode 100644 index 0000000..6dc9720 --- /dev/null +++ b/test/models/favorite_course_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class FavoriteCourseTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From dabda63cbc1888ec4759dcf9959f16047294f7e5 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Sat, 23 May 2020 15:44:39 +0200 Subject: [PATCH 15/24] Remove URL parsing The fields `courseNr` and `semesterCode` are already parsed by the controller and do not have to be parsed again when calling the add_to_fav function. --- app/controllers/crawlers/courses_crawler_controller.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 8b52363..3fab5e6 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -41,10 +41,6 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController def add_to_fav params[:api] = '/api/course/' - regex = params[:detail_url].match(/courseNr=(?\S{6})/) - params[:number] = regex[:number] - regex = params[:detail_url].match(/semester=(?\d{4}[SW])/) - params[:semester] = regex[:semester] @course = TissCrawler.get_course_details(params) From b53a1ebe812d847d9b3bb6a27fc08950aa000460 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Sat, 23 May 2020 15:50:31 +0200 Subject: [PATCH 16/24] Fix routing error for helpers Due to moving the helpers into their own folder, the modules were not defined properly anymore. --- app/helpers/crawlers/courses_crawler_helper.rb | 2 +- app/helpers/crawlers/people_crawler_helper.rb | 2 +- app/helpers/crawlers/projects_crawler_helper.rb | 2 +- app/helpers/crawlers/theses_crawler_helper.rb | 2 +- app/helpers/crawlers/tiss_crawler_helper.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/crawlers/courses_crawler_helper.rb b/app/helpers/crawlers/courses_crawler_helper.rb index 6800321..eb9da6d 100644 --- a/app/helpers/crawlers/courses_crawler_helper.rb +++ b/app/helpers/crawlers/courses_crawler_helper.rb @@ -1,2 +1,2 @@ -module CoursesCrawlerHelper +module Crawlers::CoursesCrawlerHelper end diff --git a/app/helpers/crawlers/people_crawler_helper.rb b/app/helpers/crawlers/people_crawler_helper.rb index f0357b4..b56f897 100644 --- a/app/helpers/crawlers/people_crawler_helper.rb +++ b/app/helpers/crawlers/people_crawler_helper.rb @@ -1,2 +1,2 @@ -module PeopleCrawlerHelper +module Crawlers::PeopleCrawlerHelper end diff --git a/app/helpers/crawlers/projects_crawler_helper.rb b/app/helpers/crawlers/projects_crawler_helper.rb index 5c75729..3fc4feb 100644 --- a/app/helpers/crawlers/projects_crawler_helper.rb +++ b/app/helpers/crawlers/projects_crawler_helper.rb @@ -1,2 +1,2 @@ -module ProjectsCrawlerHelper +module Crawlers::ProjectsCrawlerHelper end diff --git a/app/helpers/crawlers/theses_crawler_helper.rb b/app/helpers/crawlers/theses_crawler_helper.rb index e2f404e..1b0e136 100644 --- a/app/helpers/crawlers/theses_crawler_helper.rb +++ b/app/helpers/crawlers/theses_crawler_helper.rb @@ -1,2 +1,2 @@ -module ThesesCrawlerHelper +module Crawlers::ThesesCrawlerHelper end diff --git a/app/helpers/crawlers/tiss_crawler_helper.rb b/app/helpers/crawlers/tiss_crawler_helper.rb index ef4a1b8..b730a09 100644 --- a/app/helpers/crawlers/tiss_crawler_helper.rb +++ b/app/helpers/crawlers/tiss_crawler_helper.rb @@ -1,2 +1,2 @@ -module TissCrawlerHelper +module Crawlers::TissCrawlerHelper end From 2b8539cba9b5b7adacea5b12e42b2e89a20f32af Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Sat, 23 May 2020 16:15:40 +0200 Subject: [PATCH 17/24] Make table left/right scrollable --- app/assets/stylesheets/favorites.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index 908b25c..8cb2d3a 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -29,6 +29,8 @@ } .table_wrapper { + overflow-x: auto; + table { border-collapse: collapse; width: 100%; From 311e3d9dcbe55d1bb6137b294ed980a37804e4cc Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Mon, 25 May 2020 14:57:15 +0200 Subject: [PATCH 18/24] Finish favorite courses view --- .../crawlers/courses_crawler_controller.rb | 10 +++--- app/controllers/favorites_controller.rb | 11 ++++-- app/views/favorites/courses.html.erb | 35 +++++++++++++++++-- config/routes.rb | 1 + 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 3fab5e6..7e644fb 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -12,10 +12,12 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController def show_detail params[:api] = '/api/course/' - regex = params[:detail_url].match(/courseNr=(?\S{6})/) - params[:number] = regex[:number] - regex = params[:detail_url].match(/semester=(?\d{4}[SW])/) - params[:semester] = regex[:semester] + if (params[:number] || params[:semester]) == nil + regex = params[:detail_url].match(/courseNr=(?\S{6})/) + params[:number] = regex[:number] + regex = params[:detail_url].match(/semester=(?\d{4}[SW])/) + params[:semester] = regex[:semester] + end puts params diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 54e4275..12ac057 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -13,7 +13,14 @@ class FavoritesController < ApplicationController end def courses + @favorite_courses = FavoriteCourse.where('user_id': current_user.id) + .order(sort_column + " " + sort_direction) + @host = 'https://tiss.tuwien.ac.at' + end + def delete_course + FavoriteCourse.find_by(number: params[:number], semester: params[:semester]).destroy + redirect_back(fallback_location: courses) end def theses @@ -27,10 +34,10 @@ class FavoritesController < ApplicationController private def sort_column - params[:sort] || 'first_name' + params[:sort] || '' end def sort_direction - params[:direction] || 'asc' + params[:direction] || '' end end diff --git a/app/views/favorites/courses.html.erb b/app/views/favorites/courses.html.erb index 8509c2d..bad85bf 100644 --- a/app/views/favorites/courses.html.erb +++ b/app/views/favorites/courses.html.erb @@ -1,3 +1,34 @@ -<%= render(:partial => "nav")%> +<%= render(:partial => "nav") %> -

    Fav Courses

    \ No newline at end of file +

    Favorite Courses

    + +<% if !@favorite_courses[0].blank? %> +
    + + + + + + + + <% for course in @favorite_courses %> + + + + + + + <% end %> +
    <%= sortable "Title", "title" %><%= sortable "Registration Date", "created_at" %>
    + <%= course['title'] %> + + <%= course['created_at'] %> + + <%= button_to 'Details', crawlers_courses_crawler_show_detail_url(:number => course['number'], :semester => course['semester']) %> + + <%= button_to 'Delete', {:action => "delete_course", :number => course['number'], :semester => course['semester']}, :method => 'delete' %> +
    +
    +<% else %> + No favorite courses added yet! +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 81f9e4c..ad7b374 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,6 +28,7 @@ Rails.application.routes.draw do get 'people' delete 'delete_person' get 'courses' + delete 'delete_course' get 'theses' get 'projects' end From d84297bde7556de0c9cc9406a16922abb42d79c9 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Mon, 25 May 2020 16:14:41 +0200 Subject: [PATCH 19/24] Implement search, show_basic, show_detail and add_to_fav for theses --- app/assets/stylesheets/theses_crawler.scss | 48 ++++++++++++++++++- .../crawlers/theses_crawler_controller.rb | 29 +++++++++++ .../crawlers/tiss_crawler_controller.rb | 4 +- app/controllers/favorites_controller.rb | 7 +++ app/models/favorite_thesis.rb | 5 ++ .../theses_crawler/show_basic.html.erb | 20 ++++++++ .../theses_crawler/show_detail.html.erb | 5 ++ config/routes.rb | 9 ++++ .../20200525132942_create_favorite_theses.rb | 12 +++++ db/schema.rb | 11 ++++- lib/tiss/tiss_crawler.rb | 10 ++++ test/fixtures/favorite_theses.yml | 11 +++++ test/models/favorite_thesis_test.rb | 7 +++ 13 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 app/models/favorite_thesis.rb create mode 100644 app/views/crawlers/theses_crawler/show_basic.html.erb create mode 100644 app/views/crawlers/theses_crawler/show_detail.html.erb create mode 100644 db/migrate/20200525132942_create_favorite_theses.rb create mode 100644 test/fixtures/favorite_theses.yml create mode 100644 test/models/favorite_thesis_test.rb diff --git a/app/assets/stylesheets/theses_crawler.scss b/app/assets/stylesheets/theses_crawler.scss index 25c9a4a..2c28234 100644 --- a/app/assets/stylesheets/theses_crawler.scss +++ b/app/assets/stylesheets/theses_crawler.scss @@ -1,3 +1,49 @@ -// Place all the styles related to the ThesesCrawler controller here. +// Place all the styles related to the thesesCrawler controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: https://sass-lang.com/ + +.theses-list { + list-style: none; + padding: 0; + margin: 0; + + a { + text-decoration: none; + color: black; + } + + .thesis { + line-height: 72px; + width: 100%; + padding: 8px 0 8px 0; + + .list-link { + float: left; + width: 89%; + height: 72px; + } + + .thesis-title { + width: 100%; + display: inline-block; + text-align: left; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + } + + .add-to-fav { + display: inline-block; + vertical-align: middle; + float: right; + width: 36px; + height: 36px; + + svg { + width: 100%; + height: auto; + vertical-align: middle; + } + } + } +} diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 409a5e4..2bb8231 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -1,13 +1,42 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController def show_basic + params[:api] = '/api/search/thesis/v1.0/quickSearch' + params[:search_parameter] = 'searchterm' + puts params[:search_context] + @host = TissCrawler.get_host + # TissCrawler performs general search over the available courses + @theses = TissCrawler.search(params) end def show_detail + params[:api] = '/api/thesis/' + @id = params[:id] + + puts params + # TissCrawler fetches the person's detail information + @thesis = TissCrawler.get_thesis_details(params) + # Host is needed for image rendering + @host = TissCrawler.get_host end def add_to_fav + params[:api] = '/api/thesis/' + puts params[:id] + @thesis = TissCrawler.get_thesis_details(params) + # create stores the object to the db after creation + favorite_hash = {id: params[:id], + # the user who is currently active + user_id: current_user.id, + title: @thesis['title']['de']} + if FavoriteThesis.create(favorite_hash).valid? + FavoriteThesis.create(favorite_hash) + flash[:alert] = 'Thesis added to your favorites!' + else + flash[:alert] = 'Thesis is already favorited!' + end + redirect_back(fallback_location: search) end end diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index fac3647..d7f2368 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -16,8 +16,10 @@ class Crawlers::TissCrawlerController < ApplicationController # redirect to courses_show_basic, propagate the search_term redirect_to :controller => 'crawlers/courses_crawler', :action => :show_basic, :search_term => params[:search_term] when 'Theses' + # redirect to thesis_show_basic, propagate the search_term + redirect_to :controller => 'crawlers/theses_crawler', :action => :show_basic, :search_term => params[:search_term] when 'Projects' - else + else puts 'Undefined search context' end end diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb index 12ac057..1ea293a 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -24,7 +24,14 @@ class FavoritesController < ApplicationController end def theses + @favorite_theses = FavoriteThesis.where('user_id': current_user.id) + .order(sort_column + " " + sort_direction) + @host = 'https://tiss.tuwien.ac.at' + end + def delete_thesis + FavoriteThesis.find_by(id: params[:id]).destroy + redirect_back(fallback_location: theses) end def projects diff --git a/app/models/favorite_thesis.rb b/app/models/favorite_thesis.rb new file mode 100644 index 0000000..f1618f9 --- /dev/null +++ b/app/models/favorite_thesis.rb @@ -0,0 +1,5 @@ +class FavoriteThesis < ApplicationRecord + self.primary_key = 'id' + + validates :id, uniqueness: true +end diff --git a/app/views/crawlers/theses_crawler/show_basic.html.erb b/app/views/crawlers/theses_crawler/show_basic.html.erb new file mode 100644 index 0000000..02ba658 --- /dev/null +++ b/app/views/crawlers/theses_crawler/show_basic.html.erb @@ -0,0 +1,20 @@ +

    Results for "<%= params[:search_term] %>"

    + +
      + <% @theses.each_with_index do |thesis| %> +
    • + <%= link_to crawlers_theses_crawler_show_detail_url(:id => thesis['id'], :title => thesis['title']) do %> + + + <%= thesis['title'] %> + + + <% end %> + + <%= link_to crawlers_theses_crawler_add_to_fav_url(:id => thesis['id'], :title => thesis['title']) do %> + <%= show_svg('favorite-24px.svg') %> + <% end %> + +
    • + <% end %> +
    diff --git a/app/views/crawlers/theses_crawler/show_detail.html.erb b/app/views/crawlers/theses_crawler/show_detail.html.erb new file mode 100644 index 0000000..6725ab5 --- /dev/null +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -0,0 +1,5 @@ +<% if @thesis != nil %> +

    <%= @thesis['title']['de'] %>

    +
    <%= @thesis['thesisType'] %>, <%= @thesis['instituteCode'] %> <%= @thesis['instituteName']['de'] %>
    + <%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @thesis['title']['de'] %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index ad7b374..946e698 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,14 @@ Rails.application.routes.draw do get 'add_to_fav' post 'add_to_fav' end + + namespace :theses_crawler do + get 'show_basic' + get 'show_detail' + post 'show_detail' + get 'add_to_fav' + post 'add_to_fav' + end end namespace :favorites do @@ -30,6 +38,7 @@ Rails.application.routes.draw do get 'courses' delete 'delete_course' get 'theses' + delete 'delete_thesis' get 'projects' end diff --git a/db/migrate/20200525132942_create_favorite_theses.rb b/db/migrate/20200525132942_create_favorite_theses.rb new file mode 100644 index 0000000..64c63db --- /dev/null +++ b/db/migrate/20200525132942_create_favorite_theses.rb @@ -0,0 +1,12 @@ +class CreateFavoriteTheses < ActiveRecord::Migration[6.0] + def change + create_table :favorite_theses, id: false do |t| + t.integer :id, null: false + t.integer :user_id, null: false + t.string :title + + t.timestamps + end + add_index :favorite_theses, :id, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 2ea4a22..c1cc81e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_05_21_091231) do +ActiveRecord::Schema.define(version: 2020_05_25_132942) do create_table "favorite_courses", force: :cascade do |t| t.string "number", null: false @@ -33,6 +33,15 @@ ActiveRecord::Schema.define(version: 2020_05_21_091231) do t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true end + create_table "favorite_theses", id: false, force: :cascade do |t| + t.integer "id", null: false + t.integer "user_id", null: false + t.string "title" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["id"], name: "index_favorite_theses_on_id", unique: true + end + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false diff --git a/lib/tiss/tiss_crawler.rb b/lib/tiss/tiss_crawler.rb index c402b54..bc764cb 100644 --- a/lib/tiss/tiss_crawler.rb +++ b/lib/tiss/tiss_crawler.rb @@ -36,6 +36,16 @@ class TissCrawler response.parsed_response['tuvienna']['course'] end + def self.get_thesis_details(params) + api = params[:api] + id = params[:id] + url = $host + api + id + puts(url) + + response = HTTParty.get(url) + response.parsed_response['tuvienna']['thesis'] + end + def self.get_host $host end diff --git a/test/fixtures/favorite_theses.yml b/test/fixtures/favorite_theses.yml new file mode 100644 index 0000000..5181636 --- /dev/null +++ b/test/fixtures/favorite_theses.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/favorite_thesis_test.rb b/test/models/favorite_thesis_test.rb new file mode 100644 index 0000000..6c675a7 --- /dev/null +++ b/test/models/favorite_thesis_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class FavoriteThesisTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From b20cccf07b43700c023fe76251056bcf1b81be35 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Mon, 25 May 2020 16:20:27 +0200 Subject: [PATCH 20/24] Implement favorite view for theses --- app/views/favorites/theses.html.erb | 35 +++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/app/views/favorites/theses.html.erb b/app/views/favorites/theses.html.erb index dc46c61..d552232 100644 --- a/app/views/favorites/theses.html.erb +++ b/app/views/favorites/theses.html.erb @@ -1,3 +1,34 @@ -<%= render(:partial => "nav")%> +<%= render(:partial => "nav") %> -

    Fav Theses

    \ No newline at end of file +

    Favorite Theses

    + +<% if !@favorite_theses[0].blank? %> +
    + + + + + + + + <% for thesis in @favorite_theses %> + + + + + + + <% end %> +
    <%= sortable "Title", "title" %><%= sortable "Registration Date", "created_at" %>
    + <%= thesis['title'] %> + + <%= thesis['created_at'] %> + + <%= button_to 'Details', crawlers_theses_crawler_show_detail_url(:id => thesis['id']) %> + + <%= button_to 'Delete', {:action => "delete_thesis", :id => thesis['id']}, :method => 'delete' %> +
    +
    +<% else %> + No favorite theses added yet! +<% end %> From e359595d0f891599387600d5106c274a2bd4ad38 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Mon, 25 May 2020 16:28:22 +0200 Subject: [PATCH 21/24] Add advisor and assistant names to thesis detail view --- app/views/crawlers/theses_crawler/show_detail.html.erb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/views/crawlers/theses_crawler/show_detail.html.erb b/app/views/crawlers/theses_crawler/show_detail.html.erb index 6725ab5..24f1a83 100644 --- a/app/views/crawlers/theses_crawler/show_detail.html.erb +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -2,4 +2,12 @@

    <%= @thesis['title']['de'] %>

    <%= @thesis['thesisType'] %>, <%= @thesis['instituteCode'] %> <%= @thesis['instituteName']['de'] %>
    <%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @thesis['title']['de'] %> + <% if @thesis['advisor'] != nil %> +

    Advisor

    +

    <%= @thesis['advisor']['familyName'] %> <%= @thesis['advisor']['givenName'] %>

    + <% end %> + <% if @thesis['assistant'] != nil %> +

    Assistant

    +

    <%= @thesis['assistant']['familyName'] %> <%= @thesis['assistant']['givenName'] %>

    + <% end %> <% end %> From ae217a60eaf332246c696aeaf21fa8806d8b1b68 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 17:48:09 +0200 Subject: [PATCH 22/24] Fix comment errors Should really look at it before doing copypasta... --- app/controllers/crawlers/theses_crawler_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 2bb8231..a90ca3a 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -5,7 +5,7 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController puts params[:search_context] @host = TissCrawler.get_host - # TissCrawler performs general search over the available courses + # TissCrawler performs general search over the available theses @theses = TissCrawler.search(params) end @@ -15,7 +15,7 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @id = params[:id] puts params - # TissCrawler fetches the person's detail information + # TissCrawler fetches the thesis' detail information @thesis = TissCrawler.get_thesis_details(params) # Host is needed for image rendering @host = TissCrawler.get_host From cbcc7c3d2579ec89c57e96fb4fb6ecf24cdc56bd Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Fri, 29 May 2020 10:43:34 +0200 Subject: [PATCH 23/24] Hotfix: parse oid when only one given The function `show_detail` for courses was expecting an array of lecturer oids. When it got only one and therefore not an array but an int, the line `@lecturers_oid.each` would fail to parse the variable because it is not an array. --- .../crawlers/courses_crawler_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 7e644fb..3346345 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -29,11 +29,19 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController @lecturers_oid = @course['lecturers']['oid'] @lecturers_names = [] + puts @lecturers_oid + if @lecturers_oid != nil - @lecturers_oid.each do |item| - # For each org id get the associated name - puts TissCrawler.get_oid_name(item) - @lecturers_names << (TissCrawler.get_oid_name(item)) + if @lecturers_oid.is_a?(Array) + # In case @lecturers_oid contains multiple items + @lecturers_oid.each do |item| + # For each org id get the associated name + puts TissCrawler.get_oid_name(item) + @lecturers_names << (TissCrawler.get_oid_name(item)) + end + else + # In case @lecturers_oid only contains one item + @lecturers_names << (TissCrawler.get_oid_name(@lecturers_oid)) end end From a6a866d3575c1f55110a43502e831f7b8e75fe78 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Fri, 29 May 2020 10:57:18 +0200 Subject: [PATCH 24/24] Hotfix: Add params parsing When favoriting from `show_basic` for courses, the parameters `number` and `semester` are not passed to the underlying function. Instead, the `detail_url` is passed, which has to be parsed to get the `number` and `semester`. --- app/controllers/crawlers/courses_crawler_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index 3346345..3526a4f 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -51,6 +51,12 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController def add_to_fav params[:api] = '/api/course/' + if (params[:number] || params[:semester]) == nil + regex = params[:detail_url].match(/courseNr=(?\S{6})/) + params[:number] = regex[:number] + regex = params[:detail_url].match(/semester=(?\d{4}[SW])/) + params[:semester] = regex[:semester] + end @course = TissCrawler.get_course_details(params)