Merge branch 'personal_annotations' into 'master'

Personal annotations

See merge request kranklyboy/tiss2go!1
This commit is contained in:
Marco Zeisler 2020-06-04 23:09:44 +00:00
commit 8cd87ce642
32 changed files with 216 additions and 61 deletions

View File

@ -3,8 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.0'
# gem 'nokogiri', require: false
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '6.0.2.1'
# Use sqlite3 as the database for Active Record
@ -39,6 +37,9 @@ gem 'devise-encryptable', '0.2.0'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
# for composite primary keys
gem 'composite_primary_keys'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

View File

@ -73,6 +73,8 @@ GEM
regexp_parser (~> 1.5)
xpath (~> 3.2)
childprocess (3.0.0)
composite_primary_keys (12.0.2)
activerecord (~> 6.0.0)
concurrent-ruby (1.1.6)
crass (1.0.6)
devise (4.7.1)
@ -84,7 +86,7 @@ GEM
devise-encryptable (0.2.0)
devise (>= 2.1.0)
erubi (1.9.0)
ffi (1.12.2)
ffi (1.12.2-x64-mingw32)
globalid (0.4.2)
activesupport (>= 4.2.0)
httparty (0.18.0)
@ -105,11 +107,11 @@ GEM
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.1009)
mimemagic (0.3.4)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.0)
msgpack (1.3.3)
msgpack (1.3.3-x64-mingw32)
multi_xml (0.6.0)
nio4r (2.5.2)
nokogiri (1.10.9)
@ -157,7 +159,7 @@ GEM
rubyzip (2.3.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.2.1)
sassc (2.2.1-x64-mingw32)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
@ -184,6 +186,8 @@ GEM
turbolinks-source (5.2.0)
tzinfo (1.2.7)
thread_safe (~> 0.1)
tzinfo-data (1.2019.3)
tzinfo (>= 1.0.0)
warden (1.2.8)
rack (>= 2.0.6)
web-console (4.0.1)
@ -199,20 +203,21 @@ GEM
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
websocket-driver (0.7.1)
websocket-driver (0.7.2)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.3.0)
PLATFORMS
ruby
x64-mingw32
DEPENDENCIES
bootsnap (>= 1.4.2)
byebug
capybara (>= 2.15)
composite_primary_keys
devise (= 4.7.1)
devise-encryptable (= 0.2.0)
httparty (= 0.18.0)
@ -232,4 +237,4 @@ RUBY VERSION
ruby 2.7.0p0
BUNDLED WITH
2.1.2
2.1.4

View File

@ -119,3 +119,18 @@ input[type=text], input[type=url], input[type=email], input[type=password], inpu
font-size: 16px;
border: 1px solid #bbb;
}
input {
background-color: white;
border: solid #3F51B5;
border-width: 1px;
color: #3F51B5;
padding: 3px 3px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-right: 0.1em;
font-weight: bolder;
border-radius: 4px;
}

View File

@ -40,7 +40,10 @@
display: flex;
:nth-child(2) {
color: darkred;
-webkit-text-fill-color: #ffffff;
background-color: #ff1919;
border-radius: 4px;
border-color: #ff1919;
}
}

View File

@ -0,0 +1,17 @@
@media print {
nav, input, button, .favNav {
display: none;
}
@page {
size: A4;
}
body {
counter-reset: chapternum figurenum;
font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif;
line-height: 1.5;
font-size: 11pt;
}
}

View File

@ -1,3 +1,8 @@
// Place all the styles related to the tiss_crawler controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
.annotationField {
width: 99.5%;
height: 8em;
}

View File

@ -26,6 +26,8 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController
params[:semester] = regex[:semester]
end
@personal_annotation = get_stored_annotation FavoriteCourse, {number: params[:number]}
puts params
# TissCrawler fetches the course's detail information
@ -82,4 +84,8 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController
redirect_back(fallback_location: search)
end
def add_annotation
store_annotation FavoriteCourse, 'Course', {number: params[:id]}
end
end

View File

@ -22,6 +22,8 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
params[:api] = '/api/person/v22/id/'
params[:tiss_id] = params[:tiss_id]
@personal_annotation = get_stored_annotation FavoritePerson, {tiss_id: params[:tiss_id]}
puts params
# TissCrawler fetches the person's detail information
@person = TissCrawler.get_details(params)
@ -35,12 +37,12 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
@person = TissCrawler.get_details(params)
# create stores the object to the db after creation
favorite_hash = { tiss_id: @person['tiss_id'],
# the user who is currently active
user_id: current_user.id,
first_name: @person['first_name'],
last_name: @person['last_name'],
picture_uri: @person['picture_uri'] }
favorite_hash = {tiss_id: @person['tiss_id'],
# the user who is currently active
user_id: current_user.id,
first_name: @person['first_name'],
last_name: @person['last_name'],
picture_uri: @person['picture_uri']}
if FavoritePerson.create(favorite_hash).valid?
FavoritePerson.create(favorite_hash)
flash[:alert] = 'Person added to your favorites!'
@ -50,4 +52,8 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
redirect_back(fallback_location: crawlers_tiss_crawler_search_path)
end
def add_annotation
store_annotation FavoritePerson, 'Person', {tiss_id: params[:id]}
end
end

View File

@ -21,6 +21,8 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
@id = params[:id]
@personal_annotation = get_stored_annotation FavoriteProject, {id: @id}
puts params
# TissCrawler fetches the project's detail information
@project = TissCrawler.get_project_details(params)
@ -34,9 +36,9 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
@project = TissCrawler.get_project_details(params)
# create stores the object to the db after creation
favorite_hash = {id: params[:id],
favorite_hash = {id: [params[:id], current_user.id],
# the user who is currently active
user_id: current_user.id,
# user_id: current_user.id,
title: @project['titleDe']}
if FavoriteProject.create(favorite_hash).valid?
FavoriteProject.create(favorite_hash)
@ -46,4 +48,8 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController
end
redirect_back(fallback_location: search)
end
def add_annotation
store_annotation FavoriteProject, 'Project', {id: params[:id]}
end
end

View File

@ -21,6 +21,8 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
@id = params[:id]
@personal_annotation = get_stored_annotation FavoriteThesis, {id: @id}
puts params
# TissCrawler fetches the thesis' detail information
@thesis = TissCrawler.get_thesis_details(params)
@ -34,9 +36,9 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
@thesis = TissCrawler.get_thesis_details(params)
# create stores the object to the db after creation
favorite_hash = {id: params[:id],
favorite_hash = {id: [params[:id], current_user.id],
# the user who is currently active
user_id: current_user.id,
# user_id: current_user.id,
title: @thesis['title']['de']}
if FavoriteThesis.create(favorite_hash).valid?
FavoriteThesis.create(favorite_hash)
@ -46,4 +48,8 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController
end
redirect_back(fallback_location: search)
end
def add_annotation
store_annotation FavoriteThesis, 'Thesis', {id: params[:id]}
end
end

View File

@ -34,4 +34,31 @@ class Crawlers::TissCrawlerController < ApplicationController
def add_to_fav
end
def add_annotation
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
end

View File

@ -1,2 +1,9 @@
module Crawlers::TissCrawlerHelper
def render_personal_annotations(id, personal_annotation)
render :partial => "crawlers/personal_annotations",
:locals => {
:cur_id => id,
:personal_annotation => personal_annotation
}
end
end

View File

@ -1,4 +1,6 @@
class FavoriteCourse < ApplicationRecord
self.primary_keys = :id, :user_id
validates :title, :semester, :number, presence: true
validates :semester, :number, uniqueness: {scope: [:semester, :number]}
validates :semester, :number, uniqueness: {scope: [:semester, :number, :user_id]}
end

View File

@ -1,5 +1,5 @@
class FavoritePerson < ApplicationRecord
self.primary_key = 'tiss_id'
self.primary_keys = :tiss_id, :user_id
validates :tiss_id, uniqueness: true
validates :tiss_id, uniqueness: { scope: [:user_id] }
end

View File

@ -1,5 +1,5 @@
class FavoriteProject < ApplicationRecord
self.primary_key = 'id'
self.primary_keys = :id, :user_id
validates :id, uniqueness: true
validates :id, :user_id, uniqueness: {scope: [:id, :user_id]}
end

View File

@ -1,5 +1,5 @@
class FavoriteThesis < ApplicationRecord
self.primary_key = 'id'
self.primary_keys = :id, :user_id
validates :id, uniqueness: true
validates :id, :user_id, uniqueness: {scope: [:id, :user_id]}
end

View File

@ -0,0 +1,13 @@
<%= form_tag "add_annotation", :id => "id" do -%>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<p>
Add an annotation:
</p>
<p>
<%= text_area_tag 'body', personal_annotation, class: 'annotationField' %>
<%= hidden_field_tag :id , cur_id %>
</p>
<p>
<%= submit_tag "Save annotation" %>
</p>
<% end -%>

View File

@ -1,6 +1,8 @@
<% if @course != nil %>
<%-# TODO parse more fields and style them appropriately -%>
<h2><%= @course['title']['de'] %></h2>
<h2>Course: <%= @course['title']['de'] %></h2>
<%= button_to "PRINT", '#', onclick: "print()" %>
<h5><%= @course['courseType'] %> <%= @course['semesterCode'] %>, <%= @course['weeklyHours'] %> SWS, <%= @course['instituteCode'] %> <%= @course['instituteName']['de'] %> </h5>
<%= button_to 'Add to favorites', action: :add_to_fav, number: @course['courseNumber'], semester: @course['semesterCode'] %>
<% if @lecturers_names != nil %>
@ -13,4 +15,6 @@
<h3>Inhalt</h3>
<%= raw @course['objective']['de'] %>
<% end %>
<%= render_personal_annotations @course['courseNumber'], @personal_annotation %>
<% end %>

View File

@ -1,5 +1,7 @@
<% if @person != nil %>
<h2><%= @person['first_name'] %> <%= @person['last_name'] %></h2>
<h2>Person: <%= @person['first_name'] %> <%= @person['last_name'] %></h2>
<%= button_to "PRINT", '#', onclick: "print()" %>
<div class="profile-picture">
<% if @person['picture_uri'] != nil %>
<%= image_tag @host + @person['picture_uri'] %>
@ -14,8 +16,12 @@
<p>Other E-Mails: <%= @person['other_emails'] %></p>
<% end %>
<% if @person['main_addresses'] != nil %>
<p>Address: <%= @person['main_addresses'][0]['street'] %>, <%= @person['main_addresses'][0]['zip_code'] %> <%= @person['main_addresses'][0]['city'] %></p>
<p>Address: <%= @person['main_addresses'][0]['street'] %>
, <%= @person['main_addresses'][0]['zip_code'] %> <%= @person['main_addresses'][0]['city'] %></p>
<% end %>
<!-- <p>Employee: <%#= @person.employee %></p>-->
<%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'] %>
<!-- <p>Employee: <%#= @person.employee %></p>-->
<%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %>
<%= render_personal_annotations @person['tiss_id'], @personal_annotation %>
<% end %>

View File

@ -1,5 +1,7 @@
<% if @project != nil %>
<h2><%= @project['titleDe'] %></h2>
<h2>Project: <%= @project['titleDe'] %></h2>
<%= button_to "PRINT", '#', onclick: "print()" %>
<h5><%= @project['contractBegin'] %> - <%= @project['contractEnd'] %></h5>
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @project['titleDe'] %>
<% if @project['abstractDe'] != nil %>
@ -11,4 +13,7 @@
<p><%= raw @project['abstractEn'] %></p>
<% end %>
<% end %>
<%= render_personal_annotations @id, @personal_annotation %>
<% end %>

View File

@ -1,5 +1,7 @@
<% if @thesis != nil %>
<h2><%= @thesis['title']['de'] %></h2>
<h2>Thesis: <%= @thesis['title']['de'] %></h2>
<%= button_to "PRINT", '#', onclick: "print()" %>
<h5><%= @thesis['thesisType'] %>, <%= @thesis['instituteCode'] %> <%= @thesis['instituteName']['de'] %></h5>
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @thesis['title']['de'] %>
<% if @thesis['advisor'] != nil %>
@ -10,4 +12,6 @@
<h4>Assistant</h4>
<p><%= @thesis['assistant']['familyName'] %> <%= @thesis['assistant']['givenName'] %></p>
<% end %>
<%= render_personal_annotations @id, @personal_annotation %>
<% end %>

View File

@ -3,4 +3,6 @@
<%= link_to 'Courses', favorites_courses_url %>
<%= link_to 'Theses', favorites_theses_url %>
<%= link_to 'Projects', favorites_projects_url %>
<%= link_to "PRINT", '#', onclick: "print()" %>
</div>

View File

@ -43,6 +43,7 @@
</td>
<td></td>
<td></td>
<td></td>
</tr>
<% end %>
</table>

View File

@ -25,6 +25,7 @@
<%= button_to 'Delete', {:action => "delete_project", :id => project['id']}, :method => 'delete' %>
</div>
</td>
<td></td>
</tr>
<% end %>
</table>

View File

@ -26,6 +26,7 @@
<%= button_to 'Delete', {:action => "delete_thesis", :id => thesis['id']}, :method => 'delete' %>
</div>
</td>
<td></td>
</tr>
<% end %>
</table>

View File

@ -5,7 +5,9 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'print', media: 'print' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
@ -43,4 +45,5 @@
</main>
</body>
</html>

View File

@ -13,6 +13,7 @@ Rails.application.routes.draw do
post 'show_detail'
get 'add_to_fav'
post 'add_to_fav'
post 'add_annotation'
end
namespace :courses_crawler do
@ -21,6 +22,7 @@ Rails.application.routes.draw do
post 'show_detail'
get 'add_to_fav'
post 'add_to_fav'
post 'add_annotation'
end
namespace :theses_crawler do
@ -29,6 +31,7 @@ Rails.application.routes.draw do
post 'show_detail'
get 'add_to_fav'
post 'add_to_fav'
post 'add_annotation'
end
namespace :projects_crawler do
@ -37,6 +40,7 @@ Rails.application.routes.draw do
post 'show_detail'
get 'add_to_fav'
post 'add_to_fav'
post 'add_annotation'
end
end

View File

@ -1,14 +1,13 @@
class CreateFavoritePeople < ActiveRecord::Migration[6.0]
def change
create_table :favorite_people, id: false do |t|
create_table :favorite_people, primary_key: [:tiss_id, :user_id] do |t|
t.integer :tiss_id, null: false
t.integer :user_id, null: false
t.belongs_to :user
t.string :first_name
t.string :last_name
t.string :picture_uri
t.string :personal_annotation
t.timestamps
end
add_index :favorite_people, :tiss_id, unique: true
end
end

View File

@ -1,13 +1,14 @@
class CreateFavoriteCourses < ActiveRecord::Migration[6.0]
def change
create_table :favorite_courses do |t|
create_table :favorite_courses , primary_key: [:id, :user_id] do |t|
t.integer :id
t.belongs_to :user
t.string :number, null: false
t.string :semester, null: false
t.string :title, null: false
t.integer :user_id, null: false
t.string :personal_annotation
t.timestamps
end
add_index :favorite_courses, [:number, :semester], unique: true
end
end

View File

@ -1,12 +1,12 @@
class CreateFavoriteTheses < ActiveRecord::Migration[6.0]
def change
create_table :favorite_theses, id: false do |t|
create_table :favorite_theses, primary_key: [:id, :user_id] do |t|
t.integer :id, null: false
t.integer :user_id, null: false
t.belongs_to :user
t.string :title
t.string :personal_annotation
t.timestamps
end
add_index :favorite_theses, :id, unique: true
end
end

View File

@ -1,12 +1,12 @@
class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
def change
create_table :favorite_projects, id: false do |t|
create_table :favorite_projects, primary_key: [:id, :user_id] do |t|
t.integer :id, null: false
t.integer :user_id, null: false
t.belongs_to :user
t.string :title
t.string :personal_annotation
t.timestamps
end
add_index :favorite_projects, :id, unique: true
end
end

View File

@ -12,43 +12,48 @@
ActiveRecord::Schema.define(version: 2020_05_29_081537) do
create_table "favorite_courses", force: :cascade do |t|
create_table "favorite_courses", primary_key: ["id", "user_id"], force: :cascade do |t|
t.integer "id"
t.integer "user_id"
t.string "number", null: false
t.string "semester", null: false
t.string "title", null: false
t.integer "user_id", null: false
t.string "personal_annotation"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["number", "semester"], name: "index_favorite_courses_on_number_and_semester", unique: true
t.index ["user_id"], name: "index_favorite_courses_on_user_id"
end
create_table "favorite_people", id: false, force: :cascade do |t|
create_table "favorite_people", primary_key: ["tiss_id", "user_id"], force: :cascade do |t|
t.integer "tiss_id", null: false
t.integer "user_id", null: false
t.integer "user_id"
t.string "first_name"
t.string "last_name"
t.string "picture_uri"
t.string "personal_annotation"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true
t.index ["user_id"], name: "index_favorite_people_on_user_id"
end
create_table "favorite_projects", id: false, force: :cascade do |t|
create_table "favorite_projects", primary_key: ["id", "user_id"], force: :cascade do |t|
t.integer "id", null: false
t.integer "user_id", null: false
t.integer "user_id"
t.string "title"
t.string "personal_annotation"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["id"], name: "index_favorite_projects_on_id", unique: true
t.index ["user_id"], name: "index_favorite_projects_on_user_id"
end
create_table "favorite_theses", id: false, force: :cascade do |t|
create_table "favorite_theses", primary_key: ["id", "user_id"], force: :cascade do |t|
t.integer "id", null: false
t.integer "user_id", null: false
t.integer "user_id"
t.string "title"
t.string "personal_annotation"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["id"], name: "index_favorite_theses_on_id", unique: true
t.index ["user_id"], name: "index_favorite_theses_on_user_id"
end
create_table "users", force: :cascade do |t|