diff --git a/app/assets/stylesheets/tiss_crawler.scss b/app/assets/stylesheets/tiss_crawler.scss index dfc467c..3730e9a 100644 --- a/app/assets/stylesheets/tiss_crawler.scss +++ b/app/assets/stylesheets/tiss_crawler.scss @@ -2,7 +2,7 @@ // They will automatically be included in application.css. // You can use Sass (SCSS) here: https://sass-lang.com/ -.annotationField { +.annotationField, .keywordField { width: 99.5%; height: 8em; } \ No newline at end of file diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index e000079..339b84c 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -27,6 +27,7 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController end @personal_annotation = get_stored_annotation FavoriteCourse, {number: params[:number]} + @personal_keyword = get_stored_keyword FavoriteCourse, {number: params[:number]} puts params @@ -88,4 +89,7 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController store_annotation FavoriteCourse, 'Course', {number: params[:id]} end + def add_keyword + store_keyword 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 beed2ee..be11ffe 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -23,6 +23,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController params[:tiss_id] = params[:tiss_id] @personal_annotation = get_stored_annotation FavoritePerson, {tiss_id: params[:tiss_id]} + @personal_keyword = get_stored_keyword FavoritePerson, {tiss_id: params[:tiss_id]} puts params # TissCrawler fetches the person's detail information @@ -56,4 +57,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController store_annotation FavoritePerson, 'Person', {tiss_id: params[:id]} end + def add_keyword + store_keyword 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 c25cb31..6fe540a 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -22,6 +22,7 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController @id = params[:id] @personal_annotation = get_stored_annotation FavoriteProject, {id: @id} + @personal_keyword = get_stored_keyword FavoriteProject, {id: @id} puts params # TissCrawler fetches the project's detail information @@ -52,4 +53,8 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController def add_annotation store_annotation FavoriteProject, 'Project', {id: params[:id]} end + + def add_keyword + store_keyword 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 97c8e65..7cbd7d4 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -22,6 +22,7 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @id = params[:id] @personal_annotation = get_stored_annotation FavoriteThesis, {id: @id} + @personal_keyword = get_stored_keyword FavoriteThesis, {id: @id} puts params # TissCrawler fetches the thesis' detail information @@ -52,4 +53,8 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController def add_annotation store_annotation FavoriteThesis, 'Thesis', {id: params[:id]} end + + def add_keyword + store_keyword 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 0a9a39d..ffa0f73 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -38,6 +38,10 @@ class Crawlers::TissCrawlerController < ApplicationController end + def add_keyword + + end + private def get_stored_annotation(object, id_hash) id_hash['user_id'] = current_user @@ -61,4 +65,26 @@ class Crawlers::TissCrawlerController < ApplicationController redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end + def get_stored_keyword(object, id_hash) + id_hash['user_id'] = current_user + if object.exists?(id_hash) + object.where(id_hash)[0]['personal_keyword'] + else + "" + end + end + + def store_keyword(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_keyword => params[:body]) + flash[:alert] = 'Keyword 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 ec3bcc2..00d110c 100644 --- a/app/helpers/crawlers/tiss_crawler_helper.rb +++ b/app/helpers/crawlers/tiss_crawler_helper.rb @@ -6,4 +6,12 @@ module Crawlers::TissCrawlerHelper :personal_annotation => personal_annotation } end + + def render_personal_keywords(id, personal_keyword) + render :partial => "crawlers/personal_keywords", + :locals => { + :cur_id => id, + :personal_keyword => personal_keyword + } + end end diff --git a/app/views/crawlers/_personal_keywords.html.erb b/app/views/crawlers/_personal_keywords.html.erb new file mode 100644 index 0000000..98b7296 --- /dev/null +++ b/app/views/crawlers/_personal_keywords.html.erb @@ -0,0 +1,13 @@ +<%= form_tag "add_keyword", :id => "id" do -%> + <%= hidden_field_tag :authenticity_token, form_authenticity_token %> +
+ Add a keyword: +
++ <%= text_area_tag 'body', personal_keyword, class: 'keywordField' %> + <%= hidden_field_tag :id , cur_id %> +
++ <%= submit_tag "Save keywords" %> +
+<% 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 d8ad360..99c21f2 100644 --- a/app/views/crawlers/courses_crawler/show_detail.html.erb +++ b/app/views/crawlers/courses_crawler/show_detail.html.erb @@ -17,4 +17,5 @@ <% end %> <%= render_personal_annotations @course['courseNumber'], @personal_annotation %> + <%= render_personal_keywords @course['courseNumber'], @personal_keyword %> <% end %> diff --git a/app/views/crawlers/people_crawler/show_detail.html.erb b/app/views/crawlers/people_crawler/show_detail.html.erb index 6767af0..53608df 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -23,5 +23,6 @@ <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %> <%= render_personal_annotations @person['tiss_id'], @personal_annotation %> + <%= render_personal_keywords @person['tiss_id'], @personal_keyword %> <% 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 92be9e7..50fc12e 100644 --- a/app/views/crawlers/projects_crawler/show_detail.html.erb +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -15,5 +15,6 @@ <% end %> <%= render_personal_annotations @id, @personal_annotation %> + <%= render_personal_keywords @id, @personal_keyword %> <% end %> diff --git a/app/views/crawlers/theses_crawler/show_detail.html.erb b/app/views/crawlers/theses_crawler/show_detail.html.erb index 54cc904..61eaf3d 100644 --- a/app/views/crawlers/theses_crawler/show_detail.html.erb +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -14,4 +14,5 @@ <% end %> <%= render_personal_annotations @id, @personal_annotation %> + <%= render_personal_keywords @id, @personal_keyword %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 8f7d967..aa57fde 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,7 @@ Rails.application.routes.draw do get 'add_to_fav' post 'add_to_fav' post 'add_annotation' + post 'add_keyword' end namespace :courses_crawler do @@ -23,6 +24,7 @@ Rails.application.routes.draw do get 'add_to_fav' post 'add_to_fav' post 'add_annotation' + post 'add_keyword' end namespace :theses_crawler do @@ -32,6 +34,7 @@ Rails.application.routes.draw do get 'add_to_fav' post 'add_to_fav' post 'add_annotation' + post 'add_keyword' end namespace :projects_crawler do @@ -41,6 +44,7 @@ Rails.application.routes.draw do get 'add_to_fav' post 'add_to_fav' post 'add_annotation' + post 'add_keyword' end end diff --git a/db/migrate/20200421152314_create_favorite_people.rb b/db/migrate/20200421152314_create_favorite_people.rb index 6eb003e..d96add6 100644 --- a/db/migrate/20200421152314_create_favorite_people.rb +++ b/db/migrate/20200421152314_create_favorite_people.rb @@ -7,7 +7,7 @@ class CreateFavoritePeople < ActiveRecord::Migration[6.0] t.string :last_name t.string :picture_uri t.string :personal_annotation - t.string :keywords + t.string :personal_keyword t.timestamps end diff --git a/db/migrate/20200521091231_create_favorite_courses.rb b/db/migrate/20200521091231_create_favorite_courses.rb index c5b05ae..4b954a4 100644 --- a/db/migrate/20200521091231_create_favorite_courses.rb +++ b/db/migrate/20200521091231_create_favorite_courses.rb @@ -7,7 +7,7 @@ class CreateFavoriteCourses < ActiveRecord::Migration[6.0] t.string :semester, null: false t.string :title, null: false t.string :personal_annotation - t.string :keywords + t.string :personal_keyword t.timestamps end diff --git a/db/migrate/20200525132942_create_favorite_theses.rb b/db/migrate/20200525132942_create_favorite_theses.rb index db8b501..f31ebac 100644 --- a/db/migrate/20200525132942_create_favorite_theses.rb +++ b/db/migrate/20200525132942_create_favorite_theses.rb @@ -5,7 +5,7 @@ class CreateFavoriteTheses < ActiveRecord::Migration[6.0] t.belongs_to :user t.string :title t.string :personal_annotation - t.string :keywords + t.string :personal_keyword t.timestamps end diff --git a/db/migrate/20200529081537_create_favorite_projects.rb b/db/migrate/20200529081537_create_favorite_projects.rb index b2e6bf7..3c2d1a5 100644 --- a/db/migrate/20200529081537_create_favorite_projects.rb +++ b/db/migrate/20200529081537_create_favorite_projects.rb @@ -5,7 +5,7 @@ class CreateFavoriteProjects < ActiveRecord::Migration[6.0] t.belongs_to :user t.string :title t.string :personal_annotation - t.string :keywords + t.string :personal_keyword t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 88fe6f3..5691931 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -19,6 +19,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.string "semester", null: false t.string "title", null: false t.string "personal_annotation" + t.string "personal_keyword" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["user_id"], name: "index_favorite_courses_on_user_id" @@ -31,6 +32,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.string "last_name" t.string "picture_uri" t.string "personal_annotation" + t.string "personal_keyword" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["user_id"], name: "index_favorite_people_on_user_id" @@ -41,6 +43,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.integer "user_id" t.string "title" t.string "personal_annotation" + t.string "personal_keyword" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["user_id"], name: "index_favorite_projects_on_user_id" @@ -51,6 +54,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do t.integer "user_id" t.string "title" t.string "personal_annotation" + t.string "personal_keyword" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["user_id"], name: "index_favorite_theses_on_user_id"