Skip to content

Commit

Permalink
use turbo streams to update ontologies result and the filters counts
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Apr 23, 2023
1 parent 4408de7 commit e7d3f5e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 76 deletions.
20 changes: 16 additions & 4 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class OntologiesController < ApplicationController
include SchemesHelper
include CollectionsHelper
include MappingStatistics
include TurboHelper

require 'multi_json'
require 'cgi'
Expand Down Expand Up @@ -130,14 +131,25 @@ def ontologies_filter

@ontologies << o
end

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


@ontologies = apply_ontology_filters(@ontologies, @categories, @groups)
@object_count = count_objects(@ontologies, @filters.keys)
update_count_streams = @object_count.map do |section, values_count|
values_count.map do |value, count|
replace("count_#{section}_#{value}") do
helpers.turbo_frame_tag("count_#{section}_#{value}") do
helpers.content_tag(:span, class: 'p-1 px-2') {count.to_s}
end
end
end
end.flatten
render turbo_stream: [prepend('ontologies-browse-results', partial: 'ontologies')] + update_count_streams

end

def classes
@submission = get_ontology_submission_ready(@ontology)
get_class(params)
Expand Down Expand Up @@ -499,7 +511,7 @@ def ontology_filters_init(categories, groups)
{"id" => "ANNOTATOR", "name" => "ANNOTATOR", "acronym" => "ANNOTATOR"},
{"id" => "DIFF", "name" => "DIFF", "acronym" => "DIFF"}
]

#@missingStatus = submission_metadata.select { |x| x["@id"]["submissionStatus"] }.first["enforcedValues"].map do |id, name|
# { "id" => id, "name" => name, "acronym" => name.camelize(:lower) }
#end
Expand Down Expand Up @@ -564,7 +576,7 @@ def format_filter(ontologies_table, format)
filtered_table << ontology
end
end

filtered_table
end

Expand Down
142 changes: 70 additions & 72 deletions app/views/ontologies/_ontologies.html.haml
Original file line number Diff line number Diff line change
@@ -1,78 +1,76 @@
= turbo_frame_tag "search-results" do
%p.browse-desc-text{:style => "margin-bottom: 15px;"}
= "Showing "+ @ontologies.length.to_s
-# Here we put our turbo frame "ontologies_frame"
%div
- @ontologies.each do |ontology|
.browse-ontology-container
.browse-ontology-description
.browse-ontology-title-bar
%a.browse-ontology-title{:href => "/ontologies/#{ontology[:acronym]}", data: {'turbo-frame': '_top'}}
= ontology[:name]+" ("+ontology[:acronym]+")"
- if ontology[:deprecated]
.browse-ontology-deprecated
deprecated
- if ontology[:viewOfOnt]
.browse-ontology-view
view
.browse-desc-container{data:{controller:"text-truncate", 'text-truncate-more-text-value': '+ Show more ...' , 'text-truncate-less-text-value': '- Show less ...'}}
%p.browse-desc-text{'data-text-truncate-target': 'content'}
= ontology[:description]
.browse-show-more-button{data:{'text-truncate-target': 'button', 'action':"click->text-truncate#toggle"}}
+ Show more ...
%p.browse-desc-text{:style => "margin-bottom: 15px;"}
= "Showing "+ @ontologies.length.to_s
%div
- @ontologies.each do |ontology|
.browse-ontology-container
.browse-ontology-description
.browse-ontology-title-bar
%a.browse-ontology-title{:href => "/ontologies/#{ontology[:acronym]}", data: {'turbo-frame': '_top'}}
= ontology[:name]+" ("+ontology[:acronym]+")"
- if ontology[:deprecated]
.browse-ontology-deprecated
deprecated
- if ontology[:viewOfOnt]
.browse-ontology-view
view
.browse-desc-container{data:{controller:"text-truncate", 'text-truncate-more-text-value': '+ Show more ...' , 'text-truncate-less-text-value': '- Show less ...'}}
%p.browse-desc-text{'data-text-truncate-target': 'content'}
= ontology[:description]
.browse-show-more-button{data:{'text-truncate-target': 'button', 'action':"click->text-truncate#toggle"}}
+ Show more ...


- unless ontology[:fairScore].nil? || ontology[:acronym] == 'AGROVOC'
.browse-fair
%p.browse-fair-title
FAIR score
.browse-progress-bar
.browse-faire-progress{:style => "width: #{ontology[:normalizedFairScore].to_s+"%"}"}
%p.browse-fair-score
= ontology[:fairScore]
%a.browse-fair-details{:href => "/ontologies/#{ontology[:acronym]}#fair-details"} FAIR details ...
.d-flex.align-items-baseline
- if ontology[:creationDate]
.browse-uploaded
%p.mr-1 Uploaded
%p.browse-uploaded-date{data:{controller: 'timeago', 'timeago-datetime-value': ontology[:creationDate], 'timeago-add-suffix-value': 'true'}}
- if ontology[:contact]
%p.mx-1 by
%p.browse-uploaded-date.text-truncate
= ontology[:contact].humanize
- unless ontology[:fairScore].nil? || ontology[:acronym] == 'AGROVOC'
.browse-fair
%p.browse-fair-title
FAIR score
.browse-progress-bar
.browse-faire-progress{:style => "width: #{ontology[:normalizedFairScore].to_s+"%"}"}
%p.browse-fair-score
= ontology[:fairScore]
%a.browse-fair-details{:href => "/ontologies/#{ontology[:acronym]}#fair-details"} FAIR details ...
.d-flex.align-items-baseline
- if ontology[:creationDate]
.browse-uploaded
%p.mr-1 Uploaded
%p.browse-uploaded-date{data:{controller: 'timeago', 'timeago-datetime-value': ontology[:creationDate], 'timeago-add-suffix-value': 'true'}}
- if ontology[:contact]
%p.mx-1 by
%p.browse-uploaded-date.text-truncate
= ontology[:contact].humanize


- if ontology[:format]
.browse-ontology-view
= ontology[:format]
- if ontology[:format]
.browse-ontology-view
= ontology[:format]

.browse-ontology-cards
- if ontology[:format] != 'SKOS' && ontology[:class_count] > 0
%a.browse-onology-card{:href => "/ontologies/#{ontology[:acronym]}?p=classes"}
%p.browse-card-number
= ontology[:class_count_formatted]
%p.browse-card-text
classes
- if ontology[:individual_count] > 0
%a.browse-onology-card{:href => "/ontologies/#{ontology[:acronym]}?p=classes"}
%p.browse-card-number
= ontology[:individual_count_formatted]
%p.browse-card-text
= ontology[:format] == 'SKOS' ? "concepts" : "instances"
- if ontology[:project_count] > 0
%a.browse-onology-card{:href => "/ontologies/#{ontology[:acronym]}#projects_content"}
%p.browse-card-number
= ontology[:project_count]
%p.browse-card-text
projects
- if ontology[:note_count] > 0
%a.browse-onology-card{:href => "#"}
%p.browse-card-number
= ontology[:note_count]
%p.browse-card-text
notes
.browse-ontology-cards
- if ontology[:format] != 'SKOS' && ontology[:class_count] > 0
%a.browse-onology-card{:href => "/ontologies/#{ontology[:acronym]}?p=classes"}
%p.browse-card-number
= ontology[:class_count_formatted]
%p.browse-card-text
classes
- if ontology[:individual_count] > 0
%a.browse-onology-card{:href => "/ontologies/#{ontology[:acronym]}?p=classes"}
%p.browse-card-number
= ontology[:individual_count_formatted]
%p.browse-card-text
= ontology[:format] == 'SKOS' ? "concepts" : "instances"
- if ontology[:project_count] > 0
%a.browse-onology-card{:href => "/ontologies/#{ontology[:acronym]}#projects_content"}
%p.browse-card-number
= ontology[:project_count]
%p.browse-card-text
projects
- if ontology[:note_count] > 0
%a.browse-onology-card{:href => "#"}
%p.browse-card-number
= ontology[:note_count]
%p.browse-card-text
notes

%div.empty-state
.browse-empty-illustration
%img{:src => "#{asset_path("empty-box.svg")}"}
%p No result was found
%div.empty-state
.browse-empty-illustration
%img{:src => "#{asset_path("empty-box.svg")}"}
%p No result was found

0 comments on commit e7d3f5e

Please sign in to comment.