Merge remote-tracking branch 'origin/user_based_+_sortable_favs' into courses_search

This commit is contained in:
Tobias Eidelpes 2020-05-21 11:08:43 +02:00
commit a43c2b8edb
15 changed files with 126 additions and 32 deletions

View File

@ -22,4 +22,23 @@
a:hover, a:active { a:hover, a:active {
background-color: #009688; 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;
}
} }

View File

@ -27,14 +27,19 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
@person = TissCrawler.get_details(params) @person = TissCrawler.get_details(params)
# create stores the object to the db after creation # 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? favorite_hash = { tiss_id: @person['tiss_id'],
FavoritePerson.create(tiss_id: @person['tiss_id'], first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri']) # the user who is currently active
flash[:alert] = "Person added to your favorites!" user_id: current_user.id,
redirect_back(fallback_location: search) 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 else
flash[:alert] = "Person is already favorited!" flash[:alert] = 'Person is already favorited!'
redirect_back(fallback_location: search)
end end
redirect_back(fallback_location: search)
end end
end end

View File

@ -1,4 +1,4 @@
class Crawlers::ProjectsCrawlerController < TissCrawlerController class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
def show_basic def show_basic
end end

View File

@ -1,4 +1,4 @@
class Crawlers::ThesesCrawlerController < TissCrawlerController class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
def show_basic def show_basic
end end

View File

@ -1,10 +1,17 @@
class FavoritesController < ApplicationController class FavoritesController < ApplicationController
helper_method :sort_column, :sort_direction
def people 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' @host = 'https://tiss.tuwien.ac.at'
end end
def delete_person
FavoritePerson.find_by_tiss_id(params[:tiss_id]).destroy
redirect_back(fallback_location: people)
end
def courses def courses
end end
@ -16,4 +23,14 @@ class FavoritesController < ApplicationController
def projects def projects
end end
private
def sort_column
params[:sort] || 'first_name'
end
def sort_direction
params[:direction] || 'asc'
end
end end

View File

@ -1,2 +1,6 @@
module FavoritesHelper module FavoritesHelper
def sortable(title, column)
direction = column == sort_column && sort_direction == 'asc' ? 'desc' : 'asc'
link_to title, :sort => column, :direction => direction
end
end end

View File

@ -1,25 +1,72 @@
<%= render(:partial => "nav")%> <%= render(:partial => "nav") %>
<h1>Favorite People</h1> <h1>Favorite People</h1>
<ul class="people-list"> <!--<ul class="people-list">-->
<% @favoritePeople.each do |person| %> <%# @favorite_people.each do |person| %>
<li class="person"> <!-- <li class="person">-->
<%= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %> <%#= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %>
<span class="list-link"> <!-- <span class="list-link">-->
<span class="person-icon"> <!-- <span class="person-icon">-->
<% if person['picture_uri'] != nil %> <%# if person['picture_uri'] != nil %>
<%= image_tag @host + person['picture_uri'] %> <%#= image_tag @host + person['picture_uri'] %>
<% else %> <%# else %>
<%= show_svg('account_circle-black-48dp.svg') %> <%#= show_svg('account_circle-black-48dp.svg') %>
<% end %> <%# end %>
</span> <!-- </span>-->
<span class="person-name"> <!-- <span class="person-name">-->
<%= person['first_name'] %> <%#= person['first_name'] %>
<%#= person['last_name'] %>
<!-- </span>-->
<!-- </span>-->
<%# end %>
<!-- </li>-->
<%# end %>
<!--</ul>-->
<% if !@favorite_people[0].blank? %>
<div class="table_wrapper">
<table>
<tr>
<th></th>
<th><%= sortable "First Name", "first_name" %></th>
<th><%= sortable "Last Name", "last_name" %></th>
<th><%= sortable "Registration Date", "created_at" %></th>
<th></th>
<th></th>
</tr>
<% for person in @favorite_people %>
<tr>
<td>
<%= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %>
<span>
<% if person['picture_uri'] != nil %>
<%= image_tag @host + person['picture_uri'], class: 'thumb'%>
<% else %>
<%= show_svg('account_circle-black-48dp.svg')%>
<% end %>
</span>
<% end %>
</td>
<td>
<%= person['first_name'] %>
</td>
<td>
<%= person['last_name'] %> <%= person['last_name'] %>
</span> </td>
</span> <td>
<%= person['created_at'] %>
</td>
<td>
<%= button_to 'Details', crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) %>
</td>
<td>
<%= button_to "Delete", {:action => "delete_person", :tiss_id => person['tiss_id']}, :method => 'delete' %>
</td>
</tr>
<% end %> <% end %>
</li> </table>
<% end %> </div>
</ul> <% else %>
No favorite people added yet!
<% end %>

View File

@ -26,6 +26,7 @@ Rails.application.routes.draw do
namespace :favorites do namespace :favorites do
get 'people' get 'people'
delete 'delete_person'
get 'courses' get 'courses'
get 'theses' get 'theses'
get 'projects' get 'projects'

View File

@ -1,10 +1,10 @@
class CreateFavoritePeople < ActiveRecord::Migration[6.0] class CreateFavoritePeople < ActiveRecord::Migration[6.0]
def change def change
create_table :favorite_people, id: false do |t| 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 :first_name
t.string :last_name t.string :last_name
t.string :picture_uri t.string :picture_uri
t.timestamps t.timestamps

View File

@ -13,7 +13,8 @@
ActiveRecord::Schema.define(version: 2020_04_21_152314) do ActiveRecord::Schema.define(version: 2020_04_21_152314) do
create_table "favorite_people", id: false, force: :cascade do |t| 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 "first_name"
t.string "last_name" t.string "last_name"
t.string "picture_uri" t.string "picture_uri"