Skip to content

Commit

Permalink
Add tags field
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal authored Jan 28, 2023
1 parent 2421b67 commit 989902d
Showing 1 changed file with 75 additions and 32 deletions.
107 changes: 75 additions & 32 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

class HomeController < ApplicationController
layout :determine_layout

Expand Down Expand Up @@ -44,13 +42,29 @@ def index

# Calculate BioPortal summary statistics
@ont_count = @ontologies.length
@cls_count = LinkedData::Client::Models::Metrics.all.map { |m| m.classes.to_i }.sum
@cls_count = LinkedData::Client::Models::Metrics.all.map {|m| m.classes.to_i}.sum

@individuals_count = LinkedData::Client::Models::Metrics.all.map {|m| m.individuals.to_i}.sum
if $RESOURCE_INDEX_DISABLED == false
begin
@resources = LinkedData::Client::ResourceIndex.resources # application_controller
@ri_resources = @resources.length
@ri_record_count = @resources.map {|r| r.count}.sum
rescue
@resources = []
@ri_resources = 0
@ri_record_count = 0
end
@ri_stats = LinkedData::Client::ResourceIndex.annotation_counts
@direct_annotations = @ri_stats[:total][:direct]
@direct_expanded_annotations = @ri_stats[:total][:ancestors]
end

@prop_count = 36286
@map_count = total_mapping_count
@analytics = LinkedData::Client::Analytics.last_month

@ontology_names = @ontologies.map { |ont| ["#{ont.name} (#{ont.acronym})", ont.acronym] }
@ontology_names = @ontologies.map{ |ont| ["#{ont.name} (#{ont.acronym})", ont.acronym] }

@anal_ont_names = {}
@anal_ont_numbers = []
Expand All @@ -68,10 +82,22 @@ def render_layout_partial
render partial: "layouts/#{partial}"
end

def release
redirect_to :controller => 'home', :action => 'help'
end

def help
# Show the header/footer or not
layout = params[:pop].eql?('true') ? 'popup' : 'ontology'
render layout: layout
layout = params[:pop].eql?("true") ? "popup" : "ontology"
render :layout => layout
end

def recommender

end

def annotate

end

def all_resources
Expand All @@ -83,30 +109,44 @@ def all_resources

def feedback
# Show the header/footer or not
feedback_layout = params[:pop].eql?('true') ? 'popup' : 'ontology'
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 layout: feedback_layout
render :layout => feedback_layout
return
end

@tags = []
if not params[:bug].nil? || params[:bug].empty?
@tags << "Bug"
end
if not params[:proposition].nil? || params[:proposition].empty?
@tags << "Proposition"
end
if not params[:question].nil? || params[:question].empty?
@tags << "Question"
end
if not params[:bug].nil? || params[:bug].empty?
@tags << "ontology-submissions-request"
end

@errors = []

if params[:name].nil? || params[:name].empty?
@errors << 'Please include your name'
@errors << "Please include your 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 << 'Please include your email'
if params[:email].nil? || params[:email].length <1 || !params[:email].match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)
@errors << "Please include your email"
end
if params[:comment].nil? || params[:comment].empty?
@errors << 'Please include your comment'
@errors << "Please include your comment"
end
if using_captcha? && !session[:user]
unless verify_recaptcha
@errors << 'Please fill in the proper text from the supplied image'
if !verify_recaptcha
@errors << "Please fill in the proper text from the supplied image"
end
end

Expand All @@ -115,51 +155,53 @@ def feedback
return
end

Notifier.feedback(params[:name], params[:email], params[:comment], params[:location]).deliver_now
Notifier.feedback(params[:name],params[:email],params[:comment],params[:location], @tags).deliver_now

if params[:pop].eql?('true')
render 'feedback_complete', layout: 'popup'
if params[:pop].eql?("true")
render "feedback_complete", layout: "popup"
else
flash[:notice] = 'Feedback has been sent'
flash[:notice]="Feedback has been sent"
redirect_to_home
end
end

def user_intention_survey
render partial: 'user_intention_survey', layout: false
render :partial => "user_intention_survey", :layout => false
end

def site_config
render json: bp_config_json
end

def account
@title = 'Account Information'
@title = "Account Information"
if session[:user].nil?
redirect_to controller: 'login', action: 'index', redirect: '/account'
redirect_to :controller => 'login', :action => 'index', :redirect => "/account"
return
end

@user = LinkedData::Client::Models::User.get(session[:user].id, include: 'all')
@user = LinkedData::Client::Models::User.get(session[:user].id, include: "all")

@user_ontologies = @user.customOntology
@user_ontologies ||= []

onts = LinkedData::Client::Models::Ontology.all
@admin_ontologies = onts.select { |o| o.administeredBy.include? @user.id }
onts = LinkedData::Client::Models::Ontology.all;
@admin_ontologies = onts.select {|o| o.administeredBy.include? @user.id }

projects = LinkedData::Client::Models::Project.all
@user_projects = projects.select { |p| p.creator.include? @user.id }
projects = LinkedData::Client::Models::Project.all;
@user_projects = projects.select {|p| p.creator.include? @user.id }

render 'users/show'
render "users/show"
end

def feedback_complete; end
def feedback_complete
end

def validate_ontology_file_show; end
def validate_ontology_file_show
end

def validate_ontology_file
response = LinkedData::Client::HTTP.post('/validate_ontology_file', ontology_file: params[:ontology_file])
response = LinkedData::Client::HTTP.post("/validate_ontology_file", ontology_file: params[:ontology_file])
@process_id = response.process_id
end

Expand All @@ -170,11 +212,12 @@ def validate_ontology_file
# 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]
acronyms = ["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' }
others, agriculture = @groups.partition { |g| g.acronym != "CGIAR" }
@groups = others + agriculture
end

end

0 comments on commit 989902d

Please sign in to comment.