on detail view show stored annotation if available

This commit is contained in:
Pfingstfrosch 2020-06-04 21:54:17 +02:00
parent d59030ffc0
commit 88783ffede

View File

@ -22,6 +22,10 @@ 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])
@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
@person = TissCrawler.get_details(params) @person = TissCrawler.get_details(params)
@ -35,12 +39,12 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
@person = TissCrawler.get_details(params) @person = TissCrawler.get_details(params)
# create stores the object to the db after creation # create stores the object to the db after creation
favorite_hash = { tiss_id: @person['tiss_id'], favorite_hash = {tiss_id: @person['tiss_id'],
# the user who is currently active # the user who is currently active
user_id: current_user.id, user_id: current_user.id,
first_name: @person['first_name'], first_name: @person['first_name'],
last_name: @person['last_name'], last_name: @person['last_name'],
picture_uri: @person['picture_uri'] } picture_uri: @person['picture_uri']}
if FavoritePerson.create(favorite_hash).valid? if FavoritePerson.create(favorite_hash).valid?
FavoritePerson.create(favorite_hash) FavoritePerson.create(favorite_hash)
flash[:alert] = 'Person added to your favorites!' flash[:alert] = 'Person added to your favorites!'
@ -50,4 +54,14 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
redirect_back(fallback_location: crawlers_tiss_crawler_search_path) redirect_back(fallback_location: crawlers_tiss_crawler_search_path)
end 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)
end
end end