tiss2go/app/controllers/crawlers/tiss_crawler_controller.rb
2020-06-04 22:14:21 +02:00

61 lines
1.8 KiB
Ruby

class Crawlers::TissCrawlerController < ApplicationController
# self designed lib to call the Tiss API
require 'tiss/tiss_crawler'
def search
# search context like 'People', 'Courses', etc is mandatory
$search_context = params[:search_context]
# evaluate the proper action regarding to the $search_context
case $search_context
when 'People'
# redirect to people_show_basic, propagate the search_term
redirect_to :controller => 'crawlers/people_crawler', :action => :show_basic, :search_term => params[:search_term]
when 'Courses'
# redirect to courses_show_basic, propagate the search_term
redirect_to :controller => 'crawlers/courses_crawler', :action => :show_basic, :search_term => params[:search_term]
when 'Theses'
# redirect to thesis_show_basic, propagate the search_term
redirect_to :controller => 'crawlers/theses_crawler', :action => :show_basic, :search_term => params[:search_term]
when 'Projects'
redirect_to :controller => 'crawlers/projects_crawler', :action => :show_basic, :search_term => params[:search_term]
else
puts 'Undefined search context'
end
end
def show_basic
end
def show_detail
end
def add_to_fav
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