diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index 2baf7cb..908b25c 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -22,4 +22,23 @@ a:hover, a:active { background-color: #009688; } +} + +.thumb { + width: 3em; +} + +.table_wrapper { + table { + border-collapse: collapse; + width: 100%; + } + + th, td { + padding: 8px; + text-align: left; + border-bottom: 1px solid #ddd; + } + + } \ No newline at end of file diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 4de86da..4117991 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -27,14 +27,19 @@ 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'], + # 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'] } + 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 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/favorites_controller.rb b/app/controllers/favorites_controller.rb index 0a426dc..54e4275 100644 --- a/app/controllers/favorites_controller.rb +++ b/app/controllers/favorites_controller.rb @@ -1,10 +1,17 @@ class FavoritesController < ApplicationController + helper_method :sort_column, :sort_direction def people - @favoritePeople = FavoritePerson.all + @favorite_people = FavoritePerson.where('user_id': current_user.id) + .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 @@ -16,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/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..d8e38d2 100644 --- a/app/helpers/favorites_helper.rb +++ b/app/helpers/favorites_helper.rb @@ -1,2 +1,6 @@ module FavoritesHelper + def sortable(title, column) + direction = column == sort_column && sort_direction == 'asc' ? 'desc' : 'asc' + link_to title, :sort => column, :direction => direction + end end diff --git a/app/views/favorites/people.html.erb b/app/views/favorites/people.html.erb index eeadd54..c0db7db 100644 --- a/app/views/favorites/people.html.erb +++ b/app/views/favorites/people.html.erb @@ -1,25 +1,72 @@ -<%= render(:partial => "nav")%> +<%= render(:partial => "nav") %>
| + | <%= 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' %> + | +