From 3e3ed87b188e83832ff0db5e8f4a8b8579c5a758 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 19:24:45 +0200 Subject: [PATCH 01/21] Introduce and use print.css --- app/assets/stylesheets/print.css | 17 +++++++++++++++++ app/views/favorites/_nav.html.erb | 4 +++- app/views/layouts/application.html.erb | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/print.css diff --git a/app/assets/stylesheets/print.css b/app/assets/stylesheets/print.css new file mode 100644 index 0000000..7fada74 --- /dev/null +++ b/app/assets/stylesheets/print.css @@ -0,0 +1,17 @@ +@media print { + nav, input, button, .favNav { + display: none; + } + + @page { + size: A4; + } + + body { + counter-reset: chapternum figurenum; + font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif; + line-height: 1.5; + font-size: 11pt; + } +} + diff --git a/app/views/favorites/_nav.html.erb b/app/views/favorites/_nav.html.erb index 00728b8..265a051 100644 --- a/app/views/favorites/_nav.html.erb +++ b/app/views/favorites/_nav.html.erb @@ -3,4 +3,6 @@ <%= link_to 'Courses', favorites_courses_url %> <%= link_to 'Theses', favorites_theses_url %> <%= link_to 'Projects', favorites_projects_url %> - \ No newline at end of file + + <%= link_to "Print", '#', onclick: "print()" %> + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e48e0f0..37c8872 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,7 +5,9 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= stylesheet_link_tag 'print', media: 'print' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> @@ -43,4 +45,5 @@ + From b188b238b829b318a43ce45bf5c08dbcc4defab8 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 19:24:56 +0200 Subject: [PATCH 02/21] Reformat inputs --- app/assets/stylesheets/application.css | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b8595d5..30228f8 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -118,4 +118,18 @@ input[type=text], input[type=url], input[type=email], input[type=password], inpu line-height: 25px; font-size: 16px; border: 1px solid #bbb; +} + +input { + background-color: #3F51B5; + border: none; + color: white; + padding: 3px 3px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin-right: 0.1em; + font-weight: bolder; + border-radius: 4px; } \ No newline at end of file From d52e844fa5f3858e44fc7ccef77d50f64867a7cb Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 19:25:06 +0200 Subject: [PATCH 03/21] Reformat the delete buttons --- app/assets/stylesheets/favorites.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index a780c04..89c7057 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -40,7 +40,9 @@ display: flex; :nth-child(2) { - color: darkred; + -webkit-text-fill-color: #ffffff; + background-color: #ff1919; + border-radius: 4px; } } From 10950525f2d8b38bcb7eabd8d1870d838cee4c5f Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 19:25:27 +0200 Subject: [PATCH 04/21] Remove nokogiri as it is part of rails --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index 211a4a7..0f2f3bf 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.7.0' -# gem 'nokogiri', require: false - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '6.0.2.1' # Use sqlite3 as the database for Active Record From 6ef204797c799c61be71cb377335ee18e86f6e22 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 19:25:36 +0200 Subject: [PATCH 05/21] push --- Gemfile.lock | 235 --------------------------------------------------- 1 file changed, 235 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 17ac9f4..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,235 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - actioncable (6.0.2.1) - actionpack (= 6.0.2.1) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.0.2.1) - actionpack (= 6.0.2.1) - activejob (= 6.0.2.1) - activerecord (= 6.0.2.1) - activestorage (= 6.0.2.1) - activesupport (= 6.0.2.1) - mail (>= 2.7.1) - actionmailer (6.0.2.1) - actionpack (= 6.0.2.1) - actionview (= 6.0.2.1) - activejob (= 6.0.2.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.0.2.1) - actionview (= 6.0.2.1) - activesupport (= 6.0.2.1) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.2.1) - actionpack (= 6.0.2.1) - activerecord (= 6.0.2.1) - activestorage (= 6.0.2.1) - activesupport (= 6.0.2.1) - nokogiri (>= 1.8.5) - actionview (6.0.2.1) - activesupport (= 6.0.2.1) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.2.1) - activesupport (= 6.0.2.1) - globalid (>= 0.3.6) - activemodel (6.0.2.1) - activesupport (= 6.0.2.1) - activerecord (6.0.2.1) - activemodel (= 6.0.2.1) - activesupport (= 6.0.2.1) - activestorage (6.0.2.1) - actionpack (= 6.0.2.1) - activejob (= 6.0.2.1) - activerecord (= 6.0.2.1) - marcel (~> 0.3.1) - activesupport (6.0.2.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - bcrypt (3.1.13) - bindex (0.8.1) - bootsnap (1.4.6) - msgpack (~> 1.0) - builder (3.2.4) - byebug (11.1.1) - capybara (3.32.1) - addressable - mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (~> 1.5) - xpath (~> 3.2) - childprocess (3.0.0) - concurrent-ruby (1.1.6) - crass (1.0.6) - devise (4.7.1) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - devise-encryptable (0.2.0) - devise (>= 2.1.0) - erubi (1.9.0) - ffi (1.12.2) - globalid (0.4.2) - activesupport (>= 4.2.0) - httparty (0.18.0) - mime-types (~> 3.0) - multi_xml (>= 0.5.2) - i18n (1.8.2) - concurrent-ruby (~> 1.0) - jbuilder (2.10.0) - activesupport (>= 5.0.0) - loofah (2.5.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (1.0.0) - mime-types (3.3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2019.1009) - mimemagic (0.3.4) - mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.14.0) - msgpack (1.3.3) - multi_xml (0.6.0) - nio4r (2.5.2) - nokogiri (1.10.9) - mini_portile2 (~> 2.4.0) - orm_adapter (0.5.0) - public_suffix (4.0.4) - puma (4.3.3) - nio4r (~> 2.0) - rack (2.2.2) - rack-proxy (0.6.5) - rack - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.0.2.1) - actioncable (= 6.0.2.1) - actionmailbox (= 6.0.2.1) - actionmailer (= 6.0.2.1) - actionpack (= 6.0.2.1) - actiontext (= 6.0.2.1) - actionview (= 6.0.2.1) - activejob (= 6.0.2.1) - activemodel (= 6.0.2.1) - activerecord (= 6.0.2.1) - activestorage (= 6.0.2.1) - activesupport (= 6.0.2.1) - bundler (>= 1.3.0) - railties (= 6.0.2.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - railties (6.0.2.1) - actionpack (= 6.0.2.1) - activesupport (= 6.0.2.1) - method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) - rake (13.0.1) - regexp_parser (1.7.0) - responders (3.0.0) - actionpack (>= 5.0) - railties (>= 5.0) - rubyzip (2.3.0) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.2.1) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) - rubyzip (>= 1.2.2) - sprockets (4.0.0) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - sqlite3 (1.4.2) - thor (1.0.1) - thread_safe (0.3.6) - tilt (2.0.10) - turbolinks (5.2.1) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) - tzinfo (1.2.7) - thread_safe (~> 0.1) - warden (1.2.8) - rack (>= 2.0.6) - web-console (4.0.1) - actionview (>= 6.0.0) - activemodel (>= 6.0.0) - bindex (>= 0.4.0) - railties (>= 6.0.0) - webdrivers (4.2.0) - nokogiri (~> 1.6) - rubyzip (>= 1.3.0) - selenium-webdriver (>= 3.0, < 4.0) - webpacker (4.2.2) - activesupport (>= 4.2) - rack-proxy (>= 0.6.1) - railties (>= 4.2) - websocket-driver (0.7.1) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) - xpath (3.2.0) - nokogiri (~> 1.8) - zeitwerk (2.3.0) - -PLATFORMS - ruby - -DEPENDENCIES - bootsnap (>= 1.4.2) - byebug - capybara (>= 2.15) - devise (= 4.7.1) - devise-encryptable (= 0.2.0) - httparty (= 0.18.0) - jbuilder (~> 2.7) - puma (~> 4.1) - rails (= 6.0.2.1) - sass-rails (>= 6) - selenium-webdriver - sqlite3 (~> 1.4) - turbolinks (~> 5) - tzinfo-data - web-console (>= 3.3.0) - webdrivers - webpacker (~> 4.0) - -RUBY VERSION - ruby 2.7.0p0 - -BUNDLED WITH - 2.1.2 From 31f437c37a25999b6af597e689886806604ee805 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 19:25:51 +0200 Subject: [PATCH 06/21] Fix styling issue with missing td cell --- app/views/favorites/people.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/favorites/people.html.erb b/app/views/favorites/people.html.erb index b8d9782..7fcd78d 100644 --- a/app/views/favorites/people.html.erb +++ b/app/views/favorites/people.html.erb @@ -43,6 +43,7 @@ + <% end %> From cf0422731c68fa3d11e34f4d6c4bdabb15fbe81a Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 20:14:09 +0200 Subject: [PATCH 07/21] fix input styling --- app/assets/stylesheets/application.css | 7 ++++--- app/assets/stylesheets/favorites.scss | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 30228f8..cd97425 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -121,9 +121,10 @@ input[type=text], input[type=url], input[type=email], input[type=password], inpu } input { - background-color: #3F51B5; - border: none; - color: white; + background-color: white; + border: solid #3F51B5; + border-width: 1px; + color: #3F51B5; padding: 3px 3px; text-align: center; text-decoration: none; diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index 89c7057..2197538 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -43,6 +43,7 @@ -webkit-text-fill-color: #ffffff; background-color: #ff1919; border-radius: 4px; + border-color: #ff1919; } } From c82ba7977689ffeb88cbea05bcf17957ad03cf73 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 20:14:45 +0200 Subject: [PATCH 08/21] Add input field for personal annotations --- app/assets/stylesheets/tiss_crawler.scss | 5 +++++ app/views/crawlers/_personal_annotations.html.erb | 11 +++++++++++ .../crawlers/courses_crawler/show_detail.html.erb | 2 ++ .../crawlers/people_crawler/show_detail.html.erb | 4 +++- .../crawlers/projects_crawler/show_detail.html.erb | 2 ++ .../crawlers/theses_crawler/show_detail.html.erb | 2 ++ 6 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/views/crawlers/_personal_annotations.html.erb diff --git a/app/assets/stylesheets/tiss_crawler.scss b/app/assets/stylesheets/tiss_crawler.scss index 00b82ff..dfc467c 100644 --- a/app/assets/stylesheets/tiss_crawler.scss +++ b/app/assets/stylesheets/tiss_crawler.scss @@ -1,3 +1,8 @@ // Place all the styles related to the tiss_crawler controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: https://sass-lang.com/ + +.annotationField { + width: 99.5%; + height: 8em; +} \ No newline at end of file diff --git a/app/views/crawlers/_personal_annotations.html.erb b/app/views/crawlers/_personal_annotations.html.erb new file mode 100644 index 0000000..d19c197 --- /dev/null +++ b/app/views/crawlers/_personal_annotations.html.erb @@ -0,0 +1,11 @@ +<%= form_tag "submit", :id => "my_form" do -%> +

+ Add an annotation: +

+

+ <%= text_area_tag 'body', nil, class: 'annotationField' %> +

+

+ <%= submit_tag "Save annotation" %> +

+<% end -%> \ No newline at end of file diff --git a/app/views/crawlers/courses_crawler/show_detail.html.erb b/app/views/crawlers/courses_crawler/show_detail.html.erb index 23c85ba..1b5efb8 100644 --- a/app/views/crawlers/courses_crawler/show_detail.html.erb +++ b/app/views/crawlers/courses_crawler/show_detail.html.erb @@ -13,4 +13,6 @@

Inhalt

<%= raw @course['objective']['de'] %> <% end %> + + <%= render :partial => "crawlers/personal_annotations" %> <% end %> diff --git a/app/views/crawlers/people_crawler/show_detail.html.erb b/app/views/crawlers/people_crawler/show_detail.html.erb index ce54c90..391a4bf 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -17,5 +17,7 @@

Address: <%= @person['main_addresses'][0]['street'] %>, <%= @person['main_addresses'][0]['zip_code'] %> <%= @person['main_addresses'][0]['city'] %>

<% end %> - <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'] %> + <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %> + + <%= render :partial => "crawlers/personal_annotations" %> <% end %> \ No newline at end of file diff --git a/app/views/crawlers/projects_crawler/show_detail.html.erb b/app/views/crawlers/projects_crawler/show_detail.html.erb index 7321c2c..74d6674 100644 --- a/app/views/crawlers/projects_crawler/show_detail.html.erb +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -11,4 +11,6 @@

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

<% end %> <% end %> + + <%= render :partial => "crawlers/personal_annotations" %> <% end %> diff --git a/app/views/crawlers/theses_crawler/show_detail.html.erb b/app/views/crawlers/theses_crawler/show_detail.html.erb index 24f1a83..6880bf2 100644 --- a/app/views/crawlers/theses_crawler/show_detail.html.erb +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -10,4 +10,6 @@

Assistant

<%= @thesis['assistant']['familyName'] %> <%= @thesis['assistant']['givenName'] %>

<% end %> + + <%= render :partial => "crawlers/personal_annotations" %> <% end %> From 81a7e16bae9701b5678adebd685a4b646c2d0bed Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:51:52 +0200 Subject: [PATCH 09/21] add field for storing personal_annotation string --- db/migrate/20200421152314_create_favorite_people.rb | 1 + db/migrate/20200521091231_create_favorite_courses.rb | 1 + db/migrate/20200525132942_create_favorite_theses.rb | 1 + db/migrate/20200529081537_create_favorite_projects.rb | 1 + 4 files changed, 4 insertions(+) diff --git a/db/migrate/20200421152314_create_favorite_people.rb b/db/migrate/20200421152314_create_favorite_people.rb index d1a00b0..039d27d 100644 --- a/db/migrate/20200421152314_create_favorite_people.rb +++ b/db/migrate/20200421152314_create_favorite_people.rb @@ -6,6 +6,7 @@ class CreateFavoritePeople < ActiveRecord::Migration[6.0] t.string :first_name t.string :last_name t.string :picture_uri + t.string :personal_annotation t.timestamps end diff --git a/db/migrate/20200521091231_create_favorite_courses.rb b/db/migrate/20200521091231_create_favorite_courses.rb index 4937ab0..d475a0b 100644 --- a/db/migrate/20200521091231_create_favorite_courses.rb +++ b/db/migrate/20200521091231_create_favorite_courses.rb @@ -5,6 +5,7 @@ class CreateFavoriteCourses < ActiveRecord::Migration[6.0] t.string :semester, null: false t.string :title, null: false t.integer :user_id, null: false + t.string :personal_annotation t.timestamps end diff --git a/db/migrate/20200525132942_create_favorite_theses.rb b/db/migrate/20200525132942_create_favorite_theses.rb index 64c63db..c0edcef 100644 --- a/db/migrate/20200525132942_create_favorite_theses.rb +++ b/db/migrate/20200525132942_create_favorite_theses.rb @@ -4,6 +4,7 @@ class CreateFavoriteTheses < ActiveRecord::Migration[6.0] t.integer :id, null: false t.integer :user_id, null: false t.string :title + t.string :personal_annotation t.timestamps end diff --git a/db/migrate/20200529081537_create_favorite_projects.rb b/db/migrate/20200529081537_create_favorite_projects.rb index c5195f8..701e4e5 100644 --- a/db/migrate/20200529081537_create_favorite_projects.rb +++ b/db/migrate/20200529081537_create_favorite_projects.rb @@ -4,6 +4,7 @@ class CreateFavoriteProjects < ActiveRecord::Migration[6.0] t.integer :id, null: false t.integer :user_id, null: false t.string :title + t.string :personal_annotation t.timestamps end From b7119cdbd3ede709cccd17cb477bd8fbd9572204 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:52:22 +0200 Subject: [PATCH 10/21] add partial render for rendering the personal_annotation form --- app/views/crawlers/_personal_annotations.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/crawlers/_personal_annotations.html.erb b/app/views/crawlers/_personal_annotations.html.erb index d19c197..3f19ac4 100644 --- a/app/views/crawlers/_personal_annotations.html.erb +++ b/app/views/crawlers/_personal_annotations.html.erb @@ -1,9 +1,10 @@ -<%= form_tag "submit", :id => "my_form" do -%> +<%= form_tag "add_annotation", :id => "id" do -%>

Add an annotation:

- <%= text_area_tag 'body', nil, class: 'annotationField' %> + <%= text_area_tag 'body', personal_annotation, class: 'annotationField' %> + <%= hidden_field_tag :id , cur_id %>

<%= submit_tag "Save annotation" %> From 81965171759f92551e22ce28c0ce61fbe11d7fab Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:52:51 +0200 Subject: [PATCH 11/21] add helper for personal_annotation partial form --- app/helpers/crawlers/tiss_crawler_helper.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/helpers/crawlers/tiss_crawler_helper.rb b/app/helpers/crawlers/tiss_crawler_helper.rb index b730a09..75886e7 100644 --- a/app/helpers/crawlers/tiss_crawler_helper.rb +++ b/app/helpers/crawlers/tiss_crawler_helper.rb @@ -1,2 +1,9 @@ module Crawlers::TissCrawlerHelper + def render_personal_annotations(id, object) + render :partial => "crawlers/personal_annotations", + :locals => { + :cur_id => id, + :personal_annotation => (object['personal_annotation'] if object) + } + end end From 37cc1ae72df4b8af17056c9ce9f26cb53f0f2c75 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:53:32 +0200 Subject: [PATCH 12/21] add stubs, routes for add_annotation action --- app/controllers/crawlers/courses_crawler_controller.rb | 3 +++ app/controllers/crawlers/projects_crawler_controller.rb | 3 +++ app/controllers/crawlers/theses_crawler_controller.rb | 3 +++ app/controllers/crawlers/tiss_crawler_controller.rb | 3 +++ config/routes.rb | 4 ++++ 5 files changed, 16 insertions(+) diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index dc41553..b6c7aeb 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -82,4 +82,7 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController redirect_back(fallback_location: search) end + def add_annotation + end + end diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index 605efe2..aa087fb 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -46,4 +46,7 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController end redirect_back(fallback_location: search) end + + def add_annotation + end end diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 711b1a0..3bd5ce8 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -46,4 +46,7 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController end redirect_back(fallback_location: search) end + + def add_annotation + end end diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index aae78e3..dcf54f4 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -34,4 +34,7 @@ class Crawlers::TissCrawlerController < ApplicationController def add_to_fav end + def add_annotation + end + end diff --git a/config/routes.rb b/config/routes.rb index 5469c54..8f7d967 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end namespace :courses_crawler do @@ -21,6 +22,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end namespace :theses_crawler do @@ -29,6 +31,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end namespace :projects_crawler do @@ -37,6 +40,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end end From 72db9148c4e8dee008158cd044dce8dab305c8cb Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:53:38 +0200 Subject: [PATCH 13/21] push --- db/schema.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/schema.rb b/db/schema.rb index 846a44a..603affc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,6 +17,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.string "semester", null: false t.string "title", null: false t.integer "user_id", null: false + t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["number", "semester"], name: "index_favorite_courses_on_number_and_semester", unique: true @@ -28,6 +29,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.string "first_name" t.string "last_name" t.string "picture_uri" + t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true @@ -37,6 +39,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.integer "id", null: false t.integer "user_id", null: false t.string "title" + t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["id"], name: "index_favorite_projects_on_id", unique: true @@ -46,6 +49,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.integer "id", null: false t.integer "user_id", null: false t.string "title" + t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["id"], name: "index_favorite_theses_on_id", unique: true From d59030ffc06a113694626d6e0b885d83b4c98a7d Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:53:54 +0200 Subject: [PATCH 14/21] render personal_annotation partial with the help of render_personal_annotations helper --- app/views/crawlers/people_crawler/show_detail.html.erb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/crawlers/people_crawler/show_detail.html.erb b/app/views/crawlers/people_crawler/show_detail.html.erb index 391a4bf..833951e 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -14,10 +14,12 @@

Other E-Mails: <%= @person['other_emails'] %>

<% end %> <% if @person['main_addresses'] != nil %> -

Address: <%= @person['main_addresses'][0]['street'] %>, <%= @person['main_addresses'][0]['zip_code'] %> <%= @person['main_addresses'][0]['city'] %>

+

Address: <%= @person['main_addresses'][0]['street'] %> + , <%= @person['main_addresses'][0]['zip_code'] %> <%= @person['main_addresses'][0]['city'] %>

<% end %> - + <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %> - <%= render :partial => "crawlers/personal_annotations" %> + <%= render_personal_annotations @person['tiss_id'], @stored_person %> + <% end %> \ No newline at end of file From 88783ffede1d223a83087fabad50f92206d8bc49 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 21:54:17 +0200 Subject: [PATCH 15/21] on detail view show stored annotation if available --- .../crawlers/people_crawler_controller.rb | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index ffb605d..353433a 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -22,6 +22,10 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController params[:api] = '/api/person/v22/id/' params[:tiss_id] = params[:tiss_id] + if FavoritePerson.exists?(params[:tiss_id]) + @stored_person = FavoritePerson.find(params[:tiss_id]) + end + puts params # TissCrawler fetches the person's detail information @person = TissCrawler.get_details(params) @@ -35,12 +39,12 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController @person = TissCrawler.get_details(params) # create stores the object to the db after creation - 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'] } + 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!' @@ -50,4 +54,14 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end + def add_annotation + if FavoritePerson.exists?(params[:id]) + FavoritePerson.update(params[:id], :personal_annotation => params[:body]) + flash[:alert] = 'Annotation stored!' + else + flash[:alert] = 'Person has to be favorited first!' + end + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + end + end From 74cc3dce229a11023066782241c71c7042f4394e Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 22:14:21 +0200 Subject: [PATCH 16/21] make annotation storing and retrieving more generic --- .../crawlers/people_crawler_controller.rb | 12 ++--------- .../crawlers/tiss_crawler_controller.rb | 20 +++++++++++++++++++ app/helpers/crawlers/tiss_crawler_helper.rb | 4 ++-- .../people_crawler/show_detail.html.erb | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 353433a..7ac4571 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -22,9 +22,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController params[:api] = '/api/person/v22/id/' params[:tiss_id] = params[:tiss_id] - if FavoritePerson.exists?(params[:tiss_id]) - @stored_person = FavoritePerson.find(params[:tiss_id]) - end + @personal_annotation = get_stored_annotation FavoritePerson, {tiss_id: params[:tiss_id]} puts params # TissCrawler fetches the person's detail information @@ -55,13 +53,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController end def add_annotation - if FavoritePerson.exists?(params[:id]) - FavoritePerson.update(params[:id], :personal_annotation => params[:body]) - flash[:alert] = 'Annotation stored!' - else - flash[:alert] = 'Person has to be favorited first!' - end - redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + store_annotation FavoritePerson, 'Person', params[:id] end end diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index dcf54f4..dad9f8e 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -35,6 +35,26 @@ class Crawlers::TissCrawlerController < ApplicationController end def add_annotation + + end + + 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'] + else + "" + end + end + + def store_annotation(object, object_name, id) + if object.exists?(id) + object.update(id, :personal_annotation => params[:body]) + flash[:alert] = 'Annotation stored!' + else + flash[:alert] = object_name + ' has to be favorited first!' + end + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end end diff --git a/app/helpers/crawlers/tiss_crawler_helper.rb b/app/helpers/crawlers/tiss_crawler_helper.rb index 75886e7..ec3bcc2 100644 --- a/app/helpers/crawlers/tiss_crawler_helper.rb +++ b/app/helpers/crawlers/tiss_crawler_helper.rb @@ -1,9 +1,9 @@ module Crawlers::TissCrawlerHelper - def render_personal_annotations(id, object) + def render_personal_annotations(id, personal_annotation) render :partial => "crawlers/personal_annotations", :locals => { :cur_id => id, - :personal_annotation => (object['personal_annotation'] if object) + :personal_annotation => personal_annotation } end end diff --git a/app/views/crawlers/people_crawler/show_detail.html.erb b/app/views/crawlers/people_crawler/show_detail.html.erb index 833951e..8471927 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -20,6 +20,6 @@ <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %> - <%= render_personal_annotations @person['tiss_id'], @stored_person %> + <%= render_personal_annotations @person['tiss_id'], @personal_annotation %> <% end %> \ No newline at end of file From 9881e7962d06ebd62bb7fdff5001d5481dd9cd9d Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 22:17:38 +0200 Subject: [PATCH 17/21] add render_personal_annotations to all favorite classes --- app/views/crawlers/courses_crawler/show_detail.html.erb | 2 +- app/views/crawlers/projects_crawler/show_detail.html.erb | 3 ++- app/views/crawlers/theses_crawler/show_detail.html.erb | 2 +- app/views/favorites/projects.html.erb | 1 + app/views/favorites/theses.html.erb | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/crawlers/courses_crawler/show_detail.html.erb b/app/views/crawlers/courses_crawler/show_detail.html.erb index 1b5efb8..a92e666 100644 --- a/app/views/crawlers/courses_crawler/show_detail.html.erb +++ b/app/views/crawlers/courses_crawler/show_detail.html.erb @@ -14,5 +14,5 @@ <%= raw @course['objective']['de'] %> <% end %> - <%= render :partial => "crawlers/personal_annotations" %> + <%= render_personal_annotations @course['courseNumber'], @personal_annotation %> <% end %> diff --git a/app/views/crawlers/projects_crawler/show_detail.html.erb b/app/views/crawlers/projects_crawler/show_detail.html.erb index 74d6674..915c0a2 100644 --- a/app/views/crawlers/projects_crawler/show_detail.html.erb +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -12,5 +12,6 @@ <% end %> <% end %> - <%= render :partial => "crawlers/personal_annotations" %> + <%= render_personal_annotations @id, @personal_annotation %> + <% end %> diff --git a/app/views/crawlers/theses_crawler/show_detail.html.erb b/app/views/crawlers/theses_crawler/show_detail.html.erb index 6880bf2..17a7486 100644 --- a/app/views/crawlers/theses_crawler/show_detail.html.erb +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -11,5 +11,5 @@

<%= @thesis['assistant']['familyName'] %> <%= @thesis['assistant']['givenName'] %>

<% end %> - <%= render :partial => "crawlers/personal_annotations" %> + <%= render_personal_annotations @id, @personal_annotation %> <% end %> diff --git a/app/views/favorites/projects.html.erb b/app/views/favorites/projects.html.erb index 0af93e5..d458f9a 100644 --- a/app/views/favorites/projects.html.erb +++ b/app/views/favorites/projects.html.erb @@ -25,6 +25,7 @@ <%= button_to 'Delete', {:action => "delete_project", :id => project['id']}, :method => 'delete' %> + <% end %> diff --git a/app/views/favorites/theses.html.erb b/app/views/favorites/theses.html.erb index 4d2deac..bc14c31 100644 --- a/app/views/favorites/theses.html.erb +++ b/app/views/favorites/theses.html.erb @@ -26,6 +26,7 @@ <%= button_to 'Delete', {:action => "delete_thesis", :id => thesis['id']}, :method => 'delete' %> + <% end %> From 1e8703609443c85f3253307b4bdf595f8e47d7af Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Thu, 4 Jun 2020 23:15:54 +0200 Subject: [PATCH 18/21] 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 %> From ca38d7260da1dc8b66e3de9dc91f15a77b2e6831 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Fri, 5 Jun 2020 00:35:04 +0200 Subject: [PATCH 19/21] fixed bugfix where another user could not store the same object again fixed the primary keys => all the classes have now composite primary key which contais an id + user_id, necessary gem: 'composite_primary_keys' fixed the user_id relation => every class now "belongs_to" user pls kill me know --- Gemfile | 3 +++ .../crawlers/projects_crawler_controller.rb | 4 +-- .../crawlers/theses_crawler_controller.rb | 4 +-- app/models/favorite_course.rb | 4 ++- app/models/favorite_person.rb | 4 +-- app/models/favorite_project.rb | 4 +-- app/models/favorite_thesis.rb | 4 +-- .../20200421152314_create_favorite_people.rb | 6 ++--- .../20200521091231_create_favorite_courses.rb | 6 ++--- .../20200525132942_create_favorite_theses.rb | 5 ++-- ...20200529081537_create_favorite_projects.rb | 5 ++-- db/schema.rb | 25 ++++++++++--------- 12 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Gemfile b/Gemfile index 0f2f3bf..93e3b88 100644 --- a/Gemfile +++ b/Gemfile @@ -37,6 +37,9 @@ gem 'devise-encryptable', '0.2.0' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false +# for composite primary keys +gem 'composite_primary_keys' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index 460f496..c25cb31 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -36,9 +36,9 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController @project = TissCrawler.get_project_details(params) # create stores the object to the db after creation - favorite_hash = {id: params[:id], + favorite_hash = {id: [params[:id], current_user.id], # the user who is currently active - user_id: current_user.id, + # user_id: current_user.id, title: @project['titleDe']} if FavoriteProject.create(favorite_hash).valid? FavoriteProject.create(favorite_hash) diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index ae2d336..97c8e65 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -36,9 +36,9 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @thesis = TissCrawler.get_thesis_details(params) # create stores the object to the db after creation - favorite_hash = {id: params[:id], + favorite_hash = {id: [params[:id], current_user.id], # the user who is currently active - user_id: current_user.id, + # user_id: current_user.id, title: @thesis['title']['de']} if FavoriteThesis.create(favorite_hash).valid? FavoriteThesis.create(favorite_hash) diff --git a/app/models/favorite_course.rb b/app/models/favorite_course.rb index 60d0d1f..7bac3e6 100644 --- a/app/models/favorite_course.rb +++ b/app/models/favorite_course.rb @@ -1,4 +1,6 @@ class FavoriteCourse < ApplicationRecord + self.primary_keys = :id, :user_id + validates :title, :semester, :number, presence: true - validates :semester, :number, uniqueness: {scope: [:semester, :number]} + validates :semester, :number, uniqueness: {scope: [:semester, :number, :user_id]} end diff --git a/app/models/favorite_person.rb b/app/models/favorite_person.rb index 9d1e8b8..e5d4186 100644 --- a/app/models/favorite_person.rb +++ b/app/models/favorite_person.rb @@ -1,5 +1,5 @@ class FavoritePerson < ApplicationRecord - self.primary_key = 'tiss_id' + self.primary_keys = :tiss_id, :user_id - validates :tiss_id, uniqueness: true + validates :tiss_id, uniqueness: { scope: [:user_id] } end diff --git a/app/models/favorite_project.rb b/app/models/favorite_project.rb index f7482c4..ca4e37e 100644 --- a/app/models/favorite_project.rb +++ b/app/models/favorite_project.rb @@ -1,5 +1,5 @@ class FavoriteProject < ApplicationRecord - self.primary_key = 'id' + self.primary_keys = :id, :user_id - validates :id, uniqueness: true + validates :id, :user_id, uniqueness: {scope: [:id, :user_id]} end diff --git a/app/models/favorite_thesis.rb b/app/models/favorite_thesis.rb index f1618f9..23f5238 100644 --- a/app/models/favorite_thesis.rb +++ b/app/models/favorite_thesis.rb @@ -1,5 +1,5 @@ class FavoriteThesis < ApplicationRecord - self.primary_key = 'id' + self.primary_keys = :id, :user_id - validates :id, uniqueness: true + validates :id, :user_id, uniqueness: {scope: [:id, :user_id]} end diff --git a/db/migrate/20200421152314_create_favorite_people.rb b/db/migrate/20200421152314_create_favorite_people.rb index 039d27d..e412e40 100644 --- a/db/migrate/20200421152314_create_favorite_people.rb +++ b/db/migrate/20200421152314_create_favorite_people.rb @@ -1,15 +1,13 @@ class CreateFavoritePeople < ActiveRecord::Migration[6.0] def change - create_table :favorite_people, id: false do |t| + create_table :favorite_people, primary_key: [:tiss_id, :user_id] do |t| t.integer :tiss_id, null: false - t.integer :user_id, null: false + t.belongs_to :user t.string :first_name t.string :last_name t.string :picture_uri t.string :personal_annotation - t.timestamps end - add_index :favorite_people, :tiss_id, unique: true end end diff --git a/db/migrate/20200521091231_create_favorite_courses.rb b/db/migrate/20200521091231_create_favorite_courses.rb index d475a0b..45b675e 100644 --- a/db/migrate/20200521091231_create_favorite_courses.rb +++ b/db/migrate/20200521091231_create_favorite_courses.rb @@ -1,14 +1,14 @@ class CreateFavoriteCourses < ActiveRecord::Migration[6.0] def change - create_table :favorite_courses do |t| + create_table :favorite_courses , primary_key: [:id, :user_id] do |t| + t.integer :id + t.belongs_to :user t.string :number, null: false t.string :semester, null: false t.string :title, null: false - t.integer :user_id, null: false t.string :personal_annotation t.timestamps end - add_index :favorite_courses, [:number, :semester], unique: true end end diff --git a/db/migrate/20200525132942_create_favorite_theses.rb b/db/migrate/20200525132942_create_favorite_theses.rb index c0edcef..4292946 100644 --- a/db/migrate/20200525132942_create_favorite_theses.rb +++ b/db/migrate/20200525132942_create_favorite_theses.rb @@ -1,13 +1,12 @@ class CreateFavoriteTheses < ActiveRecord::Migration[6.0] def change - create_table :favorite_theses, id: false do |t| + create_table :favorite_theses, primary_key: [:id, :user_id] do |t| t.integer :id, null: false - t.integer :user_id, null: false + t.belongs_to :user t.string :title t.string :personal_annotation t.timestamps end - add_index :favorite_theses, :id, unique: true end end diff --git a/db/migrate/20200529081537_create_favorite_projects.rb b/db/migrate/20200529081537_create_favorite_projects.rb index 701e4e5..90dc787 100644 --- a/db/migrate/20200529081537_create_favorite_projects.rb +++ b/db/migrate/20200529081537_create_favorite_projects.rb @@ -1,13 +1,12 @@ class CreateFavoriteProjects < ActiveRecord::Migration[6.0] def change - create_table :favorite_projects, id: false do |t| + create_table :favorite_projects, primary_key: [:id, :user_id] do |t| t.integer :id, null: false - t.integer :user_id, null: false + t.belongs_to :user t.string :title t.string :personal_annotation t.timestamps end - add_index :favorite_projects, :id, unique: true end end diff --git a/db/schema.rb b/db/schema.rb index 603affc..88fe6f3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,47 +12,48 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do - create_table "favorite_courses", force: :cascade do |t| + create_table "favorite_courses", primary_key: ["id", "user_id"], force: :cascade do |t| + t.integer "id" + t.integer "user_id" t.string "number", null: false t.string "semester", null: false t.string "title", null: false - t.integer "user_id", null: false t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["number", "semester"], name: "index_favorite_courses_on_number_and_semester", unique: true + t.index ["user_id"], name: "index_favorite_courses_on_user_id" end - create_table "favorite_people", id: false, force: :cascade do |t| + create_table "favorite_people", primary_key: ["tiss_id", "user_id"], force: :cascade do |t| t.integer "tiss_id", null: false - t.integer "user_id", null: false + t.integer "user_id" t.string "first_name" t.string "last_name" t.string "picture_uri" t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true + t.index ["user_id"], name: "index_favorite_people_on_user_id" end - create_table "favorite_projects", id: false, force: :cascade do |t| + create_table "favorite_projects", primary_key: ["id", "user_id"], force: :cascade do |t| t.integer "id", null: false - t.integer "user_id", null: false + t.integer "user_id" t.string "title" t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["id"], name: "index_favorite_projects_on_id", unique: true + t.index ["user_id"], name: "index_favorite_projects_on_user_id" end - create_table "favorite_theses", id: false, force: :cascade do |t| + create_table "favorite_theses", primary_key: ["id", "user_id"], force: :cascade do |t| t.integer "id", null: false - t.integer "user_id", null: false + t.integer "user_id" t.string "title" t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["id"], name: "index_favorite_theses_on_id", unique: true + t.index ["user_id"], name: "index_favorite_theses_on_user_id" end create_table "users", force: :cascade do |t| From 9cc357fb17a1829c9f80704871a6c0750fa96504 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Fri, 5 Jun 2020 00:41:18 +0200 Subject: [PATCH 20/21] add print button to all detail views --- app/views/crawlers/courses_crawler/show_detail.html.erb | 2 ++ app/views/crawlers/people_crawler/show_detail.html.erb | 2 ++ app/views/crawlers/projects_crawler/show_detail.html.erb | 2 ++ app/views/crawlers/theses_crawler/show_detail.html.erb | 2 ++ app/views/favorites/_nav.html.erb | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/crawlers/courses_crawler/show_detail.html.erb b/app/views/crawlers/courses_crawler/show_detail.html.erb index 780d1de..d8ad360 100644 --- a/app/views/crawlers/courses_crawler/show_detail.html.erb +++ b/app/views/crawlers/courses_crawler/show_detail.html.erb @@ -1,6 +1,8 @@ <% if @course != nil %> <%-# TODO parse more fields and style them appropriately -%>

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

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<%= @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 5b6089d..6767af0 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -1,5 +1,7 @@ <% if @person != nil %>

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

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<% 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 f0709e7..92be9e7 100644 --- a/app/views/crawlers/projects_crawler/show_detail.html.erb +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -1,5 +1,7 @@ <% if @project != nil %>

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

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<%= @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 ef18732..54cc904 100644 --- a/app/views/crawlers/theses_crawler/show_detail.html.erb +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -1,5 +1,7 @@ <% if @thesis != nil %>

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

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<%= @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 %> diff --git a/app/views/favorites/_nav.html.erb b/app/views/favorites/_nav.html.erb index 265a051..4a9c8e7 100644 --- a/app/views/favorites/_nav.html.erb +++ b/app/views/favorites/_nav.html.erb @@ -4,5 +4,5 @@ <%= link_to 'Theses', favorites_theses_url %> <%= link_to 'Projects', favorites_projects_url %> - <%= link_to "Print", '#', onclick: "print()" %> + <%= link_to "PRINT", '#', onclick: "print()" %>
From 86d3e2f4e3f633bf3a7afa2732bdd8e8bcc31621 Mon Sep 17 00:00:00 2001 From: Pfingstfrosch Date: Fri, 5 Jun 2020 00:43:10 +0200 Subject: [PATCH 21/21] push --- Gemfile.lock | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..3f376de --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,240 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (6.0.2.1) + actionpack (= 6.0.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.0.2.1) + actionpack (= 6.0.2.1) + activejob (= 6.0.2.1) + activerecord (= 6.0.2.1) + activestorage (= 6.0.2.1) + activesupport (= 6.0.2.1) + mail (>= 2.7.1) + actionmailer (6.0.2.1) + actionpack (= 6.0.2.1) + actionview (= 6.0.2.1) + activejob (= 6.0.2.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (6.0.2.1) + actionview (= 6.0.2.1) + activesupport (= 6.0.2.1) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.2.1) + actionpack (= 6.0.2.1) + activerecord (= 6.0.2.1) + activestorage (= 6.0.2.1) + activesupport (= 6.0.2.1) + nokogiri (>= 1.8.5) + actionview (6.0.2.1) + activesupport (= 6.0.2.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.0.2.1) + activesupport (= 6.0.2.1) + globalid (>= 0.3.6) + activemodel (6.0.2.1) + activesupport (= 6.0.2.1) + activerecord (6.0.2.1) + activemodel (= 6.0.2.1) + activesupport (= 6.0.2.1) + activestorage (6.0.2.1) + actionpack (= 6.0.2.1) + activejob (= 6.0.2.1) + activerecord (= 6.0.2.1) + marcel (~> 0.3.1) + activesupport (6.0.2.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + zeitwerk (~> 2.2) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + bcrypt (3.1.13) + bindex (0.8.1) + bootsnap (1.4.6) + msgpack (~> 1.0) + builder (3.2.4) + byebug (11.1.1) + capybara (3.32.1) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) + childprocess (3.0.0) + composite_primary_keys (12.0.2) + activerecord (~> 6.0.0) + concurrent-ruby (1.1.6) + crass (1.0.6) + devise (4.7.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) + devise-encryptable (0.2.0) + devise (>= 2.1.0) + erubi (1.9.0) + ffi (1.12.2-x64-mingw32) + globalid (0.4.2) + activesupport (>= 4.2.0) + httparty (0.18.0) + mime-types (~> 3.0) + multi_xml (>= 0.5.2) + i18n (1.8.2) + concurrent-ruby (~> 1.0) + jbuilder (2.10.0) + activesupport (>= 5.0.0) + loofah (2.5.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) + method_source (1.0.0) + mime-types (3.3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2019.1009) + mimemagic (0.3.5) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.14.0) + msgpack (1.3.3-x64-mingw32) + multi_xml (0.6.0) + nio4r (2.5.2) + nokogiri (1.10.9) + mini_portile2 (~> 2.4.0) + orm_adapter (0.5.0) + public_suffix (4.0.4) + puma (4.3.3) + nio4r (~> 2.0) + rack (2.2.2) + rack-proxy (0.6.5) + rack + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (6.0.2.1) + actioncable (= 6.0.2.1) + actionmailbox (= 6.0.2.1) + actionmailer (= 6.0.2.1) + actionpack (= 6.0.2.1) + actiontext (= 6.0.2.1) + actionview (= 6.0.2.1) + activejob (= 6.0.2.1) + activemodel (= 6.0.2.1) + activerecord (= 6.0.2.1) + activestorage (= 6.0.2.1) + activesupport (= 6.0.2.1) + bundler (>= 1.3.0) + railties (= 6.0.2.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) + railties (6.0.2.1) + actionpack (= 6.0.2.1) + activesupport (= 6.0.2.1) + method_source + rake (>= 0.8.7) + thor (>= 0.20.3, < 2.0) + rake (13.0.1) + regexp_parser (1.7.0) + responders (3.0.0) + actionpack (>= 5.0) + railties (>= 5.0) + rubyzip (2.3.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.2.1-x64-mingw32) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + selenium-webdriver (3.142.7) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) + sprockets (4.0.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.4.2) + thor (1.0.1) + thread_safe (0.3.6) + tilt (2.0.10) + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.7) + thread_safe (~> 0.1) + tzinfo-data (1.2019.3) + tzinfo (>= 1.0.0) + warden (1.2.8) + rack (>= 2.0.6) + web-console (4.0.1) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) + bindex (>= 0.4.0) + railties (>= 6.0.0) + webdrivers (4.2.0) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (>= 3.0, < 4.0) + webpacker (4.2.2) + activesupport (>= 4.2) + rack-proxy (>= 0.6.1) + railties (>= 4.2) + websocket-driver (0.7.2) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.3.0) + +PLATFORMS + x64-mingw32 + +DEPENDENCIES + bootsnap (>= 1.4.2) + byebug + capybara (>= 2.15) + composite_primary_keys + devise (= 4.7.1) + devise-encryptable (= 0.2.0) + httparty (= 0.18.0) + jbuilder (~> 2.7) + puma (~> 4.1) + rails (= 6.0.2.1) + sass-rails (>= 6) + selenium-webdriver + sqlite3 (~> 1.4) + turbolinks (~> 5) + tzinfo-data + web-console (>= 3.3.0) + webdrivers + webpacker (~> 4.0) + +RUBY VERSION + ruby 2.7.0p0 + +BUNDLED WITH + 2.1.4