Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: metadata exporter to different formats (CSV, xml, json and ntriples) #469

Merged
merged 7 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,262 changes: 0 additions & 7,262 deletions app/assets/javascripts/jsonld.js

This file was deleted.

2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
@import "tippy.js/dist/tippy";
@import 'tippy.js/themes/light-border';
@import '@triply/yasgui/build/yasgui.min';
//@import 'highlight.js/styles/default.min';
@import 'highlight.js/styles/intellij-light';
@import "feedback";
@import "login";
@import "components/index";
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/tabs_container.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
font-size: 16px;
font-weight: 400;
color: #5e5e5e;
margin-right: 50px;
margin-right: 30px;
cursor: pointer;
opacity: 60%;
transition: opacity 0.3s ease;
Expand Down
19 changes: 17 additions & 2 deletions app/assets/stylesheets/ontologies.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $widget-table-border-color: #EFEFEF;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;

background-color: white;
padding: 0.75rem 1.25rem;

Expand All @@ -56,7 +56,7 @@ $widget-table-border-color: #EFEFEF;

a {
color: #6c757d;

&:hover {
color: #0056b3;
text-decoration: none;
Expand Down Expand Up @@ -289,4 +289,19 @@ $widget-table-border-color: #EFEFEF;
margin-right: 15px;
}
}
}

.metadata-exporter {
position: relative;
}
.metadata-exporter .download-btn {
position: absolute;
right: 20px;
z-index: 2;
.chip_button_container_clickable {
opacity: 0.6;
&:hover {
opacity: 1;
}
}
}
2 changes: 1 addition & 1 deletion app/components/date_time_field_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(value: , format: :monthfull_day_year)
end

def call
l(Date.parse(@value), format: @format.to_sym) if @value
l(Date.parse(@value), format: @format.to_sym).html_safe if @value
end

end
10 changes: 1 addition & 9 deletions app/components/submission_metadata_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ def initialize(submission: , submission_metadata:)
@submission = submission

@json_metadata = submission_metadata
metadata_list = {}
# Get extracted metadata and put them in a hash with their label, if one, as value
@json_metadata.each do |metadata|
metadata_list[metadata["attribute"]] = metadata["label"]
end
reject = [:csvDump, :dataDump, :openSearchDescription, :metrics, :prefLabelProperty, :definitionProperty,
:definitionProperty, :synonymProperty, :authorProperty, :hierarchyProperty, :obsoleteProperty,
:ontology, :endpoint, :submissionId, :submissionStatus, :uploadFilePath]
@metadata_list = metadata_list.reject{|k,v| reject.include?(k.to_sym)}.sort
@metadata_list = content_metadata_attributes(submission_metadata)
end

def display_attributes(metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@
- r.td do
.d-flex.flex-wrap.align-items-center
= display_attributes(metadata)
:javascript
$("#submission_metadata_table").dataTable({ paging: false, autoWidth: true, search :false })


2 changes: 1 addition & 1 deletion app/components/tab_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def id
end

def title
@title&.humanize
@title
end

def active_class
Expand Down
32 changes: 32 additions & 0 deletions app/controllers/metadata_export_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class MetadataExportController < ApplicationController
include MetadataHelper

def index
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
ontology_not_found(params[:ontology]) if @ontology.nil?

@submission_latest = @ontology.explore.latest_submission(include: 'all')
@ontology_metadata = {}
@ontology.to_hash.each do |k, v|
@ontology_metadata[k] = v
end

content_metadata_attributes.each do |attr, label|
value = @submission_latest.send(attr)

if attr.to_s.eql?('contact') || agent?(attr)
new_values = Array(value).map do |x|
next x if x.is_a?(String)

x = x.to_h || x.to_hash
x.delete(:context)
x.delete(:links)
x.delete(:id)
x[:email] || x[:name]
end
value = value.is_a?(Array) ? new_values : new_values.first
end
@ontology_metadata[attr] = value
end
end
end
7 changes: 0 additions & 7 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,6 @@ def widgets
end
end

def show_additional_metadata
@metadata = submission_metadata
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:id]).first
@submission_latest = @ontology.explore.latest_submission(include: 'all', display_context: false, display_links: false)
render partial: 'ontologies/sections/additional_metadata'
end

def show_licenses

@metadata = submission_metadata
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module ApplicationHelper




def resolve_namespaces
RESOLVE_NAMESPACE
end
def ontologies_analytics
data = LinkedData::Client::Analytics.last_month.onts
data.map{|x| [x[:ont].to_s, x[:views]]}.to_h
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/metadata_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ def open_to_add_metadata?(attr_key)
attrs.include?(attr_key.to_sym)
end

def content_metadata_attributes(all_metadata = submission_metadata)
metadata_list = {}
# Get extracted metadata and put them in a hash with their label, if one, as value
all_metadata.each do |metadata|
metadata_list[metadata["attribute"]] = metadata["label"]
end
reject = [:csvDump, :dataDump, :openSearchDescription, :metrics, :prefLabelProperty, :definitionProperty,
:definitionProperty, :synonymProperty, :authorProperty, :hierarchyProperty, :obsoleteProperty,
:ontology, :endpoint, :submissionId, :submissionStatus, :uploadFilePath, :diffFilePath]
metadata_list.reject{|k,v| reject.include?(k.to_sym)}.sort
end

def attr_uri?(attr_label)
input_type?(attr_metadata(attr_label), "uri")
end
Expand Down
18 changes: 0 additions & 18 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,24 +556,6 @@ def ontology_depiction_card
end
end

def metadata_formats_buttons
render SummarySectionComponent.new(title: 'Download metadata (profile/syntax)', show_card: false) do
content_tag :div, data: { controller: 'metadata-downloader' } do
horizontal_list_container([
['NQuads', 'MOD/n-triple'],
['JsonLd', 'MOD/json-ld'],
['XML', 'MOD/rdf-xml']
]) do |format, label|
render ChipButtonComponent.new(type: 'clickable', 'data-action': "click->metadata-downloader#download#{format}") do
concat content_tag(:span, label)
concat content_tag(:span, inline_svg("summary/download.svg", width: '15px', height: '15px'))
end
end
end
end

end

def count_subscriptions(ontology_id)
ontology_id = ontology_id.split('/').last
users = LinkedData::Client::Models::User.all(include: 'subscription', display_context: false, display_links: false)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/schemes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def concept_label_to_show(submission: @submission_latest)

def section_name(section)
section = concept_label_to_show(submission: @submission_latest || @submission) if section.eql?('classes')
section
section.humanize
#t("ontology_details.sections.#{section}" , section)
end

Expand Down
Loading
Loading