diff --git a/app/assets/javascripts/bp_admin.js b/app/assets/javascripts/bp_admin.js
index 744a297e9e..7e29b80be9 100644
--- a/app/assets/javascripts/bp_admin.js
+++ b/app/assets/javascripts/bp_admin.js
@@ -1303,8 +1303,14 @@ function displayGroups(data, group) {
"targets": 4,
"searchable": false,
"orderable": false,
- "title": "Actions",
- "width": "210px"
+ "title": "Count",
+ },
+ {
+ "targets": 5,
+ "searchable": false,
+ "orderable": false,
+ "title": "Actions",
+ "width": "200px"
}
],
"autoWidth": false,
@@ -1333,10 +1339,13 @@ function populateGroupRows(data) {
let description = group['description']
let created = group['created'];
let id = group['acronym'];
+ let nb = [
+ ' ' + group['ontologies'].length + ' ',
+ ];
let actions = [
'Edit',
]
- return [name, description, created, id , actions.join('|')];
+ return [name, description, created, id , nb, actions.join('|')];
})
return allRows;
@@ -1456,8 +1465,14 @@ function displayCategories(data, category) {
"targets": 5,
"searchable": false,
"orderable": false,
+ "title": "Count",
+ },
+ {
+ "targets": 6,
+ "searchable": false,
+ "orderable": false,
"title": "Actions",
- "width": "210px"
+ "width": "250px"
}
],
"autoWidth": false,
@@ -1487,10 +1502,13 @@ function populateCategoryRows(data) {
let created = category['created'];
let id = category['acronym'];
let parentCategory = category['parentCategory'];
+ let nb = [
+ ' ' + category['ontologies'].length + ' ',
+ ];
let actions = [
'Edit',
]
- return [name, description, created, id , parentCategory, actions.join('|')];
+ return [name, description, created, id , parentCategory, nb , actions.join('|')];
})
return allRows;
diff --git a/app/components/select_input_component.rb b/app/components/select_input_component.rb
index 872f7f41ee..9bcfe5d1df 100644
--- a/app/components/select_input_component.rb
+++ b/app/components/select_input_component.rb
@@ -2,13 +2,14 @@
class SelectInputComponent < ViewComponent::Base
- def initialize(id:, name:, values:, selected:, multiple: false)
+ def initialize(id:, name:, values:, selected:, multiple: false, open_to_add_values: false)
super
@id = id
@name = name
@values = values
@selected = selected
@multiple = multiple
+ @open_to_add_values = open_to_add_values
end
def options_values
diff --git a/app/components/select_input_component/select_input_component.html.haml b/app/components/select_input_component/select_input_component.html.haml
index 2a9f7692cd..a46f0ad299 100644
--- a/app/components/select_input_component/select_input_component.html.haml
+++ b/app/components/select_input_component/select_input_component.html.haml
@@ -1,7 +1,7 @@
%div{:data => { controller: "select-input", 'select-input': {'multiple-value': @multiple.to_s}}}
= select_tag(@name, options_values, { multiple: @multiple, class: "form-control", id: "select_#{@id}", data: { action: "select-input#toggleOtherValue", "select-input-target": "selectedValues" } })
- %div.d-flex.mt-1
+ %div.d-flex.mt-1{style: "display:#{@open_to_add_values ? 'none !important;' : 'block;'}"}
= text_field_tag("add_#{@id}", nil, :style => "margin-right: 1em;width: 16em;display: none;", :placeholder => "Or provide the value",
data: {action: "keydown.enter->select-input#addValue", "select-input-target": "inputValueField"}, class: 'metadataInput form-control form-control-sm')
diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb
index 2af3f9143d..df6fd128c0 100644
--- a/app/controllers/admin/categories_controller.rb
+++ b/app/controllers/admin/categories_controller.rb
@@ -1,10 +1,12 @@
class Admin::CategoriesController < ApplicationController
+ include SubmissionUpdater
layout :determine_layout
before_action :unescape_id, only: [:edit, :show, :update, :destroy]
before_action :authorize_admin
CATEGORIES_URL = "#{LinkedData::Client.settings.rest_url}/categories"
+ ATTRIBUTE_TO_INCLUDE = 'name,acronym,created,description,parentCategory,ontologies'
def index
response = _categories
@@ -20,8 +22,8 @@ def new
end
def edit
- @category = LinkedData::Client::Models::Category.find_by_acronym(params[:id]).first
-
+ @category = LinkedData::Client::Models::Category.find_by_acronym(params[:id], include:'name,acronym,created,description,parentCategory,ontologies' ).first
+ @ontologies_category = LinkedData::Client::Models::Ontology.all(include: 'acronym').map {|o|[o.acronym, o.id] }
respond_to do |format|
format.html { render "edit", :layout => false }
end
@@ -49,10 +51,11 @@ def update
response = { errors: '', success: ''}
start = Time.now
begin
- category = LinkedData::Client::Models::Category.find_by_acronym(params[:id]).first
+ category = LinkedData::Client::Models::Category.find_by_acronym(params[:id], include: ATTRIBUTE_TO_INCLUDE ).first
+ add_ontologies_to_object(category_params[:ontologies],category) if (category_params[:ontologies].size > 0 && category_params[:ontologies].first != '')
+ delete_ontologies_from_object(category_params[:ontologies],category.ontologies,category)
category.update_from_params(category_params)
category_update = category.update
-
if response_error?(category_update)
response[:errors] = response_errors(category_update)
else
@@ -89,14 +92,14 @@ def unescape_id
end
def category_params
- params.require(:category).permit(:acronym, :name, :description, :parentCategory).to_h
+ params.require(:category).permit(:acronym, :name, :description, :parentCategory, {ontologies:[]}).to_h
end
def _categories
response = { categories: Hash.new, errors: '', success: '' }
start = Time.now
begin
- response[:categories] = JSON.parse(LinkedData::Client::HTTP.get(CATEGORIES_URL, { include: 'all' }, raw: true))
+ response[:categories] = JSON.parse(LinkedData::Client::HTTP.get(CATEGORIES_URL, { include: ATTRIBUTE_TO_INCLUDE }, raw: true))
response[:success] = "categories successfully retrieved in #{Time.now - start}s"
LOG.add :debug, "Categories - retrieved #{response[:categories].length} groups in #{Time.now - start}s"
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index 842982957e..17bc125111 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -1,4 +1,5 @@
class Admin::GroupsController < ApplicationController
+ include SubmissionUpdater
layout :determine_layout
before_action :unescape_id, only: [:edit, :show, :update, :destroy]
@@ -21,7 +22,8 @@ def new
def edit
@group = LinkedData::Client::Models::Group.find_by_acronym(params[:id]).first
-
+ @acronyms = @group.ontologies.map { |url| url.match(/\/([^\/]+)$/)[1] }
+ @ontologies_group = LinkedData::Client::Models::Ontology.all(include: 'acronym').map {|o|[o.acronym, o.id] }
respond_to do |format|
format.html { render "edit", :layout => false }
end
@@ -50,6 +52,8 @@ def update
start = Time.now
begin
group = LinkedData::Client::Models::Group.find_by_acronym(params[:id]).first
+ add_ontologies_to_object(group_params[:ontologies],group) if (group_params[:ontologies].size > 0 && group_params[:ontologies].first != '')
+ delete_ontologies_from_object(group_params[:ontologies],group.ontologies,group)
group.update_from_params(group_params)
group_updated = group.update
if response_error?(group_updated)
@@ -88,7 +92,7 @@ def unescape_id
end
def group_params
- params.require(:group).permit(:acronym, :name, :description).to_h()
+ params.require(:group).permit(:acronym, :name, :description, {ontologies:[]}).to_h()
end
def _groups
diff --git a/app/controllers/concerns/submission_updater.rb b/app/controllers/concerns/submission_updater.rb
index 3b1218fc33..5967e23d2a 100644
--- a/app/controllers/concerns/submission_updater.rb
+++ b/app/controllers/concerns/submission_updater.rb
@@ -24,6 +24,32 @@ def update_submission(new_submission_hash)
@submission.update(cache_refresh_all: false)
end
+ def add_ontologies_to_object(ontologies,object)
+ ontologies.each do |ont|
+ next if object.ontologies.include?(ont)
+ ontology = LinkedData::Client::Models::Ontology.find(ont)
+ if object.type.match(/\/([^\/]+)$/)[1] == 'Group'
+ ontology.group.push(object.id)
+ else
+ ontology.hasDomain.push(object.id)
+ end
+ ontology.update
+ end
+ end
+
+ def delete_ontologies_from_object(new_ontologies,old_ontologies,object)
+ ontologies = old_ontologies - new_ontologies
+ ontologies.each do |ont|
+ ontology = LinkedData::Client::Models::Ontology.find(ont)
+ if object.type.match(/\/([^\/]+)$/)[1] == 'Group'
+ ontology.group.delete(object.id)
+ else
+ ontology.hasDomain.delete(object.id)
+ end
+ ontology.update
+ end
+ end
+
private
def update_ontology_summary_only
diff --git a/app/views/admin/categories/_form.html.haml b/app/views/admin/categories/_form.html.haml
index 1d72c63628..34bd8e82ae 100644
--- a/app/views/admin/categories/_form.html.haml
+++ b/app/views/admin/categories/_form.html.haml
@@ -14,7 +14,7 @@
%col{style: "width: 100%"}
%tr
%th
- Acronym:
+ Acronym
%span.asterik *
%td.top
- if new_record
@@ -23,21 +23,27 @@
= f.text_field :acronym, class: "form-control", readonly: true
%tr
%th
- Name:
+ Name
%span.asterik *
%td.top
= f.text_field :name, class: "form-control"
%tr
%th
- Description:
+ Description
%td.top
= f.text_area :description, class: "form-control"
- unless new_record
%tr
%th
- Created:
+ Created
%td.top
= f.text_field :created, readonly: true, class: "form-control"
+ %tr
+ %th
+ Ontologies
+ %td.top
+ = render SelectInputComponent.new(id: "category_ontologies", name: "category[ontologies]", values: @ontologies_category, selected: @category.ontologies, multiple: true, open_to_add_values: true)
+ %div.d-flex.mt-1{:style => "display: none;"}
%div.mt-2
= f.submit button_text, class: "btn btn-primary mr-sm-2 group-form-accept"
= link_to "Cancel", "javascript:;", class: "btn btn-primary dismiss-dialog"
\ No newline at end of file
diff --git a/app/views/admin/categories/edit.html.haml b/app/views/admin/categories/edit.html.haml
index b3706314da..b203c02ce3 100644
--- a/app/views/admin/categories/edit.html.haml
+++ b/app/views/admin/categories/edit.html.haml
@@ -3,4 +3,4 @@
%div
= form_for :category, url: admin_categories_path + "/" + escape(@category.acronym), method: "PATCH", remote: true, data: { collection: "categories"}, html: {class: "admin-collection-form" } do |f|
= render partial: "form", locals: {f: f, title_text: "Edit category",
- button_text: "Edit category", button_class: "edit-category"}
+ button_text: "Save", button_class: "edit-category"}
diff --git a/app/views/admin/groups/_form.html.haml b/app/views/admin/groups/_form.html.haml
index 628f648aef..ce5c958277 100644
--- a/app/views/admin/groups/_form.html.haml
+++ b/app/views/admin/groups/_form.html.haml
@@ -14,7 +14,7 @@
%col{style: "width: 100%"}
%tr
%th
- Acronym:
+ Acronym
%span.asterik *
%td.top
- if new_record
@@ -23,21 +23,26 @@
= f.text_field :acronym, class: "form-control", readonly: true
%tr
%th
- Name:
+ Name
%span.asterik *
%td.top
= f.text_field :name, class: "form-control"
%tr
%th
- Description:
+ Description
%td.top
= f.text_area :description, class: "form-control"
- unless new_record
%tr
%th
- Created:
+ Created
%td.top
= f.text_field :created, readonly: true, class: "form-control"
+ %tr
+ %th
+ Ontologies
+ %td.top
+ = render SelectInputComponent.new(id: "group_ontologies", name: "group[ontologies]", values: @ontologies_group , selected: @group.ontologies , multiple: true, open_to_add_values: true)
%div.mt-2
= f.submit button_text, class: "btn btn-primary mr-sm-2 group-form-accept"
= link_to "Cancel", "javascript:;", class: "btn btn-primary dismiss-dialog"
\ No newline at end of file
diff --git a/app/views/admin/groups/edit.html.haml b/app/views/admin/groups/edit.html.haml
index d51cf7123f..7269a374d0 100644
--- a/app/views/admin/groups/edit.html.haml
+++ b/app/views/admin/groups/edit.html.haml
@@ -3,4 +3,4 @@
%div
= form_for :group, url: admin_groups_path + "/" + escape(@group.acronym), method: "PATCH", remote: true, data: { collection: "groups"}, html: {class: "admin-collection-form" } do |f|
= render partial: "form", locals: {f: f, title_text: "Edit group",
- button_text: "Edit group", button_class: "edit-group"}
+ button_text: "Save", button_class: "edit-group"}