Add keyword field to favorites
This commit is contained in:
parent
af88064af9
commit
ba2e90386f
@ -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;
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
13
app/views/crawlers/_personal_keywords.html.erb
Normal file
13
app/views/crawlers/_personal_keywords.html.erb
Normal 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 -%>
|
||||
@ -17,4 +17,5 @@
|
||||
<% end %>
|
||||
|
||||
<%= render_personal_annotations @course['courseNumber'], @personal_annotation %>
|
||||
<%= render_personal_keywords @course['courseNumber'], @personal_keyword %>
|
||||
<% end %>
|
||||
|
||||
@ -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 %>
|
||||
@ -15,5 +15,6 @@
|
||||
<% end %>
|
||||
|
||||
<%= render_personal_annotations @id, @personal_annotation %>
|
||||
<%= render_personal_keywords @id, @personal_keyword %>
|
||||
|
||||
<% end %>
|
||||
|
||||
@ -14,4 +14,5 @@
|
||||
<% end %>
|
||||
|
||||
<%= render_personal_annotations @id, @personal_annotation %>
|
||||
<%= render_personal_keywords @id, @personal_keyword %>
|
||||
<% end %>
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user