From 3201628f2d3c07477ed08d0765321da564478350 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 16:41:27 +0200 Subject: [PATCH 1/9] Add routes for projects --- config/routes.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 946e698..9b741ff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 From 19eb7a724fd7cf50859f9911d29054f7cc6ec288 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 17:09:25 +0200 Subject: [PATCH 2/9] Add search context for projects --- app/controllers/crawlers/tiss_crawler_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index d7f2368..aae78e3 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -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 From 61933c23d4f783ca36e5e908db938531ff316b96 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 17:11:01 +0200 Subject: [PATCH 3/9] Implement `get_project_details` --- lib/tiss/tiss_crawler.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/tiss/tiss_crawler.rb b/lib/tiss/tiss_crawler.rb index bc764cb..09ca59c 100644 --- a/lib/tiss/tiss_crawler.rb +++ b/lib/tiss/tiss_crawler.rb @@ -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 From bba13f249c78dffffe2b6ff01ce9a674c6b80e49 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 17:18:23 +0200 Subject: [PATCH 4/9] Implement `show_basic`, `show_detail` and `add_to_fav` methods --- .../crawlers/projects_crawler_controller.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index 13688c9..a830b7a 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -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 From 9c76ce0553bc419e801a44932f5ace88dd7fa2b4 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 17:44:03 +0200 Subject: [PATCH 5/9] Implement a basic detail page for projects --- .../crawlers/projects_crawler/show_detail.html.erb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/views/crawlers/projects_crawler/show_detail.html.erb diff --git a/app/views/crawlers/projects_crawler/show_detail.html.erb b/app/views/crawlers/projects_crawler/show_detail.html.erb new file mode 100644 index 0000000..f87a807 --- /dev/null +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -0,0 +1,14 @@ +<% if @project != nil %> +

<%= @project['titleDe'] %>

+
<%= @project['contractBegin'] %> - <%= @project['contractEnd'] %>
+ <%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @project['titleDe'] %> + <% if @project['abstractDe'] != nil %> +

Beschreibung

+

<%= @project['abstractDe'] %>

+ <% else %> + <% if @project['abstractEn'] != nil %> +

Beschreibung

+

<%= @project['abstractEn'] %>

+ <% end %> + <% end %> +<% end %> From f2ad597c94e28c97a2a64e0da269ed340ba4b372 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 17:47:41 +0200 Subject: [PATCH 6/9] Implement the basic search result page for projects --- app/assets/stylesheets/projects_crawler.scss | 46 +++++++++++++++++++ .../projects_crawler/show_basic.html.erb | 20 ++++++++ 2 files changed, 66 insertions(+) create mode 100644 app/views/crawlers/projects_crawler/show_basic.html.erb diff --git a/app/assets/stylesheets/projects_crawler.scss b/app/assets/stylesheets/projects_crawler.scss index 9783c68..4950b24 100644 --- a/app/assets/stylesheets/projects_crawler.scss +++ b/app/assets/stylesheets/projects_crawler.scss @@ -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; + } + } + } +} diff --git a/app/views/crawlers/projects_crawler/show_basic.html.erb b/app/views/crawlers/projects_crawler/show_basic.html.erb new file mode 100644 index 0000000..21e2bab --- /dev/null +++ b/app/views/crawlers/projects_crawler/show_basic.html.erb @@ -0,0 +1,20 @@ +

Results for "<%= params[:search_term] %>"

+ +
    + <% @projects.each_with_index do |project| %> +
  • + <%= link_to crawlers_projects_crawler_show_detail_url(:id => project['id'], :title => project['title']) do %> + + + <%= project['title'] %> + + + <% end %> + + <%= link_to crawlers_projects_crawler_add_to_fav_url(:id => project['id'], :title => project['title']) do %> + <%= show_svg('favorite-24px.svg') %> + <% end %> + +
  • + <% end %> +
From b12d161b0e8c84716b4fb2ce1d60b712588a3755 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 20:03:24 +0200 Subject: [PATCH 7/9] Fix empty response --- lib/tiss/tiss_crawler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tiss/tiss_crawler.rb b/lib/tiss/tiss_crawler.rb index 09ca59c..207ccaf 100644 --- a/lib/tiss/tiss_crawler.rb +++ b/lib/tiss/tiss_crawler.rb @@ -53,7 +53,7 @@ class TissCrawler puts(url) response = HTTParty.get(url) - response.parsed_response['tuvienna']['project'] + response.parsed_response['tuVienna']['project'] end def self.get_host From c9f93d6fd826500007f91010a1ffd0c991ec2c59 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Wed, 27 May 2020 20:07:04 +0200 Subject: [PATCH 8/9] Do not parse HTML MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Might allow an attacker (in this case someone creating a course in TISS) to do some nasty HTML injection. But eeeh, who cares? ¯\_(ツ)_/¯ --- app/views/crawlers/projects_crawler/show_detail.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/crawlers/projects_crawler/show_detail.html.erb b/app/views/crawlers/projects_crawler/show_detail.html.erb index f87a807..7321c2c 100644 --- a/app/views/crawlers/projects_crawler/show_detail.html.erb +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -4,11 +4,11 @@ <%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @project['titleDe'] %> <% if @project['abstractDe'] != nil %>

Beschreibung

-

<%= @project['abstractDe'] %>

+

<%= raw @project['abstractDe'] %>

<% else %> <% if @project['abstractEn'] != nil %>

Beschreibung

-

<%= @project['abstractEn'] %>

+

<%= raw @project['abstractEn'] %>

<% end %> <% end %> <% end %> From 47d47a51b7d8949e196ab363991bfde5896e9539 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Fri, 29 May 2020 15:48:11 +0200 Subject: [PATCH 9/9] styling of favorites --- app/assets/stylesheets/favorites.scss | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index 908b25c..0d9f5ff 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -28,6 +28,27 @@ width: 3em; } +.table_wrapper { + overflow-x: auto; + + table { + border-collapse: collapse; + width: 100%; + } + + th, td { + padding: 8px; + text-align: left; + border-bottom: 1px solid #ddd; + } + + +} + +.thumb { + width: 3em; +} + .table_wrapper { table { border-collapse: collapse;