refactoring of "abstract" search controller
This commit is contained in:
parent
fbfc12e096
commit
a36796960f
@ -1,28 +1,51 @@
|
|||||||
class TissCrawlerController < ApplicationController
|
class TissCrawlerController < ApplicationController
|
||||||
|
|
||||||
|
# self designed lib to call the Tiss API
|
||||||
require 'tiss/tiss_crawler'
|
require 'tiss/tiss_crawler'
|
||||||
|
|
||||||
def index
|
def search
|
||||||
end
|
# search context like 'People', 'Courses', etc is mandatory
|
||||||
|
$search_context = params[:search_context]
|
||||||
|
|
||||||
def people_search
|
# 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 :action => 'people_show_basic', :search_term => params[:search_term]
|
||||||
|
when 'Courses'
|
||||||
|
when 'Theses'
|
||||||
|
when 'Projects'
|
||||||
|
else
|
||||||
|
puts 'Undefined search context'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def people_show_basic
|
def people_show_basic
|
||||||
params[:api] = '/api/person/v22/psuche'
|
params[:api] = '/api/person/v22/psuche'
|
||||||
params[:search_parameter] = 'q'
|
params[:search_parameter] = 'q'
|
||||||
|
puts params[:search_context]
|
||||||
|
|
||||||
|
# TissCrawler performs general search over the available people
|
||||||
@people = TissCrawler.search(params)
|
@people = TissCrawler.search(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def person_show_detail
|
def person_show_detail
|
||||||
params[:api] = '/api/person/v22/id/'
|
params[:api] = '/api/person/v22/id/'
|
||||||
|
|
||||||
|
# TissCrawler fetches the person's detail information
|
||||||
@person = TissCrawler.get_details(params)
|
@person = TissCrawler.get_details(params)
|
||||||
|
# Host is needed for image rendering
|
||||||
@host = TissCrawler.get_host
|
@host = TissCrawler.get_host
|
||||||
end
|
end
|
||||||
|
|
||||||
def person_add_to_fav
|
def person_add_to_fav
|
||||||
puts params[:tiss_id]
|
puts params[:tiss_id]
|
||||||
person = FavoritePerson.create(tiss_id: params[:tiss_id])
|
# create stores the object to the db after creation
|
||||||
|
FavoritePerson.create(tiss_id: params[:tiss_id])
|
||||||
|
# redirect and respond with success message
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to favorites_favorite_person_index_url, notice: 'Favorite person stored' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
<h1>Courses#index</h1>
|
|
||||||
<p>Find me in app/views/courses/index.html.erb</p>
|
|
||||||
@ -2,5 +2,5 @@
|
|||||||
<p>For now only the tiss_ids are stored and shown</p>
|
<p>For now only the tiss_ids are stored and shown</p>
|
||||||
|
|
||||||
<% @favoritePeople.each do |favPerson| %>
|
<% @favoritePeople.each do |favPerson| %>
|
||||||
Tiss_id: <%= favPerson.tiss_id %>
|
<p>Tiss_id: <%= favPerson.tiss_id %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<a href="#" class="logo">tiss2go</a>
|
<a href="#" class="logo">tiss2go</a>
|
||||||
<div class="left-menu">
|
<div class="left-menu">
|
||||||
<%= link_to 'Home', root_path %>
|
<%= link_to 'Home', root_path %>
|
||||||
<%= link_to 'Search', tiss_crawler_people_search_path %>
|
<%= link_to 'Search', tiss_crawler_search_path %>
|
||||||
<%= link_to 'Favorite People', '/favorites/favorite_person/index' %>
|
<%= link_to 'Favorite People', '/favorites/favorite_person/index' %>
|
||||||
<%#= link_to 'Projects', projects_index_path %>
|
<%#= link_to 'Projects', projects_index_path %>
|
||||||
<%#= link_to 'Theses', theses_index_path %>
|
<%#= link_to 'Theses', theses_index_path %>
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
<h1>People#index</h1>
|
|
||||||
<p>Find me in app/views/people/index.html.erb</p>
|
|
||||||
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
<h1>Projects#index</h1>
|
|
||||||
<p>Find me in app/views/projects/index.html.erb</p>
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
<h1>Theses#index</h1>
|
|
||||||
<p>Find me in app/views/theses/index.html.erb</p>
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
<%= form_tag('/tiss_crawler/people_show_basic', :method => "get") do %>
|
|
||||||
<%= label_tag(:search_term, "Search for people @TU Vienna:") %>
|
|
||||||
<%= text_field_tag(:search_term) %>
|
|
||||||
<%= submit_tag("Search") %>
|
|
||||||
<% end %>
|
|
||||||
@ -5,6 +5,6 @@ This is the result for your basic people search:
|
|||||||
<%= person['first_name'] %>
|
<%= person['first_name'] %>
|
||||||
<%= person['last_name'] %>
|
<%= person['last_name'] %>
|
||||||
<%= button_to 'Details', action: :person_show_detail, tiss_id: person['tiss_id'] %>
|
<%= button_to 'Details', action: :person_show_detail, tiss_id: person['tiss_id'] %>
|
||||||
<%= button_to 'Add to favs.', action: :person_add_to_fav, tiss_id: person['tiss_id'] %>
|
<%= button_to 'Add to favorites', action: :person_add_to_fav, tiss_id: person['tiss_id'] %>
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -11,4 +11,5 @@ Chosen person in detail view:
|
|||||||
<p>Other mails: <%= @person['other_emails'] %></p>
|
<p>Other mails: <%= @person['other_emails'] %></p>
|
||||||
<p>Main addresses: <%= @person['main_addresses'] %></p>
|
<p>Main addresses: <%= @person['main_addresses'] %></p>
|
||||||
<!-- <p>Employee: <%#= @person.employee %></p>-->
|
<!-- <p>Employee: <%#= @person.employee %></p>-->
|
||||||
|
<%= button_to 'Add to favorites', action: :person_add_to_fav, tiss_id: @person['tiss_id'] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
12
app/views/tiss_crawler/search.html.erb
Normal file
12
app/views/tiss_crawler/search.html.erb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<h1>Search through @TU Vienna Database</h1>
|
||||||
|
<p>Only People Search is working right now</p>
|
||||||
|
|
||||||
|
<%= form_tag('/tiss_crawler/search', :method => "get") do %>
|
||||||
|
<%= label_tag(:search_term, "Enter your search term") %>
|
||||||
|
<%= text_field_tag(:search_term) %>
|
||||||
|
<%= radio_button_tag(:search_context, 'People', true) %> People
|
||||||
|
<%= radio_button_tag(:search_context, 'Courses', false) %> Courses
|
||||||
|
<%= radio_button_tag(:search_context, 'Theses', false) %> Theses
|
||||||
|
<%= radio_button_tag(:search_context, 'Projects', false) %> Projects
|
||||||
|
<%= submit_tag("Search") %>
|
||||||
|
<% end %>
|
||||||
@ -2,9 +2,8 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
devise_for :users, path_names: {sign_in: 'log_in', sign_out: 'log out'}
|
devise_for :users, path_names: {sign_in: 'log_in', sign_out: 'log out'}
|
||||||
|
|
||||||
|
|
||||||
get 'login/index'
|
get 'login/index'
|
||||||
get 'tiss_crawler/people_search'
|
get 'tiss_crawler/search'
|
||||||
get 'tiss_crawler/people_show_basic'
|
get 'tiss_crawler/people_show_basic'
|
||||||
get 'tiss_crawler/person_show_detail'
|
get 'tiss_crawler/person_show_detail'
|
||||||
post 'tiss_crawler/person_show_detail'
|
post 'tiss_crawler/person_show_detail'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user