Merge branches 'projects_search' and 'user_based_+_sortable_favs'
# Conflicts: # app/assets/stylesheets/favorites.scss
This commit is contained in:
commit
a3f7066cc1
@ -44,3 +44,22 @@
|
||||
|
||||
|
||||
}
|
||||
|
||||
.thumb {
|
||||
width: 3em;
|
||||
}
|
||||
|
||||
.table_wrapper {
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th, td {
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,3 +1,49 @@
|
||||
// Place all the styles related to the ProjectsCrawler controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: https://sass-lang.com/
|
||||
|
||||
.projects-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.project {
|
||||
line-height: 72px;
|
||||
width: 100%;
|
||||
padding: 8px 0 8px 0;
|
||||
|
||||
.list-link {
|
||||
float: left;
|
||||
width: 89%;
|
||||
height: 72px;
|
||||
}
|
||||
|
||||
.project-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::ProjectsCrawlerController < Crawlers::TissCrawlerController
|
||||
def show_basic
|
||||
params[:api] = '/api/search/projectFullSearch/v1.0/projects'
|
||||
params[:search_parameter] = 'searchterm'
|
||||
puts params[:search_context]
|
||||
@host = TissCrawler.get_host
|
||||
|
||||
# TissCrawler performs general search over the available projects
|
||||
@projects = TissCrawler.search(params)
|
||||
end
|
||||
|
||||
def show_detail
|
||||
params[:api] = '/api/pdb/rest/project/v2/'
|
||||
|
||||
@id = params[:id]
|
||||
|
||||
puts params
|
||||
# TissCrawler fetches the project's detail information
|
||||
@project = TissCrawler.get_project_details(params)
|
||||
# Host is needed for image rendering
|
||||
@host = TissCrawler.get_host
|
||||
end
|
||||
|
||||
def add_to_fav
|
||||
params[:api] = '/api/pdb/rest/project/v2/'
|
||||
puts params[:id]
|
||||
@project = TissCrawler.get_project_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: @project['titleDe']}
|
||||
if FavoriteProject.create(favorite_hash).valid?
|
||||
FavoriteProject.create(favorite_hash)
|
||||
flash[:alert] = 'Project added to your favorites!'
|
||||
else
|
||||
flash[:alert] = 'Project is already favorited!'
|
||||
end
|
||||
redirect_back(fallback_location: search)
|
||||
end
|
||||
end
|
||||
|
||||
@ -19,6 +19,7 @@ class Crawlers::TissCrawlerController < ApplicationController
|
||||
# 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'
|
||||
redirect_to :controller => 'crawlers/projects_crawler', :action => :show_basic, :search_term => params[:search_term]
|
||||
else
|
||||
puts 'Undefined search context'
|
||||
end
|
||||
|
||||
20
app/views/crawlers/projects_crawler/show_basic.html.erb
Normal file
20
app/views/crawlers/projects_crawler/show_basic.html.erb
Normal file
@ -0,0 +1,20 @@
|
||||
<h1>Results for "<%= params[:search_term] %>"</h1>
|
||||
|
||||
<ul class="projects-list">
|
||||
<% @projects.each_with_index do |project| %>
|
||||
<li class="project">
|
||||
<%= link_to crawlers_projects_crawler_show_detail_url(:id => project['id'], :title => project['title']) do %>
|
||||
<span class="list-link">
|
||||
<span class="project-title">
|
||||
<%= project['title'] %>
|
||||
</span>
|
||||
</span>
|
||||
<% end %>
|
||||
<span class="add-to-fav">
|
||||
<%= link_to crawlers_projects_crawler_add_to_fav_url(:id => project['id'], :title => project['title']) do %>
|
||||
<%= show_svg('favorite-24px.svg') %>
|
||||
<% end %>
|
||||
</span>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
14
app/views/crawlers/projects_crawler/show_detail.html.erb
Normal file
14
app/views/crawlers/projects_crawler/show_detail.html.erb
Normal file
@ -0,0 +1,14 @@
|
||||
<% if @project != nil %>
|
||||
<h2><%= @project['titleDe'] %></h2>
|
||||
<h5><%= @project['contractBegin'] %> - <%= @project['contractEnd'] %></h5>
|
||||
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @project['titleDe'] %>
|
||||
<% if @project['abstractDe'] != nil %>
|
||||
<h4>Beschreibung</h4>
|
||||
<p><%= raw @project['abstractDe'] %></p>
|
||||
<% else %>
|
||||
<% if @project['abstractEn'] != nil %>
|
||||
<h4>Beschreibung</h4>
|
||||
<p><%= raw @project['abstractEn'] %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@ -30,6 +30,14 @@ Rails.application.routes.draw do
|
||||
get 'add_to_fav'
|
||||
post 'add_to_fav'
|
||||
end
|
||||
|
||||
namespace :projects_crawler do
|
||||
get 'show_basic'
|
||||
get 'show_detail'
|
||||
post 'show_detail'
|
||||
get 'add_to_fav'
|
||||
post 'add_to_fav'
|
||||
end
|
||||
end
|
||||
|
||||
namespace :favorites do
|
||||
@ -40,6 +48,7 @@ Rails.application.routes.draw do
|
||||
get 'theses'
|
||||
delete 'delete_thesis'
|
||||
get 'projects'
|
||||
delete 'delete_projects'
|
||||
end
|
||||
|
||||
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
|
||||
|
||||
@ -46,6 +46,16 @@ class TissCrawler
|
||||
response.parsed_response['tuvienna']['thesis']
|
||||
end
|
||||
|
||||
def self.get_project_details(params)
|
||||
api = params[:api]
|
||||
id = params[:id]
|
||||
url = $host + api + id
|
||||
puts(url)
|
||||
|
||||
response = HTTParty.get(url)
|
||||
response.parsed_response['tuVienna']['project']
|
||||
end
|
||||
|
||||
def self.get_host
|
||||
$host
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user