Skip to content

Commit

Permalink
Merge branch 'fix/taxonomy-empty-list' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Nov 25, 2024
2 parents 72e2f31 + 5ec296d commit fd9e330
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 63 deletions.
30 changes: 29 additions & 1 deletion app/assets/stylesheets/taxonomy.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@
}
.taxonomy-card .description{
color: #666666;
padding-bottom: 5px;
}

.taxonomy-card .descriptionlink svg{
margin: 0px 2px;
height: 19px;
}

.taxonomy-card .descriptionlink svg path{
fill: #666666;
}
.category-link{
color: #666666 !important;
}
.taxonomy-slice-svg{
width: 35px;
Expand Down Expand Up @@ -98,4 +109,21 @@
background-color: var(--primary-color);
}

.taxonomy-empty-illustration{
display: flex;
gap: 15px;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
margin-top: 40px;
}

.taxonomy-empty-illustration-text{
color: var(--gray-color);

}
.taxonomy-empty-illustration-button{
width: 168px;
}

1 change: 1 addition & 0 deletions app/components/display/taxonomy_card_component.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Display::TaxonomyCardComponent < ViewComponent::Base
include UrlsHelper
def initialize(taxonomy: , ontologies_names: )
@taxonomy = taxonomy
@ontologies_names = ontologies_names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
= "#{@taxonomy.name} (#{@taxonomy.acronym})"
%a{href: "https://#{@taxonomy.acronym}.#{$UI_URL.sub("https://", "")}"}
= inline_svg_tag('icons/slices.svg', class: "taxonomy-slice-svg #{@taxonomy.is_slice ? '' : 'd-none'}")

- if link?(@taxonomy.description)
.descriptionlink
%a.category-link{href: @taxonomy.description, target: '_blank'}
= @taxonomy.description
= inline_svg_tag 'icons/external-link.svg'

%a.ontologies{href: "/ontologies?#{@taxonomy.id.split('/')[-2]}=#{@taxonomy.acronym}"}
= inline_svg_tag('icons/ontology.svg')
.number-of-ontologies
= "#{@taxonomy.ontologies.length} ontologies"
.description
= render TextAreaFieldComponent.new(value: @taxonomy.description)

- unless link?(@taxonomy.description)
.description.mb-1
= render TextAreaFieldComponent.new(value: @taxonomy.description)

.ontologies-cards
- @taxonomy.ontologies.each_with_index do |ontology, index|
- if index>10
Expand Down
25 changes: 15 additions & 10 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ def show_label

def show_members
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id] || params[:ontology]).first
@submission = @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri')
@collection = get_request_collection
@submission = @ontology.explore.latest_submission(include: 'uriRegexPattern,preferredNamespaceUri')
page = params[:page] || '1'
@auto_click = page.to_s.eql?('1')
@page = @collection.explore.members({page: page, language: request_lang})
@concepts = @page.collection
@collection = get_request_collection(@ontology)

if @collection
@page = @collection.explore.members({ page: page, language: request_lang })
@concepts = @page.collection
else
@page = OpenStruct.new({ nextPage: 1, page: 1 })
@concepts = []
end

if @ontology.nil?
ontology_not_found params[:ontology]
else
Expand All @@ -72,14 +79,12 @@ def show_members

private

def get_request_collection
def get_request_collection(ontology = nil)
params[:id] = request_collection_id

if params[:id].nil? || params[:id].empty?
render plain: t('collections.error_valid_collection')
return
end
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id] || params[:ontology]).first
return nil if params[:id].nil? || params[:id].empty?

@ontology = ontology || LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id] || params[:ontology]).first
ontology_not_found(params[:ontology_id]) if @ontology.nil?
get_collection(@ontology, params[:id])
end
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ def index
def show_label
cls_id = params[:concept] || params[:id]
ont_id = params[:ontology]
pref_label = concept_label(ont_id, cls_id)
cls = @ontology.explore.single_class({ language: request_lang, include: 'prefLabel' }, cls_id)
pref_label = begin
concept_label(ont_id, cls_id)
rescue
cls_id
end
cls = @ontology.explore&.single_class({ language: request_lang, include: 'prefLabel' }, cls_id)
label = helpers.main_language_label(pref_label)
link = concept_path(cls_id, ont_id, request_lang)

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/taxonomy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def nest_categories_children(categories)
category_index[category[:id]] = category
end
categories.each do |category|
category[:parentCategory].each do |parent_id|
category[:parentCategory]&.each do |parent_id|
parent = category_index[parent_id]
next if parent.nil?
parent[:children] ||= []
parent[:children] << category
end
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def at_slice?

def add_comment_button(parent_id, parent_type)
if session[:user].nil?
link_to t('application.add_comment'), login_index_path(redirect: request.url), class: "secondary-button regular-button slim"
link_to t('application.add_comment'), login_index_path(redirect: request.url), class: "secondary-button regular-button slim", data: {'turbo-frame': '_top'}
else
link_to_modal t('application.add_comment'), notes_new_comment_path(parent_id: parent_id, parent_type: parent_type, ontology_id: @ontology.acronym),
class: "secondary-button regular-button slim", data: { show_modal_title_value: t('application.add_new_comment')}
Expand All @@ -146,7 +146,7 @@ def add_reply_button(parent_id)

def add_proposal_button(parent_id, parent_type)
if session[:user].nil?
link_to t('application.add_proposal'), login_index_path(redirect: request.url), class: "secondary-button regular-button slim"
link_to t('application.add_proposal'), login_index_path(redirect: request.url), class: "secondary-button regular-button slim", data: {'turbo-frame': '_top'}
else
link_to_modal t('application.add_proposal'), notes_new_proposal_path(parent_id: parent_id, parent_type: parent_type, ontology_id: @ontology.acronym),
class: "secondary-button regular-button slim", data: { show_modal_title_value: t('application.add_new_proposal')}
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def regular_button(id, value, variant: "secondary", state: "regular", size: "sli
end
end

def form_save_button
render Buttons::RegularButtonComponent.new(id: 'save-button', value: t('components.save_button'), variant: "primary", size: "slim", type: "submit") do |btn|
def form_save_button(enable_loading: true)
render Buttons::RegularButtonComponent.new(id: 'save-button', value: t('components.save_button'), variant: "primary", size: "slim", type: "submit", state: enable_loading ? 'animate' : '') do |btn|
btn.icon_left do
inline_svg_tag "check.svg"
end
Expand Down
14 changes: 4 additions & 10 deletions app/helpers/mappings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@ def mapping_links(mapping, concept)
process = mapping.process || {}

if inter_portal_mapping?(target_concept)
cls_link = ajax_to_inter_portal_cls(target_concept)
cls_link = target_concept.id
ont_name = target_concept.links['ontology']
ont_link = link_to ont_name, get_inter_portal_ui_link(ont_name, process['name']), target: '_blank'
source_tooltip = 'Internal-portal'
elsif internal_mapping?(target_concept)
begin
ont = target_concept.explore.ontology
ont_name = ont.acronym
ont_link = link_to ont_name, ontology_path(ont_name), 'data-turbo-frame': '_top'
rescue
ont_name = target_concept.links['ontology'] || target_concept.id
ont_link = ont_name
end
ont_name = target_concept.links['ontology'].split('/').last
ont_link = link_to ont_name, ontology_path(ont_name), 'data-turbo-frame': '_top'
cls_link = raw(get_link_for_cls_ajax(target_concept.id, ont_name, '_top'))
source_tooltip = 'Internal'
else
cls_label = ExternalLinkTextComponent.new(text: target_concept.links['self']).call
cls_link = raw("<a href='#{target_concept.links["self"]}' target='_blank'>#{cls_label}</a>")
cls_link = raw("<a href='#{target_concept.links['self']}' target='_blank'>#{cls_label}</a>")
ont_name = target_concept.links['ontology']
ont_link = link_to ExternalLinkTextComponent.new(text: ont_name).call, target_concept.links['ontology'],
target: '_blank'
Expand Down
13 changes: 8 additions & 5 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,15 @@ def render_concepts_json_button(link)

def ontology_object_details_component(frame_id: , ontology_id:, objects_title:, object:, &block)
render TurboFrameComponent.new(id: frame_id, data: {"turbo-frame-target": "frame"}) do
return if !object.present?
return alert_component(object.errors.join) if object.errors
return unless object.present?

ontology_object_tabs_component(ontology_id: ontology_id, objects_title: objects_title, object_id: object["@id"]) do |tabs|
tab_item_component(container_tabs: tabs, title: t('concepts.details'), path: '#details', selected: true) do
capture(&block)
if object.errors
alert_component(object.errors.join)
else
ontology_object_tabs_component(ontology_id: ontology_id, objects_title: objects_title, object_id: object["@id"]) do |tabs|
tab_item_component(container_tabs: tabs, title: t('concepts.details'), path: '#details', selected: true) do
capture(&block)
end
end
end
end
Expand Down
21 changes: 14 additions & 7 deletions app/helpers/submission_inputs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def attribute_input(attr_key, long_text: false, label: nil, show_tooltip: true,

end

def ontology_name_input(ontology = @ontology)
text_input(name: 'ontology[name]', value: ontology.name)
def ontology_name_input(ontology = @ontology, label: 'Name')
text_input(name: 'ontology[name]', value: ontology.name, label: label_required(label))
end

def ontology_acronym_input(ontology = @ontology, update: @is_update_ontology)
out = text_input(name: 'ontology[acronym]', value: ontology.acronym, disabled: update)
def ontology_acronym_input(ontology = @ontology, update: @is_update_ontology, label: 'Acronym')
out = text_input(name: 'ontology[acronym]', value: ontology.acronym, disabled: update, label: label_required(label))
out += hidden_field_tag('ontology[acronym]', ontology.acronym) if update
out
end
Expand All @@ -123,7 +123,7 @@ def ontology_administered_by_input(ontology = @ontology, users_list = @user_sele
users_list = LinkedData::Client::Models::User.all(include: "username").map { |u| [u.username, u.id] }
users_list.sort! { |a, b| a[1].downcase <=> b[1].downcase }
end
select_input(label: t('submission_inputs.administrators'), name: "ontology[administeredBy]", values: users_list, selected: ontology.administeredBy || session[:user].id, multiple: true)
select_input(label: label_required(t('submission_inputs.administrators')), name: "ontology[administeredBy]", values: users_list, selected: ontology.administeredBy || session[:user].id, multiple: true)
end

def ontology_categories_input(ontology = @ontology, categories = @categories)
Expand Down Expand Up @@ -213,7 +213,7 @@ def ontology_visibility_input(ontology = @ontology)

render(Layout::RevealComponent.new(possible_values: %w[private public], selected: ontology.viewingRestriction)) do |c|
c.button do
select_input(label: t('submission_inputs.visibility'), name: "ontology[viewingRestriction]", required: true,
select_input(label: label_required(t('submission_inputs.visibility')), name: "ontology[viewingRestriction]", required: true,
values: %w[public private],
selected: ontology.viewingRestriction)
end
Expand Down Expand Up @@ -248,7 +248,7 @@ def contact_input(label: '', name: t('submission_inputs.contact'), show_help: tr

render NestedFormInputsComponent.new(object_name: 'contact', default_empty_row: true) do |c|
c.header do
content_tag(:div, name.blank? ? '' : t('submission_inputs.contact_name', name: name), class: 'w-50') + content_tag(:div, name.blank? ? '' : t('submission_inputs.contact_email', name: name), class: 'w-50')
content_tag(:div, name.blank? ? '' : label_required(t('submission_inputs.contact_name', name: name)), class: 'w-50') + content_tag(:div, name.blank? ? '' : label_required(t('submission_inputs.contact_email', name: name)), class: 'w-50')
end

c.template do
Expand Down Expand Up @@ -531,4 +531,11 @@ def attribute_help_text(attr)
help_text
end
end

def label_required(label)
content_tag(:div) do
label.html_safe +
content_tag(:span, '*', style: 'color: var(--error-color);')
end
end
end
7 changes: 5 additions & 2 deletions app/views/concepts/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
= render TreeLinkComponent.new(child: concept, href: href,
children_href: '#', selected: concept.id.eql?(concepts.first.id) && c.auto_click?,
target_frame: 'concept_show', data: data, is_reused: concept_reused?(submission: @submission, concept_id: concept.id))
- c.error do
= t('concepts.list_error')

- c.error do
- if @collection.nil?
= t("ontologies.concepts_browsers.select_collection")
- else
= t('concepts.list_error')
2 changes: 1 addition & 1 deletion app/views/notes/_new_comment.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
%div.form-group
%textarea.form-control.reply_body{cols: "1", name: "body", required: true, placeholder: t('notes.new_comment.comment'), rows: "1", style: "height: 100px;", tabindex: "0"}

= submit_tag t('notes.new_comment.save') , class:'btn btn-success btn-block'
= form_save_button(enable_loading: false)
2 changes: 1 addition & 1 deletion app/views/notes/_new_proposal.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
.form-group
= text_field_tag 'proposal[parent]','', placeholder: t('notes.new_proposal.parent'), class: "form-control", required: true

= submit_tag t('notes.new_proposal.save') , class:'btn btn-success btn-block'
= form_save_button(enable_loading: false)
2 changes: 1 addition & 1 deletion app/views/notes/_note_line.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
- if parent_type.eql?('ontology')
- row.td do
- if note.relatedClass && note.relatedClass.length > 0
%a{href: "/ontologies/#{ontology_acronym}?p=classes&conceptid=#{CGI.escape(note.relatedClass.first)}", 'data-turbo': 'false'}= note.relatedClass.first
= get_link_for_cls_ajax(note.relatedClass.first, ontology_acronym, '_top')
- row.td do
= DateTime.parse(note.created).strftime("%Y-%m-%d")
2 changes: 1 addition & 1 deletion app/views/ontologies/_submission_location_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= render Input::InputFieldComponent.new(label: t("ontologies.location"), name: '') do
= render Input::InputFieldComponent.new(label: label_required(t("ontologies.location")), name: '') do
.location-choice
%input{type: "radio", name: "submission[isRemote]", value: "3", checked: summary_only?, id: "metadata_only", onchange: "displayMetadataOnlyForm()"}
%label.title{for: "metadata_only"}
Expand Down
2 changes: 1 addition & 1 deletion app/views/ontologies/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
.upload-ontology-field-container
- @submission.valid = nil unless @submission.status&.eql?('retired')
= attribute_input("valid")
.upload-ontology-field-container
.upload-ontology-field-container.mt-3
= render partial: 'ontologies/submission_location_form'

- c.page do
Expand Down
27 changes: 18 additions & 9 deletions app/views/taxonomy/_taxonomies.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
.taxonomy-section
- pairs, impairs = taxonomies.each_with_index.partition { |_, index| index.even? }
- taxonomies_first_row = pairs.map(&:first)
- taxonomies_second_row = impairs.map(&:first)
.first-row
- taxonomies_first_row.each do |taxonomy|
= render Display::TaxonomyCardComponent.new(taxonomy: taxonomy, ontologies_names: @ontologies_names)
.second-row
- taxonomies_second_row.each do |taxonomy|
= render Display::TaxonomyCardComponent.new(taxonomy: taxonomy, ontologies_names: @ontologies_names)
- if taxonomies.blank?
.taxonomy-empty-illustration
= inline_svg_tag 'empty-box.svg'
.taxonomy-empty-illustration-text
No group is created yet
- if session[:user]&.admin?
.taxonomy-empty-illustration-button
= render Buttons::RegularButtonComponent.new(id:'create-taxonomy', value: "Create #{type}", variant: "secondary", size: "slim", href: "/admin?section=#{type}")
- else
- pairs, impairs = taxonomies.each_with_index.partition { |_, index| index.even? }
- taxonomies_first_row = pairs.map(&:first)
- taxonomies_second_row = impairs.map(&:first)
.first-row
- taxonomies_first_row.each do |taxonomy|
= render Display::TaxonomyCardComponent.new(taxonomy: taxonomy, ontologies_names: @ontologies_names)
.second-row
- taxonomies_second_row.each do |taxonomy|
= render Display::TaxonomyCardComponent.new(taxonomy: taxonomy, ontologies_names: @ontologies_names)
6 changes: 3 additions & 3 deletions app/views/taxonomy/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
= t('taxonomy.groups_and_categories')
.line
.taxonomy-page-decription
= t('taxonomy.description')
= t('taxonomy.description', portal: portal_name)

= render TabsContainerComponent.new do |c|
- c.item(title: 'Groups', selected: !@category_section_active)
- c.item_content do
= render partial: '/taxonomy/taxonomies', locals: { taxonomies: @groups }
= render partial: '/taxonomy/taxonomies', locals: { taxonomies: @groups, type: 'groups' }

- c.item(title: 'Categories', selected: @category_section_active)
- c.item_content do
= render partial: '/taxonomy/taxonomies', locals: { taxonomies: @categories }
= render partial: '/taxonomy/taxonomies', locals: { taxonomies: @categories, type: 'categories' }
:javascript
document.getElementById('categories_tab').addEventListener('click', function(event) {
window.history.pushState({ path: '/categories' }, '', '/categories');
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ en:
privacy_policy_anchor: "#h-privacy-policy"
taxonomy:
groups_and_categories: Groups and Categories
description: In AgroPortal, ontologies are organized in groups and tagged with categories. Typically, groups associate ontologies from the same project or organization for better identification of the provenance. Whereas categories are about subjects/topics and enable to classify ontologies. As of 2016, AgroPortal's categories were established in cooperation with FAO AIMS. In 2024, we moved to UNESCO nomenclature for fields of science and technology. Groups and categories, along with other metadata, can be used on the “Browse” page of AgroPortal to filter out the list of ontologies.
description: "In %{portal}, ontologies are organized in groups and tagged with categories. Typically, groups associate ontologies from the same project or organization for better identification of the provenance. Whereas categories are about subjects/topics and enable to classify ontologies. As of 2016, %{portal}'s categories were established in cooperation with FAO AIMS. In 2024, we moved to UNESCO Thesaurus (https://vocabularies.unesco.org). Groups and categories, along with other metadata, can be used on the “Browse” page of %{portal} to filter out the list of ontologies."
show_sub_categories: Show sub categories

federation:
Expand Down
Loading

0 comments on commit fd9e330

Please sign in to comment.