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 -%> -