diff --git a/.gitignore b/.gitignore index 33c0294..2b59cc6 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,9 @@ # Ignore the test DB db/test.sqlite3 +# Ignore the SimpleCov output +coverage + # Ignore database configuration and token secrets config/database.yml config/secrets.yml diff --git a/.travis.yml b/.travis.yml index 6bbd6e5..bc14e2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ before_script: - cp config/database_example.yml config/database.yml - cp config/secrets_example.yml config/secrets.yml + - cp config/initializers/devise.rb.example config/initializers/devise.rb + - cp config/initializers/recaptcha.rb.example config/initializers/recaptcha.rb + - cp config/initializers/wicked_pdf.rb.example config/initializers/wicked_pdf.rb - bundle exec rake db:migrate RAILS_ENV=test script: diff --git a/Gemfile b/Gemfile index 6c77fdc..35ee76e 100644 --- a/Gemfile +++ b/Gemfile @@ -15,10 +15,10 @@ # ------------------------------------------------ # DATABASE/SERVER +gem 'mysql2', '~> 0.3.18' gem 'pg' gem 'flag_shih_tzu' # Allows for bitfields in activereccord - # ------------------------------------------------ # JS <-> RUBY BRIDGE gem 'libv8' @@ -47,6 +47,8 @@ gem 'devise_invitable' gem 'omniauth' gem 'omniauth-shibboleth' +gem 'omniauth-orcid' + #rolify for roles gem 'rolify' # Gems for repository integration @@ -63,7 +65,7 @@ gem 'jquery-rails' gem 'twitter-bootstrap-rails', '2.2.8' gem 'tinymce-rails' # WYSIWYG EDITOR -gem 'contact_us', '>= 1.2.0' # COULD BE EASILY REPLACED WITH OUR OWN CODE +gem 'contact_us', '>= 1.2.0' # COULD BE EASILY REPLACED WITH OUR OWN CODE gem 'recaptcha' gem 'dragonfly' # LOGO UPLOAD @@ -103,7 +105,9 @@ gem 'minitest-rails-capybara' gem 'minitest-reporters' gem 'rack-test' + gem 'webmock' gem 'sqlite3' + gem 'simplecov', require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 432daf6..8359a7c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,6 +108,8 @@ concurrent-ruby (1.0.2) contact_us (1.2.0) rails (>= 4.2.0) + crack (0.4.3) + safe_yaml (~> 1.0.0) daemons (1.2.4) debug_inspector (0.0.2) devise (4.2.0) @@ -119,6 +121,7 @@ devise_invitable (1.7.0) actionmailer (>= 4.0.0) devise (>= 4.0.0) + docile (1.1.5) dragonfly (1.0.12) addressable (~> 2.3) multi_json (~> 1.0) @@ -146,6 +149,7 @@ has_scope (0.6.0) actionpack (>= 3.2, < 5) activesupport (>= 3.2, < 5) + hashdiff (0.3.0) hashie (3.4.6) htmltoword (0.5.1) actionpack @@ -169,6 +173,7 @@ jquery-ui-rails (5.0.5) railties (>= 3.2.16) json (1.8.3) + jwt (1.5.6) kaminari (0.17.0) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -211,13 +216,26 @@ minitest (>= 5.0) ruby-progressbar multi_json (1.12.1) + multi_xml (0.5.5) multipart-post (2.0.0) + mysql2 (0.3.21) nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) + oauth2 (1.2.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) omniauth (1.3.1) hashie (>= 1.2, < 4) rack (>= 1.0, < 3) + omniauth-oauth2 (1.4.0) + oauth2 (~> 1.0) + omniauth (~> 1.2) + omniauth-orcid (1.2.1) + omniauth-oauth2 (~> 1.3) omniauth-shibboleth (1.2.1) omniauth (>= 1.0.0) orm_adapter (0.5.0) @@ -274,6 +292,7 @@ rolify (5.1.0) ruby-progressbar (1.8.1) rubyzip (1.2.0) + safe_yaml (1.0.4) sass (3.4.22) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -282,6 +301,11 @@ sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) sax-machine (1.3.2) + simplecov (0.12.0) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) sprockets (3.7.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -321,6 +345,10 @@ binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + webmock (2.1.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff wicked_pdf (1.1.0) wkhtmltopdf-binary (0.12.3) xpath (2.0.0) @@ -354,7 +382,9 @@ libv8 minitest-rails-capybara minitest-reporters + mysql2 (~> 0.3.18) omniauth + omniauth-orcid omniauth-shibboleth pg protected_attributes @@ -368,6 +398,7 @@ responders (~> 2.0) rolify sass-rails + simplecov sqlite3 swagger-docs therubyracer (>= 0.11.4) @@ -376,6 +407,7 @@ twitter-bootstrap-rails (= 2.2.8) uglifier web-console (~> 2.0) + webmock wicked_pdf wkhtmltopdf-binary yaml_db! diff --git a/README.md b/README.md index 597ae17..88ceaba 100644 --- a/README.md +++ b/README.md @@ -15,87 +15,22 @@ #### Summary -#### Pre-requisites -Roadmap is a Ruby on Rails application and you will need to have: -1. Ruby >= 2.0.0p247 -2. Rails >= 4.0 -3. MySql >= 5.0 +#### Installation and Requirements +See the [Installation Guide](https://github.com/DMPRoadmap/roadmap/wiki/Installation) -Further details on how to install Ruby on Rails applications are available from the Ruby on Rails site: http://rubyonrails.org +#### Migrating data from a running instance of DMPOnline_v4 or DMPTool +Migration instructions will be coming soon -Further details on how to install MySQL and create your first user and database. Be sure to follow the instructions for your particular environment. -* Install: http://dev.mysql.com/downloads/mysql/ -* Create a user: http://dev.mysql.com/doc/refman/5.7/en/create-user.html -* Create the database: http://dev.mysql.com/doc/refman/5.7/en/creating-database.html - -You may also find the following resources handy: - -* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html -* Ruby on Rails Tutorial Book: http://www.railstutorial.org/ - -#### Installation -* Create your mysql db. Select UTF-8 Unicode (utf8mb4) encoding. -* Fork the repository and then clone it onto your server - -> > git clone https://github.com/[your organization]/roadmap.git - -> > cd roadmap - -* Make copies of the yaml configuration files and update the values for your installation - -> > cp config/database_example.yml config/database.yml -> > cp config/secrets_example.yml config/secrets.yml - -* Create an environment variable for your instance's secret (as defined in config/secrets.yml). You should use the following command to generate secrets for each of your environments, storing the production one in the environment variable: - -> > rake secret - -* Run bundler and perform the DB migrations - -> > gem install bundler (if bundler is not yet installed) - -> > bundle install - -> > rake db:migrate - -> > rake db:seed - -* Setup the devise authentication gem - -> > rails generate devise:install (Is this really necessary?) - -* Start the application - -> > rails server - -* Verify that the site is running properly by going to http://localhost:3000 -* Login as the default administrator: 'super_admin@example.com' - 'password1' #### Troubleshooting -##### Installation - OSX: - -``` -An error occurred while installing libv8 (3.11.8.17), and Bundler cannot continue. - -Make sure that `gem install libv8 -v '3.11.8.17'` succeeds before bundling. -``` - -If you are installing on a system that already has v8 installed then you may need to install the libv8 gem manually using your system's current v8 engine. If you're using homebrew to manage your packages you should run 'brew update' and 'brew upgrade' to make sure you have the latest packages - -> > gem uninstall -a libv8 - -> > gem install libv8 -v '<>' -- --with-system-v8 - -> > bundle install +See the [Troubleshooting Guide](https://github.com/DMPRoadmap/roadmap/wiki/Troubleshooting) #### Support Issues should be reported here on [Github Issues](https://github.com/DMPRoadmap/roadmap/issues) Please be advised though that we can only provide limited support for your local installations. #### Become a contributor -Fork this repository and make your modifications in a new branch. Then create a pull request to our 'development' branch. We will reject any pull request made against the 'master' branch. Once your pull request has been submitted the team will review your request and accept it if appropriate. - -Join the developer email listserv at www.jiscmail.ac.uk/DMPONLINE-DEV +See the [Contributor Guide](https://github.com/DMPRoadmap/roadmap/wiki/Contributing) #### License The DMP Roadmap project uses the MIT License. diff --git a/app/admin/org_token_permission.rb b/app/admin/org_token_permission.rb deleted file mode 100644 index 4075d5cf..0000000 --- a/app/admin/org_token_permission.rb +++ /dev/null @@ -1,31 +0,0 @@ -ActiveAdmin.register OrgTokenPermission do - permit_params :organisation_id, :token_permission_type_id - - menu priority: 40, label: proc{ I18n.t('admin.org_token_permission')}, parent: "Api" - - index do - column I18n.t('admin.org') do |n| - link_to n.organisation, [:admin,n] - end - column I18n.t('admin.token_permission') do |n| - link_to n.token_permission_type, [:admin,n] - end - - actions - end - - show do - attributes_table do - row :organisation_id - row :token_permission_type_id - end - end - - controller do - def permitted_params - params.permit! - end - end - - -end diff --git a/app/controllers/api/v0/base_controller.rb b/app/controllers/api/v0/base_controller.rb index 7e939fd..b36bfa8 100644 --- a/app/controllers/api/v0/base_controller.rb +++ b/app/controllers/api/v0/base_controller.rb @@ -131,7 +131,7 @@ # end # end # end - OrgTokenPermission.where(organisation_id: @user.organisation_id).find_each do |org_token_permission| + OrgTokenPermission.where(org_id: @user.org_id).find_each do |org_token_permission| logger.debug "#{org_token_permission.token_permission_type.token_type}" if org_token_permission.token_permission_type.token_type == auth_type auth= true diff --git a/app/controllers/api/v0/dmptemplates_controller.rb b/app/controllers/api/v0/dmptemplates_controller.rb deleted file mode 100644 index 0e0a256..0000000 --- a/app/controllers/api/v0/dmptemplates_controller.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Api - module V0 - class DmptemplatesController < Api::V0::BaseController - before_action :authenticate - - - ## - # GET - # @return a list of templates ordered by organisation - def index - # check if the user has permissions to use the templates API - if has_auth(constant("api_endpoint_types.templates")) - @all_templates = Dmptemplate.all - respond_with @all_templates - else - #render unauthorised - render json: I18n.t("api.no_auth_for_endpoint"), status: 401 - end - - end - end - end -end \ No newline at end of file diff --git a/app/controllers/api/v0/guidance_groups_controller.rb b/app/controllers/api/v0/guidance_groups_controller.rb index a22c9b2..d300b39 100644 --- a/app/controllers/api/v0/guidance_groups_controller.rb +++ b/app/controllers/api/v0/guidance_groups_controller.rb @@ -5,7 +5,7 @@ def show # check if the user has permission to use the guidances api - if has_auth(constant("api_endpoint_types.guidances")) + if has_auth(constant("token_permission_types.guidances")) # determine if they have authorization to view this guidance group if GuidanceGroup.can_view?(@user, params[:id]) respond_with get_resource @@ -18,7 +18,7 @@ end def index - if has_auth(constant("api_endpoint_types.guidances")) + if has_auth(constant("token_permission_types.guidances")) @all_viewable_groups = GuidanceGroup.all_viewable(@user) respond_with @all_viewable_groups else diff --git a/app/controllers/api/v0/plans_controller.rb b/app/controllers/api/v0/plans_controller.rb new file mode 100644 index 0000000..ad76c3d --- /dev/null +++ b/app/controllers/api/v0/plans_controller.rb @@ -0,0 +1,104 @@ +module Api + module V0 + class ProjectsController < Api::V0::BaseController + before_action :authenticate + + swagger_controller :projects, 'Plans' + + swagger_api :create do |api| + summary 'Returns a single guidance group item' + notes 'Notes...' + param :header, 'Authentication-Token', :string, :required, 'Authentication-Token' + response :unauthorized + response :not_found + end + + ## + # Creates a new project based on the information passed in JSON to the API + def create + # find the user's api_token permissions + # then ensure that they have the permission associated with creating plans + if has_auth(constant("api_endpoint_types.plans")) + #params[:organization_id] = Org.where(name: params[:template][:organization]) + # find_by returns nil if none found, find_by! raises an ActiveRecord error + organization = Org.find_by name: params[:template][:organisation] + + # if organization exists + if !organization.nil? + # if organization is funder + if organization.organisation_type == (OrganisationType.find_by(name: constant("organisation_types.funder"))) + # if organization has only 1 template + if organization.dmptemplates.length == 1 + # set template id + dmptemplate = organization.dmptemplates.first + # else if params.template.name specified && params.template.name == one of organization's tempates + elsif !organization.dmptemplates.find_by title: params[:template][:name].nil? + # set template id + dmptemplate = organization.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 + end + # else error: organization specified is not a funder + else + render json: I18n.t("api.org_not_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 + end + + all_groups = [] + # Check to see if the user specified guidances + if !params[:guidance].nil? + # for each specified guidance, see if it exists + params[:guidance][:name].each do |guidance_name| + group = GuidanceGroup.find_by(name: guidance_name) + # if it exists, add it to the guidances for the new project + if !group.nil? + all_groups = all_groups + [group] + end + end + end + + # cant invite a user without having a current user because of devise :ivitable + # after we have auth, will be able to assign an :invited_by_id + user = User.find_by email: params[:project][:email] + # if user does not exist + if user.nil? + # invite user to DMPRoadmap + User.invite!({email: params[:project][:email]}, ( @user)) + # set project owner to user associated w/email + user = (User.find_by email: params[:project][:email]) + end + + # create new project with specified parameters + @project = Project.new + @project.title = params[:project][:title] + @project.dmptemplate = dmptemplate + @project.slug = params[:project][:title] + @project.organisation = @user.organisations.first + @project.assign_creator(user.id) + @project.guidance_groups = all_groups + + # if save successful, render success, otherwise show error + if @project.save + #render json: @project ,status: :created + render :show, status: :created + else + render json: get_resource.errors, status: :unprocessable_entity + end + else + + render json: I18n.t("api.no_auth_for_endpoint"), status: 400 and return + end + end + + # private + # def project_params + # params.require(:template).permit(:organisation, :name) + # params.require(:project).permit(:title, :email) + # end + end + end +end diff --git a/app/controllers/api/v0/projects_controller.rb b/app/controllers/api/v0/projects_controller.rb deleted file mode 100644 index ad76c3d..0000000 --- a/app/controllers/api/v0/projects_controller.rb +++ /dev/null @@ -1,104 +0,0 @@ -module Api - module V0 - class ProjectsController < Api::V0::BaseController - before_action :authenticate - - swagger_controller :projects, 'Plans' - - swagger_api :create do |api| - summary 'Returns a single guidance group item' - notes 'Notes...' - param :header, 'Authentication-Token', :string, :required, 'Authentication-Token' - response :unauthorized - response :not_found - end - - ## - # Creates a new project based on the information passed in JSON to the API - def create - # find the user's api_token permissions - # then ensure that they have the permission associated with creating plans - if has_auth(constant("api_endpoint_types.plans")) - #params[:organization_id] = Org.where(name: params[:template][:organization]) - # find_by returns nil if none found, find_by! raises an ActiveRecord error - organization = Org.find_by name: params[:template][:organisation] - - # if organization exists - if !organization.nil? - # if organization is funder - if organization.organisation_type == (OrganisationType.find_by(name: constant("organisation_types.funder"))) - # if organization has only 1 template - if organization.dmptemplates.length == 1 - # set template id - dmptemplate = organization.dmptemplates.first - # else if params.template.name specified && params.template.name == one of organization's tempates - elsif !organization.dmptemplates.find_by title: params[:template][:name].nil? - # set template id - dmptemplate = organization.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 - end - # else error: organization specified is not a funder - else - render json: I18n.t("api.org_not_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 - end - - all_groups = [] - # Check to see if the user specified guidances - if !params[:guidance].nil? - # for each specified guidance, see if it exists - params[:guidance][:name].each do |guidance_name| - group = GuidanceGroup.find_by(name: guidance_name) - # if it exists, add it to the guidances for the new project - if !group.nil? - all_groups = all_groups + [group] - end - end - end - - # cant invite a user without having a current user because of devise :ivitable - # after we have auth, will be able to assign an :invited_by_id - user = User.find_by email: params[:project][:email] - # if user does not exist - if user.nil? - # invite user to DMPRoadmap - User.invite!({email: params[:project][:email]}, ( @user)) - # set project owner to user associated w/email - user = (User.find_by email: params[:project][:email]) - end - - # create new project with specified parameters - @project = Project.new - @project.title = params[:project][:title] - @project.dmptemplate = dmptemplate - @project.slug = params[:project][:title] - @project.organisation = @user.organisations.first - @project.assign_creator(user.id) - @project.guidance_groups = all_groups - - # if save successful, render success, otherwise show error - if @project.save - #render json: @project ,status: :created - render :show, status: :created - else - render json: get_resource.errors, status: :unprocessable_entity - end - else - - render json: I18n.t("api.no_auth_for_endpoint"), status: 400 and return - end - end - - # private - # def project_params - # params.require(:template).permit(:organisation, :name) - # params.require(:project).permit(:title, :email) - # end - end - end -end diff --git a/app/controllers/api/v0/statistics_controller.rb b/app/controllers/api/v0/statistics_controller.rb index ec21140..f893bc5 100644 --- a/app/controllers/api/v0/statistics_controller.rb +++ b/app/controllers/api/v0/statistics_controller.rb @@ -8,7 +8,7 @@ # @return a count of users who joined DMPonline between the optional specified dates # users are scoped to the organisation of the user initiating the call def users_joined - if has_auth(constant("api_endpoint_types.statistics")) + if has_auth(constant("token_permission_types.statistics")) users = restrict_date_range(@user.organisations.first.users) confirmed_users = [] users.each do |user| @@ -29,7 +29,7 @@ # @return the number of DMPs using the specified template between the optional specified dates # ensures that the template is owned/created by the caller's organisation def using_template - if has_auth(constant("api_endpoint_types.statistics")) + if has_auth(constant("token_permission_types.statistics")) template = Dmptemplate.find(params[:id]) if template.organisation == @user.organisations.first @template_count = restrict_date_range(template.projects).count @@ -48,7 +48,7 @@ # the uses are restricted to DMPs created by users of the same organisation # as the user who ititiated the call def plans_by_template - if has_auth(constant("api_endpoint_types.statistics")) + if has_auth(constant("token_permission_types.statistics")) @org_projects = [] @user.organisations.first.users.each do |user| user.projects.each do |project| @@ -70,7 +70,7 @@ # DMPs must be owned by a user who's organisation is the same as the user # who generates the call def plans - if has_auth(constant("api_endpoint_types.statistics")) + if has_auth(constant("token_permission_types.statistics")) @org_projects = [] @user.organisations.first.users.each do |user| user.projects.each do |project| diff --git a/app/controllers/api/v0/templates_controller.rb b/app/controllers/api/v0/templates_controller.rb new file mode 100644 index 0000000..3ab1207 --- /dev/null +++ b/app/controllers/api/v0/templates_controller.rb @@ -0,0 +1,34 @@ +module Api + module V0 + class TemplatesController < Api::V0::BaseController + before_action :authenticate + + + ## + # GET + # @return a list of templates ordered by organisation + def index + # check if the user has permissions to use the templates API + if has_auth(constant("api_endpoint_types.templates")) + @org_templates = {} + published_templates = Template.includes(:org).where(customization_of: nil, published: true).order(:org_id, :version) + published_templates.all.each do |temp| + if @org_templates[temp.org].present? + if @org_templates[temp.org][temp.dmptemplate_id].nil? + @org_templates[temp.org][temp.dmptemplate_id] = temp + end + else + @org_templates[temp.org] = {} + @org_templates[temp.org][temp.dmptemplate_id] = temp + end + end + respond_with @org_templates + else + #render unauthorised + render json: I18n.t("api.no_auth_for_endpoint"), status: 401 + end + + end + end + end +end \ No newline at end of file diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index a64e773..6ce60fc 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -353,71 +353,51 @@ @plan = Plan.find(params[:id]) authorize @plan - if user_signed_in? && @plan.readable_by(current_user.id) then - @exported_plan = ExportedPlan.new.tap do |ep| - ep.plan = @plan - ep.user = current_user - #ep.format = request.format.try(:symbol) + if (user_signed_in? && @plan.readable_by(current_user.id)) then + @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) + 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.html - format.xml - format.json - format.csv { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" } - format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" } - format.docx { headers["Content-Disposition"] = "attachment; filename=\"#{file_name}.docx\""} - 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 - elsif !user_signed_in? then - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - 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') } - end - end - end - - - - private - - - def get_most_recent( templates ) - groups = Hash.new - templates.each do |t| - k = t.dmptemplate_id - if !groups.has_key?(k) - groups[k] =t - else - other = groups[k] - if other.version < t.version - groups[k] = t - end - end - end - groups.values - end - + respond_to do |format| + format.html + format.xml + format.json + format.csv { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" } + format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" } + format.docx { headers["Content-Disposition"] = "attachment; filename=\"#{file_name}.docx\""} + 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 + + elsif !user_signed_in? then + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + 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') } + end + end + end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 4e6d8e9..b23c6ca 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -169,116 +169,127 @@ # returns to AJAX call from frontend # difficult to secure as it passes through params, and dosent curate data based # on what the user can "view" or is public - # GET /projects/possible_templates.json - def possible_templates - if !params[:funder].nil? && params[:funder] != "" && params[:funder] != "undefined" then - funder = Org.find(params[:funder]) - else - funder = nil - end - if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then - institution = Org.find(params[:institution]) - else - institution = nil - end - templates = {} - unless funder.nil? then - funder.published_templates.each do |t| - templates[t.id] = t.title - end - end - if templates.count == 0 && !institution.nil? then - institution.published_templates.each do |t| - templates[t.id] = t.title - end - institution.children.each do |o| - o.published_templates.each do |t| - templates[t.id] = t.title - end - end - end - respond_to do |format| - format.json { render json: templates.to_json } - end - end + + # GET /projects/possible_templates.json + def possible_templates + if !params[:funder].nil? && params[:funder] != "" && params[:funder] != "undefined" then + funder = Org.find(params[:funder]) + else + funder = nil + end + if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then + institution = Org.find(params[:institution]) + else + institution = nil + end + templates = {} + unless funder.nil? then + funder.published_templates.each do |t| + templates[t.id] = t.title + end + end + if templates.count == 0 && !institution.nil? then + institution.published_templates.each do |t| + templates[t.id] = t.title + end + institution.children.each do |o| + o.published_templates.each do |t| + templates[t.id] = t.title + end + end + end + respond_to do |format| + format.json { render json: templates.to_json } + end + end # returns to AJAX call from frontend - # difficult to secure as it passes through params, and dosent curate data based + # difficult to secure as it passes through params, and dosent curate data based # on what the user can "view" or is public + # ----------------------------------------------------------- def possible_guidance authorize @project - if !params[:template].nil? && params[:template] != "" && params[:template] != "undefined" then - template = Dmptemplate.find(params[:template]) - else - template = nil - end - if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then - institution = Org.find(params[:institution]) - else - institution = nil - end - excluded_orgs = orgs_of_type(constant("organisation_types.funder")) + orgs_of_type(constant("organisation_types.institution")) + Org.orgs_with_parent_of_type(constant("organisation_types.institution")) - guidance_groups = {} - ggs = GuidanceGroup.guidance_groups_excluding(excluded_orgs) - ggs.each do |gg| - guidance_groups[gg.id] = gg.name - end + if !params[:template].nil? && params[:template] != "" && params[:template] != "undefined" then + template = Dmptemplate.find(params[:template]) + else + template = nil + end + if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then + institution = Org.find(params[:institution]) + else + institution = nil + end + excluded_orgs = orgs_of_type(constant("organisation_types.funder")) + orgs_of_type(constant("organisation_types.institution")) + Org.orgs_with_parent_of_type(constant("organisation_types.institution")) + guidance_groups = {} + ggs = GuidanceGroup.guidance_groups_excluding(excluded_orgs) + + ggs.each do |gg| + guidance_groups[gg.id] = gg.name + end #subset guidance that belong to the institution - unless institution.nil? then + unless institution.nil? then authorize Project - optional_gg = GuidanceGroup.where("optional_subset = ? AND organisation_id = ?", true, institution.id) - optional_gg.each do|optional| - guidance_groups[optional.id] = optional.name - end + optional_gg = GuidanceGroup.where("optional_subset = ? AND organisation_id = ?", true, institution.id) + optional_gg.each do|optional| + guidance_groups[optional.id] = optional.name + end - institution.children.each do |o| - o.guidance_groups.each do |gg| - include = false - gg.guidances.each do |g| - if g.dmptemplate.nil? || g.dmptemplate_id == template.id then - include = true - break - end - end - if include then - guidance_groups[gg.id] = gg.name - end - end + institution.children.each do |o| + o.guidance_groups.each do |gg| + include = false + gg.guidances.each do |g| + if g.dmptemplate.nil? || g.dmptemplate_id == template.id then + include = true + break end + end + if include then + guidance_groups[gg.id] = gg.name + end end + end + end #If template belongs to a funder and that funder has subset guidance display then. if !template.nil? && template.organisation.organisation_type.name == constant("organisation_types.funder") then optional_gg = GuidanceGroup.where("optional_subset = ? AND organisation_id = ?", true, template.organisation_id) - optional_gg.each do|optional| - guidance_groups[optional.id] = optional.name - end + optional_gg.each do|optional| + guidance_groups[optional.id] = optional.name + end end - respond_to do |format| - format.json { render json: guidance_groups.to_json } - end + respond_to do |format| + format.json { render json: guidance_groups.to_json } + end + end + + private + def project_params + params.require(:project).permit(:title, :grant_number, :identifier, :description, + :principal_investigator, :principal_investigator_identifier, + :data_contact, :funder_name, :visibility, + :dmptemplate_id, :organisation_id, :funder_id, :institution_id, + :guidance_group_ids, :project_group_ids) end - private - def orgs_of_type(org_type_name, published_templates = false) - org_type = OrganisationType.find_by_name(org_type_name) - all_such_orgs = org_type.organisations - if published_templates then - with_published = Array.new - all_such_orgs.each do |o| - if o.published_templates.count > 0 then - with_published << o - end - end - return with_published.sort_by {|o| [o.sort_name, o.name] } - else - return all_such_orgs.sort_by {|o| [o.sort_name, o.name] } + def orgs_of_type(org_type_name, published_templates = false) + org_type = OrganisationType.find_by_name(org_type_name) + all_such_orgs = org_type.organisations + if published_templates then + with_published = Array.new + all_such_orgs.each do |o| + if o.published_templates.count > 0 then + with_published << o end + end + return with_published.sort_by {|o| [o.sort_name, o.name] } + else + return all_such_orgs.sort_by {|o| [o.sort_name, o.name] } end + end # ----------------------------------------------------------- def get_available_templates @@ -294,7 +305,7 @@ # ----------------------------------------------------------- def get_always_available_guidance # Exclude Funders, Institutions, or children of Institutions - excluded_orgs = orgs_of_type(constant("organisation_types.funder")) + + excluded_orgs = orgs_of_type(constant("organisation_types.funder")) + orgs_of_type(constant("organisation_types.institution")) + Org.orgs_with_parent_of_type(constant("organisation_types.institution")) @@ -333,4 +344,42 @@ GuidanceGroup.where(id: guidance_groups) end + + # ----------------------------------------------------------- + def generate_export + @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 + + @exported_plan.save! # FIXME: handle invalid request types without erroring? + file_name = @exported_plan.project_name + + respond_to do |format| + format.html + format.xml + format.json + format.csv { send_data @exported_plan.as_csv, filename: "#{file_name}.csv" } + format.text { send_data @exported_plan.as_txt, filename: "#{file_name}.txt" } + format.docx { headers["Content-Disposition"] = "attachment; filename=\"#{file_name}.docx\""} + 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 + end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 0f74a00..a82b679 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -5,6 +5,31 @@ @languages = Language.all.order("name") @orgs = Org.where(parent_id: nil).order("name") @other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id) + @identifier_schemes = IdentifierScheme.where(active: true).order(:name) + end + + # GET /resource + def new + oauth = {provider: nil, uid: nil} + IdentifierScheme.all.each do |scheme| + oauth = session["devise.#{scheme.name.downcase}_data"] unless session["devise.#{scheme.name.downcase}_data"].nil? + end + + @user = User.new + + unless oauth.nil? + # The OAuth provider could not be determined or there was no unique UID! + if oauth[:provider].nil? || oauth[:uid].nil? + flash[:notice] = t('identifier_schemes.new_login_failure') + + else + # Connect the new user with the identifier sent back by the OAuth provider + flash[:notice] = t('identifier_schemes.new_login_success') + UserIdentifier.create(identifier_scheme: oauth[:provider].upcase, + identifier: oauth[:uid], + user: @user) + end + end end # POST /resource @@ -43,11 +68,16 @@ def update - if user_signed_in? then + if user_signed_in? then @user = User.find(current_user.id) + @orgs = Org.where(parent_id: nil).order("name") + @other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id) + @languages = Language.order("name") + @identifier_schemes = IdentifierScheme.where(active: true).order(:name) + do_update else - render(file: File.join(Rails.root, 'public/403.html'), status: 403, layout: false) + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) end end @@ -95,8 +125,11 @@ end set_flash_message :notice, :updated # Sign in the user bypassing validation in case his password changed - sign_in @user, bypass: true - redirect_to({controller: "registrations", action: "edit"}, {notice: I18n.t('helpers.project.details_update_success')}) + + sign_in @user, bypass_sign_in: true + + redirect_to({:controller => "registrations", :action => "edit"}, {:notice => I18n.t('helpers.project.details_update_success')}) + else render "edit" end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2bf4305..89a5f44 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,8 +1,22 @@ class SessionsController < Devise::SessionsController + # POST /auth/:provider/callback + # --------------------------------------------------------------------- +=begin + def oauth_create + existing_user = User.find_by_email(params[:user][:email]) + + unless params[:omniauth].nil? + existing_user = UserIdentifier.find_by(identifier: params[:omniauth][:auth]) + end + end +=end + # Capture the user's shibboleth id if they're coming in from an IDP + # --------------------------------------------------------------------- def create existing_user = User.find_by(email: params[:user][:email]) + if !existing_user.nil? && !params[:shibboleth_data].nil? then #after authentication verify if session[:shibboleth] exists existing_user.update_attributes(shibboleth_id: session[:shibboleth_data][:uid]) diff --git a/app/controllers/settings/projects_controller.rb b/app/controllers/settings/projects_controller.rb index 6ba2cd3..8b0f800 100644 --- a/app/controllers/settings/projects_controller.rb +++ b/app/controllers/settings/projects_controller.rb @@ -36,7 +36,7 @@ @settings = current_user.settings(:plan_list) # :name column should always be present (displayed as a disabled checkbox) # so it's not necessary to include it in the list here - @all_columns -= [:name] + @all_columns -= ['name'] end def settings_json diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index c371a2f..da81ea8 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -14,5 +14,62 @@ def roadmap end + + # GET /projects/publicly_available + # ----------------------------------------------------------- + def public_plans + @projects = Project.publicly_visible.order(title: :asc) + end + # GET /projects/[:project_slug]/public_export + # ------------------------------------------------------------- + def public_export + @project = Project.find(params[:id]) + + # Force PDF response + request.format = :pdf + + # if the project is designated as public + if @project.visibility == :publicly_visible + @plan = @project.plans.first + + 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 + + @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 + + 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 + # 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 + end end \ No newline at end of file diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 075371b..5601a7b 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -3,445 +3,289 @@ # [+Copyright:+] Digital Curation Centre and University of California Curation Center class TemplatesController < ApplicationController + respond_to :html after_action :verify_authorized # GET /dmptemplates def admin_index authorize Template - #institutional templates - @dmptemplates_own = Template.own_institutional_templates(current_user.org_id) + #institutional templates + all_versions_own_templates = Template.where(org_id: current_user.org_id, customization_of: nil).order(version: :desc) + current_templates = {} + all_versions_own_templates.each do |temp| + if current_templates[temp.dmptemplate_id].nil? + current_templates[temp.dmptemplate_id] = temp + end + end + @templates_own = current_templates.values #funders templates - @dmptemplates_funders = Template.funders_templates + @templates_funders = Template.funders_templates end + # GET /dmptemplates/1 def admin_template - @dmptemplate = Dmptemplate.find(params[:id]) - authorize @dmptemplate - respond_to do |format| - format.html # show.html.erb - end + @template = Template.find(params[:id]) + authorize @template end - # PUT /dmptemplates/1 def admin_update - @dmptemplate = Dmptemplate.find(params[:id]) - authorize @dmptemplate - @dmptemplate.description = params["template-desc"] - respond_to do |format| - if @dmptemplate.update_attributes(params[:dmptemplate]) - format.html { redirect_to admin_template_dmptemplate_path(params[:dmptemplate]), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "edit" } - end - end + @template = Template.find(params[:id]) + authorize @template + @template.description = params["template-desc"] + if @template.update_attributes(params[:template]) + redirect_to admin_template_template_path(params[:template]), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "edit" + end end # GET /dmptemplates/new def admin_new - @dmptemplate = Dmptemplate.new - authorize @dmptemplate - respond_to do |format| - format.html # new.html.erb - end + authorize Template end + # POST /dmptemplates + # creates a new template with version 0 and new dmptemplate_id def admin_create - @dmptemplate = Dmptemplate.new(params[:dmptemplate]) - @dmptemplate.organisation_id = current_user.organisation.id - @dmptemplate.description = params['template-desc'] - authorize @dmptemplate - respond_to do |format| - if @dmptemplate.save - format.html { redirect_to admin_template_dmptemplate_path(@dmptemplate), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_new" } - end + @template = Template.new(params[:template]) + @template.org_id = current_user.org_id + @template.description = params['template-desc'] + @template.published = false + @template.version = 0 + # Generate a unique identifier for the dmptemplate_id + @template.dmptemplate_id = loop do + random = rand 2147483647 + break random unless Template.exists?(dmptemplate_id: random) + end + authorize @template + if @template.save + redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_new" end end - # DELETE /dmptemplates/1 def admin_destroy - @dmptemplate = Dmptemplate.find(params[:id]) - authorize @dmptemplate - @dmptemplate.destroy - respond_to do |format| - format.html { redirect_to admin_index_dmptemplate_path } - end - end + @template = Template.find(params[:id]) + authorize @template + @template.destroy + redirect_to admin_index_template_path + end - - - # PHASES - - #show and edit a phase of the template - def admin_phase - @phase = Phase.find(params[:id]) - authorize @phase.dmptemplate - if !params.has_key?(:version_id) then - @edit = 'false' - #check for the most recent published version, if none is available then return the most recent one - versions = @phase.versions.where('published = ?', true).order('updated_at DESC') - if versions.any?() then - @version = versions.first - else - @version = @phase.versions.order('updated_at DESC').first - end - # When the version_id is passed as an argument - else - @edit = params[:edit] - @version = Version.find(params[:version_id]) - end - #verify if there are any sections if not create one - @sections = @version.sections - if !@sections.any?() || @sections.count == 0 then - @section = @version.sections.build - @section.title = '' - @section.version_id = params[:version_id] - @section.number = 1 - @section.organisation_id = current_user.organisation.id - @section.published = true - @section.save - @new_sec = true - end - #verify if section_id has been passed, if so then open that section - if params.has_key?(:section_id) then - @open = true - @section_id = params[:section_id].to_i - end - if params.has_key?(:question_id) then - @question_id = params[:question_id].to_i - end - respond_to do |format| - format.html - end - end - - - #preview a phase - def admin_previewphase - @version = Version.find(params[:id]) - authorize @version.phase.dmptemplate - respond_to do |format| - format.html - end - end - - - #add a new phase to a template - def admin_addphase - @dmptemplate = Dmptemplate.find(params[:id]) - @phase = Phase.new - authorize @dmptemplate - if @dmptemplate.phases.count == 0 then - @phase.number = '1' - else - @phase.number = @dmptemplate.phases.count + 1 - end - respond_to do |format| - format.html - end - end - - - #create a phase - def admin_createphase - @phase = Phase.new(params[:phase]) - authorize @phase.dmptemplate - @phase.description = params["phase-desc"] - @version = @phase.versions.build - @version.title = "#{@phase.title} v.1" - @version.phase_id = @phase.id - @version.number = 1 - @version.published = false - respond_to do |format| - if @phase.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end - end + # GET /templates/1 + def admin_template_history + @template = Template.find(params[:id]) + authorize @template + @templates = Template.where(dmptemplate_id: @template.dmptemplate_id).order(:version) end - #update a phase of a template - def admin_updatephase - @phase = Phase.find(params[:id]) - authorize @phase.dmptemplate - @phase.description = params["phase-desc"] - respond_to do |format| - if @phase.update_attributes(params[:phase]) - format.html { redirect_to admin_phase_dmptemplate_path(@phase), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end - end - end - #delete a version, sections and questions - def admin_destroyphase - @phase = Phase.find(params[:phase_id]) - authorize @phase.dmptemplate - @dmptemplate = @phase.dmptemplate + # PHASES + + #show and edit a phase of the template + def admin_phase + @phase = Phase.find(params[:id]) + authorize @phase.template + @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 + @section = @phase.sections.build + @section.phase = @phase + @section.title = '' + @section.number = 1 + @section.published = true + @section.modifiable = true + @section.save + @new_sec = true + end + #verify if section_id has been passed, if so then open that section + if params.has_key?(:section_id) + @open = true + @section_id = params[:section_id].to_i + end + if params.has_key?(:question_id) + @question_id = params[:question_id].to_i + end + end + + + #preview a phase + def admin_previewphase + @phase = Phase.find(params[:id]) + authorize @phase.template + @template = @phase.template + end + + + #add a new phase to a template + def admin_addphase + @template = Template.find(params[:id]) + @phase = Phase.new + authorize @template + @phase.number = @template.phases.count + 1 + end + + + #create a phase + def admin_createphase + @phase = Phase.new(params[:phase]) + authorize @phase.template + @phase.description = params["phase-desc"] + @phase.modifiable = true + if @phase.save + redirect_to admin_phase_template_path(id: @phase.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_phase" + end + end + + + #update a phase of a template + def admin_updatephase + @phase = Phase.find(params[:id]) + authorize @phase.template + @phase.description = params["phase-desc"] + if @phase.update_attributes(params[:phase]) + redirect_to admin_phase_template_path(@phase), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" + end + end + + #delete a phase + def admin_destroyphase + @phase = Phase.find(params[:phase_id]) + authorize @phase.template + @template = @phase.template @phase.destroy - respond_to do |format| - format.html { redirect_to admin_template_dmptemplate_path(@dmptemplate), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end - -# VERSIONS - - #update a version of a template - def admin_updateversion - @version = Version.find(params[:id]) - authorize @version.phase.dmptemplate - @version.description = params["version-desc"] - @phase = @version.phase - if @version.published && !@phase.dmptemplate.published then - @phase.dmptemplate.published = true - end - if @version.published == true then - @all_versions = @phase.versions.where('published = ?', true) - @all_versions.each do |v| - if v.id != @version.id && v.published == true then - v.published = false - v.save - end - end - end - respond_to do |format| - if @version.update_attributes(params[:version]) - format.html { redirect_to admin_phase_dmptemplate_path(@phase, :version_id => @version.id, :edit => 'false'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #clone a version of a template - def admin_cloneversion - @old_version = Version.find(params[:version_id]) - authorize @old_version.phase.dmptemplate - @version = @old_version.amoeba_dup - @phase = @version.phase - respond_to do |format| - if @version.save - format.html { redirect_to admin_phase_dmptemplate_path(@phase, :version_id => @version.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #delete a version, sections and questions - def admin_destroyversion - @version = Version.find(params[:version_id]) - authorize @version.phase.dmptemplate - @phase = @version.phase - @version.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(@phase), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end - + redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.destroyed_message') + end # SECTIONS - #create a section - def admin_createsection + #create a section + def admin_createsection @section = Section.new(params[:section]) - authorize @section.version.phase.dmptemplate + authorize @section.phase.template @section.description = params["section-desc"] - respond_to do |format| - if @section.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @section.version.phase_id, :version_id => @section.version_id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end - end + if @section.save + redirect_to admin_phase_template_path(id: @section.phase_id, + :section_id => @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.created_message') + else + render action: "admin_phase" + end end - #update a section of a template - def admin_updatesection - @section = Section.find(params[:id]) - authorize @section.version.phase.dmptemplate - @section.description = params["section-desc-#{params[:id]}"] - @version = @section.version - @phase = @version.phase - respond_to do |format| - if @section.update_attributes(params[:section]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id , :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + #update a section of a template + def admin_updatesection + @section = Section.find(params[:id]) + authorize @section.phase.template + @section.description = params["section-desc-#{params[:id]}"] + @phase = @section.phase + if @section.update_attributes(params[:section]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id , edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end - end + end - #delete a section and questions - def admin_destroysection - @section = Section.find(params[:section_id]) - authorize @section.version.phase.dmptemplate - @version = @section.version - @phase = @version.phase + #delete a section and questions + def admin_destroysection + @section = Section.find(params[:section_id]) + authorize @section.phase.template + @phase = @section.phase @section.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :edit => 'true' ), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end + redirect_to admin_phase_template_path(id: @phase.id, edit: 'true' ), notice: I18n.t('org_admin.templates.destroyed_message') + end # QUESTIONS - #create a question - def admin_createquestion - @question = Question.new(params[:question]) - authorize @question.section.version.phase.dmptemplate + #create a question + def admin_createquestion + @question = Question.new(params[:question]) + authorize @question.section.phase.template @question.guidance = params["new-question-guidance"] @question.default_value = params["new-question-default-value"] - respond_to do |format| - if @question.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @question.section.version.phase_id, :version_id => @question.section.version_id, :section_id => @question.section_id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #update a question of a template - def admin_updatequestion - @question = Question.find(params[:id]) - authorize @question.section.version.phase.dmptemplate - @question.guidance = params["question-guidance-#{params[:id]}"] - @question.default_value = params["question-default-value-#{params[:id]}"] - @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| - if @question.update_attributes(params[:question]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + if @question.save + redirect_to admin_phase_template_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') + else + render action: "admin_phase" end - end + end - #delete a version, sections and questions - def admin_destroyquestion - @question = Question.find(params[:question_id]) - authorize @question.section.version.phase.dmptemplate - @section = @question.section - @version = @section.version - @phase = @version.phase + #update a question of a template + def admin_updatequestion + @question = Question.find(params[:id]) + authorize @question.section.phase.template + @question.guidance = params["question-guidance-#{params[:id]}"] + @question.default_value = params["question-default-value-#{params[:id]}"] + @section = @question.section + @phase = @section.phase + if @question.update_attributes(params[:question]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" + end + end + + #delete question + def admin_destroyquestion + @question = Question.find(params[:question_id]) + authorize @question.section.phase.template + @section = @question.section + @phase = @section.phase @question.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') + end - #SUGGESTED ANSWERS - #create suggested answers - def admin_createsuggestedanswer + #SUGGESTED ANSWERS + #create suggested answers + def admin_createsuggestedanswer @suggested_answer = SuggestedAnswer.new(params[:suggested_answer]) - authorize @suggested_answer.question.section.version.phase.dmptemplate - respond_to do |format| - if @suggested_answer.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @suggested_answer.question.section.version.phase_id, :version_id => @suggested_answer.question.section.version_id, :section_id => @suggested_answer.question.section_id, :question_id => @suggested_answer.question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end + authorize @suggested_answer.question.section.phase.template + if @suggested_answer.save + redirect_to admin_phase_template_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') + else + render action: "admin_phase" end end - #update a suggested answer of a template - def admin_updatesuggestedanswer - @suggested_answer = SuggestedAnswer.find(params[:id]) - authorize @suggested_answer.question.section.version.phase.dmptemplate + #update a suggested answer of a template + def admin_updatesuggestedanswer + @suggested_answer = SuggestedAnswer.find(params[:id]) + authorize @suggested_answer.question.section.phase.template @question = @suggested_answer.question @section = @question.section - @version = @section.version - @phase = @version.phase - - respond_to do |format| - if @suggested_answer.update_attributes(params[:suggested_answer]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #delete a suggested answer - def admin_destroysuggestedanswer - @suggested_answer = SuggestedAnswer.find(params[:suggested_answer]) - authorize @suggested_answer.question.section.version.phase.dmptemplate - @question = @suggested_answer.question - @section = @question.section - @version = @section.version - @phase = @version.phase - @suggested_answer.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end - -# GUIDANCES - - #create a guidance - def admin_createguidance - @question = Question.find(params[:question][:id]) - authorize @question.section.version.phase.dmptemplate - @guidance = Guidance.new(params[:guidance]) - @guidance.question_id = @question.id - #@question.guidance = params["new-question-guidance"] - #@question.default_value = params["new-question-default-value"] - respond_to do |format| - if @guidance.save - format.html { redirect_to admin_phase_dmptemplate_path(:id => @question.section.version.phase_id, :version_id => @question.section.version_id, :section_id => @question.section_id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.created_message') } - else - format.html { render action: "admin_phase" } - end - end - end - - #update a guidance of a template - def admin_updateguidance - @question = Question.find(params[:id]) - authorize @question.section.version.phase.dmptemplate - @question.guidance = params["question-guidance-#{params[:id]}"] - @question.default_value = params["question-default-value-#{params[:id]}"] - @section = @question.section - @version = @section.version - @phase = @version.phase - respond_to do |format| - if @question.update_attributes(params[:question]) - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :question_id => @question.id, :edit => 'true'), notice: I18n.t('org_admin.templates.updated_message') } - else - format.html { render action: "admin_phase" } - end + @phase = @section.phase + if @suggested_answer.update_attributes(params[:suggested_answer]) + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, question_id: @question.id, edit: 'true'), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "admin_phase" end end - #delete a version, sections and guidance - def admin_destroyguidance - @question = Question.find(params[:question_id]) - authorize @question.section.version.phase.dmptemplate - @section = @question.section - @version = @section.version - @phase = @version.phase - @question.destroy - respond_to do |format| - format.html { redirect_to admin_phase_dmptemplate_path(:id => @phase.id, :version_id => @version.id, :section_id => @section.id, :edit => 'true'), notice: I18n.t('org_admin.templates.destroyed_message') } - end - end - + #delete a suggested answer + def admin_destroysuggestedanswer + @suggested_answer = SuggestedAnswer.find(params[:suggested_answer]) + authorize @suggested_answer.question.section.phase.template + @question = @suggested_answer.question + @section = @question.section + @phase = @section.phase + @suggested_answer.destroy + redirect_to admin_phase_template_path(id: @phase.id, section_id: @section.id, edit: 'true'), notice: I18n.t('org_admin.templates.destroyed_message') + end end \ No newline at end of file diff --git a/app/controllers/user_identifiers_controller.rb b/app/controllers/user_identifiers_controller.rb new file mode 100644 index 0000000..040a50b --- /dev/null +++ b/app/controllers/user_identifiers_controller.rb @@ -0,0 +1,25 @@ +class UserIdentifiersController < ApplicationController + + # DELETE /users/identifiers + # --------------------------------------------------------------------- + def destroy + if user_signed_in? then + user = User.find(current_user.id) + identifier = UserIdentifier.find(params[:id]) + + # If the requested identifier belongs to the current user remove it + if user.user_identifiers.include?(identifier) + identifier.destroy! + flash[:notice] = t('identifier_schemes.disconnect_success', + scheme: identifier.identifier_scheme.name) + + else + flash[:notice] = t('identifier_schemes.disconnect_failure', + scheme: identifier.identifier_scheme.name) + end + + redirect_to edit_user_registration_path + end + end + +end \ No newline at end of file diff --git a/app/controllers/users/omniauth_callback_controller.rb b/app/controllers/users/omniauth_callback_controller.rb deleted file mode 100644 index ee19c5c..0000000 --- a/app/controllers/users/omniauth_callback_controller.rb +++ /dev/null @@ -1,53 +0,0 @@ -class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController - - def shibboleth - if user_signed_in? && current_user.shibboleth_id.present? && current_user.shibboleth_id.length > 0 then - flash[:warning] = I18n.t('devise.failure.already_authenticated') - redirect_to root_path - else - auth = request.env['omniauth.auth'] || {} - eppn = auth['extra']['raw_info']['eppn'] - uid = nil - if !eppn.blank? then - uid = eppn - elsif !auth['uid'].blank? then - uid = auth['uid'] - elsif !auth['extra']['raw_info']['targeted-id'].blank? then - uid = auth['extra']['raw_info']['targeted-id'] - end - - if !uid.nil? && !uid.blank? then - s_user = User.where(shibboleth_id: uid).first - # Take out previous record if was not confirmed. - if !s_user.nil? && s_user.confirmed_at.nil? then - sign_out s_user - User.delete(s_user.id) - s_user = nil - end - - # Stops Shibboleth ID being blocked if email incorrectly entered. - if !s_user.nil? && s_user.try(:persisted?) then - flash[:notice] = I18n.t('devise.omniauth_callbacks.success', :kind => 'Shibboleth') - sign_in s_user - redirect_to root_path - else - if user_signed_in? then - current_user.update_attribute('shibboleth_id', uid) - user_id = current_user.id - sign_out current_user - session.delete(:shibboleth_data) - s_user = User.find(user_id) - sign_in s_user - redirect_to edit_user_registration_path - else - session[:shibboleth_data] = request.env['omniauth.auth'] - session[:shibboleth_data][:uid] = uid - redirect_to new_user_registration_url(:nosplash => 'true') - end - end - else - redirect_to root_path - end - end - end -end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb new file mode 100644 index 0000000..9b65b77 --- /dev/null +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -0,0 +1,116 @@ +class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController + ## + # Dynamically build a handler for each omniauth provider + # ------------------------------------------------------------- + IdentifierScheme.where(active: true).each do |scheme| + define_method(scheme.name.downcase) do + handle_omniauth(scheme) + end + end + + ## + # Processes callbacks from an omniauth provider and directs the user to + # the appropriate page: + # Not logged in and uid had no match ---> Sign Up page + # Not logged in and uid had a match ---> Sign In and go to Home Page + # Signed in and uid had no match --> Save the uid and go to the Profile Page + # Signed in and uid had a match --> Go to the Home Page + # + # @scheme [IdentifierScheme] The IdentifierScheme for the provider + # ------------------------------------------------------------- + def handle_omniauth(scheme) + user = User.from_omniauth(request.env["omniauth.auth"].nil? ? request.env : request.env["omniauth.auth"]) + + # If the user isn't logged in + if current_user.nil? + # If the uid didn't have a match in the system send them to register + if user.nil? + session["devise.#{scheme.name.downcase}_data"] = request.env["omniauth.auth"] + flash[:notice] = t('identifier_schemes.new_login_success') + redirect_to new_user_registration_url + + # Otherwise sign them in + else + sign_in_and_redirect user, event: :authentication + set_flash_message(:notice, :success, kind: scheme.name) if is_navigational_format? + end + + # The user is already logged in and just registering the uid with us + else + # If the user could not be found by that uid then attach it to their record + if user.nil? + if UserIdentifier.create(identifier_scheme: scheme, + identifier: request.env["omniauth.auth"].uid, + user: current_user) + + flash[:notice] = t('identifier_schemes.connect_success', scheme: scheme.name) + else + flash[:notice] = t('identifier_schemes.connect_failure', scheme: scheme.name) + end + end + + # Redirect to the User Profile page + redirect_to edit_user_registration_path + end + end + + + # TODO: We should consider rolling the below function up into the + # generic handler above + # ------------------------------------------------------------- + def shibboleth + if user_signed_in? && current_user.shibboleth_id.present? && current_user.shibboleth_id.length > 0 then + flash[:warning] = I18n.t('devise.failure.already_authenticated') + redirect_to root_path + else + auth = request.env['omniauth.auth'] || {} + eppn = auth['extra']['raw_info']['eppn'] + uid = nil + if !eppn.blank? then + uid = eppn + elsif !auth['uid'].blank? then + uid = auth['uid'] + elsif !auth['extra']['raw_info']['targeted-id'].blank? then + uid = auth['extra']['raw_info']['targeted-id'] + end + + if !uid.nil? && !uid.blank? then + s_user = User.where(shibboleth_id: uid).first + # Take out previous record if was not confirmed. + if !s_user.nil? && s_user.confirmed_at.nil? then + sign_out s_user + User.delete(s_user.id) + s_user = nil + end + + # Stops Shibboleth ID being blocked if email incorrectly entered. + if !s_user.nil? && s_user.try(:persisted?) then + flash[:notice] = I18n.t('devise.omniauth_callbacks.success', :kind => 'Shibboleth') + sign_in s_user + redirect_to root_path + else + if user_signed_in? then + current_user.update_attribute('shibboleth_id', uid) + user_id = current_user.id + sign_out current_user + session.delete(:shibboleth_data) + s_user = User.find(user_id) + sign_in s_user + redirect_to edit_user_registration_path + else + session[:shibboleth_data] = request.env['omniauth.auth'] + session[:shibboleth_data][:uid] = uid + redirect_to new_user_registration_url(:nosplash => 'true') + end + end + else + redirect_to root_path + end + end + end + + # ------------------------------------------------------------- + def failure + redirect_to root_path + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 56f99a5..73851a3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,41 +1,26 @@ module ApplicationHelper - def resource_name - :user - end - - def resource - @resource ||= User.new - end - - def devise_mapping - @devise_mapping ||= Devise.mappings[:user] - end - - def javascript(*files) - content_for(:head) { javascript_include_tag(*files) } - end - def link_to_add_object(name, f, association, css_class, i) - new_object = f.object.class.reflect_on_association(association).klass.new - fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| - j = i + 1 - new_object.number = j - render(association.to_s.singularize + "_fields", :f => builder) - end - link_to_function(name, "add_object(this, \"#{association}\", \"#{escape_javascript(fields)}\")", :class => css_class) + def resource_name + :user + end + + # --------------------------------------------------------------------------- + def resource + @resource ||= User.new + end + + # --------------------------------------------------------------------------- + def devise_mapping + @devise_mapping ||= Devise.mappings[:user] end - def link_to_function(name, *args, &block) - html_options = args.extract_options!.symbolize_keys - - function = block_given? ? update_page(&block) : args[0] || '' - onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" - href = html_options[:href] || '#' - - content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) + # --------------------------------------------------------------------------- + def javascript(*files) + content_for(:head) { javascript_include_tag(*files) } end - def hash_to_json_object(obj_name, hash) + # --------------------------------------------------------------------------- + def hash_to_js_json_variable(obj_name, hash) "".html_safe end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 4b326c1..e445a1a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -44,10 +44,18 @@ shared_num = project.project_groups.count - 1 text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") [ "dmp_td_small", text ] + when 'visibility' + ["dmp_td_small", (project.visibility.nil? ? I18n.t("helpers.project.visibilities.labels.organisationally_visible") : I18n.t("helpers.project.visibilities.labels.#{project.visibility}"))] when 'last_edited' [ "dmp_td_small", l(project.latest_update.to_date, formats: :short) ] when 'description' [ "dmp_td_medium", (project.try(col) || "Unknown") ] + when 'non_link_name' + [ "dmp_td_big", project.title ] + when 'template' + ["dmp_td_big", project.dmptemplate.title] + when 'organisation' + ["dmp_td_medium", (project.organisation.nil? ? project.owner.organisation.name : project.organisation.name)] else [ "dmp_td_small", (project.try(col) || "Unknown") ] end diff --git a/app/models/ability.rb b/app/models/ability.rb index e283051..ba5e6fa 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -6,7 +6,7 @@ # Define abilities for the passed in user here. For example: # user ||= User.new # guest user (not logged in) - if user.has_role? constant("user_role_types.super_admin") + if user.has_role? constant("roles.super_admin") can :manage, :all else can :read, :all diff --git a/app/models/answer.rb b/app/models/answer.rb index 02a1533..f27602f 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -1,4 +1,5 @@ class Answer < ActiveRecord::Base + ## # Associations belongs_to :question @@ -7,8 +8,32 @@ has_many :notes, dependent: :destroy has_and_belongs_to_many :question_options, join_table: "answers_question_options" + has_many :notes + ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids , :as => [:default, :admin] + attr_accessible :text, :plan_id, :question_id, :user_id, :question_option_ids, + :question, :user, :plan, :question_options, :notes, :note_ids, + :as => [:default, :admin] + + ## + # Validations + validates :user, :plan, :question, presence: true + + # Make sure there is only one answer per question! + validates :question, uniqueness: {scope: [:plan], + message: I18n.t('helpers.answer.only_one_per_question')} + + # The answer MUST have a text value if the question is NOT option based or a question_option if + # it is option based. + validates :text, presence: true, if: Proc.new{|a| + (a.question.nil? ? false : !a.question.question_format.option_based?) + } + validates :question_options, presence: true, if: Proc.new{|a| + (a.question.nil? ? false : a.question.question_format.option_based?) + } + + # Make sure the plan and question are associated with the same template! + validates :plan, :question, answer_for_correct_template: true end diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 589f096..eb57e5c 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -1,7 +1,8 @@ class ExportedPlan < ActiveRecord::Base include GlobalHelpers - attr_accessible :plan_id, :user_id, :format, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :plan_id, :user_id, :format, :user, :plan, :as => [:default, :admin] #associations between tables belongs_to :plan @@ -10,6 +11,7 @@ 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 :plan, :format, presence: true # Store settings with the exported plan so it can be recreated later # if necessary (otherwise the settings associated with the plan at a @@ -18,10 +20,13 @@ s.key :export, defaults: Settings::Template::DEFAULT_SETTINGS end - # Getters to match Settings::Dmptemplate::VALID_ADMIN_FIELDS +# TODO: Consider removing the accessor methods, they add no value. The view/controller could +# just access the value directly from the project/plan: exported_plan.plan.project.title + + # Getters to match Settings::Template::VALID_ADMIN_FIELDS def project_name name = self.plan.project.title - name += " - #{self.plan.title}" if self.plan.project.dmptemplate.phases.count > 1 + name += " - #{self.plan.title}" if self.plan.project.template.phases.count > 1 name end @@ -46,7 +51,7 @@ end def funder - org = self.plan.project.dmptemplate.try(:organisation) + org = self.plan.project.template.try(:organisation) org.name if org.present? && org.organisation_type.try(:name) == constant("organisation_types.funder") end @@ -54,6 +59,16 @@ plan.project.organisation.try(:name) end + def orcid + scheme = IdentifierScheme.find_by(name: 'orcid') + if self.user.nil? + '' + else + orcid = self.user.user_identifiers.where(identifier_scheme: scheme).first + (orcid.nil? ? '' : orcid.identifier) + end + end + # sections taken from fields settings def sections sections = self.plan.sections @@ -92,18 +107,18 @@ def as_txt output = "#{self.plan.project.title}\n\n#{self.plan.version.phase.title}\n" - - -puts "SETTINGS: #{self.plan.inspect}" - - output += "\nDetails:\n#{self.plan.settings[:export][:fields][:admin].collect{|f| f.to_s}.join('\n')}\n" + output += "\nDetails:\n\n" + attrs = self.plan.settings(:export)[:value]['fields'][:admin].collect{|f| f.to_s} + attrs.each do |attr| + output += attr + ": " + self.send(attr) + "\n" + end self.sections.each do |section| output += "\n#{section.title}\n" self.questions_for_section(section).each do |question| qtext = sanitize_text( question.text.gsub(/
  • /, ' * ') ) - output += "\n#{qtext}\n" + output += "\n* #{qtext}" answer = self.plan.answer(question.id, false) if answer.nil? || answer.text.nil? then diff --git a/app/models/file_type.rb b/app/models/file_type.rb deleted file mode 100644 index 7c836dc..0000000 --- a/app/models/file_type.rb +++ /dev/null @@ -1,3 +0,0 @@ -class FileType < ActiveRecord::Base - #attr_accessible :name, :icon_location, :icon_name, :icon_size -end diff --git a/app/models/file_upload.rb b/app/models/file_upload.rb deleted file mode 100644 index eef1ca3..0000000 --- a/app/models/file_upload.rb +++ /dev/null @@ -1,5 +0,0 @@ -class FileUpload < ActiveRecord::Base - ## - # Associations - belongs_to :file_type -end diff --git a/app/models/guidance.rb b/app/models/guidance.rb index b6048f4..31f9012 100644 --- a/app/models/guidance.rb +++ b/app/models/guidance.rb @@ -13,10 +13,8 @@ ## # Associations belongs_to :guidance_group - belongs_to :question +# belongs_to :question has_and_belongs_to_many :themes, join_table: "themes_in_guidance" - # depricated, but required for migration "single_group_for_guidance" - has_and_belongs_to_many :guidance_groups, join_table: "guidance_in_group" @@ -27,15 +25,20 @@ + validates :text, presence: true + + ## # Determine if a guidance is in a group which belongs to a specified organisation # # @param org_id [Integer] the integer id for an organisation # @return [Boolean] true if this guidance is in a group belonging to the specified organisation, false otherwise def in_group_belonging_to?(org_id) - if guidance_group.org_id == org_id - return true - end + unless guidance_group.nil? + if guidance_group.org.id == org_id + return true + end + end return false end @@ -44,7 +47,7 @@ # # @param org_id [Integer] the integer id for an organisation # @return [Array] list of guidance - def self.by_organisation(org_id) + def self.by_org(org_id) org_guidance = [] # TODO: re-write below querry when guidance_in_group removed from model Org.find_by(id: org_id).guidance_groups.each do |group| @@ -83,27 +86,24 @@ guidance = Guidance.find_by(id: id) viewable = false - # guidances may belong to many guidance groups, so we check the above case for each - guidance.guidance_groups.each do |guidance_group| - - # guidances are viewable if they are owned by any of the user's organisations - user.org do |org| - if guidance_group.org.id == org.id + unless guidance.nil? + unless guidance.guidance_group.nil? + # guidances are viewable if they are owned by any of the user's organisations + if guidance.guidance_group.org == user.org + viewable = true + end + # guidance groups are viewable if they are owned by the Managing Curation Center + if Org.managing_orgs.include?(guidance.guidance_group.org) + viewable = true + end + + # guidance groups are viewable if they are owned by a funder + if Org.funders.include?(guidance.guidance_group.org) viewable = true end end - - # guidance groups are viewable if they are owned by the Managing Curation Center - if guidance_group.organisation.id == Org.find_by( name: GlobalHelpers.constant("organisation_types.managing_organisation")).id - viewable = true - end - - # guidance groups are viewable if they are owned by a funder - if guidance_group.organisation.organisation_type == OrganisationType.find_by( name: GlobalHelpers.constant("organisation_types.funder")) - viewable = true - end end - + return viewable end @@ -117,22 +117,20 @@ # @param user [User] a user object # @return [Array] a list of all "viewable" guidances to a user def self.all_viewable(user) - managing_groups = (Org.find_by name: GlobalHelpers.constant("organisation_types.managing_organisation")).guidance_groups + managing_groups = Org.managing_orgs.collect{|o| o.guidance_groups} # find all groups owned by a Funder organisation funder_groups = [] - funders = OrganisationType.find_by( name: GlobalHelpers.constant("organisation_types.funder")) - funders.organisations.each do |funder| + funders = Org.funders + funders.each do |funder| funder_groups += funder.guidance_groups end # find all groups owned by any of the user's organisations - organisation_groups = [] - user.organisations.each do |organisation| - organisation_groups += organisation.guidance_groups - end + organisation_groups = user.org.guidance_groups + # find all guidances belonging to any of the viewable groups all_viewable_guidances = [] all_viewable_groups = managing_groups + funder_groups + organisation_groups - all_viewable_groups.each do |group| + all_viewable_groups.flatten.each do |group| all_viewable_guidances += group.guidances end # pass the list of viewable guidances to the view diff --git a/app/models/guidance_group.rb b/app/models/guidance_group.rb index e56b1cc..71535c3 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -5,15 +5,15 @@ belongs_to :org has_many :guidances # depricated but needed for migration "single_group_for_guidance" - has_and_belongs_to_many :guidances, join_table: "guidance_in_group" + # has_and_belongs_to_many :guidances, join_table: "guidance_in_group" ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :organisation_id, :name, :optional_subset, :published, :as => [:default, :admin] - attr_accessible :dmptemplate_ids, :as => [:default, :admin] + attr_accessible :org_id, :name, :optional_subset, :published, :org, :guidances, + :as => [:default, :admin] - + validates :name, :org, presence: true # EVALUATE CLASS AND INSTANCE METHODS BELOW @@ -23,15 +23,7 @@ - - - ## - # Converts a guidance group to a string containing the display name - # - # @return [String] the name of the organisation, with or without the name of the guidance group - def to_s - "#{display_name}" - end + ## # Converts the current guidance group to a string containing the display name. @@ -53,14 +45,20 @@ # # @param excluded_orgs [Array] a list of organisations to exclude in the result # @return [Array] a list of guidance groups - def self.guidance_groups_excluding(excluded_orgs) - excluded_org_ids = Array.new - excluded_orgs.each do |org| - excluded_org_ids << org.id - end - return_orgs = GuidanceGroup.where("organisation_id NOT IN (?)", excluded_org_ids) - return return_orgs - end + def self.guidance_groups_excluding(excluded_orgs) + excluded_org_ids = Array.new + + if excluded_orgs.is_a?(Array) + excluded_orgs.each do |org| + excluded_org_ids << org.id + end + else + excluded_org_ids << excluded_orgs + end + + return_orgs = GuidanceGroup.where("org_id NOT IN (?)", excluded_org_ids) + return return_orgs + end ## # Returns whether or not a given user can view a given guidance group @@ -77,17 +75,17 @@ viewable = false # groups are viewable if they are owned by any of the user's organisations - if guidance_group.organisation == user.organisation + if guidance_group.org == user.org viewable = true end # groups are viewable if they are owned by the managing curation center Org.where( name: GlobalHelpers.constant("organisation_types.managing_organisation")).find_each do |managing_group| - if guidance_group.organisation.id == managing_group.id + if guidance_group.org.id == managing_group.id viewable = true end end # groups are viewable if they are owned by a funder - if guidance_group.organisation.organisation_type == OrganisationType.find_by( name: GlobalHelpers.constant("organisation_types.funder")) + if guidance_group.org.org_type == 2 viewable = true end @@ -106,21 +104,21 @@ def self.all_viewable(user) # first find all groups owned by the Managing Curation Center managing_org_groups = [] - Org.where( name: GlobalHelpers.constant("organisation_types.managing_organisation")).find_each do |managing_org| + Org.where(name: GlobalHelpers.constant("organisation_types.managing_organisation")).find_each do |managing_org| managing_org_groups = managing_org_groups + managing_org.guidance_groups end # find all groups owned by a Funder organisation funder_groups = [] - funders = OrganisationType.find_by( name: GlobalHelpers.constant("organisation_types.funder")) - funders.organisations.each do |funder| + funders = Org.where(org_type: 2) + funders.each do |funder| funder_groups = funder_groups + funder.guidance_groups end - organisation_groups = [user.organisation.guidance_groups] + organisation_groups = [user.org.guidance_groups] # pass this organisation guidance groups to the view with respond_with @all_viewable_groups all_viewable_groups = managing_org_groups + funder_groups + organisation_groups - all_viewable_groups = all_viewable_groups.uniq{|x| x.id} + all_viewable_groups = all_viewable_groups.flatten.uniq{|x| x.id} return all_viewable_groups end end diff --git a/app/models/identifier_scheme.rb b/app/models/identifier_scheme.rb new file mode 100644 index 0000000..45b8922 --- /dev/null +++ b/app/models/identifier_scheme.rb @@ -0,0 +1,6 @@ +class IdentifierScheme < ActiveRecord::Base + has_many :user_identifiers + has_many :users, through: :user_identifiers + + validates :name, uniqueness: true, presence: true +end \ No newline at end of file diff --git a/app/models/language.rb b/app/models/language.rb index a2bdaa0..0bb5a35 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -2,7 +2,8 @@ ## # Associations has_many :users - + has_many :orgs + ## # Validations validates :abbreviation, presence: true, uniqueness: true diff --git a/app/models/new_plan.rb b/app/models/new_plan.rb new file mode 100644 index 0000000..1dac7cd --- /dev/null +++ b/app/models/new_plan.rb @@ -0,0 +1,5 @@ +class NewPlan < ActiveRecord::Base + belongs_to :template + has_many :roles + has_many :users, through: :roles +end diff --git a/app/models/note.rb b/app/models/note.rb index d314d19..74b3078 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -7,6 +7,8 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :question_id, :text, :user_id, :archived, :plan_id, :archived_by, :as => [:default, :admin] - + attr_accessible :text, :user_id, :answer_id, :archived, :archived_by, + :answer, :user, :as => [:default, :admin] + + validates :text, :answer, :user, presence: true end diff --git a/app/models/org.rb b/app/models/org.rb index 4ede001..1e6764d 100644 --- a/app/models/org.rb +++ b/app/models/org.rb @@ -11,7 +11,8 @@ has_many :templates has_many :users has_many :suggested_answers - has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions" + + has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions", unique: true ## # Possibly needed for active_admin @@ -19,7 +20,8 @@ attr_accessible :abbreviation, :banner_text, :logo, :remove_logo, :logo_file_name, :name, :target_url, :organisation_type_id, :wayfless_entity, :parent_id, :sort_name, - :token_permission_type_ids, :language_id, :contact_email + :token_permission_type_ids, :language_id, :contact_email, + :language, :org_type, :region, :token_permission_types ## # Validators @@ -44,6 +46,9 @@ 6 => :school, column: 'org_type' + # Predefined queries for retrieving the managain organisation and funders + scope :managing_orgs, -> { where(name: GlobalHelpers.constant("organisation_types.managing_organisation")) } + scope :funders, -> { where(org_type: 2) } # EVALUATE CLASS AND INSTANCE METHODS BELOW @@ -190,7 +195,7 @@ # # @return [Array] published dmptemplates def published_templates - return dmptemplates.where("published = ?", true) + return templates.where("published = ?", true) end def check_api_credentials diff --git a/app/models/perm.rb b/app/models/perm.rb index 7d17efb..114c0f0 100644 --- a/app/models/perm.rb +++ b/app/models/perm.rb @@ -7,4 +7,6 @@ # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :name, :as => [:default, :admin] + + validates :name, presence: true, uniqueness: true end diff --git a/app/models/phase.rb b/app/models/phase.rb index a9814b9..49029f8 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -8,20 +8,22 @@ ## # Associations - belongs_to :template, dependent: :destroy + belongs_to :template has_many :sections, dependent: :destroy has_many :questions, :through => :sections, dependent: :destroy ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :description, :number, :title, :dmptemplate_id, :as => [:default, :admin] + attr_accessible :description, :number, :title, :template_id, + :template, :sections, :modifiable, :as => [:default, :admin] ## # sluggable title friendly_id :title, use: [:slugged, :history, :finders] + validates :title, :number, :template, presence: true @@ -40,54 +42,48 @@ # returns the title of the phase # # @return [String] the title of the phase - def to_s - "#{title}" - end + def to_s + "#{title}" + end +# TODO: This function does not belong here anymore. It may be useless now. ## - # returns the most_recent version of this phase - # - # @return [Version] the most recent version of this phase - def latest_version - return versions.order("number DESC").last - end - - ## - # returns either the latest published version of this phase + # returns either the latest published version of this phase # also serves to verify if this phase has any published versions as returns nil # if there are no published versions # # @return [Version, nil] - def latest_published_version - pub_vers = versions.where('published = ?', true).order('updated_at DESC') - if pub_vers.any?() then - return pub_vers.first - else - return nil - end - end +# def latest_published_version +# pub_vers = versions.where('published = ?', true).order('updated_at DESC') +# if pub_vers.any?() then +# return pub_vers.first +# else +# return nil +# end +# end +# TODO: reevaluate this method. It seems like the 1st query is unecessary ## - # verify if a phase has a published version or a version with one or more sections + # verify if a phase has a published version or a version with one or more sections # # @return [Boolean] - def has_sections - versions = self.versions.where('published = ?', true).order('updated_at DESC') - if versions.any? then - version = versions.first - if !version.sections.empty? then - has_section = true - else - has_section = false - end - else - version = self.versions.order('updated_at DESC').first - if !version.sections.empty? then - has_section = true - else - has_section = false - end - end - return has_section - end + def has_sections + versions = self.versions.where('published = ?', true).order('updated_at DESC') + if versions.any? then + version = versions.first + if !version.sections.empty? then + has_section = true + else + has_section = false + end + else + version = self.versions.order('updated_at DESC').first + if !version.sections.empty? then + has_section = true + else + has_section = false + end + end + return has_section + end end diff --git a/app/models/plan.rb b/app/models/plan.rb index ca035d5..b75a662 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -13,29 +13,39 @@ has_many :guidance_groups, through: :plan_guidance_groups accepts_nested_attributes_for :template + has_many :exported_plans ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :title, :identifier, :grant_number, - :principal_investigator, :principal_investigator_identifier, - :data_contact, :description + attr_accessible :locked, :project_id, :version_id, :version, :plan_sections, + :exported_plans, :project, :title, :template, :grant_number, + :identifier, :principal_investigator, :principal_investigator_identifier, + :description, :data_contact, :funder_name, :visibility, :exported_plans, + :roles, :users, :as => [:default, :admin] + accepts_nested_attributes_for :roles + + # public is a Ruby keyword so using publicly + enum visibility: [:organisationally_visible, :publicly_visible, :is_test, :privately_visible] + + validates :template, :title, :users, presence: true + ## # Constants - A4_PAGE_HEIGHT = 297 #(in mm) - A4_PAGE_WIDTH = 210 #(in mm) - ROUNDING = 5 #round estimate up to nearest 5% - 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 + A4_PAGE_HEIGHT = 297 #(in mm) + A4_PAGE_WIDTH = 210 #(in mm) + ROUNDING = 5 #round estimate up to nearest 5% + 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 ## # Settings for the template - has_settings :export, class_name: 'Settings::Template' do |s| - s.key :export, defaults: Settings::Template::DEFAULT_SETTINGS - end - alias_method :super_settings, :settings + has_settings :export, class_name: 'Settings::Template' do |s| + s.key :export, defaults: Settings::Template::DEFAULT_SETTINGS + end + alias_method :super_settings, :settings - + def new if user_signed_in? then @@ -60,17 +70,18 @@ ## - # Proxy through to the template settings (or defaults if this plan doesn't have - # an associated template) if there are no settings stored for this plan. - # `key` is required by rails-settings, so it's required here, too. + # Proxy through to the template settings (or defaults if this plan doesn't have + # an associated template) if there are no settings stored for this plan. + # `key` is required by rails-settings, so it's required here, too. # # @param key [Key] a key required by rails # @return [Settings] settings for this plan's template - def settings(key) - self_settings = self.super_settings(key) - return self_settings if self_settings.value? - self.dmptemplate.settings(key) - end + def settings(key) + self_settings = self.super_settings(key) + return self_settings if self_settings.value? +# self.dmptemplate.settings(key) + self.template.settings(key) unless self.template.nil? + end ## # returns the template for this plan, or generates an empty template and returns that @@ -81,25 +92,7 @@ self.template end -# DON'T THINK WE NEED THIS ANYMORE - DELETE IF YOU ARE READING THIS -# AND IT'S WORKING -# -# ## -# # returns the title for this project as defined by the settings -# # -# # @return [String] the title for this project -# def title -# logger.debug "Title in settings: #{self.settings(:export).title}" -# if self.settings(:export).title == "" -# if !self.version.nil? && !self.version.phase.nil? && !self.version.phase.title? then -# return self.version.phase.title -# else -# return I18n.t('tool_title2') -# end -# else -# return self.settings(:export).title -# end -# end + ## # returns the most recent answer to the given question id @@ -131,15 +124,6 @@ # returns all of the sections for this version of the plan, and for the project's organisation # # @return [Array
    ,nil] either a list of sections, or nil if none were found -# def sections -# unless plan.organisation.nil? then -# sections = version.global_sections + project.organisation.all_sections(version_id) -# else -# sections = version.global_sections -# end -# return sections.uniq.sort_by &:number -# end - def set_possible_guidance_groups # find all the themes in this plan @@ -219,27 +203,27 @@ # @param theme [Theme] the theme object for the GuidanceGroup # @param guidance [Guidance] the guidance object to be appended to the correct section of the array # @return [{GuidanceGroup => {Theme => Array}}] the updated object which was passed in - def add_guidance_to_array(guidance_array, guidance_group, theme, guidance) - if guidance_array[guidance_group].nil? then - guidance_array[guidance_group] = {} - end - if theme.nil? then - if guidance_array[guidance_group]["no_theme"].nil? then - guidance_array[guidance_group]["no_theme"] = [] - end - if !guidance_array[guidance_group]["no_theme"].include?(guidance) then - guidance_array[guidance_group]["no_theme"].push(guidance) - end - else - if guidance_array[guidance_group][theme].nil? then - guidance_array[guidance_group][theme] = [] - end - if !guidance_array[guidance_group][theme].include?(guidance) then - guidance_array[guidance_group][theme].push(guidance) - end - end + def add_guidance_to_array(guidance_array, guidance_group, theme, guidance) + if guidance_array[guidance_group].nil? then + guidance_array[guidance_group] = {} + end + if theme.nil? then + if guidance_array[guidance_group]["no_theme"].nil? then + guidance_array[guidance_group]["no_theme"] = [] + end + if !guidance_array[guidance_group]["no_theme"].include?(guidance) then + guidance_array[guidance_group]["no_theme"].push(guidance) + end + else + if guidance_array[guidance_group][theme].nil? then + guidance_array[guidance_group][theme] = [] + end + if !guidance_array[guidance_group][theme].include?(guidance) then + guidance_array[guidance_group][theme].push(guidance) + end + end return guidance_array - end + end ## # determines if the plan is editable by the specified user @@ -253,12 +237,14 @@ ## # determines if the plan is readable by the specified user + # TODO: introduce explicit readable rather than implicit + # currently role with no flags = readable # # @param user_id [Integer] the id for a user # @return [Boolean] true if the user can read the plan def readable_by?(user_id) role = roles.where(user_id: user_id).first - return role.present? && role.editor? + return role.present? end ## @@ -315,27 +301,27 @@ "answered_by" => answer.user.name } q_format = q.question_format - status["num_answers"] += 1 if (q_format.title == I18n.t("helpers.checkbox") || q_format.title == I18n.t("helpers.multi_select_box") || + status["num_answers"] += 1 if (q_format.title == I18n.t("helpers.checkbox") || q_format.title == I18n.t("helpers.multi_select_box") || q_format.title == I18n.t("helpers.radio_buttons") || q_format.title == I18n.t("helpers.dropdown")) || answer.text.present? - section_answers += 1 - #TODO: include selected options in space estimate - else - status["questions"][q.id] = { - "answer_id" => nil, - "answer_created_at" => nil, - "answer_text" => nil, - "answer_option_ids" => nil, - "answered_by" => nil - } - end - status["sections"][s.id]["num_questions"] = section_questions - status["sections"][s.id]["num_answers"] = section_answers - end - end + section_answers += 1 + #TODO: include selected options in space estimate + else + status["questions"][q.id] = { + "answer_id" => nil, + "answer_created_at" => nil, + "answer_text" => nil, + "answer_option_ids" => nil, + "answered_by" => nil + } + end + status["sections"][s.id]["num_questions"] = section_questions + status["sections"][s.id]["num_answers"] = section_answers + end + end - status['space_used'] = estimate_space_used(space_used) - return status - end + status['space_used'] = estimate_space_used(space_used) + return status + end ## @@ -344,35 +330,35 @@ # section: title, question text for each question, answer type and answer value # # @return [Details] - def details - details = { - "project_title" => project.title, - "phase_title" => version.phase.title, - "sections" => {} - } - sections.sort_by(&:"number").each do |s| - details["sections"][s.number] = {} - details["sections"][s.number]["title"] = s.title - details["sections"][s.number]["questions"] = {} - s.questions.order("number").each do |q| - details["sections"][s.number]["questions"][q.number] = {} - details["sections"][s.number]["questions"][q.number]["question_text"] = q.text - answer = answer(q.id, false) - if ! answer.nil? then + def details + details = { + "project_title" => project.title, + "phase_title" => version.phase.title, + "sections" => {} + } + sections.sort_by(&:"number").each do |s| + details["sections"][s.number] = {} + details["sections"][s.number]["title"] = s.title + details["sections"][s.number]["questions"] = {} + s.questions.order("number").each do |q| + details["sections"][s.number]["questions"][q.number] = {} + details["sections"][s.number]["questions"][q.number]["question_text"] = q.text + answer = answer(q.id, false) + if ! answer.nil? then q_format = q.question_format - if (q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || + if (q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown")) then - details["sections"][s.number]["questions"][q.number]["selections"] = {} - answer.options.each do |o| - details["sections"][s.number]["questions"][q.number]["selections"][o.number] = o.text - end - end - details["sections"][s.number]["questions"][q.number]["answer_text"] = answer.text - end - end - end - return details - end + details["sections"][s.number]["questions"][q.number]["selections"] = {} + answer.options.each do |o| + details["sections"][s.number]["questions"][q.number]["selections"][o.number] = o.text + end + end + details["sections"][s.number]["questions"][q.number]["answer_text"] = answer.text + end + end + end + return details + end ## # determines wether or not a specified section of a plan is locked to a specified user and returns a status hash @@ -380,55 +366,55 @@ # @param section_id [Integer] the setion to determine if locked # @param user_id [Integer] the user to determine if locked for # @return [Hash{String => Hash{String => Boolean, nil, String, Integer}}] - def locked(section_id, user_id) - plan_section = plan_sections.where("section_id = ? AND user_id != ? AND release_time > ?", section_id, user_id, Time.now).last - if plan_section.nil? then - status = { - "locked" => false, - "locked_by" => nil, - "timestamp" => nil, - "id" => nil - } - else - status = { - "locked" => true, - "locked_by" => plan_section.user.name, - "timestamp" => plan_section.updated_at, - "id" => plan_section.id - } - end - end + def locked(section_id, user_id) + plan_section = plan_sections.where("section_id = ? AND user_id != ? AND release_time > ?", section_id, user_id, Time.now).last + if plan_section.nil? then + status = { + "locked" => false, + "locked_by" => nil, + "timestamp" => nil, + "id" => nil + } + else + status = { + "locked" => true, + "locked_by" => plan_section.user.name, + "timestamp" => plan_section.updated_at, + "id" => plan_section.id + } + end + end ## # for each section, lock the section with the given user_id # # @param user_id [Integer] the id for the user who can use the sections - def lock_all_sections(user_id) - sections.each do |s| - lock_section(s.id, user_id, 1800) - end - end + def lock_all_sections(user_id) + sections.each do |s| + lock_section(s.id, user_id, 1800) + end + end ## # for each section, unlock the section # # @param user_id [Integer] the id for the user to unlock the sections for - def unlock_all_sections(user_id) - plan_sections.where(:user_id => user_id).order("created_at DESC").each do |lock| - lock.delete - end - end + def unlock_all_sections(user_id) + plan_sections.where(:user_id => user_id).order("created_at DESC").each do |lock| + lock.delete + end + end ## # for each section, unlock the section # Not sure how this is different from unlock_all_sections # # @param user_id [Integer] - def delete_recent_locks(user_id) - plan_sections.where(:user_id => user_id).each do |lock| - lock.delete - end - end + def delete_recent_locks(user_id) + plan_sections.where(:user_id => user_id).each do |lock| + lock.delete + end + end ## # Locks the specified section to only be used by the specified user, for the number of secconds specified @@ -437,23 +423,23 @@ # @param user_id [Integer] the id of the user who can use the section # @param release_time [Integer] the number of secconds the section will be locked for, defaults to 60 # @return [Boolean] wether or not the section was locked - def lock_section(section_id, user_id, release_time = 60) - status = locked(section_id, user_id) - if ! status["locked"] then - plan_section = PlanSection.new - plan_section.plan_id = id - plan_section.section_id = section_id - plan_section.release_time = Time.now + release_time.seconds - plan_section.user_id = user_id - plan_section.save - elsif status["current_user"] then - plan_section = PlanSection.find(status["id"]) - plan_section.release_time = Time.now + release_time.seconds - plan_section.save - else - return false - end - end + def lock_section(section_id, user_id, release_time = 60) + status = locked(section_id, user_id) + if ! status["locked"] then + plan_section = PlanSection.new + plan_section.plan_id = id + plan_section.section_id = section_id + plan_section.release_time = Time.now + release_time.seconds + plan_section.user_id = user_id + plan_section.save + elsif status["current_user"] then + plan_section = PlanSection.find(status["id"]) + plan_section.release_time = Time.now + release_time.seconds + plan_section.save + else + return false + end + end ## # unlocks the specified section for the specified user @@ -461,28 +447,28 @@ # @param section_id [Integer] the id for the section to be unlocked # @param user_id [Integer] the id for the user for whom the section was previously locked # @return [Boolean] wether or not the lock was removed - def unlock_section(section_id, user_id) - plan_sections.where(:section_id => section_id, :user_id => user_id).order("created_at DESC").each do |lock| - lock.delete - end - end + def unlock_section(section_id, user_id) + plan_sections.where(:section_id => section_id, :user_id => user_id).order("created_at DESC").each do |lock| + lock.delete + end + end ## # returns the time of either the latest answer to any question, or the latest update to the model # # @return [DateTime] the time at which the plan was last changed - def latest_update - if answers.any? then - last_answered = answers.order("updated_at DESC").first.updated_at - if last_answered > updated_at then - return last_answered - else - return updated_at - end - else - return updated_at - end - end + def latest_update + if answers.any? then + last_answered = answers.order("updated_at DESC").first.updated_at + if last_answered > updated_at then + return last_answered + else + return updated_at + end + else + return updated_at + end + end ## # returns an array of hashes. Each hash contains the question's id, the answer_id, @@ -490,34 +476,34 @@ # # @param section_id [Integer] the section to find answers of # @return [Array nil,String,Integer,DateTime}] - def section_answers(section_id) - section = Section.find(section_id) - section_questions = Array.new - counter = 0 - section.questions.each do |q| - section_questions[counter] = {} - section_questions[counter]["id"] = q.id - #section_questions[counter]["multiple_choice"] = q.multiple_choice - q_answer = answer(q.id, false) - if q_answer.nil? then - section_questions[counter]["answer_id"] = nil - if q.suggested_answers.find_by_organisation_id(project.organisation_id).nil? then - section_questions[counter]["answer_text"] = "" - else - section_questions[counter]["answer_text"] = q.default_value - end - section_questions[counter]["answer_timestamp"] = nil - section_questions[counter]["answer_options"] = Array.new - else - section_questions[counter]["answer_id"] = q_answer.id - section_questions[counter]["answer_text"] = q_answer.text - section_questions[counter]["answer_timestamp"] = q_answer.created_at - section_questions[counter]["answer_options"] = q_answer.options.pluck(:id) - end - counter = counter + 1 - end - return section_questions - end + def section_answers(section_id) + section = Section.find(section_id) + section_questions = Array.new + counter = 0 + section.questions.each do |q| + section_questions[counter] = {} + section_questions[counter]["id"] = q.id + #section_questions[counter]["multiple_choice"] = q.multiple_choice + q_answer = answer(q.id, false) + if q_answer.nil? then + section_questions[counter]["answer_id"] = nil + if q.suggested_answers.find_by_organisation_id(project.organisation_id).nil? then + section_questions[counter]["answer_text"] = "" + else + section_questions[counter]["answer_text"] = q.default_value + end + section_questions[counter]["answer_timestamp"] = nil + section_questions[counter]["answer_options"] = Array.new + else + section_questions[counter]["answer_id"] = q_answer.id + section_questions[counter]["answer_text"] = q_answer.text + section_questions[counter]["answer_timestamp"] = q_answer.created_at + section_questions[counter]["answer_options"] = q_answer.options.pluck(:id) + end + counter = counter + 1 + end + return section_questions + end @@ -530,6 +516,62 @@ Rails.logger.debug "RAY: assign_creator #{ user_id } to plan #{ self.inspect }" add_user(user_id, true, true, true) end + + + + + ## + # Based on the height of the text gathered so far and the available vertical + # space of the pdf, estimate a percentage of how much space has been used. + # This is highly dependent on the layout in the pdf. A more accurate approach + # would be to render the pdf and check how much space had been used, but that + # could be very slow. + # NOTE: This is only an estimate, rounded up to the nearest 5%; it is intended + # for guidance when editing plan data, not to be 100% accurate. + # + # @param used_height [Integer] an estimate of the height used so far + # @return [Integer] the estimate of space used of an A4 portrain + def estimate_space_used(used_height) + @formatting ||= self.settings(:export).formatting + + return 0 unless @formatting[:font_size] > 0 + + margin_height = @formatting[:margin][:top].to_i + @formatting[:margin][:bottom].to_i + page_height = A4_PAGE_HEIGHT - margin_height # 297mm for A4 portrait + available_height = page_height * self.dmptemplate.settings(:export).max_pages + + percentage = (used_height / available_height) * 100 + (percentage / ROUNDING).ceil * ROUNDING # round up to nearest five + end + + ## + # Take a guess at the vertical height (in mm) of the given text based on the + # font-size and left/right margins stored in the plan's settings. + # This assumes a fixed-width for each glyph, which is obviously + # incorrect for the font-face choices available; the idea is that + # they'll hopefully average out to that in the long-run. + # Allows for hinting different font sizes (offset from base via font_size_inc) + # and vertical margins (i.e. for heading text) + # + # @param text [String] the text to estimate size of + # @param font_size_inc [Integer] the size of the font of the text, defaults to 0 + # @param vertical_margin [Integer] the top margin above the text, defaults to 0 + def height_of_text(text, font_size_inc = 0, vertical_margin = 0) + @formatting ||= self.settings(:export).formatting + @margin_width ||= @formatting[:margin][:left].to_i + @formatting[:margin][:right].to_i + @base_font_size ||= @formatting[:font_size] + + return 0 unless @base_font_size > 0 + + font_height = FONT_HEIGHT_CONVERSION_FACTOR * (@base_font_size + font_size_inc) + font_width = font_height * FONT_WIDTH_HEIGHT_RATIO # Assume glyph width averages at 2/5s the height + leading = font_height / 2 + + chars_in_line = (A4_PAGE_WIDTH - @margin_width) / font_width # 210mm for A4 portrait + num_lines = (text.length / chars_in_line).ceil + + (num_lines * font_height) + vertical_margin + leading + end diff --git a/app/models/question.rb b/app/models/question.rb index 8b162a9..5493b79 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -20,8 +20,14 @@ ## # 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,:options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] + attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, + :suggested_answer, :text, :section_id, :question_format_id, + :question_options_attributes, :suggested_answers_attributes, + :option_comment_display, :theme_ids, :section, :question_format, + :question_options, :suggested_answers, :answers, :themes, + :modifiable, :option_comment_display, :as => [:default, :admin] + validates :text, :section, :number, presence: true # EVALUATE CLASS AND INSTANCE METHODS BELOW @@ -38,80 +44,35 @@ "#{text}" end - def select_text - cleantext = text.gsub(/<[^<]+>/, '') - if cleantext.length > 120 - cleantext = cleantext.slice(0,120) - end - cleantext - end +# TODO: Commented this amoeba cloning gem definition out to see if its even used. The +# amoeba documentations uses [object].amoeba_dup to clone the object, but that +# command does not exist in the codebase - amoeba do - include_association :options - include_association :suggested_answers - clone [:themes] - end - - #def question_type? - # type_label = {} - # if self.is_text_field? - # type_label = 'Text field' - # elsif self.multiple_choice? - # type_label = 'Multiple choice' - # else - # type_label = 'Text area' - # end - # return type_label - #end +# amoeba do +# include_association :options +# include_association :suggested_answers +# clone [:themes] +# end ## - # for each question theme, appends them separated by comas - # shouldnt have a ? after the method name + # guidance for org # - # @return [Hash{String=> String}] - def question_themes? - themes_label = {} - i = 1 - themes_quest = self.themes - - themes_quest.each do |tt| - themes_label = tt.title - - if themes_quest.count > i then - themes_label += ',' - i +=1 - end - end - - return themes_label - end - - ## - # guidance for question in the org admin - # - # @param question [Question] the question to find guidance for - # @param org_admin [Organisation] the organisation to find guidance for + # @param org [Org] the org to find guidance for # @return [Hash{String => String}] - def guidance_for_question(question, org_admin) - # pulls together guidance from various sources for question - guidances = {} - theme_ids = question.theme_ids - - GuidanceGroup.where("organisation_id = ?", org_admin.id).each do |group| - group.guidances.each do |g| - g.themes.where("id IN (?)", theme_ids).each do |gg| - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g - end - end + def guidance_for_org(org) + # pulls together guidance from various sources for question + guidances = {} + theme_ids = themes.collect{|t| t.id} + if theme_ids.present? + GuidanceGroup.where(org_id: org.id).each do |group| + group.guidances.each do |g| + g.themes.where("id IN (?)", theme_ids).each do |gg| + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g + end end - # Guidance link to directly to a question - question.guidances.each do |g_by_q| - g_by_q.guidance_groups.each do |group| - if group.organisation == org_admin - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase')] = g_by_q - end - end - end + end + end + return guidances end @@ -121,7 +82,7 @@ # @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_organisation_id(org_id) + suggested_answer = suggested_answers.find_by(org_id: org_id) return suggested_answer end diff --git a/app/models/question_format.rb b/app/models/question_format.rb index 29ad3b8..7f1a900 100644 --- a/app/models/question_format.rb +++ b/app/models/question_format.rb @@ -3,11 +3,13 @@ ## # Associations has_many :questions - + + validates :title, presence: true, uniqueness: true + ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :title, :description, :as => [:default, :admin] + attr_accessible :title, :description, :option_based, :questions, :as => [:default, :admin] # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/question_option.rb b/app/models/question_option.rb index b16b0d9..1a079d0 100644 --- a/app/models/question_option.rb +++ b/app/models/question_option.rb @@ -7,5 +7,8 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :text, :question_id, :is_default, :number, :as => [:default, :admin] + attr_accessible :text, :question_id, :is_default, :number, :question, + :as => [:default, :admin] + + validates :text, :question, :number, presence: true end diff --git a/app/models/region.rb b/app/models/region.rb index 8147fed..2c57e79 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -1,3 +1,8 @@ class Region < ActiveRecord::Base - + has_many :sub_regions, class_name: 'Region', foreign_key: 'super_region_id' + + belongs_to :super_region, class_name: 'Region' + + validates :name, presence: true, uniqueness: true + validates :abbreviation, uniqueness: true, allow_nil: true end \ No newline at end of file diff --git a/app/models/region_group.rb b/app/models/region_group.rb deleted file mode 100644 index 8f83a83..0000000 --- a/app/models/region_group.rb +++ /dev/null @@ -1,3 +0,0 @@ -class RegionGroup < ActiveRecord::Base - -end \ No newline at end of file diff --git a/app/models/section.rb b/app/models/section.rb index 35d4aef..60fd094 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -5,14 +5,15 @@ belongs_to :phase belongs_to :organisation has_many :questions, :dependent => :destroy - has_many :plan_sections, :dependent => :destroy #Link the data accepts_nested_attributes_for :questions, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true # accepts_nested_attributes_for :version - attr_accessible :organisation_id, :description, :number, :title, :version_id , :published, :questions_attributes, :as => [:default, :admin] - + attr_accessible :organisation_id, :description, :number, :title, :published, + :questions_attributes, :organisation, :phase, :modifiable, + :as => [:default, :admin] + ## # return the title of the section # @@ -21,8 +22,11 @@ "#{title}" end - amoeba do - include_association :questions - end +# TODO: Commented this amoeba cloning gem definition out to see if its even used. The +# amoeba documentations uses [object].amoeba_dup to clone the object, but that +# command does not exist in the codebase +# amoeba do +# include_association :questions +# end end diff --git a/app/models/settings/plan_list.rb b/app/models/settings/plan_list.rb index 17e93a9..812e2c8 100644 --- a/app/models/settings/plan_list.rb +++ b/app/models/settings/plan_list.rb @@ -5,7 +5,7 @@ # TODO: can these be taken from somewhere else rather than hard-coded here? DEFAULT_COLUMNS = ['name', 'owner', 'shared', 'last_edited'] - ALL_COLUMNS = DEFAULT_COLUMNS + ['template_owner', 'identifier', 'grant_number', + ALL_COLUMNS = DEFAULT_COLUMNS + ['template_owner', 'identifier', 'grant_number', 'visibility', 'principal_investigator', 'data_contact', 'description'] validate do diff --git a/app/models/settings/template.rb b/app/models/settings/template.rb index 7bc1968..2956eac 100644 --- a/app/models/settings/template.rb +++ b/app/models/settings/template.rb @@ -12,7 +12,7 @@ VALID_MARGIN_RANGE = (5..25) VALID_ADMIN_FIELDS = ['project_name', 'project_identifier', 'grant_title', 'principal_investigator', - 'project_data_contact', 'project_description', 'funder', 'institution'] + 'project_data_contact', 'project_description', 'funder', 'institution', 'orcid'] DEFAULT_SETTINGS = { formatting: { diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb index 3e62265..5b94c8d 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -8,7 +8,8 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :organisation_id, :question_id, :text, :is_example, :as => [:default, :admin] + attr_accessible :org_id, :question_id, :text, :is_example, + :org, :question, :as => [:default, :admin] # EVALUATE CLASS AND INSTANCE METHODS BELOW diff --git a/app/models/template.rb b/app/models/template.rb index 1ddcb9d..63b48de 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -12,7 +12,9 @@ ## # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 - attr_accessible :id, :organisation_id, :description, :published, :title, :locale, :is_default, :guidance_group_ids, :as => [:default, :admin] + attr_accessible :id, :org_id, :description, :published, :title, :locale, + :is_default, :guidance_group_ids, :org, :plans, :phases, + :version, :visibility, :published, :as => [:default, :admin] # defines the export setting for a template object has_settings :export, class_name: 'Settings::Template' do |s| diff --git a/app/models/token_permission_type.rb b/app/models/token_permission_type.rb index 0d1f291..a7362d9 100644 --- a/app/models/token_permission_type.rb +++ b/app/models/token_permission_type.rb @@ -2,7 +2,7 @@ ## # Associations #has_and_belongs_to_many :org_token_permissions, join_table: "org_token_permissions" - has_and_belongs_to_many :organisations, join_table: 'org_token_permissions' + has_and_belongs_to_many :organisations, join_table: 'org_token_permissions', unique: true ## # Possibly needed for active_admin diff --git a/app/models/user.rb b/app/models/user.rb index 85fcc65..52672c4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,6 @@ class User < ActiveRecord::Base include GlobalHelpers + ## # Devise # Include default devise modules. Others available are: @@ -15,6 +16,7 @@ belongs_to :org has_many :answers has_many :notes + has_many :exported_plans has_many :roles, dependent: :destroy has_many :plans, through: :roles do def filter(query) @@ -30,6 +32,9 @@ self.where(conditions) end end + + has_many :user_identifiers + has_many :identifier_schemes, through: :user_identifiers ## # Possibly needed for active_admin @@ -39,7 +44,7 @@ :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, :user_status_id, :surname, :user_type_id, :org_id, :skip_invitation, :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, - :organisation, :language, :language_id + :organisation, :language, :language_id, :org, :perms, :confirmed_at validates :email, email: true, allow_nil: true, uniqueness: true @@ -77,6 +82,15 @@ end ## + # Returns the user's identifier for the specified scheme name + # + # @param the identifier scheme name (e.g. ORCID) + # @return [UserIdentifier] the user's identifier for that scheme + def identifier_for(scheme) + user_identifiers.where(identifier_scheme: scheme).first + end + + ## # sets a new organisation id for the user # if the user has any perms such as org_admin or admin, those are removed # if the user had an api_token, that is removed @@ -128,7 +142,7 @@ # # @return [Boolean] true if the user can add new organisations def can_add_orgs? - perms.include? Perm.find_by(name: constant("user_role_types.add_organisations")) + perms.include? Perm.find_by(name: constant("roles.add_organisations")) end ## @@ -136,7 +150,7 @@ # # @return [Boolean] true if the user can change their organisation affiliations def can_change_org? - perms.include? Perm.find_by(name: constant("user_role_types.change_org_affiliation")) + perms.include? Perm.find_by(name: constant("roles.change_org_affiliation")) end ## @@ -144,7 +158,7 @@ # # @return [Boolean] true if the user can grant their permissions to others def can_grant_permissions? - perms.include? Perm.find_by(name: constant("user_role_types.grant_permissions")) + perms.include? Perm.find_by(name: constant("roles.grant_permissions")) end ## @@ -152,7 +166,7 @@ # # @return [Boolean] true if the user can modify organisation templates def can_modify_templates? - perms.include? Perm.find_by(name: constant("user_role_types.modify_templates")) + perms.include? Perm.find_by(name: constant("roles.modify_templates")) end ## @@ -160,7 +174,7 @@ # # @return [Boolean] true if the user can modify organistion guidance def can_modify_guidance? - perms.include? Perm.find_by(name: constant("user_role_types.modify_guidance")) + perms.include? Perm.find_by(name: constant("roles.modify_guidance")) end ## @@ -168,7 +182,7 @@ # # @return [Boolean] true if the user can use the api def can_use_api? - perms.include? Perm.find_by(name: constant("user_role_types.use_api")) + perms.include? Perm.find_by(name: constant("roles.use_api")) end ## @@ -176,7 +190,7 @@ # # @return [Boolean] true if the user can modify the org's details def can_modify_org_details? - perms.include? Perm.find_by(name: constant("user_role_types.change_org_details")) + perms.include? Perm.find_by(name: constant("roles.change_org_details")) end ## @@ -184,7 +198,7 @@ # # @return [Boolean] true if the user can grant api permissions to organisations def can_grant_api_to_orgs? - perms.include? Perm.find_by(name: constant('user_role_types.grant_api_to_orgs')) + perms.include? Perm.find_by(name: constant('roles.grant_api_to_orgs')) end @@ -193,7 +207,7 @@ # # @return [Boolean] true if the user can grant api permissions to organisations def can_grant_api_to_orgs? - perms.include? Perm.find_by(name: constant('user_role_types.grant_api_to_orgs')) + perms.include? Perm.find_by(name: constant('roles.grant_api_to_orgs')) end ## @@ -201,7 +215,7 @@ # # @return [String] the organisation type def org_type - org_type = organisation.organisation_type.name + org_type = org.organisation_type return org_type end @@ -226,12 +240,25 @@ end self.save! # send an email to the user to notify them of their new api token - UserMailer.api_token_granted_notification(self) + #UserMailer.api_token_granted_notification(self) end end + ## + # Load the user based on the scheme and id provided by the Omniauth call + # -------------------------------------------------------------- + def self.from_omniauth(auth) + scheme = IdentifierScheme.find_by(name: auth.provider.downcase) + + if scheme.nil? + throw Exception.new('Unknown OAuth provider: ' + auth.provider) + else + joins(:user_identifiers).where('user_identifiers.identifier': auth.uid, + 'user_identifiers.identifier_scheme_id': scheme.id).first + end + end - # this generates a reset password link for a given user + # this generates a reset password link for a given user # which can then be sent to them with the appropriate host # prepended. def reset_password_link diff --git a/app/models/user_identifier.rb b/app/models/user_identifier.rb new file mode 100644 index 0000000..6623765 --- /dev/null +++ b/app/models/user_identifier.rb @@ -0,0 +1,9 @@ +class UserIdentifier < ActiveRecord::Base + belongs_to :user + belongs_to :identifier_scheme + + # Should only be able to have one identifier per scheme! + validates_uniqueness_of :identifier_scheme, scope: :user + + validates :identifier, :user, :identifier_scheme, presence: true +end \ No newline at end of file diff --git a/app/policies/guidance_policy.rb b/app/policies/guidance_policy.rb index 4aa8245..ee7be10 100644 --- a/app/policies/guidance_policy.rb +++ b/app/policies/guidance_policy.rb @@ -53,7 +53,7 @@ class Scope < Scope def resolve - scope = Guidance.includes(:guidance_group, :question, :themes).by_organisation(user.org_id) + scope = Guidance.includes(:guidance_group, :question, :themes).by_org(user.org_id) end end end \ No newline at end of file diff --git a/app/policies/project_policy.rb b/app/policies/project_policy.rb index 60c76fd..9ca5bcc 100644 --- a/app/policies/project_policy.rb +++ b/app/policies/project_policy.rb @@ -39,4 +39,5 @@ def possible_guidance? true end + end \ No newline at end of file diff --git a/app/policies/template_policy.rb b/app/policies/template_policy.rb index 3524c40..1fd64f5 100644 --- a/app/policies/template_policy.rb +++ b/app/policies/template_policy.rb @@ -31,6 +31,10 @@ user.can_modify_templates? && (template.org_id == user.org_id) end + def admin_template_history? + user.can_modify_templates? && (template.org_id == user.org_id) + end + def admin_phase? user.can_modify_templates? && (template.org_id == user.org_id) end diff --git a/app/validators/answer_for_correct_template_validator.rb b/app/validators/answer_for_correct_template_validator.rb new file mode 100644 index 0000000..8ec15ee --- /dev/null +++ b/app/validators/answer_for_correct_template_validator.rb @@ -0,0 +1,10 @@ +class AnswerForCorrectTemplateValidator < ActiveModel::Validator + def validate(record) + # Make sure that the question and plan belong to the same template! + unless record.plan.nil? || record.question.nil? + unless record.plan.template == record.question.section.phase.template + record.errors[:question] << I18n.t('helpers.answer.question_must_belong_to_correct_template') + end + end + end +end \ No newline at end of file diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb index a3cc4ed..d47e7c1 100644 --- a/app/validators/email_validator.rb +++ b/app/validators/email_validator.rb @@ -1,7 +1,7 @@ class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i - #record.errors[attribute] << (options[:message] || "is not a valid email address") + record.errors[attribute] << (options[:message] || "is not a valid email address") end end end \ No newline at end of file diff --git a/app/validators/url_validator.rb b/app/validators/url_validator.rb new file mode 100644 index 0000000..a967c32 --- /dev/null +++ b/app/validators/url_validator.rb @@ -0,0 +1,7 @@ +class UrlValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + unless value =~ /https?:\/\/[-a-zA-Z0-9@:%_\+.~#?&\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&\/=]*)?/ + record.errors[attribute] << (options[:message] || "is not a valid URL") + end + end +end \ No newline at end of file diff --git a/app/views/api/v0/dmptemplates/index.json.jbuilder b/app/views/api/v0/dmptemplates/index.json.jbuilder deleted file mode 100644 index 8ea25b3..0000000 --- a/app/views/api/v0/dmptemplates/index.json.jbuilder +++ /dev/null @@ -1,14 +0,0 @@ -# builds a json response to api query for a list of all dmptemplates -json.prettify! - -json.templates Org.all.each do |org| - unless org.published_templates.blank? - json.organisation_name org.name - json.organisation_id org.id - json.organisation_templates org.published_templates.each do |template| - json.title template.title - json.id template.id - json.description template.description - end - end -end \ No newline at end of file diff --git a/app/views/api/v0/plans/create.json.jbuilder b/app/views/api/v0/plans/create.json.jbuilder new file mode 100644 index 0000000..ebb8c58 --- /dev/null +++ b/app/views/api/v0/plans/create.json.jbuilder @@ -0,0 +1,15 @@ +# builds a json response to a successful project createtion + +json.prettify! + +json.project do + json.title @project.title + # TODO add after decision on user creation/identification + #json.created_by @project.owner.email + json.id @project.id + json.created_at @project.created_at +end + +# json.location do +# json.link (url_for action: 'show', controller: 'project') +# end diff --git a/app/views/api/v0/plans/show.json.jbuilder b/app/views/api/v0/plans/show.json.jbuilder new file mode 100644 index 0000000..2cd84bf --- /dev/null +++ b/app/views/api/v0/plans/show.json.jbuilder @@ -0,0 +1,13 @@ +# builds a json response to a successful project createtion + +json.prettify! + +json.project do + json.title @project.title + # TODO add after decision on user creation/identification + json.created_by @project.owner.email + json.id @project.id + json.created_at @project.created_at + #json.template @project.dmptemplate + json.dmptemplate @project.dmptemplate.title +end diff --git a/app/views/api/v0/projects/create.json.jbuilder b/app/views/api/v0/projects/create.json.jbuilder deleted file mode 100644 index ebb8c58..0000000 --- a/app/views/api/v0/projects/create.json.jbuilder +++ /dev/null @@ -1,15 +0,0 @@ -# builds a json response to a successful project createtion - -json.prettify! - -json.project do - json.title @project.title - # TODO add after decision on user creation/identification - #json.created_by @project.owner.email - json.id @project.id - json.created_at @project.created_at -end - -# json.location do -# json.link (url_for action: 'show', controller: 'project') -# end diff --git a/app/views/api/v0/projects/show.json.jbuilder b/app/views/api/v0/projects/show.json.jbuilder deleted file mode 100644 index 2cd84bf..0000000 --- a/app/views/api/v0/projects/show.json.jbuilder +++ /dev/null @@ -1,13 +0,0 @@ -# builds a json response to a successful project createtion - -json.prettify! - -json.project do - json.title @project.title - # TODO add after decision on user creation/identification - json.created_by @project.owner.email - json.id @project.id - json.created_at @project.created_at - #json.template @project.dmptemplate - json.dmptemplate @project.dmptemplate.title -end diff --git a/app/views/api/v0/templates/index.json.jbuilder b/app/views/api/v0/templates/index.json.jbuilder new file mode 100644 index 0000000..643d87d --- /dev/null +++ b/app/views/api/v0/templates/index.json.jbuilder @@ -0,0 +1,12 @@ +# builds a json response to api query for a list of all dmptemplates +json.prettify! + +json.templates @org_templates.each do |org, templates| + json.organisation_name org.name + json.organisation_id org.id + json.organisation_templates templates.each do |_, template| + json.title template.title + json.id template.id + json.description template.description + end +end \ No newline at end of file diff --git a/app/views/contact_us/contacts/new.html.erb b/app/views/contact_us/contacts/new.html.erb index 73562ec..57596a5 100644 --- a/app/views/contact_us/contacts/new.html.erb +++ b/app/views/contact_us/contacts/new.html.erb @@ -97,18 +97,26 @@ <% end %> + -
    -
    - <%= raw t("contact_page.address_text_html", - organisation_name: Rails.configuration.branding[:organisation][:name], - organisation_email: Rails.configuration.branding[:organisation][:email], - application_name: Rails.configuration.branding[:application][:name],) %> - -
    - +
    +
    + <%= raw t("contact_page.address_text_html", + organisation_name: Rails.configuration.branding[:organisation][:name], + organisation_email: Rails.configuration.branding[:organisation][:email], + application_name: Rails.configuration.branding[:application][:name], + organisation_telephone: Rails.configuration.branding[:organisation][:telephone], + organisation_address_line1: Rails.configuration.branding[:organisation][:address_line1], + organisation_address_line2: Rails.configuration.branding[:organisation][:address_line2], + organisation_address_line3: Rails.configuration.branding[:organisation][:address_line3], + organisation_address_line4: Rails.configuration.branding[:organisation][:address_line4], + organisation_address_country: Rails.configuration.branding[:organisation][:address_country]) %> + +
    + +
    -
    +
    diff --git a/app/views/devise/registrations/_external_identifier.html.erb b/app/views/devise/registrations/_external_identifier.html.erb new file mode 100644 index 0000000..bbc8d75 --- /dev/null +++ b/app/views/devise/registrations/_external_identifier.html.erb @@ -0,0 +1,27 @@ +
    ); background-size: 16px 16px;"> + + <% if id.nil? || id.identifier == '' %> + + <%= link_to "#{t("identifier_schemes.schemes.#{scheme.name}.connect")}", + Rails.application.routes.url_helpers.send( + "user_#{scheme.name.downcase}_omniauth_authorize_path" + ), + title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> + + <% else %> + <% if t("identifier_schemes.schemes.#{scheme.name}.user_landing_page").nil? %> + <%= t("identifier_schemes.schemes.connect_success").gsub(/%\{scheme\}/, scheme.name.capitalize) %> + + <% else %> + <% uri = t("identifier_schemes.schemes.#{scheme.name}.user_landing_page").gsub(/%\{id\}/, id.identifier) %> + <%= link_to uri, uri, target: '_blank', + title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> + <% end %> + + <%= link_to image_tag('remove.png', height: '16px', width: '16px'), + destroy_user_identifier_path(id), method: :delete, + title: t("identifier_schemes.schemes.#{scheme.name}.disconnect_tooltip"), + data: {confirm: t("identifier_schemes.schemes.#{scheme.name}.disconnect_confirmation")} %> + <% end %> +
    diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 9e320e7..ae0c08c 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -10,75 +10,81 @@

    <%= raw t("helpers.user_details_paragraph_html") %>

    - - - - - - - - - - - - - - - - - - "> - - - +
    <%= (t("helpers.email") + " *") %><%= f.email_field :email, as: :email %>
    <%= t("helpers.first_name") %><%= f.text_field :firstname, as: :string, - id: "first_time_login_firstname", - autofocus: true, - class: "text_field has-tooltip", - "data-toggle" => "tooltip", - "data-trigger" => "focus" , - "title" => t("helpers.first_name_help_text") %>
    <%= t("helpers.last_name") %><%= f.text_field :surname, - as: :string, id: "first_time_login_surname", - class: "text_field has-tooltip", - "data-toggle" => "tooltip", - "data-trigger" => "focus" , - "title" => t("helpers.surname_help_text") %>
    <%= t("helpers.org_type.organisation") %><%= collection_select(:user, - :org_id, @orgs, - :id, :name, {include_blank: constant("organisation_types.organisation")}, - { class: "typeahead org_sign_up" }) %>
    + + + + + + + + + + + + + + + + + "> + + + - + - - - - - <% unless @user.api_token.blank? %> - - - - - - - - - <% end %> -
    <%= (t("helpers.email") + " *") %><%= f.email_field :email, as: :email %>
    <%= t("helpers.first_name") %><%= f.text_field :firstname, as: :string, + id: "first_time_login_firstname", + autofocus: true, + class: "text_field has-tooltip", + "data-toggle" => "tooltip", + "data-trigger" => "focus" , + "title" => t("helpers.first_name_help_text") %>
    <%= t("helpers.last_name") %><%= f.text_field :surname, + as: :string, id: "first_time_login_surname", + class: "text_field has-tooltip", + "data-toggle" => "tooltip", + "data-trigger" => "focus" , + "title" => t("helpers.surname_help_text") %>
    <%= t("helpers.org_type.organisation") %><%= collection_select(:user, + :org_id, @orgs, + :id, :name, {include_blank: constant("organisation_types.organisation")}, + { class: "typeahead org_sign_up" }) %>
    <%= t('helpers.user_details_language') %> - - + + + -
    <%= t("helpers.orcid_id") %><%= f.text_field :orcid_id , - as: :string, - autocomplete: "off" , - class: "text_field has-tooltip", "data-toggle" => "tooltip", "data-html" => "true", "title" => t("helpers.orcid_html") %>
    <%= t("helpers.api_token") %><%= @user.api_token %>
    <%= t("helpers.api_info") %><%= link_to( t("helpers.api_use"), controller: "token_permission_types", action: "index")%>
    -
    -

    + + <% @identifier_schemes.each do |scheme| %> + + <%= scheme.name %> + + <%= render partial: 'external_identifier', + locals: {scheme: scheme, + id: current_user.identifier_for(scheme)} %> + + + <% end %> + + + <% unless @user.api_token.blank? %> + + <%= t("helpers.api_token") %> + <%= @user.api_token %> + + + <%= t("helpers.api_info") %> + <%= link_to( t("helpers.api_use"), controller: "token_permission_types", action: "index")%> + + <% end %> + +
    +

    <% if Rails.application.config.shibboleth_enabled %> <% if resource.shibboleth_id.nil? || resource.shibboleth_id.length == 0 then %> <%= link_to t("helpers.shibboleth_to_link_text"), user_omniauth_shibboleth_path, class: "a-orange" %> @@ -89,38 +95,38 @@ <% end %> <% end %> -

    -
    -
    -
    -

    - <%= raw t("helpers.edit_password_info")%> -

    - - <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> -
    <%= t('custom_devise.waiting_for_confirmation') %><%= resource.unconfirmed_email %>
    - <% end %> - - - - - - - - - - - - -
    <%= t("helpers.current_password") %> - <%= f.password_field :current_password, as: :password %> -
    <%= t("helpers.new_password") %><%= f.password_field :password, as: :password, autocomplete: "off" %> -
    <%= t("helpers.password_conf") %><%= f.password_field :password_confirmation, as: :password, autocomplete: "off" %>
    -
    - <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), :back, class: "btn btn-primary" %> -
    - <% end %> +

    +
    +
    +
    +

    + <%= raw t("helpers.edit_password_info")%> +

    + + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
    <%= t('custom_devise.waiting_for_confirmation') %><%= resource.unconfirmed_email %>
    + <% end %> + + + + + + + + + + + + +
    <%= t("helpers.current_password") %> + <%= f.password_field :current_password, as: :password %> +
    <%= t("helpers.new_password") %><%= f.password_field :password, as: :password, autocomplete: "off" %> +
    <%= t("helpers.password_conf") %><%= f.password_field :password_confirmation, as: :password, autocomplete: "off" %>
    +
    + <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.cancel"), :back, class: "btn btn-primary" %> +
    + <% end %>
    diff --git a/app/views/dmptemplates/_add_question.html.erb b/app/views/dmptemplates/_add_question.html.erb new file mode 100644 index 0000000..b9bbfc8 --- /dev/null +++ b/app/views/dmptemplates/_add_question.html.erb @@ -0,0 +1,183 @@ + + +<% @new_question = Question.new %> +<% @new_question.number = section.questions.count + 1 %> + + +<%= form_for @new_question, :url => {:action => "admin_createquestion"}, :html => {:id => "new_question_#{section.id}"} do |f| %> +<%= f.hidden_field :section_id, :value => section.id %> +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= t("org_admin.questions.question_number_label")%><%= f.number_field :number, :in => 1..50, :class => "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> + +
    +
    <%= t("org_admin.questions.question_text_label")%><%= f.text_area :text, :rows => "5", :id => "new_question_text_#{section.id}" %> +
    +
    <%= t("org_admin.questions.answer_format_label")%><%= f.hidden_field :section_id, :value => section.id, :class => "section_id" %> +
    +
    + <%= f.select :question_format_id, + #options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, QuestionFormat.find_by_title(t("helpers.text_area")).id), + # the above was the line but it doesn't work because in the DB + # the QuestionFormat title is in English (Text area) + # but the above uses the Fr translation and so gets a nil + options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, QuestionFormat.find_by_title("Text area").id), + {}, :id => "new-select-format-#{section.id}"%> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", :class => "question_format_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%> +
    + +
    +
    + + +
    + + +
    + + +
    + +
    +
    +
    +
    <%= t("org_admin.questions.suggested_or_example_answer_label")%>
    + <% suggested_answer = @new_question.suggested_answers.build %> + <%= f.fields_for :suggested_answers, suggested_answer do |s|%> + <%= s.hidden_field :organisation_id, :value => current_user.organisation.id %> +
      +
    • <%= s.select :is_example, {t("org_admin.questions.example_answer_label") => true, t("org_admin.questions.suggested_answer_label") => 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" => t("org_admin.questions.suggested_answer_help_text_html"))%> +
    +
    +
    + +
    <%= t("org_admin.questions.guidance_label")%>
    + <%= text_area_tag("new-question-guidance", "", class: "tinymce") %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", :class => "question_guidance_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%> +
    +
    +
    +
    <%= t("org_admin.questions.themes_label")%>
    + <%= f.collection_select(:theme_ids, + Theme.all.order("title"), + :id, :title, {:prompt => false, :include_blank => t('helpers.none')}, {:multiple => true})%> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", :class => "question_themes_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%> +
    + + +
    +
    + + +
    + <%= hidden_field_tag :section_id, section.id, :class => "section_id" %> + <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary new_question_save_button" %> + <%= hidden_field_tag :section_id, section.id, :class => "section_id_new" %> + <%= link_to t("helpers.submit.cancel"), '#', :class => "btn cancel cancel_add_new_question" %> +
    +
    + +<%end%> + diff --git a/app/views/dmptemplates/_admin_nav_tabs.html.erb b/app/views/dmptemplates/_admin_nav_tabs.html.erb new file mode 100644 index 0000000..e2237ea --- /dev/null +++ b/app/views/dmptemplates/_admin_nav_tabs.html.erb @@ -0,0 +1,34 @@ + + + diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index 42d66cf..dca92ca 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -97,6 +97,16 @@ <% end %> <%= t("helpers.help_label") %>
  • + + + <% if current_path == "/plans/public_plans" then %> +
  • + <% else %> +
  • + <% end %> + <%= t("helpers.public_plans_label") %> +
  • + <% end %> - \ No newline at end of file + diff --git a/app/views/plans/_answer_form.html.erb b/app/views/plans/_answer_form.html.erb new file mode 100644 index 0000000..dd256e4 --- /dev/null +++ b/app/views/plans/_answer_form.html.erb @@ -0,0 +1,260 @@ + +<% 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 %> + <%= t("org_admin.questions.example_answer_label")%> + <%else%> + <%= t("org_admin.questions.suggested_answer_label")%> + <%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, t("helpers.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 => t("helpers.save"), :button_html => { :class => "btn btn-primary"}, :input_html => { :disabled => true } %> + <% else %> + + + <% 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 %> + <%= t("helpers.notanswered") %> + <% else %> + <%= t("helpers.answered_by")%><%= answer.created_at %><%= t("helpers.answered_by_part2")%><%= 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 t("helpers.guidance_accordion_label"), "#", :class => "guidance_accordion_button" %> +
    • +
    • + <% if @comments.count > 0 then%> + <% comments_label_with_count = "#{t("helpers.comment_accordion_label")} (#{@comments.count})"%> + <%= link_to comments_label_with_count , "#", :class => "comments_accordion_button" %> + <%else%> + <%= link_to t("helpers.add_comment_accordion_label"), "#", :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 = "#{t("helpers.comment_accordion_label")} (#{@comments.count})"%> +

      <%= comments_label_with_count %>

      + <%else%> +

      <%= t("helpers.add_comment_accordion_label") %>

      + <%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/projects/_dropdowns_new_project.html.erb b/app/views/projects/_dropdowns_new_project.html.erb new file mode 100644 index 0000000..92b9dd5 --- /dev/null +++ b/app/views/projects/_dropdowns_new_project.html.erb @@ -0,0 +1,110 @@ + +<%= semantic_form_for @project, :url => {:controller => :projects, :action => :create }, :html=>{:method=>:post} do |f| %> + <%= f.inputs do %> + <%= hidden_field_tag :default_tag, "false" ,:id => "default_tag" %> +
    +

    <%= t('helpers.project.create_page.title')%>

    +
    +

    <%= raw t('helpers.project.create_page.desc_html')%>

    + +
    + +
    + + <% # + # The following JSON arrays are used to build/filter the contents of + # the select2 dropdown box for dmptemplates and the checkboxes for + # the guidance group selections + # (they are referenced in /app/assets/javascripts/projects.js) + # %> + + <%= hash_to_js_json_variable('funders', + @funders.collect{ |inst| + {'id': inst.id, + 'text': inst.name} + }) %> + + <%= hash_to_js_json_variable('institutions', + @institutions.collect{ |inst| + {'id': inst.id, + 'text': inst.name, + 'default': (current_user.organisation_id == inst.id)} + }) %> + + <%= hash_to_js_json_variable('templates', + @templates.collect{ |tmplt| + {'organisation': tmplt.organisation_id, + 'id': tmplt.id, + 'text': tmplt.title} + }) %> + + <%= hash_to_js_json_variable('guidance_for_template_or_organisation', + @guidance_groups.collect{ |grp| + {'organisation': grp.organisation_id, + 'templates': grp.dmptemplates.collect{ |t| t.id }, + 'id': grp.id, + 'text': grp.name} + }) %> + + <%= hash_to_js_json_variable('guidance_always_available', + @always_guidance.collect{ |grp| + {'id': grp.id, + 'text': grp.name} + }) %> + + <% end %> + + <%= f.actions do %> + + <% end %> +<% end %> diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index 526577f..360d87f 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -18,6 +18,12 @@ <%= f.text_area :note, :class => 'text_area', :rows => 10 %> +
    + <%= f.label t('helpers.is_test'), class: 'left-label' %> +
    + <%= f.check_box :is_test, class: 'check_box has-tooltip', 'data-toggle': 'tooltip' title: t('helpers.project.is_test_help_text') %> +
    +
    <%= f.submit t("helpers.submit.save"), :class => 'btn btn-primary' %> <%= link_to t("helpers.links.cancel"), diff --git a/app/views/projects/_project_details.html.erb b/app/views/projects/_project_details.html.erb index dc62033..6826f47 100644 --- a/app/views/projects/_project_details.html.erb +++ b/app/views/projects/_project_details.html.erb @@ -1,277 +1,299 @@
    -
    "> -
    -

    - <%= t('helpers.project.project_details_text_html')%> -

    -
    +
    "> +
    +

    + <%= t('helpers.project.project_details_text_html')%> +

    +
    - -
    - <% if @project.administerable_by(current_user.id) then %> - <%= t("helpers.project.edit") %> - <% end %> -
    - -
    - - - - - - - - - - - - - - - - - - <% if !@project.principal_investigator_identifier.nil? && @project.principal_investigator_identifier != "" then %> - - - - - <%end%> - - - - - - - - -
    <%= t('helpers.project.project_name') %><%= @project.title %>
    <%= t('helpers.project.project_identifier') %> - <% if !@project.identifier.nil? && @project.identifier != "" then %> - <%= @project.identifier %> - <%else%> - - - <%end%> -
    <%= t('helpers.project.grant_title') %> - <% if !@project.grant_number.nil? && @project.grant_number!= "" then %> - <%= @project.grant_number %> - <%else%> - - - <%end%> -
    <%= t('helpers.project.principal_investigator') %><% if !@project.principal_investigator.nil? && @project.principal_investigator != "" then %> - <%= @project.principal_investigator %> - <%else%> - - - <%end%> -
    <%= t('helpers.project.principal_investigator_id') %> - <%= @project.principal_investigator_identifier %> -
    <%= t('helpers.project.project_data_contact') %><% if !@project.data_contact.nil? && @project.data_contact != "" then%> - <%= @project.data_contact %> - <%else%> - - - <%end%> -
    <%= t('helpers.desc') %><% if !@project.description.nil? && @project.description != "" then%> - <%= @project.description %> - <%else%> - - - <%end%> -
    -
    -
    - <% if @project.administerable_by(current_user.id) then %> -
    "> - -
    -

    - <%= raw t('helpers.project.project_details_editing_text_html')%> -

    -
    - -
    - <%= semantic_form_for @project, :url => {:controller => :projects, :action => :update }, :html=>{:method=>:put} do |f| %> - <%= f.inputs do %> -
    + +
    + <% if @project.administerable_by(current_user.id) then %> + <%= t("helpers.project.edit") %> + <% end %> +
    + +
    + + + + + + + + + + + + + + + + + + <% if !@project.principal_investigator_identifier.nil? && @project.principal_investigator_identifier != "" then %> + + + + + <%end%> + + + + + + + + + + + + +
    <%= t('helpers.project.project_name') %><%= @project.title %>
    <%= t('helpers.project.project_identifier') %> + <% if !@project.identifier.nil? && @project.identifier != "" then %> + <%= @project.identifier %> + <%else%> + - + <%end%> +
    <%= t('helpers.project.grant_title') %> + <% if !@project.grant_number.nil? && @project.grant_number!= "" then %> + <%= @project.grant_number %> + <%else%> + - + <%end%> +
    <%= t('helpers.project.principal_investigator') %><% if !@project.principal_investigator.nil? && @project.principal_investigator != "" then %> + <%= @project.principal_investigator %> + <%else%> + - + <%end%> +
    <%= t('helpers.project.principal_investigator_id') %> + <%= @project.principal_investigator_identifier %> +
    <%= t('helpers.project.project_data_contact') %><% if !@project.data_contact.nil? && @project.data_contact != "" then%> + <%= @project.data_contact %> + <%else%> + - + <%end%> +
    <%= t('helpers.desc') %><% if !@project.description.nil? && @project.description != "" then%> + <%= @project.description %> + <%else%> + - + <%end%> +
    <%= t('helpers.project.visibility') %><%= (@project.is_test? ? t("helpers.project.visibilities.help_texts.is_test") : (@project.organisationally_visible? ? t("helpers.project.visibilities.help_texts.organisationally_visible") : (@project.publicly_visible? ? t("helpers.project.visibilities.help_texts.publicly_visible") : (@project.privately_visible? ? t("helpers.project.visibilities.help_texts.privately_visible") : "Defaulting to: #{t("helpers.project.visibilities.help_texts.not_set")}")))) %>
    +
    +
    + <% if @project.administerable_by(current_user.id) then %> +
    "> + +
    +

    + <%= raw t('helpers.project.project_details_editing_text_html')%> +

    +
    + +
    + <%= semantic_form_for @project, :url => {:controller => :projects, :action => :update }, :html=>{:method=>:put} do |f| %> + <%= f.inputs do %> +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    <%= t('helpers.project.project_name') %> - <%= f.text_field :title, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.project_name_help_text') %> -
    <%= t('helpers.project.project_identifier') %> - <%= f.text_field :identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.project_identifier_help_text') %> -
    <%= t('helpers.project.grant_title') %> - <%= f.text_field :grant_number, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.grant_help_text') %> -
    <%= t('helpers.project.principal_investigator') %> - <%= f.text_field :principal_investigator, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.principal_investigator_help_text') %> -
    <%= t('helpers.project.principal_investigator_id') %> - <%= f.text_field :principal_investigator_identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.principal_investigator_id_help_text') %> -
    <%= t('helpers.project.project_data_contact') %> - <%= f.text_field :data_contact, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.project_data_contact_help_text') %> -
    <%= t('helpers.desc') %> - <%= f.text_area :description, { :rows => 7, :class => 'text_area has-tooltip', 'data-toggle' => "tooltip", 'data-html' => "true", 'title'=> t('helpers.project.project_desc_help_text_html')} %> -
    -
    - <% end %> - - <%= f.actions do %> -
    - <%= f.submit t("helpers.submit.save"), :class => 'btn btn-primary' %> - <%= t("helpers.links.cancel") %> -
    - <%end%> - <%end%> -
    - <% end %> -

    <%= t('helpers.project.project_static_info')%>

    - - - <%if @project.dmptemplate.organisation.organisation_type.name == constant("organisation_types.funder")%> - - - - - <%end%> - <%if !@project.organisation_id.nil? %> - - - - - <%end%> -
    <%= constant("organisation_types.funder") %><%= @project.dmptemplate.organisation.name %>
    <%= constant("organisation_types.institution") %><%= @project.organisation.name %>
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= t('helpers.project.project_name') %> + <%= f.text_field :title, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.project_name_help_text') %> +
    <%= t('helpers.project.project_identifier') %> + <%= f.text_field :identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.project_identifier_help_text') %> +
    <%= t('helpers.project.grant_title') %> + <%= f.text_field :grant_number, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.grant_help_text') %> +
    <%= t('helpers.project.principal_investigator') %> + <%= f.text_field :principal_investigator, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.principal_investigator_help_text') %> +
    <%= t('helpers.project.principal_investigator_id') %> + <%= f.text_field :principal_investigator_identifier, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.principal_investigator_id_help_text') %> +
    <%= t('helpers.project.project_data_contact') %> + <%= f.text_field :data_contact, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('helpers.project.project_data_contact_help_text') %> +
    <%= t('helpers.desc') %> + <%= f.text_area :description, { :rows => 7, :class => 'text_area has-tooltip', 'data-toggle' => "tooltip", 'data-html' => "true", 'title'=> t('helpers.project.project_desc_help_text_html')} %> +
    <%= t('helpers.project.visibility') %> +
    + /><%= t('helpers.project.visibilities.help_texts.publicly_visible') %> +
    +
    + /><%= t('helpers.project.visibilities.help_texts.organisationally_visible') %> +
    +
    + /><%= t('helpers.project.visibilities.help_texts.is_test') %> +
    +
    + /><%= t('helpers.project.visibilities.help_texts.privately_visible') %> +
    +
    +
    + <% end %> + + <%= f.actions do %> +
    + <%= f.submit t("helpers.submit.save"), :class => 'btn btn-primary' %> + <%= t("helpers.links.cancel") %> +
    + <%end%> + <%end%> +
    + <% end %> +

    <%= t('helpers.project.project_static_info')%>

    + + + <%if @project.dmptemplate.organisation.organisation_type.name == constant("organisation_types.funder")%> + + + + + <%end%> + <%if !@project.organisation_id.nil? %> + + + + + <%end%> +
    <%= constant("organisation_types.funder") %><%= @project.dmptemplate.organisation.name %>
    <%= constant("organisation_types.institution") %><%= @project.organisation.name %>
    +>>>>>>> final_schema - - <% if @project.plans.any? %> - <% if @project.plans.count == 1 then %> - <% @project.plans.each do |plan| %> + + <% if @project.plans.any? %> + <% if @project.plans.count == 1 then %> + <% @project.plans.each do |plan| %> -
    - <%= link_to t('helpers.answer_questions'), [:edit, @project, plan], :class => 'btn btn-primary' %> - <%= t('helpers.export') %> -
    - <%= render :partial => "plans/export", locals: {plan: plan} %> -
    -

    <%= raw plan.version.phase.description %>

    - <% if !plan.sections.nil? %> - - - - - - - - - <% plan.sections.each do |section| %> - - - - - <%end%> - -
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    -

    <%= section.title %>

    -
    - <% if section.questions.any? %> - <% questions = section.questions.sort_by(&:number) %> -
      - <% questions.each do |ques|%> -
    • - <%= raw ques.text %> -
    • - <%end%> -
    - <%end%> -
    - <%end%> - <%end%> - <%else%> -
    - <%= raw @project.dmptemplate.description %> -
    - <% @project.plans.each do |plan| %> -
    -
    - -
    -
    -
    - <%= link_to t('helpers.answer_questions'), [:edit, @project, plan], :class => 'btn btn-primary' %> - <%= t('helpers.export') %> -
    - <%= render :partial => "plans/export", locals: {plan: plan} %> -
    -

    <%= raw plan.version.phase.description %> -

    +
    + <%= link_to t('helpers.answer_questions'), [:edit, @project, plan], :class => 'btn btn-primary' %> + <%= t('helpers.export') %> +
    + <%= render :partial => "plans/export", locals: {plan: plan} %> +
    +

    <%= raw plan.version.phase.description %>

    + <% if !plan.sections.nil? %> + + + + + + + + + <% plan.sections.each do |section| %> + + + + + <%end%> + +
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    +

    <%= section.title %>

    +
    + <% if section.questions.any? %> + <% questions = section.questions.sort_by(&:number) %> +
      + <% questions.each do |ques|%> +
    • + <%= raw ques.text %> +
    • + <%end%> +
    + <%end%> +
    + <%end%> + <%end%> + <%else%> +
    + <%= raw @project.dmptemplate.description %> +
    + <% @project.plans.each do |plan| %> +
    +
    + +
    +
    +
    + <%= link_to t('helpers.answer_questions'), [:edit, @project, plan], :class => 'btn btn-primary' %> + <%= t('helpers.export') %> +
    + <%= render :partial => "plans/export", locals: {plan: plan} %> +
    +

    <%= raw plan.version.phase.description %> +

    - <% if !plan.sections.nil? %> - - - - - - - - - <% plan.sections.each do |section| %> - - - - - <%end%> - -
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    -

    <%= section.title %>

    -
    - <% if section.questions.any? %> - <% questions = section.questions.sort_by(&:number) %> -
      - <% questions.each do |ques|%> -
    • - - <%= ques.text %> -
    • - <%end%> -
    - <%end%> -
    - <%end%> -
    -
    -
    -
    - <%end%> - <%end%> - <%end%> + <% if !plan.sections.nil? %> + + + + + + + + + <% plan.sections.each do |section| %> + + + + + <%end%> + +
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    +

    <%= section.title %>

    +
    + <% if section.questions.any? %> + <% questions = section.questions.sort_by(&:number) %> +
      + <% questions.each do |ques|%> +
    • + - <%= ques.text %> +
    • + <%end%> +
    + <%end%> +
    + <%end%> +
    +
    +
    +
    + <%end%> + <%end%> + <%end%>
    diff --git a/app/views/projects/_project_nav_tabs.html.erb b/app/views/projects/_project_nav_tabs.html.erb index 9e860f6..07200bd 100644 --- a/app/views/projects/_project_nav_tabs.html.erb +++ b/app/views/projects/_project_nav_tabs.html.erb @@ -9,8 +9,9 @@ <% end %> <%= link_to t("helpers.project.tab_plan"), project_path(project) %> - - <% project.plans.each do |plan| %> + + <% pplans = project.plans.sort { |x,y| x.version.phase.number <=> y.version.phase.number} %> + <% pplans.each do |plan| %> <% if active == plan.id then %>
  • <% else %> @@ -42,4 +43,4 @@ <%= link_to t("helpers.project.tab_export"), ["export",project] %>
  • -
    \ No newline at end of file + diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 9dd737c..8faab88 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -1,3 +1,5 @@ +<%= javascript_include_tag "projects" %> + <%- model_class = Project -%> diff --git a/app/views/shared/_register_form.html.erb b/app/views/shared/_register_form.html.erb index 462083a..cb61bfb 100644 --- a/app/views/shared/_register_form.html.erb +++ b/app/views/shared/_register_form.html.erb @@ -20,6 +20,10 @@ <%= f.text_field :surname, placeholder: t('helpers.last_name'), :as => :string, :class => 'text_field' %> <% end %> + <% if resource.user_identifiers.count > 0 %> + <% scheme = resource.user_identifiers.identifier_scheme.name %> + <%= f.hidden_field "user_identifiers[#{scheme}]", value: resource.user_identifiers.first.identifier%> + <% end %>
  • <%= collection_select(:user, :organisation_id, Org.where("parent_id IS NULL").order("sort_name ASC, name ASC"), :id, :name, {include_blank: constant("organisation_types.organisation")}, { :class => 'typeahead org_sign_up' }) %>
  • diff --git a/app/views/static_pages/about_us.html.erb b/app/views/static_pages/about_us.html.erb index 59890dc..873c031 100644 --- a/app/views/static_pages/about_us.html.erb +++ b/app/views/static_pages/about_us.html.erb @@ -37,7 +37,8 @@ organisation_url: Rails.configuration.branding[:organisation][:url], application_name: Rails.configuration.branding[:application][:name], application_home: Rails.configuration.branding[:application][:home], - application_url: Rails.configuration.branding[:application][:url])%> + application_url: Rails.configuration.branding[:application][:url], + current_locale: I18n.locale)%>
    <%= raw t("about_page.body_text_tab_2_html", diff --git a/app/views/static_pages/public_export.html.erb b/app/views/static_pages/public_export.html.erb new file mode 100644 index 0000000..37f1a18 --- /dev/null +++ b/app/views/static_pages/public_export.html.erb @@ -0,0 +1,41 @@ +<%- model_class = Project -%> + + +<%= render :partial => "/projects/project_title", locals: {project: @project} %> + + +<%= render :partial => "project_nav_tabs", locals: {project: @project, active: "export_page"} %> + + +
    + + <%= raw t('helpers.project.export_text_html')%> + + + <% if @project.plans.any? %> + <% if @project.plans.count == 1 then %> + <% @project.plans.each do |plan| %> + <%= render :partial => "/shared/export_links", locals: {plan: plan} %> + <% end %> + <%else%> + <% @project.plans.each do |plan| %> +
    +
    + +
    +
    + <%= render :partial => "/shared/export_links", locals: {plan: plan} %> +
    +
    +
    +
    + <%end%> + <%end%> + <%end%> + +
    \ No newline at end of file diff --git a/app/views/static_pages/public_export.pdf.erb b/app/views/static_pages/public_export.pdf.erb new file mode 100644 index 0000000..77d68cb --- /dev/null +++ b/app/views/static_pages/public_export.pdf.erb @@ -0,0 +1,72 @@ + + + + + + <% if @plan.project.dmptemplate.phases.count > 1 then %> + <%= "#{@plan.project.title} - #{@plan.title}" %> + <% else %> + <%= @plan.project.title %> + <% end %> + + + + +

    <%= @plan.title %>

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

    <%= t("helpers.plan.export.#{field}") -%> <%= value -%>

    + <% end %> + <% end %> + + <% @exported_plan.sections.each do |section| %> +

    <%= section.title %>

    + <% questions = @exported_plan.questions_for_section(section.id) %> + <% questions.each_with_index do |question, idx| %> +
    + <% unless idx == 0 && question.text == section.title %> +

    <%= raw question.text %>

    + <% end %> + <% answer = @plan.answer(question.id, false) %> + <% if answer.nil? then %> +

    <%= t('helpers.plan.export.pdf.question_not_answered') -%>

    + <% else %> + <% q_format = question.question_format%> + + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || + q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> +
      + <% answer.options.each do |option| %> +
    • <%= option.text %>
    • + <% end %> +
    + + <% if question.option_comment_display == true then%> + <% if !answer.text.nil? then %> + <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> + <%end%> + <%end%> + <%else%> + + <% if !answer.text.nil? then %> + <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> + <%end%> + <% end %> + <% end %> +
    + <% end %> + <% end %> + + \ No newline at end of file diff --git a/app/views/static_pages/public_plans.html.erb b/app/views/static_pages/public_plans.html.erb new file mode 100644 index 0000000..16cdb15 --- /dev/null +++ b/app/views/static_pages/public_plans.html.erb @@ -0,0 +1,41 @@ +<%- model_class = Project -%> +

    + <%= raw t("public_plans_page.title") %> +

    + + +<% if @projects.count > 0 %> +

    + <%= raw t("public_plans_page.body_text_html", {app_name: Rails.configuration.branding[:application][:name]}) %> +

    + + + + + <% ['name', 'template', 'organisation', 'owner'].each do |column| %> + <%= project_list_column_heading(column) %> + <% end %> + + + + + <% @projects.each do |project| %> + + <% ['non_link_name', 'template', 'organisation', 'owner'].each do |column| %> + <%= project_list_column_body(column, project) %> + <% end %> + + + + <% end %> + +
    + <%= link_to t("helpers.project.tab_export"), "#{public_export_path(project)}", :class => "dmp_table_link" %> +
    + + +<% else %> +

    + <%= raw t("public_plans_page.no_plans_body_text_html")%> +

    +<% end %> diff --git a/app/views/templates/_add_guidance.html.erb b/app/views/templates/_add_guidance.html.erb index de49775..af080d0 100644 --- a/app/views/templates/_add_guidance.html.erb +++ b/app/views/templates/_add_guidance.html.erb @@ -1,93 +1,93 @@
    - <%= form_for :guidance, :url => {:action => "admin_create"}, :html => {:id => "new_guidance_form"} do |f| %> - - - - - - - - + + + + + + + + + +
    <%= t("org_admin.guidance.text_label") %>
    - <%= text_area_tag("guidance-text", "", class: "tinymce") %> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "guidance_text_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.text_help_text_html"))%> -
    -
    -
    <%= t("org_admin.guidance.by_theme_or_by_question") %>
    - <%= select_tag "g_options", options_for_select([[t("org_admin.guidance.by_themes_label"), 1], - [t("org_admin.guidance.by_question_label"), 2]]) %> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "guidance_apply_to_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.apply_to_help_text_html"))%> -
    -
    + <%= form_for :guidance, url: {action: "admin_create"}, html: {id: "new_guidance_form"} do |f| %> + + + + + + + + - - - - - - - - - -
    <%= t("org_admin.guidance.text_label") %> +
    + <%= text_area_tag("guidance-text", "", class: "tinymce") %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "guidance_text_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.text_help_text_html"))%> +
    +
    +
    <%= t("org_admin.guidance.by_theme_or_by_question") %> +
    + <%= select_tag "g_options", options_for_select([[t("org_admin.guidance.by_themes_label"), 1], + [t("org_admin.guidance.by_question_label"), 2]]) %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "guidance_apply_to_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.apply_to_help_text_html"))%> +
    +
    - -
    <%= t("org_admin.guidance.published") %>
    - <%= f.check_box :published , :as => :check_boxes%> -
    -
    - -
    -
    <%= t("org_admin.guidance.guidance_group_label") %>
    - <%= f.collection_select(:guidance_group_ids, - GuidanceGroup.where("organisation_id = ?", current_user.organisation_id).order("name ASC"), - :id, :name, {:prompt => false, :include_blank => t('helpers.none')}, {:multiple => false})%> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "guidance_group_select_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.guidance_group_select_help_text_html"))%> -
    -
    - -
    - - - -
    - <%= t("helpers.submit.save")%> - - <%= link_to t("helpers.submit.cancel"), :back, :class => "btn cancel" %> + +
    <%= t("org_admin.guidance.published") %> +
    + <%= f.check_box :published , as: :check_boxes %> +
    +
    <%= t("org_admin.guidance.guidance_group_label") %> +
    + <%= f.collection_select(:guidance_group_ids, + GuidanceGroup.where(org_id: current_user.org_id).order("name ASC"), + :id, :name, {prompt: false, include_blank: t('helpers.none')}, {multiple: false})%> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "guidance_group_select_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.guidance_group_select_help_text_html"))%> +
    +
    +
    + + + +
    + <%= t("helpers.submit.save")%> + + <%= link_to t("helpers.submit.cancel"), :back, class: "btn cancel" %>
    +
    + <%= tinymce content_css: asset_path("application.css") %> + <% end %> +
    + \ No newline at end of file diff --git a/app/views/templates/_edit_guidance.html.erb b/app/views/templates/_edit_guidance.html.erb index 8debbca..e351d51 100644 --- a/app/views/templates/_edit_guidance.html.erb +++ b/app/views/templates/_edit_guidance.html.erb @@ -1,26 +1,26 @@ -<%= form_for(suggested_answer, :url => admin_updatesuggestedanswer_dmptemplate_path(suggested_answer), :html => { :method => :put}) do |f| %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> +<%= form_for(suggested_answer, url: admin_updatesuggestedanswer_template_path(suggested_answer), html: { method: :put}) do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_id %> - - - - - -
    <%= t("org_admin.questions.suggested_or_example_answer_label")%> -
      -
    • <%= f.select :is_example, {t("org_admin.questions.example_answer_label") => true, t("org_admin.questions.suggested_answer_label") => false} %>
    • -
    • <%= f.text_area :text, :rows => 5 %>
    • -
    -
    -
    + + + + + +
    <%= t("org_admin.questions.suggested_or_example_answer_label")%> +
      +
    • <%= f.select :is_example, {t("org_admin.questions.example_answer_label") => true, t("org_admin.questions.suggested_answer_label") => false} %>
    • +
    • <%= f.text_area :text, rows: 5 %>
    • +
    +
    +
    - -
    - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.delete"), admin_destroysuggestedanswer_dmptemplate_path(:suggested_answer => suggested_answer.id), - :confirm => t("org_admin.questions.delete_suggested_answer_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("helpers.submit.cancel"), "#", :class => "btn cancel cancel_edit_suggested_answer" %> -
    + +
    + <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.delete"), admin_destroysuggestedanswer_template_path(suggested_answer: suggested_answer.id), + confirm: t("org_admin.questions.delete_suggested_answer_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t("helpers.submit.cancel"), "#", class: "btn cancel cancel_edit_suggested_answer" %> +
    <%end%> diff --git a/app/views/templates/_edit_phase.html.erb b/app/views/templates/_edit_phase.html.erb index 1536a48..1aefe61 100644 --- a/app/views/templates/_edit_phase.html.erb +++ b/app/views/templates/_edit_phase.html.erb @@ -1,45 +1,45 @@ -<%= form_for(phase, :url => admin_updatephase_dmptemplate_path(phase), :html => { :method => :put}) do |f| %> - -

    - <%= t('org_admin.templates.phase_details_label')%> -

    -
    - <%= raw t('org_admin.templates.phase_details_text_html')%> -
    -
    -
    - - - - - - - - - - - - - - -
    <%= t('org_admin.templates.title_label') %><%= f.text_field :title, - :as => :string, - :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_title_help_text') %>
    <%= t('org_admin.templates.phase_order_label') %><%= f.number_field :number, :in => 0..5, :class => "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_number_help_text') %>
    <%= t('org_admin.templates.desc_label') %> -
    - <%= text_area_tag("phase-desc", phase.description, class: "tinymce") %> -
    -
    - <%= link_to( image_tag('help_button.png'), '#', :class => 'phase_desc_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.phase_desc_help_text_html'))%> -
    -
    -
    - - -
    - <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t('helpers.submit.cancel'), admin_phase_dmptemplate_path(phase), :class => 'btn cancel' %> -
    - -<%end%> \ No newline at end of file +<%= form_for(phase, url: admin_updatephase_template_path(phase), html: { method: :put}) do |f| %> + +

    + <%= t('org_admin.templates.phase_details_label')%> +

    +
    + <%= raw t('org_admin.templates.phase_details_text_html')%> +
    +
    +
    + + + + + + + + + + + + + + +
    <%= t('org_admin.templates.title_label') %><%= f.text_field :title, + as: :string, + class: 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_title_help_text') %>
    <%= t('org_admin.templates.phase_order_label') %><%= f.number_field :number, in: 0..5, class: "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_number_help_text') %>
    <%= t('org_admin.templates.desc_label') %> +
    + <%= text_area_tag("phase-desc", phase.description, class: "tinymce") %> +
    +
    + <%= link_to( image_tag('help_button.png'), '#', class: 'phase_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.phase_desc_help_text_html'))%> +
    +
    +
    + + +
    + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), admin_phase_template_path(phase), class: 'btn cancel' %> +
    + +<% end %> \ No newline at end of file diff --git a/app/views/templates/_edit_question.html.erb b/app/views/templates/_edit_question.html.erb index ab12c02..8ea1271 100644 --- a/app/views/templates/_edit_question.html.erb +++ b/app/views/templates/_edit_question.html.erb @@ -6,169 +6,169 @@ **Copyright: Digital Curation Centre and University of California Curation Center --> -<%= form_for(question, :url => admin_updatequestion_dmptemplate_path(question), :html => { :method => :put}) do |f| %> +<%= form_for(question, url: admin_updatequestion_template_path(question), html: { method: :put}) do |f| %>
    - - - - - - +
    <%= t("org_admin.questions.question_number_label")%><%= f.number_field :number, :in => 1..50, :class => "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> -
    -
    + + + + + - - - - - + + + + + - - - - + + +
    <%= t("org_admin.questions.question_number_label")%><%= f.number_field :number, in: 1..50, class: "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> +
    +
    <%= t("org_admin.questions.question_text_label")%><%= f.text_area :text, :rows => "5" %> -
    -
    <%= t("org_admin.questions.question_text_label")%><%= f.text_area :text, rows: "5" %> +
    +
    <%= t("org_admin.questions.answer_format_label")%>
    -
    - <%= f.hidden_field :id,{ :class => "quest_id" } %> - <%= f.select :question_format_id, - options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id), - {}, :id => "#{question.id}-select-format"%> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "question_format_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%> -
    + +
    <%= t("org_admin.questions.answer_format_label")%>
    +
    + <%= f.hidden_field :id,{ class: "quest_id" } %> + <%= f.select :question_format_id, + options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, question.question_format_id), + {}, id: "#{question.id}-select-format"%> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "question_format_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_format_help_text_html"))%> +
    -
    + - -
    + + <%= t("org_admin.add_option_label") %>
    - <%= f.check_box :option_comment_display, :as => :check_boxes%><%= f.label t("org_admin.questions.option_comment_display_checkbox"), :class => "checkbox inline"%> -
    -
    - - -
    - - -
    - -
    -
    -
    - - + <%= f.check_box :option_comment_display, as: :check_boxes%><%= f.label t("org_admin.questions.option_comment_display_checkbox"), class: "checkbox inline"%> +
    +
    + + +
    + + +
    + +
    +
    +
    + + - - - <%= t("org_admin.questions.suggested_or_example_answer_label")%> -
    - <% suggested_answer = question.suggested_answers.find_by_organisation_id(current_user.organisation.id) %> - <% if suggested_answer.nil? then %> - <% suggested_answer = question.suggested_answers.build %> - <%end%> - <%= f.fields_for :suggested_answers, suggested_answer do |s|%> - <%= s.hidden_field :organisation_id, :value => current_user.organisation.id %> - - <%end%> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "suggested_answer_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.suggested_answer_help_text_html"))%> -
    -
    -
    - - - - - <%= t("org_admin.questions.guidance_label")%> -
    - <%= text_area_tag("question-guidance-#{question.id}", question.guidance , class: "tinymce") %> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "question_guidance_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%> -
    -
    -
    - - - - - <%= t("org_admin.questions.themes_label")%> -
    - <%= f.collection_select(:theme_ids, - Theme.all.order("title"), - :id, :title, {:prompt => false, :include_blank => "None"}, {:multiple => true})%> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "question_themes_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%> -
    - - - -
    - -
    - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <% if !question.section.version.published? then%> - <%= link_to t("helpers.submit.delete"), admin_destroyquestion_dmptemplate_path(:question_id => question.id), - :confirm => t("org_admin.questions.delete_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> - <%end%> - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("helpers.submit.cancel"), "#", :class => "btn cancel cancel_edit_question" %> -
    - + + + <%= t("org_admin.questions.suggested_or_example_answer_label")%> +
    + <% suggested_answer = question.suggested_answers.find_by_org_id(current_user.org.id) %> + <% if suggested_answer.nil? %> + <% suggested_answer = question.suggested_answers.build %> + <% end %> + <%= f.fields_for :suggested_answers, suggested_answer do |s|%> + <%= s.hidden_field :org_id, value: current_user.org.id %> + + <% end %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "suggested_answer_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.suggested_answer_help_text_html"))%> +
    +
    +
    + + + + + <%= t("org_admin.questions.guidance_label")%> +
    + <%= text_area_tag("question-guidance-#{question.id}", question.guidance , class: "tinymce") %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "question_guidance_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_guidance_help_text_html"))%> +
    +
    +
    + + + + + <%= t("org_admin.questions.themes_label")%> +
    + <%= f.collection_select(:theme_ids, + Theme.all.order("title"), + :id, :title, {prompt: false, include_blank: "None"}, {multiple: true})%> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "question_themes_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.questions.question_themes_help_text_html"))%> +
    + + + +
    + +
    + <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <% if !question.section.phase.template.published? %> + <%= link_to t("helpers.submit.delete"), admin_destroyquestion_template_path(question_id: question.id), + confirm: t("org_admin.questions.delete_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <% end %> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t("helpers.submit.cancel"), "#", class: "btn cancel cancel_edit_question" %> +
    + -<%= render :partial => "guidance_display", locals: {question: question}%> -<%end%> +<%= render partial: "guidance_display", locals: {question: question} %> +<% end %> diff --git a/app/views/templates/_edit_section.html.erb b/app/views/templates/_edit_section.html.erb index 8f7f8b4..22b7730 100644 --- a/app/views/templates/_edit_section.html.erb +++ b/app/views/templates/_edit_section.html.erb @@ -1,116 +1,116 @@ - -<%= form_for(section, :url => admin_updatesection_dmptemplate_path(section, :phase => phase, :edit => edit), :html => { :method => :put}) do |s| %> - <%if @open && @section_id == section.id then%> - <% toggle = 'accordion-body section-collapse in collapse'%> - <%else%> - <% toggle = 'accordion-body collapse section-collapse' %> - <%end%> +<%= form_for(section, url: admin_updatesection_template_path(section, phase: phase, edit: edit), html: { method: :put}) do |s| %> + <% if @open && @section_id == section.id then%> + <% toggle = 'accordion-body section-collapse in collapse'%> + <% else %> + <% toggle = 'accordion-body collapse section-collapse' %> + <% end %> - <%if @new_sec then%> - <% toggle = 'accordion-body section-collapse in collapse'%> - <%end%> + <% if @new_sec %> + <% toggle = 'accordion-body section-collapse in collapse'%> + <% end %> -
    -
    -
    -
    - <%= s.text_field :title, :as => :string, :class => 'text_field', :placeholder => t('org_admin.templates.section_title_placeholder') %> +
    +
    +
    +
    + <%= s.text_field :title, as: :string, class: 'text_field', placeholder: t('org_admin.templates.section_title_placeholder') %> -
    -
    - -
    +
    +
    + +
    -
    -
    - - - - - - - - - -
    <%= t('org_admin.templates.phase_order_label') %><%= s.number_field :number, :in => 1..15, :class => "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.section_number_help_text') %>
    <%= t('org_admin.templates.desc_label') %> -
    - <%= text_area_tag("section-desc-#{section.id}", section.description , class: "tinymce") %> -
    -
    - <%= link_to( image_tag('help_button.png'), '#', :class => 'section_desc_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.section_desc_help_text_html'))%> -
    -
    - -
    - <%= s.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <% if !section.version.published? || phase.dmptemplate.org_type == constant("organisation_types.funder") then%> - <%= link_to t("helpers.submit.delete"), admin_destroysection_dmptemplate_path(:section_id => section.id), - :confirm => t("org_admin.templates.section_delete_message", :section_title => section.title ), :method => :delete, :class => "btn btn-primary"%> - <%end%> - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn cancel' %> -
    - <%end%> -
    - <% @questions = section.questions.order("number")%> - <%if @questions.count > 0 %> - <% question_left = @questions.count %> - <% @questions.each do |question| %> -
    -
    "> - - <%= render :partial => 'show_question', locals: {question: question} %> -
    +
    +
    + + + + + + + + + +
    <%= t('org_admin.templates.phase_order_label') %><%= s.number_field :number, in: 1..15, class: "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.section_number_help_text') %>
    <%= t('org_admin.templates.desc_label') %> +
    + <%= text_area_tag("section-desc-#{section.id}", section.description , class: "tinymce") %> +
    +
    + <%= link_to( image_tag('help_button.png'), '#', class: 'section_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.section_desc_help_text_html'))%> +
    +
    + +
    + <%= s.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <% if section.modifiable %> + <%= link_to t("helpers.submit.delete"), admin_destroysection_template_path(section_id: section.id), + confirm: t("org_admin.templates.section_delete_message", section_title: section.title ), method: :delete, class: "btn btn-primary"%> + <% end %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %> +
    +<% end %> +
    + <% @questions = section.questions.order("number")%> + <% if @questions.count > 0 %> + <% question_left = @questions.count %> + <% @questions.each do |question| %> +
    +
    "> + + <%= render partial: 'show_question', locals: {question: question} %> +
    - -
    - - <%if question_left.to_i > 1 then %> -
    - <%else%> -
    - <%end%> - <% question_left = question_left - 1 %> + +
    + + <% if question_left.to_i > 1 %> +
    + <% else %> +
    + <% end %> + <% question_left = question_left - 1 %> - <%end%> - <%end%> + <% end %> + <% end %> - - <% if !section.version.published? || phase.dmptemplate.org_type == constant("organisation_types.funder") then%> + + <% if section.modifiable %> - <%if @questions.count != 0 %> -
    - <%end%> - - + <% if @questions.count != 0 %> +
    + <% end%> + + - -
    -
    - <%= hidden_field_tag :section_id, section.id, :class => "section_id" %> - <%= link_to t("org_admin.add_question_label"), '#', :class => "btn btn-primary add_question_button" %> -
    -
    - <%end%> + +
    +
    + <%= hidden_field_tag :section_id, section.id, class: "section_id" %> + <%= link_to t("org_admin.add_question_label"), '#', class: "btn btn-primary add_question_button" %> +
    +
    + <% end %> -
    -
    -
    -
    +
    +
    +
    +
    diff --git a/app/views/templates/_edit_suggested_answer.html.erb b/app/views/templates/_edit_suggested_answer.html.erb index 2f78934..fe20950 100644 --- a/app/views/templates/_edit_suggested_answer.html.erb +++ b/app/views/templates/_edit_suggested_answer.html.erb @@ -1,26 +1,26 @@ -<%= form_for(suggested_answer, :url => admin_updatesuggestedanswer_dmptemplate_path(suggested_answer), :html => { :method => :put}) do |f| %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> +<%= form_for(suggested_answer, url: admin_updatesuggestedanswer_template_path(suggested_answer), html: { method: :put}) do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_id %> - - - - - -
    <%= t('org_admin.questions.suggested_or_example_answer_label')%> -
      -
    • <%= f.select :is_example, {t('org_admin.questions.example_answer_label') => true, t('org_admin.questions.suggested_answer_label') => false} %>
    • -
    • <%= f.text_area :text, :rows => 5 %>
    • -
    -
    -
    + + + + + +
    <%= t('org_admin.questions.suggested_or_example_answer_label')%> +
      +
    • <%= f.select :is_example, {t('org_admin.questions.example_answer_label') => true, t('org_admin.questions.suggested_answer_label') => false} %>
    • +
    • <%= f.text_area :text, rows: 5 %>
    • +
    +
    +
    - -
    - <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t("helpers.submit.delete"), admin_destroysuggestedanswer_dmptemplate_path(:suggested_answer => suggested_answer.id), - :confirm => t("org_admin.questions.delete_suggested_answer_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t('helpers.submit.cancel'), '#', :class => 'btn cancel cancel_edit_suggested_answer' %> -
    -<%end%> + +
    + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t("helpers.submit.delete"), admin_destroysuggestedanswer_template_path(suggested_answer: suggested_answer.id), + confirm: t("org_admin.questions.delete_suggested_answer_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t('helpers.submit.cancel'), '#', class: 'btn cancel cancel_edit_suggested_answer' %> +
    +<% end %> diff --git a/app/views/templates/_edit_template.html.erb b/app/views/templates/_edit_template.html.erb index dbea10a..3dc7154 100644 --- a/app/views/templates/_edit_template.html.erb +++ b/app/views/templates/_edit_template.html.erb @@ -1,52 +1,52 @@ -<%= form_for(dmptemplate, :url => admin_update_dmptemplate_path(dmptemplate), :html => { :method => :put}) do |f| %> -
    - - - - - - - - - - - - - - - - - - - - - -
    <%= t('org_admin.templates.title_label') %><%= f.text_field :title, :as => :string, - :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.title_help_text') %>
    <%= t('org_admin.templates.desc_label') %>
    - <%= text_area_tag("template-desc", dmptemplate.description, class: "tinymce") %> -
    -
    - <%= link_to( image_tag('help_button.png'), '#', :class => 'template_desc_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.desc_help_text_html'))%> -
    -
    <%= t('org_admin.templates.published_label') %><%if dmptemplate.published? || dmptemplate.has_published_versions? then%> - <%= f.check_box :published, :as => :check_boxes %> - <%else%> - <%= t('org_admin.templates.cannot_publish')%> - <%end%> -
    <%= t('org_admin.templates.created') %> - <%= l dmptemplate.created_at.to_date, :formats => :short %> -
    <%= t('org_admin.templates.last_updated') %> - <%= l dmptemplate.updated_at.to_date, :formats => :short %> -
    - - -
    - <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t('helpers.submit.cancel'), admin_template_dmptemplate_path(dmptemplate), :class => 'btn cancel' %> -
    - -
    - -<%end%> \ No newline at end of file +<%= form_for(template, url: admin_update_template_path(template), html: { method: :put}) do |f| %> +
    + + + + + + + + + + + + + + + + + + + + + +
    <%= t('org_admin.templates.title_label') %><%= f.text_field :title, as: :string, + class: 'text_field has-tooltip', 'data-toggle' => "tooltip", title: t('org_admin.templates.title_help_text') %>
    <%= t('org_admin.templates.desc_label') %>
    + <%= text_area_tag("template-desc", template.description, class: "tinymce") %> +
    +
    + <%= link_to( image_tag('help_button.png'), '#', class: 'template_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.desc_help_text_html'))%> +
    +
    <%= t('org_admin.templates.published_label') %><% if template.published? %> + <%= f.check_box :published, as: :check_boxes %> + <% else %> + <%= t('org_admin.templates.cannot_publish')%> + <% end %> +
    <%= t('org_admin.templates.created') %> + <%= l template.created_at.to_date, formats: :short %> +
    <%= t('org_admin.templates.last_updated') %> + <%= l template.updated_at.to_date, formats: :short %> +
    + + +
    + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), admin_template_template_path(template), class: 'btn cancel' %> +
    + +
    + +<% end %> \ No newline at end of file diff --git a/app/views/templates/_edit_version.html.erb b/app/views/templates/_edit_version.html.erb deleted file mode 100644 index 416fdb7..0000000 --- a/app/views/templates/_edit_version.html.erb +++ /dev/null @@ -1,47 +0,0 @@ - - - -<%= form_for(version, :url => admin_updateversion_dmptemplate_path(version, :edit => edit, :phase => phase), :html => { :method => :put}) do |f| %> - -

    - <%= t('org_admin.templates.version_details_label')%> -

    -
    - -
    - - - - - - - - - - - - - - - -
    <%= t('org_admin.templates.title_label') %><%= f.text_field :title, :as => :string, - :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_title_help_text') %>
    <%= t('org_admin.templates.desc_label') %>
    - <%= text_area_tag("version-desc", version.description, class: "tinymce") %> -
    -
    - <%= link_to( image_tag('help_button.png'), '#', :class => 'version_desc_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.versions.desc_help_text_html'))%> -
    -
    <%= t('org_admin.templates.published_label') %><%= f.check_box :published, :as => :check_boxes %>
    - -
    - -
    - <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t('helpers.submit.cancel'), admin_phase_dmptemplate_path(phase), :class => 'btn cancel' %> -
    -
    - -<%end%> - - - \ No newline at end of file diff --git a/app/views/templates/_guidance_display.html.erb b/app/views/templates/_guidance_display.html.erb index 4082baf..9a0755a 100644 --- a/app/views/templates/_guidance_display.html.erb +++ b/app/views/templates/_guidance_display.html.erb @@ -1,36 +1,36 @@
    -
    - <% if !question.guidance.nil? && question.guidance != "" then %> - - <% end %> - - <% question.guidance_for_question(question, current_user.organisation).each_pair do |title,guidance| %> -
    - -
    -
    <%= raw guidance.text %>
    -
    -
    - <% end %> -
    - -
    \ No newline at end of file +
    + <% if !question.guidance.nil? && question.guidance != "" %> + + <% end %> + + <% question.guidance_for_org(current_user.org).each_pair do |title,guidance| %> +
    + +
    +
    <%= raw guidance.text %>
    +
    +
    + <% end %> +
    + + \ No newline at end of file diff --git a/app/views/templates/_option_fields.html.erb b/app/views/templates/_option_fields.html.erb index 21f3e80..5182510 100644 --- a/app/views/templates/_option_fields.html.erb +++ b/app/views/templates/_option_fields.html.erb @@ -1,7 +1,7 @@ - <%= f.number_field :number,:in => 1..20, :class => "number_field option"%> - <%= f.text_field :text, :as => :string, :class => "small_text_field" %> - <%= f.check_box :is_default %> - <%= f.hidden_field :_destroy %><%= t('org_admin.remove_option_label') %> + <%= f.number_field :number, in: 1..20, class: "number_field option"%> + <%= f.text_field :text, as: :string, class: "small_text_field" %> + <%= f.check_box :is_default %> + <%= f.hidden_field :_destroy %><%= t('org_admin.remove_option_label') %> diff --git a/app/views/templates/_preview_question.html.erb b/app/views/templates/_preview_question.html.erb index fa75e30..37d3fb1 100644 --- a/app/views/templates/_preview_question.html.erb +++ b/app/views/templates/_preview_question.html.erb @@ -1,124 +1,124 @@
    - - - <% q_format = question.question_format%> -
    -
    - - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> - <% options = question.options.order("number") %> - - - <% if q_format.title == t("helpers.checkbox") then %> - <%if !options.nil? then %> -
    - -
      - <% options.each do |op|%> -
    1. - <%end%> -
    -
    - <%end%> - - <% elsif q_format.title == t("helpers.multi_select_box") then %> - <%if !options.nil? then %> - - - <%end%> - - <% elsif q_format.title == t("helpers.radio_buttons") then%> - <%if !options.nil? then %> -
    - -
      - <% options.each do |op|%> -
    1. - <%end%> -
    -
    - <%end%> - - <% elsif q_format.title == t("helpers.dropdown") then%> - <%if !options.nil? then %> - - - <%end%> - <% end %> - - - <% suggested_answer = question.suggested_answers.find_by_organisation_id(current_user.organisation_id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" then %> -
    - - <% if suggested_answer.is_example? then %> - <%= t("org_admin.questions.example_answer_label")%> - <%else%> - <%= t("org_admin.questions.suggested_answer_label")%> - <%end%> - -
    -

    - <%= raw suggested_answer.text %> -

    -
    -
    - <% end %> - -
    - - <% else %> - - - <% suggested_answer = question.suggested_answers.find_by_organisation_id(current_user.organisation_id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" then %> -
    - - <% if suggested_answer.is_example? then %> - <%= t("org_admin.questions.example_answer_label")%> - <%else%> - <%= t("org_admin.questions.suggested_answer_label")%> - <%end%> - -
    -

    - <%= raw suggested_answer.text %> -

    -
    -
    - <% end %> - - <% end %> - - - - - <% if q_format.title == t("helpers.text_field") then %> - - - <%elsif q_format.title == t("helpers.text_area") then%> - - <%end%> -
    - - <%= link_to t("helpers.save"), "#", :class => "btn btn-primary", :onclick => "event.preventDefault();" %> - - <%= t("helpers.notanswered") %> - -
    -
    -
    - + + <% q_format = question.question_format%> +
    +
    + + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %> + <% options = question.question_options.order("number") %> + + + <% if q_format.title == t("helpers.checkbox") %> + <%if !options.nil? %> +
    + +
      + <% options.each do |op|%> +
    1. + <% end %> +
    +
    + <% end %> + + <% elsif q_format.title == t("helpers.multi_select_box") %> + <% if !options.nil? %> + + + <% end %> + + <% elsif q_format.title == t("helpers.radio_buttons") %> + <% if !options.nil? %> +
    + +
      + <% options.each do |op|%> +
    1. + <% end %> +
    +
    + <% end %> + + <% elsif q_format.title == t("helpers.dropdown") %> + <% if !options.nil? %> + + + <% end %> + <% end %> + + + <% suggested_answer = question.suggested_answers.find_by(org_id: current_user.org_id) %> + <% if !suggested_answer.blank? %> +
    + + <% if suggested_answer.is_example? %> + <%= t("org_admin.questions.example_answer_label")%> + <% else %> + <%= t("org_admin.questions.suggested_answer_label")%> + <% end %> + +
    +

    + <%= raw suggested_answer.text %> +

    +
    +
    + <% end %> + +
    + + <% else %> + + + <% suggested_answer = question.suggested_answers.find_by(org_id: current_user.org_id) %> + <% if !suggested_answer.blank? %> +
    + + <% if suggested_answer.is_example? %> + <%= t("org_admin.questions.example_answer_label")%> + <% else %> + <%= t("org_admin.questions.suggested_answer_label")%> + <% end %> + +
    +

    + <%= raw suggested_answer.text %> +

    +
    +
    + <% end %> + + <% end %> + + + + + <% if q_format.title == t("helpers.text_field") %> + + + <%elsif q_format.title == t("helpers.text_area") %> + + <%end%> +
    + + <%= link_to t("helpers.save"), "#", class: "btn btn-primary", onclick: "event.preventDefault();" %> + + <%= t("helpers.notanswered") %> + +
    +
    + + + -<%= render :partial => "guidance_display", locals: {question: question}%> +<%= render partial: "guidance_display", locals: {question: question}%> diff --git a/app/views/templates/_show_phase.html.erb b/app/views/templates/_show_phase.html.erb index 01117cf..f110902 100644 --- a/app/views/templates/_show_phase.html.erb +++ b/app/views/templates/_show_phase.html.erb @@ -1,37 +1,37 @@

    - <%= t('org_admin.templates.phase_details_label')%> + <%= t('org_admin.templates.phase_details_label')%> - - <% if @phase.dmptemplate.org_type != constant("organisation_types.funder") || current_user.org_type == constant("organisation_types.funder") then %> -
    - <%= link_to t("org_admin.templates.edit_phase_details_label"), '#', :class => "btn btn-primary", :id => "edit_phase_button"%> -
    - <%end%> + + <% if @phase.modifiable %> +
    + <%= link_to t("org_admin.templates.edit_phase_details_label"), '#', class: "btn btn-primary", id: "edit_phase_button"%> +
    + <% end %>

    -<%if @phase.dmptemplate.org_type != constant("organisation_types.funder") then%> -
    - <%= raw t('org_admin.templates.phase_details_text_html')%> -
    -<%end%> +<% if @phase.template.org.not_funder %> +
    + <%= raw t('org_admin.templates.phase_details_text_html')%> +
    +<% end %>
    - - - - - - - - - - - - + + + + + + + + + + + +
    <%= t('org_admin.templates.title_label') %><%= @phase.title %>
    <%= t('org_admin.templates.phase_order_label') %><%= @phase.number %>
    <%= t('org_admin.templates.desc_label') %><%= raw @phase.description %>
    <%= t('org_admin.templates.title_label') %><%= @phase.title %>
    <%= t('org_admin.templates.phase_order_label') %><%= @phase.number %>
    <%= t('org_admin.templates.desc_label') %><%= raw @phase.description %>
    diff --git a/app/views/templates/_show_phases_sections.html.erb b/app/views/templates/_show_phases_sections.html.erb index 19c603a..63f5a08 100644 --- a/app/views/templates/_show_phases_sections.html.erb +++ b/app/views/templates/_show_phases_sections.html.erb @@ -3,71 +3,60 @@
    -

    <%= raw phase.description %>

    +

    <%= raw phase.description %>

    -<% if phase.versions.any? then %> - - <% version = phase.versions.where("published = ?", true).first %> - <% if version.nil? then%> - <% version = phase.versions.order("updated_at DESC").first %> - <%end%> -
    - +
    + - <%if phase.has_sections == true then %> - <%= link_to t("helpers.preview"), admin_previewphase_dmptemplate_path(version), :class => 'btn btn-primary'%> - <%end%> - <% if phase.latest_published_version == nil then%> - <%= link_to t("helpers.submit.delete"), admin_destroyphase_dmptemplate_path(:phase_id => phase.id), - :confirm => t("org_admin.templates.phase_delete_message", :phase_title => phase.title ), :method => :delete, :class => "btn btn-primary"%> - <%end%> - <%if phase.dmptemplate.org_type == constant("organisation_types.funder") && current_user.org_type != constant("organisation_types.funder") then%> - <% b_label = t('org_admin.templates.view_phase_label')%> - <%else %> - <% b_label = t('org_admin.templates.edit_phase_label')%> - <%end%> - <%= link_to b_label, admin_phase_dmptemplate_path(phase), :class => "btn btn-primary" %> + <% if phase.sections.length > 0 %> + <%= link_to t("helpers.preview"), admin_previewphase_template_path(phase), class: 'btn btn-primary'%> + <% end %> + <% if !phase.template.published? %> + <%= link_to t("helpers.submit.delete"), admin_destroyphase_template_path(phase_id: phase.id), + confirm: t("org_admin.templates.phase_delete_message", phase_title: phase.title ), method: :delete, class: "btn btn-primary"%> + <% end %> + <% if !phase.modifiable %> + <% b_label = t('org_admin.templates.view_phase_label')%> + <% else %> + <% b_label = t('org_admin.templates.edit_phase_label')%> + <% end %> + <%= link_to b_label, admin_phase_template_path(id: phase.id, edit: (b_label == t('org_admin.templates.edit_phase_label'))), class: "btn btn-primary" %> -
    - <% if version.sections.any? then %> - - - - - - - - - <% version.sections.order("number ASC").each do |section| %> - <%if (section.organisation_id == phase.dmptemplate.organisation_id ) || ( section.organisation_id == current_user.organisation_id) then%> - - - - - <%end%> - <%end%> - -
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    -

    <%= section.title %>

    -
    - <% if section.questions.any? %> - <% questions = section.questions.order("number ASC") %> -
      - <% questions.each do |ques|%> -
    • - - <%= raw ques.text %> -
    • - <%end%> -
    - <%end%> -
    - - <%end%> - -<%end%> +
    + <% if phase.sections.any? %> + + + + + + + + + <% phase.sections.order("number ASC").each do |section| %> + + + + + <% end %> + +
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    +

    <%= section.title %>

    +
    + <% if section.questions.any? %> + <% questions = section.questions.order("number ASC") %> +
      + <% questions.each do |ques|%> +
    • + - <%= raw ques.text %> +
    • + <% end %> +
    + <% end %> +
    + <% end %>
    diff --git a/app/views/templates/_show_question.html.erb b/app/views/templates/_show_question.html.erb index df79c2b..122c44f 100644 --- a/app/views/templates/_show_question.html.erb +++ b/app/views/templates/_show_question.html.erb @@ -1,153 +1,148 @@ -
    - - - - - - +
    <%= t('org_admin.questions.question_number_label')%><%= question.number%>
    + + + + + - - - - - - - <%if q_format.title == t("helpers.text_field") || q_format.title == t("helpers.text_area") then %> - <%if !question.default_value.nil? then %> - - - - - <%end%> - <% end %> - - - - - + + + + + + + <% if q_format.title == t("helpers.text_field") || q_format.title == t("helpers.text_area") %> + <% if !question.default_value.nil? %> + + + + + <% end %> + <% end %> + + + + + - - <% if (question.section.version.phase.dmptemplate.org_type != constant("organisation_types.funder") && question.section.organisation_id == current_user.organisation_id ) then%> - <% suggested_answer = question.get_suggested_answer(current_user.organisation.id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" then %> - - - - - <%end%> - <%end%> - - <%if !question.guidance.nil? then %> - - - - - <%end%> - - <% themes_q = question.themes %> - <%if !themes_q.nil? then%> - - - - - <%end%> -
    <%= t('org_admin.questions.question_number_label')%><%= question.number %>
    <%= t('org_admin.questions.question_text_label')%><%= raw question.text %> -
    -
    - <% q_format = question.question_format %> - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> -
      - <% if question.options.is_a? Option then %> -
    • - <%= question.options.text %>
    • - <% else %> - <% if !question.options.to_a.nil? then %> - <% question.options.to_a.sort_by{|op| op['number']}.each do |o| %> -
    • - <%= o.text %>
    • - <%end%> - <% end %> - <% end %> -
    - <% end %> -
    -
    <%= t('org_admin.questions.default_value_label')%><%= raw question.default_value %>
    <%= t('org_admin.questions.answer_format_label')%><%= q_format.title %> -
    - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> - <% if question.option_comment_display == true then%> - <%= t("org_admin.questions.option_comment_display")%> - <%else%> - <%= t("org_admin.questions.option_comment_hide")%> - <%end%> - <%end%> -
    -
    <%= t('org_admin.questions.question_text_label')%><%= raw question.text %> +
    +
    + <% q_format = question.question_format %> + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %> +
      + <% if question.question_options.is_a? QuestionOption %> +
    • - <%= question.question_options.text %>
    • + <% else %> + <% if !question.question_options.to_a.nil? %> + <% question.question_options.to_a.sort_by{|op| op['number']}.each do |o| %> +
    • - <%= o.text %>
    • + <% end %> + <% end %> + <% end %> +
    + <% end %> +
    +
    <%= t('org_admin.questions.default_value_label')%><%= raw question.default_value %>
    <%= t('org_admin.questions.answer_format_label')%><%= q_format.title %> +
    + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %> + <% if question.option_comment_display == true %> + <%= t("org_admin.questions.option_comment_display")%> + <% else %> + <%= t("org_admin.questions.option_comment_hide")%> + <% end %> + <% end %> +
    +
    - <% if suggested_answer.is_example? then %> - <%= t('org_admin.questions.example_answer_label')%> - <%else%> - <%= t('org_admin.questions.suggested_answer_label')%> - <%end%> - <%= raw suggested_answer.text %>
    <%= t('org_admin.questions.guidance_label')%><%= raw question.guidance %>
    <%= t('org_admin.questions.themes_label')%><% i = 1%> - <% themes_q.each do |t|%> - <%= t.title %> - <% if themes_q.count > i then%> - , - <% i +=1 %> - <% end %> - <%end%> -
    -
    - - <% if (question.section.version.phase.dmptemplate.org_type == constant("organisation_types.funder") && question.section.organisation_id != current_user.organisation_id ) then%> - <% suggested_answer = question.get_suggested_answer(current_user.organisation.id) %> - <% if !suggested_answer.nil? && suggested_answer.text != "" then %> -
    - <%= render :partial => 'show_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %> -
    - + + <% if question.section.phase.template.org_type != constant("organisation_types.funder") %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if !suggested_answer.nil? && suggested_answer.text != "" %> + + + <% if suggested_answer.is_example? %> + <%= t('org_admin.questions.example_answer_label')%> + <% else %> + <%= t('org_admin.questions.suggested_answer_label')%> + <% end %> + + <%= raw suggested_answer.text %> + + <% end %> + <% end %> + + <% if !question.guidance.nil? %> + + <%= t('org_admin.questions.guidance_label')%> + <%= raw question.guidance %> + + <% end %> + + <% themes_q = question.themes %> + <% if !themes_q.nil? %> + + <%= t('org_admin.questions.themes_label')%> + <% i = 1%> + <% themes_q.each do |t|%> + <%= t.title %> + <% if themes_q.count > i %> + , + <% i +=1 %> + <% end %> + <% end %> + + + <% end %> + +
    + + <% if !question.modifiable %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if !suggested_answer.nil? && suggested_answer.text != "" %> +
    + <%= render partial: 'show_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %> +
    + + <% end %> + + <% end %> - <%end%> - - - - - - <%end%> - -
    - - <%if (@edit == 'true'&& question.section.organisation_id == current_user.organisation_id) || (question.section.version.phase.dmptemplate.org_type == constant("organisation_types.funder") && question.section.organisation_id == current_user.organisation_id && current_user.org_type != constant("organisation_types.funder")) then%> -
    - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("org_admin.questions.question_edit_button"), '# ', :class => "btn btn-primary edit_question_button"%> - <% if !question.section.version.published? then%> - <%= link_to t("org_admin.questions.question_delete_button"), admin_destroyquestion_dmptemplate_path(:question_id => question.id), - :confirm => t("org_admin.questions.delete_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> - <%end%> -
    - <%elsif (@edit == 'false' && question.section.organisation_id != current_user.organisation_id )|| (question.section.version.phase.dmptemplate.org_type == constant("organisation_types.funder") && question.section.organisation_id != current_user.organisation_id ) then%> - <% suggested_answer = question.get_suggested_answer(current_user.organisation.id) %> - <% if suggested_answer.nil? then %> -
    -
    - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("org_admin.questions.suggested_or_example_answer_button"), '# ', :class => "btn btn-primary add_suggested_answer_button"%> -
    -
    - <%end%> - <%end%> -
    +
    + + <% if (@edit && question.modifiable) %> +
    + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t("org_admin.questions.question_edit_button"), '# ', class: "btn btn-primary edit_question_button"%> + <% if !question.section.published? %> + <%= link_to t("org_admin.questions.question_delete_button"), admin_destroyquestion_template_path(question_id: question.id), + confirm: t("org_admin.questions.delete_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <% end %> +
    + <% elsif !@edit && question.modifiable %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if suggested_answer.nil? %> +
    +
    + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t("org_admin.questions.suggested_or_example_answer_button"), '# ', class: "btn btn-primary add_suggested_answer_button"%> +
    +
    + <% end %> + <% end %> +
    -<%= render :partial => 'guidance_display', locals: {question: question}%> +<%= render partial: 'guidance_display', locals: {question: question}%> diff --git a/app/views/templates/_show_section.html.erb b/app/views/templates/_show_section.html.erb index 1dbf719..128728e 100644 --- a/app/views/templates/_show_section.html.erb +++ b/app/views/templates/_show_section.html.erb @@ -1,43 +1,41 @@ -<%if @open && @section_id == section.id then%> - <% toggle = 'accordion-body section-collapse in collapse'%> -<%else%> - <% toggle = 'accordion-body collapse section-collapse' %> -<%end%> +<% if @open && @section_id == section.id %> + <% toggle = 'accordion-body section-collapse in collapse'%> +<% else %> + <% toggle = 'accordion-body collapse section-collapse' %> +<% end %>
    -
    - -
    - <% if section.title == '' then%> - <%= t('org_admin.templates.new_section')%> - <%else%> - <%= section.title %> - <%end%> -
    - - -
    + -
    -
    - <%= raw section.description %> -
    -
    - <% section.questions.order("number").each do |question| %> - <% last_question_id = section.questions.order("number DESC").first.id %> - -
    - - <%= render :partial => 'show_question', locals: {question: question}%> -
    +
    +
    + <%= raw section.description %> +
    +
    + <% last_question_id = section.questions.order("number DESC").first.id %> + <% section.questions.order("number").each do |question| %> +
    + + <%= render partial: 'show_question', locals: {question: question}%> +
    - <% if last_question_id == question.id then %> -
    - <% else %> -
    - <% end %> - - <%end%> -
    -
    + <% if last_question_id == question.id %> +
    + <% else %> +
    + <% end %> + <% end %> +
    +
    diff --git a/app/views/templates/_show_suggested_answer.html.erb b/app/views/templates/_show_suggested_answer.html.erb index 888dd45..c760bc9 100644 --- a/app/views/templates/_show_suggested_answer.html.erb +++ b/app/views/templates/_show_suggested_answer.html.erb @@ -4,9 +4,9 @@ <% if suggested_answer.is_example? then %> <%= t('org_admin.questions.example_answer_label')%> - <%else%> + <% else %> <%= t('org_admin.questions.suggested_answer_label')%> - <%end%> + <% end %> <%= raw suggested_answer.text %> @@ -14,6 +14,6 @@
    - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= link_to t("org_admin.questions.edit_suggested_answer_button"), '# ', :class => "btn btn-primary edit_form_for_suggested_answer"%> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t("org_admin.questions.edit_suggested_answer_button"), '# ', class: "btn btn-primary edit_form_for_suggested_answer"%>
    diff --git a/app/views/templates/_show_template.html.erb b/app/views/templates/_show_template.html.erb index 7cfec9d..cd60ea3 100644 --- a/app/views/templates/_show_template.html.erb +++ b/app/views/templates/_show_template.html.erb @@ -1,43 +1,43 @@ -<% if @dmptemplate.org_type != constant("organisation_types.funder") || current_user.org_type == constant("organisation_types.funder") then %> -

    -
    - <%= link_to t("org_admin.templates.edit_details"), '# ', :class => "btn btn-primary", :id => "edit_template_button"%> -
    -

    -<%end%> -
    +<% if template.org.not_funder? || current_user.org.funder? then %> +

    +
    + <%= link_to t("org_admin.templates.edit_details"), '# ', class: "btn btn-primary", id: "edit_template_button"%> +
    +

    +<% end %> +
    - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + +
    <%= t('org_admin.templates.title_label') %><%= dmptemplate.title %>
    <%= t('org_admin.templates.desc_label') %><% if !dmptemplate.description.nil? && dmptemplate.description != "" then %> - <%= raw dmptemplate.description %> - <%else%> - - - <%end%> -
    <%= t('org_admin.templates.published_label') %><%if dmptemplate.published || dmptemplate.has_published_versions? then%> - <%= dmptemplate.published %> - <%else%> - <%= t('org_admin.templates.cannot_publish')%> - <%end%> -
    <%= t('org_admin.templates.created') %><%= l dmptemplate.created_at.to_date, :formats => :short %>
    <%= t('org_admin.templates.last_updated') %><%= l dmptemplate.updated_at.to_date, :formats => :short %>
    <%= t('org_admin.templates.title_label') %><%= template.title %>
    <%= t('org_admin.templates.desc_label') %><% if !template.description.nil? && template.description != "" then %> + <%= raw template.description %> + <% else %> + - + <% end %> +
    <%= t('org_admin.templates.published_label') %><% if template.published then%> + <%= template.published %> + <% else %> + <%= t('org_admin.templates.cannot_publish')%> + <% end %> +
    <%= t('org_admin.templates.created') %><%= l template.created_at.to_date, formats: :short %>
    <%= t('org_admin.templates.last_updated') %><%= l template.updated_at.to_date, formats: :short %>
    diff --git a/app/views/templates/_show_version.html.erb b/app/views/templates/_show_version.html.erb deleted file mode 100644 index 3e1456e..0000000 --- a/app/views/templates/_show_version.html.erb +++ /dev/null @@ -1,42 +0,0 @@ - - - -

    - <%= t('org_admin.templates.version_details_label')%> -

    -
    - - - - - - - <% if version.description != "" then%> - - - - - <%end%> - - - - - - - - - - - - -
    <%= t('org_admin.templates.title_label') %><%= version.title %>
    <%= t('org_admin.templates.desc_label') %><%= raw version.description %>
    <%= t('org_admin.templates.published_label') %><%= version.published %>
    <%= t('org_admin.templates.created') %> - <%= l version.created_at.to_date, :formats => :short %> -
    <%= t('org_admin.templates.last_updated') %> - <%= l version.updated_at.to_date, :formats => :short %> -
    -
    - - - - - diff --git a/app/views/templates/_versions_table.html.erb b/app/views/templates/_versions_table.html.erb deleted file mode 100644 index e51dbfe..0000000 --- a/app/views/templates/_versions_table.html.erb +++ /dev/null @@ -1,73 +0,0 @@ -<%if !phase.versions.nil? then %> -
    -

    <%= t('org_admin.templates.versions_label')%>

    -

    - <%= t('org_admin.versions.versions_text_html')%> -

    - - - - - - - - - - - - - - <% phase.versions.each do |v|%> - - - - - - - - - - - - - <%end%> - -
    <%= t('org_admin.templates.title_label')%><%= t('org_admin.templates.published_label')%><%= t('org_admin.templates.created')%><%= t('org_admin.templates.last_updated') %><%= t('org_admin.templates.actions') %>
    - <%= v.title %> - - <%= v.published %> - - <%= l v.created_at.to_date, :formats => :short %> - - <%= l v.updated_at.to_date, :formats => :short %> - - <%= link_to t("helpers.view"), admin_phase_dmptemplate_path( :version_id => v.id, :id => phase.id , :edit => 'false'), :class => "dmp_table_link"%> - <% if v.published? then%> - - <%= t('org_admin.versions.edit_label')%> - - <%= link_to t("helpers.preview"), admin_previewphase_dmptemplate_path(v), :class => "dmp_table_link" %> - <%else%> - <%= link_to t("org_admin.versions.edit_label"), admin_phase_dmptemplate_path(phase, :version_id => v.id, :edit => 'true'), :class => "dmp_table_link" %> - <%= link_to t("helpers.preview"), admin_previewphase_dmptemplate_path(v), :class => "dmp_table_link" %> - <%#= link_to t("helpers.submit.delete"), admin_destroyversion_dmptemplate_path(:version_id => v.id, :phase => phase , :edit => 'false'), - :confirm => t("org_admin.versions.delete_message", :version_title => v.title ), :method => :delete, :class => "dmp_table_link"%> - <%end%> -
    -
    - - - -<%end%> diff --git a/app/views/templates/admin_addphase.html.erb b/app/views/templates/admin_addphase.html.erb index 6e8a336..02c62ad 100644 --- a/app/views/templates/admin_addphase.html.erb +++ b/app/views/templates/admin_addphase.html.erb @@ -3,73 +3,73 @@ <% javascript "admin.js" %>

    - <%= @dmptemplate.title %> - -
    - <%= link_to t("org_admin.templates.view_all_templates"), - admin_index_dmptemplate_path, - :class => "btn btn-primary" %> -
    + <%= @template.title %> + +
    + <%= link_to t("org_admin.templates.view_all_templates"), + admin_index_template_path, + class: "btn btn-primary" %> +

    -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @dmptemplate, active: "add_plan"} %> +<%= render partial: "admin_nav_tabs", locals: {template: @template, active: "add_plan"} %>
    - - -
    -
    - - - <%= form_for :phase, :url => { :action => "admin_createphase"} do |f| %> -

    - <%= t("org_admin.templates.phase_details_label")%> -

    - <%= raw t("org_admin.templates.phase_new_text_html")%> -
    -
    - <%= f.hidden_field :dmptemplate_id, :value => @dmptemplate.id%> - - - - - - - - - - - - - -
    <%= t("org_admin.templates.title_label") %><%= f.text_field :title, - :as => :string, - :class => "text_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.phase_title_help_text") %>
    <%= t("org_admin.templates.phase_order_label") %><%= f.number_field :number, :in => 1..5, :class => "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.phase_number_help_text") %>
    <%= t("org_admin.templates.desc_label") %> -
    - <%= text_area_tag("phase-desc","" , class: "tinymce") %> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "phase_desc_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.templates.phase_desc_help_text_html"))%> -
    -
    -
    -
    - - -
    - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), admin_dmptemplate_path(@dmptemplate), :class => "btn cancel" %> -
    - - <%end%> -
    -
    -
    + + +
    +
    + + + <%= form_for :phase, url: { action: "admin_createphase"} do |f| %> +

    + <%= t("org_admin.templates.phase_details_label")%> +

    + <%= raw t("org_admin.templates.phase_new_text_html")%> +
    +
    + <%= f.hidden_field :template_id, value: @template.id%> + + + + + + + + + + + + + +
    <%= t("org_admin.templates.title_label") %><%= f.text_field :title, + as: :string, + class: "text_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.phase_title_help_text") %>
    <%= t("org_admin.templates.phase_order_label") %><%= f.number_field :number, in: 1..5, class: "number_field has-tooltip", "data-toggle" => "tooltip", title: t("org_admin.templates.phase_number_help_text") %>
    <%= t("org_admin.templates.desc_label") %> +
    + <%= text_area_tag("phase-desc","" , class: "tinymce") %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "phase_desc_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.templates.phase_desc_help_text_html"))%> +
    +
    +
    +
    + + +
    + <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.cancel"), admin_template_template_path(@template), class: "btn cancel" %> +
    + + <%end%> +
    +
    +
    - -<%= tinymce :content_css => asset_path("application.css") %> \ No newline at end of file + +<%= tinymce content_css: asset_path("application.css") %> \ No newline at end of file diff --git a/app/views/templates/admin_index.html.erb b/app/views/templates/admin_index.html.erb index 9af877a..4051b7d 100644 --- a/app/views/templates/admin_index.html.erb +++ b/app/views/templates/admin_index.html.erb @@ -1,72 +1,69 @@ <%= stylesheet_link_tag "admin" %>

    - <%= t('org_admin.templates_label') %> + <%= t('org_admin.templates_label') %>

    - <%= t('org_admin.templates.own_temp') %> + <%= t('org_admin.templates.own_temp') %>

    - <%= raw t('org_admin.templates.create_own_template_text_html')%> + <%= raw t('org_admin.templates.create_own_template_text_html')%>
    - -
    - <%= link_to t("org_admin.templates.create_template"), - admin_new_template_path, - :class => 'btn btn-primary' %> -
    + +
    + <%= link_to t("org_admin.templates.create_template"), + admin_new_template_path, + class: 'btn btn-primary' %> +
    -<% if @dmptemplates_own.count > 0 then %> - - - - - - - - - - - - <% @dmptemplates_own.each do |org_template| %> +<% if @templates_own.length > 0 then %> +
    <%= t('org_admin.templates.title_label') %><%= t('org_admin.templates.desc_label') %><%= t('org_admin.templates.published_label') %><%= t('org_admin.templates.last_updated') %><%= t('org_admin.templates.actions') %>
    + + + + + + + + + + + <% @templates_own.each do |org_template| %> - - - - - + + + + - - - <%end%> - -
    <%= t('org_admin.templates.title_label') %><%= t('org_admin.templates.desc_label') %><%= t('org_admin.templates.published_label') %><%= t('org_admin.templates.last_updated') %><%= t('org_admin.templates.actions') %>
    - <%= org_template.title%> - - <%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %> - - <%= org_template.published %> - - <% last_temp_updated = org_template.updated_at %> +
    + <%= org_template.title%> + + <%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %> + + <%= org_template.published %> + + <% last_temp_updated = org_template.updated_at %> <% org_template.phases.each do |phase|%> <% if org_template.updated_at.to_date < phase.updated_at.to_date then %> <% last_temp_updated = phase.updated_at %> <% end %> <% end %> - <%= l last_temp_updated.to_date, :formats => :short %> - - <%if current_user.can_org_admin? then%> - <% b_label = t('helpers.submit.edit')%> - <%else%> - <% b_label = t('helpers.view')%> - <%end%> - <%= link_to b_label, admin_template_template_path(org_template), :class => "dmp_table_link"%> -
    + <%= l last_temp_updated.to_date, formats: :short %> + + + <%= link_to t('helpers.submit.edit'), admin_template_template_path(id: org_template.id, edit: "true"), class: "dmp_table_link" %> + <%= link_to t('helpers.view'), admin_template_template_path(id: org_template), class: "dmp_table_link"%> + <%= link_to t('helpers.history'), admin_template_history_template_path(id: org_template.id), class: "dmp_table_link" %> + + + <%end%> + + <%end%> @@ -80,7 +77,7 @@ - <% if @dmptemplates_funders.count > 0 then %> + <% if @templates_funders.length > 0 then %> @@ -94,7 +91,7 @@ - <% @dmptemplates_funders.each do |org_template| %> + <% @templates_funders.each do |org_template| %> <% if org_template.published? ||org_template.has_customisations?(current_user.organisation_id, org_template) then %> <%end%> <%end%>
    @@ -112,16 +109,7 @@ <% last_updated = org_template.updated_at %> - <% org_template.phases.each do |phase|%> - <% if phase.versions.any? then%> - <% phase.versions.each do |version| %> - <% if org_template.updated_at.to_date < version.updated_at.to_date then %> - <% last_updated = version.updated_at %> - <%end%> - <%end%> - <%end%> - <%end%> - <%= l last_updated.to_date, :formats => :short %> + <%= l last_updated.to_date, formats: :short %> @@ -138,12 +126,12 @@ <%else%> <% b_label = t("helpers.view")%> <%end%> - <%= link_to b_label, admin_template_template_path(org_template), :class => "dmp_table_link"%> + <%= link_to b_label, admin_template_template_path(org_template), class: "dmp_table_link"%>
    - <%end%> + <%end%> <%end%> diff --git a/app/views/templates/admin_new.html.erb b/app/views/templates/admin_new.html.erb index 798f855..0fdf7cc 100644 --- a/app/views/templates/admin_new.html.erb +++ b/app/views/templates/admin_new.html.erb @@ -2,47 +2,46 @@ <% javascript "admin.js" %>

    - <%= t("org_admin.templates.new_label") %> - -
    - <%= link_to t("org_admin.templates.view_all_templates"), - admin_index_dmptemplate_path, - :class => "btn btn-primary" %> -
    + <%= t("org_admin.templates.new_label") %> + +
    + <%= link_to t("org_admin.templates.view_all_templates"), + admin_index_template_path, class: "btn btn-primary" %> +

    - -
    - <%= raw t("org_admin.templates.create_new_template_text_html")%> -
    - <%= form_for :dmptemplate, :url => {:action => "admin_create"} do |f| %> - - - - - - - - - - -
    <%= t("org_admin.templates.title_label") %><%= f.text_field :title, :as => :string, - :class => "text_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.title_help_text") %>
    <%= t("org_admin.templates.desc_label") %>
    - <%= text_area_tag("template-desc", "", class: "tinymce") %> -
    -
    - <%= link_to( image_tag("help_button.png"), "#", :class => "template_desc_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.template_desc_help_text_html"))%> -
    -
    - -
    - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), admin_index_dmptemplate_path, :class => "btn cancel" %> -
    -
    - <%end%> -
    + +
    + <%= raw t("org_admin.templates.create_new_template_text_html")%> +
    + <%= form_for :template, url: {action: "admin_create"} do |f| %> + + + + + + + + + + +
    <%= t("org_admin.templates.title_label") %><%= f.text_field :title, as: :string, + class: "text_field has-tooltip", "data-toggle" => "tooltip", title: t("org_admin.templates.title_help_text") %>
    <%= t("org_admin.templates.desc_label") %>
    + <%= text_area_tag("template-desc", "", class: "tinymce") %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "template_desc_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.template_desc_help_text_html"))%> +
    +
    + +
    + <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.cancel"), admin_index_template_path, class: "btn cancel" %> +
    +
    + <% end %> +
    -<%= tinymce :content_css => asset_path("application.css") %> \ No newline at end of file +<%= tinymce content_css: asset_path("application.css") %> \ No newline at end of file diff --git a/app/views/templates/admin_phase.html.erb b/app/views/templates/admin_phase.html.erb index b85927b..575e86a 100644 --- a/app/views/templates/admin_phase.html.erb +++ b/app/views/templates/admin_phase.html.erb @@ -2,81 +2,70 @@ <%= stylesheet_link_tag "admin" %> <% javascript 'admin.js' %> -<%= tinymce :content_css => asset_path('application.css') %> +<%= tinymce content_css: asset_path('application.css') %>

    - <%= @phase.dmptemplate.title %> - -
    - <%= link_to t("org_admin.templates.view_all_templates"), - admin_index_dmptemplate_path, - :class => 'btn btn-primary' %> -
    + <%= @phase.template.title %> + +
    + <%= link_to t("org_admin.templates.view_all_templates"), + admin_index_template_path, + class: 'btn btn-primary' %> +

    -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @phase.dmptemplate, active: @phase.id} %> +<%= render partial: "admin_nav_tabs", locals: {template: @phase.template, active: @phase.id} %>
    -
    +
    - -
    -
    + +
    +
    - -
    - <%= render :partial => "show_phase", locals: {phase: @phase}%> -
    - <% if @phase.dmptemplate.org_type != constant("organisation_types.funder") || current_user.org_type == constant("organisation_types.funder") then %> - + +
    + <%= render partial: "show_phase", locals: {phase: @phase}%> +
    + <% if @phase.modifiable then %> + + <% end %> +
    +
    - - <%= render :partial => "versions_table", locals: {phase: @phase}%> - <%end%> + + <% @sections.order("number ASC").each do |section| %> + <% if @edit && section.modifiable %> + <%= render partial: 'edit_section', locals: {section: section, edit: @edit, phase: @phase} %> + <% else %> + <%= render partial: 'show_section', locals: {section: section}%> + <% end %> + <% end %> - - <% if @edit == "false" || (@phase.dmptemplate.org_type == constant("organisation_types.funder") && current_user.org_type != constant("organisation_types.funder")) then%> - <%= render :partial => 'show_version', locals: {version: @version}%> - <%elsif @edit == "true" || current_user.org_type == constant("organisation_types.funder") then %> - <%= render :partial => 'edit_version', locals: {version: @version, edit: @edit, phase: @phase} %> - <%end%> -
    -
    - - - <% @sections.order("number ASC").each do |section| %> - <%if (@edit == "true" && section.organisation_id == current_user.organisation_id) || - (@phase.dmptemplate.org_type == constant("organisation_types.funder") && section.organisation_id == current_user.organisation_id && current_user.org_type != constant("organisation_types.funder"))then%> - <%= render :partial => 'edit_section', locals: {section: section, edit: @edit, phase: @phase, version: @version} %> - <%elsif (section.organisation_id == @phase.dmptemplate.organisation_id ) || ( section.organisation_id == current_user.organisation_id) then%> - <%= render :partial => 'show_section', locals: {section: section}%> - <%end%> - <% end %> - -
    +
    - - <% if !@version.published? || (@phase.dmptemplate.org_type == constant("organisation_types.funder") && current_user.org_type != constant("organisation_types.funder"))then %> + + <% if !@phase.template.published %> - - + + - -
    -
    - <%= link_to t('org_admin.add_section_label'),'#', :id => 'add_section_button', :class =>'btn btn-primary' %> -
    -
    - <%end%> + +
    +
    + <%= link_to t('org_admin.add_section_label'),'#', id: 'add_section_button', aclass: 'btn btn-primary' %> +
    +
    + <%end%> diff --git a/app/views/templates/admin_previewphase.html.erb b/app/views/templates/admin_previewphase.html.erb index 12c2507..58de962 100644 --- a/app/views/templates/admin_previewphase.html.erb +++ b/app/views/templates/admin_previewphase.html.erb @@ -2,63 +2,58 @@ <%= stylesheet_link_tag "admin" %>

    - <%= @version.phase.dmptemplate.title %> - -
    - <%= link_to t("org_admin.templates.back_to_edit_phase_label"), - admin_phase_dmptemplate_path(:id => @version.phase_id, :version_id => @version.id, :edit => "true"), - :class => 'btn btn-primary' %> - <%= link_to t("org_admin.templates.view_all_templates"), - admin_index_dmptemplate_path, - :class => 'btn btn-primary' %> -
    + <%= @template.title %> + +
    + <%= link_to t("org_admin.templates.back_to_edit_phase_label"), + admin_phase_template_path(id: @phase.id, edit: "true"), + class: 'btn btn-primary' %> + <%= link_to t("org_admin.templates.view_all_templates"), + admin_index_template_path, + class: 'btn btn-primary' %> +

    -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @version.phase.dmptemplate, active: @version.phase_id} %> +<%= render partial: "admin_nav_tabs", locals: {template: @template, active: @phase.id} %>
    -
    - <% sections = @version.sections %> - <% sections.order(:number).each do |section| %> - <%if (section.organisation_id == @version.phase.dmptemplate.organisation_id ) || ( section.organisation_id == current_user.organisation_id) then%> - -
    - -
    -
    - <%= raw section.description %> -
    -
    - <% section.questions.order("number").each do |question| %> - <% last_question_id = section.questions.order("number DESC").first.id%> - - - <%= render :partial => 'preview_question', locals: {question: question}%> - - <% if last_question_id == question.id then %> -
    - <% else %> -
    - <% end %> - - <%end%> -
    -
    -
    - <%end%> - <%end%> -
    -
    \ No newline at end of file +
    + <% sections = @phase.sections %> + <% sections.order(:number).each do |section| %> +
    + +
    +
    + <%= raw section.description %> +
    +
    + <% last_question_id = section.questions.order("number DESC").first.id%> + + <% section.questions.order("number").each do |question| %> + + <%= render partial: 'preview_question', locals: {question: question}%> + <% if last_question_id == question.id then %> +
    + <% else %> +
    + <% end %> + + <% end %> +
    +
    +
    + <% end %> +
    + \ No newline at end of file diff --git a/app/views/templates/admin_template.html.erb b/app/views/templates/admin_template.html.erb index 642fb15..fec8cc3 100644 --- a/app/views/templates/admin_template.html.erb +++ b/app/views/templates/admin_template.html.erb @@ -2,60 +2,60 @@ <% javascript 'admin.js' %>

    - <%= @dmptemplate.title %> - -
    - <%= link_to t("org_admin.templates.view_all_templates"), - admin_index_dmptemplate_path, - :class => 'btn btn-primary' %> -
    + <%= @template.title %> + +
    + <%= link_to t("org_admin.templates.view_all_templates"), + admin_index_template_path, + class: 'btn btn-primary' %> +

    -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @dmptemplate, active: "show_template"} %> +<%= render partial: "admin_nav_tabs", locals: {template: @template, active: "show_template"} %>
    -
    - <% if @dmptemplate.org_type != constant("organisation_types.funder") || current_user.org_type == constant("organisation_types.funder") then %> - - <%end%> -
    - <%= render :partial => "show_template", locals: {dmptemplate: @dmptemplate}%> -
    -
    - - <% if !@dmptemplate.phases.nil? then %> - <% if @dmptemplate.phases.count == 1 then %> - <% @dmptemplate.phases.each do |phase| %> - - <%= render :partial => 'show_phases_sections', locals: {phase: phase}%> - <%end%> - <%else%> - <% @dmptemplate.phases.order(:number).each do |phase| %> -
    -
    - -
    -
    - - <%= render :partial => 'show_phases_sections', locals: {phase: phase}%> -
    -
    -
    -
    - <%end%> - <%end%> - <%end%> +
    + <% if @template.org_type != constant("organisation_types.funder") || current_user.org_type == constant("organisation_types.funder") then %> + + <%end%> +
    + <%= render partial: "show_template", locals: {template: @template}%> +
    +
    + + <% if !@template.phases.nil? then %> + <% if @template.phases.count == 1 then %> + <% @template.phases.each do |phase| %> + + <%= render partial: 'show_phases_sections', locals: {phase: phase}%> + <%end%> + <%else%> + <% @template.phases.order(:number).each do |phase| %> +
    +
    + +
    +
    + + <%= render partial: 'show_phases_sections', locals: {phase: phase}%> +
    +
    +
    +
    + <%end%> + <%end%> + <%end%>
    -<%= tinymce :content_css => asset_path('application.css') %> +<%= tinymce content_css: asset_path('application.css') %> diff --git a/app/views/templates/admin_template_history.html.erb b/app/views/templates/admin_template_history.html.erb new file mode 100644 index 0000000..c8c5a82 --- /dev/null +++ b/app/views/templates/admin_template_history.html.erb @@ -0,0 +1,63 @@ +<%= stylesheet_link_tag "admin" %> + +

    + <%= @template.title %> +

    +
    +

    + <%= t('org_admin.templates.template_history') %> +

    + +
    + <%= raw t('org_admin.templates.template_history_text_html')%> +
    +
    + <%= link_to t("org_admin.templates.view_all_templates"), + admin_index_template_path, + class: 'btn btn-primary' %> +
    + +
    + + +<% if @templates.length > 0 then %> + + + + + + + + + + + + <% @templates.each do |org_template| %> + + + + + + + + <%end%> + +
    <%= t('org_admin.templates.title_label') %><%= "Version" %><%= t('org_admin.templates.published_label') %><%= t('org_admin.templates.last_updated') %><%= t('org_admin.templates.actions') %>
    + <%= org_template.title%> + + <%= org_template.version %> + + <%= org_template.published %> + + <% last_temp_updated = org_template.updated_at %> + <% org_template.phases.each do |phase|%> + <% if org_template.updated_at.to_date < phase.updated_at.to_date %> + <% last_temp_updated = phase.updated_at %> + <% end %> + <% end %> + <%= l last_temp_updated.to_date, formats: :short %> + + <%= link_to t('helpers.view'), admin_template_template_path(id: org_template), class: "dmp_table_link"%> +
    + +<%end%> \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index f13810f..f4e3351 100644 --- a/config/application.rb +++ b/config/application.rb @@ -98,6 +98,5 @@ # Load Branded terminology (e.g. organization name, application name, etc.) config.branding = config_for(:branding).deep_symbolize_keys - end end diff --git a/config/branding.yml b/config/branding.yml index 578347c..5649562 100644 --- a/config/branding.yml +++ b/config/branding.yml @@ -26,4 +26,4 @@ <<: *defaults production: - <<: *defaults \ No newline at end of file + <<: *defaults diff --git a/config/environment.rb b/config/environment.rb index c82b616..3488440 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -5,5 +5,4 @@ Rails.logger = Logger.new(STDOUT) # Initialize the Rails application. -#DMPonline4::Application.initialize! Rails.application.initialize! \ No newline at end of file diff --git a/config/initializers/devise.rb.example b/config/initializers/devise.rb.example index 17b481e..cce856a 100644 --- a/config/initializers/devise.rb.example +++ b/config/initializers/devise.rb.example @@ -247,7 +247,11 @@ # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' - + + # Any entries here MUST match a corresponding entry in the identifier_schemes table as + # well as an identifier_schemes.schemes section in each locale file! + config.omniauth :orcid, 'client_id', 'client_secret', {'scope': '/authenticate'} + # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or # change the failure app, you can configure them inside the config.warden block. @@ -269,7 +273,7 @@ # # When using omniauth, Devise cannot automatically set Omniauth path, # so you need to do it manually. For the users scope, it would be: - # config.omniauth_path_prefix = "/my_engine/users/auth" + config.omniauth_path_prefix = "/users/auth" config.warden do |manager| manager.failure_app = CustomFailure diff --git a/config/initializers/wicked_pdf.rb.example b/config/initializers/wicked_pdf.rb.example new file mode 100644 index 0000000..1473351 --- /dev/null +++ b/config/initializers/wicked_pdf.rb.example @@ -0,0 +1,7 @@ +module DMPRoadmap + class Application < Rails::Application + WickedPdf.config = { + :exe_path => '/usr/local/bin/wkhtmltopdf' + } + end +end \ No newline at end of file diff --git a/config/initializers/wicked_pdf_example.rb b/config/initializers/wicked_pdf_example.rb deleted file mode 100644 index 103b3e5..0000000 --- a/config/initializers/wicked_pdf_example.rb +++ /dev/null @@ -1,9 +0,0 @@ -module DMPRoadmap - class Application < Rails::Application - - WickedPdf.config = { - :exe_path => '/usr/local/bin/wkhtmltopdf' - } - - end -end \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index 9c10799..d010da5 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -289,6 +289,7 @@ news_label: "Aktuelles" help_label: "Hilfe" contact_label: "Kontakt" + public_plans_label: "Öffentliche DMPs" jisc: "Das DCC wird untertützt von" greeting: "Hallo" @@ -338,8 +339,8 @@ error: "Fehler!" comment: "Kommentar" send: "Senden" - yes: "Ja" - no: "Nein" + 'yes': "Ja" + 'no': "Nein" none: "Keines" title: "Titel" note: "Anmerkung" @@ -407,6 +408,10 @@ add_comment_accordion_label: "Füge Kommentar hinzu" comment_accordion_label: "Kommentare" + answer: + only_one_per_question: "Eine Frage kann nur eine Antwort haben." + question_must_belong_to_correct_template: "Die Frage muss zur richtigen vorlage gehören." + comments: add_comment_label: "Füge Kommentar hinzu" add_comment_text: "Bitte füge einen Kommentar hinzu" @@ -511,6 +516,21 @@ project_identifier_help_text: "Eine Identifikationskürzel, wie es von Förderern oder Institutionen vergeben wird." project_static_info: "Dieser Plan basiert auf:" projects_title: "Meine Pläne" + + visibility: "Sichtweite" + visibilities: + labels: + privately_visible: "Private" + organisationally_visible: "Organisatorische" + publicly_visible: "Öffentlichkeit" + is_test: "Test/Übung" + help_texts: + privately_visible: "Private (Besitzer, Miteigentümer und Admins) Siehe unsere Nutzungsbedingungen." + organisationally_visible: "Mit anderen innerhalb Ihrer Organisation" + publicly_visible: "Öffentlich im Internet. Ihr DMP erscheint auf der Public DMPs Seite dieser Seite." + is_test: "Test / Praxis (Ihr Plan ist für andere Benutzer nicht sichtbar) Siehe unsere Nutzungsbedingungen." + not_set: "Nicht angegeben (wird standardmäßig für andere in Ihrer Organisation sichtbar sein)" + project_settings_text: "Die hier ausgewählten Einträge werden in der Tabelle unten angezeigt. Sie können die Daten durch jeden ihrer Tabellenköpfe sortieren oder filtern, indem Sie eine Zeichenkette in der Suchbox eingeben." project_text_when_no_project: "

    Willkommen.
    Sie können nun ihren ersten DMP erstellen.
    Wählen Sie 'Plan erstellen' weiter unten aus, um zu beginnen.

    " project_text_when_project: "

    Die folgende Tabelle listet alle von Ihnen erstellten und von anderen mit Ihnen geteilten Pläne.
    Diese können jederzeit bearbeitet, geteilt, exportiert und gelöscht werden.

    " @@ -577,6 +597,10 @@ data_contact: "Plandatenkontakt" description: "Beschreibung" unknown: " - " + visibility: "Sichtweite" + name: 'Name' + template: 'Vorlage' + organisation: 'Organisation' filter: placeholder: "Filter Pläne" submit: "Filter" @@ -597,6 +621,7 @@ project_description: "Beschreibung" funder: "Geldgeber" institution: "Institution" + orcid: "Ihre ORCID" settings: title: "Einstellungen" @@ -608,6 +633,7 @@ no_name: "'Name' muss in der Liste von Spalten enthalten sein." duplicate: "Doppelter Spaltenname. Bitte jede Spalte nur einmal einfügen." unknown: "Unbekannter Spaltenname." + no_plan: "Der Plan ist unvollständig." plans: title: "Dateiname" reset: "Zurücksetzen" @@ -684,6 +710,23 @@ no_auth_for_endpoint: '{"Error":"You do not have authorisation to view this endpoint"}' bad_resource: '{"Error":"You do not have authorisation to view this resource"}' + identifier_schemes: + connect_success: 'Ihr Konto wurde mit %{scheme}' + connect_failure: 'Wir konnten nicht auf Ihr Konto %{scheme} verbinden' + disconnect_success: 'Ihr Konto wurde von %{scheme} getrennt' + disconnect_failure: 'Wir waren nicht in der Lage, Ihr Konto zu trennen von %{scheme}' + new_login_success: 'Sie haben nicht Setup ein Konto bei uns. Bitte füllen Sie das folgende Informationen, um Ihre Registrierung abzuschließen.' + new_login_failure: 'Wir waren nicht in der Lage, Ihr Konto zu überprüfen. Bitte benutzen Sie das folgende Formular ein neues Konto zu erstellen. Sie können danach Ihr neues Konto zu verknüpfen.' + + schemes: + orcid: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + user_landing_page: 'https://orcid.org/%{id}' + connect: 'Erstellen oder Verbinden Sie Ihren ORCID ID' + connect_tooltip: 'ORCID bietet eine persistente digitale Kennung, die Sie von anderen Forschern unterscheidet. Erfahren Sie mehr unter orcid.org' + disconnect_confirmation: 'Sind Sie sicher, dass Sie Ihre ORCID ID trennen möchten?' + disconnect_tooltip: 'Trennen Sie Ihr Konto von ORCID. Sie können jederzeit wieder an.' + magic_strings: organisation_types: funder: 'Funder' @@ -694,6 +737,10 @@ template: 'Template' managing_organisation: 'Digital Curation Centre' user_role_types: + admin: 'admin' + org_admin: 'org_admin' + user: 'user' + roles: super_admin: 'admin' organisational_admin: 'org_admin' user: 'user' @@ -705,7 +752,7 @@ use_api: 'use_api' change_org_details: 'change_org_details' grant_api_to_orgs: 'grant_api_to_orgs' - api_endpoint_types: + token_permission_types: guidances: 'guidances' plans: 'plans' templates: 'templates' diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index de174bd..45caa75 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -232,6 +232,7 @@ updated_message: "Guidance group was successfully updated." destroyed_message: "Guidance group was successfully deleted." templates: + template_history: "Template History" create_template: "Create a template" new_label: "New template" template_details: "Template details" @@ -244,6 +245,7 @@ create_own_template_text_html: "

    If you wish to add an institutional template for a Data Management Plan, use the 'create template' button. You can create more than one template if desired e.g. one for researchers and one for PhD students.

    Your template will be presented to users within your institution when no funder templates apply. If you want to add questions to funder templates use the 'customise template' options below.

    " create_new_template_text_html: "

    To create a new template, first enter a title and description. Once you have saved this you will be presented with options to add one or more phases.

    " + template_history_text_html: "

    Here you can view previously published versions of your template. These can no longer be modified.

    " desc_help_text_html: "Enter a description that helps you to differentiate between templates e.g. if you have ones for different audiences" own_temp: "Own templates" add_phase_label: "Add new phase +" @@ -338,11 +340,17 @@ about_us_label: "About" roadmap_label: "Future plans" help_label: "Help" + public_plans_label: "Public DMPs" + contact_label: "Contact" + public_plans_label: "Public DMPs" jisc: "The %{organisation_abbreviation} is funded by" format: "format" change_language: "Change language" + 'yes': 'Yes' + 'no': 'No' + sign_in: "Sign in" sign_out: "Sign out" sign_up: "Sign up" @@ -423,6 +431,7 @@ note: "Note" me: "Me" view: "View" + history: "History" desc: "Description" save: "Save" preview: "Preview" @@ -501,6 +510,10 @@ add_comment_accordion_label: "Share note" comment_accordion_label: "Notes" + answer: + only_one_per_question: "A question can only have one answer." + question_must_belong_to_correct_template: "The question must belong to the correct template." + comments: add_comment_label: "Add note" add_comment_text: "Share note with collaborators" @@ -574,6 +587,21 @@ project_identifier_help_text: "A pertinent ID as determined by the funder and/or institution." project_static_info: "This plan is based on:" projects_title: "My plans" + + visibility: "Visibility" + visibilities: + labels: + privately_visible: "Private" + organisationally_visible: "Organisational" + publicly_visible: "Public" + is_test: "Test/Practice" + help_texts: + privately_visible: "Private (owners, co-owners, and administrators only) See our Terms of Use." + organisationally_visible: "Organisational (visibile to others within your organisation)" + publicly_visible: "Public (Your DMP will appear on the Public DMPs page of this site)" + is_test: "Test/Practice (your plan is not visible to other users) See our Terms of Use." + not_set: "Not specified (will be visible to others within your organisation by default)" + project_settings_text: "The items you select here will be displayed in the table below. You can sort the data by each of these headings or filter by entering a text string in the search box." project_text_when_no_project: "

    Welcome.
    You are now ready to create your first DMP.
    Click the 'Create plan' button below to begin.

    " project_text_when_project: "

    The table below lists the plans that you have created, and any that have been shared with you by others.
    These can be edited, shared, exported or deleted at anytime.

    " @@ -626,6 +654,11 @@ data_contact: "Plan data contact" description: "Description" unknown: " - " + visibility: "Visibility" + name: 'Name' + template: 'Template' + organisation: 'Organization' + filter: placeholder: "Filter plans" submit: "Filter" @@ -657,6 +690,7 @@ project_description: "Plan Description" funder: "Funder" institution: "Institution" + orcid: "Your ORCID" not_valid_format: '%{value}% is not a valid format' settings: @@ -668,6 +702,7 @@ no_name: "'name' must be included in column list." duplicate: "Duplicate column name. Please only include each column once." unknown: "Unknown column name." + no_plan: "The plan is incomplete." plans: title: "File Name" reset: "Reset" @@ -739,6 +774,23 @@ no_auth_for_endpoint: '{"Error":"You do not have authorisation to view this endpoint"}' bad_resource: '{"Error":"You do not have authorisation to view this resource"}' + identifier_schemes: + connect_success: 'Your account has bee connected to %{scheme}' + connect_failure: 'We could not connect your account to %{scheme}' + disconnect_success: 'Your account has been disconnected from %{scheme}' + disconnect_failure: 'We were unable to disconnect your account from %{scheme}' + new_login_success: 'It does not look like you have setup an account with us yet. Please fill in the following information to complete your registration.' + new_login_failure: 'We were unable to verify your account. Please use the following form to create a new account. You will be able to link your new account afterward.' + + schemes: + orcid: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + user_landing_page: 'https://orcid.org/%{id}' + connect: 'Create or Connect your ORCID ID' + connect_tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at orcid.org' + disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' + disconnect_tooltip: 'Disconnect your account from ORCID. You can reconnect at any time.' + magic_strings: organisation_types: funder: 'Funder' @@ -749,6 +801,10 @@ template: 'Template' managing_organisation: 'Digital Curation Centre' user_role_types: + admin: 'admin' + org_admin: 'org_admin' + user: 'user' + roles: super_admin: 'admin' organisational_admin: 'org_admin' user: 'user' @@ -760,7 +816,7 @@ use_api: 'use_api' change_org_details: 'change_org_details' grant_api_to_orgs: 'grant_api_to_orgs' - api_endpoint_types: + token_permission_types: guidances: 'guidances' plans: 'plans' templates: 'templates' diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 16de5b7..2d9b60b 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -327,9 +327,13 @@ roadmap_label: "Future plans" help_label: "Help" contact_label: "Contact" + public_plans_label: "Public DMPs" jisc: "The %{organisation_abbreviation} is funded by" format: "format" + 'yes': 'Yes' + 'no': 'No' + sign_in: "Sign in" sign_out: "Sign out" sign_up: "Sign up" @@ -487,6 +491,10 @@ add_comment_accordion_label: "Share note" comment_accordion_label: "Notes" + answer: + only_one_per_question: "A question can only have one answer." + question_must_belong_to_correct_template: "The question must belong to the correct template." + comments: add_comment_label: "Add note" add_comment_text: "Share note with collaborators" @@ -560,6 +568,21 @@ project_identifier_help_text: "A pertinent ID as determined by the funder and/or institution." project_static_info: "This plan is based on:" projects_title: "My plans" + + visibility: "Visibility" + visibilities: + labels: + privately_visible: "Private" + organisationally_visible: "Organizational" + publicly_visible: "Public" + is_test: "Test/Practice" + help_texts: + privately_visible: "Private (owners, co-owners, and administrators only) See our Terms of Use." + organisationally_visible: "Organizational (visibile to others within your organization)" + publicly_visible: "Public (Your DMP will appear on the Public DMPs page of this site)" + is_test: "Test/Practice (your plan is not visible to other users) See our Terms of Use." + not_set: "Not specified (will be visible to others within your organization by default)" + project_settings_text: "The items you select here will be displayed in the table below. You can sort the data by each of these headings or filter by entering a text string in the search box." project_text_when_no_project: "

    Welcome.
    You are now ready to create your first DMP.
    Click the 'Create plan' button below to begin.

    " project_text_when_project: "

    The table below lists the plans that you have created, and any that have been shared with you by others.
    These can be edited, shared, exported or deleted at anytime.

    " @@ -612,6 +635,10 @@ data_contact: "Plan data contact" description: "Description" unknown: " - " + visibility: "Visibility" + name: 'Name' + template: 'Template' + organisation: 'Organization' filter: placeholder: "Filter plans" submit: "Filter" @@ -643,6 +670,7 @@ project_description: "Description" funder: "Funder" institution: "Institution" + orcid: "Your ORCID" not_valid_format: '%{value}% is not a valid format' settings: @@ -654,6 +682,7 @@ no_name: "'name' must be included in column list." duplicate: "Duplicate column name. Please only include each column once." unknown: "Unknown column name." + no_plan: "The plan is incomplete." plans: title: "File Name" reset: "Reset" @@ -725,6 +754,23 @@ no_auth_for_endpoint: '{"Error":"You do not have authorisation to view this endpoint"}' bad_resource: '{"Error":"You do not have authorisation to view this resource"}' + identifier_schemes: + connect_success: 'Your account has bee connected to %{scheme}' + connect_failure: 'We could not connect your account to %{scheme}' + disconnect_success: 'Your account has been disconnected from %{scheme}' + disconnect_failure: 'We were unable to disconnect your account from %{scheme}' + new_login_success: 'It does not look like you have setup an account with us yet. Please fill in the following information to complete your registration.' + new_login_failure: 'We were unable to verify your account. Please use the following form to create a new account. You will be able to link your new account afterward.' + + schemes: + orcid: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + user_landing_page: 'https://orcid.org/%{id}' + connect: 'Create or Connect your ORCID ID' + connect_tooltip: 'ORCID provides a persistent digital identifier that distinguishes you from other researchers. Learn more at orcid.org' + disconnect_confirmation: 'Are you sure you want to disconnect your ORCID ID?' + disconnect_tooltip: 'Disconnect your account from ORCID. You can reconnect at any time.' + magic_strings: organisation_types: funder: 'Funder' @@ -735,6 +781,10 @@ template: 'Template' managing_organisation: 'Digital Curation Centre' user_role_types: + admin: 'admin' + org_admin: 'org_admin' + user: 'user' + roles: super_admin: 'admin' organisational_admin: 'org_admin' user: 'user' @@ -746,7 +796,7 @@ use_api: 'use_api' change_org_details: 'change_org_details' grant_api_to_orgs: 'grant_api_to_orgs' - api_endpoint_types: + token_permission_types: guidances: 'guidances' plans: 'plans' templates: 'templates' diff --git a/config/locales/es.yml b/config/locales/es.yml index 9c288cd..a7e52e5 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -280,6 +280,7 @@ roadmap_label: "Hoja de ruta" help_label: "Ayuda" contact_label: "Contacto" + public_plans_label: "DMP Públicos" jisc: "El DCC está financiado por" sign_in: "Conectar" @@ -322,8 +323,8 @@ error: "¡Error!" comment: "Comentario" send: "Enviar" - yes: "Si" - no: "No" + 'yes': "Si" + 'no': "No" none: "Ninguno/a" false_lowercase: "falso" title: "Título" @@ -387,6 +388,10 @@ add_comment_accordion_label: "Compartir nota" comment_accordion_label: "Notas" + answer: + only_one_per_question: "Una pregunta sólo puede tener una respuesta." + question_must_belong_to_correct_template: "La pregunta debe pertenecer a la plantilla correcta." + comments: add_comment_label: "Añadir nota" add_comment_text: "Compartir nota con colaboradores" @@ -453,6 +458,21 @@ project_identifier_help_text: "El ID tal como lo determinó la institución u organismo financiador." project_static_info: "Este plan está basado en:" projects_title: "Mis planes" + + visibility: "Visibilidad" + visibilities: + labels: + privately_visible: "Privado" + organisationally_visible: "Organizativo" + publicly_visible: "Público" + is_test: "Prueba/Práctica" + help_texts: + privately_visible: "Privado (propietarios, copropietarios y administradores solamente) Consulte nuestras Condiciones de uso." + organisationally_visible: "Con otros miembros de su organización" + publicly_visible: "Publicamente en la web. Su DMP aparecerá en la página Public DMPs de este sitio." + is_test: "Prueba / Práctica (su plan no es visible para otros usuarios) Vea nuestras Condiciones de uso." + not_set: "No especificado (será visible para otros dentro de su organización de forma predeterminada)" + project_settings_text: "Los items que seleccione se mostarán en la siguiente tabla. Puede ordenar los datos según sus encabezados o filtrar tecleando textos en la caja de búsqueda." project_text_when_no_project: "

    Bienvenido.
    Ya está listo para crear su primer PGD.
    Haga clic en el botón 'Crear un plan' para comenzar.

    " project_text_when_project: "

    La siguiente tabla lista los planes que usted ha creado, así como los que otros investigadores hayan compartido con usted.
    Se pueden editar, compartir, exportar o borrar en cualquier momento.

    " @@ -504,6 +524,10 @@ principal_investigator: "Principal Investigador / Científico" data_contact: "Datos de contacto del plan" description: "Descripción" + visibility: 'Visibilidad' + name: 'Nombre' + template: 'Plantilla' + organisation: 'Organización' filter: placeholder: "Filtro de planes" submit: "Filtrar" @@ -534,6 +558,7 @@ no_name: "'nombre' tiene que estar en la lista de columnas." duplicate: "Nombre de columna duplicado. Por favor, indique cada columna sólo una vez." unknown: "Nombre de columna desconocido." + no_plan: "El plan es incompleto." plans: title: Título del plan reset: "Reiniciar" @@ -789,3 +814,60 @@

    El uso de la herramienta indica que usted entiende y está de acuerdo con estos términos y condiciones.

    " + + api: + bad_credentials: '{"Error":"Bad credentials"}' + org_dosent_exist: '{"Error":"Organization does not exist"}' + org_not_funder: '{"Error":"Organization specified is not a funder"}' + org_multiple_templates: '{"Error":"Organization has more than one template and template name unspecified or invalid"}' + no_auth_for_endpoint: '{"Error":"You do not have authorisation to view this endpoint"}' + bad_resource: '{"Error":"You do not have authorisation to view this resource"}' + + identifier_schemes: + connect_success: 'Tu cuenta se ha conectado a %{scheme}' + connect_failure: 'No pudimos conectar tu cuenta a %{scheme}' + disconnect_success: 'Su cuenta se ha desconectado de %{scheme}' + disconnect_failure: 'No hemos podido desconectar tu cuenta de %{scheme}' + new_login_success: 'No ha configurado una cuenta. Por favor complete su registro.' + new_login_failure: 'No hemos podido verificar tu cuenta. Utilice el siguiente formulario para crear una cuenta nueva. Podrá vincular su nueva cuenta posteriormente.' + + schemes: + orcid: + logo: 'http://orcid.org/sites/default/files/images/orcid_16x16.png' + user_landing_page: 'https://orcid.org/%{id}' + connect: 'Cree o conecte su ID de ORCID ID' + connect_tooltip: 'ORCID proporciona un identificador digital persistente que lo distingue de otros investigadores. Más información en orcid.org' + disconnect_confirmation: '¿Está seguro de que desea desconectar su ORCID ID?' + disconnect_tooltip: 'Desconecte su cuenta de ORCID. Puede volver a conectarse en cualquier momento.' + + magic_strings: + organisation_types: + funder: 'Financiador' + organisation: 'Organización' + project: 'Proyecto' + institution: 'Institución' + research_institute: 'Instituto de Investigación' + template: 'Modelo' + managing_organisation: 'Centro de Cura Digital' + user_role_types: + admin: 'admin' + org_admin: 'org_admin' + user: 'user' + roles: + super_admin: 'admin' + organisational_admin: 'org_admin' + user: 'user' + add_organisations: 'add_organisations' + change_org_affiliation: 'change_org_affiliation' + grant_permissions: 'grant_permissions' + modify_templates: 'modify_templates' + modify_guidance: 'modify_guidance' + use_api: 'use_api' + change_org_details: 'change_org_details' + grant_api_to_orgs: 'grant_api_to_orgs' + token_permission_types: + guidances: 'guidances' + plans: 'plans' + templates: 'templates' + statistics: 'statistics' + languages: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 5f4e0eb..d045462 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -19,7 +19,7 @@ day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi] abbr_day_names: [DIM, LUN, MAR, MER, JEU, VEN, SAM] - # Don't forget the nil at the beginning; there's no such thing as a 0th month + # Dont forget the nil at the beginning; theres no such thing as a 0th month month_names: [~, janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre] abbr_month_names: [~, JAN, FEV, MAR, AVR, MAI, JUN, JUL, AOU, SEP, OCT, NOV, DEC] # Used in date_select and datetime_select. @@ -42,23 +42,23 @@ dmponline3_text: "Version précédente de DMPonline" dcc_name: "Digital Curation Centre" welcome_title: "Bienvenue !" - welcome_text: "

    DMPonline est un développement du Digital Curation Centre (Centre de curation numérique britannique - DCC) pour vous aider dans la rédaction de plans de gestion de données, ou DMP.

    " - screencast_text: "Vidéo en ligne sur l'utilisation de DMPonline" - screencast_error_text: "La balise