diff --git a/app/controllers/admin/annotations_controller.rb b/app/controllers/admin/annotations_controller.rb new file mode 100644 index 0000000..f0881d1 --- /dev/null +++ b/app/controllers/admin/annotations_controller.rb @@ -0,0 +1,21 @@ +module Admin + class AnnotationsController < Admin::ApplicationController + # To customize the behavior of this controller, + # you can overwrite any of the RESTful actions. For example: + # + # def index + # super + # @resources = Annotation. + # page(params[:page]). + # per(10) + # end + + # Define a custom finder by overriding the `find_resource` method: + # def find_resource(param) + # Annotation.find_by!(slug: param) + # end + + # See https://administrate-prototype.herokuapp.com/customizing_controller_actions + # for more information + end +end diff --git a/app/controllers/admin/suggested_answers_controller.rb b/app/controllers/admin/suggested_answers_controller.rb deleted file mode 100644 index 35d5243..0000000 --- a/app/controllers/admin/suggested_answers_controller.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Admin - class SuggestedAnswersController < Admin::ApplicationController - # To customize the behavior of this controller, - # you can overwrite any of the RESTful actions. For example: - # - # def index - # super - # @resources = SuggestedAnswer. - # page(params[:page]). - # per(10) - # end - - # Define a custom finder by overriding the `find_resource` method: - # def find_resource(param) - # SuggestedAnswer.find_by!(slug: param) - # end - - # See https://administrate-prototype.herokuapp.com/customizing_controller_actions - # for more information - end -end diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb new file mode 100644 index 0000000..a262cb3 --- /dev/null +++ b/app/controllers/annotations_controller.rb @@ -0,0 +1,53 @@ +class AnnotationsController < ApplicationController + respond_to :html + after_action :verify_authorized + + #create annotations + def admin_create + @example_answer = Annotation.new(params[:annotation]) + authorize @example_answer + if @example_answer.save + redirect_to admin_show_phase_path(id: @example_answer.question.section.phase_id, section_id: @example_answer.question.section_id, question_id: @example_answer.question.id, edit: 'true'), notice: _('Information was successfully created.') + else + @section = @example_answer.question.section + @phase = @section.phase + @open = true + @sections = @phase.sections + @section_id = @section.id + @question_id = @example_answer.question + flash[:notice] = failed_create_error(@example_answer, _('example answer')) + render "phases/admin_show" + end + end + + + #update a example answer of a template + def admin_update + @example_answer = Annotation.includes(question: { section: {phase: :template}}).find(params[:id]) + authorize @example_answer #.question.section.phase.template + @question = @example_answer.question + @section = @question.section + @phase = @section.phase + if @example_answer.update_attributes(params[:annotation]) + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully updated.') + else + flash[:notice] = failed_update_error(@example_answer, _('example answer')) + render action: "phases/admin_show" + end + end + + #delete an annotation + def admin_destroy + @example_answer = Annotation.includes(question: { section: {phase: :template}}).find(params[:id]) + authorize @example_answer + @question = @example_answer.question + @section = @question.section + @phase = @section.phase + if @example_answer.destroy + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: _('Information was successfully deleted.') + else + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: flash[:notice] = failed_destroy_error(@example_answer, _('example answer')) + end + end + +end \ No newline at end of file diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 9d79400..eead0ca 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -4,14 +4,16 @@ after_action :verify_authorized - # GET /plans/:plan_id/phases/:id/edit - def edit + # GET /plans/:plan_id/phases/:id/edit + def edit @plan = Plan.eager_load2(params[:plan_id]) + # authorization done on plan so found in plan_policy authorize @plan phase_id = params[:id].to_i @phase = @plan.template.phases.select {|p| p.id == phase_id}.first + @readonly = !@plan.editable_by?(current_user.id) # the eager_load pulls in ALL answers # need to restrict to just ones for this plan @@ -43,7 +45,7 @@ # create a map from theme to array of guidances # where guidance is a hash with the text and the org name - theme_guidance = {} + theme_guidance = {} guidance_groups.each do |guidance_group| guidance_group.guidances.each do |guidance| @@ -83,14 +85,14 @@ if !user_signed_in? then respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - end + format.html { redirect_to edit_user_registration_path } + end + end - end + end - # GET /plans/PLANID/phases/PHASEID/status.json + # GET /plans/PLANID/phases/PHASEID/status.json def status @plan = Plan.eager_load(params[:plan_id]) authorize @plan @@ -110,9 +112,10 @@ @phase = Phase.eager_load(:sections).find_by('phases.id = ?', params[:id]) authorize @phase - @edit = (@phase.template.org == current_user.org) + @current = Template.current(@phase.template.dmptemplate_id) + @edit = (@phase.template.org == current_user.org) && (@phase.template == @current) #@edit = params[:edit] == "true" ? true : false - + #verify if there are any sections if not create one @sections = @phase.sections if !@sections.any?() || @sections.count == 0 @@ -158,13 +161,13 @@ def admin_create @phase = Phase.new(params[:phase]) authorize @phase - + @phase.description = params["phase-desc"] @phase.modifiable = true if @phase.save @phase.template.dirty = true @phase.template.save! - + redirect_to admin_show_phase_path(id: @phase.id, edit: 'true'), notice: _('Information was successfully created.') else flash[:notice] = failed_create_error(@phase, _('phase')) @@ -182,7 +185,7 @@ if @phase.update_attributes(params[:phase]) @phase.template.dirty = true @phase.template.save! - + redirect_to admin_show_phase_path(@phase), notice: _('Information was successfully updated.') else @sections = @phase.sections @@ -190,7 +193,7 @@ # These params may not be available in this context so they may need # to be set to true without the check @edit = true - @open = !params[:section_id].nil? + @open = !params[:section_id].nil? @section_id = (params[:section_id].nil? ? nil : params[:section_id].to_i) @question_id = (params[:question_id].nil? ? nil : params[:question_id].to_i) flash[:notice] = failed_update_error(@phase, _('phase')) @@ -206,15 +209,15 @@ if @phase.destroy @template.dirty = true @template.save! - + redirect_to admin_template_template_path(@template), notice: _('Information was successfully deleted.') else @sections = @phase.sections - + # These params may not be available in this context so they may need # to be set to true without the check @edit = true - @open = !params[:section_id].nil? + @open = !params[:section_id].nil? @section_id = (params[:section_id].nil? ? nil : params[:section_id].to_i) @question_id = (params[:question_id].nil? ? nil : params[:question_id].to_i) flash[:notice] = failed_destroy_error(@phase, _('phase')) diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 526f76a..e554b93 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -140,7 +140,7 @@ authorize @plan # If there was no phase specified use the template's 1st phase @phase = (params[:phase].nil? ? @plan.template.phases.first : Phase.find(params[:phase])) - @readonly = @plan.editable_by?(current_user.id) + @readonly = !@plan.editable_by?(current_user.id) respond_to :html end diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 6ed74f3..14a6d21 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -6,12 +6,24 @@ def admin_create @question = Question.new(params[:question]) authorize @question - @question.guidance = params["new-question-guidance"] + example = @question.annotations.first + if example.present? + example.org_id = current_user.org_id + example.example_answer! + end + if params["new-question-guidance"].present? + guidance = @question.annotations.build + guidance.text = params["new-question-guidance"] + guidance.org_id = current_user.org_id + guidance.guidance! + guidance.save + end @question.default_value = params["new-question-default-value"] + @question.modifiable = true if @question.save @question.section.phase.template.dirty = true @question.section.phase.template.save! - + redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully created.') else @edit = (@question.section.phase.template.org == current_user.org) @@ -21,7 +33,7 @@ @sections = @phase.sections @section_id = @question.section.id @question_id = @question.id - + flash[:notice] = failed_create_error(@question, _('question')) render template: 'phases/admin_show' end @@ -31,14 +43,23 @@ def admin_update @question = Question.find(params[:id]) authorize @question - @question.guidance = params["question-guidance-#{params[:id]}"] + guidance = @question.get_guidance_annotation(current_user.org_id) + if params["question-guidance-#{params[:id]}"].present? + if guidance.blank? + guidance = @question.annotations.build + guidance.type = :guidance + end + guidance.text = params["question-guidance-#{params[:id]}"] + guidance.save + end @question.default_value = params["question-default-value-#{params[:id]}"] @section = @question.section @phase = @section.phase + template = @phase.template if @question.update_attributes(params[:question]) - @question.section.phase.template.dirty = true - @question.section.phase.template.save! - + @phase.template.dirty = true + @phase.template.save! + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully updated.') else @edit = (@phase.template.org == current_user.org) @@ -46,7 +67,7 @@ @sections = @phase.sections @section_id = @section.id @question_id = @question.id - + flash[:notice] = failed_update_error(@question, _('question')) render template: 'phases/admin_show' end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index dbc8dd4..bcaf9b9 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -40,10 +40,10 @@ redirect_to after_sign_up_error_path_for(resource), alert: _('You must accept the terms and conditions to register.') else existing_user = User.find_by_email(sign_up_params[:email]) - if !existing_user.nil? then - if (existing_user.password == "" || existing_user.password.nil?) && existing_user.confirmed_at.nil? then - @user = existing_user - do_update(false, true) + if !existing_user.nil? # If email exists + if (existing_user.password == "" || existing_user.password.nil?) && existing_user.confirmed_at.nil? # If user has not accepted invitation yet + existing_user.destroy # Only solution for now + super else redirect_to after_sign_up_error_path_for(resource), alert: _('That email address is already registered.') end @@ -91,16 +91,16 @@ end def do_update(require_password = true, confirm = false) - if require_password # user is changing email or password - if current_user.email != params[:user][:email] # if user changing email - if params[:user][:current_password].blank? # password needs to be present + if require_password # user is changing email or password + if current_user.email != params[:user][:email] # if user is changing email + if params[:user][:current_password].blank? # password needs to be present message = _('Please enter your password to change email address.') successfully_updated = false else successfully_updated = current_user.update_with_password(password_update) end - elsif params[:user][:password].present? # user is changing password - successfully_updated = false # shared across first 3 conditions + elsif params[:user][:password].present? # if user is changing password + successfully_updated = false # shared across first 3 conditions if params[:user][:current_password].blank? message = _('Please enter your current password') elsif params[:user][:password_confirmation].blank? @@ -110,10 +110,10 @@ else successfully_updated = current_user.update_with_password(password_update) end - else # potentially unreachable... but I dont like to leave off the else + else # potentially unreachable... but I dont like to leave off the else successfully_updated = current_user.update_with_password(password_update) end - else # password not required + else # password not required successfully_updated = current_user.update_without_password(update_params) end @@ -125,7 +125,7 @@ #render the correct page if successfully_updated if confirm - current_user.skip_confirmation! + current_user.skip_confirmation! # will error out if confirmable is turned off in user model current_user.save! end session[:locale] = current_user.get_locale unless current_user.get_locale.nil? diff --git a/app/controllers/suggested_answers_controller.rb b/app/controllers/suggested_answers_controller.rb deleted file mode 100644 index e15d0c0..0000000 --- a/app/controllers/suggested_answers_controller.rb +++ /dev/null @@ -1,65 +0,0 @@ -class SuggestedAnswersController < ApplicationController - respond_to :html - after_action :verify_authorized - - #create suggested answers - def admin_create - @suggested_answer = SuggestedAnswer.new(params[:suggested_answer]) - authorize @suggested_answer - if @suggested_answer.save - # Set the template's dirty flag to true - @suggested_answer.question.section.phase.template.dirty = true - @suggested_answer.question.section.phase.template.save - - redirect_to admin_show_phase_path(id: @suggested_answer.question.section.phase_id, section_id: @suggested_answer.question.section_id, question_id: @suggested_answer.question.id, edit: 'true'), notice: _('Information was successfully created.') - else - @phase = @suggested_answer.question.section.phase - @section = @suggested_answer.question.section - @open = true - @sections = @phase.sections - @section_id = @section.id - @question_id = @suggested_answer.question - flash[:notice] = failed_create_error(@suggested_answer, _('suggested answer')) - render "phases/admin_show" - end - end - - - #update a suggested answer of a template - def admin_update - @suggested_answer = SuggestedAnswer.includes(question: { section: {phase: :template}}).find(params[:id]) - authorize @suggested_answer #.question.section.phase.template - @question = @suggested_answer.question - @section = @question.section - @phase = @section.phase - if @suggested_answer.update_attributes(params[:suggested_answer]) - # Set the template's dirty flag to true - @phase.template.dirty = true - @phase.template.save - - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: _('Information was successfully updated.') - else - flash[:notice] = failed_update_error(@suggested_answer, _('suggested answer')) - render action: "phases/admin_show" - end - end - - #delete a suggested answer - def admin_destroy - @suggested_answer = SuggestedAnswer.includes(question: { section: {phase: :template}}).find(params[:id]) - authorize @suggested_answer - @question = @suggested_answer.question - @section = @question.section - @phase = @section.phase - if @suggested_answer.destroy - # Set the template's dirty flag to true - @phase.template.dirty = true - @phase.template.save - - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: _('Information was successfully deleted.') - else - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: flash[:notice] = failed_destroy_error(@suggested_answer, _('suggested answer')) - end - end - -end \ No newline at end of file diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 1f5efa4..6d7c775 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -10,30 +10,30 @@ # ----------------------------------------------------- def admin_index authorize Template - + funder_templates, org_templates, customizations = [], [], [] - + # Get all of the unique template family ids (dmptemplate_id) for each funder and the current org funder_ids = Org.funders.includes(:templates).collect{|f| f.templates.collect{|ft| ft.dmptemplate_id } }.flatten.uniq org_ids = current_user.org.templates.collect{|t| t.dmptemplate_id }.flatten.uniq - + org_ids.each do |id| current = Template.current(id) live = Template.live(id) - + # If this isn't a customization of a funder template if current.customization_of.nil? org_templates << {current: current, live: live} - + # This is a customization of a funder template else funder_live = Template.live(current.customization_of) customizations << current.customization_of # Mark the customization as stale if the funder has a newer version - funder_templates << {current: current, live: live, stale: funder_live.updated_at > current.created_at} + funder_templates << {current: current, live: live, stale: funder_live.updated_at > current.created_at} end end - + # Get the funder templates funder_ids.each do |id| # If the org has a customization we don't want to load the funder version @@ -41,11 +41,11 @@ funder_templates << {current: Template.current(id), live: Template.live(id)} end end - - @funder_templates = funder_templates.sort{|x,y| + + @funder_templates = funder_templates.sort{|x,y| x[:current].title <=> y[:current].title } - @org_templates = org_templates.sort{|x,y| + @org_templates = org_templates.sort{|x,y| x[:current].title <=> y[:current].title } end @@ -55,7 +55,7 @@ def admin_customize @template = Template.find(params[:id]) authorize @template - + customisation = Template.deep_copy(@template) customisation.org = current_user.org customisation.version = 0 @@ -65,7 +65,7 @@ break random unless Template.exists?(dmptemplate_id: random) end customisation.save - + customisation.phases.includes(:sections, :questions).each do |phase| phase.modifiable = false phase.save! @@ -78,10 +78,10 @@ end end end - + redirect_to admin_template_template_path(customisation) end - + # PUT /org/admin/templates/:id/admin_publish # ----------------------------------------------------- def admin_publish @@ -89,7 +89,7 @@ authorize @template current = Template.current(@template.dmptemplate_id) - + # Only allow the current version to be updated if current != @template redirect_to admin_template_template_path(@template), notice: _('You can not publish a historical version of this template.') @@ -106,12 +106,6 @@ @template.published = true @template.save - # Create a new version - new_version = Template.deep_copy(@template) - new_version.version = (@template.version + 1) - new_version.published = false - new_version.save - flash[:notice] = _('Your template has been published and is now available to users.') redirect_to admin_index_template_path(current_user.org) @@ -134,23 +128,43 @@ @template.save flash[:notice] = _('Your template is no longer published. Users will not be able to create new DMPs for this template until you re-publish it') end - + redirect_to admin_index_template_path(current_user.org) end # GET /org/admin/templates/:id/admin_template # ----------------------------------------------------- def admin_template - @template = Template.includes(:org, phases: [sections: [questions: [:question_options, :question_format, - :suggested_answers]]]).find(params[:id]) + @template = Template.includes(:org, phases: [sections: [questions: [:question_options, :question_format, :annotations]]]).find(params[:id]) authorize @template - + @current = Template.current(@template.dmptemplate_id) - - unless @template == @current + + if @template == @current + # If the template is published + if @template.published? + # We need to create a new, editable version + new_version = Template.deep_copy(@template) + new_version.version = (@template.version + 1) + new_version.published = false + new_version.save + @template = new_version +# @current = Template.current(@template.dmptemplate_id) + end + else flash[:notice] = _('You are viewing a historical version of this template. You will not be able to make changes.') end - + + # If the template is published + if @template.published? + # We need to create a new, editable version + new_version = Template.deep_copy(@template) + new_version.version = (@template.version + 1) + new_version.published = false + new_version.save + @template = new_version + end + # once the correct template has been generated, we convert it to hash @hash = @template.to_hash end @@ -161,9 +175,9 @@ def admin_update @template = Template.find(params[:id]) authorize @template - + current = Template.current(@template.dmptemplate_id) - + # Only allow the current version to be updated if current != @template redirect_to admin_template_template_path(@template), notice: _('You can not edit a historical version of this template.') @@ -173,18 +187,18 @@ @template.title != params[:template][:title] @template.dirty = true end - + @template.description = params["template-desc"] if @template.update_attributes(params[:template]) flash[:notice] = _('Information was successfully updated.') - + else flash[:notice] = failed_update_error(@template, _('template')) end - + @hash = @template.to_hash render 'admin_template' - end + end end @@ -219,9 +233,9 @@ def admin_destroy @template = Template.find(params[:id]) authorize @template - + current = Template.current(@template.dmptemplate_id) - + # Only allow the current version to be destroyed if current == @template if @template.destroy @@ -246,4 +260,4 @@ @current = Template.current(@template.dmptemplate_id) end -end \ No newline at end of file +end diff --git a/app/dashboards/annotation_dashboard.rb b/app/dashboards/annotation_dashboard.rb new file mode 100644 index 0000000..e26b609 --- /dev/null +++ b/app/dashboards/annotation_dashboard.rb @@ -0,0 +1,60 @@ +require "administrate/base_dashboard" + +class AnnotationDashboard < Administrate::BaseDashboard + # ATTRIBUTE_TYPES + # a hash that describes the type of each of the model's fields. + # + # Each different type represents an Administrate::Field object, + # which determines how the attribute is displayed + # on pages throughout the dashboard. + ATTRIBUTE_TYPES = { + org: Field::BelongsTo, + question: Field::BelongsTo, + id: Field::Number, + text: Field::Text, + type: Field::String.with_options(searchable: false), + created_at: Field::DateTime, + updated_at: Field::DateTime, + }.freeze + + # COLLECTION_ATTRIBUTES + # an array of attributes that will be displayed on the model's index page. + # + # By default, it's limited to four items to reduce clutter on index pages. + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = [ + :org, + :question, + :id, + :text, + ].freeze + + # SHOW_PAGE_ATTRIBUTES + # an array of attributes that will be displayed on the model's show page. + SHOW_PAGE_ATTRIBUTES = [ + :org, + :question, + :id, + :text, + :type, + :created_at, + :updated_at, + ].freeze + + # FORM_ATTRIBUTES + # an array of attributes that will be displayed + # on the model's form (`new` and `edit`) pages. + FORM_ATTRIBUTES = [ + :org, + :question, + :text, + :type, + ].freeze + + # Overwrite this method to customize how annotations are displayed + # across all pages of the admin dashboard. + # + # def display_resource(annotation) + # "Annotation ##{annotation.id}" + # end +end diff --git a/app/dashboards/org_dashboard.rb b/app/dashboards/org_dashboard.rb index 013748f..c00db7b 100644 --- a/app/dashboards/org_dashboard.rb +++ b/app/dashboards/org_dashboard.rb @@ -12,7 +12,7 @@ guidance_groups: Field::HasMany, templates: Field::HasMany, users: Field::HasMany, - suggested_answers: Field::HasMany, + annotations: Field::HasMany, token_permission_types: Field::HasMany, id: Field::Number, name: Field::String, @@ -59,7 +59,7 @@ :contact_email, :org_type, :users, - :suggested_answers, + :annotations, :token_permission_types, :id, :target_url, @@ -84,7 +84,7 @@ :guidance_groups, # :templates, # :users, -# :suggested_answers, +# :annotations, :token_permission_types, :name, :abbreviation, diff --git a/app/dashboards/question_dashboard.rb b/app/dashboards/question_dashboard.rb index 1d1f8aa..af3d8bb 100644 --- a/app/dashboards/question_dashboard.rb +++ b/app/dashboards/question_dashboard.rb @@ -10,7 +10,7 @@ ATTRIBUTE_TYPES = { answers: Field::HasMany, question_options: Field::HasMany, - suggested_answers: Field::HasMany, + annotations: Field::HasMany, themes: Field::HasMany, section: Field::BelongsTo, question_format: Field::BelongsTo, @@ -33,7 +33,7 @@ COLLECTION_ATTRIBUTES = [ :answers, :question_options, - :suggested_answers, + :annotations, :themes, ].freeze @@ -42,7 +42,7 @@ SHOW_PAGE_ATTRIBUTES = [ :answers, :question_options, - :suggested_answers, + :annotations, :themes, :section, :question_format, @@ -63,7 +63,7 @@ FORM_ATTRIBUTES = [ :answers, :question_options, - :suggested_answers, + :annotations, :themes, :section, :question_format, diff --git a/app/dashboards/suggested_answer_dashboard.rb b/app/dashboards/suggested_answer_dashboard.rb deleted file mode 100644 index 980ef11..0000000 --- a/app/dashboards/suggested_answer_dashboard.rb +++ /dev/null @@ -1,60 +0,0 @@ -require "administrate/base_dashboard" - -class SuggestedAnswerDashboard < Administrate::BaseDashboard - # ATTRIBUTE_TYPES - # a hash that describes the type of each of the model's fields. - # - # Each different type represents an Administrate::Field object, - # which determines how the attribute is displayed - # on pages throughout the dashboard. - ATTRIBUTE_TYPES = { - org: Field::BelongsTo, - question: Field::BelongsTo, - id: Field::Number, - text: Field::Text, - is_example: Field::Boolean, - created_at: Field::DateTime, - updated_at: Field::DateTime, - }.freeze - - # COLLECTION_ATTRIBUTES - # an array of attributes that will be displayed on the model's index page. - # - # By default, it's limited to four items to reduce clutter on index pages. - # Feel free to add, remove, or rearrange items. - COLLECTION_ATTRIBUTES = [ - :org, - :question, - :id, - :text, - ].freeze - - # SHOW_PAGE_ATTRIBUTES - # an array of attributes that will be displayed on the model's show page. - SHOW_PAGE_ATTRIBUTES = [ - :org, - :question, - :id, - :text, - :is_example, - :created_at, - :updated_at, - ].freeze - - # FORM_ATTRIBUTES - # an array of attributes that will be displayed - # on the model's form (`new` and `edit`) pages. - FORM_ATTRIBUTES = [ - :org, - :question, - :text, - :is_example, - ].freeze - - # Overwrite this method to customize how suggested answers are displayed - # across all pages of the admin dashboard. - # - # def display_resource(suggested_answer) - # "SuggestedAnswer ##{suggested_answer.id}" - # end -end diff --git a/app/models/annotation.rb b/app/models/annotation.rb new file mode 100644 index 0000000..66b58e6 --- /dev/null +++ b/app/models/annotation.rb @@ -0,0 +1,40 @@ +class Annotation < ActiveRecord::Base + enum type: [ :guidance, :example_answer] + ## + # Associations + belongs_to :org + belongs_to :question + + ## + # I liked type as the name for the enum so overriding inheritance column + self.inheritance_column = nil + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :org_id, :question_id, :text, :type, + :org, :question, :as => [:default, :admin] + + + validates :question, :org, presence: {message: _("can't be blank")} + + ## + # returns the text from the annotation + # + # @return [String] the text from the annotation + def to_s + "#{text}" + end + + + ## + # deep copy the given annotation and all it's associations + # + # @params [Annotation] annotation to be deep copied + # @return [Annotation] the saved, copied annotation + def self.deep_copy(annotation) + annotation_copy = annotation.dup + annotation_copy.save! + return annotation_copy + end +end \ No newline at end of file diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 5684072..368f077 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -86,7 +86,7 @@ end def questions_for_section(section_id) - questions.where(section_id: section_id).sort_by(&:number) + Question.where(id: questions).where(section_id: section_id).order(:number) end def admin_details @@ -128,6 +128,8 @@ value = self.send(at) if value.present? output += admin_field_t(at.to_s) + ": " + value + "\n" + else + output += admin_field_t(at.to_s) + ": " + _('-') + "\n" end end @@ -162,18 +164,17 @@ private def questions - @questions ||= begin - question_settings = self.settings(:export).fields[:questions] - - return [] if question_settings.is_a?(Array) && question_settings.empty? - - questions = if question_settings.present? && question_settings != :all - Question.where(id: question_settings) + question_settings = self.settings(:export).fields[:questions] + @questions ||= if question_settings.present? + if question_settings == :all + Question.where(section_id: self.plan.sections.collect { |s| s.id }).pluck(:id) + elsif question_settings.is_a?(Array) + question_settings else - Question.where(section_id: self.plan.sections.collect {|s| s.id }) + [] end - - questions.order(:number) + else + [] end end diff --git a/app/models/org.rb b/app/models/org.rb index e11d5e1..e754693 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -10,7 +10,7 @@ has_many :guidance_groups has_many :templates has_many :users - has_many :suggested_answers + has_many :annotations has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions", unique: true diff --git a/app/models/plan.rb b/app/models/plan.rb index 8c8d3c7..549b4fe 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -970,7 +970,7 @@ def self.eager_load2(id) Plan.includes( [{template: [ - {phases: {sections: {questions: [{answers: :notes}, :suggested_answers, :question_format, :themes]}}}, + {phases: {sections: {questions: [{answers: :notes}, :annotations, :question_format, :themes]}}}, {customizations: :org}, :org ]}, diff --git a/app/models/question.rb b/app/models/question.rb index 336cae9..10efc8b 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -3,7 +3,7 @@ # Associations has_many :answers, :dependent => :destroy has_many :question_options, :dependent => :destroy - has_many :suggested_answers, :dependent => :destroy + has_many :annotations, :dependent => :destroy has_and_belongs_to_many :themes, join_table: "questions_themes" belongs_to :section belongs_to :question_format @@ -13,17 +13,17 @@ # TODO: evaluate if we need this accepts_nested_attributes_for :answers, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true accepts_nested_attributes_for :question_options, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true - accepts_nested_attributes_for :suggested_answers, :allow_destroy => true + accepts_nested_attributes_for :annotations, :allow_destroy => true accepts_nested_attributes_for :themes ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, - :suggested_answer, :text, :section_id, :question_format_id, - :question_options_attributes, :suggested_answers_attributes, + :annotation, :text, :section_id, :question_format_id, + :question_options_attributes, :annotations_attributes, :option_comment_display, :theme_ids, :section, :question_format, - :question_options, :suggested_answers, :answers, :themes, + :question_options, :annotations, :answers, :themes, :modifiable, :option_comment_display, :as => [:default, :admin] validates :text, :section, :number, presence: {message: _("can't be blank")} @@ -65,10 +65,10 @@ question_option_copy.question_id = question_copy.id question_option_copy.save! end - question.suggested_answers.each do |suggested_answer| - suggested_answer_copy = SuggestedAnswer.deep_copy(suggested_answer) - suggested_answer_copy.question_id = question_copy.id - suggested_answer_copy.save! + question.annotations.each do |annotation| + annotation_copy = Annotation.deep_copy(annotation) + annotation_copy.question_id = question_copy.id + annotation_copy.save! end question.themes.each do |theme| question_copy.themes << theme @@ -101,13 +101,24 @@ end ## - # get suggested answer belonging to the currents user for this question + # get example answer belonging to the currents user for this question # # @param org_id [Integer] the id for the organisation - # @return [String] the suggested_answer for this question for the specified organisation - def get_suggested_answer(org_id) - suggested_answer = suggested_answers.find_by(org_id: org_id) - return suggested_answer + # @return [String] the example answer for this question for the specified org + def get_example_answer(org_id) + example_answer = self.annotations.where(org_id: org_id).where(type: Annotation.types[:example_answer]).order(:created_at) + return example_answer.first end + ## + # get guidance belonging to the current user's org for this question(need org + # to distinguish customizations) + # + # @param org_id [Integer] the id for the organisation + # @return [String] the annotation guidance for this question for the specified org + def get_guidance_annotation(org_id) + guidance = self.annotations.where(org_id: org_id).where(type: Annotation.types[:guidance]) + return guidance.first + end + end diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb deleted file mode 100644 index 881f302..0000000 --- a/app/models/suggested_answer.rb +++ /dev/null @@ -1,42 +0,0 @@ -class SuggestedAnswer < ActiveRecord::Base - - ## - # Associations - belongs_to :org - belongs_to :question - - ## - # Possibly needed for active_admin - # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :org_id, :question_id, :text, :is_example, - :org, :question, :as => [:default, :admin] - - - validates :question, :org, presence: {message: _("can't be blank")} - - # EVALUATE CLASS AND INSTANCE METHODS BELOW - # - # What do they do? do they do it efficiently, and do we need them? - - - - ## - # returns the text from the suggested_answer - # - # @return [String] the text from the suggested_answer - def to_s - "#{text}" - end - - - ## - # deep copy the given question_option and all it's associations - # - # @params [QuestionOption] question_option to be deep copied - # @return [QuestionOption] the saved, copied question_option - def self.deep_copy(suggested_answer) - suggested_answer_copy = suggested_answer.dup - suggested_answer_copy.save! - return suggested_answer_copy - end -end \ No newline at end of file diff --git a/app/models/template.rb b/app/models/template.rb index 94a845b..f7d5639 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -67,11 +67,11 @@ ## # convert the given template to a hash and return with all it's associations - # to use, please pre-fetch org, phases, section, questions, suggested_answers, + # to use, please pre-fetch org, phases, section, questions, annotations, # question_options, question_formats, # TODO: Themes & guidance? # - # @return [hash] hash of template, phases, sections, questions, question_options, suggested_answers + # @return [hash] hash of template, phases, sections, questions, question_options, annotations def to_hash hash = {} hash[:template] = {} @@ -90,10 +90,10 @@ section.questions.each do |question| phases[phase.number][:sections][section.number][:questions][question.number] = {} phases[phase.number][:sections][section.number][:questions][question.number][:data] = question - phases[phase.number][:sections][section.number][:questions][question.number][:suggested_answers] = {} - question.suggested_answers.each do |suggested_answer| - phases[phase.number][:sections][section.number][:questions][question.number][:suggested_answers][suggested_answer.id] = {} - phases[phase.number][:sections][section.number][:questions][question.number][:suggested_answers][suggested_answer.id][:data] = suggested_answer + phases[phase.number][:sections][section.number][:questions][question.number][:annotations] = {} + question.annotations.each do |annotation| + phases[phase.number][:sections][section.number][:questions][question.number][:annotations][annotation.id] = {} + phases[phase.number][:sections][section.number][:questions][question.number][:annotations][annotation.id][:data] = annotation end phases[phase.number][:sections][section.number][:questions][question.number][:question_options] = {} question.question_options.each do |question_option| diff --git a/app/models/user.rb b/app/models/user.rb index 352b564..14f1af2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -107,14 +107,13 @@ # # @param new_organisation_id [Integer] the id for an organisation # @return [String] the empty string as a causality of setting api_token -=begin - def organisation_id=(new_organisation_id) - unless self.can_change_org? || new_organisation_id.nil? || self.organisation.nil? + def org_id=(new_org_id) + unless self.can_change_org? || new_org_id.nil? || self.org.nil? # rip all permissions from the user self.perms.delete_all end # set the user's new organisation - super(new_organisation_id) + super(new_org_id) self.save! # rip api permissions from the user self.remove_token! @@ -124,10 +123,9 @@ # sets a new organisation for the user # # @param new_organisation [Organisation] the new organisation for the user - def organisation=(new_organisation) - organisation_id = new_organisation.id unless new_organisation.nil? + def organisation=(new_org) + org_id = new_org.id unless new_org.nil? end -=end ## # checks if the user is a super admin diff --git a/app/policies/annotation_policy.rb b/app/policies/annotation_policy.rb new file mode 100644 index 0000000..cf63f42 --- /dev/null +++ b/app/policies/annotation_policy.rb @@ -0,0 +1,28 @@ +class AnnotationPolicy < ApplicationPolicy + attr_reader :user, :annotation + + def initialize(user, annotation) + raise Pundit::NotAuthorizedError, "must be logged in" unless user + @user = user + @annotation = annotation + end + + ## + # Users can modify annotations if: + # - They can modify templates + # - The template which they are modifying belongs to their orggi + ## + + def admin_create? + user.can_modify_templates? && (annotation.question.section.phase.template.org_id == user.org_id) + end + + def admin_update? + user.can_modify_templates? && (annotation.question.section.phase.template.org_id == user.org_id) + end + + def admin_destroy? + user.can_modify_templates? && (annotation.question.section.phase.template.org_id == user.org_id) + end + +end \ No newline at end of file diff --git a/app/policies/phase_policy.rb b/app/policies/phase_policy.rb index 5d43a7e..caa0e3c 100644 --- a/app/policies/phase_policy.rb +++ b/app/policies/phase_policy.rb @@ -8,10 +8,10 @@ end ## + # Org-admin side # Users can modify phases if: # - They can modify templates # - The template which they are modifying belongs to their org - ## def admin_show? user.can_modify_templates? && (phase.template.org_id == user.org_id) diff --git a/app/policies/plan_policy.rb b/app/policies/plan_policy.rb index d6c8703..aa99a2b 100644 --- a/app/policies/plan_policy.rb +++ b/app/policies/plan_policy.rb @@ -7,13 +7,13 @@ @user = user @plan = plan end - + def show? @plan.readable_by?(@user.id) end def edit? - @plan.editable_by?(@user.id) + @plan.readable_by?(@user.id) end def update_guidance_choices? diff --git a/app/policies/suggested_answer_policy.rb b/app/policies/suggested_answer_policy.rb deleted file mode 100644 index e6cd49c..0000000 --- a/app/policies/suggested_answer_policy.rb +++ /dev/null @@ -1,28 +0,0 @@ -class SuggestedAnswerPolicy < ApplicationPolicy - attr_reader :user, :suggested_answer - - def initialize(user, suggested_answer) - raise Pundit::NotAuthorizedError, "must be logged in" unless user - @user = user - @suggested_answer = suggested_answer - end - - ## - # Users can modify suggested answers if: - # - They can modify templates - # - The template which they are modifying belongs to their org - ## - - def admin_create? - user.can_modify_templates? && (suggested_answer.question.section.phase.template.org_id == user.org_id) - end - - def admin_update? - user.can_modify_templates? && (suggested_answer.question.section.phase.template.org_id == user.org_id) - end - - def admin_destroy? - user.can_modify_templates? && (suggested_answer.question.section.phase.template.org_id == user.org_id) - end - -end \ No newline at end of file diff --git a/app/views/administrate/application/_search.html.erb b/app/views/administrate/application/_search.html.erb new file mode 100644 index 0000000..7145011 --- /dev/null +++ b/app/views/administrate/application/_search.html.erb @@ -0,0 +1,21 @@ + diff --git a/app/views/annotations/_add_annotation.html.erb b/app/views/annotations/_add_annotation.html.erb new file mode 100644 index 0000000..8cf9113 --- /dev/null +++ b/app/views/annotations/_add_annotation.html.erb @@ -0,0 +1,25 @@ + +<%= form_for :annotation, url: admin_create_annotation_path do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_id %> + <%= f.hidden_field :question_id, value: question.id %> + <%= f.hidden_field :type, value: Annotation.types[:example_answer] %> + + + + + + +
<%= _('Example Answer')%> +
    +
  • <%= f.text_area :text, rows: 5 %> +
  • +
+
+
+ + +
+ <%= f.submit _('Save'), class: "btn btn-primary" %> + <%= link_to _('Cancel'), "#", id: "cancel_suugested_answer", class: "btn cancel" %> +
+<%end%> diff --git a/app/views/annotations/_edit_annotation.html.erb b/app/views/annotations/_edit_annotation.html.erb new file mode 100644 index 0000000..6fa1e35 --- /dev/null +++ b/app/views/annotations/_edit_annotation.html.erb @@ -0,0 +1,25 @@ + +<%= form_for( annotation, url: admin_update_annotation_path(annotation.id), html: { method: :put}) do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_id %> + + + + + + +
<%= _('Example of Answer')%> +
    +
  • <%= f.text_area :text, rows: 5 %>
  • +
+
+
+ + +
+ <%= f.submit _('Save'), class: 'btn btn-primary' %> + <%= link_to _('Delete'), admin_destroy_annotation_path(id: annotation.id), + confirm: _("You are about to delete an example answer for '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-primary"%> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to _('Cancel'), '#', class: 'btn cancel cancel_edit_suggested_answer' %> +
+<% end %> diff --git a/app/views/annotations/_show_annotation.html.erb b/app/views/annotations/_show_annotation.html.erb new file mode 100644 index 0000000..9cc93de --- /dev/null +++ b/app/views/annotations/_show_annotation.html.erb @@ -0,0 +1,15 @@ + + + + + + +
+ <%= _('Example of answer')%> + <%= raw annotation.text %>
+
+ +
+ <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to _('Edit Example of Answer'), '# ', class: "btn btn-primary edit_form_for_suggested_answer"%> +
diff --git a/app/views/guidances/_edit_guidance.html.erb b/app/views/guidances/_edit_guidance.html.erb index 36fe926..7138ceb 100644 --- a/app/views/guidances/_edit_guidance.html.erb +++ b/app/views/guidances/_edit_guidance.html.erb @@ -1,4 +1,4 @@ - + <%= form_for(suggested_answer, url: admin_update_suggested_answer_path(suggested_answer), html: { method: :put}) do |f| %> <%= f.hidden_field :org_id, value: current_user.org_id %> diff --git a/app/views/guidances/admin_edit.html.erb b/app/views/guidances/admin_edit.html.erb index 565f5d4..7b43313 100644 --- a/app/views/guidances/admin_edit.html.erb +++ b/app/views/guidances/admin_edit.html.erb @@ -24,7 +24,8 @@ - - +
<%= _('Text') %>
+
+
<%= text_area_tag("guidance-text", @guidance.text, class: "tinymce") %>
diff --git a/app/views/guidances/admin_new.html.erb b/app/views/guidances/admin_new.html.erb index eb7f7a3..95239c0 100644 --- a/app/views/guidances/admin_new.html.erb +++ b/app/views/guidances/admin_new.html.erb @@ -19,7 +19,8 @@ - - + <% end %> diff --git a/app/views/plans/export.pdf.erb b/app/views/plans/export.pdf.erb index c41b244..874acd4 100644 --- a/app/views/plans/export.pdf.erb +++ b/app/views/plans/export.pdf.erb @@ -21,9 +21,10 @@

<%= @plan.title %>

<% @exported_plan.admin_details.each do |field| value = @exported_plan.send(field) - if value.present? - %> -

<%= admin_field_t(field.to_s) -%> <%= value -%>

+ if value.present? %> +

<%= admin_field_t(field.to_s) -%> <%= value -%>

+ <% else %> +

<%= admin_field_t(field.to_s) -%> <%= _('-') %>

<% end %> <% end %> diff --git a/app/views/questions/_add_question.html.erb b/app/views/questions/_add_question.html.erb index 3a95f58..9ca04bf 100644 --- a/app/views/questions/_add_question.html.erb +++ b/app/views/questions/_add_question.html.erb @@ -114,20 +114,20 @@ - + - + - + <% end %> <% end %> - <% if !question.guidance.nil? %> + <% guidance = question.get_guidance_annotation(current_user.org_id) %> + <% if guidance.present? %> - + <% end %> @@ -104,17 +101,17 @@
<% if !question.modifiable %> - <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" %> + <% example_answer = question.get_example_answer(current_user.org_id) %> + <% if example_answer.present? && example_answer.text.present? %>
- <%= render partial: 'suggested_answers/show_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %> + <%= render partial: 'annotations/show_annotation', locals: {annotation: example_answer, question: question} %>
<% end %> <% end %> @@ -129,12 +126,12 @@ confirm: _("You are about to delete '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-primary"%> <% elsif !@edit && question.modifiable %> - <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> - <% if suggested_answer.nil? %> + <% example_answer = question.get_example_answer(current_user.org_id) %> + <% if example_answer.nil? %>
<%= hidden_field_tag :question_id, question.id, class: "question_id" %> - <%= link_to _('Add suggested answer/ example'), '# ', class: "btn btn-primary add_suggested_answer_button"%> + <%= link_to _('Add example answer'), '# ', class: "btn btn-primary add_suggested_answer_button"%>
<% end %> diff --git a/app/views/shared/_accessible_combobox.html.erb b/app/views/shared/_accessible_combobox.html.erb index c2f99e0..e06ec20 100644 --- a/app/views/shared/_accessible_combobox.html.erb +++ b/app/views/shared/_accessible_combobox.html.erb @@ -4,6 +4,7 @@ "user", :url => registration_path("user"), :htmlb => {:autocomplete =>"off"}) do |f| %> +<% javascript "shared/register_form.js" %> + +<%= form_for(resource, :as => "user", :url => registration_path("user"), :htmlb => {:autocomplete =>"off"}, :html => {class: "roadmap-form"}) do |f| %>
  • <%= devise_error_messages! %>
  • - <%= f.email_field :email, placeholder: (_('Email') + ' *'), :required => true, :as => :email, :class => 'text_field has-tooltip reg-input', 'data-toggle' => "tooltip", 'data-container' => "body", 'title' => _('This must be a valid email address - a message will be sent to it for confirmation.') %> + <%= f.email_field :email, placeholder: (_('Email') + ' *'), :as => :email, :class => 'text_field has-tooltip reg-input', 'data-toggle' => "tooltip", 'data-container' => "body", 'title' => _('Please enter your email') %> @@ -36,24 +38,28 @@ <%= f.text_field :other_organisation, placeholder: ( _('Organisation name') + ' *'), :as => :string , :autocomplete => "off", :class => 'text_field has-tooltip reg-input', 'data-toggle' => "tooltip", 'data-container' => "body", 'title' => _('Please enter the name of your organisation.') %>
  • - <%= f.password_field :password, placeholder: (_('Password') + ' *'), :autocomplete => "off", :required => true, :as => :password, :class => 'text_field has-tooltip reg-input', 'data-toggle' => "tooltip", 'data-container' => "body", 'title' => _('Your password must contain at least 8 characters.') %> + <%= f.password_field :password, placeholder: (_('Password') + ' *'), :autocomplete => "off", :as => :password, :class => 'text_field has-tooltip reg-input', 'data-toggle' => "tooltip", 'data-container' => "body", 'title' => _('Your password must contain at least 8 characters.') %>
  • - <%= f.password_field :password_confirmation, placeholder: (_('Password confirmation') + ' *'), :required => true, :as => :password, :class => 'text_field has-tooltip reg-input', 'data-toggle' => "tooltip", 'data-container' => "body", 'title' => _('Your password must contain at least 8 characters.') %> + <%= f.password_field :password_confirmation, placeholder: (_('Password confirmation') + ' *'), :as => :password, :class => 'text_field has-tooltip reg-input', 'data-toggle' => "tooltip", 'data-container' => "body", 'title' => _('Your password must contain at least 8 characters.') %>
  • - <%= f.check_box :accept_terms, :required => true %> <%= f.label :accept_terms, :class => "remember_div" do %> - <%= raw _(' I accept the terms and conditions *') % { :current_locale => FastGettext.locale } %> + <%= f.check_box :accept_terms %> <%= f.label :accept_terms, :class => "remember_div" do %> + <%= raw _(' I accept the terms and conditions *') %> <%end%>
  • - <%= f.submit _('Sign up'), :class => "btn btn-primary" %> + <%= render partial: 'shared/accessible_submit_button', + locals: {id: 'sign_up_submit', + val: _('Sign up'), + disabled_initially: true, + tooltip: _('You can not continue until you have filled in all of the required information.')} %>
<% end %> diff --git a/app/views/suggested_answers/_add_suggested_answer.html.erb b/app/views/suggested_answers/_add_suggested_answer.html.erb deleted file mode 100644 index fa5a8bf..0000000 --- a/app/views/suggested_answers/_add_suggested_answer.html.erb +++ /dev/null @@ -1,25 +0,0 @@ - -<%= form_for :suggested_answer, url: admin_create_suggested_answer_path do |f| %> - <%= f.hidden_field :org_id, value: current_user.org_id %> - <%= f.hidden_field :question_id, value: question.id %> - -
<%= _('Text') %>
+
+
<%= text_area_tag("guidance-text", "", class: "tinymce") %>
diff --git a/app/views/layouts/_signin_signout.html.erb b/app/views/layouts/_signin_signout.html.erb index 6222e55..27011a7 100644 --- a/app/views/layouts/_signin_signout.html.erb +++ b/app/views/layouts/_signin_signout.html.erb @@ -19,7 +19,7 @@ <% elsif current_user.can_modify_org_details? %>
  • <%= link_to _("Admin area"), admin_show_org_path(current_user.org_id), class: "signIn_dropdown_link" %>
  • <% elsif current_user.can_grant_permissions? %> -
  • <%= link_to _("Admin area"), admin_index_user_path, class: "signIn_dropdown_link" %>
  • +
  • <%= link_to _("Admin area"), admin_index_users_path, class: "signIn_dropdown_link" %>
  • <% end %> <% end %>
  • <%= link_to _('Sign out'), destroy_user_session_path, method: :delete, class: "signIn_dropdown_link" %>
  • diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb index bdd8c1d..7a1ab93 100644 --- a/app/views/phases/_answer_form.html.erb +++ b/app/views/phases/_answer_form.html.erb @@ -31,22 +31,18 @@ <%= raw question.text %> - - <% if question.suggested_answers.any? %> - <% suggested_answer = question.suggested_answers.first %> - <% if suggested_answer.text.present? %> + + <% if question.annotations.where('type <> ?',Annotation.types[:example_answer]).any? %> + <% annotation = question.annotations.where('type <> ?',Annotation.types[:example_answer]).order(:created_at).first %> + <% if annotation.text.present? %>
    - <% if suggested_answer.is_example? then %> - <%= _('Example of answer')%> - <%else%> - <%= _('Suggested answer')%> - <%end%> + <%="#{annotation.org.abbreviation} "%> <%=_('Example of answer')%>

    - <%= raw suggested_answer.text %> + <%= raw annotation.text %>

    @@ -119,7 +115,8 @@ <% comments = answer.notes.all %> <%= hidden_field_tag :question_id, question_id, class: "question_id" %>
      - <% if question.guidance.present? || question_guidances[question_id] %> + <% annotations = question.annotations.where("type <> ?", Annotation.types[:guidance]) %> + <% if annotations.present? || question_guidances[question_id] %> <% css_style_comment_div = "display: none;"%> <% css_style_guidance_div = ""%> @@ -127,26 +124,26 @@ <%= link_to _('Guidance'), "#", class: "guidance_accordion_button" %>
    • - <% if comments.count > 0 then%> + <% if comments.count > 0%> <% comments_label_with_count = "#{_('Notes')} (#{comments.count})"%> <%= link_to comments_label_with_count , "#", id: "notes_number_#{question_id}", class: "comments_accordion_button" %> - <%else%> + <% else %> <%= link_to _('Share note'), "#", id: "notes_number_#{question_id}", class: "comments_accordion_button" %> - <%end%> + <% end %>
    • - <%else%> + <% else %> <% css_style_comment_div = ""%> <% css_style_guidance_div = "display: none;"%>
    • - <% if comments.count > 0 then%> + <% if comments.count > 0 %> <% comments_label_with_count = "#{_('Notes')} (#{comments.count})"%>

      <%= comments_label_with_count %>

      - <%else%> + <% else %>

      <%= _('Share note') %>

      - <%end%> + <% end %>
    • - <%end%> + <% end %>
    @@ -155,25 +152,28 @@
    - - <% if question.guidance.present? %> -
    + + <% if annotations.present? %> + <% annotations.each do |annotation| %> - - +
    - -
    -
    <%= raw question.guidance %>
    -
    + + -
    + +
    +
    <%= raw annotation.text %>
    +
    + +
    + <% end %> <% end %> @@ -182,13 +182,13 @@ <% group.each do |gobj| %>
    -
    +
    <%= raw gobj[:text] %>
    <% guidance_accordion_id += 1 %> diff --git a/app/views/phases/_answer_form_ro.html.erb b/app/views/phases/_answer_form_ro.html.erb index 4f68019..915db2a 100644 --- a/app/views/phases/_answer_form_ro.html.erb +++ b/app/views/phases/_answer_form_ro.html.erb @@ -1,4 +1,4 @@ - <% q_format = question.question_format%> + <% if readonly != "always" then %>
    > - <%= semantic_form_for answer, :url => {:controller => :answers, :action => :create }, :html=>{:method=>:post}, :remote => true do |f| %> + <%= semantic_form_for answer, :url => {:controller => :answers, :action => :update }, :html=>{:method=>:post}, :remote => true do |f| %> <%= f.inputs do %> <%= f.input :plan_id, :as => :hidden %> <%= f.input :user_id, :as => :hidden, :input_html => { :value => current_user.id } %> @@ -20,22 +21,18 @@ - <%= raw question.text %> +

    <%= raw question.text %>

    - <% suggested_answer = question.suggested_answers.where(org_id: @plan.template.org_id).first %> - <% if suggested_answer.present? %> + <% if question.annotations.where('type <> ?',Annotation.types[:example_answer]).any? %> + <% annotation = question.annotations.where('type <> ?',Annotation.types[:example_answer]).order(:created_at).first %>
    - <% if suggested_answer.is_example? then %> - <%= _('Example of answer')%> - <%else%> - <%= _('Suggested answer')%> - <%end%> + <%= _('Example of answer')%>

    - <%= raw suggested_answer.text %> + <%= raw annotation.text %>

    @@ -45,21 +42,21 @@ <% if q_format.title == _('Check box') || q_format.title == _('Multi select box') || q_format.title == _('Radio buttons') || q_format.title == _('helpers.dropdown') then%> <% options = question.options.order("number") %> - <% if q_format.title == _('Check box') then %> - <% if readonly then %> + <% if q_format.title == _('Check box') %> + <% if readonly %> <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, input_html => { :disabled => true, :id => "options-#{question.id}" } %> <% else %> <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, :input_html => { :id => "options-#{question.id}" } %> <% end %> - <% elsif q_format.title == _('Multi select box') then %> + <% elsif q_format.title == _('Multi select box') %> <% if readonly then %> <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true, :disabled => true , :id => "options-#{question.id}" } %> <% else %> <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true , :id => "options-#{question.id}" } %> <% end %> - <% elsif q_format.title == _('Radio buttons') then%> + <% elsif q_format.title == _('Radio buttons') %>
      <% options.each do |op| %>
    1. @@ -67,31 +64,25 @@ <% if readonly then %> <%= f.radio_button :option_ids, op.id, :checked => true, disabled: true, id: "answer_option_ids_#{op.id}"%> <% else %> - <%= f.radio_button :option_ids, op.id, :checked => true, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, :checked => true, id: "answer_option_ids_#{op.id}"%> <% end %> <%else%> <% if readonly then %> - <%= f.radio_button :option_ids, op.id, :checked => false, disabled: true, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, :checked => false, disabled: true, id: "answer_option_ids_#{op.id}"%> <% else %> - <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> + <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> <% end %> <% end %> <%= op.text %>
    2. <% end %>
    - <% elsif q_format.title == _('Dropdown') then%> - <% if readonly then %> + <% elsif q_format.title == _('Dropdown') %> + <% if readonly %> <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :disabled => true, :id => "options-#{question.id}" } %> <% else %> <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :id => "options-#{question.id}" } %> <% end %> - <% end %> - - <% if question.option_comment_display == true then%> - <%= label_tag("answer-text-#{question.id}".to_sym, _('Comment')) %> - <%= text_area_tag("answer-text-#{question.id}".to_sym, answer.text, class: "tinymce") %> - <%end%> <% elsif q_format.title == _('Text field') then %> @@ -100,16 +91,17 @@ <% elsif q_format.title == _('Text area') then%> <%= text_area_tag("answer-text-#{question.id}".to_sym, answer.text, class: "tinymce") %> <% end %> + + <% if question.option_comment_display == true then%> + <%= label_tag("answer-text-#{question.id}".to_sym, _('Comment')) %> + <%= text_area_tag("answer-text-#{question.id}".to_sym, answer.text, class: "tinymce") %> + <%end%> <% end %> <%= f.actions do %> - <% if readonly then %> - <%= f.action :submit, :label => _('Save'), :button_html => { :class => "btn btn-primary"}, :input_html => { :disabled => true } %> - <% else %> - <%= f.action :submit, :label => _('Save'), :button_html => { :class => "btn btn-primary"} %> - <% end %> + <% end %> <% end %> @@ -117,7 +109,6 @@ <% end %>
    > -

    <%= question.text %>

    <% if q_format.title == _('Check box') || q_format.title == _('Multi select box') || q_format.title == _('Radio buttons') || q_format.title == _('Dropdown') %>
      @@ -138,7 +129,7 @@ <% if answer.created_at.nil? then %> <%= _('Not answered yet') %> <% else %> - <%= _('Answered')%><%= answer.created_at %><%= _(' by')%><%= answer.user.name %> + <%= _('Answered ')%><%= answer.created_at %><%= _(' by ')%><%= answer.user.name %> <% end %>
    @@ -147,12 +138,13 @@
    - <% @comments = Notes.where("question_id = ? AND plan_id = ?", question.id, answer.plan_id ) %> + <% @comments = answer.notes.all %> <%= hidden_field_tag :question_id, question.id, :class => "question_id" %>
      - <% if (!question.guidance.nil? && question.guidance != "") || !question_guidances.empty? then %> + <% q_guidance = question.get_guidance_annotation(current_user.org) %> + <% if (q_guidance.present? && q_guidance.text.present?) || !question_guidances.empty? %> <% css_style_comment_div = "display: none;"%> <% css_style_guidance_div = ""%> @@ -160,8 +152,8 @@ <%= link_to _('Guidance'), "#", :class => "guidance_accordion_button" %>
    • - <% if @comments.count > 0 then%> - <% comments_label_with_count = "#{_('Notes')} (#{@comments.count})"%> + <% if @comments.length > 0 %> + <% comments_label_with_count = "#{_('Notes')} (#{@comments.length})"%> <%= link_to comments_label_with_count , "#", :class => "comments_accordion_button" %> <%else%> <%= link_to _('Share note'), "#", :class => "comments_accordion_button" %> @@ -188,59 +180,56 @@
      - <% if !question.guidance.nil? && question.guidance != "" then %> + <% q_guidance = question.get_guidance_annotation(current_user.org) %> + <% if q_guidance.present? && q_guidance.text.present %> <% end %> - <% guidance_accordion_id = 1 %> - <% question_guidances.each_pair do |theme, group| %> - <% group.each do |gobj| %> -
      - -
      -
      <%= raw gobj[:text] %>
      -
      - <% guidance_accordion_id += 1 %> -
      - <% end %> + <% guidance_accordion_id = 0 %> + <% question_guidances.each_pair do |theme, group| %> + <% group.each do |gobj| %> +
      + +
      +
      <%= raw gobj[:text] %>
      +
      + <% guidance_accordion_id += 1 %> +
      + <% end %> + <% end %> <% end %>
      - <%= render :partial => "comments", locals: {questionId: question.id, plan_id: answer.plan_id }%> + <%= render :partial => "note", locals: {question: question, plan: @plan, answer: answer }%>
    -<% if last_question_id == question.id then %> +<% if last_question_id == question.id %>
    <% else %>
    -<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/phases/_show_phase.html.erb b/app/views/phases/_show_phase.html.erb index 0fb55d0..ecb5dd4 100644 --- a/app/views/phases/_show_phase.html.erb +++ b/app/views/phases/_show_phase.html.erb @@ -4,7 +4,7 @@ <%= _('Phase details')%> - <% if @phase.modifiable %> + <% if @phase.modifiable && @edit %>
    <%= link_to _('Edit phase details'), '#', class: "btn btn-primary", id: "edit_phase_button"%>
    diff --git a/app/views/phases/admin_show.html.erb b/app/views/phases/admin_show.html.erb index cd02a2d..e27f41e 100644 --- a/app/views/phases/admin_show.html.erb +++ b/app/views/phases/admin_show.html.erb @@ -17,7 +17,7 @@
    -<%= render partial: "templates/admin_nav_tabs", locals: {template: @phase.template, active: @phase.id} %> +<%= render partial: "templates/admin_nav_tabs", locals: {template: @phase.template, active: @phase.id, edit: @edit, current: @current} %>
    diff --git a/app/views/phases/edit.html.erb b/app/views/phases/edit.html.erb index f91d5f7..3a29a21 100644 --- a/app/views/phases/edit.html.erb +++ b/app/views/phases/edit.html.erb @@ -28,10 +28,10 @@ <% if session[:question_id_comments].to_i != 0 then %> <% question_from_comment = Question.find(session[:question_id_comments])%> - <% if sectionid == question_from_comment.section_id then %> + <% if sectionid == question_from_comment.section_id then %> <%= hidden_field_tag :comment_section_id, question_from_comment.section_id, :class => "comment_section_id" %> - <%end%> - <% end%> + <%end%> + <% end%>
    @@ -91,9 +91,9 @@ partialname += "_ro" end %> - + <% guidances = @question_guidance[question.id] %> - + <%= render partial: partialname, locals: { plan: @plan, @@ -101,9 +101,10 @@ question: question, question_guidances: guidances, last_question_id: section.questions.last.id, + readonly: @readonly } %> -
    +
    <% end %>
    diff --git a/app/views/plans/_answer_form.html.erb b/app/views/plans/_answer_form.html.erb deleted file mode 100644 index 45f908b..0000000 --- a/app/views/plans/_answer_form.html.erb +++ /dev/null @@ -1,269 +0,0 @@ - -<% answer = @plan.answer(question.id) %> - -
    - - <% q_format = question.question_format%> - - <% if readonly != "always" then %> -
    > - <%= semantic_form_for answer, :url => {:controller => :answers, :action => :create }, :html=>{:method=>:post}, :remote => true do |f| %> - <%= f.inputs do %> - <%= f.input :plan_id, :as => :hidden %> - <%= f.input :user_id, :as => :hidden, :input_html => { :value => current_user.id } %> - <%= f.input :question_id, :as => :hidden, :input_html => { :class => "question_id" } %> - - - - <%= raw question.text %> - - - <% suggested_answer = question.suggested_answers.find_by_organisation_id(@plan.project.organisation_id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" then %> -
    - - <% if suggested_answer.is_example? then %> - <%= _('Example of answer')%> - <%else%> - <%= _('Suggested answer')%> - <%end%> - -
    -

    - <%= raw suggested_answer.text %> -

    -
    -
    - <% end %> - - - <% if q_format.title == "Check box" || - q_format.title == "Multi select box" || - q_format.title == "Radio buttons" || - q_format.title == "Dropdown" then%> - <% options = question.options.order("number") %> - - <% if q_format.title == "Check box" then %> - <% if readonly then %> - <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, input_html => { :disabled => true, :id => "options-#{question.id}" } %> - <% else %> - <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, :input_html => { :id => "options-#{question.id}" } %> - <% end %> - - <% elsif q_format.title == "Multi select box" then %> - <% if readonly then %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true, :disabled => true , :id => "options-#{question.id}" } %> - <% else %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true , :id => "options-#{question.id}" } %> - <% end %> - - <% elsif q_format.title == "Radio buttons" then%> -
      - <% options.each do |op| %> -
    1. - <% if answer.option_ids[0] == op.id then%> - <% if readonly then %> - <%= f.radio_button :option_ids, op.id, :checked => true, disabled: true, id: "answer_option_ids_#{op.id}"%> - <% else %> - <%= f.radio_button :option_ids, op.id, :checked => true, id: "answer_option_ids_#{op.id}"%> - <% end %> - <%else%> - <% if readonly then %> - <%= f.radio_button :option_ids, op.id, :checked => false, disabled: true, id: "answer_option_ids_#{op.id}"%> - <% else %> - <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> - <% end %> - <% end %> - <%= op.text %>
    2. - <% end %> -
    - - <% elsif q_format.title == "Dropdown" then%> - <% if readonly then %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :disabled => true, :id => "options-#{question.id}" } %> - <% else %> - <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :id => "options-#{question.id}" } %> - <% end %> - <% end %> - - - - - <% if question.option_comment_display == true then%> - <%= label_tag("answer-text-#{question.id}".to_sym, _('Comment')) %> - <%= text_area_tag("answer-text-#{question.id}".to_sym, answer.text, class: "tinymce") %> - <%end%> - - - <% elsif q_format.title == "Text field" then %> - <%= text_field_tag("answer-text-#{question.id}".to_sym, strip_tags(answer.text), class: "question_text_field") %> - - <% elsif q_format.title == "Text area" then%> - <%= text_area_tag("answer-text-#{question.id}".to_sym, answer.text, class: "tinymce") %> - <% end %> - - <% end %> - - - <%= f.actions do %> - <% if readonly then %> - <%= f.action :submit, :label => _('Save'), :button_html => { :class => "btn btn-primary"}, :input_html => { :disabled => true } %> - <% else %> - <%= f.action :submit, :label => _('Save'), :button_html => { :class => "btn btn-primary"} %> - - <% end %> - - <% end %> - <% end %> -
    - <% end %> - -
    > -

    <%= question.text %>

    -
    - <% if q_format.title == "Check box" || - q_format.title == "Multi select box" || - q_format.title == "Radio buttons" || - q_format.title == "Dropdown" %> -
      - <% if answer.options.is_a? Option then %> -
    • <%= answer.options.text %>
    • - <% else %> - <% answer.options.each do |o| %> -
    • <%= o.text %>
    • - <% end %> - <% end %> -
    - <% end %> -
    - <%= raw answer.text %> -
    -
    -
    - <% if answer.created_at.nil? then %> - <%= _('Not answered yet') %> - <% else %> - <%= _('Answered')%><%= answer.created_at %><%= _(' by')%><%= answer.user.name %> - <% end %> - -
    - - - -
    -
    - <% @comments = Comment.where("question_id = ? AND plan_id = ?", question.id, answer.plan_id ) %> - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <% @question_guidances = @plan.guidance_for_question(question) %> -
      - <% if (!question.guidance.nil? && question.guidance != "") || @question_guidances.count > 0 then %> - - <% css_style_comment_div = "display: none;"%> - <% css_style_guidance_div = ""%> -
    • - <%= link_to _('Guidance'), "#", :class => "guidance_accordion_button" %> -
    • -
    • - <% if @comments.count > 0 then%> - <% comments_label_with_count = "#{_('Notes')} (#{@comments.count})"%> - <%= link_to comments_label_with_count , "#", :class => "comments_accordion_button" %> - <%else%> - <%= link_to _('Share note'), "#", :class => "comments_accordion_button" %> - <%end%> -
    • - <%else%> - - <% css_style_comment_div = ""%> - <% css_style_guidance_div = "display: none;"%> -
    • - <% if @comments.count > 0 then%> - <% comments_label_with_count = "#{_('Notes')} (#{@comments.count})"%> -

      <%= comments_label_with_count %>

      - <%else%> -

      <%= _('Share note') %>

      - <%end%> -
    • - <%end%> -
    -
    - - - -
    -
    - - <% if !question.guidance.nil? && question.guidance != "" then %> - - <% end %> - - <% @question_guidances.each_pair do |group,themes| %> - <% themes.each_pair do |theme,guidances| %> - <% guidances.each do |guidance| %> - - <% end %> - <% end %> - <% end %> -
    -
    - - -
    - <%= render :partial => "comments", locals: {questionId: question.id, plan_id: answer.plan_id }%> -
    - - - -
    - -<% if last_question_id == question.id then %> -
    -<% else %> -
    -<% end %> diff --git a/app/views/plans/edit.html.erb b/app/views/plans/edit.html.erb index d44caea..57a7d38 100644 --- a/app/views/plans/edit.html.erb +++ b/app/views/plans/edit.html.erb @@ -8,6 +8,7 @@ <%= render :partial => "plan_title", locals: {plan: @plan} %> +

    <%=@readonly%>

    <% status = @plan.status %> diff --git a/app/views/plans/export.html.erb b/app/views/plans/export.html.erb index 990af6c..8e79cc4 100644 --- a/app/views/plans/export.html.erb +++ b/app/views/plans/export.html.erb @@ -22,7 +22,7 @@ %>

    - <%= admin_field_t(field.to_s) -%>

    <%= value.present? ? value : _('-') -%><%= value.present? ? value : _('-') %>
    <%= _('Suggested answer/ Example')%><%= _('Example Answer')%>
    - <% suggested_answer = @new_question.suggested_answers.build %> - <%= f.fields_for :suggested_answers, suggested_answer do |s|%> + <% example_answer = @new_question.annotations.build %> + <% example_answer.type = :example_answer %> + <%= f.fields_for :annotations, example_answer do |s|%> <%= s.hidden_field :org_id, value: current_user.org_id %>
      -
    • <%= s.select :is_example, {_('Example of answer') => true, _('Suggested answer') => false} %>
    • <%= s.text_area :text, rows: 5 %>
    <% end %>
    - <%= link_to( image_tag("help_button.png"), "#", class: "suggested_answer_popover", rel: "popover", "data-html" => "true", "data-content" => _('You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted.'))%> + <%= link_to( image_tag("help_button.png"), "#", class: "suggested_answer_popover", rel: "popover", "data-html" => "true", "data-content" => _('You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted.'))%>
    diff --git a/app/views/questions/_edit_question.html.erb b/app/views/questions/_edit_question.html.erb index 6c3d573..a0928df 100644 --- a/app/views/questions/_edit_question.html.erb +++ b/app/views/questions/_edit_question.html.erb @@ -106,16 +106,16 @@
    <%= _('Suggested answer/ Example')%><%= _('Example Answer')%>
    - <% suggested_answer = question.suggested_answers.find_by_org_id(current_user.org.id) %> - <% if suggested_answer.nil? %> - <% suggested_answer = question.suggested_answers.build %> + <% example_answer = question.get_example_answer(current_user.org.id) %> + <% if example_answer.nil? %> + <% example_answer = question.annotations.build %> + <% example_answer.type = :example_answer %> <% end %> - <%= f.fields_for :suggested_answers, suggested_answer do |s|%> + <%= f.fields_for :annotations, example_answer do |s|%> <%= s.hidden_field :org_id, value: current_user.org.id %>
      -
    • <%= s.select :is_example, {_('Example of answer') => true, _('Suggested answer') => false} %>
    • <%= s.text_area :text, rows: 5 %>
    @@ -132,7 +132,9 @@
    <%= _('Guidance')%>
    - <%= text_area_tag("question-guidance-#{question.id}", question.guidance , class: "tinymce") %> + <% guidance = question.get_guidance_annotation(current_user.org_id) %> + <% guidance_text = guidance.present? ? guidance.text : "" %> + <%= text_area_tag("question-guidance-#{question.id}", guidance_text , class: "tinymce") %>
    <%= link_to( image_tag("help_button.png"), "#", class: "question_guidance_popover", rel: "popover", "data-html" => "true", "data-content" => _("Enter specific guidance to accompany this question. If you have guidance by themes too, this will be pulled in based on your selections below so it's best not to duplicate too much text."))%> diff --git a/app/views/questions/_preview_question.html.erb b/app/views/questions/_preview_question.html.erb index dc51641..e4a86a8 100644 --- a/app/views/questions/_preview_question.html.erb +++ b/app/views/questions/_preview_question.html.erb @@ -57,19 +57,15 @@ <% end %> - <% suggested_answer = question.suggested_answers.find_by(org_id: current_user.org_id) %> - <% if !suggested_answer.blank? %> + <% if question.annotations.where('type <> ?',Annotation.types[:example_answer]).any? %> + <% annotation = question.annotations.where('type <> ?',Annotation.types[:example_answer]).order(:created_at).first %>
    - <% if suggested_answer.is_example? %> <%= _('Example of answer')%> - <% else %> - <%= _('Suggested answer')%> - <% end %>

    - <%= raw suggested_answer.text %> + <%= raw annotation.text %>

    @@ -80,19 +76,15 @@ <% else %> - <% suggested_answer = question.suggested_answers.find_by(org_id: current_user.org_id) %> - <% if !suggested_answer.blank? %> + <% annotations = question.annotations.find_by(org_id: current_user.org_id) %> + <% if !annotations.blank? %>
    - <% if suggested_answer.is_example? %> <%= _('Example of answer')%> - <% else %> - <%= _('Suggested answer')%> - <% end %>

    - <%= raw suggested_answer.text %> + <%= raw annotations.text %>

    @@ -106,9 +98,9 @@ <% if q_format.title == _('Text field') %> - <%elsif q_format.title == _('Text area') %> + <% elsif q_format.title == _('Text area') %> - <%end%> + <% end %>
    <%= link_to _('Save'), "#", class: "btn btn-primary", onclick: "event.preventDefault();" %> diff --git a/app/views/questions/_show_question.html.erb b/app/views/questions/_show_question.html.erb index 754d330..1f3423b 100644 --- a/app/views/questions/_show_question.html.erb +++ b/app/views/questions/_show_question.html.erb @@ -63,25 +63,22 @@ <% if !question.section.phase.template.org.funder? %> - <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" %> + <% example_answer = question.get_example_answer(current_user.org_id) %> + <% if example_answer.present? && example_answer.text.present? %>
    - <% if suggested_answer.is_example? %> - <%= _('Example of answer')%> - <% else %> - <%= _('Suggested answer')%> - <% end %> + <%= _('Example of answer')%> <%= raw suggested_answer.text %><%= raw example_answer.text %>
    <%= _('Guidance')%><%= raw question.guidance %><%= raw guidance.text %>
    - - - - -
    <%= _('Suggested answer/ Example')%> -
      -
    • <%= f.select :is_example, {_('Example of answer') => true, _('Suggested answer') => false} %>
    • -
    • <%= f.text_area :text, rows: 5 %> -
    • -
    -
    -
    - - -
    - <%= f.submit _('Save'), class: "btn btn-primary" %> - <%= link_to _('Cancel'), "#", id: "cancel_suugested_answer", class: "btn cancel" %> -
    -<%end%> diff --git a/app/views/suggested_answers/_edit_suggested_answer.html.erb b/app/views/suggested_answers/_edit_suggested_answer.html.erb deleted file mode 100644 index f0d92b7..0000000 --- a/app/views/suggested_answers/_edit_suggested_answer.html.erb +++ /dev/null @@ -1,26 +0,0 @@ - -<%= form_for(suggested_answer, url: admin_update_suggested_answer_path(suggested_answer), html: { method: :put}) do |f| %> - <%= f.hidden_field :org_id, value: current_user.org_id %> - - - - - - -
    <%= _('Suggested answer/ Example')%> -
      -
    • <%= f.select :is_example, {_('Example of answer') => true, _('Suggested answer') => false} %>
    • -
    • <%= f.text_area :text, rows: 5 %>
    • -
    -
    -
    - - -
    - <%= f.submit _('Save'), class: 'btn btn-primary' %> - <%= link_to _('Delete'), admin_destroy_suggested_answer_path(id: suggested_answer.id), - confirm: _("You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?") % { :question_text => question.text }, method: :delete, class: "btn btn-primary"%> - <%= hidden_field_tag :question_id, question.id, class: "question_id" %> - <%= link_to _('Cancel'), '#', class: 'btn cancel cancel_edit_suggested_answer' %> -
    -<% end %> diff --git a/app/views/suggested_answers/_show_suggested_answer.html.erb b/app/views/suggested_answers/_show_suggested_answer.html.erb deleted file mode 100644 index 5d04606..0000000 --- a/app/views/suggested_answers/_show_suggested_answer.html.erb +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - -
    - <% if suggested_answer.is_example? then %> - <%= _('Example of answer')%> - <% else %> - <%= _('Suggested answer')%> - <% end %> - <%= raw suggested_answer.text %>
    -
    - -
    - <%= hidden_field_tag :question_id, question.id, class: "question_id" %> - <%= link_to _('Edit suggested answer/ example'), '# ', class: "btn btn-primary edit_form_for_suggested_answer"%> -
    diff --git a/app/views/templates/_admin_nav_tabs.html.erb b/app/views/templates/_admin_nav_tabs.html.erb index 79b61df..937faae 100644 --- a/app/views/templates/_admin_nav_tabs.html.erb +++ b/app/views/templates/_admin_nav_tabs.html.erb @@ -1,4 +1,5 @@ + \ No newline at end of file +
    diff --git a/app/views/templates/_edit_annotations.html.erb b/app/views/templates/_edit_annotations.html.erb index 96e7708..d388f61 100644 --- a/app/views/templates/_edit_annotations.html.erb +++ b/app/views/templates/_edit_annotations.html.erb @@ -44,19 +44,17 @@
    <%= _('Suggested answer/ Example')%><%= _('Example of Answer')%>
    - <% suggested_answer = question.suggested_answers.find_by_org_id(current_user.org.id) %> - <% if suggested_answer.nil? %> - <% suggested_answer = question.suggested_answers.build %> + <% annotations = question.annotations.where(org_id: current_user.org_id).where('type <> ?',Annotation.types[:example_answer]).order(:created_at).first %> + <% if annotations.nil? %> + <% annotations = question.annotations.build %> <% end %> - <%= f.fields_for :suggested_answers, suggested_answer do |s|%> + <%= f.fields_for :annotations, annotation do |s|%> <%= s.hidden_field :org_id, value: current_user.org.id %>
      -
    • <%= s.select :is_example, {_('Example of answer') => true, _('Suggested answer') => false} %>
    • -
    • <%= s.text_area :text, rows: 5 %> -
    • +
    • <%= s.text_area :text, rows: 5 %>
    <% end %>
    diff --git a/app/views/templates/_show_phases_sections.html.erb b/app/views/templates/_show_phases_sections.html.erb index 0c15d12..64fe81f 100644 --- a/app/views/templates/_show_phases_sections.html.erb +++ b/app/views/templates/_show_phases_sections.html.erb @@ -17,13 +17,11 @@ <% if template == current && phase.modifiable %> <%= link_to _('Delete'), admin_destroy_phase_path(phase_id: phase.id), confirm: _("You are about to delete '%{phase_title}'. This will affect versions, sections and questions linked to this phase. Are you sure?") % { :phase_title => phase.title }, method: :delete, class: "btn btn-primary"%> - <% end %> - <% if !phase.modifiable %> - <% b_label = _('View phase')%> - <% else %> <% b_label = _('Edit phase')%> + <% else %> + <% b_label = _('View phase')%> <% end %> - <%= link_to b_label, admin_show_phase_path(id: phase.id, edit: (b_label == _('org_admin.templates.edit_phase_label'))), class: "btn btn-primary" %> + <%= link_to b_label, admin_show_phase_path(id: phase.id, edit: (b_label == _('Edit phase'))), class: "btn btn-primary" %> <% if phase_hash[:sections].present? %> diff --git a/app/views/templates/admin_template_history.html.erb b/app/views/templates/admin_template_history.html.erb index 297bf17..95897a8 100644 --- a/app/views/templates/admin_template_history.html.erb +++ b/app/views/templates/admin_template_history.html.erb @@ -36,6 +36,9 @@
    <%= org_template.title%> + <% if org_template == @current && !org_template.published%> +     <%=_('Draft')%> + <% end %> <%= org_template.version %> @@ -60,4 +63,4 @@
    -<%end%> \ No newline at end of file +<%end%> diff --git a/app/views/user_mailer/permissions_change_notification.html.erb b/app/views/user_mailer/permissions_change_notification.html.erb index 92eed7f..c2c0740 100644 --- a/app/views/user_mailer/permissions_change_notification.html.erb +++ b/app/views/user_mailer/permissions_change_notification.html.erb @@ -12,7 +12,7 @@ end %>

    <%= _('Hello ') %><%= @role.user.name %>,

    -

    <%= _('Your permissions relating to ') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%= _(' have been changed by') %><%=" #{@current_user.firstname} #{@current_user.surname}. " %><%= _('You now have ') %><%= access_level %><%= _(' access. ') %><%= permissions %>

    +

    <%= _('Your permissions relating to ') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%= _(' have been changed by') %><%="#{@current_user.name(false)}. " %><%= _('You now have ') %><%= access_level %><%= _(' access. ') %><%= permissions %>

    <%=_('All the best,')%>
    <%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.

    <% end %> diff --git a/app/views/user_mailer/project_access_removed_notification.html.erb b/app/views/user_mailer/project_access_removed_notification.html.erb index 63ec8d9..53a5e40 100644 --- a/app/views/user_mailer/project_access_removed_notification.html.erb +++ b/app/views/user_mailer/project_access_removed_notification.html.erb @@ -1,6 +1,6 @@ <% FastGettext.with_locale FastGettext.default_locale do %>

    <%= _('Hello ') %><%= @user.email %>,

    -

    <%= _('Your access to ') %>"<%= @plan.title %>"<%= _(' has been removed by ') %><%= "#{@current_user.firstname} #{@current_user.surname}"%>.

    +

    <%= _('Your access to ') %>"<%= @plan.title %>"<%= _(' has been removed by ') %><%= "#{@current_user.name(false)}"%>.

    <%=_('All the best,')%>
    <%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.

    <% end %> diff --git a/app/views/user_mailer/sharing_notification.html.erb b/app/views/user_mailer/sharing_notification.html.erb index 95ee5b1..dc2fed4 100644 --- a/app/views/user_mailer/sharing_notification.html.erb +++ b/app/views/user_mailer/sharing_notification.html.erb @@ -13,7 +13,7 @@ %>

    <%= _('Hello ') %><%= @role.user.name %>,

    <%= _('A colleague has invited you to contribute to their Data Management Plan at ') %><%= link_to Rails.configuration.branding[:application][:name], root_url %>.

    -

    <%= _('You have been given ') %><%= access_level %><%= _(' access to') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%=_(' by ')%><%= "#{@user.firstname} #{@user.surname}"%>.

    +

    <%= _('You have been given ') %><%= access_level %><%= _(' access to') %> "<%= link_to @role.plan.title, url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %>" <%=_('by ')%><%= "#{@user.name(false)}" %>.

    <%= link_to _('Click here'), url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %><%= _(' to accept the invitation, (or copy ') %><%= url_for(action: 'show', controller: 'plans', id: @role.plan.id, locale: FastGettext.default_locale) %><%= _(' into your browser)')%>

    <%= _('If you don\'t want to accept the invitation, please ignore this email.') %>

    <%=_('All the best,')%>
    <%= _('The ')%><%= Rails.configuration.branding[:application][:name] %><%=_(' team')%>.

    diff --git a/config/application.rb b/config/application.rb index 8994e51..ce4f957 100644 --- a/config/application.rb +++ b/config/application.rb @@ -81,6 +81,7 @@ config.assets.precompile += %w(roadmap-form.scss) config.assets.precompile += %w(plans/new_plan.js) config.assets.precompile += %w(contacts/new_contact.js) + config.assets.precompile += %w(shared/register_form.js) config.autoload_paths += %W(#{config.root}/lib) config.action_controller.include_all_helpers = true diff --git a/config/locale/app.pot b/config/locale/app.pot index 6dd6de5..8383875 100644 --- a/config/locale/app.pot +++ b/config/locale/app.pot @@ -8,8 +8,8 @@ msgstr "" "Project-Id-Version: app 1.0.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-05-15 20:57+0000\n" -"PO-Revision-Date: 2017-05-15 20:57+0000\n" +"POT-Creation-Date: 2017-05-19 17:36+0100\n" +"PO-Revision-Date: 2017-05-19 17:36+0100\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" @@ -24,7 +24,10 @@ msgid " - " msgstr "" -msgid " I accept the terms and conditions *" +msgid " Guidance" +msgstr "" + +msgid " I accept the terms and conditions *" msgstr "" msgid " Plan" @@ -252,6 +255,9 @@ msgid "Add collaborator" msgstr "" +msgid "Add example answer" +msgstr "" + msgid "Add guidance" msgstr "" @@ -273,9 +279,6 @@ msgid "Add section" msgstr "" -msgid "Add suggested answer/ example" -msgstr "" - msgid "Additional comment area will be displayed." msgstr "" @@ -303,6 +306,9 @@ msgid "Answered" msgstr "" +msgid "Answered " +msgstr "" + msgid "Answered at" msgstr "" @@ -342,6 +348,9 @@ msgid "Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs." msgstr "" +msgid "Begin typing to see a filtered list" +msgstr "" + msgid "Below is a list of users registered for your organisation. You can sort the data by each field." msgstr "" @@ -465,6 +474,9 @@ msgid "Display additional comment area." msgstr "" +msgid "Draft" +msgstr "" + msgid "Dropdown" msgstr "" @@ -474,6 +486,9 @@ msgid "Edit" msgstr "" +msgid "Edit Example of Answer" +msgstr "" + msgid "Edit User Privileges" msgstr "" @@ -495,9 +510,6 @@ msgid "Edit question" msgstr "" -msgid "Edit suggested answer/ example" -msgstr "" - msgid "Edit template details" msgstr "" @@ -537,6 +549,12 @@ msgid "Error!" msgstr "" +msgid "Example Answer" +msgstr "" + +msgid "Example of Answer" +msgstr "" + msgid "Example of answer" msgstr "" @@ -942,6 +960,9 @@ msgid "Please enter your current password below when changing your email address." msgstr "" +msgid "Please enter your email" +msgstr "" + msgid "Please enter your first name." msgstr "" @@ -969,9 +990,6 @@ msgid "Please select one" msgstr "" -msgid "Policy Expectations" -msgstr "" - msgid "Preview" msgstr "" @@ -1233,9 +1251,6 @@ msgid "This document was generated by %{application_name}" msgstr "" -msgid "This must be a valid email address - a message will be sent to it for confirmation." -msgstr "" - msgid "This must match what you entered in the previous field." msgstr "" @@ -1392,12 +1407,18 @@ msgid "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" msgstr "" +msgid "You are about to delete an example answer for '%{question_text}'. Are you sure?" +msgstr "" + msgid "You are not authorized to perform this action." msgstr "" msgid "You are viewing a historical version of this template. You will not be able to make changes." msgstr "" +msgid "You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted." +msgstr "" + msgid "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." msgstr "" @@ -1527,6 +1548,9 @@ msgid "by" msgstr "" +msgid "by " +msgstr "" + msgid "can't be blank" msgstr "" @@ -1539,6 +1563,9 @@ msgid "e.g. School/ Department" msgstr "" +msgid "example answer" +msgstr "" + msgid "from now" msgstr "" @@ -1596,9 +1623,6 @@ msgid "or copy" msgstr "" -msgid "org_admin.templates.edit_phase_label" -msgstr "" - msgid "organisation" msgstr "" @@ -1632,9 +1656,6 @@ msgid "select at least one theme" msgstr "" -msgid "suggested answer" -msgstr "" - msgid "template" msgstr "" diff --git a/config/locale/de/app.po b/config/locale/de/app.po index bdbe788..b52820b 100644 --- a/config/locale/de/app.po +++ b/config/locale/de/app.po @@ -23,7 +23,11 @@ msgstr " - " #, fuzzy -msgid " I accept the terms and conditions *" +msgid " Guidance" +msgstr "Hilfestellung" + +#, fuzzy +msgid " I accept the terms and conditions *" msgstr "Ich akzeptiere die Nutzungsbedingungen *" #, fuzzy @@ -269,6 +273,9 @@ msgid "Add collaborator" msgstr "Mitarbeitende(n) hinzufügen" +msgid "Add example answer" +msgstr "" + msgid "Add guidance" msgstr "Hilfestellung hinzufügen" @@ -290,9 +297,6 @@ msgid "Add section" msgstr "Abschnitt hinzufügen" -msgid "Add suggested answer/ example" -msgstr "Antwortvorschlag / Beispiel hinzufügen" - msgid "Additional comment area will be displayed." msgstr "" @@ -323,6 +327,10 @@ msgstr "Beantwortet " #, fuzzy +msgid "Answered " +msgstr "Beantwortet " + +#, fuzzy msgid "Answered at" msgstr "Beantwortet " @@ -364,6 +372,9 @@ msgid "Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs." msgstr "Fragen" +msgid "Begin typing to see a filtered list" +msgstr "" + msgid "Below is a list of users registered for your organisation. You can sort the data by each field." msgstr "Folgend findet sich die Liste von Benutzern registriert bzgl. Ihrer Org. Sie können diese Liste bzgl. aller Felder sortieren." @@ -492,6 +503,9 @@ msgid "Display additional comment area." msgstr "" +msgid "Draft" +msgstr "" + msgid "Dropdown" msgstr "Klappliste" @@ -501,6 +515,10 @@ msgid "Edit" msgstr "Bearbeiten" +#, fuzzy +msgid "Edit Example of Answer" +msgstr "Beispielantwort" + msgid "Edit User Privileges" msgstr "Bearbeiten Benutzerberechtigungen" @@ -522,9 +540,6 @@ msgid "Edit question" msgstr "Frage bearbeiten" -msgid "Edit suggested answer/ example" -msgstr "Antwortvorschlag / Beispiel bearbeiten" - msgid "Edit template details" msgstr "Details der Vorlage bearbeiten" @@ -565,6 +580,14 @@ msgid "Error!" msgstr "Fehler!" +#, fuzzy +msgid "Example Answer" +msgstr "Beispielantwort" + +#, fuzzy +msgid "Example of Answer" +msgstr "Beispielantwort" + msgid "Example of answer" msgstr "Beispielantwort" @@ -983,6 +1006,9 @@ msgid "Please enter your current password below when changing your email address." msgstr "" +msgid "Please enter your email" +msgstr "" + msgid "Please enter your first name." msgstr "Bitte geben Sie ihren Vornamen ein." @@ -1011,9 +1037,6 @@ msgid "Please select one" msgstr "" -msgid "Policy Expectations" -msgstr "Policy Expectations" - msgid "Preview" msgstr "Vorschau" @@ -1282,9 +1305,6 @@ msgid "This document was generated by %{application_name}" msgstr "%{application_name}" -msgid "This must be a valid email address - a message will be sent to it for confirmation." -msgstr "" - msgid "This must match what you entered in the previous field." msgstr "Die Eingabe in diesem Feld muss mit der im vorherigen Feld übereinstimmen." @@ -1450,6 +1470,10 @@ msgid "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" msgstr "Sie sind dabei den Antwortvorschlag / das Beispiel für '%{question_text}' zu löschen. Sind Sie sicher?" +#, fuzzy +msgid "You are about to delete an example answer for '%{question_text}'. Are you sure?" +msgstr "Sie sind dabei den Antwortvorschlag / das Beispiel für '%{question_text}' zu löschen. Sind Sie sicher?" + msgid "You are not authorized to perform this action." msgstr "" @@ -1457,6 +1481,10 @@ msgid "You are viewing a historical version of this template. You will not be able to make changes." msgstr "templates" +#, fuzzy +msgid "You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted." +msgstr "Hier können Sie einen Text als Beispiel oder Vorschlag angeben, der Nutzern bei der Beantwortung helfen soll. Der Text erscheint oberhalb des Antwortfeldes und kann kopiert und eingefügt werden." + msgid "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." msgstr "Hier können Sie einen Text als Beispiel oder Vorschlag angeben, der Nutzern bei der Beantwortung helfen soll. Der Text erscheint oberhalb des Antwortfeldes und kann kopiert und eingefügt werden." @@ -1609,6 +1637,10 @@ msgid "by" msgstr "" +#, fuzzy +msgid "by " +msgstr " von " + msgid "can't be blank" msgstr "" @@ -1621,6 +1653,10 @@ msgid "e.g. School/ Department" msgstr "z.B. Fakultät / Einrichtung" +#, fuzzy +msgid "example answer" +msgstr "Beispielantwort" + msgid "from now" msgstr "" @@ -1687,10 +1723,6 @@ msgstr "(or copy" #, fuzzy -msgid "org_admin.templates.edit_phase_label" -msgstr "org_admin" - -#, fuzzy msgid "organisation" msgstr "Organisation" @@ -1731,10 +1763,6 @@ msgstr "select at least one theme" #, fuzzy -msgid "suggested answer" -msgstr "Antwortvorschlag" - -#, fuzzy msgid "template" msgstr "templates" diff --git a/config/locale/en_GB/app.po b/config/locale/en_GB/app.po index 3a2db97..8c0cca3 100644 --- a/config/locale/en_GB/app.po +++ b/config/locale/en_GB/app.po @@ -22,7 +22,12 @@ msgid " - " msgstr " - " -msgid " I accept the terms and conditions *" +#, fuzzy +msgid " Guidance" +msgstr "Guidance" + +#, fuzzy +msgid " I accept the terms and conditions *" msgstr " I accept the terms and conditions *" #, fuzzy @@ -259,6 +264,9 @@ msgid "Add collaborator" msgstr "Add collaborator" +msgid "Add example answer" +msgstr "" + msgid "Add guidance" msgstr "Add guidance" @@ -280,9 +288,6 @@ msgid "Add section" msgstr "Add section" -msgid "Add suggested answer/ example" -msgstr "Add suggested answer/ example" - msgid "Additional comment area will be displayed." msgstr "Additional comment area will be displayed." @@ -310,6 +315,10 @@ msgid "Answered" msgstr "Answered" +#, fuzzy +msgid "Answered " +msgstr "Answered" + msgid "Answered at" msgstr "Answered at" @@ -350,6 +359,9 @@ msgid "Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs." msgstr "questions" +msgid "Begin typing to see a filtered list" +msgstr "" + msgid "Below is a list of users registered for your organisation. You can sort the data by each field." msgstr "Below is a list of users registered for your organisation. You can sort the data by each field." @@ -474,6 +486,9 @@ msgid "Display additional comment area." msgstr "Display additional comment area." +msgid "Draft" +msgstr "" + msgid "Dropdown" msgstr "Dropdown" @@ -483,6 +498,10 @@ msgid "Edit" msgstr "Edit" +#, fuzzy +msgid "Edit Example of Answer" +msgstr "Example of answer" + msgid "Edit User Privileges" msgstr "Edit User Privileges" @@ -504,9 +523,6 @@ msgid "Edit question" msgstr "Edit question" -msgid "Edit suggested answer/ example" -msgstr "Edit suggested answer/ example" - msgid "Edit template details" msgstr "Edit template details" @@ -546,6 +562,14 @@ msgid "Error!" msgstr "Error!" +#, fuzzy +msgid "Example Answer" +msgstr "Example of answer" + +#, fuzzy +msgid "Example of Answer" +msgstr "Example of answer" + msgid "Example of answer" msgstr "Example of answer" @@ -959,6 +983,9 @@ msgid "Please enter your current password below when changing your email address." msgstr "" +msgid "Please enter your email" +msgstr "" + msgid "Please enter your first name." msgstr "Please enter your first name." @@ -987,9 +1014,6 @@ msgid "Please select one" msgstr "" -msgid "Policy Expectations" -msgstr "Policy Expectations" - msgid "Preview" msgstr "Preview" @@ -1256,9 +1280,6 @@ msgid "This document was generated by %{application_name}" msgstr "This document was generated by %{application_name}" -msgid "This must be a valid email address - a message will be sent to it for confirmation." -msgstr "This must be a valid email address - a message will be sent to it for confirmation." - msgid "This must match what you entered in the previous field." msgstr "This must match what you entered in the previous field." @@ -1421,12 +1442,20 @@ msgid "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" msgstr "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" +#, fuzzy +msgid "You are about to delete an example answer for '%{question_text}'. Are you sure?" +msgstr "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" + msgid "You are not authorized to perform this action." msgstr "" msgid "You are viewing a historical version of this template. You will not be able to make changes." msgstr "You are viewing a historical version of this template. You will not be able to make changes." +#, fuzzy +msgid "You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted." +msgstr "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." + msgid "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." msgstr "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." @@ -1560,6 +1589,10 @@ msgid "by" msgstr "" +#, fuzzy +msgid "by " +msgstr " by " + msgid "can't be blank" msgstr "" @@ -1572,6 +1605,10 @@ msgid "e.g. School/ Department" msgstr "e.g. School/ Department" +#, fuzzy +msgid "example answer" +msgstr "Example of answer" + msgid "from now" msgstr "from now" @@ -1631,9 +1668,6 @@ msgid "or copy" msgstr "or copy" -msgid "org_admin.templates.edit_phase_label" -msgstr "" - msgid "organisation" msgstr "organisation" @@ -1667,9 +1701,6 @@ msgid "select at least one theme" msgstr "select at least one theme" -msgid "suggested answer" -msgstr "suggested answer" - msgid "template" msgstr "template" diff --git a/config/locale/en_US/app.po b/config/locale/en_US/app.po index dd2eafe..b70e2b3 100644 --- a/config/locale/en_US/app.po +++ b/config/locale/en_US/app.po @@ -22,7 +22,12 @@ msgid " - " msgstr " - " -msgid " I accept the terms and conditions *" +#, fuzzy +msgid " Guidance" +msgstr "Guidance" + +#, fuzzy +msgid " I accept the terms and conditions *" msgstr " I accept the terms and conditions *" #, fuzzy @@ -259,6 +264,9 @@ msgid "Add collaborator" msgstr "Add collaborator" +msgid "Add example answer" +msgstr "" + msgid "Add guidance" msgstr "Add guidance" @@ -280,9 +288,6 @@ msgid "Add section" msgstr "Add section" -msgid "Add suggested answer/ example" -msgstr "Add suggested answer/ example" - msgid "Additional comment area will be displayed." msgstr "Additional comment area will be displayed." @@ -310,6 +315,10 @@ msgid "Answered" msgstr "Answered" +#, fuzzy +msgid "Answered " +msgstr "Answered" + msgid "Answered at" msgstr "Answered at" @@ -350,6 +359,9 @@ msgid "Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs." msgstr "questions" +msgid "Begin typing to see a filtered list" +msgstr "" + msgid "Below is a list of users registered for your organisation. You can sort the data by each field." msgstr "Below is a list of users registered for your organization. You can sort the data by each field." @@ -474,6 +486,9 @@ msgid "Display additional comment area." msgstr "Display additional comment area." +msgid "Draft" +msgstr "" + msgid "Dropdown" msgstr "Dropdown" @@ -483,6 +498,10 @@ msgid "Edit" msgstr "Edit" +#, fuzzy +msgid "Edit Example of Answer" +msgstr "Example of answer" + msgid "Edit User Privileges" msgstr "Edit User Permissions" @@ -504,9 +523,6 @@ msgid "Edit question" msgstr "Edit question" -msgid "Edit suggested answer/ example" -msgstr "Edit suggested answer/ example" - msgid "Edit template details" msgstr "Edit template details" @@ -546,6 +562,14 @@ msgid "Error!" msgstr "Error!" +#, fuzzy +msgid "Example Answer" +msgstr "Example of answer" + +#, fuzzy +msgid "Example of Answer" +msgstr "Example of answer" + msgid "Example of answer" msgstr "Example of answer" @@ -959,6 +983,9 @@ msgid "Please enter your current password below when changing your email address." msgstr "" +msgid "Please enter your email" +msgstr "" + msgid "Please enter your first name." msgstr "Please enter your first name." @@ -987,9 +1014,6 @@ msgid "Please select one" msgstr "" -msgid "Policy Expectations" -msgstr "Policy Expectations" - msgid "Preview" msgstr "Preview" @@ -1256,9 +1280,6 @@ msgid "This document was generated by %{application_name}" msgstr "This document was generated by %{application_name}" -msgid "This must be a valid email address - a message will be sent to it for confirmation." -msgstr "This must be a valid email address - a message will be sent to it for confirmation." - msgid "This must match what you entered in the previous field." msgstr "This must match what you entered in the previous field." @@ -1421,12 +1442,20 @@ msgid "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" msgstr "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" +#, fuzzy +msgid "You are about to delete an example answer for '%{question_text}'. Are you sure?" +msgstr "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" + msgid "You are not authorized to perform this action." msgstr "" msgid "You are viewing a historical version of this template. You will not be able to make changes." msgstr "You are viewing a historical version of this template. You will not be able to make changes." +#, fuzzy +msgid "You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted." +msgstr "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." + msgid "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." msgstr "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." @@ -1560,6 +1589,10 @@ msgid "by" msgstr "" +#, fuzzy +msgid "by " +msgstr " by " + msgid "can't be blank" msgstr "" @@ -1572,6 +1605,10 @@ msgid "e.g. School/ Department" msgstr "e.g. School/ Department" +#, fuzzy +msgid "example answer" +msgstr "Example of answer" + msgid "from now" msgstr "from now" @@ -1631,9 +1668,6 @@ msgid "or copy" msgstr "or copy" -msgid "org_admin.templates.edit_phase_label" -msgstr "" - msgid "organisation" msgstr "organization" @@ -1667,9 +1701,6 @@ msgid "select at least one theme" msgstr "select at least one theme" -msgid "suggested answer" -msgstr "suggested answer" - msgid "template" msgstr "template" diff --git a/config/locale/es/app.po b/config/locale/es/app.po index 4909cb5..5711578 100644 --- a/config/locale/es/app.po +++ b/config/locale/es/app.po @@ -23,7 +23,11 @@ msgstr "" #, fuzzy -msgid " I accept the terms and conditions *" +msgid " Guidance" +msgstr "Guía" + +#, fuzzy +msgid " I accept the terms and conditions *" msgstr " Acepto los términos y condiciones *" #, fuzzy @@ -265,6 +269,9 @@ msgid "Add collaborator" msgstr "Añadir colaborador" +msgid "Add example answer" +msgstr "" + msgid "Add guidance" msgstr "Añadir orientación" @@ -286,9 +293,6 @@ msgid "Add section" msgstr "Añadir sección" -msgid "Add suggested answer/ example" -msgstr "Añadir respuesta sugerida / ejemplo" - msgid "Additional comment area will be displayed." msgstr "Se mostrará un área adicional para comentarios." @@ -319,6 +323,10 @@ msgstr "Contestado " #, fuzzy +msgid "Answered " +msgstr "Contestado " + +#, fuzzy msgid "Answered at" msgstr "Contestado " @@ -361,6 +369,9 @@ msgid "Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs." msgstr "Preguntas" +msgid "Begin typing to see a filtered list" +msgstr "" + msgid "Below is a list of users registered for your organisation. You can sort the data by each field." msgstr "Debajo tiene la lista de usuarios registrados en su entidad. Puede ordenar los datos por campo." @@ -488,6 +499,9 @@ msgid "Display additional comment area." msgstr "Mostrar un área de comentarios adicional." +msgid "Draft" +msgstr "" + msgid "Dropdown" msgstr "Dropdown" @@ -497,6 +511,10 @@ msgid "Edit" msgstr "Editar" +#, fuzzy +msgid "Edit Example of Answer" +msgstr "Respuesta de ejemplo" + msgid "Edit User Privileges" msgstr "" @@ -518,9 +536,6 @@ msgid "Edit question" msgstr "Editar la pregunta" -msgid "Edit suggested answer/ example" -msgstr "Editar respuesta sugerida / ejemplo" - msgid "Edit template details" msgstr "Editar plantilla" @@ -561,6 +576,14 @@ msgid "Error!" msgstr "¡Error!" +#, fuzzy +msgid "Example Answer" +msgstr "Respuesta de ejemplo" + +#, fuzzy +msgid "Example of Answer" +msgstr "Respuesta de ejemplo" + msgid "Example of answer" msgstr "Respuesta de ejemplo" @@ -978,6 +1001,9 @@ msgid "Please enter your current password below when changing your email address." msgstr "" +msgid "Please enter your email" +msgstr "" + msgid "Please enter your first name." msgstr "Por favor, introduzca su nombre." @@ -1006,9 +1032,6 @@ msgid "Please select one" msgstr "" -msgid "Policy Expectations" -msgstr "Política esperada" - msgid "Preview" msgstr "Previsualización" @@ -1275,9 +1298,6 @@ msgid "This document was generated by %{application_name}" msgstr "DMPonline" -msgid "This must be a valid email address - a message will be sent to it for confirmation." -msgstr "" - msgid "This must match what you entered in the previous field." msgstr "Ha de coincidir con lo que introdujo en el campo anterior." @@ -1443,6 +1463,10 @@ msgid "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" msgstr "Va a eliminar una respuesta sugerida / ejemplo de '%{question_text}'. ¿Está seguro?" +#, fuzzy +msgid "You are about to delete an example answer for '%{question_text}'. Are you sure?" +msgstr "Va a eliminar una respuesta sugerida / ejemplo de '%{question_text}'. ¿Está seguro?" + msgid "You are not authorized to perform this action." msgstr "" @@ -1450,6 +1474,10 @@ msgid "You are viewing a historical version of this template. You will not be able to make changes." msgstr "templates" +#, fuzzy +msgid "You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted." +msgstr "Puede añadir un ejemplo o respuesta sugerida para ayudar a responder a sus usuarios. Se presentará bajo la caja de respuestas y pueden ser copiada y pegada." + msgid "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." msgstr "Puede añadir un ejemplo o respuesta sugerida para ayudar a responder a sus usuarios. Se presentará bajo la caja de respuestas y pueden ser copiada y pegada." @@ -1594,6 +1622,10 @@ msgid "by" msgstr "" +#, fuzzy +msgid "by " +msgstr " por " + msgid "can't be blank" msgstr "" @@ -1606,6 +1638,10 @@ msgid "e.g. School/ Department" msgstr "ej: Escuela / Departmento" +#, fuzzy +msgid "example answer" +msgstr "Respuesta de ejemplo" + msgid "from now" msgstr "" @@ -1670,10 +1706,6 @@ msgstr "" #, fuzzy -msgid "org_admin.templates.edit_phase_label" -msgstr "org_admin" - -#, fuzzy msgid "organisation" msgstr "Organización" @@ -1714,10 +1746,6 @@ msgstr "" #, fuzzy -msgid "suggested answer" -msgstr "Respuesta sugerida" - -#, fuzzy msgid "template" msgstr "templates" diff --git a/config/locale/fr/app.po b/config/locale/fr/app.po index e582167..21b7c0d 100644 --- a/config/locale/fr/app.po +++ b/config/locale/fr/app.po @@ -23,7 +23,11 @@ msgstr "" #, fuzzy -msgid " I accept the terms and conditions *" +msgid " Guidance" +msgstr "Conseils" + +#, fuzzy +msgid " I accept the terms and conditions *" msgstr " Jaccepte les Conditions générales dutilisation. *" #, fuzzy @@ -264,6 +268,9 @@ msgid "Add collaborator" msgstr "Ajouter le collaborateur" +msgid "Add example answer" +msgstr "" + msgid "Add guidance" msgstr "Ajoutez des conseils" @@ -285,9 +292,6 @@ msgid "Add section" msgstr "Ajouter une section" -msgid "Add suggested answer/ example" -msgstr "Ajouter une suggestion/un exemple de réponse" - msgid "Additional comment area will be displayed." msgstr "" @@ -318,6 +322,10 @@ msgstr "Réponse " #, fuzzy +msgid "Answered " +msgstr "Réponse " + +#, fuzzy msgid "Answered at" msgstr "Réponse " @@ -360,6 +368,9 @@ msgid "Before you get started, we need to ask a few questions to set you up with the best DMP template for your needs." msgstr "Questions" +msgid "Begin typing to see a filtered list" +msgstr "" + msgid "Below is a list of users registered for your organisation. You can sort the data by each field." msgstr "La liste ci-dessous indique les utilisateurs de votre organisme. Ces informations peuvent être triées par champ." @@ -486,6 +497,9 @@ msgid "Display additional comment area." msgstr "" +msgid "Draft" +msgstr "" + msgid "Dropdown" msgstr "Liste déroulante" @@ -495,6 +509,10 @@ msgid "Edit" msgstr "Modifier" +#, fuzzy +msgid "Edit Example of Answer" +msgstr "Exemple de réponse" + msgid "Edit User Privileges" msgstr "" @@ -516,9 +534,6 @@ msgid "Edit question" msgstr "Modifier la question" -msgid "Edit suggested answer/ example" -msgstr "Modifier la suggestion/lexemple de réponse" - msgid "Edit template details" msgstr "Modifier les détails du modèle" @@ -559,6 +574,14 @@ msgid "Error!" msgstr "Erreur!" +#, fuzzy +msgid "Example Answer" +msgstr "Exemple de réponse" + +#, fuzzy +msgid "Example of Answer" +msgstr "Exemple de réponse" + msgid "Example of answer" msgstr "Exemple de réponse" @@ -975,6 +998,9 @@ msgid "Please enter your current password below when changing your email address." msgstr "" +msgid "Please enter your email" +msgstr "" + msgid "Please enter your first name." msgstr "Entrez votre prénom, svp." @@ -1003,9 +1029,6 @@ msgid "Please select one" msgstr "" -msgid "Policy Expectations" -msgstr "Résultats attendus du plan" - msgid "Preview" msgstr "Aperçu" @@ -1272,9 +1295,6 @@ msgid "This document was generated by %{application_name}" msgstr "%{application_name}" -msgid "This must be a valid email address - a message will be sent to it for confirmation." -msgstr "" - msgid "This must match what you entered in the previous field." msgstr "" @@ -1440,6 +1460,10 @@ msgid "You are about to delete a suggested answer/ example for '%{question_text}'. Are you sure?" msgstr "Vous allez supprimer la suggestion/lexemple de réponse à la questioo : %{question_text}. En êtes-vous sûr ?" +#, fuzzy +msgid "You are about to delete an example answer for '%{question_text}'. Are you sure?" +msgstr "Vous allez supprimer la suggestion/lexemple de réponse à la questioo : %{question_text}. En êtes-vous sûr ?" + msgid "You are not authorized to perform this action." msgstr "" @@ -1447,6 +1471,10 @@ msgid "You are viewing a historical version of this template. You will not be able to make changes." msgstr "templates" +#, fuzzy +msgid "You can add an example answer to help users respond. These will be presented above the answer box and can be copied/ pasted." +msgstr "Vous pouvez ajouter un exemple ou une suggestion de réponse pour aider les utilisateurs. Ils safficheront au-dessus de la grille de réponse et on peut les copier/coller." + msgid "You can add an example or suggested answer to help users respond. These will be presented above the answer box and can be copied/ pasted." msgstr "Vous pouvez ajouter un exemple ou une suggestion de réponse pour aider les utilisateurs. Ils safficheront au-dessus de la grille de réponse et on peut les copier/coller." @@ -1591,6 +1619,10 @@ msgid "by" msgstr "" +#, fuzzy +msgid "by " +msgstr " par " + msgid "can't be blank" msgstr "" @@ -1603,6 +1635,10 @@ msgid "e.g. School/ Department" msgstr "par ex. : Faculté/Département" +#, fuzzy +msgid "example answer" +msgstr "Exemple de réponse" + msgid "from now" msgstr "" @@ -1667,10 +1703,6 @@ msgstr "" #, fuzzy -msgid "org_admin.templates.edit_phase_label" -msgstr "org_admin" - -#, fuzzy msgid "organisation" msgstr "Organisation" @@ -1711,10 +1743,6 @@ msgstr "" #, fuzzy -msgid "suggested answer" -msgstr "Suggestion de réponse" - -#, fuzzy msgid "template" msgstr "templates" diff --git a/config/routes.rb b/config/routes.rb index c09d22f..27c1d67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ resources :questions resources :question_formats resources :question_options - resources :suggested_answers + resources :annotations resources :answers resources :guidances resources :guidance_groups @@ -161,7 +161,7 @@ end end - resources :suggested_answers, path: 'org/admin/templates/suggested_answers', only: [] do + resources :annotations, path: 'org/admin/templates/annotations', only: [] do member do post 'admin_create' put 'admin_update' diff --git a/db/schema.rb b/db/schema.rb index fe00e7b..f0bfbd2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -16,6 +16,15 @@ # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "annotations", force: :cascade do |t| + t.integer "question_id" + t.integer "org_id" + t.text "text" + t.integer "type", default: 0, null: false + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "answers", force: :cascade do |t| t.text "text" t.integer "plan_id" @@ -271,15 +280,6 @@ t.datetime "updated_at", null: false end - create_table "suggested_answers", force: :cascade do |t| - t.integer "question_id" - t.integer "org_id" - t.text "text" - t.boolean "is_example" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "templates", force: :cascade do |t| t.string "title" t.text "description" @@ -330,8 +330,8 @@ t.string "email", default: "", null: false t.string "orcid_id" t.string "shibboleth_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "encrypted_password", default: "" t.string "reset_password_token" t.datetime "reset_password_sent_at" @@ -370,6 +370,8 @@ add_index "users_perms", ["user_id", "perm_id"], name: "index_users_perms_on_user_id_and_perm_id", using: :btree + add_foreign_key "annotations", "orgs" + add_foreign_key "annotations", "questions" add_foreign_key "answers", "plans" add_foreign_key "answers", "questions" add_foreign_key "answers", "users" @@ -395,8 +397,6 @@ add_foreign_key "roles", "plans" add_foreign_key "roles", "users" add_foreign_key "sections", "phases" - add_foreign_key "suggested_answers", "orgs" - add_foreign_key "suggested_answers", "questions" add_foreign_key "templates", "orgs" add_foreign_key "themes_in_guidance", "guidances" add_foreign_key "themes_in_guidance", "themes" diff --git a/db/seeds.rb b/db/seeds.rb index 9277a5a..7da10a5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -671,17 +671,17 @@ # Create suggested answers for a few questions # ------------------------------------------------------- -suggested_answers = [ +annotations = [ {text: "We will preserve it in Dryad or a similar data repository service.", - is_example: true, + type: Annotation.types[:example_answer], org: Org.find_by(abbreviation: 'GA'), question: Question.find_by(text: "What is your policy for long term access to your dataset?")}, {text: "We recommend that you identify the type(s) of content as well as the type of file(s) involved", - is_example: false, + type: Annotation.types[:example_answer], org: Org.find_by(abbreviation: 'GA'), question: Question.find_by(text: "What types of data will you collect and how will it be stored?")}, ] -suggested_answers.map{ |s| SuggestedAnswer.create!(s) if SuggestedAnswer.find_by(text: s[:text]).nil? } +annotations.map{ |s| Annotation.create!(s) if Annotation.find_by(text: s[:text]).nil? } # Create options for the dropdown, multi-select and radio buttons # ------------------------------------------------------- diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index 59b9a26..3f45565 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -84,33 +84,6 @@ $(this).closest("form").submit(); }); - $("#user_email.text_field.reg-input").blur(function () { - if (validateEmail($(this).val())) { - $(this).parent().children("div").hide(); - } - else { - $(this).parent().children("div").show(); - } - }); - - $("#user_password.text_field.reg-input").blur(function () { - if ($(this).val().length >= 8) { - $(this).parent().children("div").hide(); - } - else { - $(this).parent().children("div").show(); - } - }); - - $("#user_password_confirmation.text_field.reg-input").blur(function () { - if ($(this).val() == $("#user_password.text_field.reg-input").val()) { - $(this).parent().children("div").hide(); - } - else { - $(this).parent().children("div").show(); - } - }); - $('#user_organisation_id').on("change", function(e) { e.preventDefault(); var selected_org = $(this).select2("val"); @@ -199,17 +172,6 @@ }); // --------------------------------------------------------------------------- -function validateEmail(sEmail) { - var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/; - if (filter.test(sEmail)) { - return true; - } - else { - return false; - } -} - -// --------------------------------------------------------------------------- function selectItemsFromJsonArray(array, selector, array_of_values, callback){ var out = []; diff --git a/lib/assets/javascripts/shared/register_form.js b/lib/assets/javascripts/shared/register_form.js new file mode 100644 index 0000000..82b077d --- /dev/null +++ b/lib/assets/javascripts/shared/register_form.js @@ -0,0 +1,61 @@ +$(document).ready(function() { + var email_regex = /[^@\s]+@(?:[-a-z0-9]+\.)+[a-z]{2,}$/; + var valid_email = false; + var valid_password = false; + var valid_password_confirmation = false; + var valid_accept_terms = false; + + $("#user_email.text_field.reg-input").change(function(){ + if (email_regex.test($(this).val())) { + $(this).next().hide(); + valid_email = true; + } + else { + $(this).next().show(); + valid_email = false; + } + set_aria_submit(); + }); + $("#user_password.text_field.reg-input").change(function() { + if($(this).val().length >= 8) { + $(this).next().hide(); + valid_password = true; + } + else { + $(this).next().show(); + valid_password = false; + } + // If password_confirmation is non empty already, force to check its validity + if($("#user_password_confirmation.text_field.reg-input").val().length > 0){ + console.log('force to check validity of confirmation'); + $("#user_password_confirmation.text_field.reg-input").change(); + } + set_aria_submit(); + }); + $("#user_password_confirmation.text_field.reg-input").change(function() { + if ($(this).val() === $("#user_password.text_field.reg-input").val()) { + $(this).next().hide(); + valid_password_confirmation = true; + } + else { + $(this).next().show(); + valid_password_confirmation = false; + } + set_aria_submit(); + }); + $("#user_accept_terms").change(function(){ + valid_accept_terms = $(this).prop('checked'); + set_aria_submit(); + }); + function set_aria_submit(){ + if(valid_email + && valid_password + && valid_password_confirmation + && valid_accept_terms){ + $("#sign_up_submit").attr('aria-disabled', false); + } + else { + $("#sign_up_submit").attr('aria-disabled', true); + } + } +}); \ No newline at end of file diff --git a/lib/assets/stylesheets/admin.css.less b/lib/assets/stylesheets/admin.css.less index 00ea783..89eadf6 100644 --- a/lib/assets/stylesheets/admin.css.less +++ b/lib/assets/stylesheets/admin.css.less @@ -1185,6 +1185,10 @@ width: 250px; } +table.dmp_details_table tr td.tinymce{ + min-width: 370px; +} + table.dmp_details_table .text_area{ width: 90%; } diff --git a/lib/assets/stylesheets/roadmap-form.scss b/lib/assets/stylesheets/roadmap-form.scss index 9abd90a..72345a1 100644 --- a/lib/assets/stylesheets/roadmap-form.scss +++ b/lib/assets/stylesheets/roadmap-form.scss @@ -150,13 +150,12 @@ input.form-submit { background-color: $primary-color; color: $reverse-text; - padding: 10px 30px; - font-size: 12pt; - margin-top: 15px; - - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; + font-size: 14px; + padding: 4px 12px; + + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; } /* Override the button color for the Org Admin sections */ input[type="submit"].admin{ @@ -171,13 +170,12 @@ button.form-cancel { background-color: $cancel-button-color; color: $reverse-text; - padding: 10px 30px; - font-size: 12pt; - margin-top: 15px; + font-size: 14px; + padding: 4px 12px; - -webkit-border-radius: 10px; - -moz-border-radius: 10px; - border-radius: 10px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; } .submit-tooltip { display: none; diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index cc9e87e..0bd54fd 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -248,5 +248,22 @@ end end end + + desc "enforce single published version for templates" + task single_published_template: :environment do + # for each group of versions of a template + Template.all.pluck(:dmptemplate_id).uniq.each do |dmptemplate_id| + published = false + Template.where(dmptemplate_id: dmptemplate_id).order(version: :desc).each do |template| + # leave the first published template we find alone + if !published && template.published + published = true + elsif published && template.published + template.published = false + template.save! + end + end + end + end end diff --git a/test/functional/annotations_controller_test.rb b/test/functional/annotations_controller_test.rb new file mode 100644 index 0000000..8615d16 --- /dev/null +++ b/test/functional/annotations_controller_test.rb @@ -0,0 +1,116 @@ +require 'test_helper' + +class AnnotationsControllerTest < ActionDispatch::IntegrationTest + + include Devise::Test::IntegrationHelpers + + setup do + @question = Annotation.first.question + + # Get the first Org Admin + scaffold_org_admin(@question.section.phase.template.org) + end + +# TODO: The following methods SHOULD replace the old 'admin_' prefixed methods. The routes file already has +# these defined. They are defined multiple times though and we need to clean this up! In particular +# look at the unnamed routes after 'new_plan_phase' below. They are not named because they are duplicates. +# We should just have: +# +# SHOULD BE: +# -------------------------------------------------- +# suggested_answers GET /templates/:template_id/phases/:phase_id/sections/:section_id/questions/:id sections#index +# POST /templates/:template_id/phases/:phase_id/sections/:section_id/questions/:id sections#create +# suggested_answer GET /templates/:template_id/phases/:phase_id/sections/:section_id/questions/:question_id/suggested_answer/:id sections#show +# PATCH /templates/:template_id/phases/:phase_id/section/:section_id/questions/:question_id/suggested_answer/:id sections#update +# PUT /templates/:template_id/phases/:phase_id/section/:section_id/questions/:question_id/suggested_answer/:id sections#update +# DELETE /templates/:template_id/phases/:phase_id/section/:section_id/questions/:question_id/suggested_answer/:id sections#destroy +# +# CURRENT RESULTS OF `rake routes` +# -------------------------------------------------- +# admin_create_suggested_answer POST /org/admin/templates/suggested_answers/:id/admin_create suggested_answers#admin_create +# admin_update_suggested_answer PUT /org/admin/templates/suggested_answers/:id/admin_update suggested_answers#admin_update +# admin_destroy_suggested_answer DELETE /org/admin/templates/suggested_answers/:id/admin_destroy suggested_answers#admin_destroy + + + + # POST /org/admin/templates/suggested_answers/:id/admin_create (admin_create_annotation_path) + # ---------------------------------------------------------- + test "create a new annotation" do + params = {org_id: @user.org.id, question_id: @question.id, text: "Here's a suggestion"} + + # Should redirect user to the root path if they are not logged in! + post admin_create_annotation_path(@question.id), {annotation: params} + assert_unauthorized_redirect_to_root_path + + sign_in @user + + post admin_create_annotation_path(@question.id), {annotation: params} + assert_response :redirect + assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" + assert_equal _('Information was successfully created.'), flash[:notice] + assert_equal "Here's a suggestion", Annotation.last.text, "expected the record to have been created!" + assert assigns(:example_answer) + + # Invalid object + post admin_create_annotation_path(@question.id), {annotation: {question_id: @question.id}} + assert flash[:notice].starts_with?(_('Could not create your')) + assert_response :success + assert assigns(:example_answer) + end + + # PUT /org/admin/templates/suggested_answers/:id/admin_update (admin_update_suggested_answer_path) + # ---------------------------------------------------------- + test "update the annotation" do + params = {text: 'UPDATE'} + + # Should redirect user to the root path if they are not logged in! + put admin_update_annotation_path(Annotation.first), {annotation: params} + assert_unauthorized_redirect_to_root_path + + sign_in @user + + # Valid save + put admin_update_annotation_path(Annotation.first), {annotation: params} + assert_equal _('Information was successfully updated.'), flash[:notice] + assert_response :redirect + assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" + assert assigns(:example_answer) + assert assigns(:question) + assert assigns(:section) + assert assigns(:phase) + assert_equal 'UPDATE', Annotation.first.text, "expected the record to have been updated" + +# TODO: We need to add in validation checks on the model and reactivate this test + # Invalid save +# put admin_update_suggested_answer_path(SuggestedAnswer.first), {suggested_answer: {text: nil}} +# assert flash[:notice].starts_with?(_('Could not update your')) +# assert_response :success +# assert assigns(:suggested_answer) +# assert assigns(:question) +# assert assigns(:section) +# assert assigns(:phase) + end + + # DELETE /org/admin/templates/suggested_answers/:id/admin_destroy (admin_destroy_suggested_answer_path) + # ---------------------------------------------------------- + test "delete the section" do + id = Annotation.first.id + # Should redirect user to the root path if they are not logged in! + delete admin_destroy_annotation_path(id: id) + assert_unauthorized_redirect_to_root_path + + sign_in @user + + delete admin_destroy_annotation_path(id: id) + assert_equal _('Information was successfully deleted.'), flash[:notice] + assert_response :redirect + assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true§ion_id=#{@question.section.id}" + assert assigns(:question) + assert assigns(:section) + assert assigns(:phase) + assert_raise ActiveRecord::RecordNotFound do + Annotation.find(id).nil? + end + end + +end \ No newline at end of file diff --git a/test/functional/plans_controller_test.rb b/test/functional/plans_controller_test.rb index 259bfbf..3811003 100644 --- a/test/functional/plans_controller_test.rb +++ b/test/functional/plans_controller_test.rb @@ -107,20 +107,6 @@ assert assigns(:selected_guidance_groups) end - # GET /plan/:id/edit (edit_plan_path) - # ---------------------------------------------------------- - test 'show the edit plan page' do - # Should redirect user to the root path if they are not logged in! - try_no_user_and_unauthorized(edit_plan_path(@plan)) - - sign_in @user - get edit_plan_path(@plan) - assert_response :success - assert assigns(:plan) - assert assigns(:phase) - assert assigns(:readonly) - end - # PUT /plan/:id (plan_path) # ---------------------------------------------------------- test 'update the plan' do diff --git a/test/functional/questions_controller_test.rb b/test/functional/questions_controller_test.rb index 2a9cbcf..9a156f5 100644 --- a/test/functional/questions_controller_test.rb +++ b/test/functional/questions_controller_test.rb @@ -38,7 +38,7 @@ # POST /org/admin/templates/questions/:id/admin_create (admin_create_question_path) # ---------------------------------------------------------- test "create a new question" do - params = {section_id: @section.id, text: 'Test Question', number: 9, question_format_id: @question_format.id} + params = {section_id: @section.id, text: 'Test Question', number: 9, question_format_id: @question_format.id, annotations_attributes: {0 => {text: "some text", org_id: Org.first.id}}} @section.phase.template.dirty = false @section.phase.template.save! @@ -48,7 +48,11 @@ assert_unauthorized_redirect_to_root_path sign_in @user - + @new_question = Question.new + @new_question.number = @section.questions.count + 1 + example_answer = @new_question.annotations.build + example_answer.type = :example_answer + example_answer.save post admin_create_question_path(@section), {question: params} assert_response :redirect assert assigns(:question) diff --git a/test/functional/suggested_answers_controller_test.rb b/test/functional/suggested_answers_controller_test.rb deleted file mode 100644 index dcdd2ce..0000000 --- a/test/functional/suggested_answers_controller_test.rb +++ /dev/null @@ -1,116 +0,0 @@ -require 'test_helper' - -class SuggestedAnswersControllerTest < ActionDispatch::IntegrationTest - - include Devise::Test::IntegrationHelpers - - setup do - @question = SuggestedAnswer.first.question - - # Get the first Org Admin - scaffold_org_admin(@question.section.phase.template.org) - end - -# TODO: The following methods SHOULD replace the old 'admin_' prefixed methods. The routes file already has -# these defined. They are defined multiple times though and we need to clean this up! In particular -# look at the unnamed routes after 'new_plan_phase' below. They are not named because they are duplicates. -# We should just have: -# -# SHOULD BE: -# -------------------------------------------------- -# suggested_answers GET /templates/:template_id/phases/:phase_id/sections/:section_id/questions/:id sections#index -# POST /templates/:template_id/phases/:phase_id/sections/:section_id/questions/:id sections#create -# suggested_answer GET /templates/:template_id/phases/:phase_id/sections/:section_id/questions/:question_id/suggested_answer/:id sections#show -# PATCH /templates/:template_id/phases/:phase_id/section/:section_id/questions/:question_id/suggested_answer/:id sections#update -# PUT /templates/:template_id/phases/:phase_id/section/:section_id/questions/:question_id/suggested_answer/:id sections#update -# DELETE /templates/:template_id/phases/:phase_id/section/:section_id/questions/:question_id/suggested_answer/:id sections#destroy -# -# CURRENT RESULTS OF `rake routes` -# -------------------------------------------------- -# admin_create_suggested_answer POST /org/admin/templates/suggested_answers/:id/admin_create suggested_answers#admin_create -# admin_update_suggested_answer PUT /org/admin/templates/suggested_answers/:id/admin_update suggested_answers#admin_update -# admin_destroy_suggested_answer DELETE /org/admin/templates/suggested_answers/:id/admin_destroy suggested_answers#admin_destroy - - - - # POST /org/admin/templates/suggested_answers/:id/admin_create (admin_create_suggested_answer_path) - # ---------------------------------------------------------- - test "create a new section" do - params = {org_id: @user.org.id, question_id: @question.id, text: "Here's a suggestion"} - - # Should redirect user to the root path if they are not logged in! - post admin_create_suggested_answer_path(@question.id), {suggested_answer: params} - assert_unauthorized_redirect_to_root_path - - sign_in @user - - post admin_create_suggested_answer_path(@question.id), {suggested_answer: params} - assert_response :redirect - assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" - assert_equal _('Information was successfully created.'), flash[:notice] - assert_equal "Here's a suggestion", SuggestedAnswer.last.text, "expected the record to have been created!" - assert assigns(:suggested_answer) - - # Invalid object - post admin_create_suggested_answer_path(@question.id), {suggested_answer: {question_id: @question.id}} - assert flash[:notice].starts_with?(_('Could not create your')) - assert_response :success - assert assigns(:suggested_answer) - end - - # PUT /org/admin/templates/suggested_answers/:id/admin_update (admin_update_suggested_answer_path) - # ---------------------------------------------------------- - test "update the section" do - params = {text: 'UPDATE'} - - # Should redirect user to the root path if they are not logged in! - put admin_update_suggested_answer_path(SuggestedAnswer.first), {suggested_answer: params} - assert_unauthorized_redirect_to_root_path - - sign_in @user - - # Valid save - put admin_update_suggested_answer_path(SuggestedAnswer.first), {suggested_answer: params} - assert_equal _('Information was successfully updated.'), flash[:notice] - assert_response :redirect - assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true&question_id=#{@question.id}§ion_id=#{@question.section.id}" - assert assigns(:suggested_answer) - assert assigns(:question) - assert assigns(:section) - assert assigns(:phase) - assert_equal 'UPDATE', SuggestedAnswer.first.text, "expected the record to have been updated" - -# TODO: We need to add in validation checks on the model and reactivate this test - # Invalid save -# put admin_update_suggested_answer_path(SuggestedAnswer.first), {suggested_answer: {text: nil}} -# assert flash[:notice].starts_with?(_('Could not update your')) -# assert_response :success -# assert assigns(:suggested_answer) -# assert assigns(:question) -# assert assigns(:section) -# assert assigns(:phase) - end - - # DELETE /org/admin/templates/suggested_answers/:id/admin_destroy (admin_destroy_suggested_answer_path) - # ---------------------------------------------------------- - test "delete the section" do - id = SuggestedAnswer.first.id - # Should redirect user to the root path if they are not logged in! - delete admin_destroy_suggested_answer_path(id: id) - assert_unauthorized_redirect_to_root_path - - sign_in @user - - delete admin_destroy_suggested_answer_path(id: id) - assert_equal _('Information was successfully deleted.'), flash[:notice] - assert_response :redirect - assert_redirected_to "#{admin_show_phase_path(@question.section.phase.id)}?edit=true§ion_id=#{@question.section.id}" - assert assigns(:question) - assert assigns(:section) - assert assigns(:phase) - assert_raise ActiveRecord::RecordNotFound do - SuggestedAnswer.find(id).nil? - end - end - -end \ No newline at end of file diff --git a/test/functional/templates_controller_test.rb b/test/functional/templates_controller_test.rb index 45ca826..70e6edd 100644 --- a/test/functional/templates_controller_test.rb +++ b/test/functional/templates_controller_test.rb @@ -1,12 +1,12 @@ require 'test_helper' class TemplatesControllerTest < ActionDispatch::IntegrationTest - + include Devise::Test::IntegrationHelpers - + setup do scaffold_template - + # Get the first Org Admin scaffold_org_admin(@template.org) end @@ -36,41 +36,41 @@ # admin_destroy_template DELETE /org/admin/templates/:id/admin_destroy(.:format) templates#admin_destroy # admin_create_template POST /org/admin/templates/:id/admin_create(.:format) templates#admin_create # admin_update_template PUT /org/admin/templates/:id/admin_update(.:format) templates#admin_update - - + + # GET /org/admin/templates/:id/admin_index (admin_index_template_path) the :id here makes no sense! # ---------------------------------------------------------- test "get the list of admin templates" do # Should redirect user to the root path if they are not logged in! get admin_index_template_path(@user.org) assert_unauthorized_redirect_to_root_path - + sign_in @user - + get admin_index_template_path(@user.org) assert_response :success - + assert assigns(:funder_templates) assert assigns(:org_templates) - end - + end + # GET /org/admin/templates/:id/admin_template (admin_template_template_path) # ---------------------------------------------------------- test "get the admin template" do # Should redirect user to the root path if they are not logged in! get admin_template_template_path(@template) assert_unauthorized_redirect_to_root_path - + sign_in @user - + get admin_template_template_path(@template) assert_response :success - + assert assigns(:template) assert assigns(:hash) assert assigns(:current) end - + # TODO: Why are we passing an :id here!? Its a new record but we seem to need the last template's id # GET /org/admin/templates/:id/admin_new (admin_new_template_path) # ---------------------------------------------------------- @@ -78,30 +78,30 @@ # Should redirect user to the root path if they are not logged in! get admin_new_template_path(Template.last.id) assert_unauthorized_redirect_to_root_path - + sign_in @user - + get admin_new_template_path(Template.last.id) assert_response :success end - + # GET /org/admin/templates/:id/admin_template_history (admin_template_history_template_path) # ---------------------------------------------------------- test "get the admin template history page" do # Should redirect user to the root path if they are not logged in! get admin_template_history_template_path(@template) assert_unauthorized_redirect_to_root_path - + sign_in @user - + get admin_template_history_template_path(@template) assert_response :success - + assert assigns(:template) assert assigns(:templates) assert assigns(:current) end - + # DELETE /org/admin/templates/:id/admin_destroy (admin_destroy_template_path) # ---------------------------------------------------------- test "delete the admin template" do @@ -109,16 +109,16 @@ # Should redirect user to the root path if they are not logged in! delete admin_destroy_template_path(@template) assert_unauthorized_redirect_to_root_path - + sign_in @user - + family = @template.dmptemplate_id prior = Template.current(family) - + version_the_template - + current = Template.current(family) - + # Try to delete a historical version should fail delete admin_destroy_template_path(prior) assert_equal _('You cannot delete historical versions of this template.'), flash[:notice] @@ -130,31 +130,31 @@ delete admin_destroy_template_path(current) assert_response :redirect assert_redirected_to admin_index_template_path - assert_raise ActiveRecord::RecordNotFound do + assert_raise ActiveRecord::RecordNotFound do Template.find(current.id).nil? end assert_equal prior, Template.current(family), "expected the old version to now be the current version" end - + # TODO: Why are we passing an :id here!? Its a new record but we seem to need the last template's id # POST /org/admin/templates/:id/admin_create (admin_create_template_path) # ---------------------------------------------------------- test "create a template" do params = {title: 'Testing create route'} - + # Should redirect user to the root path if they are not logged in! post admin_create_template_path(@user.org), {template: params} assert_unauthorized_redirect_to_root_path - + sign_in @user - + post admin_create_template_path(@user.org), {template: params} assert_equal _('Information was successfully created.'), flash[:notice] assert_response :redirect assert_redirected_to admin_template_template_url(Template.last.id) assert assigns(:template) assert_equal 'Testing create route', Template.last.title, "expected the record to have been created!" - + # Invalid object post admin_create_template_path(@user.org), {template: {title: nil, org_id: @user.org.id}} assert flash[:notice].starts_with?(_('Could not create your')) @@ -162,23 +162,25 @@ assert assigns(:template) assert assigns(:hash) end - + # GET /org/admin/templates/:id/admin_update (admin_update_template_path) # ---------------------------------------------------------- test "update the admin template" do params = {title: 'ABCD'} - + # Should redirect user to the root path if they are not logged in! + #get admin_template_template_path(@template) # Click on 'edit' + #@template = Template.current(@template.dmptemplate_id) # Edit working copy put admin_update_template_path(@template), {template: params} assert_unauthorized_redirect_to_root_path - + sign_in @user family = @template.dmptemplate_id prior = Template.current(family) - + version_the_template - + current = Template.current(family) # We shouldn't be able to edit a historical version @@ -187,7 +189,7 @@ assert_response :redirect assert_redirected_to admin_template_template_url(prior) assert assigns(:template) - + # Make sure we get the right response when editing an unpublished template put admin_update_template_path(current), {template: params} assert_equal _('Information was successfully updated.'), flash[:notice] @@ -195,8 +197,8 @@ assert assigns(:template) assert assigns(:hash) assert_equal 'ABCD', current.reload.title, "expected the record to have been updated" - assert current.reload.dirty? - + assert current.reload.dirty? + # Make sure we get the right response when providing an invalid template put admin_update_template_path(current), {template: {title: nil}} assert flash[:notice].starts_with?(_('Could not update your')) @@ -211,7 +213,7 @@ # Make sure we are redirected if we're not logged in put admin_customize_template_path(@template) assert_unauthorized_redirect_to_root_path - + funder_template = Template.create(org: Org.funders.first, title: 'Testing integration') # Sign in as the funder so that we cna publish the template @@ -220,24 +222,24 @@ put admin_publish_template_path(funder_template) assert_response :redirect assert_redirected_to admin_index_template_path(funder_template.org) - + # Sign in as the regular user so we can customize the funder template sign_in @user - + template = Template.live(funder_template.dmptemplate_id) - + put admin_customize_template_path(template) - + customization = Template.where(customization_of: template.dmptemplate_id).last assert_response :redirect assert_redirected_to admin_template_template_url(Template.last) assert assigns(:template) - + assert_equal 0, customization.version assert_not customization.published? assert_not customization.dirty? - + # Make sure the funder templates data is not modifiable! customization.phases.each do |p| assert_not p.modifiable @@ -249,21 +251,21 @@ end end end - + # GET /org/admin/templates/:id/admin_publish (admin_publish_template_path) # ---------------------------------------------------------- test "publish a template" do # Should redirect user to the root path if they are not logged in! put admin_publish_template_path(@template) assert_unauthorized_redirect_to_root_path - + sign_in @user family = @template.dmptemplate_id prior = Template.current(family) - + version_the_template - + current = Template.current(family) # We shouldn't be able to edit a historical version @@ -272,51 +274,56 @@ assert_response :redirect assert_redirected_to admin_template_template_url(prior) assert assigns(:template) - + # Publish the current template put admin_publish_template_path(current) assert_equal _('Your template has been published and is now available to users.'), flash[:notice] assert_response :redirect assert_redirected_to admin_index_template_path(@user.org) - + current = Template.current(family) + + # Update the description so that the template gets versioned + get admin_template_template_path(current) # Click on 'edit' + new_version = Template.current(family) # Edit working copy + put admin_update_template_path(new_version), {template: {description: "this is an update"}} + # Make sure it versioned properly - current = Template.includes(:phases, :sections, :questions).find(current.id) new_version = Template.current(family) assert_not_equal current.id = new_version.id, "expected it to create a new version" assert_equal (current.version + 1), new_version.version, "expected the version to have incremented" assert current.published?, "expected the old version to be published" assert_not new_version.published?, "expected the new version to NOT be published" assert_not current.dirty?, "expected the old dirty flag to be false" - assert_not new_version.dirty?, "expected the new dirty flag to be false" + assert new_version.dirty?, "expected the new dirty flag to be true" assert_equal current.dmptemplate_id, new_version.dmptemplate_id, "expected the old and new versions to share the same dmptemplate_id" end - + # GET /org/admin/templates/:id/admin_unpublish (admin_unpublish_template_path) # ---------------------------------------------------------- test "unpublish a template" do # Should redirect user to the root path if they are not logged in! put admin_unpublish_template_path(@template) assert_unauthorized_redirect_to_root_path - + sign_in @user family = @template.dmptemplate_id prior = Template.current(family) - + version_the_template - + current = Template.current(family) - + # Publish it so we can unpublish put admin_publish_template_path(current) assert_not Template.live(family).nil? - + put admin_unpublish_template_path(current) assert_equal _('Your template is no longer published. Users will not be able to create new DMPs for this template until you re-publish it'), flash[:notice] assert_response :redirect assert_redirected_to admin_index_template_path(@user.org) - + # Make sure there are no published versions assert Template.live(family).nil? end -end \ No newline at end of file +end diff --git a/test/integration/template_versioning_test.rb b/test/integration/template_versioning_test.rb index aea0d73..dd59836 100644 --- a/test/integration/template_versioning_test.rb +++ b/test/integration/template_versioning_test.rb @@ -6,74 +6,70 @@ setup do scaffold_template scaffold_org_admin(@template.org) - + sign_in @user - + # Make sure the template starts out as unpublished. The controller will not allow changes once its published @template.published = false @template.save! - + @initial_id = @template.id @initial_version = @template.version @initial_title = @template.title @dmptemplate_id = @template.dmptemplate_id end - + # ---------------------------------------------------------- test 'template gets versioned when its details are updated but it is already published' do # Publish the template put admin_publish_template_path(@template) @template = Template.current(@dmptemplate_id) + get admin_template_template_path(@template) # Click on 'edit' + @template = Template.current(@dmptemplate_id) # Edit new version - assert_equal (@initial_version + 1), @template.version, "expected the version to have incremented" - assert_not_equal @initial_id, @template.id, "expected the id to have changed" - assert_equal @dmptemplate_id, @template.dmptemplate_id, "expected the dmptemplate_id to match" - assert_equal false, @template.published?, "expected the new version to be unpublished" - assert_equal @initial_title, @template.title, "expected the title to have been updated" - # Change the title after its been published put admin_update_template_path(@template), {template: {title: "Blah blah blah"}} @template = Template.current(@dmptemplate_id) - + # Make sure that the template was versioned assert_equal (@initial_version + 1), @template.version, "expected the version to have incremented" assert_not_equal @initial_id, @template.id, "expected the id to have changed" assert_equal @dmptemplate_id, @template.dmptemplate_id, "expected the dmptemplate_id to match" assert_equal false, @template.published?, "expected the new version to be unpublished" assert_not_equal @initial_title, @template.title, "expected the title to have been updated" - + # Now retrieve the published version and verify that it is unchanged old = Template.live(@dmptemplate_id) assert_equal @initial_version, old.version, "expected the version number of the published version to be the same" assert_equal @initial_id, old.id, "expected the id of the published version to be the same" assert_equal @initial_title, old.title, "expected the title of the published version to be the same" end - + # ---------------------------------------------------------- test 'template gets versioned when its phases are modified and it is already published' do @template.dirty = false @template.save! - + put admin_update_phase_path @template.phases.first, {phase: {title: 'UPDATED'}} @template.reload assert @template.dirty end - + # ---------------------------------------------------------- test 'template gets versioned when its sections are modified and it is already published' do @template.dirty = false @template.save! - + put admin_update_section_path @template.phases.first.sections.first, {section: {title: 'UPDATED'}} @template.reload assert @template.dirty end - + # ---------------------------------------------------------- test 'template gets versioned when its questions are modified and it is already published' do @template.dirty = false @template.save! - + put admin_update_question_path @template.phases.first.sections.first.questions.first, {question: {text: 'UPDATED'}} @template.reload assert @template.dirty @@ -90,7 +86,7 @@ assert_equal @dmptemplate_id, @template.dmptemplate_id, "expected the dmptemplate_id to match" assert_equal false, @template.published?, "expected the version to have remained unpublished" end - + # ---------------------------------------------------------- test 'publishing a plan unpublishes the old published plan' do put admin_publish_template_path(@template) @@ -104,7 +100,7 @@ put admin_unpublish_template_path(@template) assert Template.live(@dmptemplate_id).nil? end - + # ---------------------------------------------------------- test 'plans get attached to the appropriate template version' do =begin @@ -118,7 +114,7 @@ # Sign in as the funder so that we cna publish the template sign_in User.find_by(org: funder_template.org) - + # Publish the funder template put admin_publish_template_path(funder_template) assert_response :redirect @@ -128,41 +124,41 @@ liveA = Template.live(funder_template.dmptemplate_id) @dmptemplate_id = @template.dmptemplate_id end - + sign_in @user - + # Plan A gets attached to the template v1 post plans_path, {plan: {funder_id: @template.org.id}} planA = Plan.last assert_equal liveA, planA.template, "expected the latest published version to have been assigned to PlanA" - + # Template v2 is updated put admin_update_template_path(@template), {template: {title: "Blah blah blah"}} @template = Template.current(@dmptemplate_id) - + # Plan B gets attached to the template v1 because v2 is not yet published post plans_path, {plan: {funder_id: @template.org.id}} planB = Plan.last assert_equal liveA, planB.template, "expected the latest published version to have been assigned to PlanB" - + # Plan A should still be attached to v1 assert_equal liveA, planA.template, "expected PlanA to still be attached to the original published version" - - # Sign back in as the funder + + # Sign back in as the funder sign_in User.find_by(org: funder_template.org) - + # Template v2 is published put admin_publish_template_path(@template) @template = Template.current(@dmptemplate_id) liveB = Template.live(@dmptemplate_id) - + sign_in @user - + # Plan C gets attached to template v2 post plans_path, {plan: {funder_id: @template.org.id}} planC = Plan.last assert_equal liveB, planC.template, "expected the latest published version to have been assigned to PlanA" - + # Plan A and B are still attached to v1 assert_equal liveA, planA.template, "expected PlanA to still be attached to the original published version" assert_equal liveA, planB.template, "expected PlanB to still be attached to the original published version" diff --git a/test/test_helper.rb b/test/test_helper.rb index def6783..43b64d3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,16 +11,16 @@ class ActiveSupport::TestCase include GlobalHelpers - + # Suppress noisy ActiveRecord logs because fixtures load for each test ActiveRecord::Base.logger.level = Logger::INFO - + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting #fixtures :all - + # Use the seeds.rb file to seed the test database require_relative '../db/seeds.rb' @@ -32,112 +32,115 @@ def scaffold_org_admin(org) @user = User.create!(email: "admin-#{org.abbreviation.downcase}@example.com", firstname: "Org", surname: "Admin", language: Language.find_by(abbreviation: FastGettext.locale), - password: "password123", password_confirmation: "password123", + password: "password123", password_confirmation: "password123", org: org, accept_terms: true, confirmed_at: Time.zone.now, perms: Perm.where.not(name: ['admin', 'add_organisations', 'change_org_affiliation', 'grant_api_to_orgs'])) #perms: [Perm::GRANT_PERMISSIONS, Perm::MODIFY_TEMPLATES, Perm::MODIFY_GUIDANCE, Perm::CHANGE_ORG_DETAILS]) end - - + + # Convert Ruby Class Names into attribute names (e.g. MyClass --> my_class) # ---------------------------------------------------------------------- def class_name_to_attribute_name(name) name.gsub(/([a-z]+)([A-Z])/, '\1_\2').gsub('-', '_').downcase end - - # Scaffold a new Template with one Phase, one Section, and a Question for - # each of the possible Question Formats. + + # Scaffold a new Template with one Phase, one Section, and a Question for + # each of the possible Question Formats. # ---------------------------------------------------------------------- def scaffold_template - template = Template.new(title: 'Test template', + template = Template.new(title: 'Test template', description: 'My test template', org: Org.first) - - template.phases << Phase.new(title: 'Test phase', - description: 'My test phase', + + template.phases << Phase.new(title: 'Test phase', + description: 'My test phase', number: 1) - - section = Section.new(title: 'Test section', + + section = Section.new(title: 'Test section', description: 'My test section', number: 99, phase: template.phases.first) - + i = 1 # Add each type of Question to the new section QuestionFormat.all.each do |frmt| - question = Question.new(text: "Test question - #{frmt.title}", number: i, + question = Question.new(text: "Test question - #{frmt.title}", number: i, question_format: frmt) - + if frmt.option_based? 3.times do |j| question.question_options << QuestionOption.new(text: "Option #{j}", number: j) end end - + section.questions << question i += 1 end - + template.phases.first.sections << section template.save! assert template.valid?, "unable to create new Template: #{template.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" - + @template = template.reload end - + # Version the template # ---------------------------------------------------------------------- def version_the_template put admin_publish_template_path(@template) + get admin_template_template_path(@template) # Click on 'edit' + @template = Template.current(@template.dmptemplate_id) # Edit working copy + put admin_update_template_path(@template), {template: {title: "#{@template.title} - VERSIONED"}} end - - # Scaffold a new Plan based on the scaffolded Template + + # Scaffold a new Plan based on the scaffolded Template # ---------------------------------------------------------------------- def scaffold_plan scaffold_template if @template.nil? - - @plan = Plan.new(template: @template, title: 'Test Plan', grant_number: 'Grant-123', + + @plan = Plan.new(template: @template, title: 'Test Plan', grant_number: 'Grant-123', principal_investigator: 'me', principal_investigator_identifier: 'me-1234', description: "this is my plan's informative description", identifier: '1234567890', data_contact: 'me@example.com', visibility: 0, roles: [Role.new(user: User.last, creator: true)]) - + assert @plan.valid?, "unable to create new Plan: #{@plan.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" @plan.save! end - - + + # FUNCTIONAL/INTEGRATION TEST HELPERS # ---------------------------------------------------------------------- def assert_unauthorized_redirect_to_root_path assert_response :redirect assert_match "#{root_url}", @response.redirect_url - + follow_redirects - + assert_response :success assert_select '.welcome-message h2', _('Welcome.') end - + # ---------------------------------------------------------------------- def assert_authorized_redirect_to_plans_page assert_response :redirect assert_match "#{root_url}", @response.redirect_url - + # Sometimes Devise has an intermediary step prior to sending the user to the final destination follow_redirects - + assert_response :success assert_select '.main_page_content h1', _('My plans') end - + # ---------------------------------------------------------------------- def follow_redirects while @response.status >= 300 && @response.status < 400 follow_redirect! end end - + # UNIT TEST HELPERS # ---------------------------------------------------------------------- def verify_deep_copy(object, exclusions) @@ -153,40 +156,40 @@ end end end - + # ---------------------------------------------------------------------- def verify_has_many_relationship(object, new_association, initial_expected_count) # Assumes that the association name matches the pluralized name of the class rel = "#{class_name_to_attribute_name(new_association.class.name).pluralize}" - + assert_equal initial_expected_count, object.send(rel).count, "was expecting #{object.class.name} to initially have #{initial_expected_count} #{rel}" - + # Add another association for the object object.send(rel) << new_association object.save! assert_equal (initial_expected_count + 1), object.send(rel).count, "was expecting #{object.class.name} to have #{initial_expected_count + 1} #{rel} after adding a new one - #{new_association.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" - + # Remove the newly added association object.send(rel).delete(new_association) object.save! assert_equal initial_expected_count, object.send(rel).count, "was expecting #{object.class.name} to have #{initial_expected_count} #{rel} after removing the new one we added" end - + # ---------------------------------------------------------------------- def verify_belongs_to_relationship(child, parent) # Assumes that the association name matches the lower case name of the class prnt = "#{class_name_to_attribute_name(parent.class.name)}" chld = "#{class_name_to_attribute_name(child.class.name)}" - + child.send("#{prnt}=", parent) child.save! assert_equal parent, child.send(prnt), "was expecting #{chld} to have a #{prnt}.id == #{parent.id}" - + # Search the parent for the child parent.reload assert_includes parent.send("#{chld.pluralize}"), child, "was expecting the #{prnt}.#{chld.pluralize} to contain the #{chld}" end - + # STUBS FOR CALLS To EXTERNAL SITES # ---------------------------------------------------------------------- def stub_blog_calls @@ -206,7 +209,7 @@ "1 at http://www.example.com/stubbed/blog" + "" + "" - + stub_request(:get, "http://www.dcc.ac.uk/news/dmponline-0/feed"). with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.2'}). to_return(:status => 200, :body => blog_feed, :headers => {}) diff --git a/test/unit/annotation_test.rb b/test/unit/annotation_test.rb new file mode 100644 index 0000000..9734c10 --- /dev/null +++ b/test/unit/annotation_test.rb @@ -0,0 +1,63 @@ +require 'test_helper' + +class AnnotationTest < ActiveSupport::TestCase + + setup do + scaffold_template + + @org = Org.last + @question = @template.phases.first.sections.first.questions.first + + @annotation = Annotation.create(org: @org, question: @question, text: 'Test', + type: Annotation.types[:example_answer]) + end + + # --------------------------------------------------- + test "required fields are required" do + assert_not Annotation.new.valid? + assert_not Annotation.new(org: @org, text: 'Tester').valid?, "expected the 'question' field to be required" + assert_not Annotation.new(question: @question, text: 'Tester').valid?, "expected the 'org' field to be required" + + # TODO: introduce validation on the model that requires text to be provided. + #assert_not Annotation.new(org: @org, question: @question).valid?, "expected the 'text' field to be required" + + # Ensure the bare minimum and complete versions are valid + a = Annotation.new(org: @org, question: @question, text: 'Tester') + assert a.valid?, "expected the 'org', 'question' and 'text' fields to be enough to create an Annotation! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + end + + # --------------------------------------------------- + test "to_s returns the text" do + assert_equal @annotation.text, @annotation.to_s + end + + # --------------------------------------------------- + test "deep_copy" do + verify_deep_copy(@annotation, ['id', 'created_at', 'updated_at']) + end + + # --------------------------------------------------- + test "can CRUD Annotation" do + obj = Annotation.create(org: @org, question: @question, text: 'Tester') + assert_not obj.id.nil?, "was expecting to be able to create a new Annotation: #{obj.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + + obj.text = 'my tester' + obj.save! + obj.reload + assert_equal 'my tester', obj.text, "Was expecting to be able to update the text of the Annotation!" + + assert obj.destroy!, "Was unable to delete the Annotation!" + end + + # --------------------------------------------------- + test "can manage belongs_to relationship with Org" do + annotation = Annotation.new(question: @question, text: 'Testing') + verify_belongs_to_relationship(annotation, @org) + end + + # --------------------------------------------------- + test "can manage belongs_to relationship with Question" do + annotation = Annotation.new(org: @org, text: 'Testing') + verify_belongs_to_relationship(annotation, @question) + end +end \ No newline at end of file diff --git a/test/unit/org_test.rb b/test/unit/org_test.rb index c2c497d..3e7fd34 100644 --- a/test/unit/org_test.rb +++ b/test/unit/org_test.rb @@ -181,9 +181,9 @@ end # --------------------------------------------------- - test "can manage has_many relationship with SuggestedAnswers" do - sa = SuggestedAnswer.new(question: Question.first, text: 'Test Suggested Answer') - verify_has_many_relationship(@org, sa, @org.suggested_answers.count) + test "can manage has_many relationship with Annotations" do + a = Annotation.new(question: Question.first, text: 'Test Annotation') + verify_has_many_relationship(@org, a, @org.annotations.count) end # --------------------------------------------------- diff --git a/test/unit/question_test.rb b/test/unit/question_test.rb index be8981e..a5bb6c3 100644 --- a/test/unit/question_test.rb +++ b/test/unit/question_test.rb @@ -4,18 +4,18 @@ setup do @user = User.last - + scaffold_template - + @section = @template.phases.first.sections.first - + @question = Question.create(text: 'Test question', default_value: 'ABCD', guidance: 'Hello', - number: 999, section: @section, - question_format: QuestionFormat.where(option_based: false).first, + number: 999, section: @section, + question_format: QuestionFormat.where(option_based: false).first, option_comment_display: true, modifiable: true, - themes: [Theme.first], - suggested_answers: [SuggestedAnswer.new(org: @user.org, - text: "just a suggestion")]) + themes: [Theme.first], + annotations: [Annotation.new(org: @user.org, + text: "just a suggestion")]) end # --------------------------------------------------- @@ -24,21 +24,21 @@ assert_not Question.new(section: @section, number: 7).valid?, "expected the 'text' field to be required" assert_not Question.new(number: 7, text: 'Testing').valid?, "expected the 'section' field to be required" assert_not Question.new(section: @section, text: 'Testing').valid?, "expected the 'number' field to be required" - + # Ensure the bar minimum and complete versions are valid a = Question.new(section: @section, text: 'Testing', number: 7) assert a.valid?, "expected the 'text', 'section' and 'number' fields to be enough to create an Question! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" end - + # --------------------------------------------------- test "to_s returns the Question text" do assert_equal @question.text, @question.to_s end - + # --------------------------------------------------- test "returns the correct themed guidance for the org" do all = Theme.first.guidances + Theme.last.guidances - + # Attach 2 themes to the question @question.themes = [Theme.first, Theme.last] @question.save! @@ -53,25 +53,25 @@ assert @question.guidance_for_org(@user.org).first.first.include?(Theme.first.guidances.first.guidance_group.name), "expected the guidance_group.name" assert_equal Theme.first.guidances.first, @question.guidance_for_org(@user.org).first.last, "expected the guidance object to be returned" end - + # --------------------------------------------------- - test "returns the correct suggested answer for the org" do - @question.suggested_answers = [SuggestedAnswer.new(org: @user.org, text: 'Test 1', is_example: false), - SuggestedAnswer.new(org: Org.first, text: 'Test 2', is_example: false)] + test "returns the correct annotation for the org" do + @question.annotations = [Annotation.create(org: @user.org, text: 'Test 1', type: Annotation.types[:example_answer]), + Annotation.create(org: Org.first, text: 'Test 2', type: Annotation.types[:example_answer])] @question.save! - - assert_equal 'Test 1', @question.get_suggested_answer(@user.org.id).text, "expected the correct suggested answer" - assert_equal 'Test 2', @question.get_suggested_answer(Org.first.id).text, "expected the correct suggested answer" - + + assert_equal 'Test 1', @question.annotations.where(org_id: @user.org.id).first.text, "expected the correct annotation" + assert_equal 'Test 2', @question.annotations.where(org_id: Org.first.id).first.text, "expected the correct annotation" + org = Org.create(name: 'New One') - assert_equal nil, @question.get_suggested_answer(org.id), "expected no suggested answer for a new org" + assert_equal nil, @question.get_example_answer(org.id), "expected no annotation for a new org" end - + # --------------------------------------------------- test "deep copy" do verify_deep_copy(@question, ['id', 'created_at', 'updated_at']) end - + # --------------------------------------------------- test "can CRUD Question" do obj = Question.create(section: @section, text: 'Test ABC', number: 7) @@ -81,39 +81,39 @@ obj.save! obj.reload assert_equal 'Testing an update', obj.text, "Was expecting to be able to update the text of the Question!" - + assert obj.destroy!, "Was unable to delete the Question!" end - + # --------------------------------------------------- test "can manage belongs_to relationship with Section" do verify_belongs_to_relationship(@question, @template.phases.first.sections.last) end - + # --------------------------------------------------- test "can manage belongs_to relationship with QuestionFormat" do verify_belongs_to_relationship(@question, QuestionFormat.where(option_based: false).last) end - + # --------------------------------------------------- test "can manage has_many relationship with Answer" do scaffold_plan a = Answer.new(user: @user, plan: @plan, text: 'Test Answer') verify_has_many_relationship(@question, a, @question.answers.count) end - + # --------------------------------------------------- test "can manage has_many relationship with QuestionOption" do qo = QuestionOption.new(text: 'Test', number: 9) verify_has_many_relationship(@question, qo, @question.question_options.count) end - + # --------------------------------------------------- - test "can manage has_many relationship with SuggestedAnswer" do - sa = SuggestedAnswer.new(text: 'Suggested Answer', org: @user.org) - verify_has_many_relationship(@question, sa, @question.suggested_answers.count) + test "can manage has_many relationship with Annotation" do + sa = Annotation.new(text: 'Suggested Answer', org: @user.org) + verify_has_many_relationship(@question, sa, @question.annotations.count) end - + # --------------------------------------------------- test "can manage has_many relationship with Themes" do t = Theme.new(title: 'Test Theme') diff --git a/test/unit/suggested_answer_test.rb b/test/unit/suggested_answer_test.rb deleted file mode 100644 index 31be604..0000000 --- a/test/unit/suggested_answer_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -require 'test_helper' - -class SuggestedAnswerTest < ActiveSupport::TestCase - - setup do - scaffold_template - - @org = Org.last - @question = @template.phases.first.sections.first.questions.first - - @suggested_answer = SuggestedAnswer.create(org: @org, question: @question, text: 'Test', - is_example: true) - end - - # --------------------------------------------------- - test "required fields are required" do - assert_not SuggestedAnswer.new.valid? - assert_not SuggestedAnswer.new(org: @org, text: 'Tester').valid?, "expected the 'question' field to be required" - assert_not SuggestedAnswer.new(question: @question, text: 'Tester').valid?, "expected the 'org' field to be required" - - # TODO: introduce validation on the model that requires text to be provided. - #assert_not SuggestedAnswer.new(org: @org, question: @question).valid?, "expected the 'text' field to be required" - - # Ensure the bare minimum and complete versions are valid - a = SuggestedAnswer.new(org: @org, question: @question, text: 'Tester') - assert a.valid?, "expected the 'org', 'question' and 'text' fields to be enough to create an SuggestedAnswer! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" - end - - # --------------------------------------------------- - test "to_s returns the text" do - assert_equal @suggested_answer.text, @suggested_answer.to_s - end - - # --------------------------------------------------- - test "deep_copy" do - verify_deep_copy(@suggested_answer, ['id', 'created_at', 'updated_at']) - end - - # --------------------------------------------------- - test "can CRUD SuggestedAnswer" do - obj = SuggestedAnswer.create(org: @org, question: @question, text: 'Tester') - assert_not obj.id.nil?, "was expecting to be able to create a new SuggestedAnswer: #{obj.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" - - obj.text = 'my tester' - obj.save! - obj.reload - assert_equal 'my tester', obj.text, "Was expecting to be able to update the text of the SuggestedAnswer!" - - assert obj.destroy!, "Was unable to delete the SuggestedAnswer!" - end - - # --------------------------------------------------- - test "can manage belongs_to relationship with Org" do - suggested_answer = SuggestedAnswer.new(question: @question, text: 'Testing') - verify_belongs_to_relationship(suggested_answer, @org) - end - - # --------------------------------------------------- - test "can manage belongs_to relationship with Question" do - suggested_answer = SuggestedAnswer.new(org: @org, text: 'Testing') - verify_belongs_to_relationship(suggested_answer, @question) - end -end \ No newline at end of file