From 1970a65bf8daed6ed73790a5dc3432ac1bcc4517 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Sat, 16 May 2020 11:44:21 +0200 Subject: [PATCH 01/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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