make annotation storing and retrieving more generic
This commit is contained in:
parent
88783ffede
commit
74cc3dce22
@ -22,9 +22,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
|
|||||||
params[:api] = '/api/person/v22/id/'
|
params[:api] = '/api/person/v22/id/'
|
||||||
params[:tiss_id] = params[:tiss_id]
|
params[:tiss_id] = params[:tiss_id]
|
||||||
|
|
||||||
if FavoritePerson.exists?(params[:tiss_id])
|
@personal_annotation = get_stored_annotation FavoritePerson, {tiss_id: params[:tiss_id]}
|
||||||
@stored_person = FavoritePerson.find(params[:tiss_id])
|
|
||||||
end
|
|
||||||
|
|
||||||
puts params
|
puts params
|
||||||
# TissCrawler fetches the person's detail information
|
# TissCrawler fetches the person's detail information
|
||||||
@ -55,13 +53,7 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_annotation
|
def add_annotation
|
||||||
if FavoritePerson.exists?(params[:id])
|
store_annotation FavoritePerson, 'Person', 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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -35,6 +35,26 @@ class Crawlers::TissCrawlerController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_annotation
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
module Crawlers::TissCrawlerHelper
|
module Crawlers::TissCrawlerHelper
|
||||||
def render_personal_annotations(id, object)
|
def render_personal_annotations(id, personal_annotation)
|
||||||
render :partial => "crawlers/personal_annotations",
|
render :partial => "crawlers/personal_annotations",
|
||||||
:locals => {
|
:locals => {
|
||||||
:cur_id => id,
|
:cur_id => id,
|
||||||
:personal_annotation => (object['personal_annotation'] if object)
|
:personal_annotation => personal_annotation
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -20,6 +20,6 @@
|
|||||||
<!-- <p>Employee: <%#= @person.employee %></p>-->
|
<!-- <p>Employee: <%#= @person.employee %></p>-->
|
||||||
<%= 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'], @stored_person %>
|
<%= render_personal_annotations @person['tiss_id'], @personal_annotation %>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
Loading…
x
Reference in New Issue
Block a user