store and display favorite person by tiss_id

This commit is contained in:
Marco Zeisler 2020-04-21 18:06:07 +02:00
parent c32819d819
commit fbfc12e096
31 changed files with 153 additions and 88 deletions

View File

@ -0,0 +1,3 @@
// Place all the styles related to the favorites controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the favorites/favorite_person controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the favorites/favorite_person controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/

View File

@ -1,3 +0,0 @@
class CoursesController < ApplicationController
end

View File

@ -0,0 +1,5 @@
class Favorites::FavoritePersonController < ApplicationController
def index
@favoritePeople = FavoritePerson.all
end
end

View File

@ -1,3 +0,0 @@
class PeopleController < ApplicationController
end

View File

@ -1,3 +0,0 @@
class ProjectsController < ApplicationController
end

View File

@ -1,3 +0,0 @@
class ThesesController < ApplicationController
end

View File

@ -9,15 +9,20 @@ class TissCrawlerController < ApplicationController
end end
def people_show_basic def people_show_basic
result = TissCrawler.search(params) params[:api] = '/api/person/v22/psuche'
$people = result.map { |person| Tiss::Person.new(person) } params[:search_parameter] = 'q'
@people = $people @people = TissCrawler.search(params)
end end
def people_show_detail def person_show_detail
people = $people params[:api] = '/api/person/v22/id/'
index = params[:index] @person = TissCrawler.get_details(params)
@person = people[Integer(index)] @host = TissCrawler.get_host
end
def person_add_to_fav
puts params[:tiss_id]
person = FavoritePerson.create(tiss_id: params[:tiss_id])
end end
end end

View File

@ -0,0 +1,2 @@
module Favorite::FavoritePersonHelper
end

View File

@ -0,0 +1,2 @@
module FavoriteHelper
end

View File

@ -0,0 +1,2 @@
module Favorites::FavoritePersonHelper
end

View File

@ -0,0 +1,3 @@
class FavoritePerson < ApplicationRecord
self.primary_key = "tiss_id"
end

View File

@ -1,43 +0,0 @@
module Tiss
class Base
def base_uri
'https://tiss.tuwien.ac.at/'
end
def initialize(args = {})
args.each do |name, value|
attr_name = name.to_s.underscore
send("#{attr_name}=", value) if respond_to?("#{attr_name}=")
end
end
end
class Person < Base
# tiss json properties
attr_accessor :tiss_id,
:oid,
:old_tiss_ids,
:first_name,
:last_name,
:gender,
:pseudoperson,
:preceding_titles,
:postpositioned_titles,
:orcid,
:card_uri,
:picture_uri,
:main_phone_number,
:main_email,
:other_emails,
:main_addresses,
:employee
def initialize(args = {})
super(args)
end
end
end

View File

@ -0,0 +1,6 @@
<h1>Your favorite perople listed here ...</h1>
<p>For now only the tiss_ids are stored and shown</p>
<% @favoritePeople.each do |favPerson| %>
Tiss_id: <%= favPerson.tiss_id %>
<% end %>

View File

@ -21,8 +21,8 @@
<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 'People', tiss_crawler_people_search_path %> <%= link_to 'Search', tiss_crawler_people_search_path %>
<%#= link_to 'Courses', courses_index_path %> <%= 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 %>
</div> </div>

View File

@ -1,7 +1,4 @@
<%= form_tag('/tiss_crawler/people_show_basic', :method => "get") do %> <%= form_tag('/tiss_crawler/people_show_basic', :method => "get") do %>
<%= hidden_field_tag(:context, 'People') %>
<%= hidden_field_tag(:api, '/api/person/v22/psuche') %>
<%= hidden_field_tag(:search_parameter, 'q') %>
<%= label_tag(:search_term, "Search for people @TU Vienna:") %> <%= label_tag(:search_term, "Search for people @TU Vienna:") %>
<%= text_field_tag(:search_term) %> <%= text_field_tag(:search_term) %>
<%= submit_tag("Search") %> <%= submit_tag("Search") %>

View File

@ -2,8 +2,9 @@ This is the result for your basic people search:
<% @people.each_with_index do |person, index| %> <% @people.each_with_index do |person, index| %>
<p> <p>
<%= person.first_name %> <%= person['first_name'] %>
<%= person.last_name %> <%= person['last_name'] %>
<%= button_to 'Details', action: :people_show_detail, index: index %> <%= 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'] %>
</p> </p>
<% end %> <% end %>

View File

@ -1,14 +0,0 @@
Chosen person in detail view:
<% if @person != nil %>
<% if @person.picture_uri != nil %>
<%= image_tag @person.base_uri + @person.picture_uri %>
<% end %>
<p><%= @person.preceding_titles %> <%= @person.first_name %> <%= @person.last_name %>,
<%= @person.gender %> <%= @person.postpositioned_titles %></p>
<p>Phone: <%= @person.main_phone_number %></p>
<p>Mail: <%= @person.main_email %></p>
<p>Other mails: <%= @person.other_emails %></p>
<p>Main addresses: <%= @person.main_addresses %></p>
<!-- <p>Employee: <%#= @person.employee %></p>-->
<% end %>

View File

@ -0,0 +1,14 @@
Chosen person in detail view:
<% if @person != nil %>
<% if @person['picture_uri'] != nil %>
<%= image_tag @host + @person['picture_uri'] %>
<% end %>
<p><%= @person['preceding_titles'] %> <%= @person['first_name'] %> <%= @person['last_name'] %>,
<%= @person['gender'] %> <%= @person['postpositioned_titles'] %></p>
<p>Phone: <%= @person['main_phone_number'] %></p>
<p>Mail: <%= @person['main_email'] %></p>
<p>Other mails: <%= @person['other_emails'] %></p>
<p>Main addresses: <%= @person['main_addresses'] %></p>
<!-- <p>Employee: <%#= @person.employee %></p>-->
<% end %>

View File

@ -1,12 +1,19 @@
Rails.application.routes.draw do 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/people_search'
get 'tiss_crawler/people_show_basic' get 'tiss_crawler/people_show_basic'
get 'tiss_crawler/people_show_detail' get 'tiss_crawler/person_show_detail'
post 'tiss_crawler/people_show_detail' post 'tiss_crawler/person_show_detail'
get 'tiss_crawler/person_add_to_fav'
post 'tiss_crawler/person_add_to_fav'
namespace :favorites do
get 'favorite_person/index'
end
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root 'login#index' root 'login#index'

View File

@ -0,0 +1,9 @@
class CreateFavoritePeople < ActiveRecord::Migration[6.0]
def change
create_table :favorite_people do |t|
t.string :tiss_id
t.timestamps
end
end
end

View File

@ -10,7 +10,13 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_14_101256) do ActiveRecord::Schema.define(version: 2020_04_21_152314) do
create_table "favorite_people", force: :cascade do |t|
t.string "tiss_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false

View File

@ -15,9 +15,18 @@ class TissCrawler
JSON.parse(response.body)["results"] JSON.parse(response.body)["results"]
end end
def self.get_details(params)
api = params[:api]
id = params[:tiss_id]
url = $host + api + id
puts(url)
def details response = HTTParty.get(url)
JSON.parse(response.body)
end
def self.get_host
$host
end end
end end

View File

@ -0,0 +1,9 @@
require 'test_helper'
class Favorite::FavoritePersonControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get favorite_favorite_person_index_url
assert_response :success
end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class FavoriteControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,9 @@
require 'test_helper'
class Favorites::FavoritePersonControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get favorites_favorite_person_index_url
assert_response :success
end
end

7
test/fixtures/favorite_people.yml vendored Normal file
View File

@ -0,0 +1,7 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
tiss_id: MyString
two:
tiss_id: MyString

11
test/fixtures/people.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@ -0,0 +1,7 @@
require 'test_helper'
class FavoritePersonTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class PersonTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end