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;' %>