Add keyword field to favorites

This commit is contained in:
Tobias Eidelpes 2020-06-09 19:30:16 +02:00
parent af88064af9
commit ba2e90386f
18 changed files with 82 additions and 5 deletions

View File

@ -2,7 +2,7 @@
// They will automatically be included in application.css. // They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/ // You can use Sass (SCSS) here: https://sass-lang.com/
.annotationField { .annotationField, .keywordField {
width: 99.5%; width: 99.5%;
height: 8em; height: 8em;
} }

View File

@ -27,6 +27,7 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController
end end
@personal_annotation = get_stored_annotation FavoriteCourse, {number: params[:number]} @personal_annotation = get_stored_annotation FavoriteCourse, {number: params[:number]}
@personal_keyword = get_stored_keyword FavoriteCourse, {number: params[:number]}
puts params puts params
@ -88,4 +89,7 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController
store_annotation FavoriteCourse, 'Course', {number: params[:id]} store_annotation FavoriteCourse, 'Course', {number: params[:id]}
end end
def add_keyword
store_keyword FavoriteCourse, 'Course', {number: params[:id]}
end
end end

View File

@ -23,6 +23,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
params[:tiss_id] = params[:tiss_id] params[:tiss_id] = params[:tiss_id]
@personal_annotation = get_stored_annotation FavoritePerson, {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 puts params
# TissCrawler fetches the person's detail information # TissCrawler fetches the person's detail information
@ -56,4 +57,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
store_annotation FavoritePerson, 'Person', {tiss_id: params[:id]} store_annotation FavoritePerson, 'Person', {tiss_id: params[:id]}
end end
def add_keyword
store_keyword FavoritePerson, 'Person', {tiss_id: params[:id]}
end
end end

View File

@ -22,6 +22,7 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
@id = params[:id] @id = params[:id]
@personal_annotation = get_stored_annotation FavoriteProject, {id: @id} @personal_annotation = get_stored_annotation FavoriteProject, {id: @id}
@personal_keyword = get_stored_keyword FavoriteProject, {id: @id}
puts params puts params
# TissCrawler fetches the project's detail information # TissCrawler fetches the project's detail information
@ -52,4 +53,8 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
def add_annotation def add_annotation
store_annotation FavoriteProject, 'Project', {id: params[:id]} store_annotation FavoriteProject, 'Project', {id: params[:id]}
end end
def add_keyword
store_keyword FavoriteProject, 'Project', {id: params[:id]}
end
end end

View File

@ -22,6 +22,7 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
@id = params[:id] @id = params[:id]
@personal_annotation = get_stored_annotation FavoriteThesis, {id: @id} @personal_annotation = get_stored_annotation FavoriteThesis, {id: @id}
@personal_keyword = get_stored_keyword FavoriteThesis, {id: @id}
puts params puts params
# TissCrawler fetches the thesis' detail information # TissCrawler fetches the thesis' detail information
@ -52,4 +53,8 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
def add_annotation def add_annotation
store_annotation FavoriteThesis, 'Thesis', {id: params[:id]} store_annotation FavoriteThesis, 'Thesis', {id: params[:id]}
end end
def add_keyword
store_keyword FavoriteThesis, 'Thesis', {id: params[:id]}
end
end end

View File

@ -38,6 +38,10 @@ class Crawlers::TissCrawlerController < ApplicationController
end end
def add_keyword
end
private private
def get_stored_annotation(object, id_hash) def get_stored_annotation(object, id_hash)
id_hash['user_id'] = current_user id_hash['user_id'] = current_user
@ -61,4 +65,26 @@ class Crawlers::TissCrawlerController < ApplicationController
redirect_back(fallback_location: crawlers_tiss_crawler_search_path) redirect_back(fallback_location: crawlers_tiss_crawler_search_path)
end 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 end

View File

@ -6,4 +6,12 @@ module Crawlers::TissCrawlerHelper
:personal_annotation => personal_annotation :personal_annotation => personal_annotation
} }
end end
def render_personal_keywords(id, personal_keyword)
render :partial => "crawlers/personal_keywords",
:locals => {
:cur_id => id,
:personal_keyword => personal_keyword
}
end
end end

View File

@ -0,0 +1,13 @@
<%= form_tag "add_keyword", :id => "id" do -%>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<p>
Add a keyword:
</p>
<p>
<%= text_area_tag 'body', personal_keyword, class: 'keywordField' %>
<%= hidden_field_tag :id , cur_id %>
</p>
<p>
<%= submit_tag "Save keywords" %>
</p>
<% end -%>

View File

@ -17,4 +17,5 @@
<% end %> <% end %>
<%= render_personal_annotations @course['courseNumber'], @personal_annotation %> <%= render_personal_annotations @course['courseNumber'], @personal_annotation %>
<%= render_personal_keywords @course['courseNumber'], @personal_keyword %>
<% end %> <% end %>

View File

@ -23,5 +23,6 @@
<%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %> <%= 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_annotations @person['tiss_id'], @personal_annotation %>
<%= render_personal_keywords @person['tiss_id'], @personal_keyword %>
<% end %> <% end %>

View File

@ -15,5 +15,6 @@
<% end %> <% end %>
<%= render_personal_annotations @id, @personal_annotation %> <%= render_personal_annotations @id, @personal_annotation %>
<%= render_personal_keywords @id, @personal_keyword %>
<% end %> <% end %>

View File

@ -14,4 +14,5 @@
<% end %> <% end %>
<%= render_personal_annotations @id, @personal_annotation %> <%= render_personal_annotations @id, @personal_annotation %>
<%= render_personal_keywords @id, @personal_keyword %>
<% end %> <% end %>

View File

@ -14,6 +14,7 @@ Rails.application.routes.draw do
get 'add_to_fav' get 'add_to_fav'
post 'add_to_fav' post 'add_to_fav'
post 'add_annotation' post 'add_annotation'
post 'add_keyword'
end end
namespace :courses_crawler do namespace :courses_crawler do
@ -23,6 +24,7 @@ Rails.application.routes.draw do
get 'add_to_fav' get 'add_to_fav'
post 'add_to_fav' post 'add_to_fav'
post 'add_annotation' post 'add_annotation'
post 'add_keyword'
end end
namespace :theses_crawler do namespace :theses_crawler do
@ -32,6 +34,7 @@ Rails.application.routes.draw do
get 'add_to_fav' get 'add_to_fav'
post 'add_to_fav' post 'add_to_fav'
post 'add_annotation' post 'add_annotation'
post 'add_keyword'
end end
namespace :projects_crawler do namespace :projects_crawler do
@ -41,6 +44,7 @@ Rails.application.routes.draw do
get 'add_to_fav' get 'add_to_fav'
post 'add_to_fav' post 'add_to_fav'
post 'add_annotation' post 'add_annotation'
post 'add_keyword'
end end
end end

View File

@ -7,7 +7,7 @@ class CreateFavoritePeople < ActiveRecord::Migration[6.0]
t.string :last_name t.string :last_name
t.string :picture_uri t.string :picture_uri
t.string :personal_annotation t.string :personal_annotation
t.string :keywords t.string :personal_keyword
t.timestamps t.timestamps
end end

View File

@ -7,7 +7,7 @@ class CreateFavoriteCourses < ActiveRecord::Migration[6.0]
t.string :semester, null: false t.string :semester, null: false
t.string :title, null: false t.string :title, null: false
t.string :personal_annotation t.string :personal_annotation
t.string :keywords t.string :personal_keyword
t.timestamps t.timestamps
end end

View File

@ -5,7 +5,7 @@ class CreateFavoriteTheses < ActiveRecord::Migration[6.0]
t.belongs_to :user t.belongs_to :user
t.string :title t.string :title
t.string :personal_annotation t.string :personal_annotation
t.string :keywords t.string :personal_keyword
t.timestamps t.timestamps
end end

View File

@ -5,7 +5,7 @@ class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
t.belongs_to :user t.belongs_to :user
t.string :title t.string :title
t.string :personal_annotation t.string :personal_annotation
t.string :keywords t.string :personal_keyword
t.timestamps t.timestamps
end end

View File

@ -19,6 +19,7 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do
t.string "semester", null: false t.string "semester", null: false
t.string "title", null: false t.string "title", null: false
t.string "personal_annotation" t.string "personal_annotation"
t.string "personal_keyword"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_favorite_courses_on_user_id" 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 "last_name"
t.string "picture_uri" t.string "picture_uri"
t.string "personal_annotation" t.string "personal_annotation"
t.string "personal_keyword"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_favorite_people_on_user_id" 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.integer "user_id"
t.string "title" t.string "title"
t.string "personal_annotation" t.string "personal_annotation"
t.string "personal_keyword"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_favorite_projects_on_user_id" 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.integer "user_id"
t.string "title" t.string "title"
t.string "personal_annotation" t.string "personal_annotation"
t.string "personal_keyword"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_favorite_theses_on_user_id" t.index ["user_id"], name: "index_favorite_theses_on_user_id"