diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index 353433a..7ac4571 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -22,9 +22,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController params[:api] = '/api/person/v22/id/' params[:tiss_id] = params[:tiss_id] - if FavoritePerson.exists?(params[:tiss_id]) - @stored_person = FavoritePerson.find(params[:tiss_id]) - end + @personal_annotation = get_stored_annotation FavoritePerson, {tiss_id: params[:tiss_id]} puts params # TissCrawler fetches the person's detail information @@ -55,13 +53,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController end def add_annotation - if FavoritePerson.exists?(params[:id]) - FavoritePerson.update(params[:id], :personal_annotation => params[:body]) - flash[:alert] = 'Annotation stored!' - else - flash[:alert] = 'Person has to be favorited first!' - end - redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + store_annotation FavoritePerson, 'Person', params[:id] end end diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index dcf54f4..dad9f8e 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -35,6 +35,26 @@ class Crawlers::TissCrawlerController < ApplicationController end def add_annotation + + end + + 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'] + else + "" + end + end + + def store_annotation(object, object_name, id) + if object.exists?(id) + object.update(id, :personal_annotation => params[:body]) + flash[:alert] = 'Annotation 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 75886e7..ec3bcc2 100644 --- a/app/helpers/crawlers/tiss_crawler_helper.rb +++ b/app/helpers/crawlers/tiss_crawler_helper.rb @@ -1,9 +1,9 @@ module Crawlers::TissCrawlerHelper - def render_personal_annotations(id, object) + def render_personal_annotations(id, personal_annotation) render :partial => "crawlers/personal_annotations", :locals => { :cur_id => id, - :personal_annotation => (object['personal_annotation'] if object) + :personal_annotation => personal_annotation } end end diff --git a/app/views/crawlers/people_crawler/show_detail.html.erb b/app/views/crawlers/people_crawler/show_detail.html.erb index 833951e..8471927 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -20,6 +20,6 @@ <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %> - <%= render_personal_annotations @person['tiss_id'], @stored_person %> + <%= render_personal_annotations @person['tiss_id'], @personal_annotation %> <% end %> \ No newline at end of file