From a36796960fe36e4e2133dea7ca2cc38986f94ff5 Mon Sep 17 00:00:00 2001 From: Marco Zeisler Date: Tue, 21 Apr 2020 18:58:48 +0200 Subject: [PATCH] refactoring of "abstract" search controller --- app/controllers/tiss_crawler_controller.rb | 31 ++++++++++++++++--- app/views/courses/index.html.erb | 2 -- .../favorites/favorite_person/index.html.erb | 2 +- app/views/layouts/application.html.erb | 2 +- app/views/people/index.html.erb | 3 -- app/views/projects/index.html.erb | 2 -- app/views/theses/index.html.erb | 2 -- app/views/tiss_crawler/_search_form.html.erb | 0 app/views/tiss_crawler/people_search.html.erb | 5 --- .../tiss_crawler/people_show_basic.html.erb | 2 +- .../tiss_crawler/person_show_detail.html.erb | 1 + app/views/tiss_crawler/search.html.erb | 12 +++++++ config/routes.rb | 3 +- 13 files changed, 44 insertions(+), 23 deletions(-) delete mode 100644 app/views/courses/index.html.erb delete mode 100644 app/views/people/index.html.erb delete mode 100644 app/views/projects/index.html.erb delete mode 100644 app/views/theses/index.html.erb delete mode 100644 app/views/tiss_crawler/_search_form.html.erb delete mode 100644 app/views/tiss_crawler/people_search.html.erb create mode 100644 app/views/tiss_crawler/search.html.erb diff --git a/app/controllers/tiss_crawler_controller.rb b/app/controllers/tiss_crawler_controller.rb index 8482bec..3f5d05a 100644 --- a/app/controllers/tiss_crawler_controller.rb +++ b/app/controllers/tiss_crawler_controller.rb @@ -1,28 +1,51 @@ class TissCrawlerController < ApplicationController + # self designed lib to call the Tiss API require 'tiss/tiss_crawler' - def index - end + def search + # 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 def people_show_basic params[:api] = '/api/person/v22/psuche' params[:search_parameter] = 'q' + puts params[:search_context] + + # TissCrawler performs general search over the available people @people = TissCrawler.search(params) end def person_show_detail params[:api] = '/api/person/v22/id/' + + # TissCrawler fetches the person's detail information @person = TissCrawler.get_details(params) + # Host is needed for image rendering @host = TissCrawler.get_host end def person_add_to_fav 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 diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb deleted file mode 100644 index 1d072e8..0000000 --- a/app/views/courses/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Courses#index

-

Find me in app/views/courses/index.html.erb

diff --git a/app/views/favorites/favorite_person/index.html.erb b/app/views/favorites/favorite_person/index.html.erb index 604245e..3e21932 100644 --- a/app/views/favorites/favorite_person/index.html.erb +++ b/app/views/favorites/favorite_person/index.html.erb @@ -2,5 +2,5 @@

For now only the tiss_ids are stored and shown

<% @favoritePeople.each do |favPerson| %> - Tiss_id: <%= favPerson.tiss_id %> +

Tiss_id: <%= favPerson.tiss_id %>

<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5cfbd1c..d7c5d1d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -21,7 +21,7 @@
<%= 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 'Projects', projects_index_path %> <%#= link_to 'Theses', theses_index_path %> diff --git a/app/views/people/index.html.erb b/app/views/people/index.html.erb deleted file mode 100644 index 575bbf8..0000000 --- a/app/views/people/index.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

People#index

-

Find me in app/views/people/index.html.erb

- diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb deleted file mode 100644 index 3b2a90a..0000000 --- a/app/views/projects/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Projects#index

-

Find me in app/views/projects/index.html.erb

diff --git a/app/views/theses/index.html.erb b/app/views/theses/index.html.erb deleted file mode 100644 index 335b5cb..0000000 --- a/app/views/theses/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Theses#index

-

Find me in app/views/theses/index.html.erb

diff --git a/app/views/tiss_crawler/_search_form.html.erb b/app/views/tiss_crawler/_search_form.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/tiss_crawler/people_search.html.erb b/app/views/tiss_crawler/people_search.html.erb deleted file mode 100644 index 0a98dc3..0000000 --- a/app/views/tiss_crawler/people_search.html.erb +++ /dev/null @@ -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 %> \ No newline at end of file diff --git a/app/views/tiss_crawler/people_show_basic.html.erb b/app/views/tiss_crawler/people_show_basic.html.erb index 4420e47..3b35b64 100644 --- a/app/views/tiss_crawler/people_show_basic.html.erb +++ b/app/views/tiss_crawler/people_show_basic.html.erb @@ -5,6 +5,6 @@ This is the result for your basic people search: <%= person['first_name'] %> <%= person['last_name'] %> <%= 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'] %>

<% end %> diff --git a/app/views/tiss_crawler/person_show_detail.html.erb b/app/views/tiss_crawler/person_show_detail.html.erb index b929ed8..54b2a06 100644 --- a/app/views/tiss_crawler/person_show_detail.html.erb +++ b/app/views/tiss_crawler/person_show_detail.html.erb @@ -11,4 +11,5 @@ Chosen person in detail view:

Other mails: <%= @person['other_emails'] %>

Main addresses: <%= @person['main_addresses'] %>

+ <%= button_to 'Add to favorites', action: :person_add_to_fav, tiss_id: @person['tiss_id'] %> <% end %> \ No newline at end of file diff --git a/app/views/tiss_crawler/search.html.erb b/app/views/tiss_crawler/search.html.erb new file mode 100644 index 0000000..37ab496 --- /dev/null +++ b/app/views/tiss_crawler/search.html.erb @@ -0,0 +1,12 @@ +

Search through @TU Vienna Database

+

Only People Search is working right now

+ +<%= 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 %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 812aed1..350bec2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,9 +2,8 @@ Rails.application.routes.draw do devise_for :users, path_names: {sign_in: 'log_in', sign_out: 'log out'} - get 'login/index' - get 'tiss_crawler/people_search' + get 'tiss_crawler/search' get 'tiss_crawler/people_show_basic' get 'tiss_crawler/person_show_detail' post 'tiss_crawler/person_show_detail'