diff --git a/app/controllers/api/v0/plans_controller.rb b/app/controllers/api/v0/plans_controller.rb index c96d174..ac2f1b4 100644 --- a/app/controllers/api/v0/plans_controller.rb +++ b/app/controllers/api/v0/plans_controller.rb @@ -37,15 +37,15 @@ template = org.templates.find_by title: params[:template][:name] # else error: organization has more than one template and template name unspecified else - render json: I18n.t("api.org_multiple_templates"), status: 400 and return + render json: _('{"Error":"Organisation has more than one template and template name unspecified or invalid"}'), status: 400 and return end # else error: organization specified is not a funder else - render json: I18n.t("api.org_not_funder"), status: 400 and return + render json: _('{"Error":"Organisation specified is not a funder"}'), status: 400 and return end # else error: organization does not exist else - render json: I18n.t("api.org_dosent_exist"), status: 400 and return + render json: _('{"Error":"Organisation does not exist"}'), status: 400 and return end all_groups = [] @@ -90,7 +90,7 @@ end else - render json: I18n.t("api.no_auth_for_endpoint"), status: 400 and return + render json: _('{"Error":"You do not have authorisation to view this endpoint"}'), status: 400 and return end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9b06df8..d04b380 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,18 +14,13 @@ rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized def user_not_authorized - redirect_to root_url, alert: I18n.t('unauthorized') + redirect_to root_url, alert: _('You need to sign in or sign up before continuing.') end - before_filter :get_languages before_filter :set_gettext_locale after_filter :store_location - def get_languages - @languages = Language.sorted_by_abbreviation - end - # Sets FastGettext locale for every request made def set_gettext_locale FastGettext.locale = session[:locale] || FastGettext.default_locale diff --git a/app/controllers/guidance_groups_controller.rb b/app/controllers/guidance_groups_controller.rb index 3729dd7..585f32c 100644 --- a/app/controllers/guidance_groups_controller.rb +++ b/app/controllers/guidance_groups_controller.rb @@ -27,7 +27,7 @@ end if @guidance_group.save - redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.created_message') + redirect_to admin_index_guidance_path, notice: _('Guidance group was successfully created.') else render action: "new" end @@ -48,7 +48,7 @@ @guidance_group.org_id = current_user.org_id if @guidance_group.update_attributes(params[:guidance_group]) - redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') + redirect_to admin_index_guidance_path(params[:guidance_group]), notice: _('Guidance group was successfully updated.') else render action: "edit" end @@ -63,7 +63,7 @@ @guidance_group.published = true if @guidance_group.update_attributes(params[:guidance_group]) - redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') + redirect_to admin_index_guidance_path(params[:guidance_group]), notice: _('Guidance group was successfully updated.') else render action: "edit" end @@ -77,7 +77,7 @@ authorize @guidance_group @guidance_group.destroy - redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.destroyed_message') + redirect_to admin_index_guidance_path, notice: _('Guidance group was successfully deleted.') end end \ No newline at end of file diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index 75c0808..674e0f6 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -59,10 +59,10 @@ # updates phases, versions, sections and questions based on template selected dmptemplate = Template.find(params[:dmptemplate_id]) # map to title and id for use in our options_for_select - @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, I18n.t('helpers.select_phase')) - @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) - @sections = dmptemplate.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) - @questions = dmptemplate.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, _('Select a phase')) + @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, _('Select a version')) + @sections = dmptemplate.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section')) + @questions = dmptemplate.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end def update_versions @@ -70,9 +70,9 @@ # updates versions, sections and questions based on phase selected phase = Phase.find(params[:phase_id]) # map to name and id for use in our options_for_select - @versions = phase.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) - @sections = phase.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) - @questions = phase.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @versions = phase.versions.map{|s| [s.title, s.id]}.insert(0, _('Select a version')) + @sections = phase.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section')) + @questions = phase.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end def update_sections @@ -80,15 +80,15 @@ # updates sections and questions based on version selected version = Version.find(params[:version_id]) # map to name and id for use in our options_for_select - @sections = version.sections.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_section')) - @questions = version.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @sections = version.sections.map{|s| [s.title, s.id]}.insert(0, _('Select a section')) + @questions = version.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end def update_questions authorize Guidance # updates songs based on artist selected section = Section.find(params[:section_id]) - @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) + @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, _('Select a question')) end ## @@ -116,7 +116,7 @@ end if @guidance.save - redirect_to admin_show_guidance_path(@guidance), notice: I18n.t('org_admin.guidance.created_message') + redirect_to admin_show_guidance_path(@guidance), notice: _('Guidance was successfully created.') else render action: "new" end @@ -131,7 +131,7 @@ @guidance.question_id = params["question_id"] if @guidance.update_attributes(params[:guidance]) - redirect_to admin_show_guidance_path(params[:guidance]), notice: I18n.t('org_admin.guidance.updated_message') + redirect_to admin_show_guidance_path(params[:guidance]), notice: _('Guidance was successfully updated.') else render action: "edit" end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 8a400f6..40f5e32 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -32,7 +32,7 @@ if @note.save session[:question_id_notes] = answer.question_id - redirect_to edit_plan_phase_path(@plan, @phase), status: :found, notice: I18n.t("helpers.comments.note_created") + redirect_to edit_plan_phase_path(@plan, @phase), status: :found, notice: _('Comment was successfully created.') end end @@ -48,7 +48,7 @@ if @note.update_attributes(params[:note]) session[:question_id_notes] = @note.question_id - redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.note_updated") + redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment was successfully updated.') end end @@ -65,7 +65,7 @@ if @note.update_attributes(params[:note]) session[:question_id_notes] = @note.question_id - redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.note_removed") + redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment has been removed.') end end end diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index 905fd06..301f1c6 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -30,13 +30,13 @@ begin if @org.update_attributes(assign_params) - redirect_to admin_show_org_path(params[:id]), notice: I18n.t("admin.org_updated_message") + redirect_to admin_show_org_path(params[:id]), notice: _('Organisation was successfully updated.') else flash[:notice] = @org.errors.collect{|e| e.message}.join('
').html_safe render action: "admin_edit" end rescue Dragonfly::Job::Fetch::NotFound => dflye - flash[:notice] = I18n.t("admin.org_bad_logo") + flash[:notice] = _('There seems to be a problem with your logo. Please upload it again.') render action: "admin_edit" end end diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index 8c66763..2303795 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -150,7 +150,7 @@ @phase.description = params["phase-desc"] @phase.modifiable = true if @phase.save - redirect_to admin_show_phase_path(id: @phase.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_show_phase_path(id: @phase.id, edit: 'true'), notice: _('Information was successfully created.') else render action: "admin_show" end @@ -163,7 +163,7 @@ authorize @phase @phase.description = params["phase-desc"] if @phase.update_attributes(params[:phase]) - redirect_to admin_show_phase_path(@phase), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_show_phase_path(@phase), notice: _('Information was successfully updated.') else render action: "admin_show" end @@ -175,7 +175,7 @@ authorize @phase @template = @phase.template @phase.destroy - redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_template_template_path(@template), notice: _('Information was successfully deleted.') end diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index abc7b8f..1e27043 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -77,7 +77,7 @@ @plan.principal_investigator = current_user.name - @plan.title = I18n.t('helpers.project.my_project_name')+' ('+@plan.template.title+')' + @plan.title = _('My plan')+' ('+@plan.template.title+')' # We should use interpolated string since the order of the words from this message could vary among languages @plan.assign_creator(current_user.id) @@ -89,9 +89,9 @@ respond_to do |format| if @plan.save #format.html { redirect_to({:action => "show", :id => @plan.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } - format.html { redirect_to({:action => "show", :id => @plan.id, :editing => true }, {:notice => I18n.t('helpers.project.success')}) } + format.html { redirect_to({:action => "show", :id => @plan.id, :editing => true }, {:notice => _('Plan was successfully created.')}) } else - @error = "Something went wrong" + @error = "Something went wrong" format.html { render action: "new" } end end @@ -119,7 +119,7 @@ end elsif user_signed_in? then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end else respond_to do |format| @@ -156,7 +156,7 @@ end elsif !@plan.readable_by?(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end @@ -169,7 +169,7 @@ if user_signed_in? && @plan.editable_by?(current_user.id) then respond_to do |format| if @plan.update_attributes(params[:plan]) - format.html { redirect_to @plan, :editing => false, notice: I18n.t('helpers.project.success_update') } + format.html { redirect_to @plan, :editing => false, notice: _('Plan was successfully updated.') } format.json { head :no_content } else format.html { render action: "edit" } @@ -211,7 +211,7 @@ end elsif !@plan.editable_by?(current_user.id) then respond_to do |format| - format.html { redirect_to plans_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to plans_url, notice: _('This account does not have access to that plan.') } end end end @@ -392,7 +392,7 @@ end elsif !@plan.editable_by(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5b98dd2..5bb893f 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -9,7 +9,9 @@ ## TODO: Is this A magic String? the "Show_shib_link?" as we define it and users dont see cookies if user_signed_in? then if (current_user.shibboleth_id.nil? || current_user.shibboleth_id.length == 0) && !cookies[:show_shib_link].nil? && cookies[:show_shib_link] == "show_shib_link" then - flash.notice = "Would you like to #{view_context.link_to I18n.t('helpers.shibboleth_to_link_text'), user_omniauth_shibboleth_path}".html_safe + flash.notice = ActionController::Base.helpers.link_to( + _('Link your %{application_name} account to your institutional credentials (UK users only)' % { :application_name => Rails.configuration.branding[:application][:name]}, + user_omniauth_shibboleth_path)).html_safe() end @projects = current_user.projects.filter(params[:filter]) @@ -40,7 +42,7 @@ end elsif user_signed_in? then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end else respond_to do |format| @@ -77,7 +79,7 @@ end elsif !@project.editable_by(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end @@ -91,7 +93,7 @@ end elsif !@project.editable_by(current_user.id) then respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + format.html { redirect_to projects_url, notice: _('This account does not have access to that plan.') } end end end @@ -132,11 +134,11 @@ end @project.principal_investigator = current_user.name(false) - @project.title = I18n.t('helpers.project.my_project_name')+' ('+@project.dmptemplate.title+')' + @project.title = _('My plan')+' ('+@project.dmptemplate.title+')' # We should use interpolated string since the order of the words from this message could vary among languages @project.assign_creator(current_user.id) respond_to do |format| if @project.save - format.html { redirect_to({:action => "show", :id => @project.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } + format.html { redirect_to({:action => "show", :id => @project.slug, :show_form => "yes"}, {:notice => _('Plan was successfully created.')}) } else format.html { render action: "new" } end @@ -154,7 +156,7 @@ if user_signed_in? && @project.editable_by(current_user.id) then if @project.update_attributes(params[:project]) respond_to do |format| - format.html { redirect_to({:action => "show", :id => @project.slug, notice: I18n.t('helpers.project.success_update') }) } + format.html { redirect_to({:action => "show", :id => @project.slug, notice: _('Plan was successfully updated.') }) } end else respond_to do |format| diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index d150bff..803479f 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -9,7 +9,7 @@ @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] if @question.save! - redirect_to admin_show_phase_path(id: @question.section.phase_id, section_id: @question.section_id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + 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 render action: "phases/admin_show" end @@ -24,7 +24,7 @@ @section = @question.section @phase = @section.phase if @question.update_attributes(params[:question]) - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + 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 render action: "phases/admin_show" end @@ -37,7 +37,7 @@ @section = @question.section @phase = @section.phase @question.destroy - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: _('Information was successfully deleted.') end end \ No newline at end of file diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index d4e4072..8b2b71c 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -7,12 +7,12 @@ authorize @role @role.access_level = params[:role][:access_level].to_i if params[:role][:email].present? - message = I18n.t('helpers.project.user_added') + message = _('User added to project') if @role.save if @role.user.nil? then if User.find_by_email(params[:role][:email]).nil? then User.invite!(email: params[:role][:email]) - message = I18n.t('helpers.project.invitation_success') + message = _('Invitation issued successfully.') @role.user = User.find_by_email(params[:role][:email]) @role.save else @@ -29,7 +29,7 @@ render action: "new" end else - flash[:notice] = I18n.t('helpers.project.enter_email') + flash[:notice] = _('Please enter an email address') redirect_to controller: 'plans', action: 'share', id: @role.plan.slug end end @@ -39,7 +39,7 @@ authorize @role @role.access_level = params[:role][:access_level].to_i if @role.update_attributes(params[:role]) - flash[:notice] = I18n.t('helpers.project.sharing_updated') + flash[:notice] = _('Sharing details successfully updated.') UserMailer.permissions_change_notification(@role).deliver redirect_to controller: 'plans', action: 'share', id: @role.plan.slug else @@ -54,7 +54,7 @@ plan = @role.plan @role.destroy - flash[:notice] = I18n.t('helpers.project.access_removed') + flash[:notice] = _('Access removed') UserMailer.project_access_removed_notification(user, plan).deliver redirect_to controller: 'plans', action: 'share', id: @role.plan.slug end diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index 42a65a4..9670c84 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -11,7 +11,7 @@ @phase = section.phase if @section.save redirect_to admin_show_phase_template_path(id: @section.phase_id, - :section_id => @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + :section_id => @section.id, edit: 'true'), notice: _('Information was successfully created.') else render action: "phases/admin_show" end @@ -25,7 +25,7 @@ @section.description = params["section-desc-#{params[:id]}"] @phase = @section.phase if @section.update_attributes(params[:section]) - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id , edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id , edit: 'true'), notice: _('Information was successfully updated.') else render action: "phases/admin_show" end @@ -38,9 +38,7 @@ authorize @section @phase = @section.phase @section.destroy - redirect_to admin_show_phase_path(id: @phase.id, edit: 'true' ), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_show_phase_path(id: @phase.id, edit: 'true' ), notice: _('Information was successfully deleted.') end - - - + end \ No newline at end of file diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 99a0aad..6f38009 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -15,64 +15,59 @@ def roadmap end - - def locale - puts 'test locale' - end - # GET /plans/publicly_available - # ----------------------------------------------------------- def public_plans - @plans = Plan.where(visibility: :publicly_visible).order(title: :asc) + @plans = Plan.publicly_visible end # GET /plans/[:plan_slug]/public_export # ------------------------------------------------------------- def public_export - @plan = Plan.find(params[:id]) + redirect_to public_plans_path, notice: _('Exporting public plan is under development. Apologies for any inconvience.') + #@plan = Plan.find(params[:id]) # Force PDF response - request.format = :pdf + #request.format = :pdf # if the project is designated as public - if @plan.visibility == :publicly_visible - if !@plan.nil? - @exported_plan = ExportedPlan.new.tap do |ep| - ep.plan = @plan - ep.user = current_user ||= nil - #ep.format = request.format.try(:symbol) - ep.format = request.format.to_sym - plan_settings = @plan.settings(:export) + #if @plan.visibility == :publicly_visible + # if !@plan.nil? + # @exported_plan = ExportedPlan.new.tap do |ep| + # ep.plan = @plan + # ep.user = current_user ||= nil + # #ep.format = request.format.try(:symbol) + # ep.format = request.format.to_sym + # plan_settings = @plan.settings(:export) - Settings::Dmptemplate::DEFAULT_SETTINGS.each do |key, value| - ep.settings(:export).send("#{key}=", plan_settings.send(key)) - end - end + # Settings::Dmptemplate::DEFAULT_SETTINGS.each do |key, value| + # ep.settings(:export).send("#{key}=", plan_settings.send(key)) + # end + # end - @exported_plan.save! # FIXME: handle invalid request types without erroring? - file_name = @exported_plan.project_name + # @exported_plan.save! # FIXME: handle invalid request types without erroring? + # file_name = @exported_plan.project_name - respond_to do |format| - format.pdf do - @formatting = @plan.settings(:export).formatting - render pdf: file_name, - margin: @formatting[:margin], - footer: { - center: t('helpers.plan.export.pdf.generated_by'), - font_size: 8, - spacing: (@formatting[:margin][:bottom] / 2) - 4, - right: '[page] of [topage]' - } - end - end + # respond_to do |format| + # format.pdf do + # @formatting = @plan.settings(:export).formatting + # render pdf: file_name, + # margin: @formatting[:margin], + # footer: { + # center: t('helpers.plan.export.pdf.generated_by'), + # font_size: 8, + # spacing: (@formatting[:margin][:bottom] / 2) - 4, + # right: '[page] of [topage]' + # } + # end + # end - else + # else # the project has no plans for some reason - redirect_to public_plans_path, notice: I18n.t('helpers.settings.projects.errors.no_plan') - end - else + # redirect_to public_plans_path, notice: _('The plan is incomplete.') + # end + #else # Otherwise redirect to the home page with an unauthorized message - redirect_to public_plans_path, notice: I18n.t('helpers.settings.plans.errors.no_access_account') - end + # redirect_to public_plans_path, notice: _('This account does not have access to that plan.') + #end end end \ No newline at end of file diff --git a/app/controllers/suggested_answers_controller.rb b/app/controllers/suggested_answers_controller.rb index a42e289..bb53c6a 100644 --- a/app/controllers/suggested_answers_controller.rb +++ b/app/controllers/suggested_answers_controller.rb @@ -7,7 +7,7 @@ @suggested_answer = SuggestedAnswer.new(params[:suggested_answer]) authorize @suggested_answer if @suggested_answer.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: I18n.t('org_admin.templates.created_message') + 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 render action: "phases/admin_show" end @@ -22,7 +22,7 @@ @section = @question.section @phase = @section.phase if @suggested_answer.update_attributes(params[:suggested_answer]) - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + 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 render action: "phases/admin_show" end @@ -36,7 +36,7 @@ @section = @question.section @phase = @section.phase @suggested_answer.destroy - redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') + redirect_to admin_show_phase_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: _('Information was successfully deleted.') end end \ No newline at end of file diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 8f2d4df..a0521c9 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -51,7 +51,8 @@ # GET /dmptemplates/1 def admin_template - @template = Template.find(params[:id]) + @template = Template.includes(:org, phases: [sections: [questions: [:question_options, :question_format, + :suggested_answers]]]).find(params[:id]) # check to see if this is a funder template needing customized if @template.org_id != current_user.org_id # definitely need to deep_copy the given template @@ -72,7 +73,7 @@ end end end - customizations = Template.includes(phases: [sections: [questions: :suggested_answers ]]).where(org_id: current_user.org_id, customization_of: @template.dmptemplate_id).order(version: :desc) + customizations = Template.includes(:org, phases: [sections: [questions: :suggested_answers ]]).where(org_id: current_user.org_id, customization_of: @template.dmptemplate_id).order(version: :desc) if customizations.present? # existing customization to port over max_version = customizations.first @@ -145,6 +146,8 @@ @template = new_version end authorize @template + # once the correct template has been generated, we convert it to hash + @hash = @template.to_hash end @@ -154,7 +157,7 @@ authorize @template if @template.published? # published templates cannot be edited - redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.read_only') and return + redirect_to admin_template_template_path(@template), notice: _('Published templates cannot be edited.') and return end @template.description = params["template-desc"] if @template.update_attributes(params[:template]) @@ -165,7 +168,7 @@ new_version.published = false new_version.save! end - redirect_to admin_index_template_path(), notice: I18n.t('org_admin.templates.updated_message') + redirect_to admin_index_template_path(), notice: _('Information was successfully updated.') else render action: "edit" end @@ -193,7 +196,7 @@ end authorize @template if @template.save! - redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.created_message') + redirect_to admin_template_template_path(@template), notice: _('Information was successfully created.') else render action: "admin_new" end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 17ab73f..98b9c59 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -48,7 +48,7 @@ end end @user.save! - redirect_to({controller: 'users', action: 'admin_index'}, {notice: I18n.t('helpers.success')}) + redirect_to({controller: 'users', action: 'admin_index'}, {notice: _('Information was successfully updated.')}) # helpers.success key does not exist, replaced with a generic string end end diff --git a/app/helpers/plans_helper.rb b/app/helpers/plans_helper.rb index bca0305..cf5a0c6 100644 --- a/app/helpers/plans_helper.rb +++ b/app/helpers/plans_helper.rb @@ -4,18 +4,18 @@ # -------------------------------------------------------- def plan_list_column_heading(column) if column.kind_of?(Array) - heading = (column.first.kind_of?(String) ? column.first : t("helpers.project.columns.unknown")) + heading = (column.first.kind_of?(String) ? column.first : _(' - ')) elsif column.kind_of?(String) heading = column else - heading = t("helpers.project.columns.unknown") + heading = _(' - ') end klass = (['name', 'description'].include?(heading) ? :dmp_th_big : :dmp_th_small) - content_tag(:th, t("helpers.project.columns.#{heading}"), class: klass) + content_tag(:th, t("helpers.project.columns.#{heading}"), class: klass) # parametrised YAML keys are no longer possible with gettext, TODO end # Populate a variable column for the project list @@ -27,14 +27,12 @@ klass, content = case col when 'name' [ "dmp_td_big", link_to(plan.title, plan_path(plan), class: "dmp_table_link") ] - when 'owner' user = plan.owner - text = if user.nil? - t("helpers.project.columns.unknown") + _(' - ') elsif user == current_user - t("helpers.me") + _('Me') else user.name end @@ -42,24 +40,32 @@ [ "tmp_td_small", text ] when 'shared' shared_num = plan.users.count - 1 - text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") + text = shared_num > 0 ? (_('Yes') + " (with #{shared_num} people) ") : _('No') # Hardcoded strings are not internationalised [ "dmp_td_small", text ] when 'visibility' - ["dmp_td_small", (plan.visibility.nil? ? I18n.t("helpers.project.visibilities.labels.organisationally_visible") : I18n.t("helpers.project.visibilities.labels.#{plan.visibility}"))] + text = if plan.visibility == 'organisationally_visible' + _('Organisational') + elsif plan.visibility == 'publicly_visible' + _('Public') + elsif plan.visibility == 'is_test' + _('Test/Practice') + elsif plan.visibility == 'privately_visible' + _('Private') + end + ["dmp_td_small", text ] when 'last_edited' [ "dmp_td_small", l(plan.latest_update.to_date, formats: :short) ] when 'description' - [ "dmp_td_medium", (plan.try(col) || t("helpers.settings.unknown")) ] + [ "dmp_td_medium", (plan.try(col) || _(' - ')) ] when 'non_link_name' [ "dmp_td_big", plan.title ] when 'template' ["dmp_td_big", plan.template.title] when 'organisation' - ["dmp_td_medium", (plan.owner.org.nil? ? t("helpers.settings.unknown") : plan.owner.org.name) ] + ["dmp_td_medium", plan.template.org.name] # This will trigger 2 queries for each function call, i.e. one for templates and another for orgs tables else - [ "dmp_td_small", (plan.try(col) || t("helpers.settings.unknown")) ] + [ "dmp_td_small", (plan.try(col) || _(' - ')) ] end - content_tag(:td, content, class: klass) end diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 4045298..1d04142 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -10,7 +10,12 @@ VALID_FORMATS = ['csv', 'html', 'json', 'pdf', 'text', 'xml', 'docx'] - validates :format, inclusion: { in: VALID_FORMATS, message: I18n.t('helpers.plan.export.not_valid_format') } + validates :format, inclusion: { + in: VALID_FORMATS, + message: -> (object, data) do + _('%{value} is not a valid format') % { :value => data[:value] } + end + } validates :plan, :format, presence: true # Store settings with the exported plan so it can be recreated later @@ -124,7 +129,7 @@ answer = self.plan.answer(question.id, false) if answer.nil? || answer.text.nil? then - output += I18n.t('helpers.plan.export.pdf.question_not_answered')+ "\n" + output += _('Question not answered.')+ "\n" else output += answer.options.collect {|o| o.text}.join("\n") if question.option_comment_display == true then diff --git a/app/models/plan.rb b/app/models/plan.rb index ba76aa4..30ce215 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -17,6 +17,8 @@ has_many :exported_plans has_many :roles + + # COMMENTED OUT THE DIRECT CONNECTION HERE TO Users to prevent assignment of users without an access_level specified (currently defaults to creator) # has_many :users, through: :roles @@ -46,6 +48,10 @@ FONT_HEIGHT_CONVERSION_FACTOR = 0.35278 #convert font point size to mm FONT_WIDTH_HEIGHT_RATIO = 0.4 #Assume glyph width averages 2/5 the height + # Scope queries + # Note that in ActiveRecord::Enum the mappings are exposed through a class method with the pluralized attribute name (e.g visibilities rather than visibility) + scope :publicly_visible, -> { where(:visibility => visibilities[:publicly_visible]).order(:title => :asc) } + ## # Settings for the template has_settings :export, class_name: 'Settings::Template' do |s| @@ -346,7 +352,7 @@ if atext.present? space_used += height_of_text(atext) else - space_used += height_of_text(I18n.t('helpers.plan.export.pdf.question_not_answered')) + space_used += height_of_text(_('Question not answered.')) end if answer.present? then diff --git a/app/models/question.rb b/app/models/question.rb index 4533cc6..4c0efdc 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -45,7 +45,7 @@ end - def isOptionBased? + def option_based? format = self.question_format return format.option_based end @@ -92,7 +92,7 @@ group.guidances.each do |g| g.themes.each do |theme| if theme_ids.include? theme.id - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{theme.title}"] = g + guidances["#{group.name} " + _('guidance on') + " #{theme.title}"] = g end end end diff --git a/app/models/settings/plan_list.rb b/app/models/settings/plan_list.rb index 26f6ed5..01d5c88 100644 --- a/app/models/settings/plan_list.rb +++ b/app/models/settings/plan_list.rb @@ -12,9 +12,9 @@ cols = value["columns"] if cols.present? # columns can be empty, in which case they revert to defaults - errors.add(:columns, I18n.t("helpers.settings.projects.errors.no_name")) unless cols.member?("name") - errors.add(:columns, I18n.t("helpers.settings.projects.errors.duplicate")) unless cols.keys.uniq == cols.keys - errors.add(:columns, I18n.t("helpers.settings.projects.errors.unknown")) unless (cols.keys.uniq & ALL_COLUMNS) == cols.keys.uniq + errors.add(:columns, _("'name' must be included in column list.")) unless cols.member?("name") + errors.add(:columns, _('Duplicate column name. Please only include each column once.')) unless cols.keys.uniq == cols.keys + errors.add(:columns, _('Unknown column name.')) unless (cols.keys.uniq & ALL_COLUMNS) == cols.keys.uniq end end end diff --git a/app/models/settings/template.rb b/app/models/settings/template.rb index 2956eac..59ac3de 100644 --- a/app/models/settings/template.rb +++ b/app/models/settings/template.rb @@ -59,13 +59,27 @@ end errs.map do |key| - errors.add(:formatting, I18n.t("helpers.settings.plans.errors.#{key}")) + if key == :missing_key + errors.add(:formatting, _('A required setting has not been provided')) + elsif key == :invalid_margin + errors.add(:formatting, _('Margin value is invalid')) + elsif key == :negative_margin + errors.add(:formatting, _('Margin cannot be negative')) + elsif key == :unknown_margin + errors.add(:formatting, _("Unknown margin. Can only be 'top', 'bottom', 'left' or 'right'")) + elsif key == :invalid_font_size + errors.add(:formatting, _('Invalid font size')) + elsif key == :invalid_font_face + errors.add(:formatting, _('Invalid font face')) + elsif key == :unknown_key + errors.add(:formatting, _('Unknown formatting setting')) + end end end if max_pages.present? && (!max_pages.is_a?(Integer) || max_pages <= 0) - errors.add(:max_pages, I18n.t('helpers.settings.plans.errors.invalid_max_pages')) + errors.add(:max_pages, _('Invalid maximum pages')) end end diff --git a/app/models/template.rb b/app/models/template.rb index 9c59637..16b7ac4 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -48,95 +48,47 @@ end ## - # takes a type or organisation and returns all published templates from - # organisations of that type + # 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, + # question_options, question_formats, + # TODO: Themes & guidance? # - # @param ot [String] name of an organisation type e.g. founder - # @return [Array] list of published dmptemplates -=begin - def self.templates_org_type(ot) - # DISCUSS - This function other than the check for the template being published - # is a superclass for the below funders_templates - new_org_obejcts = OrganisationType.find_by( name: ot ).organisations - - org_templates = Array.new - new_org_obejcts.each do |neworg| - org_templates += neworg.dmptemplates.where("published = ?", true) + # @return [hash] hash of template, phases, sections, questions, question_options, suggested_answers + def to_hash + hash = {} + hash[:template] = {} + hash[:template][:data] = self + hash[:template][:org] = self.org + phases = {} + hash[:template][:phases] = phases + self.phases.each do |phase| + phases[phase.number] = {} + phases[phase.number][:data] = phase + phases[phase.number][:sections] = {} + phase.sections.each do |section| + phases[phase.number][:sections][section.number] = {} + phases[phase.number][:sections][section.number][:data] = section + phases[phase.number][:sections][section.number][:questions] = {} + 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 + end + phases[phase.number][:sections][section.number][:questions][question.number][:question_options] = {} + question.question_options.each do |question_option| + phases[phase.number][:sections][section.number][:questions][question.number][:question_options][:data] = question_option + phases[phase.number][:sections][section.number][:questions][question.number][:question_format] = question.question_format + end + end + end end - - return org_templates + return hash end - ## - # returns all templates from all organisations of the Organisation_Type funder - # - # @return [Array] all templates from funder organisations - def self.funders_templates - funder_orgs = Org.includes(:templates).funder - org_templates = Array.new - - funder_orgs.each do |neworg| - org_templates += neworg.templates - end - - return org_templates - end - - ## - # returns all institutional templates bellowing to the given organisation - # - # @param org_id [integer] the integer id for an organisation - # @return [Array] all templates from a user's organisation - def self.own_institutional_templates(org_id) - # DISCUSS - Why is this done by scanning organisation_id's from the templates - # yet all other calls are done by finding an organisation, and using the - # has_many relationship to find the dmptemplates? - # - A possible answer is that there may be deleted organisations which we are - # serching for templates for. - # - A standardised behavior on querries, wether through active reccord or the - # where, should maybe be thought of/decided upon - new_templates = self.where("org_id = ?", org_id) - return new_templates - end - - ## - # returns an array with all funders and of the given organisations's - # institutional templates - # - # @param org_id [integer] the integer id for an organisation - # @return [Array] all templates from the template's organisation - # or from a funder organisation - def self.funders_and_own_templates(org_id) - funders_templates = self.funders_templates - - #verify if org type is not a funder - current_org = Org.find(org_id) - if !current_org.funder? then - own_institutional_templates = self.own_institutional_templates(org_id) - else - own_institutional_templates = [] - end - - templates_list = Array.new - templates_list += own_institutional_templates - templates_list += funders_templates - templates_list = templates_list.sort_by { |f| f['title'].downcase } - - return templates_list - end - - ## - # Returns the string name of the organisation type of the organisation who - # owns this dmptemplate - # - # @return [string] the string name of an organisation type - def org_type - org_type = org.organisation_type - return org_type - end -=end - -# TODO: Why are we passing in an org and template here? +# TODO: Why are we passing in an org and template here? ## # Verify if a template has customisation by given organisation # @@ -149,33 +101,6 @@ modifiable = modifiable && phase.modifiable end return !modifiable - # if temp.org_id != org_id then - # temp.phases.each do |phase| - # phase.versions.each do |version| - # version.sections.each do |section| - # return true if section.organisation_id == org_id - # end - # end - # return false - # end - # else - # return false - # end end -=begin - ## - # verify if there are any publish version for the template - # - # @return [Boolean] true if there is a published version for the template - def has_published_versions? - phases.each do |phase| - return true if !phase.latest_published_version.nil? - end - return false - end -=end - - # OLD CODE STARTS HERE - end diff --git a/app/views/admin/dmptemplates/settings.html.erb b/app/views/admin/dmptemplates/settings.html.erb index c955083..df9557e 100644 --- a/app/views/admin/dmptemplates/settings.html.erb +++ b/app/views/admin/dmptemplates/settings.html.erb @@ -13,10 +13,14 @@
  • <%= f.label(_('Margin')) %> - <% ["top", "bottom", "left", "right"].each do |pos| %> - <%= t("helpers.settings.plans.margins.#{pos}") -%> - <%= select_tag("settings[export][formatting][margin][#{pos}]", options_for_select((0..100).to_a, @settings.formatting[:margin][pos])) %> - <% end %> + <%= _('Top') -%> + <%= select_tag("settings[export][formatting][margin][top]", options_for_select((0..100).to_a, @settings.formatting[:margin][:top])) %> + <%= _('Bottom') -%> + <%= select_tag("settings[export][formatting][margin][bottom]", options_for_select((0..100).to_a, @settings.formatting[:margin][:bottom])) %> + <%= _('Left') -%> + <%= select_tag("settings[export][formatting][margin][left]", options_for_select((0..100).to_a, @settings.formatting[:margin][:left])) %> + <%= _('Right') -%> + <%= select_tag("settings[export][formatting][margin][right]", options_for_select((0..100).to_a, @settings.formatting[:margin][:right])) %>
  • diff --git a/app/views/answers/update.js.erb b/app/views/answers/update.js.erb index c26a623..1ffdc73 100644 --- a/app/views/answers/update.js.erb +++ b/app/views/answers/update.js.erb @@ -1,5 +1,3 @@ -console.log("Answer update called"); - // after saving the answer (and possibly getting a conflict) // set the message div about the answer. // On success this will be "" on error it will be the diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 63cef43..71f1e7b 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -37,7 +37,7 @@ <%= _('Organisation') %> <%= collection_select(:user, :org_id, @orgs, - :id, :name, {include_blank: constant("organisation_types.organisation")}, + :id, :name, {include_blank: _('Select Organisation')}, { class: "typeahead org_sign_up" }) %> "> diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index e355bf6..4ed662d 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -52,20 +52,22 @@
  • > <%= link_to _('Public DMPs'), public_plans_path %>
  • - - + <% if MANY_LANGUAGES %> + + + <% end %> <% end %> diff --git a/app/views/phases/_answer.html.erb b/app/views/phases/_answer.html.erb index d3563f9..3383519 100644 --- a/app/views/phases/_answer.html.erb +++ b/app/views/phases/_answer.html.erb @@ -20,7 +20,7 @@ <%= af.inputs do %> - <% if question.isOptionBased? %> + <% if question.option_based? %> <% options = question.options.order("number") %> @@ -37,7 +37,7 @@ :collection => options, :label => false, :input_html => { :multiple => true , :disabled => :true } %> - <% elsif qformat.radiobuttons %> + <% elsif qformat.radiobuttons?%>
      <% options.each do |op| %>
    1. @@ -58,7 +58,7 @@ <% if question.option_comment_display %> - <%= label_tag("answer-text-Ans#{question.id}".to_sym, t("helpers.comment")) %> + <%= label_tag("answer-text-Ans#{question.id}".to_sym, _('Comment')) %> <%= text_area_tag("answer-text-Ans#{question.id}".to_sym, answer.text, class: "tinymce") %> <%end%> <% end %> diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb index 5b498fe..763735b 100644 --- a/app/views/phases/_answer_form.html.erb +++ b/app/views/phases/_answer_form.html.erb @@ -56,7 +56,7 @@
      - <% if question.isOptionBased? %> + <% if question.option_based? %> <% options = question.options.order("number") %> diff --git a/app/views/plans/_dropdowns_new_plan.html.erb b/app/views/plans/_dropdowns_new_plan.html.erb index 544d874..1fb8708 100644 --- a/app/views/plans/_dropdowns_new_plan.html.erb +++ b/app/views/plans/_dropdowns_new_plan.html.erb @@ -21,7 +21,7 @@ :collection => @funders, :label => _('If applying for funding, select your research funder.'), :input_html => { :multiple => false, :class => ["select2", "select2-container"] }, - :include_blank => constant("organisation_types.funder") %> + :include_blank => _('Select Funder') %>
      diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb index 8329658..981b3c0 100644 --- a/app/views/plans/_plan_details.html.erb +++ b/app/views/plans/_plan_details.html.erb @@ -200,7 +200,7 @@ <%if plan.template.org.name.present? %> - <%= constant("organisation_types.funder") %> + <%= _('Funder') %> <%= plan.template.org.name %> <%end%> diff --git a/app/views/projects/_dropdowns_new_project.html.erb b/app/views/projects/_dropdowns_new_project.html.erb index 87add23..f9a91ce 100644 --- a/app/views/projects/_dropdowns_new_project.html.erb +++ b/app/views/projects/_dropdowns_new_project.html.erb @@ -11,7 +11,7 @@