Implement search, show_basic, show_detail and add_to_fav for theses

This commit is contained in:
2020-05-25 16:14:41 +02:00
parent 311e3d9dcb
commit d84297bde7
13 changed files with 175 additions and 3 deletions
+47 -1
View File
@@ -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;
}
}
}
}
@@ -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
@@ -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
+7
View File
@@ -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
+5
View File
@@ -0,0 +1,5 @@
class FavoriteThesis < ApplicationRecord
self.primary_key = 'id'
validates :id, uniqueness: true
end
@@ -0,0 +1,20 @@
<h1>Results for "<%= params[:search_term] %>"</h1>
<ul class="theses-list">
<% @theses.each_with_index do |thesis| %>
<li class="thesis">
<%= link_to crawlers_theses_crawler_show_detail_url(:id => thesis['id'], :title => thesis['title']) do %>
<span class="list-link">
<span class="thesis-title">
<%= thesis['title'] %>
</span>
</span>
<% end %>
<span class="add-to-fav">
<%= link_to crawlers_theses_crawler_add_to_fav_url(:id => thesis['id'], :title => thesis['title']) do %>
<%= show_svg('favorite-24px.svg') %>
<% end %>
</span>
</li>
<% end %>
</ul>
@@ -0,0 +1,5 @@
<% if @thesis != nil %>
<h2><%= @thesis['title']['de'] %></h2>
<h5><%= @thesis['thesisType'] %>, <%= @thesis['instituteCode'] %> <%= @thesis['instituteName']['de'] %></h5>
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @thesis['title']['de'] %>
<% end %>