forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhome_controller.rb
More file actions
236 lines (198 loc) · 7.18 KB
/
Copy pathhome_controller.rb
File metadata and controls
236 lines (198 loc) · 7.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# frozen_string_literal: true
class HomeController < ApplicationController
layout :determine_layout
include FairScoreHelper, FederationHelper,MetricsHelper
def index
@analytics = Rails.cache.fetch("ontologies_analytics-#{@subdomain_filter[:acronym].presence || 'all'}-#{Time.now.year}-#{Time.now.month}", expires_in: 2.hours) do
helpers.ontologies_analytics
end
@slices = LinkedData::Client::Models::Slice.all
@anal_ont_names = []
@anal_ont_numbers = []
unless @analytics.empty?
@analytics.first(3).each do |ont, count|
@anal_ont_names << ont
@anal_ont_numbers << count
end
end
end
# Add a new action for the metrics frame
def metrics
@analytics = Rails.cache.fetch("ontologies_analytics-#{@subdomain_filter[:acronym].presence || 'all'}-#{Time.now.year}-#{Time.now.month}", expires_in: 2.hours) do
helpers.ontologies_analytics
end
@metrics = portal_metrics(@analytics)
respond_to do |format|
format.html { render partial: 'metrics', layout: false }
end
end
def set_cookies
cookies.permanent[:cookies_accepted] = params[:cookies] if params[:cookies]
render 'cookies', layout: nil
end
def portal_config
@config = $PORTALS_INSTANCES.select { |x| x[:name].downcase.eql?((params[:portal] || helpers.portal_name).downcase) }.first
if @config && @config[:api]
@portal_config = get_portal_config
@color = @portal_config[:color].present? ? @portal_config[:color] : @config[:color]
@name = @portal_config[:title].present? ? @portal_config[:title] : @config[:name]
else
@portal_config = {}
end
end
def tools
@tools = {
search: {
link: "search/ontologies/content",
icon: "icons/search.svg",
title: t('tools.search.title'),
description: t('tools.search.description'),
},
converter: {
link: "/content_finder",
icon: "icons/settings.svg",
title: t('tools.converter.title'),
description: t('tools.converter.description'),
},
url_checker: {
link: check_resolvability_path,
icon: "check.svg",
title: t('tools.url_checker.title'),
description: t('tools.url_checker.description')
}
}
@title = "#{helpers.portal_name} #{t('layout.footer.tools')}"
render 'tools', layout: 'tool'
end
def all_resources
@conceptid = params[:conceptid]
@ontologyid = params[:ontologyid]
@ontologyversionid = params[:ontologyversionid]
@search = params[:search]
end
def feedback
# Show the header/footer or not
feedback_layout = params[:pop].eql?('true') ? 'popup' : 'ontology'
# We're using a hidden form field to trigger for error checking
# If sim_submit is nil, we know the form hasn't been submitted and we should
# bypass form processing.
if params[:sim_submit].nil?
render 'home/feedback/feedback', layout: feedback_layout
return
end
@tags = []
unless params[:bug].nil? || params[:bug].empty?
@tags << t('home.bug')
end
unless params[:proposition].nil? || params[:proposition].empty?
@tags << t('home.proposition')
end
unless params[:question].nil? || params[:question].empty?
@tags << t('home.question')
end
unless params[:ontology_submissions_request].nil? || params[:ontology_submissions_request].empty?
@tags << t('home.ontology_submissions_request')
end
@errors = []
if params[:name].nil? || params[:name].empty?
@errors << t('home.include_name')
end
if params[:email].nil? || params[:email].length < 1 || !params[:email].match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)
@errors << t('home.include_email')
end
if params[:comment].nil? || params[:comment].empty?
@errors << t('home.include_comment')
end
if using_captcha? && !session[:user]
unless verify_recaptcha
@errors << t('home.fill_text')
end
end
unless @errors.empty?
render 'home/feedback/feedback', layout: feedback_layout
return
end
Notifier.feedback(params[:name], params[:email], params[:comment], params[:location], @tags).deliver_later
if params[:pop].eql?('true')
render 'home/feedback/feedback_complete', layout: 'popup'
else
flash[:notice] = t('home.notice_feedback')
redirect_to_home
end
end
def slice
unless session[:user]
redirect_to "/login?redirect=/slice", alert: t('home.slice.login_required')
return
end
# Skip processing if form not submitted
return render('home/slice/slice') if params[:sim_submit].nil?
@errors = []
# Validation
@errors << t('home.include_email') if invalid_email?(params[:email])
@errors << t('home.include_name') if params[:name].blank?
@errors << t('home.include_slice_name') if params[:slice_name].blank?
@errors << t('home.include_ontologies') if params[:ontologies].blank?
@errors << t('home.include_comment') if params[:comment].blank?
# Re-render form if errors exist
if @errors.any?
return render('home/slice/slice')
end
begin
ontologies_str = params[:ontologies].join(", ")
# Process slice
Notifier.slice(
params[:name],
params[:email],
params[:comment],
params[:slice_name],
ontologies_str
).deliver_later
flash[:notice] = t('home.notice_slice')
redirect_to_home
end
end
def invalid_email?(email)
email.blank? || !email.match?(/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i)
end
def site_config
render json: bp_config_json
end
def feedback_complete; end
def annotator_recommender_form
if params[:submit_button] == "annotator"
redirect_to "/annotator?text=#{helpers.escape(params[:input])}"
elsif params[:submit_button] == "recommender"
redirect_to "/recommender?input=#{helpers.escape(params[:input])}"
end
end
def federation_portals_status
@name = params[:name]
@acronym = params[:acronym]
@key = params[:portal_name]
@checked = params[:checked].eql?('true')
@portal_up = federation_portal_status(portal_name: @key.downcase.to_sym)
render inline: helpers.federation_chip_component(@key, @name, @acronym, @checked, @portal_up)
end
private
# Dr. Musen wants 5 specific groups to appear first, sorted by order of importance.
# Ordering is documented in GitHub: https://github.com/ncbo/bioportal_web_ui/issues/15.
# All other groups come after, with agriculture in the last position.
def organize_groups
# Reference: https://lildude.co.uk/sort-an-array-of-strings-by-severity
acronyms = %w[UMLS OBO_Foundry WHO-FIC CTSA caBIG]
size = @groups.size
@groups.sort_by! { |g| acronyms.find_index(g.acronym[/(UMLS|OBO_Foundry|WHO-FIC|CTSA|caBIG)/]) || size }
others, agriculture = @groups.partition { |g| g.acronym != 'CGIAR' }
@groups = others + agriculture
end
def get_portal_config
portal_config = LinkedData::Client::Models::Ontology.top_level_links(@config[:api])
if portal_config.is_a?(LinkedData::Client::Models::SemanticArtefactCatalog)
portal_config = portal_config.to_hash
else
portal_config = portal_config.to_h
end
portal_config
end
end