tiss2go/app/controllers/crawlers/theses_crawler_controller.rb

61 lines
1.9 KiB
Ruby

class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
def show_basic
params[:api] = '/api/search/thesis/v1.0/quickSearch'
params[:search_parameter] = 'searchterm'
puts params[:search_context]
@host = TissCrawler.host
# TissCrawler performs general search over the available theses
result = TissCrawler.search(params)
if result.has_key? :error
flash[:alert] = 'Something went wrong! ' + result[:error]
redirect_back(fallback_location: crawlers_tiss_crawler_search_path)
else
# TissCrawler performs general search over the available people
@theses = result[:content]
end
end
def show_detail
params[:api] = '/api/thesis/'
@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
@thesis = TissCrawler.get_thesis_details(params)
# Host is needed for image rendering
@host = TissCrawler.host
end
def add_to_fav
params[:api] = '/api/thesis/'
puts params[:id]
@thesis = TissCrawler.get_thesis_details(params)
# create stores the object to the db after creation
favorite_hash = {id: [params[:id], current_user.id],
# the user who is currently active
# user_id: current_user.id,
title: @thesis['title']['de']}
if FavoriteThesis.create(favorite_hash).valid?
FavoriteThesis.create(favorite_hash)
flash[:alert] = 'Thesis added to your favorites!'
else
flash[:alert] = 'Thesis is already favorited!'
end
redirect_back(fallback_location: search)
end
def add_annotation
store_annotation FavoriteThesis, 'Thesis', {id: params[:id]}
end
def add_keyword
store_keyword FavoriteThesis, 'Thesis', {id: params[:id]}
end
end