diff --git a/app/assets/stylesheets/dmpopidor.scss b/app/assets/stylesheets/dmpopidor.scss index 3fb3f34..35724c7 100644 --- a/app/assets/stylesheets/dmpopidor.scss +++ b/app/assets/stylesheets/dmpopidor.scss @@ -680,22 +680,31 @@ } } -.research-outputs-description { - width: 50vw; +#research-outputs { + width: 100%; padding: 0 5px; margin-top: 5px; + .form-group { + margin: 0; + margin-right: 5px; + } .research-output-element { display: flex; flex-direction: row; - .research-output-name { - width: 30%; - } - .research-output-description { - width: 60%; + margin: 5px 0; + + .research-output-fields { + flex: 9; + border: 0.5px groove $color-border-light; + box-shadow: 0px 0px 0px 0px $color-shadow-dark; + padding: 5px; + .research-output-abbreviation, .research-output-pid, .research-output-type { + width: 30%; + } } .research-output-actions { - width: 10%; + flex: 1; display: flex; align-items: center; justify-content: center; @@ -708,9 +717,5 @@ color: $blue; } } - .form-group { - margin: 0; - margin-right: 5px; - } } } diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 32799cc..324fcd5 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -400,7 +400,8 @@ :principal_investigator_phone, :principal_investigator, :principal_investigator_email, :data_contact, :principal_investigator_identifier, :data_contact_email, - :data_contact_phone, :guidance_group_ids, research_outputs_attributes: %i[id abbreviation fullname order _destroy]) + :data_contact_phone, :guidance_group_ids, + research_outputs_attributes: %i[id abbreviation fullname order pid other_type_label research_output_type_id _destroy]) end # different versions of the same template have the same family_id diff --git a/app/controllers/research_outputs_controller.rb b/app/controllers/research_outputs_controller.rb index 5ed2c20..dd96063 100644 --- a/app/controllers/research_outputs_controller.rb +++ b/app/controllers/research_outputs_controller.rb @@ -9,9 +9,11 @@ begin @plan = Plan.find(params[:plan_id]) @research_outputs = @plan.research_outputs + @research_output_types = ResearchOutputType.all authorize @plan - render('plans/research_outputs', locals: { plan: @plan, research_outputs: @research_outputs }) + render('plans/research_outputs', locals: { plan: @plan, research_outputs: @research_outputs, + research_output_types: @research_output_types }) rescue ActiveRecord::RecordNotFound flash[:alert] = _("There is no plan associated with id %{id}") % { id: params[:id] diff --git a/app/javascript/views/plans/research_outputs.js b/app/javascript/views/plans/research_outputs.js index a3db2f0..623e086 100644 --- a/app/javascript/views/plans/research_outputs.js +++ b/app/javascript/views/plans/research_outputs.js @@ -16,16 +16,26 @@ const duplicatedId = `plan_research_outputs_attributes_${new Date().getTime()}`; const duplicatedName = `plan[research_outputs_attributes][${new Date().getTime()}]`; - // Research Output name - duplicated.find('.research-output-name input').attr('id', `${duplicatedId}_name`); - duplicated.find('.research-output-name input').attr('name', `${duplicatedName}[name]`); - duplicated.find('.research-output-name label').attr('for', `${duplicatedId}_name`); - duplicated.find('.research-output-name input').val(null); - // Research Output description - duplicated.find('.research-output-description input').attr('id', `${duplicatedId}_description`); - duplicated.find('.research-output-description input').attr('name', `${duplicatedName}[description]`); - duplicated.find('.research-output-description label').attr('for', `${duplicatedId}_description`); - duplicated.find('.research-output-description input').val(null); + // Research Output abbreviation + duplicated.find('.research-output-abbreviation input').attr('id', `${duplicatedId}_abbreviation`); + duplicated.find('.research-output-abbreviation input').attr('name', `${duplicatedName}[abbreviation]`); + duplicated.find('.research-output-abbreviation label').attr('for', `${duplicatedId}_abbreviation`); + duplicated.find('.research-output-abbreviation input').val(null); + // Research Output fullname + duplicated.find('.research-output-fullname input').attr('id', `${duplicatedId}_fullname`); + duplicated.find('.research-output-fullname input').attr('name', `${duplicatedName}[fullname]`); + duplicated.find('.research-output-fullname label').attr('for', `${duplicatedId}_fullname`); + duplicated.find('.research-output-fullname input').val(null); + // Research Output pid + duplicated.find('.research-output-pid input').attr('id', `${duplicatedId}_pid`); + duplicated.find('.research-output-pid input').attr('name', `${duplicatedName}[pid]`); + duplicated.find('.research-output-pid label').attr('for', `${duplicatedId}_pid`); + duplicated.find('.research-output-pid input').val(null); + // Research Output type + duplicated.find('.research-output-type select').attr('id', `${duplicatedId}_research_output_type_id`); + duplicated.find('.research-output-type select').attr('name', `${duplicatedName}[research_output_type_id]`); + duplicated.find('.research-output-type label').attr('for', `${duplicatedId}_research_output_type_id`); + duplicated.find('.research-output-type select').val(null); // Research Output order duplicated.find('.research-output-order').attr('id', `${duplicatedId}_order`); duplicated.find('.research-output-order').attr('name', `${duplicatedName}[order]`); @@ -33,4 +43,15 @@ duplicated.appendTo('#research-outputs'); }); + + $('.research-output-type-select').change((e) => { + const selectElement = $(e.target); + const parentElement = selectElement.closest('.research-output-element'); + const otherTypeElement = parentElement.find('.research-output-other-type'); + if (selectElement.find('option:selected').data('other')) { + otherTypeElement.show(); + } else { + otherTypeElement.hide(); + } + }); }); diff --git a/app/models/answer.rb b/app/models/answer.rb index b963cd5..cfb7297 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -61,7 +61,7 @@ validates :user, presence: { message: PRESENCE_MESSAGE } - #validates :question, presence: { message: PRESENCE_MESSAGE }, + validates :question, presence: { message: PRESENCE_MESSAGE }#, # uniqueness: { message: UNIQUENESS_MESSAGE, # scope: :plan_id } diff --git a/app/models/research_output.rb b/app/models/research_output.rb index abbc008..bfc511f 100644 --- a/app/models/research_output.rb +++ b/app/models/research_output.rb @@ -2,54 +2,85 @@ # # Table name: research_outputs # -# id :integer not null, primary key -# abbreviation :string -# fullname :string -# is_default :boolean default(FALSE) -# order :integer -# created_at :datetime not null -# updated_at :datetime not null -# plan_id :integer +# id :integer not null, primary key +# abbreviation :string +# fullname :string +# is_default :boolean default(FALSE) +# order :integer +# other_type_label :string +# pid :string +# created_at :datetime not null +# updated_at :datetime not null +# plan_id :integer +# research_output_type_id :integer # # Indexes # -# index_research_outputs_on_plan_id (plan_id) +# index_research_outputs_on_plan_id (plan_id) +# index_research_outputs_on_research_output_type_id (research_output_type_id) # # Foreign Keys # # fk_rails_... (plan_id => plans.id) +# fk_rails_... (research_output_type_id => research_output_types.id) # class ResearchOutput < ActiveRecord::Base - belongs_to :plan - has_many :answers, dependent: :destroy - - default_scope { order(order: :asc) } + include ValidationMessages - def main? - eql?(plan.research_outputs.where(order: 1).first) - end + # ================ + # = Associations = + # ================ + belongs_to :plan - # Return main research output - def get_main - plan.research_outputs.first - end + belongs_to :research_output_type - def has_common_answers?(section_id) - self.answers.each do |answer| - if answer.question_id.in?(Section.find(section_id).questions.pluck(:id)) && answer.is_common - return true - end - end - return false - end + has_many :answers, dependent: :destroy - ## - # deep copy the given research output - # - # Returns Research output - def self.deep_copy(research_output) - research_output.dup - end + # =============== + # = Validations = + # =============== + validates :abbreviation, presence: { message: PRESENCE_MESSAGE } + + validates :fullname, presence: { message: PRESENCE_MESSAGE } + + + # ========== + # = Scopes = + # ========== + + default_scope { order(order: :asc) } + + + # ================= + # = Class methods = + # ================= + + def main? + eql?(plan.research_outputs.where(order: 1).first) end + + # Return main research output + def get_main + plan.research_outputs.first + end + + def has_common_answers?(section_id) + self.answers.each do |answer| + if answer.question_id.in?(Section.find(section_id).questions.pluck(:id)) && answer.is_common + return true + end + end + return false + end + + ## + # deep copy the given research output + # + # Returns Research output + def self.deep_copy(research_output) + research_output.dup + end + +end diff --git a/app/models/research_output_type.rb b/app/models/research_output_type.rb new file mode 100644 index 0000000..269d2a8 --- /dev/null +++ b/app/models/research_output_type.rb @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: research_output_types +# +# id :integer not null, primary key +# is_other :boolean default(FALSE), not null +# label :string not null +# slug :string not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class ResearchOutputType < ActiveRecord::Base + has_many :research_outputs + + ## + # Before save & create, generate the slug + before_save :generate_slug + + def generate_slug + if self.label + self.slug = self.label.parameterize + end + end +end diff --git a/app/views/branded/plans/_research_output_fields.html.erb b/app/views/branded/plans/_research_output_fields.html.erb index a4bb264..2406d02 100644 --- a/app/views/branded/plans/_research_output_fields.html.erb +++ b/app/views/branded/plans/_research_output_fields.html.erb @@ -1,14 +1,39 @@ -<%# locals: { plan, research_output } %> +<%# locals: { plan, research_output, research_output_types } %> +<% other_type_displayed = research_output.research_output_type.is_other ? '' : 'display:none;' %>
-
- <%= f.label :name, _('Abbreviated Name (20 chars max.)'), class: 'control-label' %> - <%= f.text_field :abbreviation, maxlength: 20, class: 'form-control', "aria-required": true %> -
-
- <%= f.label :fullname, _('Fullname'), class: 'control-label' %> - <%= f.text_field :fullname, class: 'form-control' %> -
+
+
+ <%= f.label :name, d_('dmpopidor', 'Abbreviated Name (20 chars max.)'), class: 'control-label' %> + <%= f.text_field :abbreviation, maxlength: 20, class: 'form-control', "aria-required": true %> +
+
+ <%= f.label :fullname, d_('dmpopidor', 'Fullname'), class: 'control-label' %> + <%= f.text_field :fullname, class: 'form-control', "aria-required": true %> +
+
+ <%= f.label :research_output_type_id, d_('dmpopidor', 'Type'), class: 'control-label' %> + + + + <%= f.select(:research_output_type_id, + options_for_select( + research_output_types.map{ |r| [r.label, r.id, { 'data-other' => r.is_other }] }, + selected: research_output.research_output_type_id, disabled: "" + ), + { prompt: d_('dmpopidor', 'Please select the type of your research output.') }, + { multiple: false, class: 'form-control research-output-type-select', "aria-required": true}) + %> +
+
+ <%= f.label :other_type_label, d_('dmpopidor', 'Other Type'), class: 'control-label' %> + <%= f.text_field :other_type_label, class: 'form-control' %> +
+
+ <%= f.label :pid, d_('dmpopidor', 'Persistent Identifier'), class: 'control-label' %> + <%= f.text_field :pid, class: 'form-control' %> +
<%= f.hidden_field :order, class: 'research-output-order' %> +
@@ -19,5 +44,5 @@ title="<%= d_('dmpopidor', 'Delete research output') %>" %> <% end %>
-
+
\ No newline at end of file diff --git a/app/views/branded/plans/_research_outputs_form.html.erb b/app/views/branded/plans/_research_outputs_form.html.erb index 9206a93..6b76c3c 100644 --- a/app/views/branded/plans/_research_outputs_form.html.erb +++ b/app/views/branded/plans/_research_outputs_form.html.erb @@ -1,11 +1,12 @@ -<%# locals: { plan, research_outputs } %> +<%# locals: { plan, research_outputs, research_output_types } %>
<%= d_('dmpopidor', 'Research outputs') %> <%= form_for plan, html: {method: :put, class: 'form-horizontal edit_plan' } do |f| %>
<% @research_outputs.each do |research_output|%> <%= f.fields_for :research_outputs, research_output do |d| %> - <%= render 'plans/research_output_fields', f: d, plan: plan, research_output: research_output %> + <%= render 'plans/research_output_fields', f: d, plan: plan, + research_output: research_output, research_output_types: research_output_types %> <% end %> <% end %>
diff --git a/app/views/branded/plans/research_outputs.html.erb b/app/views/branded/plans/research_outputs.html.erb index 23c954e..9db68ae 100644 --- a/app/views/branded/plans/research_outputs.html.erb +++ b/app/views/branded/plans/research_outputs.html.erb @@ -1,4 +1,4 @@ -<%# locals: { plan, research_outputs } %> +<%# locals: { plan, research_outputs, research_output_types } %>
<%= _('Beta') %>
<% title "#{plan.title}" %>
diff --git a/config/locale/dmpopidor.pot b/config/locale/dmpopidor.pot index b900785..9f698db 100644 --- a/config/locale/dmpopidor.pot +++ b/config/locale/dmpopidor.pot @@ -276,6 +276,9 @@ msgid "Fullname" msgstr "" +msgid "Persistent Identifier" +msgstr "" + msgid "Select research outputs to download" msgstr "" diff --git a/config/locale/en_GB/dmpopidor.po b/config/locale/en_GB/dmpopidor.po index 478f896..bcbfd36 100644 --- a/config/locale/en_GB/dmpopidor.po +++ b/config/locale/en_GB/dmpopidor.po @@ -272,6 +272,9 @@ msgid "Fullname" msgstr "Fullname" +msgid "Persistent Identifier" +msgstr "Persistent Identifier" + msgid "Select research outputs to download" msgstr "Select research outputs to download" diff --git a/config/locale/fr_FR/dmpopidor.po b/config/locale/fr_FR/dmpopidor.po index de6b7e3..b526baf 100644 --- a/config/locale/fr_FR/dmpopidor.po +++ b/config/locale/fr_FR/dmpopidor.po @@ -270,7 +270,10 @@ msgstr "Nom abbrégé (20 caractères max.)" msgid "Fullname" -msgstr "" +msgstr "Nom complet" + +msgid "Persistent Identifier" +msgstr "Identifiant Pérenne" msgid "Select research outputs to download" msgstr "Sélectionner les produits de recherche à télécharger" diff --git a/config/routes.rb b/config/routes.rb index 519bbfb..cea6ada 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -274,6 +274,7 @@ get 'help', to: 'static/static_pages#show', name: 'help' get 'roadmap', to: 'static/static_pages#show', name: 'roadmap' get 'terms', to: 'static/static_pages#show', name: 'termsuse' + get 'research_output_types', to: 'static/static_pages#show', name: 'research_output_types' get "tutorials", to: 'static_pages#tutorials' get "news_feed", to: 'static_pages#news_feed' diff --git a/db/migrate/20190620143119_create_research_output_types.rb b/db/migrate/20190620143119_create_research_output_types.rb new file mode 100644 index 0000000..eadaa88 --- /dev/null +++ b/db/migrate/20190620143119_create_research_output_types.rb @@ -0,0 +1,11 @@ +class CreateResearchOutputTypes < ActiveRecord::Migration + def change + create_table :research_output_types do |t| + t.string :label, null: false + t.string :slug, null: false + t.boolean :is_other, default: false, null: false + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20190620144049_add_columns_to_research_outputs.rb b/db/migrate/20190620144049_add_columns_to_research_outputs.rb new file mode 100644 index 0000000..53d7965 --- /dev/null +++ b/db/migrate/20190620144049_add_columns_to_research_outputs.rb @@ -0,0 +1,8 @@ +class AddColumnsToResearchOutputs < ActiveRecord::Migration + def change + add_column :research_outputs, :pid, :string + add_column :research_outputs, :other_type_label, :string + + add_reference :research_outputs, :research_output_type, index: true, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 52d5d5c..bde80d4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190620135111) do +ActiveRecord::Schema.define(version: 20190620144049) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -299,17 +299,29 @@ t.integer "super_region_id" end + create_table "research_output_types", force: :cascade do |t| + t.string "label", null: false + t.string "slug", null: false + t.boolean "is_other", default: false, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "research_outputs", force: :cascade do |t| t.string "abbreviation" t.integer "order" t.string "fullname" - t.boolean "is_default", default: false + t.boolean "is_default", default: false t.integer "plan_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "pid" + t.string "other_type_label" + t.integer "research_output_type_id" end add_index "research_outputs", ["plan_id"], name: "index_research_outputs_on_plan_id", using: :btree + add_index "research_outputs", ["research_output_type_id"], name: "index_research_outputs_on_research_output_type_id", using: :btree create_table "roles", force: :cascade do |t| t.integer "user_id" @@ -520,6 +532,7 @@ add_foreign_key "questions_themes", "questions" add_foreign_key "questions_themes", "themes" add_foreign_key "research_outputs", "plans" + add_foreign_key "research_outputs", "research_output_types" add_foreign_key "roles", "plans" add_foreign_key "roles", "users" add_foreign_key "sections", "phases" diff --git a/db/seeds.rb b/db/seeds.rb index ad0fce5..ff63fd3 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -809,3 +809,23 @@ question: Question.find_by(text: "What types of data will you collect and how will it be stored?")}, ] annotations.map{ |s| Annotation.create!(s) if Annotation.find_by(text: s[:text]).nil? } + +research_output_types = [ + {label: 'Audiovisual'}, + {label: 'Collection'}, + {label: 'DataPaper'}, + {label: 'Dataset'}, + {label: 'Event'}, + {label: 'Image'}, + {label: 'Interactive Resource'}, + {label: 'Model'}, + {label: 'Physical Object'}, + {label: 'Service'}, + {label: 'Software'}, + {label: 'Sound'}, + {label: 'Text'}, + {label: 'Workflow'}, + {label: 'Other', is_other: true}, +] + +research_output_types.map{ |s| ResearchOutputType.create!(s) if ResearchOutputType.find_by(label: s[:label]).nil? } diff --git a/lib/tasks/dmpopidor_upgrade.rake b/lib/tasks/dmpopidor_upgrade.rake index 959c59f..3edf5e2 100644 --- a/lib/tasks/dmpopidor_upgrade.rake +++ b/lib/tasks/dmpopidor_upgrade.rake @@ -12,6 +12,7 @@ desc "Upgrade to 2.2.0" task v2_2_0: :environment do Rake::Task['dmpopidor_upgrade:research_outputs_enable'].execute + Rake::Task['dmpopidor_upgrade:create_research_output_types'].execute end @@ -78,4 +79,27 @@ Rake::Task['db:migrate:down VERSION=20190620120126'].execute end + desc 'Create Research output types' + task create_research_output_types: :environment do + research_output_types = [ + {label: 'Audiovisual'}, + {label: 'Collection'}, + {label: 'DataPaper'}, + {label: 'Dataset'}, + {label: 'Event'}, + {label: 'Image'}, + {label: 'Interactive Resource'}, + {label: 'Model'}, + {label: 'Physical Object'}, + {label: 'Service'}, + {label: 'Software'}, + {label: 'Sound'}, + {label: 'Text'}, + {label: 'Workflow'}, + {label: 'Other', is_other: true}, + ] + + research_output_types.map{ |s| ResearchOutputType.create!(s) if ResearchOutputType.find_by(label: s[:label]).nil? } + end + end