Merge remote-tracking branch 'origin/user_based_+_sortable_favs' into courses_search
This commit is contained in:
commit
a43c2b8edb
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
class Crawlers::ProjectsCrawlerController < TissCrawlerController
|
||||
class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
|
||||
def show_basic
|
||||
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
class Crawlers::ThesesCrawlerController < TissCrawlerController
|
||||
class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
|
||||
def show_basic
|
||||
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,25 +1,72 @@
|
||||
<%= render(:partial => "nav")%>
|
||||
<%= render(:partial => "nav") %>
|
||||
|
||||
<h1>Favorite People</h1>
|
||||
|
||||
<ul class="people-list">
|
||||
<% @favoritePeople.each do |person| %>
|
||||
<li class="person">
|
||||
<%= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %>
|
||||
<span class="list-link">
|
||||
<span class="person-icon">
|
||||
<% if person['picture_uri'] != nil %>
|
||||
<%= image_tag @host + person['picture_uri'] %>
|
||||
<% else %>
|
||||
<%= show_svg('account_circle-black-48dp.svg') %>
|
||||
<% end %>
|
||||
</span>
|
||||
<span class="person-name">
|
||||
<%= person['first_name'] %>
|
||||
<!--<ul class="people-list">-->
|
||||
<%# @favorite_people.each do |person| %>
|
||||
<!-- <li class="person">-->
|
||||
<%#= link_to crawlers_people_crawler_show_detail_url(:tiss_id => person['tiss_id']) do %>
|
||||
<!-- <span class="list-link">-->
|
||||
<!-- <span class="person-icon">-->
|
||||
<%# if person['picture_uri'] != nil %>
|
||||
<%#= image_tag @host + person['picture_uri'] %>
|
||||
<%# else %>
|
||||
<%#= show_svg('account_circle-black-48dp.svg') %>
|
||||
<%# end %>
|
||||
<!-- </span>-->
|
||||
<!-- <span class="person-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'] %>
|
||||
</span>
|
||||
</span>
|
||||
</td>
|
||||
<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 %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</table>
|
||||
</div>
|
||||
<% else %>
|
||||
No favorite people added yet!
|
||||
<% end %>
|
||||
@ -26,6 +26,7 @@ Rails.application.routes.draw do
|
||||
|
||||
namespace :favorites do
|
||||
get 'people'
|
||||
delete 'delete_person'
|
||||
get 'courses'
|
||||
get 'theses'
|
||||
get 'projects'
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user