diff --git a/app/assets/stylesheets/dmpopidor.scss b/app/assets/stylesheets/dmpopidor.scss
index 80aa88e..6e2282e 100644
--- a/app/assets/stylesheets/dmpopidor.scss
+++ b/app/assets/stylesheets/dmpopidor.scss
@@ -1006,7 +1006,7 @@
}
/*
- * STRUCTURED ANSWERS
+ * maDMP FRAGMENTS
*/
.madmp-fragment {
.dynamic-field {
@@ -1045,6 +1045,14 @@
}
+ .fragment-display {
+ margin-top: 20px;
+ .sub-fragment {
+ border: 0.5px #ddd groove;
+ border-radius: 5px;
+ }
+ }
+
#modal-window {
.modal-dialog {
width: 50%;
diff --git a/app/controllers/madmp_fragments_controller.rb b/app/controllers/madmp_fragments_controller.rb
index 90b15ca..493ea78 100644
--- a/app/controllers/madmp_fragments_controller.rb
+++ b/app/controllers/madmp_fragments_controller.rb
@@ -6,11 +6,10 @@
def create_or_update
p_params = permitted_params()
- classname = params[:classname]
- schema = MadmpSchema.find_by(classname: classname)
+ schema = MadmpSchema.find(p_params[:schema_id])
+ classname = schema.classname
data = schema_params(schema)
-
# rubocop:disable BlockLength
MadmpFragment.transaction do
if p_params[:id].empty?
@@ -40,17 +39,17 @@
render json: {
"fragment_id" => @fragment.parent_id,
"classname" => classname,
- "html" => render_fragment_list(@fragment.dmp_id, @fragment.parent_id, classname)
+ "html" => render_fragment_list(@fragment.dmp_id, @fragment.parent_id, schema.id)
}
end
end
-
-
def new_edit_linked
- @classname = params[:classname]
+ @schema = MadmpSchema.find(params[:schema_id])
@parent_fragment = MadmpFragment.find(params[:parent_id])
- @schema = MadmpSchema.find_by(classname: @classname)
+ @classname = @schema.classname
+ @readonly = false
+
@fragment = nil
dmp_id = @parent_fragment.classname == "dmp" ? @parent_fragment.id : @parent_fragment.dmp_id
if params[:fragment_id]
@@ -68,6 +67,20 @@
end
end
+ def show_linked
+ @fragment = MadmpFragment.find(params[:fragment_id])
+ @schema = @fragment.madmp_schema
+ @classname = @fragment.classname
+ @parent_fragment = @fragment.parent
+ @readonly = true
+
+ authorize @fragment
+ respond_to do |format|
+ format.html
+ format.js { render :partial => "shared/dynamic_form/linked_fragment" }
+ end
+ end
+
def destroy
@fragment = MadmpFragment.find(params[:id])
classname = @fragment.classname
@@ -79,13 +92,13 @@
obj_list = MadmpFragment.where(
dmp_id: dmp_id,
parent_id: parent_id,
- classname: classname
+ madmp_schema_id: @fragment.madmp_schema_id
)
render json: {
"fragment_id" => parent_id,
"classname" => classname,
- "html" => render_fragment_list(dmp_id, parent_id, classname)
+ "html" => render_fragment_list(dmp_id, parent_id, @fragment.madmp_schema_id)
}
end
end
@@ -102,8 +115,9 @@
private
- def render_fragment_list(dmp_id, parent_id, classname)
- case classname
+ def render_fragment_list(dmp_id, parent_id, schema_id)
+ schema = MadmpSchema.find(schema_id)
+ case schema.classname
when "research_output"
@plan = Fragment::Dmp.where(id: dmp_id).first.plan
return render_to_string(partial: 'research_outputs/list', locals: {
@@ -116,12 +130,13 @@
obj_list = MadmpFragment.where(
dmp_id: dmp_id,
parent_id: parent_id,
- classname: classname
+ madmp_schema_id: schema.id
)
return render_to_string(partial: 'shared/dynamic_form/linked_fragment/list', locals: {
parent_id: parent_id,
obj_list: obj_list,
- classname: classname
+ schema: schema,
+ readonly: false
})
end
end
diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb
index 39315bc..8878657 100644
--- a/app/controllers/plans_controller.rb
+++ b/app/controllers/plans_controller.rb
@@ -209,6 +209,7 @@
end
# GET /plans/:plan_id/phases/:id/edit
+ # SEE MODULE
def edit
plan = Plan.find(params[:id])
authorize plan
@@ -476,6 +477,7 @@
# = Private instance methods =
# ============================
+ # SEE MODULE
def render_phases_edit(plan, phase, guidance_groups)
readonly = !plan.editable_by?(current_user.id)
# Since the answers have been pre-fetched through plan (see Plan.load_for_phase)
diff --git a/app/controllers/research_outputs_controller.rb b/app/controllers/research_outputs_controller.rb
index ec4f364..95219b8 100644
--- a/app/controllers/research_outputs_controller.rb
+++ b/app/controllers/research_outputs_controller.rb
@@ -41,7 +41,7 @@
@plan = Plan.find(params[:plan_id])
authorize @plan
params[:updated_order].each_with_index do |id, index|
- ResearchOutput.find(id).update(order: index)
+ ResearchOutput.find(id).update(order: index + 1)
end
head :ok
end
diff --git a/app/helpers/dynamic_form_helper.rb b/app/helpers/dynamic_form_helper.rb
index b0881ca..9d4aee9 100644
--- a/app/helpers/dynamic_form_helper.rb
+++ b/app/helpers/dynamic_form_helper.rb
@@ -1,6 +1,6 @@
module DynamicFormHelper
- def create_text_field(form, value, name, label, html_class: nil, is_multiple: false, index: 0)
+ def create_text_field(form, value, name, label, html_class: nil, is_multiple: false, readonly: false, index: 0)
render partial: 'shared/dynamic_form/fields/text_field',
locals: {
f: form,
@@ -10,13 +10,14 @@
field_name: name,
field_label: label,
field_class: html_class,
- input_type: nil
+ input_type: nil,
+ readonly: readonly
}
end
- def create_url_field(form, value, name, label, html_class: nil, is_multiple: false, index: 0)
+ def create_url_field(form, value, name, label, html_class: nil, is_multiple: false, readonly: false, index: 0)
render partial: 'shared/dynamic_form/fields/text_field',
locals: {
f: form,
@@ -26,13 +27,14 @@
field_name: name,
field_label: label,
field_class: html_class,
- input_type: 'url'
+ input_type: 'url',
+ readonly: readonly
}
end
- def create_email_field(form, value, name, label, html_class: nil, is_multiple: false, index: 0)
+ def create_email_field(form, value, name, label, html_class: nil, is_multiple: false, readonly: false, index: 0)
render partial: 'shared/dynamic_form/fields/text_field',
locals: {
f: form,
@@ -42,13 +44,14 @@
field_name: name,
field_label: label,
field_class: html_class,
- input_type: 'email'
+ input_type: 'email',
+ readonly: readonly
}
end
- def create_date_field(form, value, name, label, html_class: nil, is_multiple: false, index: 0)
+ def create_date_field(form, value, name, label, html_class: nil, is_multiple: false, readonly: false, index: 0)
render partial: 'shared/dynamic_form/fields/text_field',
locals: {
f: form,
@@ -58,13 +61,14 @@
field_name: name,
field_label: label,
field_class: html_class,
- input_type: 'date'
+ input_type: 'date',
+ readonly: readonly
}
end
- def create_number_field(form, value, name, label, html_class: nil, is_multiple: false, index: 0)
+ def create_number_field(form, value, name, label, html_class: nil, is_multiple: false, readonly: false, index: 0)
render partial: 'shared/dynamic_form/fields/number_field',
locals: {
f: form,
@@ -73,23 +77,25 @@
field_value: value,
field_name: name,
field_label: label,
- field_class: html_class
+ field_class: html_class,
+ readonly: readonly
}
end
- def create_checkbox_field(form, value, name, label, html_class: nil)
+ def create_checkbox_field(form, value, name, label, html_class: nil, readonly: false)
render partial: 'shared/dynamic_form/fields/checkbox_field',
locals: {
f: form,
field_value: value,
field_name: name,
- field_label: label
+ field_label: label,
+ readonly: readonly
}
end
- def create_select_field(form, value, name, label, select_values, html_class: nil)
+ def create_select_field(form, value, name, label, select_values, html_class: nil, readonly: false)
render partial: 'shared/dynamic_form/fields/select_field',
locals: {
f: form,
@@ -97,7 +103,8 @@
field_name: name,
field_label: label,
select_values: select_values,
- field_class: html_class
+ field_class: html_class,
+ readonly: readonly
}
end
@@ -105,8 +112,8 @@
# Formats the data extract from the structured answer form to valid JSON data
# This is useful because Rails converts all form data to strings and JSON needs the actual types
def data_reformater(schema, data)
- schema["properties"].each do |key, value|
- case value["type"]
+ schema["properties"].each do |key, prop|
+ case prop["type"]
when "integer"
data[key] = data[key].to_i
when "boolean"
@@ -114,6 +121,10 @@
when "array"
data[key] = data[key].kind_of?(Array) ? data[key] : [data[key]]
when "object"
+ if prop['schema_id'].present?
+ sub_schema = MadmpSchema.find(prop['schema_id'])
+ data[key] = data_reformater(sub_schema.schema, data[key])
+ end
# if value["dictionnary"]
# data[key] = JSON.parse(DictionnaryValue.where(id: data[key]).select(:id, :uri, :label).take.to_json)
# end
diff --git a/app/javascript/views/answers/edit.js b/app/javascript/views/answers/edit.js
index 8012460..ead84b5 100644
--- a/app/javascript/views/answers/edit.js
+++ b/app/javascript/views/answers/edit.js
@@ -54,7 +54,7 @@
$(`#answer-locking-${data.question.id}-research-output-${data.research_output.id}`).html(data.question.locking);
} else { // When answer is NOT stale...
$(`#answer-locking-${data.question.id}-research-output-${data.research_output.id}`).html('');
- $(`#answer-form-${data.question.id}-research-output-${data.research_output.id}`).html(data.question.form);
+ form.html(data.question.form);
if (isNumber(data.question.answer_lock_version)) {
form.find('#answer_lock_version').val(data.question.answer_lock_version);
}
@@ -92,7 +92,7 @@
const target = $(e.target);
const id = questionId(target);
if (!debounceMap[id]) {
- debounceMap[id] = debounce(autoSaving);
+ debounceMap[id] = debounce(autoSaving, 2000);
}
debounceMap[id](target);
};
diff --git a/app/models/madmp_fragment.rb b/app/models/madmp_fragment.rb
index 9d9e5d2..0dab9e2 100644
--- a/app/models/madmp_fragment.rb
+++ b/app/models/madmp_fragment.rb
@@ -93,6 +93,15 @@
self.madmp_schema.schema
end
+ def get_sub_fragments
+ sub_fragments = self.dmp.persons.group_by(&:madmp_schema_id)
+ unless self.children.empty?
+ sub_fragments.merge(self.children.group_by(&:madmp_schema_id))
+ end
+
+ sub_fragments
+ end
+
# Returns a human readable version of the structured answer
def to_s
displayable = ""
diff --git a/app/models/madmp_schema.rb b/app/models/madmp_schema.rb
index 6142735..3fee62a 100644
--- a/app/models/madmp_schema.rb
+++ b/app/models/madmp_schema.rb
@@ -50,11 +50,17 @@
label + " ( " + name + "_V" + version.to_s + " )"
end
+ def get_sub_schemas
+ path = JsonPath.new('$..schema_id')
+ ids = path.on(self.schema)
+ MadmpSchema.where(id: ids).map { |s| [s.id, s] }.to_h
+ end
+
def generate_strong_params(flat = false)
parameters = Array.new
self.schema['properties'].each do |key, prop|
- if prop['type'] == "object" && prop['classname'].present?
- sub_schema = MadmpSchema.find_by(classname: prop['classname'])
+ if prop['type'] == "object" && prop['schema_id'].present?
+ sub_schema = MadmpSchema.find(prop['schema_id'])
parameters.append(key => sub_schema.generate_strong_params(false))
elsif prop['type'] == "array" && !flat
parameters.append({key => []})
diff --git a/app/models/plan.rb b/app/models/plan.rb
index db1608b..9d519a5 100644
--- a/app/models/plan.rb
+++ b/app/models/plan.rb
@@ -228,10 +228,11 @@
# Pre-fetched a plan phase together with its sections and questions
# associated. It also pre-fetches the answers and notes associated to the plan
+ # CHANGES: Added PRELOAD for madmp_schema & research_output
def self.load_for_phase(plan_id, phase_id)
# Preserves the default order defined in the model relationships
- plan = Plan.joins(template: { phases: { sections: :questions } })
- .preload(template: { phases: { sections: :questions } })
+ plan = Plan.joins(:research_outputs, template: { phases: { sections: { questions: :madmp_schema } } })
+ .preload(:research_outputs, template: { phases: { sections: { questions: :madmp_schema } } })
.where(id: plan_id, phases: { id: phase_id })
.merge(Plan.includes(answers: :notes)).first
phase = plan.template.phases.find { |p| p.id == phase_id.to_i }
diff --git a/app/policies/madmp_fragment_policy.rb b/app/policies/madmp_fragment_policy.rb
index f593203..e466d5e 100644
--- a/app/policies/madmp_fragment_policy.rb
+++ b/app/policies/madmp_fragment_policy.rb
@@ -13,6 +13,9 @@
def new_edit_linked?
@fragment.plan.editable_by?(@user.id) || @user == @answer.plan.owner
end
+ def show_linked?
+ @fragment.plan.readable_by?(@user.id) || @user == @answer.plan.owner
+ end
def get_fragment?
@fragment.plan.editable_by?(@user.id) || @user == @answer.plan.owner
end
diff --git a/app/views/branded/answers/_new_edit.html.erb b/app/views/branded/answers/_new_edit.html.erb
index 7afd5b0..dcd5013 100644
--- a/app/views/branded/answers/_new_edit.html.erb
+++ b/app/views/branded/answers/_new_edit.html.erb
@@ -58,22 +58,27 @@
<%= hidden_field_tag :standards, answer_hash['standards'].to_json %>
<% end %>
<% end %>
-
>
- <% if question.option_based? || question.question_format.rda_metadata? %>
- <%= render(partial: 'questions/new_edit_question_option_based', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
- <% elsif question.question_format.structured %>
- <%= render(partial: 'questions/new_edit_question_structured', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
- <% elsif question.question_format.textfield?%>
- <%= render(partial: 'questions/new_edit_question_textfield', locals: { f: f, question: question, answer: answer, research_output: research_output }) %>
- <% elsif question.question_format.textarea? %>
- <%= render(partial: 'questions/new_edit_question_textarea', locals: { f: f, question: question, answer: answer, research_output: research_output, locking: locking, readonly: readonly}) %>
- <% elsif question.question_format.date? %>
- <%= render(partial: 'questions/new_edit_question_datefield', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
- <% elsif question.question_format.number? %>
- <%= render(partial: 'questions/new_edit_question_numberfield', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
- <% end %>
- <%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>
-
+ <% if question.question_format.structured %>
+
+ <%= render(partial: 'questions/new_edit_question_structured', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
+ <%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>
+
+ <% else %>
+ >
+ <% if question.option_based? || question.question_format.rda_metadata? %>
+ <%= render(partial: 'questions/new_edit_question_option_based', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
+ <% elsif question.question_format.textfield?%>
+ <%= render(partial: 'questions/new_edit_question_textfield', locals: { f: f, question: question, answer: answer, research_output: research_output }) %>
+ <% elsif question.question_format.textarea? %>
+ <%= render(partial: 'questions/new_edit_question_textarea', locals: { f: f, question: question, answer: answer, research_output: research_output, locking: locking, readonly: readonly}) %>
+ <% elsif question.question_format.date? %>
+ <%= render(partial: 'questions/new_edit_question_datefield', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
+ <% elsif question.question_format.number? %>
+ <%= render(partial: 'questions/new_edit_question_numberfield', locals: { f: f, question: question, answer: answer, research_output: research_output, readonly: readonly }) %>
+ <% end %>
+ <%= f.button(_('Save'), class: "btn btn-default", type: "submit") %>
+
+ <% end %>
<% if template.present? && template.org.present? %>
<% question.example_answers([base_template_org.id, template.org.id]).each do |annotation| %>
diff --git a/app/views/branded/plans/_form.html.erb b/app/views/branded/plans/_form.html.erb
new file mode 100644
index 0000000..d408525
--- /dev/null
+++ b/app/views/branded/plans/_form.html.erb
@@ -0,0 +1,157 @@
+
+
+
+ <%= form_for Plan.new, url: plans_path do |f| %>
+
+
+ <%= _('Project title') %>
+
+
+
+
+
+
<%= d_('dmpopidor', 'Choose a template') %>
+
+ <%= d_('dmpopidor', 'You can either choose a template provided by your organisation, another organisation or a funder template. The default template is ') %>
+ <%= @default_template.title + "." %>
+
+ <%= link_to d_('dmpopidor', 'Find the list of the available templates'), public_templates_path, :target => "_blank" %>
+
+
+
+
+
+ <% end %>
+
+
\ No newline at end of file
diff --git a/app/views/branded/plans/_form_v1.html.erb b/app/views/branded/plans/_form_v1.html.erb
deleted file mode 100644
index ce9b5de..0000000
--- a/app/views/branded/plans/_form_v1.html.erb
+++ /dev/null
@@ -1,96 +0,0 @@
-
-
- <%= form_for Plan.new, url: plans_path do |f| %>
-
-
- *
- <%= _('Project title') %>
-
-
-
-
-
<%= d_('dmpopidor', 'Choose a template') %>
-
- <%= d_('dmpopidor', 'Several template types are available:') %>
-
- <%= d_('dmpopidor', 'Organisation templates: Select the organisation and check "No funder"') %>
- <%= d_('dmpopidor', 'Funder templates: Check "No organisation" and select the funder') %>
- <%= d_('dmpopidor', 'Funder templates customized by an organisation: Select the organisation and select the funder') %>
- <%= raw("#{ d_('dmpopidor', 'Default template')} H2020 FAIR DMP (anglais) : #{ d_('dmpopidor', 'Check "No organisation" and check "No funder"')}") %>
-
- <%= link_to d_('dmpopidor', 'Find the list of the available templates'), public_templates_path, :target => "_blank" %>
-
-
<%= d_('dmpopidor', 'Select a research organisation:') %>
-
-
-
-
<%= d_('dmpopidor', 'Select a funder:') %>
-
-
-
-
- <%= hidden_field_tag 'template-option-target', org_admin_template_options_path %>
-
<%= d_('dmpopidor', 'Select a template:') %>
-
-
-
- <%= f.hidden_field(:visibility, value: @is_test ? 'is_test' : Rails.application.config.default_plan_visibility) %>
- <%= f.button(_('Create plan'), class: "btn btn-primary", type: "submit") %>
- <%= link_to _('Cancel'), plans_path, class: 'btn btn-default' %>
- <% end %>
-
-
diff --git a/app/views/branded/plans/_form_v2.html.erb b/app/views/branded/plans/_form_v2.html.erb
deleted file mode 100644
index d408525..0000000
--- a/app/views/branded/plans/_form_v2.html.erb
+++ /dev/null
@@ -1,157 +0,0 @@
-
-
-
- <%= form_for Plan.new, url: plans_path do |f| %>
-
-
- <%= _('Project title') %>
-
-
-
-
-
-
<%= d_('dmpopidor', 'Choose a template') %>
-
- <%= d_('dmpopidor', 'You can either choose a template provided by your organisation, another organisation or a funder template. The default template is ') %>
- <%= @default_template.title + "." %>
-
- <%= link_to d_('dmpopidor', 'Find the list of the available templates'), public_templates_path, :target => "_blank" %>
-
-
-
-
-
- <% end %>
-
-
\ No newline at end of file
diff --git a/app/views/branded/plans/_show_details.html.erb b/app/views/branded/plans/_show_details.html.erb
new file mode 100644
index 0000000..2a1b17e
--- /dev/null
+++ b/app/views/branded/plans/_show_details.html.erb
@@ -0,0 +1,30 @@
+<% meta_fragment = @plan.json_fragment().meta%>
+<% project_fragment = @plan.json_fragment().project%>
+
+
+
+
+ <%= render(partial: 'shared/fragments/display', locals: {
+ fragment: meta_fragment,
+ schema: meta_fragment.madmp_schema,
+ classname: "meta"
+ } ) %>
+
+
+
+ <%= render(partial: 'shared/fragments/display', locals: {
+ fragment: project_fragment,
+ schema: project_fragment.madmp_schema,
+ classname: "project"
+ } ) %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/branded/plans/new.html.erb b/app/views/branded/plans/new.html.erb
index 9fabc88..239cdec 100644
--- a/app/views/branded/plans/new.html.erb
+++ b/app/views/branded/plans/new.html.erb
@@ -1,9 +1,5 @@
<% if current_user.org.active? %>
- <% if params[:v1] == "true" %>
- <%= render "form_v1" %>
- <% else %>
- <%= render "form_v2" %>
- <% end %>
+ <%= render "form" %>
<% else%>
diff --git a/app/views/branded/plans/plan_details/_plan_funding_form.html.erb b/app/views/branded/plans/plan_details/_plan_funding_form.html.erb
deleted file mode 100644
index e119f61..0000000
--- a/app/views/branded/plans/plan_details/_plan_funding_form.html.erb
+++ /dev/null
@@ -1,74 +0,0 @@
-<%# locals: { fragment } %>
-
- <%= _('Funder') %>
-
- <%= create_text_field(
- f,
- fragment && fragment["funder"] ? fragment["funder"]["name"] : nil,
- "funder[name]",
- _('Name')
- )
- %>
-
-
- <%= create_text_field(
- f,
- fragment && fragment["funder"] && fragment["funder"]["funderId"] ? fragment["funder"]["funderId"]["value"] : nil,
- "funder[funderId[value]]",
- _('Identifiant')
- )
- %>
-
-
- <%= create_select_field(
- f,
- fragment && fragment["funder"] && fragment["funder"]["funderId"] ? fragment["funder"]["funderId"]["idType"] : "ROR",
- "madmp_fragment[funder[funderId[idType]]]",
- _('Identifier Type'),
- ["ROR", "ISSNI", "RNSR", "FundRef"]
- )
- %>
-
-
- <%= create_url_field(
- f,
- fragment && fragment["funder"] ? fragment["funder"]["dataPolicyUrl"] : nil,
- "funder[dataPolicyUrl]",
- _('Data Policy URL')
- )
- %>
-
-
-
-
- <%= _('Grant ID') %>
-
- <%= create_text_field(
- f,
- fragment && fragment["grantId"] ? fragment["grantId"]["value"] : nil,
- "grantId[value]",
- _('Value')
- )
- %>
-
-
- <%= create_select_field(
- f,
- fragment && fragment["grantId"] ? fragment["grantId"]["idType"] : "DOI",
- "madmp_fragment[grantId[idType]]",
- _('Identifier Type'),
- ["DOI", "URL"]
- )
- %>
-
-
-
- <%= create_select_field(
- f,
- fragment ? fragment["fundingStatus"] : "Planned",
- "madmp_fragment[fundingStatus]",
- _('Funding Status'),
- ["Planned","Applied", "Granted", "Rejected"]
- )
- %>
-
\ No newline at end of file
diff --git a/app/views/branded/plans/plan_details/_plan_metadata.html.erb b/app/views/branded/plans/plan_details/_plan_metadata.html.erb
index 478fc95..249f910 100644
--- a/app/views/branded/plans/plan_details/_plan_metadata.html.erb
+++ b/app/views/branded/plans/plan_details/_plan_metadata.html.erb
@@ -2,7 +2,6 @@
<% meta = meta_fragment.data %>
<% contact = meta_fragment.contact %>
<% dmpID = meta["dmpID"] %>
-<% p_version = meta["version"] %>
<% licence = meta["licence"] %>
@@ -60,17 +59,17 @@
<%= create_text_field(
f,
- p_version ? p_version["versionNumber"] : nil,
- "version[versionNumber]",
+ meta["versionNumber"],
+ "versionNumber",
_('Number')
)
%>
<%= create_text_field(
- f,
- p_version ? p_version["versionNotes"] : nil,
- "version[versionNotes]",
+ f,
+ meta["versionNotes"],
+ "versionNotes",
_('Notes')
)
%>
@@ -78,12 +77,17 @@
- <%= create_text_field(
- f,
- meta["relatedDocUrl"],
- "relatedDocUrl",
- _('Related Documentation URL')
- )
+ <%= render(partial: 'shared/dynamic_form/fields/simple_multiple_field', locals: {
+ f: f,
+ field_values: meta["relatedDocUrl"],
+ readonly: false,
+ field_label: _('Related Documentation URL'),
+ field_properties: {
+ "type" => "string",
+ "format" => "uri"
+ },
+ field_name: "relatedDocUrl", answer_id: nil
+ })
%>
diff --git a/app/views/branded/plans/plan_details/_plan_partner_form.html.erb b/app/views/branded/plans/plan_details/_plan_partner_form.html.erb
deleted file mode 100644
index aafc7cd..0000000
--- a/app/views/branded/plans/plan_details/_plan_partner_form.html.erb
+++ /dev/null
@@ -1,44 +0,0 @@
-<%# locals: { fragment } %>
-
-
- <%= create_text_field(
- f,
- fragment ? fragment["name"] : nil,
- "name",
- _('Name')
- )
- %>
-
-
-
- <%= _('Org ID') %>
-
- <%= create_text_field(
- f,
- fragment && fragment["orgId"] ? fragment["orgId"]["value"] : nil,
- "orgId[value]",
- _('ID')
- )
- %>
-
-
- <%= create_select_field(
- f,
- fragment && fragment["orgId"] ? fragment["orgId"]["idType"] : "ROR",
- "madmp_fragment[orgId[idType]]",
- _('Identifier Type'),
- ["ROR", "ISSNI", "RNSR"]
- )
- %>
-
-
-
-
- <%= create_url_field(
- f,
- fragment ? fragment["dataPolicyUrl"] : nil,
- "dataPolicyUrl",
- _('Data Policy URL')
- )
- %>
-
\ No newline at end of file
diff --git a/app/views/branded/plans/plan_details/_plan_project.html.erb b/app/views/branded/plans/plan_details/_plan_project.html.erb
index bcd5f9b..ad4f9ca 100644
--- a/app/views/branded/plans/plan_details/_plan_project.html.erb
+++ b/app/views/branded/plans/plan_details/_plan_project.html.erb
@@ -48,7 +48,8 @@
<%= render(partial: 'shared/dynamic_form/fields/complex_multiple_field', locals: {
field_values: fundings,
parent_id: project_fragment.id,
- classname: "funding",
+ schema: MadmpSchema.find_by(classname: "funding"),
+ readonly: false,
field_name: "funding", answer_id: nil
}
) %>
@@ -75,7 +76,8 @@
<%= render(partial: 'shared/dynamic_form/fields/complex_multiple_field', locals: {
field_values: partners,
parent_id: project_fragment.id,
- classname: "partner",
+ schema: MadmpSchema.find_by(classname: "partner"),
+ readonly: false,
field_name: "partner", answer_id: nil
}
) %>
diff --git a/app/views/branded/questions/_new_edit_question_structured.erb b/app/views/branded/questions/_new_edit_question_structured.erb
index 2aee9d6..c87bbaa 100644
--- a/app/views/branded/questions/_new_edit_question_structured.erb
+++ b/app/views/branded/questions/_new_edit_question_structured.erb
@@ -1,14 +1,12 @@
<%= f.label(:text, sanitize(question.text), class: 'control-label') unless question.nil? %>
-<% data = answer.madmp_fragment.data unless answer.madmp_fragment.nil? %>
<% fragment_id = answer.madmp_fragment.nil? ? nil : answer.madmp_fragment.id %>
<% classname = answer.madmp_fragment.classname unless answer.madmp_fragment.nil? %>
<%= render(partial: 'shared/dynamic_form/form', locals: {
f: f,
- data: data,
+ fragment: answer.madmp_fragment,
+ schema: question.madmp_schema,
readonly: readonly,
- research_output: research_output,
- schema: question.madmp_schema.schema,
classname: classname,
fragment_id: fragment_id
}) %>
diff --git a/app/views/branded/research_outputs/_list.html.erb b/app/views/branded/research_outputs/_list.html.erb
index e67e608..6fda2a5 100644
--- a/app/views/branded/research_outputs/_list.html.erb
+++ b/app/views/branded/research_outputs/_list.html.erb
@@ -25,6 +25,7 @@
nil,
:fragment_id => research_output_fragment.id,
:parent_id => research_output_fragment.dmp_id,
+ :schema_id => MadmpSchema.find_by(classname: "research_output").id,
:classname => "research_output"
), {
:remote => true,
diff --git a/app/views/branded/shared/dynamic_form/_form.html.erb b/app/views/branded/shared/dynamic_form/_form.html.erb
index f1191e9..52f9a18 100644
--- a/app/views/branded/shared/dynamic_form/_form.html.erb
+++ b/app/views/branded/shared/dynamic_form/_form.html.erb
@@ -1,31 +1,39 @@
-<%# locals: { f, data, research_output, schema, parent_id } %>
-<% schema['properties'].each do |key, prop| %>
+<%# locals: { f, fragment, schema, readonly, classname, Fragment_id } %>
+<% sub_schemas = schema.get_sub_schemas %>
+<% data = fragment.data unless fragment.nil? %>
+<% sub_fragments = fragment.present? ? fragment.get_sub_fragments() : [] %>
+<% schema_properties = schema.schema["properties"]%>
+
+<% schema_properties.each do |key, prop| %>
<% value = data[key] unless data.nil? %>
<% field_name = defined?(form_prefix) ? "#{form_prefix}[#{key}]" : key %>
<% case prop['type'] %>
<% when 'string' %>
<% if prop['format'].nil?%>
- <%= create_text_field(f, value, field_name, prop['label']) %>
+ <%= create_text_field(f, value, field_name, prop['label'], readonly: readonly) %>
<% elsif prop['format'] == 'date' %>
- <%= create_date_field(f, value, field_name, prop['label']) %>
+ <%= create_date_field(f, value, field_name, prop['label'], readonly: readonly) %>
<% elsif prop['format'] == 'uri' %>
- <%= create_url_field(f, value, field_name, prop['label']) %>
+ <%= create_url_field(f, value, field_name, prop['label'], readonly: readonly) %>
<% elsif prop['format'] == 'email' %>
- <%= create_email_field(f, value, field_name, prop['label']) %>
+ <%= create_email_field(f, value, field_name, prop['label'], readonly: readonly) %>
<% elsif prop['format'] == 'select' && prop['values'] %>
- <%= create_select_field(f, value, "#{f.object_name}[#{field_name}]", prop['label'], prop['values']) %>
+ <%= create_select_field(f, value, "#{f.object_name}[#{field_name}]", prop['label'], prop['values'], readonly: readonly) %>
<%end%>
<% when 'integer' %>
- <%= create_number_field(f, value, field_name, prop['label']) %>
+ <%= create_number_field(f, value, field_name, prop['label'], readonly: readonly) %>
<% when 'boolean' %>
- <%= create_checkbox_field(f, value, field_name, prop['label']) %>
+ <%= create_checkbox_field(f, value, field_name, prop['label'], readonly: readonly) %>
<% when 'array' %>
- <% if prop['items']['type'] == 'object' %>
+ <% if prop['items']['type'] == 'object' && prop['items']['schema_id'].present? %>
<% unless classname == "research_output" %>
+ <% sub_schema = sub_schemas[prop['items']['schema_id']] %>
+ <% values = sub_fragments[prop['items']['schema_id']] unless sub_fragments.empty? %>
<%= render(partial: 'shared/dynamic_form/fields/complex_multiple_field', locals: {
- field_values: MadmpFragment.where(parent_id: fragment_id, classname: prop['items']['classname']),
+ field_values: values,
+ readonly: readonly,
parent_id: fragment_id,
- classname: prop['items']['classname'],
+ schema: sub_schema,
field_name: field_name, answer_id: nil
}
) %>
@@ -34,6 +42,7 @@
<%= render(partial: 'shared/dynamic_form/fields/simple_multiple_field', locals: {
f: f,
field_values: value,
+ readonly: readonly,
field_label: prop['label'],
field_properties: prop['items'],
field_name: field_name, answer_id: nil
@@ -41,26 +50,33 @@
) %>
<% end %>
<% when 'object' %>
- <% if !prop["classname"].nil? || classname != "research_output" %>
-
-
- <%= field_name %>
- <%
- sub_schema = prop["classname"] ?
- MadmpSchema.find_by(classname: prop["classname"]).schema :
- prop
- %>
- <%= render(partial: 'shared/dynamic_form/form', locals: {
- f: f,
- data: value,
- readonly: readonly,
- schema: sub_schema,
- classname: prop["classname"],
- fragment_id: fragment_id,
- form_prefix: prop["classname"]
- }) %>
-
-
+ <% if prop["schema_id"].present? %>
+ <% unless classname == "research_output" %>
+
+
+ <%= field_name %>
+ <%
+ sub_schema = sub_schemas[prop["schema_id"]]
+ sub_fragment = MadmpFragment.new(
+ data: value,
+ dmp_id: fragment.dmp_id,
+ parent_id: fragment_id
+ ) unless fragment.nil?
+ # TODO : SINGLE SUB FRAGMENT SAVING
+ #sub_fragment = sub_fragments[sub_schema.id].find { |f| f.id == value["dbId"] } unless value.nil?
+ %>
+ <%= render(partial: 'shared/dynamic_form/form', locals: {
+ f: f,
+ fragment: sub_fragment,
+ schema: sub_schema,
+ readonly: readonly,
+ classname: sub_schema.classname,
+ fragment_id: fragment_id,
+ form_prefix: field_name
+ }) %>
+
+
+ <% end %>
<% end %>
<% end %>
<% end %>
\ No newline at end of file
diff --git a/app/views/branded/shared/dynamic_form/_modal.html.erb b/app/views/branded/shared/dynamic_form/_modal.html.erb
index 79f1052..059317f 100644
--- a/app/views/branded/shared/dynamic_form/_modal.html.erb
+++ b/app/views/branded/shared/dynamic_form/_modal.html.erb
@@ -6,26 +6,27 @@
×
- <%= form_for @fragment, url: create_or_update_madmp_fragments_path(@fragment.id, classname: @classname),
+ <%= form_for @fragment, url: create_or_update_madmp_fragments_path(@fragment.id),
html: {method: :post, remote: true, class: 'form-horizontal', id: "madmp_fragment_form" } do |f| %>
<%= f.hidden_field :dmp_id, id: nil %>
<%= f.hidden_field :parent_id, id: nil %>
<%= f.hidden_field :id, id: nil %>
<%= f.hidden_field :schema_id, :value => @schema.id, id: nil%>
- <%= render(partial: "shared/dynamic_form/form", locals: {
- f: f,
- data: @fragment.data,
- research_output: nil,
- fragment_id: @parent_fragment.id,
- schema: @schema.schema,
- classname: @classname,
- readonly: false
- })%>
+
>
+ <%= render(partial: "shared/dynamic_form/form", locals: {
+ f: f,
+ fragment: @fragment,
+ fragment_id: @parent_fragment.id,
+ schema: @schema,
+ classname: @classname,
+ readonly: false
+ })%>
+
<% end %>
diff --git a/app/views/branded/shared/dynamic_form/fields/_checkbox_field.html.erb b/app/views/branded/shared/dynamic_form/fields/_checkbox_field.html.erb
index 560b3d1..f5b8150 100644
--- a/app/views/branded/shared/dynamic_form/fields/_checkbox_field.html.erb
+++ b/app/views/branded/shared/dynamic_form/fields/_checkbox_field.html.erb
@@ -4,5 +4,9 @@
<%= f.label check_box, field_label, class: 'control-label' %>
- <%= f.number_field field_name, value: field_value, multiple: multiple, class: "form-control #{field_class}" %>
+ <%= f.number_field field_name,
+ value: field_value,
+ multiple: multiple,
+ disabled: readonly,
+ class: "form-control #{field_class}" %>
diff --git a/app/views/branded/shared/dynamic_form/fields/_complex_multiple_field.html.erb b/app/views/branded/shared/dynamic_form/fields/_complex_multiple_field.html.erb
index 9019388..b8ae46b 100644
--- a/app/views/branded/shared/dynamic_form/fields/_complex_multiple_field.html.erb
+++ b/app/views/branded/shared/dynamic_form/fields/_complex_multiple_field.html.erb
@@ -1,9 +1,9 @@
-<%# locals: { field_values, parent_id, classname, field_name } %>
+<%# locals: { field_values, parent_id, schema, field_name } %>
<% field_values = [] if field_values.nil? %>
<%= field_name.capitalize.pluralize(2) %>
-
+
<%= field_name.capitalize %> Actions
@@ -11,16 +11,17 @@
<%= render(partial: 'shared/dynamic_form/linked_fragment/list', locals: {
obj_list: field_values,
parent_id: parent_id,
- classname: classname
+ schema: schema,
+ readonly: readonly
}
) %>
- <% unless parent_id.nil?%>
+ <% unless parent_id.nil? || readonly %>
<%= link_to 'Create', new_edit_linked_madmp_fragments_url(
nil,
:parent_id => parent_id,
- :classname => classname
+ :schema_id => schema.id
), {
:remote => true,
:class => "btn btn-primary",
diff --git a/app/views/branded/shared/dynamic_form/fields/_date_field.html.erb b/app/views/branded/shared/dynamic_form/fields/_date_field.html.erb
index 93a734f..71b0048 100644
--- a/app/views/branded/shared/dynamic_form/fields/_date_field.html.erb
+++ b/app/views/branded/shared/dynamic_form/fields/_date_field.html.erb
@@ -6,7 +6,11 @@
<% end %>
- <%= f.text_field field_name, value: field_value, multiple: multiple, class: "form-control #{field_class}", type: "date" %>
+ <%= f.text_field field_name,
+ value: field_value,
+ multiple: multiple,
+ disabled: readonly,
+ class: "form-control #{field_class}", type: "date" %>
<% if multiple %>
diff --git a/app/views/branded/shared/dynamic_form/fields/_number_field.html.erb b/app/views/branded/shared/dynamic_form/fields/_number_field.html.erb
index 280973e..7ea54fd 100644
--- a/app/views/branded/shared/dynamic_form/fields/_number_field.html.erb
+++ b/app/views/branded/shared/dynamic_form/fields/_number_field.html.erb
@@ -6,7 +6,11 @@
<% end %>
- <%= f.number_field field_name, value: field_value, multiple: multiple, class: "form-control #{field_class}" %>
+ <%= f.number_field field_name,
+ value: field_value,
+ multiple: multiple,
+ disabled: readonly,
+ class: "form-control #{field_class}" %>
<% if multiple %>
diff --git a/app/views/branded/shared/dynamic_form/fields/_select_field.html.erb b/app/views/branded/shared/dynamic_form/fields/_select_field.html.erb
index eff68bf..b5e453b 100644
--- a/app/views/branded/shared/dynamic_form/fields/_select_field.html.erb
+++ b/app/views/branded/shared/dynamic_form/fields/_select_field.html.erb
@@ -6,5 +6,6 @@
<%= select_tag field_name,
options_for_select(select_values,
selected: selected_value),
+ disabled: readonly,
class: "form-control #{field_class}" %>
\ No newline at end of file
diff --git a/app/views/branded/shared/dynamic_form/fields/_simple_multiple_field.html.erb b/app/views/branded/shared/dynamic_form/fields/_simple_multiple_field.html.erb
index 2b4648d..430e5b0 100644
--- a/app/views/branded/shared/dynamic_form/fields/_simple_multiple_field.html.erb
+++ b/app/views/branded/shared/dynamic_form/fields/_simple_multiple_field.html.erb
@@ -1,4 +1,4 @@
-<%# locals: { f, field_label, field_name, select_values, selected_value, field_class } %>
+<%# locals: { f, field_values, readonly, field_label, field_properties, field_name } %>
<%= f.label field_name, field_label, class: 'control-label' %>
@@ -7,16 +7,16 @@
<% case field_properties["type"] %>
<% when "string" %>
<% if field_properties['format'].nil?%>
- <%= create_text_field(f, value, field_name, field_label, is_multiple: true, index: idx) %>
+ <%= create_text_field(f, value, field_name, field_label, is_multiple: true, readonly: readonly, index: idx) %>
<% elsif field_properties['format'] == 'date' %>
- <%= create_date_field(f, value, field_name, field_label, is_multiple: true, index: idx) %>
+ <%= create_date_field(f, value, field_name, field_label, is_multiple: true, readonly: readonly, index: idx) %>
<% elsif field_properties['format'] == 'uri' %>
- <%= create_url_field(f, value, field_name, field_label, is_multiple: true, index: idx) %>
+ <%= create_url_field(f, value, field_name, field_label, is_multiple: true, readonly: readonly, index: idx) %>
<% elsif field_properties['format'] == 'email' %>
- <%= create_email_field(f, value, field_name, field_label, is_multiple: true, index: idx) %>
+ <%= create_email_field(f, value, field_name, field_label, is_multiple: true, readonly: readonly, index: idx) %>
<%end%>
<% when "integer" %>
- <%= create_number_field(f, value, field_name, field_label, is_multiple: true, index: idx)%>
+ <%= create_number_field(f, value, field_name, field_label, is_multiple: true, readonly: readonly, index: idx)%>
<% when "boolean" %>
<%= create_checkbox_field(f, value, field_name, field_label)%>
<% end %>
@@ -25,16 +25,16 @@
<% case field_properties["type"] %>
<% when "string" %>
<% if field_properties['format'].nil?%>
- <%= create_text_field(f, nil, field_name, field_label, is_multiple: true, index: 0) %>
+ <%= create_text_field(f, nil, field_name, field_label, is_multiple: true, readonly: readonly, index: 0) %>
<% elsif field_properties['format'] == 'date' %>
- <%= create_date_field(f, nil, field_name, field_label, is_multiple: true, index: 0) %>
+ <%= create_date_field(f, nil, field_name, field_label, is_multiple: true, readonly: readonly, index: 0) %>
<% elsif field_properties['format'] == 'uri' %>
- <%= create_url_field(f, nil, field_name, field_label, is_multiple: true, index: 0) %>
+ <%= create_url_field(f, nil, field_name, field_label, is_multiple: true, readonly: readonly, index: 0) %>
<% elsif field_properties['format'] == 'email' %>
- <%= create_email_field(f, nil, field_name, field_label, is_multiple: true, index: 0) %>
+ <%= create_email_field(f, nil, field_name, field_label, is_multiple: true, readonly: readonly, index: 0) %>
<%end%>
<% when "integer" %>
- <%= create_number_field(f, nil, field_name, field_label, is_multiple: true, index: 0)%>
+ <%= create_number_field(f, nil, field_name, field_label, is_multiple: true, readonly: readonly, index: 0)%>
<% when "boolean" %>
<%= create_checkbox_field(f, nil, field_name, field_label)%>
<% end %>
diff --git a/app/views/branded/shared/dynamic_form/fields/_text_field.html.erb b/app/views/branded/shared/dynamic_form/fields/_text_field.html.erb
index 66c0d32..2395a07 100644
--- a/app/views/branded/shared/dynamic_form/fields/_text_field.html.erb
+++ b/app/views/branded/shared/dynamic_form/fields/_text_field.html.erb
@@ -1,12 +1,17 @@
-<%# locals: { f, field_label, field_name, multiple, classname, field_name } %>
+<%# locals: { f, field_label, field_name, multiple, classname, field_name, readonly } %>
<% unless multiple %>
<%= f.label field_name, field_label, class: 'control-label' %>
<% end %>
- <%= f.text_field field_name, value: field_value, multiple: multiple, class: "form-control #{field_class}", type: input_type %>
- <% if multiple %>
+ <%= f.text_field field_name,
+ value: field_value,
+ multiple: multiple,
+ disabled: readonly,
+ class: "form-control #{field_class}",
+ type: input_type %>
+ <% if multiple && readonly == false%>
<% if index != 0 %>
diff --git a/app/views/branded/shared/dynamic_form/linked_fragment/_list.html.erb b/app/views/branded/shared/dynamic_form/linked_fragment/_list.html.erb
index 5ef87f3..0fb1173 100644
--- a/app/views/branded/shared/dynamic_form/linked_fragment/_list.html.erb
+++ b/app/views/branded/shared/dynamic_form/linked_fragment/_list.html.erb
@@ -1,23 +1,35 @@
+<%# locals: { obj_list, parent_id, schema, readonly } %>
<% obj_list.each do |obj| %>
<%= obj.to_s %>
- <%= link_to new_edit_linked_madmp_fragments_url(
- nil,
- :fragment_id => obj.id,
- :parent_id => parent_id,
- :classname => classname
- ), {
- :remote => true,
- 'data-toggle' => "modal",
- 'data-target' => '#modal-window'
- } do %>
- <%= _('Edit') %>
+ <% if readonly %>
+ <%= link_to show_linked_madmp_fragments_url(
+ :fragment_id => obj.id
+ ), {
+ :remote => true,
+ 'data-toggle' => 'modal',
+ 'data-target' => '#modal-window'
+ } do %>
+ <%= _('View') %>
+ <% end %>
+ <% else %>
+ <%= link_to new_edit_linked_madmp_fragments_url(
+ :fragment_id => obj.id,
+ :parent_id => parent_id,
+ :schema_id => schema.id
+ ), {
+ :remote => true,
+ 'data-toggle' => 'modal',
+ 'data-target' => '#modal-window'
+ } do %>
+ <%= _('Edit') %>
+ <% end %>
+ <%= _('Delete') %>
<% end %>
- <%= _('Delete') %>
<% end %>
\ No newline at end of file
diff --git a/app/views/branded/shared/export/_display_madmp_fragment.erb b/app/views/branded/shared/export/_display_madmp_fragment.erb
new file mode 100644
index 0000000..b5fe4c1
--- /dev/null
+++ b/app/views/branded/shared/export/_display_madmp_fragment.erb
@@ -0,0 +1,67 @@
+<% sub_schemas = schema.get_sub_schemas %>
+<% data = fragment.data unless fragment.nil? %>
+<% sub_fragments = fragment.present? ? fragment.get_sub_fragments() : [] %>
+<% schema_properties = schema.schema["properties"]%>
+
+ <% schema_properties.each do |key, prop| %>
+
+ <% value = data[key] unless data.nil? %>
+ <% field_name = defined?(form_prefix) ? "#{form_prefix}[#{key}]" : key %>
+ <% case prop['type'] %>
+ <% when 'boolean' %>
+ <%= field_name %>
+ <%= value ? _('Yes') : _('No') %>
+ <% when 'array' %>
+ <% if prop['items']['type'] == 'object' && prop['items']['schema_id'].present? %>
+ <%
+ sub_schema = sub_schemas[prop['items']['schema_id']]
+ %>
+ <% unless sub_fragments[sub_schema.id].nil? %>
+
+
+ <%= field_name.capitalize.pluralize(2) %>
+
+ <% sub_fragments[sub_schema.id].each do |val| %>
+
+ <%= render(partial: 'shared/export/display_madmp_fragment', locals: {
+ fragment: val,
+ schema: sub_schema,
+ classname: sub_schema.classname
+ } ) %>
+
+ <% end %>
+
+
+
+ <% end %>
+ <% else %>
+ <%= field_name %>
+
+ <% value.each do |val| %>
+ <%= val %>
+ <% end %>
+
+ <% end %>
+ <% when 'object' %>
+ <% if prop["schema_id"].present? %>
+ <% unless value.nil? %>
+ <%
+ sub_schema = sub_schemas[prop["schema_id"]]
+ %>
+ <%= field_name.capitalize %>
+
+ <%= render(partial: 'shared/export/display_madmp_fragment', locals: {
+ fragment: sub_fragments[sub_schema.id], #TODO : Implement Person fragments display
+ schema: sub_schema,
+ classname: sub_schema.classname
+ } ) %>
+
+ <% end %>
+ <% end %>
+ <% else%>
+ <%= field_name %>
+ <%= value %>
+ <% end %>
+
+ <% end %>
+
\ No newline at end of file
diff --git a/app/views/branded/shared/export/_export_by_question.erb b/app/views/branded/shared/export/_export_by_question.erb
index 398771c..9365359 100644
--- a/app/views/branded/shared/export/_export_by_question.erb
+++ b/app/views/branded/shared/export/_export_by_question.erb
@@ -11,6 +11,7 @@
@plan.answer(question[:id], false, research_output[:id]) %>
<% blank = answer.present? ? answer.is_blank? : true %>
<% options = answer.present? ? answer.question_options : [] %>
+ <% fragment = answer.present? ? answer.madmp_fragment : nil %>
<% unless @show_unanswered == false && blank %>
@@ -33,44 +34,46 @@
<% end %>
+
<%# case where question has not been answered sufficiently to display%>
- <% if @show_unanswered && (answer.blank? || (options.blank? && blank))%>
-
-
- <%= _('Question not answered.') -%>
-
-
-
- <% else %>
-
- <%# case where Question has options %>
- <% if options.any? %>
-
- <% options.each do |opt| %>
- <%= opt.text %>
+ <% if @show_unanswered %>
+ <%# case where Question has options %>
+ <% if options.any? %>
+
+ <% options.each do |opt| %>
+ <%= opt.text %>
+ <% end %>
+
<% end %>
-
- <% end %>
- <%# case for RDA answer display %>
- <% if question[:format].rda_metadata? && !blank %>
- <% ah = answer.answer_hash %>
- <% if ah['standards'].present? %>
+ <% if question[:format].rda_metadata? && !blank %>
+ <% ah = answer.answer_hash %>
+ <% if ah['standards'].present? %>
<% ah['standards'].each do |id, title| %>
<%= title %>
<% end %>
- <% end %>
-
<%= sanitize ah['text'] %>
-
- <%# case for displaying comments OR text %>
- <% elsif !blank %>
-
+ <% end %>
+
<%= sanitize ah['text'] %>
+
+ <% elsif question[:format].structured? && fragment.present? %>
+ <%= render partial: 'shared/export/display_madmp_fragment',
+ locals: {
+ fragment: fragment,
+ schema: fragment.madmp_schema,
+ classname: fragment.classname
+ } %>
+ <%# case for displaying comments OR text %>
+ <% elsif !blank %>
<%= sanitize answer.text %>
-
- <% end %>
-
+ <% else %>
+
+
<%= _('Question not answered.') -%>
+
+
+ <% end %>
+
<% end %>
<% end %>
<% if section_has_common_answers %>
diff --git a/app/views/branded/shared/export/_export_by_research_output.erb b/app/views/branded/shared/export/_export_by_research_output.erb
index ae5ff03..e9d43b6 100644
--- a/app/views/branded/shared/export/_export_by_research_output.erb
+++ b/app/views/branded/shared/export/_export_by_research_output.erb
@@ -22,9 +22,10 @@
@plan.answer(question[:id], false, research_output[:id]) %>
<% blank = answer.present? ? answer.is_blank? : true %>
<% options = answer.present? ? answer.question_options : [] %>
- <% unless @show_unanswered == false && blank %>
-
- <% if !@public_plan && @show_sections_questions%>
+ <% fragment = answer.present? ? answer.madmp_fragment : nil %>
+ <% unless @show_unanswered == false && blank %>
+
+ <% if !@public_plan && @show_sections_questions%>
<%# Hack: for DOCX export - otherwise, bold highlighting of question inconsistent. %>
<% if local_assigns[:export_format] && export_format == 'docx' %>
@@ -35,15 +36,9 @@
- <% end %>
- <%# case where question has not been answered sufficiently to display%>
- <% if @show_unanswered && (answer.blank? || (options.blank? && blank))%>
-
-
<%= _('Question not answered.') -%>
-
-
- <% else %>
-
+ <% end %>
+ <%# case where question has not been answered sufficiently to display%>
+ <% if @show_unanswered %>
<%# case where Question has options %>
<% if options.any? %>
@@ -52,7 +47,6 @@
<% end %>
<% end %>
- <%# case for RDA answer display %>
<% if question[:format].rda_metadata? && !blank %>
<% ah = answer.answer_hash %>
<% if ah['standards'].present? %>
@@ -64,16 +58,28 @@
<% end %>
<%= sanitize ah['text'] %>
+ <% elsif question[:format].structured? && fragment.present? %>
+ <%= render partial: 'shared/export/display_madmp_fragment',
+ locals: {
+ fragment: fragment,
+ schema: fragment.madmp_schema,
+ classname: fragment.classname
+ } %>
<%# case for displaying comments OR text %>
<% elsif !blank %>
<%= sanitize answer.text %>
+ <% else %>
+
+
<%= _('Question not answered.') -%>
+
+
<% end %>
- <% end %>
-
- <% end %>
- <% end %>
+ <% end %>
+
+ <% end %>
+ <% end %>
<% end %>
diff --git a/app/views/branded/shared/export/_export_by_section.erb b/app/views/branded/shared/export/_export_by_section.erb
index 9600e52..077bb40 100644
--- a/app/views/branded/shared/export/_export_by_section.erb
+++ b/app/views/branded/shared/export/_export_by_section.erb
@@ -17,6 +17,7 @@
@plan.answer(question[:id], false, research_output[:id]) %>
<% blank = answer.present? ? answer.is_blank? : true %>
<% options = answer.present? ? answer.question_options : [] %>
+ <% fragment = answer.present? ? answer.madmp_fragment : nil %>
<% unless @show_unanswered == false && blank %>
@@ -33,39 +34,44 @@
<% end %>
<%# case where question has not been answered sufficiently to display%>
- <% if @show_unanswered && (answer.blank? || (options.blank? && blank))%>
-
-
<%= _('Question not answered.') -%>
-
-
- <% else %>
-
- <%# case where Question has options %>
- <% if options.any? %>
-
- <% options.each do |opt| %>
- <%= opt.text %>
- <% end %>
-
- <% end %>
- <%# case for RDA answer display %>
- <% if question[:format].rda_metadata? && !blank %>
- <% ah = answer.answer_hash %>
- <% if ah['standards'].present? %>
-
- <% ah['standards'].each do |id, title| %>
- <%= title %>
+ <% if @show_unanswered %>
+ <%# case where Question has options %>
+ <% if options.any? %>
+
+ <% options.each do |opt| %>
+ <%= opt.text %>
<% end %>
-
+
<% end %>
-
<%= sanitize ah['text'] %>
-
- <%# case for displaying comments OR text %>
- <% elsif !blank %>
- <%= sanitize answer.text %>
-
- <% end %>
-
+ <% if question[:format].rda_metadata? && !blank %>
+ <% ah = answer.answer_hash %>
+ <% if ah['standards'].present? %>
+
+ <% ah['standards'].each do |id, title| %>
+ <%= title %>
+ <% end %>
+
+ <% end %>
+
<%= sanitize ah['text'] %>
+
+ <% elsif question[:format].structured? && fragment.present? %>
+ <%= render partial: 'shared/export/display_madmp_fragment',
+ locals: {
+ fragment: fragment,
+ schema: fragment.madmp_schema,
+ classname: fragment.classname
+ } %>
+ <%# case for displaying comments OR text %>
+ <% elsif !blank %>
+ <%= sanitize answer.text %>
+
+ <% else %>
+
+
<%= _('Question not answered.') -%>
+
+
+ <% end %>
+
<% end %>
<% end %>
diff --git a/app/views/branded/shared/export/_plan_styling.erb b/app/views/branded/shared/export/_plan_styling.erb
index 7f51750..8653b4c 100644
--- a/app/views/branded/shared/export/_plan_styling.erb
+++ b/app/views/branded/shared/export/_plan_styling.erb
@@ -40,6 +40,9 @@
padding: 0;
margin: 1em 0 0 0;
}
+ h4 {
+ color: #2c7dad;
+ }
h3 + div.question > h4 {
margin: 0;
}
@@ -83,4 +86,26 @@
margin: 5px;
padding: 5px;
}
+
+ table.fragment-display {
+ width: 50%;
+ }
+ .fragment-display td {
+ border: none !important;
+ }
+ .attribute-name {
+ width: 25%;
+ font-weight: 700;
+ }
+
+ .sub-fragment-list {
+ width: 100%;
+ }
+ .sub-fragment-list .fragment-display{
+ width: 100%;
+ }
+ .sub-fragment-list .fragment-display td{
+ border: 1px solid black !important;
+ }
+
\ No newline at end of file
diff --git a/app/views/branded/shared/fragments/_display.html.erb b/app/views/branded/shared/fragments/_display.html.erb
new file mode 100644
index 0000000..eda93f2
--- /dev/null
+++ b/app/views/branded/shared/fragments/_display.html.erb
@@ -0,0 +1,68 @@
+<% sub_schemas = schema.get_sub_schemas %>
+<% data = fragment.data unless fragment.nil? %>
+<% sub_fragments = fragment.present? ? fragment.get_sub_fragments() : [] %>
+<% schema_properties = schema.schema["properties"]%>
+
+ <% schema_properties.each do |key, prop| %>
+ <% value = data[key] unless data.nil? %>
+ <% field_name = defined?(form_prefix) ? "#{form_prefix}[#{key}]" : key %>
+ <% case prop['type'] %>
+ <% when 'boolean' %>
+ <%= field_name %>
+ <%= value ? _('Yes') : _('No') %>
+ <% when 'array' %>
+ <% if prop['items']['type'] == 'object' && prop['items']['schema_id'].present? %>
+ <% unless classname == "research_output"%>
+ <%
+ sub_schema = sub_schemas[prop['items']['schema_id']]
+ %>
+
+
+ <%= field_name.capitalize.pluralize(2) %>
+
+ <% unless sub_fragments[sub_schema.id].nil? %>
+ <% sub_fragments[sub_schema.id].each do |val| %>
+
+ <%= render(partial: 'shared/fragments/display', locals: {
+ fragment: val,
+ schema: sub_schema,
+ classname: sub_schema.classname
+ } ) %>
+
+ <% end %>
+ <% end %>
+
+
+ <% end %>
+ <% else %>
+
+ <%= field_name %>
+ <% value.each do |val| %>
+ <%= val %>
+ <% end %>
+
+ <% end %>
+ <% when 'object' %>
+ <% if prop["schema_id"].present? %>
+ <% unless classname == "research_output" || value.nil? %>
+ <%
+ sub_schema = sub_schemas[prop["schema_id"]]
+ sub_fragment = sub_fragments[sub_schema.id].find { |f| f.id == value["dbId"] }
+ %>
+
+ <%= field_name.capitalize %>
+
+ <%= render(partial: 'shared/fragments/display', locals: {
+ fragment: sub_fragment, #TODO : Implement Person fragments display
+ schema: sub_schema,
+ classname: sub_schema.classname
+ } ) %>
+
+ <% end %>
+ <% end %>
+ <% else%>
+ <%= field_name %>
+ <%= value %>
+ <% end %>
+ <% end %>
+
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 177b96d..fce31cb 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -127,9 +127,10 @@
post 'sort', on: :collection
end
- resources :madmp_fragments, only: [:new, :edit, :create, :update, :destroy] do
+ resources :madmp_fragments, only: [:destroy] do
post 'create_or_update', on: :collection
- get 'new_edit_linked', on: :collection
+ get 'new_edit_linked', on: :collection, constraints: {format: [:js]}
+ get 'show_linked', on: :collection, constraints: {format: [:js]}
get 'get_fragment/:id', action: :get_fragment, on: :collection, as: :get_fragment
end
diff --git a/lib/dmpopidor/controllers/answers.rb b/lib/dmpopidor/controllers/answers.rb
index 6de26c7..7688eb6 100644
--- a/lib/dmpopidor/controllers/answers.rb
+++ b/lib/dmpopidor/controllers/answers.rb
@@ -94,8 +94,8 @@
@plan = Plan.includes(
sections: {
questions: [
- :answers,
- :question_format
+ :question_format,
+ answers: :madmp_fragment
]
}
).find(p_params[:plan_id])
diff --git a/lib/dmpopidor/controllers/plans.rb b/lib/dmpopidor/controllers/plans.rb
index b587c0b..dfa0195 100644
--- a/lib/dmpopidor/controllers/plans.rb
+++ b/lib/dmpopidor/controllers/plans.rb
@@ -141,6 +141,16 @@
end
end
+ # GET /plans/:plan_id/phases/:id/edit
+ # CHANGES :
+ # Added Research Output Support
+ def edit
+ plan = Plan.includes(:research_outputs).find(params[:id])
+ authorize plan
+ plan, phase = Plan.load_for_phase(params[:id], params[:phase_id])
+ guidance_groups = GuidanceGroup.where(published: true, id: plan.guidance_group_ids)
+ render_phases_edit(plan, phase, guidance_groups)
+ end
# PUT /plans/1
# PUT /plans/1.json
@@ -272,11 +282,11 @@
def plan_meta_params
params.require(:plan)
- .permit(:title, :description, :relatedDocUrl, :associatedDMPId,
+ .permit(:title, :descriptione, :associatedDMPId, :versionNumber, :versionNotes,
+ relatedDocUrl: [],
contact: [:lastName, :firstName, :mbox, :identifier],
licence: [ :licenseName, :licenseUrl, :licenceStartDate],
- dmpID: [:value, :idType],
- version: [:versionNumber, :versionNotes])
+ dmpID: [:value, :idType])
end
def plan_project_params
@@ -285,6 +295,23 @@
:project_start_date, :project_end_date, :experimental_plan_url,
principalInvestigator: [:lastName, :firstName, :mbox, :identifier] )
end
+
+ # CHANGES : maDMP Fragments SUPPORT
+ def render_phases_edit(plan, phase, guidance_groups)
+ readonly = !plan.editable_by?(current_user.id)
+ # Since the answers have been pre-fetched through plan (see Plan.load_for_phase)
+ # we create a hash whose keys are question id and value is the answer associated
+ answers = plan.answers.includes(:madmp_fragment).reduce({}) { |m, a| m["#{a.question_id}_#{a.research_output_id}"] = a; m }
+ render("/phases/edit", locals: {
+ base_template_org: phase.template.base_org,
+ plan: plan,
+ phase: phase,
+ readonly: readonly,
+ guidance_groups: guidance_groups,
+ answers: answers,
+ guidance_presenter: GuidancePresenter.new(plan)
+ })
+ end
end
end
end
\ No newline at end of file