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 def add_keyword end private def get_stored_annotation(object, id_hash) id_hash['user_id'] = current_user if object.exists?(id_hash) object.where(id_hash)[0]['personal_annotation'] else "" end end def store_annotation(object, object_name, id_hash) id_hash['user_id'] = current_user # Allow storing empty strings as a way of "clearing" the stored val if object.exists?(id_hash) object.where(id_hash)[0].update(: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 def get_stored_keyword(object, id_hash) id_hash['user_id'] = current_user if object.exists?(id_hash) object.where(id_hash)[0]['personal_keyword'] else "" end end def store_keyword(object, object_name, id_hash) id_hash['user_id'] = current_user # Allow storing empty strings as a way of "clearing" the stored val if object.exists?(id_hash) object.where(id_hash)[0].update(:personal_keyword => params[:body]) flash[:alert] = 'Keyword stored!' else flash[:alert] = object_name + ' has to be favorited first!' end redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end end