Skip to content

Commit

Permalink
tmp comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Mar 21, 2023
1 parent 276021a commit 33060be
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 147 deletions.
185 changes: 168 additions & 17 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OntologiesController < ApplicationController
helper :concepts
helper :fair_score

layout :determine_layout
layout 'ontology'

before_action :authorize_and_redirect, :only => [:edit, :update, :create, :new]
before_action :submission_metadata, only: [:show]
Expand Down Expand Up @@ -170,21 +170,179 @@ def index
filtered_ontologies = @ontologies

filtered_ontologies = search(filtered_ontologies, params[:search]) unless (params[:search].nil? || params[:search].empty?)

puts "params format ................."
puts params[:format]
filtered_ontologies = format_filter(filtered_ontologies, params[:format]) unless params[:format].nil?


filtered_ontologies = filter_ontologies_by(filtered_ontologies, :categories)
#filtered_ontologies, no_filter = filter_ontologies_by(filtered_ontologies, no_filter, :groups)
#filtered_ontologies, no_filter = filter_ontologies_by(filtered_ontologies, no_filter, :naturalLanguage)
#filtered_ontologies, no_filter = filter_ontologies_by(filtered_ontologies, no_filter, :hasFormalityLevel)
#filtered_ontologies, no_filter = filter_ontologies_by(filtered_ontologies, no_filter, :isOfType)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :groups)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :naturalLanguage)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :hasFormalityLevel)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :isOfType)

@ontologies = filtered_ontologies

render 'browse'
end

def ontologies_filter
@app_name = 'FacetedBrowsing'
@app_dir = '/browse'
@base_path = @app_dir
ontologies = LinkedData::Client::Models::Ontology.all(
include: LinkedData::Client::Models::Ontology.include_params + ',viewOf', include_views: true, display_context: false)
ontologies_hash = Hash[ontologies.map { |o| [o.id, o] }]
@admin = session[:user] ? session[:user].admin? : false
@development = Rails.env.development?

# We could get naturalLanguages, isOfType and formalityLevels from the API, but for performance we are storing it in config/bioportal_config_production.rb
#@metadata = submission_metadata

# The attributes used when retrieving the submission. We are not retrieving all attributes to be faster
browse_attributes = 'ontology,acronym,submissionStatus,description,pullLocation,creationDate,released,name,naturalLanguage,hasOntologyLanguage,hasFormalityLevel,isOfType,contact'
submissions = LinkedData::Client::Models::OntologySubmission.all(include_views: true, display_links: false,
display_context: false, include: browse_attributes)
submissions_map = Hash[submissions.map { |sub| [sub.ontology.acronym, sub] }]

@categories = LinkedData::Client::Models::Category.all(display_links: false, display_context: false)
@categories_hash = Hash[@categories.map { |c| [c.id, c] }]

@groups = LinkedData::Client::Models::Group.all(display_links: false, display_context: false)
@groups_hash = Hash[@groups.map { |g| [g.id, g] }]

analytics = LinkedData::Client::Analytics.last_month
@analytics = Hash[analytics.onts.map { |o| [o[:ont].to_s, o[:views]] }]

reviews = {}
LinkedData::Client::Models::Review.all(display_links: false, display_context: false).each do |r|
reviews[r.reviewedOntology] ||= []
reviews[r.reviewedOntology] << r
end

metrics_hash = get_metrics_hash

@formats = Set.new
#get fairscores of all ontologies
@fair_scores = fairness_service_enabled? ? get_fair_score('all') : nil;

@ontologies = []
ontologies.each do |ont|
o = {}

if metrics_hash[ont.id]
o[:class_count] = metrics_hash[ont.id].classes
o[:individual_count] = metrics_hash[ont.id].individuals
else
o[:class_count] = 0
o[:individual_count] = 0
end
o[:class_count_formatted] = number_with_delimiter(o[:class_count], delimiter: ',')
o[:individual_count_formatted] = number_with_delimiter(o[:individual_count], delimiter: ',')

o[:id] = ont.id
o[:type] = ont.viewOf.nil? ? 'ontology' : 'ontology_view'
o[:show] = ont.viewOf.nil? ? true : false # show ontologies only by default
o[:reviews] = reviews[ont.id] || []
o[:groups] = ont.group || []
o[:categories] = ont.hasDomain || []
o[:note_count] = ont.notes.length
o[:review_count] = ont.reviews.length
o[:project_count] = ont.projects.length
o[:private] = ont.private?
o[:popularity] = @analytics[ont.acronym] || 0
o[:submissionStatus] = []
o[:administeredBy] = ont.administeredBy
o[:name] = ont.name
o[:acronym] = ont.acronym
o[:projects] = ont.projects
o[:notes] = ont.notes

if !@fair_scores.nil? && !@fair_scores[ont.acronym].nil?
o[:fairScore] = @fair_scores[ont.acronym]['score']
o[:normalizedFairScore] = @fair_scores[ont.acronym]['normalizedScore']
else
o[:fairScore] = nil
o[:normalizedFairScore] = 0
end

if o[:type].eql?('ontology_view')
unless ontologies_hash[ont.viewOf].blank?
o[:viewOfOnt] = {
name: ontologies_hash[ont.viewOf].name,
acronym: ontologies_hash[ont.viewOf].acronym
}
end
end

o[:artifacts] = []
o[:artifacts] << 'notes' if ont.notes.length > 0
o[:artifacts] << 'reviews' if ont.reviews.length > 0
o[:artifacts] << 'projects' if ont.projects.length > 0
o[:artifacts] << 'summary_only' if ont.summaryOnly

sub = submissions_map[ont.acronym]
if sub
o[:submissionStatus] = sub.submissionStatus
o[:submission] = true
o[:pullLocation] = sub.pullLocation
o[:description] = sub.description
o[:creationDate] = sub.creationDate
o[:released] = sub.released
o[:naturalLanguage] = sub.naturalLanguage
o[:hasFormalityLevel] = sub.hasFormalityLevel
o[:isOfType] = sub.isOfType
o[:submissionStatusFormatted] = submission_status2string(sub).gsub(/\(|\)/, '')

o[:format] = sub.hasOntologyLanguage
@formats << sub.hasOntologyLanguage
else
# Used to sort ontologies without submissions to the end when sorting on upload date
o[:creationDate] = DateTime.parse('19900601')
end

@ontologies << o
end

@ontologies.sort! { |a, b| b[:popularity] <=> a[:popularity] }

@total_ontologies_number = @ontologies.length
### ----------------------------------- FILTERS --------------------------------------------------

@languages = submission_metadata.select { |x| x["@id"]["naturalLanguage"] }.first["enforcedValues"].map do |id, name|
{ "id" => "http://lexvo.org/id/iso639-3/#{id}", "name" => name, "acronym" => id.split('/').last }
end

@formalityLevel = submission_metadata.select { |x| x["@id"]["hasFormalityLevel"] }.first["enforcedValues"].map do |id, name|
{ "id" => id, "name" => name, "acronym" => name.camelize(:lower) }
end

@isOfType = submission_metadata.select { |x| x["@id"]["isOfType"] }.first["enforcedValues"].map do |id, name|
{ "id" => id, "name" => name, "acronym" => name.camelize(:lower) }
end

@filters = {
categories: object_filter(@categories, :categories),
groups: object_filter(@groups, :groups),
naturalLanguage: object_filter(@languages, :naturalLanguage),
hasFormalityLevel: object_filter(@formalityLevel, :hasFormalityLevel),
isOfType: object_filter(@isOfType, :isOfType)
}

filtered_ontologies = @ontologies

filtered_ontologies = search(filtered_ontologies, params[:search]) unless (params[:search].nil? || params[:search].empty?)
puts "params format ................."
puts params[:format]
filtered_ontologies = format_filter(filtered_ontologies, params[:format]) unless params[:format].nil?
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :categories)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :groups)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :naturalLanguage)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :hasFormalityLevel)
filtered_ontologies = filter_ontologies_by(filtered_ontologies, :isOfType)

@ontologies = filtered_ontologies
render partial: "ontologies"
end

def classes
@submission = get_ontology_submission_ready(@ontology)
get_class(params)
Expand Down Expand Up @@ -513,14 +671,6 @@ def ontology_params
p.to_h
end

def determine_layout
case action_name
when 'index'
'angular'
else
super
end
end

def get_views(ontology)
views = ontology.explore.views || []
Expand All @@ -542,7 +692,8 @@ def search(ontologies_table, search_input)
def format_filter(ontologies_table, format)
filtered_table = []
ontologies_table.each do |ontology|
if ontology[:format] == format
#binding.pry
if ontology[:format]&.downcase == format.downcase
filtered_table << ontology
end
end
Expand Down
32 changes: 32 additions & 0 deletions app/javascript/controllers/browse_filters_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="browse-filters"
export default class extends Controller {
connect() {
console.log("working1")
}

dispatchFilterEvent(event){

const checks = this.#getSelectedChecks().map( x => x.name)

const filter = this.element.id.split("_")[0]
let data = {
[filter]: checks,
}

var event = new CustomEvent('changed', {
detail: {
data: data
}
});

this.element.dispatchEvent(event);

}

#getSelectedChecks(){
return Array.from(this.element.querySelectorAll('input:checked'))
}

}
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import { application } from "./application"

import BrowseFiltersController from "./browse_filters_controller"
application.register("browse-filters", BrowseFiltersController)

import ChosenController from "./chosen_controller"
application.register("chosen", ChosenController)

Expand Down
1 change: 1 addition & 0 deletions app/javascript/controllers/show_filter_count_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class extends Controller {
updateCount(){
const checkInputs = this.element.querySelectorAll('input:checked')
const count = checkInputs.length
this.countSpanTarget.style.display = count === 0 ? "none" : "inline-block"
this.countSpanTarget.innerHTML = count === 0 ? "" : count
}
}
1 change: 1 addition & 0 deletions app/javascript/controllers/turbo_frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class extends Controller {
}

updateFrame(event) {

const newData = event.detail.data
const values = Object.entries(newData)[0][1]
if (values.filter(x => x.length !== 0).length === 0) {
Expand Down
11 changes: 9 additions & 2 deletions app/javascript/mixins/useHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export class HistoryService {
}

getUpdatedURL(currentUrl, newData) {

const url = new URL(currentUrl, document.location.origin)
const urlParams = url.searchParams
this.#updateURLFromState(urlParams, this.getState())


this.#filterUnwantedData(newData).forEach(([updatedParam, newValue]) => {
newValue = Array.isArray(newValue) ? newValue : [newValue]
if (newValue !== null && Array.from(newValue).length > 0) {
Expand Down Expand Up @@ -59,8 +60,14 @@ export class HistoryService {
let oldValue = null
urlParams.forEach((newVal, key) => {
oldValue = state[key]

if (oldValue !== undefined && oldValue !== newVal) {
urlParams.set(key, newVal)
if (newVal.length !== 0){
urlParams.set(key, newVal)
}else{
urlParams.remove(key)
}

} else if (oldValue !== undefined) {
state[key] = newVal
}
Expand Down
72 changes: 0 additions & 72 deletions app/views/layouts/angular.html.erb

This file was deleted.

Loading

0 comments on commit 33060be

Please sign in to comment.