Add keyword field to favorites
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
Reference in New Issue
Block a user