From 1e8703609443c85f3253307b4bdf595f8e47d7af Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 23:15:54 +0200 Subject: [PATCH] personal annotations for all classes implemented --- .../crawlers/courses_crawler_controller.rb | 3 +++ .../crawlers/people_crawler_controller.rb | 2 +- .../crawlers/projects_crawler_controller.rb | 3 +++ .../crawlers/theses_crawler_controller.rb | 3 +++ .../crawlers/tiss_crawler_controller.rb | 14 +++++++++----- app/views/crawlers/_personal_annotations.html.erb | 1 + .../crawlers/courses_crawler/show_detail.html.erb | 2 +- .../crawlers/people_crawler/show_detail.html.erb | 2 +- .../crawlers/projects_crawler/show_detail.html.erb | 2 +- .../crawlers/theses_crawler/show_detail.html.erb | 2 +- 10 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index b6c7aeb..e000079 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -26,6 +26,8 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController params[:semester] = regex[:semester] end + @personal_annotation = get_stored_annotation FavoriteCourse, {number: params[:number]} + puts params # TissCrawler fetches the course's detail information @@ -83,6 +85,7 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController end def add_annotation + store_annotation FavoriteCourse, 'Course', {number: params[:id]} end end diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 7ac4571..beed2ee 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -53,7 +53,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController end def add_annotation - store_annotation FavoritePerson, 'Person', params[:id] + store_annotation FavoritePerson, 'Person', {tiss_id: params[:id]} end end diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index aa087fb..460f496 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -21,6 +21,8 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController @id = params[:id] + @personal_annotation = get_stored_annotation FavoriteProject, {id: @id} + puts params # TissCrawler fetches the project's detail information @project = TissCrawler.get_project_details(params) @@ -48,5 +50,6 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController end def add_annotation + store_annotation FavoriteProject, 'Project', {id: params[:id]} end end diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 3bd5ce8..ae2d336 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -21,6 +21,8 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @id = params[:id] + @personal_annotation = get_stored_annotation FavoriteThesis, {id: @id} + puts params # TissCrawler fetches the thesis' detail information @thesis = TissCrawler.get_thesis_details(params) @@ -48,5 +50,6 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController end def add_annotation + store_annotation FavoriteThesis, 'Thesis', {id: params[:id]} end end diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index dad9f8e..0a9a39d 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -40,16 +40,20 @@ class Crawlers::TissCrawlerController < ApplicationController private def get_stored_annotation(object, id_hash) - if object.exists?(params[:tiss_id]) - object.where(id_hash, user_id: current_user.id)[0]['personal_annotation'] + id_hash['user_id'] = current_user + if object.exists?(id_hash) + object.where(id_hash)[0]['personal_annotation'] else "" end end - def store_annotation(object, object_name, id) - if object.exists?(id) - object.update(id, :personal_annotation => params[:body]) + def store_annotation(object, object_name, id_hash) + id_hash['user_id'] = current_user + + # Allow storing empty strings as a way of "clearing" the stored val + if object.exists?(id_hash) + object.where(id_hash)[0].update(:personal_annotation => params[:body]) flash[:alert] = 'Annotation stored!' else flash[:alert] = object_name + ' has to be favorited first!' diff --git a/app/views/crawlers/_personal_annotations.html.erb b/app/views/crawlers/_personal_annotations.html.erb index 3f19ac4..d28329b 100644 --- a/app/views/crawlers/_personal_annotations.html.erb +++ b/app/views/crawlers/_personal_annotations.html.erb @@ -1,4 +1,5 @@ <%= form_tag "add_annotation", :id => "id" do -%> + <%= hidden_field_tag :authenticity_token, form_authenticity_token %>

Add an annotation:

diff --git a/app/views/crawlers/courses_crawler/show_detail.html.erb b/app/views/crawlers/courses_crawler/show_detail.html.erb index a92e666..780d1de 100644 --- a/app/views/crawlers/courses_crawler/show_detail.html.erb +++ b/app/views/crawlers/courses_crawler/show_detail.html.erb @@ -1,6 +1,6 @@ <% if @course != nil %> <%-# TODO parse more fields and style them appropriately -%> -

<%= @course['title']['de'] %>

+

Course: <%= @course['title']['de'] %>

<%= @course['courseType'] %> <%= @course['semesterCode'] %>, <%= @course['weeklyHours'] %> SWS, <%= @course['instituteCode'] %> <%= @course['instituteName']['de'] %>
<%= button_to 'Add to favorites', action: :add_to_fav, number: @course['courseNumber'], semester: @course['semesterCode'] %> <% if @lecturers_names != nil %> diff --git a/app/views/crawlers/people_crawler/show_detail.html.erb b/app/views/crawlers/people_crawler/show_detail.html.erb index 8471927..5b6089d 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -1,5 +1,5 @@ <% if @person != nil %> -

<%= @person['first_name'] %> <%= @person['last_name'] %>

+

Person: <%= @person['first_name'] %> <%= @person['last_name'] %>

<% if @person['picture_uri'] != nil %> <%= image_tag @host + @person['picture_uri'] %> diff --git a/app/views/crawlers/projects_crawler/show_detail.html.erb b/app/views/crawlers/projects_crawler/show_detail.html.erb index 915c0a2..f0709e7 100644 --- a/app/views/crawlers/projects_crawler/show_detail.html.erb +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -1,5 +1,5 @@ <% if @project != nil %> -

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

+

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

<%= @project['contractBegin'] %> - <%= @project['contractEnd'] %>
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @project['titleDe'] %> <% if @project['abstractDe'] != nil %> diff --git a/app/views/crawlers/theses_crawler/show_detail.html.erb b/app/views/crawlers/theses_crawler/show_detail.html.erb index 17a7486..ef18732 100644 --- a/app/views/crawlers/theses_crawler/show_detail.html.erb +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -1,5 +1,5 @@ <% if @thesis != nil %> -

<%= @thesis['title']['de'] %>

+

Thesis: <%= @thesis['title']['de'] %>

<%= @thesis['thesisType'] %>, <%= @thesis['instituteCode'] %> <%= @thesis['instituteName']['de'] %>
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @thesis['title']['de'] %> <% if @thesis['advisor'] != nil %>