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/Gemfile b/Gemfile index e1c9c28..2b41610 100644 --- a/Gemfile +++ b/Gemfile @@ -15,8 +15,9 @@ # ------------------------------------------------ # DATABASE/SERVER -gem 'pg' gem 'mysql2', '~> 0.3.18' +gem 'pg' +gem 'flag_shih_tzu' # Allows for bitfields in activereccord # ------------------------------------------------ # JS <-> RUBY BRIDGE @@ -28,10 +29,6 @@ gem 'jbuilder' # ------------------------------------------------ -# CLONE ACTIVERECORD MODELS AND ASSOCIATIONS -gem 'amoeba' - -# ------------------------------------------------ # SLUGS/PERMALINKS gem 'friendly_id' @@ -47,6 +44,7 @@ gem 'omniauth' gem 'omniauth-shibboleth' gem 'omniauth-orcid' + #rolify for roles gem 'rolify' # Gems for repository integration @@ -63,7 +61,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 @@ -81,6 +79,7 @@ # ------------------------------------------------ # INTERNATIONALIZATION gem "i18n-js", ">= 3.0.0.rc11" #damodar added TODO: explain +gem 'gettext_i18n_rails', '~> 1.8' # ------------------------------------------------ # API @@ -105,12 +104,15 @@ gem 'rack-test' gem 'webmock' gem 'sqlite3' + gem 'simplecov', require: false end group :development do gem "better_errors" gem "binding_of_caller" gem 'web-console', '~>2.0' + gem 'rack-mini-profiler' + #gem 'flamegraph' end group :production do diff --git a/Gemfile.lock b/Gemfile.lock index e0916b1..d430a3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,8 +64,6 @@ thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.4.0) - amoeba (3.0.0) - activerecord (>= 3.2.6) ansi (1.5.0) arbre (1.1.1) activesupport (>= 3.0.0) @@ -121,6 +119,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) @@ -137,6 +136,7 @@ faraday_middleware (~> 0.9) loofah (~> 2.0) sax-machine (~> 1.0) + flag_shih_tzu (0.3.15) formtastic (3.1.4) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) @@ -246,6 +246,8 @@ pundit (1.1.0) activesupport (>= 3.0.0) rack (1.6.4) + rack-mini-profiler (0.10.1) + rack (>= 1.2.0) rack-test (0.6.3) rack (>= 1.0) rails (4.2.7) @@ -297,6 +299,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) @@ -351,7 +358,6 @@ DEPENDENCIES activeadmin! - amoeba better_errors binding_of_caller byebug @@ -362,6 +368,7 @@ devise_invitable dragonfly feedjira + flag_shih_tzu friendly_id htmltoword i18n-js (>= 3.0.0.rc11) @@ -379,6 +386,7 @@ pg protected_attributes pundit + rack-mini-profiler rack-test rails (= 4.2.7) railties @@ -387,6 +395,7 @@ responders (~> 2.0) rolify sass-rails + simplecov sqlite3 swagger-docs therubyracer (>= 0.11.4) @@ -405,4 +414,4 @@ ruby 2.2.2p95 BUNDLED WITH - 1.13.2 + 1.13.7 diff --git a/README.md b/README.md index e47a09f..88ceaba 100644 --- a/README.md +++ b/README.md @@ -15,99 +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 - -* Make copies of the example gem initializer files and update the values for your installation - -> > 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 - -* 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 (Unless you are migrating data from an old DMPOnline system) - -* 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' - -#### Migrating data from a running instance of DMPOnline_v4 into DMPRoadmap - -TODO: Add instructions on exporting data from the old DB and migrating it into the Roadmap DB #### 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 - -##### Post Installation Issues - -I installed the system and migrated my legacy DMPOnline data into the database but none of my users are able to login! - -This happens when the 'pepper' key defined in config/initializers/devise.rb does not match the one on your old server. Simply update the pepper and restart the application. +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/dmptemplate.rb b/app/admin/dmptemplate.rb deleted file mode 100644 index e0cd394..0000000 --- a/app/admin/dmptemplate.rb +++ /dev/null @@ -1,125 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register Dmptemplate do - permit_params :title, :description, :organisation_id, :published, :is_default - - menu :priority => 11, :label => proc{ I18n.t('admin.template')}, :parent => "Templates management" - - # FIXME: The below member_actions only work on :export settings. - member_action :settings do - @template = resource - @settings = resource.settings(:export) - end - - member_action :update_settings, method: :put do - new_settings = params[:settings][:export] - - settings = resource.settings(:export).tap do |s| - s.formatting, s.max_pages = if params[:commit] != 'Reset' - [ - new_settings[:formatting].try(:deep_symbolize_keys), - new_settings[:max_pages].try(:to_i) - ] - else - [ nil, nil ] - end - end - - if settings.save - redirect_to(action: :show, flash: { notice: I18n.t('admin.settings_updated') }) - else - settings.formatting = nil - @template = resource - @settings = settings - render(action: :settings) - end - end - - action_item(:edit) do - link_to(I18n.t('helpers.settings.title'), settings_admin_dmptemplate_path(resource.id)) - end - - index do - column :title do |dmptemp| - link_to dmptemp.title, [:admin, dmptemp] - end - column :description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - column I18n.t('admin.org_title'), :sortable => :organisation_id do |org_title| - if !org_title.organisation.nil? then - link_to org_title.organisation.name, [:admin, org_title.organisation] - else - '-' - end - end - column :published - column :is_default - - actions defaults: true do |template| - link_to(I18n.t('helpers.settings.title'), settings_admin_dmptemplate_path(template.id)) - end - end - - - # show Template details - show do - attributes_table do - row :title - row :description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - row I18n.t('admin.org_title'), :sortable => :organisation_id do |org_title| - if !org_title.organisation.nil? then - link_to org_title.organisation.name, [:admin, org_title.organisation] - else - '-' - end - end - row :published - row :is_default - row :created_at - row :updated_at - end - end - - #phases sidebar - sidebar I18n.t('admin.phases'), :only => :show, :if => proc { dmptemplate.phases.count >= 1} do - table_for dmptemplate.phases.order("number asc") do |temp_phases| - column :number - column :title do |row| - link_to row.title, [:admin, row] - end - end - end - - #form - form do |f| - f.inputs "Details" do - f.input :title - f.input :description - f.input :organisation_id, :label => I18n.t('admin.org_title'), - :as => :select, - :collection => Organisation.order('name').map{|orgp|[orgp.name, orgp.id]} - f.input :published - f.input :is_default - end - f.actions - end - - controller do - def permitted_params - params.permit! - end - end - -end - diff --git a/app/admin/guidance_group.rb b/app/admin/guidance_group.rb index 76667f7..c193af9 100644 --- a/app/admin/guidance_group.rb +++ b/app/admin/guidance_group.rb @@ -56,7 +56,7 @@ f.input :name f.input :organisation_id, :label => I18n.t('admin.org_title'), :as => :select, - :collection => Organisation.order('name').map{|orgp|[orgp.name, orgp.id]} + :collection => Org.order('name').map{|orgp|[orgp.name, orgp.id]} f.input :published f.input :optional_subset end diff --git a/app/admin/option.rb b/app/admin/option.rb index ce44cfc..cd68f1a 100644 --- a/app/admin/option.rb +++ b/app/admin/option.rb @@ -4,7 +4,7 @@ # [+Created:+] 03/09/2014 # [+Copyright:+] Digital Curation Centre and University of California Curation Center -ActiveAdmin.register Option do +ActiveAdmin.register QuestionOption do permit_params :question_id, :text, :number, :is_default menu :priority => 6, :label => proc{I18n.t('admin.multi_options')}, :parent => "Templates management" diff --git a/app/admin/org.rb b/app/admin/org.rb new file mode 100644 index 0000000..7d9391b --- /dev/null +++ b/app/admin/org.rb @@ -0,0 +1,110 @@ +# [+Project:+] DMPRoadmap +# [+Description:+] +# +# [+Created:+] 03/09/2014 +# [+Copyright:+] Digital Curation Centre and University of California Curation Center + +ActiveAdmin.register Org do + permit_params :abbreviation, :banner_file_id, :description, :logo_file_id, :name, :target_url, :organisation_type_id, :wayfless_entity, :parent_id + + menu :priority => 14, :label => proc{I18n.t('admin.org')}, :parent => "Organisations management" + + index do + column I18n.t('admin.org_title'), :sortable => :name do |ggn| + link_to ggn.name, [:admin, ggn] + end + column I18n.t('admin.abbrev'), :sortable => :abbreviation do |ggn| + if !ggn.abbreviation.nil? + link_to ggn.abbreviation, [:admin, ggn] + else + '-' + end + end + column I18n.t('admin.org_type'), :sortable => :organisation_type_id do |org_type| + if !org_type.organisation_type_id.nil? then + link_to org_type.organisation_type.name, [:admin, org_type] + end + end + + actions + end + + + #show details of an organisation + show do + resource.check_api_credentials + attributes_table do + row I18n.t('admin.org_title'), :sortable => :name do |gn| + if !gn.name.nil? then + link_to gn.name, [:admin, gn] + end + end + row I18n.t('admin.abbrev'), :abbreviation do |ggn| + if !ggn.abbreviation.nil? + link_to ggn.abbreviation, [:admin, ggn] + else + '-' + end + end + row :sort_name + row I18n.t('admin.org_type'), :organisation_type_id do |org_type| + if !org_type.organisation_type_id.nil? then + link_to org_type.organisation_type.name, [:admin, org_type] + end + end + row :banner_text do |banner| + if !banner.banner_text.nil? then + banner.banner_text.html_safe + end + end + # row :target_url + row :logo_file_name + row :wayfless_entity + row I18n.t('admin.token_permission_type') do + (organisation.token_permission_types.map{|tpt| link_to tpt.token_type, [:admin, tpt]}).join(', ').html_safe + end + row :created_at + row :updated_at + end + end + + #templates sidebar + sidebar I18n.t('admin.templates'), :only => :show, :if => proc { organisation.dmptemplates.count >= 1} do + table_for organisation.dmptemplates.order("title asc") do |temp| + column :title do |dmptemp| + link_to dmptemp.title, [:admin, dmptemp] + end + column :published + end + end + + #form + form do |f| + f.inputs "Details" do + f.input :name + f.input :abbreviation + f.input :sort_name + f.input :organisation_type_id, :label => I18n.t('admin.org_type'), :as => :select, :collection => OrganisationType.order('name').map{|orgt|[orgt.name, orgt.id]} + # f.input :target_url + f.input :banner_text + f.input :logo_file_name + f.input :wayfless_entity + f.input :token_permission_types, label: I18n.t('admin.token_permission_type'), + as: :select, multiple: true, include_blank: I18n.t('helpers.none'), + collection: TokenPermissionType.order(:token_type).map{|token| [token.token_type, token.id]}, + hint: I18n.t('admin.choose_api_permissions') + # f.input :parent_id, :label => I18n.t('admin.org_parent'), :as => :select, :collection => Org.find(:all, :order => 'name ASC').map{|orgp|[orgp.name, orgp.id]} + # f.input :stylesheet_file_id + end + f.actions + end + + + controller do + def permitted_params + params.permit! + end + end + + +end 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/admin/organisation.rb b/app/admin/organisation.rb deleted file mode 100644 index 5acc929..0000000 --- a/app/admin/organisation.rb +++ /dev/null @@ -1,112 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register Organisation do - permit_params :abbreviation, :banner_file_id, :description, :domain, :logo_file_id, :name, :stylesheet_file_id, :target_url, :organisation_type_id, :wayfless_entity, :parent_id - - menu :priority => 14, :label => proc{I18n.t('admin.org')}, :parent => "Organisations management" - - index do - column I18n.t('admin.org_title'), :sortable => :name do |ggn| - link_to ggn.name, [:admin, ggn] - end - column I18n.t('admin.abbrev'), :sortable => :abbreviation do |ggn| - if !ggn.abbreviation.nil? - link_to ggn.abbreviation, [:admin, ggn] - else - '-' - end - end - column I18n.t('admin.org_type'), :sortable => :organisation_type_id do |org_type| - if !org_type.organisation_type_id.nil? then - link_to org_type.organisation_type.name, [:admin, org_type] - end - end - - actions - end - - - #show details of an organisation - show do - resource.check_api_credentials - attributes_table do - row I18n.t('admin.org_title'), :sortable => :name do |gn| - if !gn.name.nil? then - link_to gn.name, [:admin, gn] - end - end - row I18n.t('admin.abbrev'), :abbreviation do |ggn| - if !ggn.abbreviation.nil? - link_to ggn.abbreviation, [:admin, ggn] - else - '-' - end - end - row :sort_name - row I18n.t('admin.org_type'), :organisation_type_id do |org_type| - if !org_type.organisation_type_id.nil? then - link_to org_type.organisation_type.name, [:admin, org_type] - end - end - row :banner_text do |banner| - if !banner.banner_text.nil? then - banner.banner_text.html_safe - end - end - # row :target_url - row :logo_file_name - row :domain - row :wayfless_entity - row I18n.t('admin.token_permission_type') do - (organisation.token_permission_types.map{|tpt| link_to tpt.token_type, [:admin, tpt]}).join(', ').html_safe - end - row :created_at - row :updated_at - end - end - - #templates sidebar - sidebar I18n.t('admin.templates'), :only => :show, :if => proc { organisation.dmptemplates.count >= 1} do - table_for organisation.dmptemplates.order("title asc") do |temp| - column :title do |dmptemp| - link_to dmptemp.title, [:admin, dmptemp] - end - column :published - end - end - - #form - form do |f| - f.inputs "Details" do - f.input :name - f.input :abbreviation - f.input :sort_name - f.input :organisation_type_id, :label => I18n.t('admin.org_type'), :as => :select, :collection => OrganisationType.order('name').map{|orgt|[orgt.name, orgt.id]} - # f.input :target_url - f.input :banner_text - f.input :logo_file_name - f.input :domain - f.input :wayfless_entity - f.input :token_permission_types, label: I18n.t('admin.token_permission_type'), - as: :select, multiple: true, include_blank: I18n.t('helpers.none'), - collection: TokenPermissionType.order(:token_type).map{|token| [token.token_type, token.id]}, - hint: I18n.t('admin.choose_api_permissions') - # f.input :parent_id, :label => I18n.t('admin.org_parent'), :as => :select, :collection => Organisation.find(:all, :order => 'name ASC').map{|orgp|[orgp.name, orgp.id]} - # f.input :stylesheet_file_id - end - f.actions - end - - - controller do - def permitted_params - params.permit! - end - end - - -end diff --git a/app/admin/organisation_type.rb b/app/admin/organisation_type.rb deleted file mode 100644 index 4575f54..0000000 --- a/app/admin/organisation_type.rb +++ /dev/null @@ -1,55 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register OrganisationType do - permit_params :organisation_id, :name - - menu :priority => 4, :label => proc{I18n.t('admin.org_type')}, :parent => "Organisations management" - - index do - column I18n.t('admin.title'), :sortable => :name do |ggn| - link_to ggn.name, [:admin, ggn] - end - column I18n.t('admin.desc'), :description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - - actions - end - - - #show organisation type details - show do - attributes_table do - row :name - row :description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - row :created_at - row :updated_at - end - end - - #organisations sidebar - sidebar I18n.t('admin.orgs'), :only => :show, :if => proc { organisation_type.organisations.count >= 1} do - table_for organisation_type.organisations.order("name") do |org_list| - column I18n.t('admin.org_title'), :sortable => :name do |ggn| - link_to ggn.name, [:admin, ggn] - end - end - end - - controller do - def permitted_params - params.permit! - end - end - -end diff --git a/app/admin/perm.rb b/app/admin/perm.rb new file mode 100644 index 0000000..4401e31 --- /dev/null +++ b/app/admin/perm.rb @@ -0,0 +1,60 @@ +# [+Project:+] DMPRoadmap +# [+Description:+] +# +# [+Created:+] 03/09/2014 +# [+Copyright:+] Digital Curation Centre and University of California Curation Center + +ActiveAdmin.register Perm do + permit_params :name + + menu :priority => 5, :label => proc{I18n.t('admin.role')}, :parent => "User management" + + index do + column I18n.t('admin.title'), :sortable => :name do |role_name| + link_to role_name.name, [:admin, role_name] + end + + actions + end + + + show do + attributes_table do + row :name + row :created_at + row :updated_at + end + + table_for( (Perm.find(params[:id]).users)) do + column (:email){|user| link_to user.email, [:admin, user]} + column (:firstname){|user| user.firstname} + column (:surname){|user| user.surname} + column (:last_sign_in_at){|user| user.last_sign_in_at} + column (I18n.t('admin.org_title')){|user| + if !user.organisation.nil? then + if user.other_organisation.nil? || user.other_organisation == "" then + link_to user.organisation.name, [:admin, user.organisation] + else + I18n.t('helpers.org_type.org_name') + ' - ' + user.other_organisation + + end + end + } + end + + end + + form do |f| + f.inputs "Details" do + f.input :name + end + + f.actions + end + + controller do + def permitted_params + params.permit! + end + end +end diff --git a/app/admin/plan.rb b/app/admin/plan.rb new file mode 100644 index 0000000..574a7c2 --- /dev/null +++ b/app/admin/plan.rb @@ -0,0 +1,39 @@ +# [+Project:+] DMPRoadmap +# [+Description:+] +# +# [+Created:+] 03/09/2014 +# [+Copyright:+] Digital Curation Centre and University of California Curation Center + +ActiveAdmin.register Plan do + permit_params :template_id, :title, :org_id, :unit_id, :guidance_group_ids, :role_ids, :funder_id, :institution_id, :grant_number,:identifier, :description, :principal_investigator, :principal_investigator_identifier, :data_contact + + menu :priority => 25, :label => proc{I18n.t('admin.plans')} + + + index do + column :title + column I18n.t('admin.org_title'), :sortable => :org_id do |org_title| + if !org_title.organisation.nil? then + link_to org_title.organisation.name, [:admin, org_title.organisation] + else + '-' + end + end + column I18n.t('admin.template_title'), :sortable => :template_id do |dmptemp| + if !dmptemp.template.nil? then + link_to dmptemp.template.title, [:admin, dmptemp.template] + else + '-' + end + end + + actions + end + + + controller do + def permitted_params + params.permit! + end + end +end diff --git a/app/admin/project.rb b/app/admin/project.rb deleted file mode 100644 index 2028428..0000000 --- a/app/admin/project.rb +++ /dev/null @@ -1,39 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register Project do - permit_params :dmptemplate_id, :title, :organisation_id, :unit_id, :guidance_group_ids, :project_group_ids, :funder_id, :institution_id, :grant_number,:identifier, :description, :principal_investigator, :principal_investigator_identifier, :data_contact - - menu :priority => 25, :label => proc{I18n.t('admin.plans')} - - - index do - column :title - column I18n.t('admin.org_title'), :sortable => :organisation_id do |org_title| - if !org_title.organisation.nil? then - link_to org_title.organisation.name, [:admin, org_title.organisation] - else - '-' - end - end - column I18n.t('admin.template_title'), :sortable => :dmptemplate_id do |dmptemp| - if !dmptemp.dmptemplate.nil? then - link_to dmptemp.dmptemplate.title, [:admin, dmptemp.dmptemplate] - else - '-' - end - end - - actions - end - - - controller do - def permitted_params - params.permit! - end - end -end diff --git a/app/admin/project_group.rb b/app/admin/project_group.rb deleted file mode 100644 index 67c681c..0000000 --- a/app/admin/project_group.rb +++ /dev/null @@ -1,9 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register ProjectGroup do - menu false -end diff --git a/app/admin/question.rb b/app/admin/question.rb index 8d46df1..45d8e18 100644 --- a/app/admin/question.rb +++ b/app/admin/question.rb @@ -5,7 +5,7 @@ # [+Copyright:+] Digital Curation Centre and University of California Curation Center ActiveAdmin.register Question do - permit_params :default_value, :dependency_id, :dependency_text, :guidance, :number, :parent_id, :suggested_answer, :text, :question_type, :section_id + permit_params :default_value, :dependency_id, :dependency_text, :guidance, :number, :suggested_answer, :text, :question_type, :section_id menu :priority => 7, :label => proc{I18n.t('admin.question')}, :parent => "Templates management" @@ -54,28 +54,6 @@ row I18n.t('admin.question_format') do |format| link_to format.question_format.title, [:admin, format.question_format] end - #row :guidance do |qguidance| - # if !qguidance.guidance.nil? then - # qguidance.guidance.html_safe - # end - #end - #row :parent_id do |qparent| - # if !qparent.parent_id.nil? then - # parent_q = Question.where('id = ?', qparent.parent_id) - # link_to parent_q.text, [:admin, parent_q] - # end - #end - #row :dependency_id do |qdepend| - # if !qdepend.dependency_id.nil? then - # qdep = Question.where('id = ?', qparent.dependency_id) - # link_to qdep.text, [:admin, qdep] - # end - #end - #row :dependency_text do |dep_text| - # if !dep_text.dependency_text.nil? then - # dep_text.dependency_text.html_safe - # end - #end row I18n.t('admin.themes') do (question.themes.map{|t_q| link_to t_q.title, [:admin, t_q]}).join(', ').html_safe end @@ -95,14 +73,6 @@ :as => :select, :collection => Section.order('title').map{ |sec| ["#{sec.version.phase.dmptemplate.title} - #{sec.title}", sec.id] } f.input :default_value - # f.input :guidance - # f.input :parent_id, :label => "Parent", - # :as => :select, - # :collection => Question.find(:all, :order => 'text ASC').map{|que|[que.text, que.id]} - #f.input :dependency_id, :label => "Dependency question", - # :as => :select, - # :collection => Question.find(:all, :order => 'text ASC').map{|que|[que.text, que.id]} - # f.input :dependency_text end f.inputs "Question Format" do diff --git a/app/admin/role.rb b/app/admin/role.rb index dc386de..4fcf03b 100644 --- a/app/admin/role.rb +++ b/app/admin/role.rb @@ -5,58 +5,5 @@ # [+Copyright:+] Digital Curation Centre and University of California Curation Center ActiveAdmin.register Role do - permit_params :name, :role_in_plans - - menu :priority => 5, :label => proc{I18n.t('admin.role')}, :parent => "User management" - - index do - column I18n.t('admin.title'), :sortable => :name do |role_name| - link_to role_name.name, [:admin, role_name] - end - - actions - end - - - show do - attributes_table do - row :name - row :role_in_plans - row :created_at - row :updated_at - end - - table_for( (Role.find(params[:id]).users)) do - column (:email){|user| link_to user.email, [:admin, user]} - column (:firstname){|user| user.firstname} - column (:surname){|user| user.surname} - column (:last_sign_in_at){|user| user.last_sign_in_at} - column (I18n.t('admin.org_title')){|user| - if !user.organisation.nil? then - if user.other_organisation.nil? || user.other_organisation == "" then - link_to user.organisation.name, [:admin, user.organisation] - else - I18n.t('helpers.org_type.org_name') + ' - ' + user.other_organisation - - end - end - } - end - - end - - form do |f| - f.inputs "Details" do - f.input :name - f.input :role_in_plans - end - - f.actions - end - - controller do - def permitted_params - params.permit! - end - end + menu false end diff --git a/app/admin/section.rb b/app/admin/section.rb index c8ceab8..4cc6c37 100644 --- a/app/admin/section.rb +++ b/app/admin/section.rb @@ -78,7 +78,7 @@ f.input :title f.input :number f.input :version, :collection => Version.all.map{ |ver| [ver.title, ver.id] } - f.input :organisation, :as => :select, :collection => Organisation.order('name').map{|orgp|[orgp.name, orgp.id]} + f.input :organisation, :as => :select, :collection => Org.order('name').map{|orgp|[orgp.name, orgp.id]} f.input :description end diff --git a/app/admin/suggested_answer.rb b/app/admin/suggested_answer.rb index ab957eb..9c46eab 100644 --- a/app/admin/suggested_answer.rb +++ b/app/admin/suggested_answer.rb @@ -18,7 +18,7 @@ :collection => Question.order('text').map{|ques|[ques.text, ques.id]} f.input :organisation_id, :label => I18n.t('admin.org_title'), :as => :select, - :collection => Organisation.order('name').map{|orgp|[orgp.name, orgp.id]} + :collection => Org.order('name').map{|orgp|[orgp.name, orgp.id]} f.input :text f.input :is_example end diff --git a/app/admin/template.rb b/app/admin/template.rb new file mode 100644 index 0000000..2f2695b --- /dev/null +++ b/app/admin/template.rb @@ -0,0 +1,125 @@ +# [+Project:+] DMPRoadmap +# [+Description:+] +# +# [+Created:+] 03/09/2014 +# [+Copyright:+] Digital Curation Centre and University of California Curation Center + +ActiveAdmin.register Template do + permit_params :title, :description, :organisation_id, :published, :is_default + + menu :priority => 11, :label => proc{ I18n.t('admin.template')}, :parent => "Templates management" + + # FIXME: The below member_actions only work on :export settings. + member_action :settings do + @template = resource + @settings = resource.settings(:export) + end + + member_action :update_settings, method: :put do + new_settings = params[:settings][:export] + + settings = resource.settings(:export).tap do |s| + s.formatting, s.max_pages = if params[:commit] != 'Reset' + [ + new_settings[:formatting].try(:deep_symbolize_keys), + new_settings[:max_pages].try(:to_i) + ] + else + [ nil, nil ] + end + end + + if settings.save + redirect_to(action: :show, flash: { notice: I18n.t('admin.settings_updated') }) + else + settings.formatting = nil + @template = resource + @settings = settings + render(action: :settings) + end + end + + action_item(:edit) do + link_to(I18n.t('helpers.settings.title'), settings_admin_template_path(resource.id)) + end + + index do + column :title do |dmptemp| + link_to dmptemp.title, [:admin, dmptemp] + end + column :description do |descr| + if !descr.description.nil? then + descr.description.html_safe + end + end + column I18n.t('admin.org_title'), :sortable => :organisation_id do |org_title| + if !org_title.organisation.nil? then + link_to org_title.organisation.name, [:admin, org_title.organisation] + else + '-' + end + end + column :published + column :is_default + + actions defaults: true do |template| + link_to(I18n.t('helpers.settings.title'), settings_admin_template_path(template.id)) + end + end + + + # show Template details + show do + attributes_table do + row :title + row :description do |descr| + if !descr.description.nil? then + descr.description.html_safe + end + end + row I18n.t('admin.org_title'), :sortable => :organisation_id do |org_title| + if !org_title.organisation.nil? then + link_to org_title.organisation.name, [:admin, org_title.organisation] + else + '-' + end + end + row :published + row :is_default + row :created_at + row :updated_at + end + end + + #phases sidebar + sidebar I18n.t('admin.phases'), :only => :show, :if => proc { template.phases.count >= 1} do + table_for template.phases.order("number asc") do |temp_phases| + column :number + column :title do |row| + link_to row.title, [:admin, row] + end + end + end + + #form + form do |f| + f.inputs "Details" do + f.input :title + f.input :description + f.input :organisation_id, :label => I18n.t('admin.org_title'), + :as => :select, + :collection => Org.order('name').map{|orgp|[orgp.name, orgp.id]} + f.input :published + f.input :is_default + end + f.actions + end + + controller do + def permitted_params + params.permit! + end + end + +end + diff --git a/app/admin/user.rb b/app/admin/user.rb index 464798b..1456f53 100644 --- a/app/admin/user.rb +++ b/app/admin/user.rb @@ -52,18 +52,6 @@ end end row :other_organisation - # row I18n.t('admin.user_status'), :user_status_id do |us| - # if !us.user_status.nil? then - # link_to us.user_status.name, [:admin, us.user_status] - # end - # end - # row I18n.t('admin.user_type'), :user_type_id do |ut| - # if !ut.user_type.nil? then - # link_to ut.user_type.name, [:admin, ut.user_type] - # else - # '-' - # end - # end row I18n.t('admin.user_role') do (user.roles.map{|ro| link_to ro.name, [:admin, ro]}).join(', ').html_safe end @@ -86,14 +74,8 @@ # f.input :shibboleth_id f.input :organisation_id, :label => I18n.t('admin.org_title'), :as => :select, - :collection => Organisation.order('name').map{|orgp|[orgp.name, orgp.id]} + :collection => Org.order('name').map{|orgp|[orgp.name, orgp.id]} f.input :other_organisation - # f.input :user_status_id, :label => I18n.t('admin.user_status'), - # :as => :select, - # :collection => UserStatus.find(:all, :order => 'name ASC').map{|us|[us.name, us.id]} - # f.input :user_type_id, :label => I18n.t('admin.user_type'), - # :as => :select, - # :collection => UserType.find(:all, :order => 'name ASC').map{|ut|[ut.name, ut.id]} f.input :role_ids, :label => I18n.t('admin.user_role'), :as => :select, :multiple => true, diff --git a/app/admin/user_role_type.rb b/app/admin/user_role_type.rb deleted file mode 100644 index e40f5ee..0000000 --- a/app/admin/user_role_type.rb +++ /dev/null @@ -1,30 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register UserRoleType do - permit_params :description, :name - menu false - #:priority => 5, :label => proc{I18n.t('admin.user_role_type')}, :parent => "User management" - - index do - column I18n.t('admin.title'), :sortable => :name do |user_n| - link_to user_n.name, [:admin, user_n] - end - column I18n.t('admin.desc'),:description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - - actions - end - - controller do - def permitted_params - params.permit! - end - end -end diff --git a/app/admin/user_status.rb b/app/admin/user_status.rb deleted file mode 100644 index 856577c..0000000 --- a/app/admin/user_status.rb +++ /dev/null @@ -1,31 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register UserStatus do - permit_params :description, :name - - menu false - #:priority => 5, :label => proc{I18n.t('admin.user_status')}, :parent => "User management" - - index do - column I18n.t('admin.title'), :sortable => :name do |user_n| - link_to user_n.name, [:admin, user_n] - end - column I18n.t('admin.desc'),:description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - - actions - end - - controller do - def permitted_params - params.permit! - end - end -end diff --git a/app/admin/user_type.rb b/app/admin/user_type.rb deleted file mode 100644 index 7836401..0000000 --- a/app/admin/user_type.rb +++ /dev/null @@ -1,42 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register UserType do - permit_params :description, :name - - menu false - #:priority => 5, :label => proc{I18n.t('admin.user_type')}, :parent => "User management" - - index do - column I18n.t('admin.user_type'), :sortable => :name do |user_n| - link_to user_n.name, [:admin, user_n] - end - - actions - end - - # show Template details - show do - attributes_table do - row :name - row :description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - row :created_at - row :updated_at - end - end - - controller do - def permitted_params - params.permit! - end - end - - -end diff --git a/app/admin/version.rb b/app/admin/version.rb deleted file mode 100644 index 7dbed51..0000000 --- a/app/admin/version.rb +++ /dev/null @@ -1,86 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] -# -# [+Created:+] 03/09/2014 -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -ActiveAdmin.register Version do - permit_params :description, :number, :published, :title, :phase_id - - menu :priority => 9, :label => proc{I18n.t('admin.version')}, :parent => "Templates management" - - index do - column I18n.t('admin.title'), :sortable => :title do |version_used| - if !version_used.title.nil? then - link_to version_used.title, [:admin, version_used] - end - end - column I18n.t('admin.version_numb'), :number - column :published - column I18n.t('admin.phase'), :sortable => :phase_id do |phase_title| - if !phase_title.phase_id.nil? then - link_to phase_title.phase.title, [:admin, phase_title.phase] - else - '-' - end - end - - actions - end - - #show details of a version - show do - attributes_table do - row :title - row :number - row :description do |descr| - if !descr.description.nil? then - descr.description.html_safe - end - end - row I18n.t('admin.phase'), :sortable => :phase_id do |phase_title| - if !phase_title.phase_id.nil? then - link_to phase_title.phase.title, [:admin, phase_title.phase] - end - end - row :published - row :created_at - row :updated_at - end - - end - - #sections sidebar (:organisation_id, :description, :number, :title, :version_id) - sidebar I18n.t('admin.sections'), :only => :show, :if => proc { version.sections.count >= 1} do - table_for version.sections.order("number") do |temp_phases| - column :number - column :title do |row| - link_to row.title, [:admin, row] - end - column I18n.t('admin.org_title'), :sortable => :organisation_id do |org_title| - link_to org_title.organisation.name, [:admin, org_title.organisation] - end - - end - end - - #form - form do |f| - f.inputs "Details" do - f.input :title - f.input :number - f.input :description - f.input :phase, :label => I18n.t('admin.phase_title'), - :as => :select, - :collection => Phase.order('title').map{|ph|[ph.title, ph.id]} - f.input :published - end - f.actions - end - - controller do - def permitted_params - params.permit! - end - end -end diff --git a/app/assets/images/orcid.png b/app/assets/images/orcid.png deleted file mode 100644 index 2db382d..0000000 --- a/app/assets/images/orcid.png +++ /dev/null Binary files differ diff --git a/app/assets/images/remove.png b/app/assets/images/remove.png deleted file mode 100644 index b2ef137..0000000 --- a/app/assets/images/remove.png +++ /dev/null Binary files differ diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index e157e76..8ef2500 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -1,37 +1,50 @@ class AnswersController < ApplicationController after_action :verify_authorized + respond_to :html - # POST /answers - def create - @answer = Answer.new(params[:answer]) + ## + # PUT/PATCH /[:locale]/answer/[:id] + def update + # create a new answer based off the passed params + + ans_params = params[:answer] + plan_id = ans_params[:plan_id] + user_id = ans_params[:user_id] + question_id = ans_params[:question_id] + @answer = Answer.find_by( + plan_id: plan_id, + user_id: user_id, + question_id: question_id) + if @answer.nil? + @answer = Answer.new(params[:answer]) + end + authorize @answer - old_answer = @answer.plan.answer(@answer.question_id, false) - proceed = false + +puts params.inspect + @answer.text = params["answer-text-#{@answer.question_id}".to_sym] - if (old_answer.nil? && @answer.text != "") || ((!old_answer.nil?) && (old_answer.text != @answer.text)) then - proceed = true - end - - if (@answer.question.question_format.title == I18n.t("helpers.checkbox") || - @answer.question.question_format.title == I18n.t("helpers.multi_select_box") || - @answer.question.question_format.title == I18n.t("helpers.radio_buttons") || - @answer.question.question_format.title == I18n.t("helpers.dropdown")) then - if (old_answer.nil? && @answer.option_ids.count > 0) || ((!old_answer.nil?) && (old_answer.option_ids - @answer.option_ids).count != 0 && (@answer.option_ids - old_answer.option_ids).count != 0) then - proceed = true + + #TODO: check for optimistic locking + + # Is this validation necessary? +# if (@answer.question.question_format.title == I18n.t("helpers.checkbox") || +# @answer.question.question_format.title == I18n.t("helpers.multi_select_box") || +# @answer.question.question_format.title == I18n.t("helpers.radio_buttons") || +# @answer.question.question_format.title == I18n.t("helpers.dropdown")) then +# if (old_answer.nil? && @answer.option_ids.count > 0) || ((!old_answer.nil?) && (old_answer.option_ids - @answer.option_ids).count != 0 && (@answer.option_ids - old_answer.option_ids).count != 0) then +# proceed = true +# end +# end + +# if proceed + if @answer.save + redirect_to :back, status: :found, notice: I18n.t('helpers.project.answer_recorded') + else + redirect_to :back, notice: I18n.t('helpers.project.answer_error') end - end - if proceed - respond_to do |format| - if @answer.save - format.html { redirect_to :back, status: :found, notice: I18n.t('helpers.project.answer_recorded') } - else - format.html { redirect_to :back, notice: I18n.t('helpers.project.answer_error') } - end - end - else - respond_to do |format| - format.html { redirect_to :back, notice: I18n.t('helpers.project.answer_no_change') } - end - end +# else +# redirect_to :back, notice: I18n.t('helpers.project.answer_no_change') +# end end -end \ No newline at end of file +end diff --git a/app/controllers/api/v0/base_controller.rb b/app/controllers/api/v0/base_controller.rb index 7e939fd..631983e 100644 --- a/app/controllers/api/v0/base_controller.rb +++ b/app/controllers/api/v0/base_controller.rb @@ -121,7 +121,7 @@ end def has_auth (auth_type) - auth = false + #auth = false # not sure if initial if is necissary, but it works with it there... refactor later? # if !TokenPermission.where(api_token: @token).nil? # TokenPermission.where(api_token: @token).find_each do |permission| @@ -131,13 +131,16 @@ # end # end # end - OrgTokenPermission.where(organisation_id: @user.organisation_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 - end - end - return auth + + #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 + # end + #end + #return auth + tpt = TokenPermissionType.find_by(token_type: auth) + org.token_permission_types.include?(tpt) end end 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..c96d174 --- /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 + org = Org.find_by name: params[:template][:organisation] + + # if organization exists + if !org.nil? + # if organization is funder + if org.funder? + # if organization has only 1 template + if org.templates.length == 1 + # set template id + template = org.templates.first + # else if params.template.name specified && params.template.name == one of organization's tempates + elsif !org.templates.find_by title: params[:template][:name].nil? + # set template id + template = org.templates.find_by title: params[:template][:name] + # else error: organization has more than one template and template name unspecified + else + render json: I18n.t("api.org_multiple_templates"), status: 400 and return + 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 = Plan.new + @project.title = params[:project][:title] + @project.template = template + @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 47bae8d..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] = Organisation.where(name: params[:template][:organization]) - # find_by returns nil if none found, find_by! raises an ActiveRecord error - organization = Organisation.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..a09bec3 100644 --- a/app/controllers/api/v0/statistics_controller.rb +++ b/app/controllers/api/v0/statistics_controller.rb @@ -8,8 +8,8 @@ # @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")) - users = restrict_date_range(@user.organisations.first.users) + if has_auth(constant("token_permission_types.statistics")) + users = restrict_date_range(@user.org.users) confirmed_users = [] users.each do |user| unless user.confirmed_at.blank? @@ -29,10 +29,10 @@ # @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 + if template.org == @user.org + @template_count = restrict_date_range(template.plans).count respond_with @template_count else #no auth to view statistics for this template @@ -48,12 +48,12 @@ # 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| - unless @org_projects.include? project - @org_projects += [project] + @user.org.users.each do |user| + user.plans.each do |plan| + unless @org_projects.include? plan + @org_projects += [plan] end end end @@ -70,12 +70,12 @@ # 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| - unless @org_projects.include? project - @org_projects += [project] + @user.org.users.each do |user| + user.plans.each do |plan| + unless @org_projects.include? plan + @org_projects += [plan] end end end 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/application_controller.rb b/app/controllers/application_controller.rb index b2f7983..a02811c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,29 +17,21 @@ redirect_to root_url, alert: I18n.t('unauthorized') end - before_filter :set_locale + before_filter :set_gettext_locale after_filter :store_location - def set_locale - # parameter from url takes precedence - # check if locale is defined - if params[:locale] # and I18n.available_locales.include? params[:locale] # throw an error if not available - # if locales data is present in the parameter from url use it - I18n.locale = params[:locale] - + def set_gettext_locale + if params[:locale] and FastGettext.default_available_locales.include?(params[:locale]) + FastGettext.locale = params[:locale] elsif user_signed_in? and !current_user[:language_id].nil? - I18n.locale = Language.find_by_id(current_user[:language_id]).abbreviation - # if user has set preferred language use it - - elsif user_signed_in? and current_user.organisation.present? and !current_user.organisation[:language_id].nil? - I18n.locale = Language.find_by_id(current_user.organisation[:language_id]).abbreviation - # use user's organization language, keep in mine the "OTHER ORG" edge case which should use default language - + FastGettext.locale = Language.find_by_id(current_user[:language_id]).abbreviation #Relies on successful db call + elsif user_signed_in? and current_user.org.present? and !current_user.org[:language_id].nil? + FastGettext.locale = Language.find_by_id(current_user.org[:language_id]).abbreviation #Relies on successful db call else - # just use the default language, line can be commented out, included just for clarity - I18n.locale = I18n.default_locale + FastGettext.locale = FastGettext.default_locale end + puts 'FastGettext.locale = '+FastGettext.locale end # Added setting for passing local params across pages diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb deleted file mode 100644 index 87838cb..0000000 --- a/app/controllers/comments_controller.rb +++ /dev/null @@ -1,61 +0,0 @@ -class CommentsController < ApplicationController - after_action :verify_authorized - - # POST /comments - def create - @comment = Comment.new(params[:new_comment]) - @comment.text = params["#{params[:new_comment][:question_id]}new_comment_text"] - @comment.question_id = params[:new_comment][:question_id] - @comment.user_id = params[:new_comment][:user_id] - @comment.plan_id = params[:new_comment][:plan_id] - authorize @comment - - @plan = Plan.find(@comment.plan_id) - @project = Project.find(@plan.project_id) - - respond_to do |format| - if @comment.save - session[:question_id_comments] = @comment.question_id - format.html { redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.comment_created") } - end - end - end - - # PUT /comments/1 - def update - @comment = Comment.find(params[:comment][:id]) - authorize @comment - @comment.text = params["#{params[:comment][:id]}_comment_text"] - - @plan = Plan.find(@comment.plan_id) - @project = Project.find(@plan.project_id) - - respond_to do |format| - if @comment.update_attributes(params[:comment]) - session[:question_id_comments] = @comment.question_id - format.html { redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.comment_updated") } - end - end - end - - # ARCHIVE /comments/1 - # ARCHIVE /comments/1.json - def archive - @comment = Comment.find(params[:comment][:id]) - authorize @comment - @comment.archived = true - @comment.archived_by = params[:comment][:archived_by] - - @plan = Plan.find(@comment.plan_id) - @project = Project.find(@plan.project_id) - - respond_to do |format| - if @comment.update_attributes(params[:comment]) - session[:question_id_comments] = @comment.question_id - format.html { redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.comment_removed") } - end - end - end - - -end diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index ae9e85a..36fa10f 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -1,33 +1,28 @@ class ContactsController < ContactUs::ContactsController + respond_to :html - # in order to i18 this file recaptcha gem has to be updated - + ## + # create + # + # POST - Create a Contact Request def create @contact = ContactUs::Contact.new(params[:contact_us_contact]) if (!user_signed_in?) - if verify_recaptcha(:message => "You have not added the validation words correctly") && @contact.save + if verify_recaptcha(message: "You have not added the validation words correctly") && @contact.save flash[:notice] = t('contact_us.notices.success') - if user_signed_in? then - redirect_to :controller => 'projects', :action => 'index' - else - redirect_to(root_path) - end - else - flash[:alert] = t('contact_us.notices.error') - render_new_page + redirect_to(root_path) + else # recaptcha invalid or contact failed to save + flash[:alert] = t('contact_us.notices.error') + render_new_page end - else + else # no user signed in if @contact.save flash[:notice] = t('contact_us.notices.success') - if user_signed_in? then - redirect_to :controller => 'projects', :action => 'index' - else - redirect_to(root_path) - end - else - flash[:alert] = t('contact_us.notices.error') - render_new_page + redirect_to :controller => 'projects', :action => 'index' + else # contact failed to save + flash[:alert] = t('contact_us.notices.error') + render_new_page end - end + end end end \ No newline at end of file diff --git a/app/controllers/dmptemplates_controller.rb b/app/controllers/dmptemplates_controller.rb deleted file mode 100644 index 9c7f757..0000000 --- a/app/controllers/dmptemplates_controller.rb +++ /dev/null @@ -1,450 +0,0 @@ -# [+Project:+] DMPRoadmap -# [+Description:+] This controller is responsible for all the actions in the admin interface under templates (e.g. phases, versions, sections, questions, suggested answer) (index; show; create; edit; delete) -# [+Copyright:+] Digital Curation Centre and University of California Curation Center - -class DmptemplatesController < ApplicationController - after_action :verify_authorized - - # GET /dmptemplates - def admin_index - authorize Dmptemplate - #institutional templates - @dmptemplates_own = Dmptemplate.own_institutional_templates(current_user.organisation_id) - #funders templates - @dmptemplates_funders = Dmptemplate.funders_templates - respond_to do |format| - format.html # index.html.erb - end - end - - # GET /dmptemplates/1 - def admin_template - @dmptemplate = Dmptemplate.find(params[:id]) - authorize @dmptemplate - respond_to do |format| - format.html # show.html.erb - end - 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 - end - - - # GET /dmptemplates/new - def admin_new - @dmptemplate = Dmptemplate.new - authorize @dmptemplate - respond_to do |format| - format.html # new.html.erb - end - end - - # POST /dmptemplates - 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 - 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 - - - - # 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 - 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 - @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 - - -# SECTIONS - #create a section - def admin_createsection - @section = Section.new(params[:section]) - authorize @section.version.phase.dmptemplate - @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 - 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 - 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 - @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 - - -# QUESTIONS - - #create a question - def admin_createquestion - @question = Question.new(params[:question]) - authorize @question.section.version.phase.dmptemplate - @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 - 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 - @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 - - - #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 - 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 - @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 - 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 - - -end \ No newline at end of file diff --git a/app/controllers/guidance_groups_controller.rb b/app/controllers/guidance_groups_controller.rb index 8b3a6d5..3729dd7 100644 --- a/app/controllers/guidance_groups_controller.rb +++ b/app/controllers/guidance_groups_controller.rb @@ -1,13 +1,11 @@ class GuidanceGroupsController < ApplicationController after_action :verify_authorized + respond_to :html # GET /guidance_groups/1 def admin_show @guidance_group = GuidanceGroup.find(params[:id]) authorize @guidance_group - respond_to do |format| - format.html - end end @@ -15,9 +13,6 @@ def admin_new @guidance_group = GuidanceGroup.new authorize @guidance_group - respond_to do |format| - format.html # new.html.erb - end end @@ -26,17 +21,15 @@ def admin_create @guidance_group = GuidanceGroup.new(params[:guidance_group]) authorize @guidance_group - @guidance_group.organisation_id = current_user.organisation_id - if params[:save_publish] - @guidance_group.published = true - end + @guidance_group.org_id = current_user.org_id + if params[:save_publish] + @guidance_group.published = true + end - respond_to do |format| - if @guidance_group.save - format.html { redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.created_message') } - else - format.html { render action: "new" } - end + if @guidance_group.save + redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.created_message') + else + render action: "new" end end @@ -52,13 +45,12 @@ def admin_update @guidance_group = GuidanceGroup.find(params[:id]) authorize @guidance_group - @guidance_group.organisation_id = current_user.organisation_id - respond_to do |format| - if @guidance_group.update_attributes(params[:guidance_group]) - format.html { redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') } - else - format.html { render action: "edit" } - end + @guidance_group.org_id = current_user.org_id + + if @guidance_group.update_attributes(params[:guidance_group]) + redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') + else + render action: "edit" end end @@ -67,15 +59,13 @@ def admin_update_publish @guidance_group = GuidanceGroup.find(params[:id]) authorize @guidance_group - @guidance_group.organisation_id = current_user.organisation_id - @guidance_group.published = true + @guidance_group.org.id = current_user.org.id + @guidance_group.published = true - respond_to do |format| - if @guidance_group.update_attributes(params[:guidance_group]) - format.html { redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') } - else - format.html { render action: "edit" } - end + if @guidance_group.update_attributes(params[:guidance_group]) + redirect_to admin_index_guidance_path(params[:guidance_group]), notice: I18n.t('org_admin.guidance_group.updated_message') + else + render action: "edit" end end @@ -86,9 +76,8 @@ @guidance_group = GuidanceGroup.find(params[:id]) authorize @guidance_group @guidance_group.destroy - respond_to do |format| - format.html { redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.destroyed_message') } - end + + redirect_to admin_index_guidance_path, notice: I18n.t('org_admin.guidance_group.destroyed_message') end end \ No newline at end of file diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index 8df36eb..75c0808 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -1,51 +1,44 @@ class GuidancesController < ApplicationController after_action :verify_authorized - + respond_to :html + + ## # GET /guidances def admin_index authorize Guidance @guidances = policy_scope(Guidance) - @guidance_groups = GuidanceGroup.where('organisation_id = ?', current_user.organisation_id ) - respond_to do |format| - format.html # index.html.erb - end + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id) end + ## # GET /guidances/1 def admin_show - @guidance = Guidance.find(params[:id]) + @guidance = Guidance.includes(:guidance_group, :question, :themes).find(params[:id]) authorize @guidance - respond_to do |format| - format.html # show.html.erb - end end def admin_new @guidance = Guidance.new authorize @guidance - @dmptemplates = Dmptemplate.funders_and_own_templates(current_user.organisation_id) + + #@templates = Template.funders_and_own_templates(current_user.org_id) + # Replacing weird accessor on Template + @templates = (Org.funders.collect{|o| o.templates } + current_user.org.templates).flatten + @phases = nil - @dmptemplates.each do |template| + @templates.includes(:phases).each do |template| if @phases.nil? then @phases = template.phases.all.order('number') else @phases = @phases + template.phases.all.order('number') end end - @versions = nil - @phases.each do |phase| - if @versions.nil? then - @versions = phase.versions.all.order('title') - else - @versions = @versions + phase.versions.all.order('title') - end - end @sections = nil - @versions.each do |version| + @phases.each do |phase| if @sections.nil? then - @sections = version.sections.all.order('number') + @sections = phase.sections.all.order('number') else - @sections = @sections + version.sections.all.order('number') + @sections = @sections + phase.sections.all.order('number') end end @questions = nil @@ -56,16 +49,15 @@ @questions = @questions + section.questions.all.order('number') end end - respond_to do |format| - format.html - end + @themes = Theme.all.order('title') + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') end #setup variables for use in the dynamic updating def update_phases authorize Guidance # updates phases, versions, sections and questions based on template selected - dmptemplate = Dmptemplate.find(params[:dmptemplate_id]) + dmptemplate = Template.find(params[:dmptemplate_id]) # map to title and id for use in our options_for_select @phases = dmptemplate.phases.map{|a| [a.title, a.id]}.insert(0, I18n.t('helpers.select_phase')) @versions = dmptemplate.versions.map{|s| [s.title, s.id]}.insert(0, I18n.t('helpers.select_version')) @@ -99,92 +91,60 @@ @questions = section.questions.map{|s| [s.text, s.id]}.insert(0, I18n.t('helpers.select_question')) end - + ## # GET /guidances/1/edit def admin_edit - @guidance = Guidance.find(params[:id]) + @guidance = Guidance.includes(:themes, :guidance_group).find(params[:id]) authorize @guidance - @dmptemplates = Dmptemplate.funders_and_own_templates(current_user.organisation_id) - @phases = nil - @dmptemplates.each do |template| - if @phases.nil? then - @phases = template.phases.all.order('number') - else - @phases = @phases + template.phases.all.order('number') - end - end - @versions = nil - @phases.each do |phase| - if @versions.nil? then - @versions = phase.versions.all.order('title') - else - @versions = @versions + phase.versions.all.order('title') - end - end - @sections = nil - @versions.each do |version| - if @sections.nil? then - @sections = version.sections.all.order('number') - else - @sections = @sections + version.sections.all.order('number') - end - end - @questions = nil - @sections.each do |section| - if @questions.nil? then - @questions = section.questions.all.order('number') - else - @questions = @questions + section.questions.all.order('number') - end - end + @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC') + @themes = Theme.all.order('title') end + ## # POST /guidances def admin_create @guidance = Guidance.new(params[:guidance]) authorize @guidance @guidance.text = params["guidance-text"] @guidance.question_id = params["question_id"] - if @guidance.published == true then - @gg = GuidanceGroup.find(@guidance.guidance_group_ids).first - if @gg.published == false || @gg.published.nil? then - @gg.published = true - @gg.save - end + if @guidance.published == true then + @gg = GuidanceGroup.find(@guidance.guidance_group_ids).first + if @gg.published == false || @gg.published.nil? then + @gg.published = true + @gg.save end - respond_to do |format| - if @guidance.save - format.html { redirect_to admin_show_guidance_path(@guidance), notice: I18n.t('org_admin.guidance.created_message') } - else - format.html { render action: "new" } - end + end + + if @guidance.save + redirect_to admin_show_guidance_path(@guidance), notice: I18n.t('org_admin.guidance.created_message') + else + render action: "new" end end + ## # PUT /guidances/1 def admin_update @guidance = Guidance.find(params[:id]) authorize @guidance @guidance.text = params["guidance-text"] @guidance.question_id = params["question_id"] - respond_to do |format| - if @guidance.update_attributes(params[:guidance]) - format.html { redirect_to admin_show_guidance_path(params[:guidance]), notice: I18n.t('org_admin.guidance.updated_message') } - else - format.html { render action: "edit" } - end + + if @guidance.update_attributes(params[:guidance]) + redirect_to admin_show_guidance_path(params[:guidance]), notice: I18n.t('org_admin.guidance.updated_message') + else + render action: "edit" end end - + ## # DELETE /guidances/1 def admin_destroy @guidance = Guidance.find(params[:id]) authorize @guidance @guidance.destroy - respond_to do |format| - format.html { redirect_to admin_index_guidance_path } - end + + redirect_to admin_index_guidance_path end end \ No newline at end of file diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index fe5a071..a311c09 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,12 +1,20 @@ class HomeController < ApplicationController + respond_to :html + ## + # Index + # + # Currently redirects user to their list of projects + # UNLESS + # User's contact name is not filled in + # Is this the desired behavior? def index if user_signed_in? name = current_user.name(false) if name.blank? redirect_to edit_user_registration_path else - redirect_to projects_url + redirect_to plans_url end end end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb new file mode 100644 index 0000000..8a400f6 --- /dev/null +++ b/app/controllers/notes_controller.rb @@ -0,0 +1,71 @@ +class NotesController < ApplicationController + after_action :verify_authorized + respond_to :html + + ## + # POST /notes + def create + @note = Note.new + user_id = params[:new_note][:user_id] + @note.user_id = user_id + + answer_id = params[:new_note][:answer_id] + question_id = params[:new_note][:question_id] + plan_id = params[:new_note][:plan_id] + if answer_id.present? + answer = Answer.find(@note.answer_id) + else + answer = Answer.new + answer.plan_id = plan_id + answer.question_id = question_id + answer.user_id = user_id + answer.save! + end + + @note.answer= answer + @note.text = params["#{params[:new_note][:answer_id]}new_note_text"] + + authorize @note + + @plan = answer.plan + @phase = answer.question.section.phase + + if @note.save + session[:question_id_notes] = answer.question_id + redirect_to edit_plan_phase_path(@plan, @phase), status: :found, notice: I18n.t("helpers.comments.note_created") + end + end + + ## + # PUT /notes/1 + def update + @note = Note.find(params[:note][:id]) + authorize @note + @note.text = params["#{params[:note][:id]}_note_text"] + + @plan = Plan.find(@note.plan_id) + @project = Project.find(@plan.project_id) + + if @note.update_attributes(params[:note]) + session[:question_id_notes] = @note.question_id + redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.note_updated") + end + end + + ## + # ARCHIVE /notes/1 + def archive + @note = Note.find(params[:note][:id]) + authorize @note + @note.archived = true + @note.archived_by = params[:note][:archived_by] + + @plan = Plan.find(@note.plan_id) + @project = Project.find(@plan.project_id) + + if @note.update_attributes(params[:note]) + session[:question_id_notes] = @note.question_id + redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: I18n.t("helpers.comments.note_removed") + end + end +end diff --git a/app/controllers/organisation_users_controller.rb b/app/controllers/organisation_users_controller.rb deleted file mode 100644 index 6bdeeb3..0000000 --- a/app/controllers/organisation_users_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -class OrganisationUsersController < ApplicationController - - def admin_index - if user_signed_in? && current_user.is_org_admin? then - # find excluded user_id's - excluded_ids = params[:user_ids] - excluded_ids.each do |user_id| - User.find(user_id).remove_token - end - # remove their api_tokens - # find included user id's - params[:user_ids].each do |user_id| - User.find(user_id).keep_or_generate_token - end - # keep_or_generate_token - respond_to do |format| - format.html # index.html.erb - format.json { render json: @organisation_users } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - -end \ No newline at end of file diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb deleted file mode 100644 index cd4c340..0000000 --- a/app/controllers/organisations_controller.rb +++ /dev/null @@ -1,91 +0,0 @@ -class OrganisationsController < ApplicationController - after_action :verify_authorized - - # GET /organisations/1 - def admin_show - @organisation = Organisation.find(params[:id]) - authorize @organisation - respond_to do |format| - format.html # show.html.erb - end - end - - # GET /organisations/1/edit - def admin_edit - @organisation = Organisation.find(params[:id]) - authorize @organisation - - @languages = Language.all.order("name") - end - - - # PUT /organisations/1 - def admin_update - @organisation = Organisation.find(params[:id]) - authorize @organisation - @organisation.banner_text = params["org_banner_text"] - @organisation.logo = params[:organisation][:logo] if params[:organisation][:logo] - assign_params = params[:organisation].dup - assign_params.delete(:logo) - assign_params.delete(:contact_email) unless params[:organisation][:contact_email].present? - - respond_to do |format| - begin - if @organisation.update_attributes(assign_params) - format.html { redirect_to admin_show_organisation_path(params[:id]), notice: I18n.t("admin.org_updated_message") } - else - flash[:noice] = @organisation.errors.collect{|e| e.message}.join('
').html_safe - format.html { render action: "admin_edit" } - end - - rescue Dragonfly::Job::Fetch::NotFound => dflye - flash[:notice] = I18n.t("admin.org_bad_logo") - format.html {render action: "admin_edit"} - end - end - end - - #TODO: see if this is used by the ajax... otherwise lock it down - def parent - @organisation = Organisation.find(params[:id]) - authorize @organisation - parent_org = @organisation.find_by {|o| o.parent_id } - return parent_org - end - - #TODO: see is this is used by the ajax... otherwise lock it down - def children - @organisation = Organisation.find(params[:id]) - authorize @organisation - #if user_signed_in? then - children = {} - @organisation.children.each do |child| - children[child.id] = child.name - end - respond_to do |format| - format.json { render json: children.to_json } - end -# else -# render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) -# end - end - - #TODO: see if this is used by the ajax... otherwise lock it down - def templates - @organisation = Organisation.find(params[:id]) - authorize @organisation - #if user_signed_in? then - templates = {} - @organisation.dmptemplates.each do |template| - if template.is_published? then - templates[template.id] = template.title - end - end - respond_to do |format| - format.json { render json: templates.to_json } - end -# else -# render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) -# end - end -end diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb new file mode 100644 index 0000000..905fd06 --- /dev/null +++ b/app/controllers/orgs_controller.rb @@ -0,0 +1,43 @@ +class OrgsController < ApplicationController + after_action :verify_authorized + respond_to :html + + ## + # GET /organisations/1 + def admin_show + @org = Org.find(params[:id]) + authorize @org + end + + ## + # GET /organisations/1/edit + def admin_edit + @org = Org.find(params[:id]) + authorize @org + @languages = Language.all.order("name") + end + + ## + # PUT /organisations/1 + def admin_update + @org = Org.find(params[:id]) + authorize @org + @org.banner_text = params["org_banner_text"] + @org.logo = params[:org][:logo] if params[:org][:logo] + assign_params = params[:org].dup + assign_params.delete(:logo) + assign_params.delete(:contact_email) unless params[:org][:contact_email].present? + + begin + if @org.update_attributes(assign_params) + redirect_to admin_show_org_path(params[:id]), notice: I18n.t("admin.org_updated_message") + else + flash[:notice] = @org.errors.collect{|e| e.message}.join('
').html_safe + render action: "admin_edit" + end + rescue Dragonfly::Job::Fetch::NotFound => dflye + flash[:notice] = I18n.t("admin.org_bad_logo") + render action: "admin_edit" + end + end +end diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb new file mode 100644 index 0000000..b65f33f --- /dev/null +++ b/app/controllers/phases_controller.rb @@ -0,0 +1,55 @@ +class PhasesController < ApplicationController + require 'pp' + + after_action :verify_authorized + + TEXTAREA = QuestionFormat.where(title: "Text area").first.id + TEXTFIELD = QuestionFormat.where(title: "Text field").first.id + RADIO = QuestionFormat.where(title: "Radio buttons").first.id + CHECKBOX = QuestionFormat.where(title: "Check box").first.id + DROPDOWN = QuestionFormat.where(title: "Dropdown").first.id + MULTI = QuestionFormat.where(title: "Multi select box").first.id + + # GET /plans/PLANID/phases/PHASEID/edit + def edit + + @textarea = TEXTAREA + @textfield = TEXTFIELD + @radio = RADIO + @checkbox = CHECKBOX + @dropdown = DROPDOWN + @multi = MULTI + + @plan = Plan.find(params[:plan_id]) + authorize @plan + + @plan_data = @plan.to_hash + + phase_id = params[:id].to_i + @phase = Phase.find(phase_id) + @phase_data = @plan_data["template"]["phases"].select {|p| p["id"] == phase_id}.first + + if !user_signed_in? then + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + end + + end + + + # GET /plans/PLANID/phases/PHASEID/status.json + def status + @plan = Plan.find(params[:plan_id]) + authorize @plan + if user_signed_in? && @plan.readable_by?(current_user.id) then + respond_to do |format| + format.json { render json: @plan.status } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + +end diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index f5125d6..edae8f5 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -1,218 +1,479 @@ class PlansController < ApplicationController - #Uncomment the line below in order to add authentication to this page - users without permission will not be able to add new plans - #load_and_authorize_resource + require 'pp' + #Uncomment the line below in order to add authentication to this page - users without permission will not be able to add new plans + #load_and_authorize_resource + # + before_filter :get_plan_list_columns, only: %i( index ) after_action :verify_authorized - - # GET /plans/1/edit - def edit - @plan = Plan.find(params[:id]) + TEXTAREA = QuestionFormat.where(title: "Text area").first.id + TEXTFIELD = QuestionFormat.where(title: "Text field").first.id + RADIO = QuestionFormat.where(title: "Radio buttons").first.id + CHECKBOX = QuestionFormat.where(title: "Check box").first.id + DROPDOWN = QuestionFormat.where(title: "Dropdown").first.id + MULTI = QuestionFormat.where(title: "Multi select box").first.id + + def index + authorize Plan + @plans = current_user.plans + end + + + + # GET /plans/new + def new + if user_signed_in? then + @plan = Plan.new + authorize @plan + @funders = Org.funders.all + + respond_to do |format| + format.html # new.html.erb + end + else + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + end + end + + + def create + if user_signed_in? then + @plan = Plan.new + authorize @plan + @plan.save + + funder_id = params[:plan][:funder_id] + if !funder_id.blank? + # get all funder @templates + funder = Org.find(params[:plan][:funder_id]) + @templates = get_most_recent( funder.templates.where("published = ?", true).all ) + + orgtemplates = current_user.org.templates.all + replacements = [] + + # replace any that are customised by the org + orgtemplates.each do |orgt| + base_template = orgt.customization_of + @templates.delete(base_template) + replacements << orgt + end + @templates + replacements + + else + # get all org @templates which are not customisations + @templates = current_user.org.templates.where(customization_of: nil) + + # if none of these get the basic dcc template + if @templates.blank? + @templates = Template.find_by_is_default(true) + end + end + + # if we have more than one template then back to the user + # using the 'create' template + # to choose otherwise just create the plan + # and go to the plan/show template + if @templates.length > 1 + return + end + + @plan.template = @templates[0] + + @plan.principal_investigator = current_user.name + + @plan.title = I18n.t('helpers.project.my_project_name')+' ('+@plan.template.title+')' + + @plan.assign_creator(current_user.id) + + @plan.set_possible_guidance_groups + + @selected_guidance_groups = @plan.guidance_groups.map{ |pgg| [pgg.name, pgg.id, :checked => false] } + @selected_guidance_groups.sort! + + respond_to do |format| + if @plan.save + #format.html { redirect_to({:action => "show", :id => @plan.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } + format.html { redirect_to({:action => "show", :id => @plan.id, :editing => true }, {:notice => I18n.t('helpers.project.success')}) } + else + @error = "Something went wrong" + format.html { render action: "new" } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + + + # GET /plans/show + def show + @plan = Plan.find(params[:id]) authorize @plan + + @plan_data = @plan.to_hash + + @editing = params[:editing] && @plan.administerable_by?(current_user.id) + @selected_guidance_groups = [] + all_guidance_groups = @plan_data["plan_guidance_groups"] + @selected_guidance_groups = all_guidance_groups.map{ |pgg| [ pgg["guidance_group"]["name"], pgg["guidance_group"]["id"], :checked => pgg["selected"] ] } + @selected_guidance_groups.sort! + + if user_signed_in? && @plan.readable_by?(current_user.id) then + respond_to do |format| + format.html # show.html.erb + end + elsif user_signed_in? then + respond_to do |format| + format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + else + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + end + end + + + + # we can go into this with the user able to edit or not able to edit + # the same edit form gets rendered but then different partials get used + # to render the answers depending on whether it is readonly or not + # + # we may or may not have a phase param. + # if we have none then we are editing/displaying the plan details + # if we have a phase then we are editing that phase. + # + # GET /plans/1/edit + def edit + @textarea = TEXTAREA + @textfield = TEXTFIELD + @radio = RADIO + @checkbox = CHECKBOX + @dropdown = DROPDOWN + @multi = MULTI + + @plan = Plan.find(params[:id]) + + @phase = nil + if params[:phase] + @phase = Phase.find(params[:phase]) + end + + authorize @plan + @readonly = @plan.editable_by?(current_user.id) if !user_signed_in? then respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - elsif !@plan.readable_by(current_user.id) then - respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } - end - end - end + format.html { redirect_to edit_user_registration_path } + end + elsif !@plan.readable_by?(current_user.id) then + respond_to do |format| + format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + end + end - # PUT /plans/1 - # PUT /plans/1.json - def update - @plan = Plan.find(params[:id]) + # PUT /plans/1 + # PUT /plans/1.json + def update + @plan = Plan.find(params[:id]) authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.update_attributes(params[:plan]) - format.html { redirect_to @plan, notice: I18n.t('helpers.project.success_update') } - format.json { head :no_content } - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + if user_signed_in? && @plan.editable_by?(current_user.id) then + respond_to do |format| + if @plan.update_attributes(params[:plan]) + format.html { redirect_to @plan, :editing => false, notice: I18n.t('helpers.project.success_update') } + format.json { head :no_content } + else + format.html { render action: "edit" } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + + + def update_guidance_choices + @plan = Plan.find(params[:id]) + authorize @plan + if user_signed_in? && @plan.editable_by?(current_user.id) then + guidance_ids = params[:plan][:plan_guidance_group_ids] + @plan.plan_guidance_groups.each do |pgg| + pgg.selected = guidance_ids.include?(pgg.guidance_group_id.to_s) + pgg.save! + end + @plan.save! + + respond_to do |format| + format.json { head :no_content } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + def share + @plan = Plan.find(params[:id]) + authorize @plan + @plan_data = @plan.to_hash + if !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 plans_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + end + end + + + def destroy + @plan = Plan.find(params[:id]) + authorize @plan + if user_signed_in? && @plan.editable_by?(current_user.id) then + @plan.destroy + + respond_to do |format| + format.html { redirect_to plans_url } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end # GET /status/1.json - # only returns json, why is this here? + # only returns json, why is this here? def status - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.readable_by(current_user.id) then - respond_to do |format| - format.json { render json: @plan.status } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def section_answers - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.readable_by(current_user.id) then - respond_to do |format| - format.json { render json: @plan.section_answers(params[:section_id]) } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def locked - @plan = Plan.find(params[:id]) - authorize @plan - if !@plan.nil? && user_signed_in? && @plan.readable_by(current_user.id) then - respond_to do |format| - format.json { render json: @plan.locked(params[:section_id],current_user.id) } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def delete_recent_locks - @plan = Plan.find(params[:id]) + @plan = Plan.find(params[:id]) authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.delete_recent_locks(current_user.id) - format.html { render action: "edit" } - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + if user_signed_in? && @plan.readable_by(current_user.id) then + respond_to do |format| + format.json { render json: @plan.status } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end - def unlock_all_sections - @plan = Plan.find(params[:id]) + def section_answers + @plan = Plan.find(params[:id]) authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.unlock_all_sections(current_user.id) - format.html { render action: "edit" } - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + if user_signed_in? && @plan.readable_by(current_user.id) then + respond_to do |format| + format.json { render json: @plan.section_answers(params[:section_id]) } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end - def lock_section - @plan = Plan.find(params[:id]) + def locked + @plan = Plan.find(params[:id]) authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.lock_section(params[:section_id], current_user.id) - format.html { render action: "edit" } - else - format.html { render action: "edit" } - format.json { render json: @plan.errors, status: :unprocessable_entity } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + if !@plan.nil? && user_signed_in? && @plan.readable_by(current_user.id) then + respond_to do |format| + format.json { render json: @plan.locked(params[:section_id],current_user.id) } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end - def unlock_section - @plan = Plan.find(params[:id]) + def delete_recent_locks + @plan = Plan.find(params[:id]) authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.unlock_section(params[:section_id], current_user.id) - format.html { render action: "edit" } + if user_signed_in? && @plan.editable_by(current_user.id) then + respond_to do |format| + if @plan.delete_recent_locks(current_user.id) + format.html { render action: "edit" } + else + format.html { render action: "edit" } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + def unlock_all_sections + @plan = Plan.find(params[:id]) + authorize @plan + if user_signed_in? && @plan.editable_by(current_user.id) then + respond_to do |format| + if @plan.unlock_all_sections(current_user.id) + format.html { render action: "edit" } + else + format.html { render action: "edit" } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end - def answer - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.readable_by(current_user.id) then - respond_to do |format| - format.json { render json: @plan.answer(params[:q_id], false).to_json(:include => :options) } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + def lock_section + @plan = Plan.find(params[:id]) + authorize @plan + if user_signed_in? && @plan.editable_by(current_user.id) then + respond_to do |format| + if @plan.lock_section(params[:section_id], current_user.id) + format.html { render action: "edit" } + else + format.html { render action: "edit" } + format.json { render json: @plan.errors, status: :unprocessable_entity } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end - def warning - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.readable_by(current_user.id) then - respond_to do |format| - format.json { render json: @plan.warning(params[:option_id]) } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + def unlock_section + @plan = Plan.find(params[:id]) + authorize @plan + if user_signed_in? && @plan.editable_by(current_user.id) then + respond_to do |format| + if @plan.unlock_section(params[:section_id], current_user.id) + format.html { render action: "edit" } - def export - @plan = Plan.find(params[:id]) + else + format.html { render action: "edit" } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + def answer + @plan = Plan.find(params[:id]) + authorize @plan + if user_signed_in? && @plan.readable_by(current_user.id) then + respond_to do |format| + format.json { render json: @plan.answer(params[:q_id], false).to_json(:include => :options) } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + def export + @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 + #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::Template::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 + 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 + + + def fixup_hash(plan) + rollup(plan, "notes", "answer_id", "answers") + rollup(plan, "answers", "question_id", "questions") + rollup(plan, "questions", "section_id", "sections") + rollup(plan, "sections", "phase_id", "phases") + + plan["template"]["phases"] = plan.delete("phases") + + ghash = {} + plan["guidance_groups"].map{|g| ghash[g["id"]] = g} + plan["plan_guidance_groups"].each do |pgg| + pgg["guidance_group"] = ghash[ pgg["guidance_group_id"] ] + end + + plan["template"]["org"] = Org.find(plan["template"]["org_id"]).serializable_hash() + end + + + # find all object under src_plan_key + # merge them into the items under obj_plan_key using + # super_id = id + # so we have answers which each have a question_id + # rollup(plan, "answers", "quesiton_id", "questions") + # will put the answers into the right questions. + def rollup(plan, src_plan_key, super_id, obj_plan_key) + id_to_obj = Hash.new() + plan[src_plan_key].each do |o| + id = o[super_id] + if !id_to_obj.has_key?(id) + id_to_obj[id] = Array.new + end + id_to_obj[id] << o + end + + plan[obj_plan_key].each do |o| + id = o["id"] + if id_to_obj.has_key?(id) + o[src_plan_key] = id_to_obj[ id ] + end + end + plan.delete(src_plan_key) + end + end diff --git a/app/controllers/project_groups_controller.rb b/app/controllers/project_groups_controller.rb deleted file mode 100644 index 2d81d39..0000000 --- a/app/controllers/project_groups_controller.rb +++ /dev/null @@ -1,94 +0,0 @@ -class ProjectGroupsController < ApplicationController - after_action :verify_authorized - - def create - @project_group = ProjectGroup.new(params[:project_group]) - authorize @project_group - access_level = params[:project_group][:access_level].to_i - if access_level >= 3 then - @project_group.project_administrator = true - end - if access_level >= 2 then - @project_group.project_editor = true - end - if (user_signed_in?) && @project_group.project.administerable_by(current_user.id) then - respond_to do |format| - if params[:project_group][:email].present? && params[:project_group][:email].length > 0 then - message = I18n.t('helpers.project.user_added') - if @project_group.save - if @project_group.user.nil? then - if User.find_by_email(params[:project_group][:email]).nil? then - User.invite!(:email => params[:project_group][:email]) - message = I18n.t('helpers.project.invitation_success') - @project_group.user = User.find_by_email(params[:project_group][:email]) - @project_group.save - else - @project_group.user = User.find_by_email(params[:project_group][:email]) - @project_group.save - UserMailer.sharing_notification(@project_group).deliver - end - else - UserMailer.sharing_notification(@project_group).deliver - end - flash[:notice] = message - format.html { redirect_to :controller => 'projects', :action => 'share', :id => @project_group.project.slug } - else - format.html { render action: "new" } - end - else - flash[:notice] = I18n.t('helpers.project.enter_email') - format.html { redirect_to :controller => 'projects', :action => 'share', :id => @project_group.project.slug } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - - end - - def update - @project_group = ProjectGroup.find(params[:id]) - authorize @project_group - access_level = params[:project_group][:access_level].to_i - if access_level >= 3 then - @project_group.project_administrator = true - else - @project_group.project_administrator = false - end - if access_level >= 2 then - @project_group.project_editor = true - else - @project_group.project_editor = false - end - if (user_signed_in?) && @project_group.project.administerable_by(current_user.id) then - respond_to do |format| - if @project_group.update_attributes(params[:project_group]) - flash[:notice] = I18n.t('helpers.project.sharing_updated') - UserMailer.permissions_change_notification(@project_group).deliver - format.html { redirect_to :controller => 'projects', :action => 'share', :id => @project_group.project.slug } - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def destroy - @project_group = ProjectGroup.find(params[:id]) - authorize @project_group - if (user_signed_in?) && @project_group.project.administerable_by(current_user.id) then - user = @project_group.user - project = @project_group.project - @project_group.destroy - respond_to do |format| - flash[:notice] = I18n.t('helpers.project.access_removed') - UserMailer.project_access_removed_notification(user, project).deliver - format.html { redirect_to :controller => 'projects', :action => 'share', :id => @project_group.project.slug } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end -end \ No newline at end of file diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e5b9bed..5b98dd2 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,204 +1,200 @@ class ProjectsController < ApplicationController - before_filter :get_plan_list_columns, only: %i( index ) + before_filter :get_plan_list_columns, only: %i( index ) after_action :verify_authorized - # GET /projects - # GET /projects.json - def index + # GET /projects + # GET /projects.json + def index authorize Project ## TODO: Is this A magic String? the "Show_shib_link?" as we define it and users dont see cookies - if user_signed_in? then - if (current_user.shibboleth_id.nil? || current_user.shibboleth_id.length == 0) && !cookies[:show_shib_link].nil? && cookies[:show_shib_link] == "show_shib_link" then - flash.notice = "Would you like to #{view_context.link_to I18n.t('helpers.shibboleth_to_link_text'), user_omniauth_shibboleth_path}".html_safe - end + if user_signed_in? then + if (current_user.shibboleth_id.nil? || current_user.shibboleth_id.length == 0) && !cookies[:show_shib_link].nil? && cookies[:show_shib_link] == "show_shib_link" then + flash.notice = "Would you like to #{view_context.link_to I18n.t('helpers.shibboleth_to_link_text'), user_omniauth_shibboleth_path}".html_safe + end - @projects = current_user.projects.filter(params[:filter]) - @has_projects = current_user.projects.any? # unfiltered count + @projects = current_user.projects.filter(params[:filter]) + @has_projects = current_user.projects.any? # unfiltered count - respond_to do |format| - format.html # index.html.erb - end - else - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - end - end + respond_to do |format| + format.html # index.html.erb + end + else + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + end + end - # GET /projects/1 - # GET /projects/1.json - def show - @project = Project.find(params[:id]) + # GET /projects/1 + # GET /projects/1.json + def show + @project = Project.find(params[:id]) authorize @project - @show_form = false - if params[:show_form] == "yes" then - @show_form = true - end - if user_signed_in? && @project.readable_by(current_user.id) then - respond_to do |format| - format.html # show.html.erb - end - elsif user_signed_in? then - respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } - end - else - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - end - end + @show_form = false + if params[:show_form] == "yes" then + @show_form = true + end + if user_signed_in? && @project.readable_by(current_user.id) then + respond_to do |format| + format.html # show.html.erb + end + elsif user_signed_in? then + respond_to do |format| + format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + else + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + end + end - # GET /projects/new - # GET /projects/new.json - def new - if user_signed_in? then - @project = Project.new - authorize @project - @project.organisation = current_user.organisation - @funders = orgs_of_type(constant("organisation_types.funder"), true) - @templates = get_available_templates - @guidance_groups = get_available_guidance - @always_guidance = get_always_available_guidance - @institutions = orgs_of_type(constant("organisation_types.institution")) - - respond_to do |format| - format.html # new.html.erb - end - else - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - end - end + def new + if user_signed_in? then + @plan = Plan.new + authorize @plan + @funders = Org.funder.all - # GET /projects/1/edit - # Should this be removed? - def edit - @project = Project.find(params[:id]) - authorize @project - if !user_signed_in? then - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - elsif !@project.editable_by(current_user.id) then - respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } - end - end - end - - def share - @project = Project.find(params[:id]) - authorize @project - if !user_signed_in? then - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - elsif !@project.editable_by(current_user.id) then - respond_to do |format| - format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } - end - end - end - - def export - @project = Project.find(params[:id]) - authorize @project - if !user_signed_in? then - respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - else - respond_to do |format| - format.html { render action: "export" } - - end - end - end - - # POST /projects - # POST /projects.json - def create - if user_signed_in? then - @project = Project.new(params[:project]) - authorize @project - if @project.dmptemplate.nil? && params[:project][:funder_id] != "" then # this shouldn't be necessary - see setter for funder_id in project.rb - funder = Organisation.find(params[:project][:funder_id]) - if funder.dmptemplates.count == 1 then - @project.dmptemplate = funder.published_templates.first - end - elsif @project.dmptemplate.nil? || params[:default_tag] == 'true' then - if @project.organisation.nil? || params[:default_tag] == 'true' || @project.organisation.published_templates.first.nil? then - @project.dmptemplate = Dmptemplate.find_by_is_default(true) - else - @project.dmptemplate = @project.organisation.published_templates.first - end - end - @project.principal_investigator = current_user.name(false) - - @project.title = I18n.t('helpers.project.my_project_name')+' ('+@project.dmptemplate.title+')' - @project.assign_creator(current_user.id) - respond_to do |format| - if @project.save - format.html { redirect_to({:action => "show", :id => @project.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } - else - format.html { render action: "new" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - # PUT /projects/1 - # PUT /projects/1.json - def update - @project = Project.find(params[:id]) - authorize @project - if user_signed_in? && @project.editable_by(current_user.id) then - if @project.update_attributes(params[:project]) respond_to do |format| - format.html { redirect_to({:action => "show", :id => @project.slug, notice: I18n.t('helpers.project.success_update') }) } + format.html # new.html.erb end else respond_to do |format| - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + format.html { redirect_to edit_user_registration_path } + end + end + end - # DELETE /projects/1 - # DELETE /projects/1.json - def destroy - @project = Project.find(params[:id]) + + # GET /projects/1/edit + # Should this be removed? + def edit + @project = Project.find(params[:id]) authorize @project - if user_signed_in? && @project.editable_by(current_user.id) then - @project.destroy + if !user_signed_in? then + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + elsif !@project.editable_by(current_user.id) then + respond_to do |format| + format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + end + end - respond_to do |format| - format.html { redirect_to projects_url } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end + def share + @project = Project.find(params[:id]) + authorize @project + if !user_signed_in? then + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + elsif !@project.editable_by(current_user.id) then + respond_to do |format| + format.html { redirect_to projects_url, notice: I18n.t('helpers.settings.plans.errors.no_access_account') } + end + end + end + + def export + @project = Project.find(params[:id]) + authorize @project + if !user_signed_in? then + respond_to do |format| + format.html { redirect_to edit_user_registration_path } + end + else + respond_to do |format| + format.html { render action: "export" } + + end + end + end + + # POST /projects + def create + puts params + return + if user_signed_in? then + @plan = Plan.new(params[:plan]) + authorize @project + if @project.dmptemplate.nil? && params[:project][:funder_id] != "" then # this shouldn't be necessary - see setter for funder_id in project.rb + funder = Org.find(params[:project][:funder_id]) + if funder.dmptemplates.count == 1 then + @project.dmptemplate = funder.published_templates.first + end + elsif @project.dmptemplate.nil? || params[:default_tag] == 'true' then + if @project.organisation.nil? || params[:default_tag] == 'true' || @project.organisation.published_templates.first.nil? then + @project.dmptemplate = Dmptemplate.find_by_is_default(true) + else + @project.dmptemplate = @project.organisation.published_templates.first + end + end + @project.principal_investigator = current_user.name(false) + + @project.title = I18n.t('helpers.project.my_project_name')+' ('+@project.dmptemplate.title+')' + @project.assign_creator(current_user.id) + respond_to do |format| + if @project.save + format.html { redirect_to({:action => "show", :id => @project.slug, :show_form => "yes"}, {:notice => I18n.t('helpers.project.success')}) } + else + format.html { render action: "new" } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + # PUT /projects/1 + # PUT /projects/1.json + def update + @project = Project.find(params[:id]) + authorize @project + if user_signed_in? && @project.editable_by(current_user.id) then + if @project.update_attributes(params[:project]) + respond_to do |format| + format.html { redirect_to({:action => "show", :id => @project.slug, notice: I18n.t('helpers.project.success_update') }) } + end + else + respond_to do |format| + format.html { render action: "edit" } + end + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end + + # DELETE /projects/1 + # DELETE /projects/1.json + def destroy + @project = Project.find(params[:id]) + authorize @project + if user_signed_in? && @project.editable_by(current_user.id) then + @project.destroy + + respond_to do |format| + format.html { redirect_to projects_url } + end + else + render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) + end + end # 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 = Organisation.find(params[:funder]) + funder = Org.find(params[:funder]) else funder = nil end if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then - institution = Organisation.find(params[:institution]) + institution = Org.find(params[:institution]) else institution = nil end @@ -224,86 +220,96 @@ 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 = Organisation.find(params[:institution]) + 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")) + Organisation.orgs_with_parent_of_type(constant("organisation_types.institution")) + excluded_orgs = Org.funders + Org.institutions guidance_groups = {} ggs = GuidanceGroup.guidance_groups_excluding(excluded_orgs) - ggs.each do |gg| - guidance_groups[gg.id] = gg.name - end + 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 - 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 - end + respond_to do |format| + format.json { render json: guidance_groups.to_json } + end + 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] } - 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 + + 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 - Dmptemplate.where(published: true) + Template.find_by(published: true) end # ----------------------------------------------------------- @@ -315,9 +321,9 @@ # ----------------------------------------------------------- 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")) + - Organisation.orgs_with_parent_of_type(constant("organisation_types.institution")) + Org.orgs_with_parent_of_type(constant("organisation_types.institution")) GuidanceGroup.guidance_groups_excluding(excluded_orgs) end @@ -354,4 +360,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 49115c7..a82b679 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -2,25 +2,31 @@ class RegistrationsController < Devise::RegistrationsController def edit - @languages = Language.order("name") + @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 = session["devise.#{scheme.name.downcase}_data"] + 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? + 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, + UserIdentifier.create(identifier_scheme: oauth[:provider].upcase, + identifier: oauth[:uid], user: @user) end end @@ -34,35 +40,44 @@ else existing_user = User.find_by_email(sign_up_params[:email]) if !existing_user.nil? then - redirect_to after_sign_up_error_path_for(resource), alert: I18n.t('helpers.email_already_registered') + if (existing_user.password == "" || existing_user.password.nil?) && existing_user.confirmed_at.nil? then + @user = existing_user + do_update(false, true) + else + redirect_to after_sign_up_error_path_for(resource), alert: I18n.t('helpers.email_already_registered') + end else - build_resource(sign_up_params) - if resource.save - if resource.active_for_authentication? - set_flash_message :notice, :signed_up if is_navigational_format? - sign_up(resource_name, resource) - respond_with resource, :location => after_sign_up_path_for(resource) - else - set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format? - #expire_session_data_after_sign_in! <-- DEPRECATED BY DEVISE - respond_with resource, :location => after_inactive_sign_up_path_for(resource) - end - else - clean_up_passwords resource - redirect_to after_sign_up_error_path_for(resource), alert: I18n.t('helpers.error_registration_check') - end - end + build_resource(sign_up_params) + if resource.save + if resource.active_for_authentication? + set_flash_message :notice, :signed_up if is_navigational_format? + sign_up(resource_name, resource) + respond_with resource, location: after_sign_up_path_for(resource) + else + set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format? + #expire_session_data_after_sign_in! <-- DEPRECATED BY DEVISE + respond_with resource, location: after_inactive_sign_up_path_for(resource) + end + else + clean_up_passwords resource + redirect_to after_sign_up_error_path_for(resource), alert: I18n.t('helpers.error_registration_check') + end + end end end - def update - if user_signed_in? then - @user = User.find(current_user.id) - - do_update + def update + 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 @@ -72,8 +87,7 @@ # ie if password or email was changed # extend this as needed def needs_password?(user, params) - user.email != params[:user][:email] || - params[:user][:password].present? + user.email != params[:user][:email] || params[:user][:password].present? end def do_update(require_password = true, confirm = false) @@ -87,7 +101,7 @@ @user.update_without_password(params[:user]) end else - @user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation]) + @user.update_attributes(password: params[:user][:password], password_confirmation: params[:user][:password_confirmation]) successfully_updated = @user.update_without_password(params[:user]) end @@ -95,13 +109,13 @@ if params[:user][:language_id] if @user.language_id != params[:user][:language_id] params[:locale] = Language.find(params[:user][:language_id]).abbreviation - set_locale + set_locale end end - + #unlink shibboleth from user's details if params[:unlink_flag] == 'true' then - @user.update_attributes(:shibboleth_id => "") + @user.update_attributes(shibboleth_id: "") end if successfully_updated @@ -111,21 +125,18 @@ end set_flash_message :notice, :updated # Sign in the user bypassing validation in case his password changed - sign_in @user, :bypass => true - - #if params[:unlink_flag] == 'true' then - redirect_to({:controller => "registrations", :action => "edit"}, {:notice => I18n.t('helpers.project.details_update_success')}) - #else - # redirect_to({:controller => "projects", :action => "index"}, {:notice => I18n.t('helpers.project.details_update_success')}) - #end + 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 end def sign_up_params - params.require(:user).permit(:email, :password, :password_confirmation, :accept_terms, + params.require(:user).permit(:email, :password, :password_confirmation, :accept_terms, :organisation_id, :other_organisation) end diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb new file mode 100644 index 0000000..d4e4072 --- /dev/null +++ b/app/controllers/roles_controller.rb @@ -0,0 +1,61 @@ +class RolesController < ApplicationController + respond_to :html + after_action :verify_authorized + + def create + @role = Role.new(params[:role]) + authorize @role + @role.access_level = params[:role][:access_level].to_i + if params[:role][:email].present? + message = I18n.t('helpers.project.user_added') + if @role.save + if @role.user.nil? then + if User.find_by_email(params[:role][:email]).nil? then + User.invite!(email: params[:role][:email]) + message = I18n.t('helpers.project.invitation_success') + @role.user = User.find_by_email(params[:role][:email]) + @role.save + else + @role.user = User.find_by_email(params[:role][:email]) + @role.save + UserMailer.sharing_notification(@role).deliver + end + else + UserMailer.sharing_notification(@role).deliver + end + flash[:notice] = message + redirect_to controller: 'plans', action: 'share', id: @role.plan.slug + else + render action: "new" + end + else + flash[:notice] = I18n.t('helpers.project.enter_email') + redirect_to controller: 'plans', action: 'share', id: @role.plan.slug + end + end + + def update + @role = Role.find(params[:id]) + authorize @role + @role.access_level = params[:role][:access_level].to_i + if @role.update_attributes(params[:role]) + flash[:notice] = I18n.t('helpers.project.sharing_updated') + UserMailer.permissions_change_notification(@role).deliver + redirect_to controller: 'plans', action: 'share', id: @role.plan.slug + else + render action: "edit" + end + end + + def destroy + @role = Role.find(params[:id]) + authorize @role + user = @role.user + plan = @role.plan + @role.destroy + + flash[:notice] = I18n.t('helpers.project.access_removed') + UserMailer.project_access_removed_notification(user, plan).deliver + redirect_to controller: 'plans', action: 'share', id: @role.plan.slug + end +end \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 3719d84..89a5f44 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -15,8 +15,8 @@ # 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]) - + 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.rb b/app/controllers/settings.rb index 612db61..a0342b3 100644 --- a/app/controllers/settings.rb +++ b/app/controllers/settings.rb @@ -1,5 +1,4 @@ module Settings class SettingsController < ApplicationController - end end diff --git a/app/controllers/settings/plans_controller.rb b/app/controllers/settings/plans_controller.rb index 2c65aea..9708521 100644 --- a/app/controllers/settings/plans_controller.rb +++ b/app/controllers/settings/plans_controller.rb @@ -1,14 +1,17 @@ module Settings class PlansController < SettingsController + before_filter :get_plan_list_columns before_filter :get_settings + after_action :verify_authorized def show - authorize @plan + authorize [:settings, @plan] respond_to do |format| format.html format.partial + format.json{ render json: settings_json } end end 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/splash_logs_controller.rb b/app/controllers/splash_logs_controller.rb index c2824d5..4fce98d 100644 --- a/app/controllers/splash_logs_controller.rb +++ b/app/controllers/splash_logs_controller.rb @@ -1,20 +1,19 @@ class SplashLogsController < ApplicationController + respond_to :html + ## # POST /answers - # POST /answers.json def create @splash_log = SplashLog.new() @splash_log.destination = params[:destination] - respond_to do |format| - if @splash_log.save - cookies[:dmp_splash_seen] = { - value: 'splash_dialog_seen', - expires: 3.hours.from_now, - } - format.html { redirect_to params[:destination] } - else - format.html { redirect_to home_url } - end + if @splash_log.save + cookies[:dmp_splash_seen] = { + value: 'splash_dialog_seen', + expires: 3.hours.from_now, + } + redirect_to params[:destination] + else + redirect_to home_url end end end \ No newline at end of file diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 8408cfe..cded887 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -2,7 +2,7 @@ def about_us dcc_news_feed_url = "http://www.dcc.ac.uk/news/dmponline-0/feed" - @dcc_news_feed = Feedjira::Feed.fetch_and_parse dcc_news_feed_url + @dcc_news_feed = Feedjira::Feed.fetch_and_parse dcc_news_feed_url respond_to do |format| format.rss { redirect_to dcc_news_feed_url } format.html @@ -11,8 +11,63 @@ def contact_us end - + def roadmap end + # GET /plans/publicly_available + # ----------------------------------------------------------- + def public_plans + @plans = Plan.where(visibility: :publicly_visible).order(title: :asc) + end + + # GET /plans/[:plan_slug]/public_export + # ------------------------------------------------------------- + def public_export + @plan = Plan.find(params[:id]) + + # Force PDF response + request.format = :pdf + + # if the project is designated as public + if @plan.visibility == :publicly_visible + if !@plan.nil? + @exported_plan = ExportedPlan.new.tap do |ep| + ep.plan = @plan + ep.user = current_user ||= nil + #ep.format = request.format.try(:symbol) + ep.format = request.format.to_sym + plan_settings = @plan.settings(:export) + + 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 new file mode 100644 index 0000000..50f3c60 --- /dev/null +++ b/app/controllers/templates_controller.rb @@ -0,0 +1,421 @@ +# [+Project:+] DMPRoadmap +# [+Description:+] This controller is responsible for all the actions in the admin interface under templates (e.g. phases, versions, sections, questions, suggested answer) (index; show; create; edit; delete) +# [+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 + all_versions_own_templates = Template.where(org_id: current_user.org_id, customization_of: nil).order(version: :desc) + current_templates = {} + # take most recent version of each template + 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 + @other_published_version = {} + current_templates.keys.each do |dmptemplate_id| + @other_published_version[dmptemplate_id] = Template.where(org_id: current_user.org_id, dmptemplate_id: dmptemplate_id, published: true).present? + end + + # funders templates + funders_templates = {} + Org.includes(:templates).funder.each do |org| + org.templates.where(customization_of: nil, published: true).order(version: :desc).each do |temp| + if funders_templates[temp.dmptemplate_id].nil? + funders_templates[temp.dmptemplate_id] = temp + end + end + end + + @templates_funders = funders_templates.values + # are any funder templates customized + @templates_customizations = {} + Template.where(org_id: current_user.org_id, customization_of: funders_templates.keys).order(version: :desc).each do |temp| + if @templates_customizations[temp.customization_of].nil? + @templates_customizations[temp.customization_of] = {} + @templates_customizations[temp.customization_of][:temp] = temp + @templates_customizations[temp.customization_of][:published] = temp.published + else + @templates_customizations[temp.customization_of][:published] = @templates_customizations[temp.customization_of][:published] || temp.published + end + end + end + + + # GET /dmptemplates/1 + def admin_template + @template = Template.find(params[:id]) + # check to see if this is a funder template needing customized + if @template.org_id != current_user.org_id + # definitely need to deep_copy the given template + new_customization = Template.deep_copy(@template) + new_customization.org_id = current_user.org_id + new_customization.published = false + new_customization.customization_of = @template.dmptemplate_id + # need to mark all Phases, questions, sections as not-modifiable + new_customization.phases.includes(sections: :questions).each do |phase| + phase.modifiable = false + phase.save! + phase.sections.each do |section| + section.modifiable = false + section.save! + section.questions.each do |question| + question.modifiable = false + question.save! + end + end + end + customizations = Template.includes(phases: [sections: [questions: :suggested_answers ]]).where(org_id: current_user.org_id, customization_of: @template.dmptemplate_id).order(version: :desc) + if customizations.present? + # existing customization to port over + max_version = customizations.first + new_customization.dmptemplate_id = max_version.dmptemplate_id + new_customization.version = max_version.version + 1 + # here we rip the customizations out of the old template + # First, we find any customized phases or sections + max_version.phases.each do |phase| + # check if the phase was added as a customization + if phase.modifiable + # deep copy the phase and add it to the template + phase_copy = Phase.deep_copy(phase) + phase_copy.number = new_customization.phases.length + 1 + phase_copy.template_id = new_customization.id + phase_copy.save! + else + # iterate over the sections to see if any of them are customizations + phase.sections.each do |section| + if section.modifiable + # this is a custom section + section_copy = Section.deep_copy(section) + customization_phase = new_customization.phases.includes(:sections).where(number: phase.number).first + section_copy.phase_id = customization_phase.id + # custom sections get added to the end + section_copy.number = customization_phase.sections.length + 1 + # section from phase with corresponding number in the main_template + section_copy.save! + else + # not a customized section, iterate over questions + customization_phase = new_customization.phases.includes(sections: [questions: :suggested_answers]).where(number: phase.number).first + customization_section = customization_phase.sections.where(number: section.number).first + section.questions.each do |question| + # find corresponding question in new template + customization_question = customization_section.questions.where(number: question.number).first + # apply suggested_answers + question.suggested_answers.each do |suggested_answer| + suggested_answer_copy = SuggestedAnswer.deep_copy(suggested_answer) + suggested_answer_copy.org_id = current_user.org_id + suggested_answer_copy.question_id = customization_question.id + suggested_answer_copy.save! + end + # guidance attached to a question is also a form of customization + # It will soon become an annotation of the question, and be combined with + # suggested answers + customization_question.guidance = customization_question.guidance + question.guidance + customization_question.save! + end + end + end + end + end + else + # first time customization + new_customization.version = 0 + new_customization.dmptemplate_id = loop do + random = rand 2147483647 # max int field in psql + break random unless Template.exists?(dmptemplate_id: random) + end + end + new_customization.save! + @template = new_customization + end + # needed for some post-migration edge cases + # some customized templates which were edited + if @template.published + new_version = Template.deep_copy(@template) + new_version.version = @template.version + 1 + new_version.published = false + new_version.save! + @template = new_version + end + authorize @template + end + + + # PUT /dmptemplates/1 + def admin_update + @template = Template.find(params[:id]) + authorize @template + if @template.published? + # published templates cannot be edited + redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.read_only') and return + end + @template.description = params["template-desc"] + if @template.update_attributes(params[:template]) + if @template.published + # create a new template version if this template became published + new_version = Template.deep_copy(@template) + new_version.version = @template.version + 1 + new_version.published = false + new_version.save! + end + redirect_to admin_index_template_path(), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "edit" + end + end + + + # GET /dmptemplates/new + def admin_new + authorize Template + end + + + # POST /dmptemplates + # creates a new template with version 0 and new dmptemplate_id + def admin_create + @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 + @template = Template.find(params[:id]) + authorize @template + @template.destroy + redirect_to admin_index_template_path + 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 + + + + # 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 + redirect_to admin_template_template_path(@template), notice: I18n.t('org_admin.templates.destroyed_message') + end + +# SECTIONS + #create a section + def admin_createsection + @section = Section.new(params[:section]) + authorize @section.phase.template + @section.description = params["section-desc"] + @section.modifiable = true + 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.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 + + + #delete a section and questions + def admin_destroysection + @section = Section.find(params[:section_id]) + authorize @section.phase.template + @phase = @section.phase + @section.destroy + 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.phase.template + @question.guidance = params["new-question-guidance"] + @question.default_value = params["new-question-default-value"] + 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 + + #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 + 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_answer = SuggestedAnswer.new(params[:suggested_answer]) + 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.phase.template + @question = @suggested_answer.question + @section = @question.section + @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 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/token_permission_types_controller.rb b/app/controllers/token_permission_types_controller.rb index 3500374..345bf1f 100644 --- a/app/controllers/token_permission_types_controller.rb +++ b/app/controllers/token_permission_types_controller.rb @@ -1,10 +1,12 @@ class TokenPermissionTypesController < ApplicationController + respond_to :html + + ## + # GET - Lists all TokenPermissionTypes available to the user + # also lists their description def index authorize TokenPermissionType @user = current_user - @token_types = @user.organisation.token_permission_types - respond_to do |format| - format.html - end + @token_types = @user.org.token_permission_types end end \ No newline at end of file diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 9b65b77..593e146 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -7,7 +7,7 @@ handle_omniauth(scheme) end end - + ## # Processes callbacks from an omniauth provider and directs the user to # the appropriate page: diff --git a/app/controllers/users/omniauth_shibboleth_request_controller.rb b/app/controllers/users/omniauth_shibboleth_request_controller.rb index 7cb8368..3190c2f 100644 --- a/app/controllers/users/omniauth_shibboleth_request_controller.rb +++ b/app/controllers/users/omniauth_shibboleth_request_controller.rb @@ -1,9 +1,9 @@ class Users::OmniauthShibbolethRequestController < ApplicationController - before_filter :authenticate_user!, :only => :associate + before_filter :authenticate_user!, only: :associate def redirect - if !current_user.nil? && !current_user.organisation.nil? - idp = params[:idp] || current_user.organisation.wayfless_entity + if !current_user.nil? && !current_user.org.nil? + idp = params[:idp] || current_user.org.wayfless_entity else idp = params[:idp] end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 52f9558..6ca0cd7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,49 +1,53 @@ class UsersController < ApplicationController after_action :verify_authorized + respond_to :html + ## + # GET - List of all users for an organisation + # Displays number of roles[was project_group], name, email, and last sign in def admin_index authorize User - - @users = current_user.organisation.users.includes(:project_groups) - - respond_to do |format| - format.html # index.html.erb - end + @users = current_user.org.users.includes(:roles) end + ## + # GET - Displays the permissions available to the selected user + # Permissions which the user already has are pre-selected + # Selecting new permissions and saving calls the admin_update_permissions action def admin_grant_permissions - @user = User.includes(:roles).find(params[:id]) + @user = User.includes(:perms).find(params[:id]) authorize @user - user_roles = current_user.roles - @roles = user_roles & Role.where(name: [constant("user_role_types.change_org_details"),constant("user_role_types.use_api"), constant("user_role_types.modify_guidance"), constant("user_role_types.modify_templates"), constant("user_role_types.grant_permissions")]) + user_perms = current_user.perms + @perms = user_perms & Perm.where(name: [constant("user_role_types.change_org_details"),constant("user_role_types.use_api"), constant("user_role_types.modify_guidance"), constant("user_role_types.modify_templates"), constant("user_role_types.grant_permissions")]) end + ## + # POST - updates the permissions for a user + # redirects to the admin_index action def admin_update_permissions - @user = User.includes(:roles).find(params[:id]) + @user = User.includes(:perms).find(params[:id]) authorize @user - roles_ids = params[:role_ids].blank? ? [] : params[:role_ids].map(&:to_i) - roles = Role.where( id: roles_ids) - current_user.roles.each do |role| - if @user.roles.include? role - if ! roles.include? role - @user.roles.delete(role) - if role.name == constant("user_role_types.use_api") + perms_ids = params[:perm_ids].blank? ? [] : params[:perm_ids].map(&:to_i) + perms = Perm.where( id: perms_ids) + current_user.perms.each do |perm| + if @user.perms.include? perm + if ! perms.include? perm + @user.perms.delete(perm) + if perm.name == constant("user_role_types.use_api") @user.remove_token! end end else - if roles.include? role - @user.roles << role - if role.name == constant("user_role_types.use_api") + if perms.include? perm + @user.perms << perm + if perm.name == constant("user_role_types.use_api") @user.keep_or_generate_token! end end end end @user.save! - respond_to do |format| - format.html { redirect_to({controller: 'users', action: 'admin_index'}, {notice: I18n.t('helpers.success')})} - end + redirect_to({controller: 'users', action: 'admin_index'}, {notice: I18n.t('helpers.success')}) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 56f99a5..0d8de1a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,41 +1,32 @@ 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 + + # Determines whether or not the URL path passed matches with the full path (including params) of the last URL requested. + # see http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-fullpath for details + def isActivePage(path) + return request.fullpath() == path + end end diff --git a/app/helpers/plans_helper.rb b/app/helpers/plans_helper.rb new file mode 100644 index 0000000..8cdd5d9 --- /dev/null +++ b/app/helpers/plans_helper.rb @@ -0,0 +1,84 @@ +module PlansHelper + + # Build variable column headings for the project list + # -------------------------------------------------------- + def plan_list_column_heading(column) + if column.kind_of?(Array) + heading = (column.first.kind_of?(String) ? column.first : t("helpers.project.columns.unknown")) + + elsif column.kind_of?(String) + heading = column + + else + heading = t("helpers.project.columns.unknown") + end + + klass = (['name', 'description'].include?(heading) ? :dmp_th_big : :dmp_th_small) + + content_tag(:th, t("helpers.project.columns.#{heading}"), class: klass) + end + + # Populate a variable column for the project list + # -------------------------------------------------------- + def plan_list_column_body(column, plan) + + col = (column.kind_of?(Array) ? column[0] : column) + + klass, content = case col + when 'name' + [ "dmp_td_big", link_to(plan.title, plan_path(I18n.locale, plan), class: "dmp_table_link") ] + + when 'owner' + user = plan.owner + + text = if user.nil? + t("helpers.project.columns.unknown") + elsif user == current_user + t("helpers.me") + else + user.name + end + + [ "tmp_td_small", text ] + when 'shared' + shared_num = plan.users.count - 1 + text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") + [ "dmp_td_small", text ] + when 'visibility' + ["dmp_td_small", (plan.visibility.nil? ? I18n.t("helpers.project.visibilities.labels.organisationally_visible") : I18n.t("helpers.project.visibilities.labels.#{plan.visibility}"))] + when 'last_edited' + [ "dmp_td_small", l(plan.latest_update.to_date, formats: :short) ] + when 'description' + [ "dmp_td_medium", (plan.try(col) || t("helpers.settings.unknown")) ] + when 'non_link_name' + [ "dmp_td_big", plan.title ] + when 'template' + ["dmp_td_big", plan.template.title] + when 'organisation' + ["dmp_td_medium", (plan.owner.org.nil? ? t("helpers.settings.unknown") : plan.owner.org.name) ] + else + [ "dmp_td_small", (plan.try(col) || t("helpers.settings.unknown")) ] + end + + content_tag(:td, content, class: klass) + end + + # Shows whether the user has default, template-default or custom settings + # for the given plan. + # -------------------------------------------------------- + def plan_settings_indicator(plan) + plan_settings = plan.super_settings(:export) + template_settings = plan.template.try(:settings, :export) + + key = if plan_settings.try(:value?) + plan_settings.formatting == template_settings.formatting ? "template_formatting" : "custom_formatting" + elsif template_settings.try(:value?) + "template_formatting" + else + "default_formatting" + end + + content_tag(:small, t("helpers.settings.plans.#{key}")) + end + +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb deleted file mode 100644 index 4679053..0000000 --- a/app/helpers/projects_helper.rb +++ /dev/null @@ -1,76 +0,0 @@ -module ProjectsHelper - - # Build variable column headings for the project list - # -------------------------------------------------------- - def project_list_column_heading(column) - if column.kind_of?(Array) - heading = (column.first.kind_of?(String) ? column.first : t("helpers.project.columns.unknown")) - - elsif column.kind_of?(String) - heading = column - - else - heading = t("helpers.project.columns.unknown") - end - - klass = (['name', 'description'].include?(heading) ? :dmp_th_big : :dmp_th_small) - - content_tag(:th, t("helpers.project.columns.#{heading}"), class: klass) - end - - # Populate a variable column for the project list - # -------------------------------------------------------- - def project_list_column_body(column, project) - - col = (column.kind_of?(Array) ? column[0] : column) - - klass, content = case col - when 'name' - [ "dmp_td_big", link_to(project.title, project_path(project), class: "dmp_table_link") ] - - when 'owner' - user = project.owner - - text = if user.nil? - "Unknown" - elsif user == current_user - t("helpers.me") - else - user.name - end - - [ "tmp_td_small", text ] - when 'shared' - 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 'last_edited' - [ "dmp_td_small", l(project.latest_update.to_date, formats: :short) ] - when 'description' - [ "dmp_td_medium", (project.try(col) || "Unknown") ] - else - [ "dmp_td_small", (project.try(col) || "Unknown") ] - end - - content_tag(:td, content, class: klass) - end - - # Shows whether the user has default, template-default or custom settings - # for the given plan. - # -------------------------------------------------------- - def plan_settings_indicator(plan) - plan_settings = plan.super_settings(:export) - template_settings = plan.project.dmptemplate.try(:settings, :export) - - key = if plan_settings.try(:value?) - plan_settings.formatting == template_settings.formatting ? "template_formatting" : "custom_formatting" - elsif template_settings.try(:value?) - "template_formatting" - else - "default_formatting" - end - - content_tag(:small, t("helpers.settings.plans.#{key}")) - end - -end diff --git a/app/models/ability.rb b/app/models/ability.rb deleted file mode 100644 index e283051..0000000 --- a/app/models/ability.rb +++ /dev/null @@ -1,38 +0,0 @@ -class Ability - include GlobalHelpers - include CanCan::Ability - - def initialize(user) - # 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") - can :manage, :all - else - can :read, :all - end - - can :manage_settings, User do |viewed_user| - viewed_user.present? && user.id == viewed_user.id - end - # - # The first argument to `can` is the action you are giving the user - # permission to do. - # If you pass :manage it will apply to every action. Other common actions - # here are :read, :create, :update and :destroy. - # - # The second argument is the resource the user can perform the action on. - # If you pass :all it will apply to every resource. Otherwise pass a Ruby - # class of the resource. - # - # The third argument is an optional hash of conditions to further filter the - # objects. - # For example, here the user can only update published articles. - # - # can :update, Article, :published => true - # - # See the wiki for details: - # https://github.com/ryanb/cancan/wiki/Defining-Abilities - - end -end diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb deleted file mode 100644 index 511e649..0000000 --- a/app/models/admin_user.rb +++ /dev/null @@ -1,4 +0,0 @@ -class AdminUser < ActiveRecord::Base - devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable - attr_accessible :email, :password, :password_confirmation, :remember_me -end diff --git a/app/models/answer.rb b/app/models/answer.rb index cadb66d..35e0c2d 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -1,16 +1,39 @@ class Answer < ActiveRecord::Base - #associations between tables + ## + # Associations belongs_to :question belongs_to :user belongs_to :plan + has_many :notes, dependent: :destroy + has_and_belongs_to_many :question_options, join_table: "answers_question_options" -# accepts_nested_attributes_for :question -# accepts_nested_attributes_for :plan - - has_and_belongs_to_many :options, join_table: "answers_options" - - attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids , :as => [:default, :admin] - - + 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, :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/comment.rb b/app/models/comment.rb deleted file mode 100644 index b4af9f9..0000000 --- a/app/models/comment.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Comment < ActiveRecord::Base - - #associations between tables - belongs_to :question - - #fields - attr_accessible :question_id, :text, :user_id, :archived, :plan_id, :archived_by, :as => [:default, :admin] - - - - def to_s - "#{text}" - end - -end diff --git a/app/models/dmptemplate.rb b/app/models/dmptemplate.rb deleted file mode 100644 index 981b585..0000000 --- a/app/models/dmptemplate.rb +++ /dev/null @@ -1,163 +0,0 @@ -class Dmptemplate < ActiveRecord::Base - include GlobalHelpers - - attr_accessible :id, :organisation_id, :description, :published, :title, :user_id, :locale, - :is_default, :guidance_group_ids, :as => [:default, :admin] - - #associations between tables - has_many :phases - has_many :versions, through: :phases - has_many :sections, through: :versions - has_many :questions, through: :sections - has_many :projects - - #has_many :guidances needs to be removed and checked - - belongs_to :organisation - - has_and_belongs_to_many :guidance_groups, join_table: "dmptemplates_guidance_groups" - - accepts_nested_attributes_for :guidance_groups - accepts_nested_attributes_for :phases - accepts_nested_attributes_for :organisation - accepts_nested_attributes_for :projects - - - has_settings :export, class_name: 'Settings::Dmptemplate' do |s| - s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS - end - - ## - # Converts a DMPtemplate object into a string containing it's title - # - # @return [String] the title of the DMPtemplate - def to_s - "#{title}" - end - - ## - # takes a type or organisation and returns all published templates from - # organisations of that type - # - # @param ot [String] name of an organisation type e.g. founder - # @return [Array] list of published dmptemplates - def self.templates_org_type(ot) - # DISCUSS - This function other than the check for the template being published - # is a superclass for the below funders_templates - new_org_obejcts = OrganisationType.find_by( name: ot ).organisations - - org_templates = Array.new - new_org_obejcts.each do |neworg| - org_templates += neworg.dmptemplates.where("published = ?", true) - end - - return org_templates - end - - ## - # returns all templates from all organisations of the Organisation_Type funder - # - # @return [Array] all templates from funder organisations - def self.funders_templates - new_org_obejcts = OrganisationType.find_by(name: GlobalHelpers.constant("organisation_types.funder")).organisations - org_templates = Array.new - - new_org_obejcts.each do |neworg| - org_templates += neworg.dmptemplates - end - - return org_templates - end - - ## - # returns all institutional templates bellowing to the given organisation - # - # @param org_id [integer] the integer id for an organisation - # @return [Array] all templates from a user's organisation - def self.own_institutional_templates(org_id) - # DISCUSS - Why is this done by scanning organisation_id's from the templates - # yet all other calls are done by finding an organisation, and using the - # has_many relationship to find the dmptemplates? - # - A possible answer is that there may be deleted organisations which we are - # serching for templates for. - # - A standardised behavior on querries, wether through active reccord or the - # where, should maybe be thought of/decided upon - new_templates = self.where("organisation_id = ?", org_id) - return new_templates - end - - ## - # returns an array with all funders and of the given organisations's - # institutional templates - # - # @param org_id [integer] the integer id for an organisation - # @return [Array] all templates from the template's organisation - # or from a funder organisation - def self.funders_and_own_templates(org_id) - funders_templates = self.funders_templates - # DISCUSS - Here we internationalise the word funder. There is code in the - # api that just uses the english word funder. Why are we internationalising - # the database querry, and do I need to change things like this elsewhere? - - #verify if org type is not a funder - current_org = Organisation.find(org_id) - if current_org.organisation_type.name != GlobalHelpers.constant("organisation_types.funder") then - own_institutional_templates = self.own_institutional_templates(org_id) - else - own_institutional_templates = [] - end - - templates_list = Array.new - templates_list += own_institutional_templates - templates_list += funders_templates - templates_list = templates_list.sort_by { |f| f['title'].downcase } - - return templates_list - end - - ## - # Returns the string name of the organisation type of the organisation who - # owns this dmptemplate - # - # @return [string] the string name of an organisation type - def org_type - org_type = organisation.organisation_type.name - return org_type - end - - ## - # Verify if a template has customisation by given organisation - # - # @param org_id [integer] the integer id for an organisation - # @param temp [dmptemplate] a template object - # @return [Boolean] true if temp has customisation by the given organisation - def has_customisations?(org_id, temp) - # EXPLAIN - I dont Understand the data model here. If the template isnt - # owned by the organisation, how can it make changes to a section? - # Why cant the owner make customisations? - if temp.organisation_id != org_id then - temp.phases.each do |phase| - phase.versions.each do |version| - version.sections.each do |section| - return true if section.organisation_id == org_id - end - end - return false - end - else - return false - end - end - - ## - # verify if there are any publish version for the template - # - # @return [Boolean] true if there is a published version for the template - def has_published_versions? - phases.each do |phase| - return true if !phase.latest_published_version.nil? - end - return false - end - -end diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 797e0a8..4045298 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,59 +11,69 @@ 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 # given time can be lost) - has_settings :export, class_name: 'Settings::Dmptemplate' do |s| - s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS + has_settings :export, class_name: 'Settings::Template' do |s| + 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.template.title + name += " - #{self.plan.title}" if self.plan.template.phases.count > 1 name end def project_identifier - self.plan.project.identifier + self.plan.identifier end def grant_title - self.plan.project.grant_number + self.plan.grant_number end def principal_investigator - self.plan.project.principal_investigator + self.plan.principal_investigator end def project_data_contact - self.plan.project.data_contact + self.plan.data_contact end def project_description - self.plan.project.description + self.plan.description end def funder - org = self.plan.project.dmptemplate.try(:organisation) - org.name if org.present? && org.organisation_type.try(:name) == constant("organisation_types.funder") + org = self.plan.template.try(:org) + org.name if org.present? && org.funder? end def institution - plan.project.organisation.try(:name) + plan.owner.org.try(:name) end def orcid - scheme = IdentifierScheme.find_by(name: 'orcid') - orcid = self.user.user_identifiers.where(identifier_scheme: scheme).first + scheme = IdentifierScheme.find_by(name: 'orcid') + if self.owner.nil? + '' + else + orcid = self.owner.user_identifiers.where(identifier_scheme: scheme).first (orcid.nil? ? '' : orcid.identifier) + end end +# TODO: This looks like it will always return an empty array as questions is undefined # sections taken from fields settings def sections - sections = self.plan.sections + # TODO: How do we know which phase to use here!? + sections = self.template.phases.first.sections return [] if questions.empty? @@ -98,18 +109,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 7cf325c..0000000 --- a/app/models/file_upload.rb +++ /dev/null @@ -1,7 +0,0 @@ -class FileUpload < ActiveRecord::Base - #attr_accessible :file_type_id, :description, :location, :name, :published, :size, :title - - #associations between tables - belongs_to :file_type - -end diff --git a/app/models/guidance.rb b/app/models/guidance.rb index ac1e886..3b15e2a 100644 --- a/app/models/guidance.rb +++ b/app/models/guidance.rb @@ -9,22 +9,26 @@ class Guidance < ActiveRecord::Base include GlobalHelpers - #associations between tables - attr_accessible :text, :question_id, :published, :as => [:default, :admin] - attr_accessible :guidance_group_ids, :as => [:default, :admin] - attr_accessible :theme_ids, :as => [:default, :admin] - - belongs_to :question - - #belongs_to :dmptemplate - #belongs_to :theme - - has_and_belongs_to_many :guidance_groups, join_table: "guidance_in_group" + ## + # Associations + belongs_to :guidance_group +# 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" - accepts_nested_attributes_for :themes - accepts_nested_attributes_for :guidance_groups + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + + + validates :text, presence: true ## @@ -32,12 +36,12 @@ # # @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?(organisation_id) - guidance_groups.each do |guidance_group| - if guidance_group.organisation_id == organisation_id - return true - end - end + def in_group_belonging_to?(org_id) + unless guidance_group.nil? + if guidance_group.org.id == org_id + return true + end + end return false end @@ -46,10 +50,11 @@ # # @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 = [] - Organisation.find_by(id: org_id).guidance_groups.each do |group| - org_guidance += group.guidances + # TODO: re-write below querry when guidance_in_group removed from model + Org.find_by(id: org_id).guidance_groups.each do |group| + org_guidance += Guidance.where(guidance_group_id: group.id) end return org_guidance end @@ -84,28 +89,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.organisations.each do |organisation| + 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 - if guidance_group.organisation.id == organisation.id + # 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 == Organisation.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 @@ -119,22 +120,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 = (Organisation.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 d9102a4..71535c3 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -1,26 +1,29 @@ class GuidanceGroup < ActiveRecord::Base include GlobalHelpers - - #associations between tables - belongs_to :organisation - - has_and_belongs_to_many :guidances, join_table: "guidance_in_group" - - has_and_belongs_to_many :projects, join_table: "project_guidance" - has_and_belongs_to_many :dmptemplates, join_table: "dmptemplates_guidance_groups" - - accepts_nested_attributes_for :dmptemplates - - attr_accessible :organisation_id, :name, :optional_subset, :published, :as => [:default, :admin] - attr_accessible :dmptemplate_ids, :as => [:default, :admin] + ## + # Associations + 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" ## - # Converts a guidance group to a string containing the display name + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :org_id, :name, :optional_subset, :published, :org, :guidances, + :as => [:default, :admin] + + validates :name, :org, presence: true + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW # - # @return [String] the name of the organisation, with or without the name of the guidance group - def to_s - "#{display_name}" - end + # What do they do? do they do it efficiently, and do we need them? + + + + + ## # Converts the current guidance group to a string containing the display name. @@ -30,10 +33,10 @@ # # @return [String] the display name for the guidance group def display_name - if organisation.guidance_groups.count > 1 - return "#{organisation.name}: #{name}" + if org.guidance_groups.count > 1 + return "#{org.name}: #{name}" else - return organisation.name + return org.name end end @@ -42,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 @@ -66,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 - Organisation.where( name: GlobalHelpers.constant("organisation_types.managing_organisation")).find_each do |managing_group| - if guidance_group.organisation.id == managing_group.id + Org.where( name: GlobalHelpers.constant("organisation_types.managing_organisation")).find_each do |managing_group| + 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 @@ -95,21 +104,21 @@ def self.all_viewable(user) # first find all groups owned by the Managing Curation Center managing_org_groups = [] - Organisation.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/language.rb b/app/models/language.rb index 65477be..0bb5a35 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -1,5 +1,10 @@ class Language < ActiveRecord::Base + ## + # Associations has_many :users + has_many :orgs + ## + # Validations validates :abbreviation, presence: true, uniqueness: true end \ No newline at end of file diff --git a/app/models/note.rb b/app/models/note.rb new file mode 100644 index 0000000..74b3078 --- /dev/null +++ b/app/models/note.rb @@ -0,0 +1,14 @@ +class Note < ActiveRecord::Base + ## + # Associations + belongs_to :answer + belongs_to :user + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + 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/option.rb b/app/models/option.rb deleted file mode 100644 index 87dfc46..0000000 --- a/app/models/option.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Option < ActiveRecord::Base - - #associations between tables - belongs_to :question - - has_many :option_warnings, :dependent => :destroy - - has_and_belongs_to_many :answers, join_table: "answers_options" - - attr_accessible :text, :question_id, :is_default, :number, :as => [:default, :admin] - - def to_s - "#{text}" - end -end \ No newline at end of file diff --git a/app/models/option_warning.rb b/app/models/option_warning.rb deleted file mode 100644 index d67709f..0000000 --- a/app/models/option_warning.rb +++ /dev/null @@ -1,12 +0,0 @@ -class OptionWarning < ActiveRecord::Base - - #associations between tables - belongs_to :option - belongs_to :organisation - - attr_accessible :text, :option_id, :organisation_id, :as => [:default, :admin] - - def to_s - "#{text}" - end -end \ No newline at end of file diff --git a/app/models/org.rb b/app/models/org.rb new file mode 100644 index 0000000..15dcd92 --- /dev/null +++ b/app/models/org.rb @@ -0,0 +1,228 @@ +class Org < ActiveRecord::Base + include GlobalHelpers + include FlagShihTzu + extend Dragonfly::Model::Validations + + ## + # Associations + belongs_to :organisation_type # depricated, but cannot be removed until migration run + belongs_to :language + has_many :guidance_groups + has_many :templates + has_many :users + has_many :suggested_answers + + has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions", unique: true + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + 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, + :language, :org_type, :region, :token_permission_types + + ## + # Validators + validates :contact_email, email: true, allow_nil: true + validates :name, presence: true, uniqueness: true + # allow validations for logo upload + dragonfly_accessor :logo do + after_assign :resize_image + end + validates_property :height, of: :logo, in: (0..100) + validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp'] + validates_size_of :logo, maximum: 500.kilobytes + + ## + # Define Bit Field values + # Column org_type + has_flags 1 => :institution, + 2 => :funder, + 3 => :organisation, + 4 => :research_institute, + 5 => :project, + 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) } + scope :institutions, -> { where(org_type: 3) } + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + +# TODO: Should these be hardcoded? Also, an Org can currently be multiple org_types at one time. +# For example you can do: funder = true; project = true; school = true +# Calling type in the above scenario returns "Funder" which is a bit misleading +# Is FlagShihTzu's Bit flag the appropriate structure here or should we use an enum? +# Tests are setup currently to work with this issue. + ## + # returns the name of the type of the organisation as a string + # defaults to none if no org type present + # + # @return [String] + def type + if self.institution? + return "Institution" + elsif self.funder? + return "Funder" + elsif self.organisation? + return "Organisation" + elsif self.research_institute? + return "Research Institute" + elsif self.project? + return "Project" + elsif self.school? + return "School" + end + return "None" + end + + + ## + # returns the name of the organisation + # + # @return [String] + def to_s + name + end + + ## + # returns the abbreviation for the organisation if it exists, or the name if not + # + # @return [String] name or abbreviation of the organisation + def short_name + if abbreviation.nil? then + return name + else + return abbreviation + end + end + + ## + # finds all organisations who have a parent of the passed organisation type + # + # @param [String] the name of an organisation type + # @return [Array] +=begin + def self.orgs_with_parent_of_type(org_type) + parents = OrganisationType.find_by_name(org_type).organisations + children = Array.new + parents.each do |parent| + children += parent.children + end + return children + end + + ## + # returns a list of all guidance groups belonging to other organisations + # + # @return [Array] + def self.other_organisations + org_types = [GlobalHelpers.constant("organisation_types.funder")] + organisations_list = [] + org_types.each do |ot| + new_org_obejct = OrganisationType.find_by_name(ot) + + org_with_guidance = GuidanceGroup.joins(new_org_obejct.organisations) + + organisations_list = organisations_list + org_with_guidance + end + return organisations_list + end + + + ## + # returns a list of all guidance groups belonging to other organisations + # + # @return [Array] + def self.other_organisations + org_types = [GlobalHelpers.constant("organisation_types.funder")] + organisations_list = [] + org_types.each do |ot| + new_org_obejct = OrganisationType.find_by_name(ot) + + org_with_guidance = GuidanceGroup.joins(new_org_obejct.organisations) + + organisations_list = organisations_list + org_with_guidance + end + return organisations_list + end + + ## + # returns a list of all sections of a given version from this organisation and it's parents + # + # @param version_id [Integer] version number of the section + # @return [Array
    ] list of sections + def all_sections(version_id) + if parent.nil? + secs = sections.where("version_id = ?", version_id) + if secs.nil? then + secs = Array.new + end + return secs + else + return sections.where("version_id = ? ", version_id).all + parent.all_sections(version_id) + end + end + + ## + # returns the guidance groups of this organisation and all of it's children + # + # @return [Array] list of guidance groups + def all_guidance_groups + ggs = guidance_groups + children.each do |c| + ggs = ggs + c.all_guidance_groups + end + return ggs + end + + ## + # returns the highest parent organisation in the tree + # + # @return [organisation] the root organisation + def root + if parent.nil? + return self + else + return parent.root + end + end +=end + + ## + # returns all published templates belonging to the organisation + # + # @return [Array] published dmptemplates + def published_templates + return templates.where("published = ?", true) + end + + def check_api_credentials + if token_permission_types.count == 0 + users.each do |user| + user.api_token = "" + user.save! + end + end + end + + private + ## + # checks size of logo and resizes if necessary + # + def resize_image + unless logo.nil? + if logo.height != 100 + self.logo = logo.thumb('x100') # resize height and maintain aspect ratio + end + end + end +end diff --git a/app/models/org_token_permission.rb b/app/models/org_token_permission.rb deleted file mode 100644 index c00a248..0000000 --- a/app/models/org_token_permission.rb +++ /dev/null @@ -1,8 +0,0 @@ -class OrgTokenPermission < ActiveRecord::Base - attr_accessible :organisation_id, :token_permission_type_id, :organisation, :token_permission_type, :as => [:default, :admin] - - #associations between tables - belongs_to :organisation - belongs_to :token_permission_type - -end diff --git a/app/models/organisation.rb b/app/models/organisation.rb deleted file mode 100644 index 5aabbf0..0000000 --- a/app/models/organisation.rb +++ /dev/null @@ -1,194 +0,0 @@ -class Organisation < ActiveRecord::Base - include GlobalHelpers - - extend Dragonfly::Model::Validations - - #associations between tables - belongs_to :organisation_type - has_many :guidance_groups - has_many :dmptemplates - has_many :sections - has_many :users - has_many :option_warnings - has_many :suggested_answers - has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions" - - belongs_to :parent, :class_name => 'Organisation' - - has_one :language - - has_many :children, :class_name => 'Organisation', :foreign_key => 'parent_id' - - accepts_nested_attributes_for :dmptemplates - accepts_nested_attributes_for :token_permission_types - - attr_accessible :abbreviation, :banner_text, :logo, :remove_logo, :domain, - :logo_file_name, :name, :stylesheet_file_id, :target_url, - :organisation_type_id, :wayfless_entity, :parent_id, :sort_name, - :token_permission_type_ids, :language_id, :contact_email - - validates :contact_email, email: true, allow_nil: true - validates :name, presence: true, uniqueness: true - - # allow validations for logo upload - dragonfly_accessor :logo do - after_assign :resize_image - end - - validates_property :height, of: :logo, in: (0..100) - validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp'] - validates_size_of :logo, maximum: 500.kilobytes - - ## - # returns the name of the organisation - # - # @return [String] - def to_s - name - end - - ## - # returns the abbreviation for the organisation if it exists, or the name if not - # - # @return [String] name or abbreviation of the organisation - def short_name - if abbreviation.nil? then - return name - else - return abbreviation - end - end - - ## - # finds all organisations who have a parent of the passed organisation type - # - # @param [String] the name of an organisation type - # @return [Array] - def self.orgs_with_parent_of_type(org_type) - parents = OrganisationType.find_by_name(org_type).organisations - children = Array.new - parents.each do |parent| - children += parent.children - end - return children - end - - ## - # returns a list of all guidance groups belonging to other organisations - # - # @return [Array] - def self.other_organisations - org_types = [GlobalHelpers.constant("organisation_types.funder")] - organisations_list = [] - org_types.each do |ot| - new_org_obejct = OrganisationType.find_by_name(ot) - - org_with_guidance = GuidanceGroup.joins(new_org_obejct.organisations) - - organisations_list = organisations_list + org_with_guidance - end - return organisations_list - end - - - ## - # returns a list of all guidance groups belonging to other organisations - # - # @return [Array] - def self.other_organisations - org_types = [GlobalHelpers.constant("organisation_types.funder")] - organisations_list = [] - org_types.each do |ot| - new_org_obejct = OrganisationType.find_by_name(ot) - - org_with_guidance = GuidanceGroup.joins(new_org_obejct.organisations) - - organisations_list = organisations_list + org_with_guidance - end - return organisations_list - end - - ## - # returns a list of all sections of a given version from this organisation and it's parents - # - # @param version_id [Integer] version number of the section - # @return [Array
    ] list of sections - def all_sections(version_id) - if parent.nil? - secs = sections.where("version_id = ?", version_id) - if secs.nil? then - secs = Array.new - end - return secs - else - return sections.where("version_id = ? ", version_id).all + parent.all_sections(version_id) - end - end - - ## - # returns the guidance groups of this organisation and all of it's children - # - # @return [Array] list of guidance groups - def all_guidance_groups - ggs = guidance_groups - children.each do |c| - ggs = ggs + c.all_guidance_groups - end - return ggs - end - - ## - # returns the highest parent organisation in the tree - # - # @return [organisation] the root organisation - def root - if parent.nil? - return self - else - return parent.root - end - end - - ## - # takes in the id of, and returns an OptionWarning - # - # @param option_id [number] the id of the desired warning - # @return [OptionWarning] the specified warning - def warning(option_id) - warning = option_warnings.find_by_option_id(option_id) - if warning.nil? && !parent.nil? then - return parent.warning(option_id) - else - return warning - end - end - - ## - # returns all published templates belonging to the organisation - # - # @return [Array] published dmptemplates - def published_templates - return dmptemplates.where("published = ?", true) - end - - def check_api_credentials - if token_permission_types.count == 0 - users.each do |user| - user.api_token = "" - user.save! - end - end - end - - private - ## - # checks size of logo and resizes if necessary - # - def resize_image - unless logo.nil? - if logo.height != 100 - self.logo = logo.thumb('x100') # resize height and maintain aspect ratio - end - end - end -end diff --git a/app/models/organisation_type.rb b/app/models/organisation_type.rb deleted file mode 100644 index 20df31d..0000000 --- a/app/models/organisation_type.rb +++ /dev/null @@ -1,7 +0,0 @@ -class OrganisationType < ActiveRecord::Base - attr_accessible :description, :organisations, :name, :as => [:default, :admin] - - has_many :organisations - - validates :name, presence: true, uniqueness: true -end diff --git a/app/models/perm.rb b/app/models/perm.rb new file mode 100644 index 0000000..114c0f0 --- /dev/null +++ b/app/models/perm.rb @@ -0,0 +1,12 @@ +class Perm < ActiveRecord::Base + ## + # Associations + has_and_belongs_to_many :users, :join_table => :users_perms + + ## + # 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 155a86f..88429fd 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -4,76 +4,104 @@ # [+Created:+] 03/09/2014 # [+Copyright:+] Digital Curation Centre and University of California Curation Center class Phase < ActiveRecord::Base +# extend FriendlyId - extend FriendlyId + ## + # Associations + belongs_to :template + has_many :sections, dependent: :destroy + has_many :questions, :through => :sections, dependent: :destroy - #associations between tables - belongs_to :dmptemplate + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :description, :number, :title, :template_id, + :template, :sections, :modifiable, :as => [:default, :admin] - has_many :versions, :dependent => :destroy - has_many :sections, :through => :versions, :dependent => :destroy - has_many :questions, :through => :sections, :dependent => :destroy + ## + # sluggable title + #friendly_id :title, use: [:slugged, :history, :finders] - #Link the child's data - accepts_nested_attributes_for :versions, :allow_destroy => true -# accepts_nested_attributes_for :dmptemplate - attr_accessible :description, :number, :title, :dmptemplate_id, :as => [:default, :admin] + validates :title, :number, :template, presence: true - friendly_id :title, use: [:slugged, :history, :finders] + + + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + + ## # 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 +=begin + 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 + + ## + # deep copy the given phase and all it's associations + # + # @params [Phase] phase to be deep copied + # @return [Phase] the saved, copied phase + def self.deep_copy(phase) + phase_copy = phase.dup + phase_copy.save! + phase.sections.each do |section| + section_copy = Section.deep_copy(section) + section_copy.phase_id = phase_copy.id + section_copy.save! + end + return phase_copy + end end diff --git a/app/models/plan.rb b/app/models/plan.rb index f25998c..a32b171 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -1,66 +1,83 @@ class Plan < ActiveRecord::Base + ## + # Associations + belongs_to :template + has_many :phases, through: :template + has_many :sections, through: :phases + has_many :questions, through: :sections + has_many :themes, through: :questions + has_many :answers, dependent: :destroy + has_many :notes, through: :answers + has_many :roles, dependent: :destroy + has_many :users, through: :roles + has_many :plan_guidance_groups, dependent: :destroy + has_many :guidance_groups, through: :plan_guidance_groups - attr_accessible :locked, :project_id, :version_id, :version, :plan_sections, :as => [:default, :admin] + accepts_nested_attributes_for :template + has_many :exported_plans - 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 + has_many :roles +# COMMENTED OUT THE DIRECT CONNECTION HERE TO Users to prevent assignment of users without an access_level specified (currently defaults to creator) +# has_many :users, through: :roles - #associations between tables - belongs_to :project - belongs_to :version - has_many :answers - has_many :plan_sections - -# accepts_nested_attributes_for :project - accepts_nested_attributes_for :answers -# accepts_nested_attributes_for :version - - has_settings :export, class_name: 'Settings::Dmptemplate' do |s| - s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS - end - - alias_method :super_settings, :settings ## - # 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. + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + 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, :org, :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] + + #TODO: work out why this messes up plan creation : + # briley: Removed reliance on :users, its really on :roles (shouldn't have a plan without at least a creator right?) It should be ok like this though now +# validates :template, :title, 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 + + ## + # 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 + + + ## + # 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 # # @return [Dmptemplate] the template associated with this plan def dmptemplate - self.project.try(:dmptemplate) || Dmptemplate.new + #self.project.try(:dmptemplate) || Dmptemplate.new + self.template end - ## - # 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 @@ -78,69 +95,91 @@ answer.question_id = qid answer.text = question.default_value default_options = Array.new - question.options.each do |option| + question.question_options.each do |option| if option.is_default default_options << option end end - answer.options = default_options + answer.question_options = default_options end return answer end +# TODO: This just retrieves all of the guidance associated with the themes within the template +# so why are we transferring it here to the plan? ## # 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 project.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 + # and get the guidance groups they belong to + ggroups = [] + self.template.phases.each do |phase| + phase.sections.each do |section| + section.questions.each do |question| + question.themes.each do |theme| + theme.guidances.each do |guidance| + ggroups << guidance.guidance_group + end + end + end + end + end + + self.guidance_groups = ggroups.uniq + end + + + ## # returns the guidances associated with the project's organisation, for a specified question # # @param question [Question] the question to find guidance for - # @return [Array] the list of guidances which pretain to the specified question - def guidance_for_question(question) - guidances = {} - # If project org isn't nil, get guidance by theme from any "non-subset" groups belonging to project org - unless project.organisation.nil? then - project.organisation.guidance_groups.each do |group| - if !group.optional_subset && (group.dmptemplates.pluck(:id).include?(project.dmptemplate_id) || group.dmptemplates.count == 0) then - group.guidances.each do |guidance| - guidance.themes.where("id IN (?)", question.theme_ids).each do |theme| - guidances = self.add_guidance_to_array(guidances, group, theme, guidance) - end - end - end - end - end - # Get guidance by theme from any guidance groups selected on creation - project.guidance_groups.each do |group| - if group.dmptemplates.pluck(:id).include?(project.dmptemplate_id) || group.dmptemplates.count == 0 then - group.guidances.each do |guidance| - guidance.themes.where("id IN (?)", question.theme_ids).each do |theme| - guidances = self.add_guidance_to_array(guidances, group, theme, guidance) - end - end - end - end - # Get guidance by question where guidance group was selected on creation or if group is organisation default - question.guidances.each do |guidance| - guidance.guidance_groups.each do |group| - if (group.organisation == project.organisation && !group.optional_subset) || project.guidance_groups.include?(group) then - guidances = self.add_guidance_to_array(guidances, group, nil, guidance) - end + # @return array of hashes with orgname, themes and the guidance itself + def guidance_for_question(question) + guidances = [] + + # add in the guidance for the template org + unless self.template.org.nil? then + self.template.org.guidance_groups.each do |group| + group.guidances.each do |guidance| + common_themes = guidance.themes.all & question.themes.all + if common_themes.length > 0 + guidances << { orgname: self.template.org.name, theme: common_themes.join(','), guidance: guidance } + end + end end - end + end + + # add in the guidance for the user's org + unless self.owner.nil? + unless self.owner.org.nil? then + self.owner.org.guidance_groups.each do |group| + group.guidances.each do |guidance| + common_themes = guidance.themes.all & question.themes.all + if common_themes.length > 0 + guidances << { orgname: self.template.org.name, theme: common_themes.join(','), guidance: guidance } + end + end + end + end + end - return guidances - end + # Get guidance by theme from any guidance groups currently selected + self.plan_guidance_groups.where(selected: true).each do |pgg| + group = pgg.guidance_group + group.guidances.each do |guidance| + common_themes = guidance.themes.all & question.themes.all + if common_themes.length > 0 + guidances << { orgname: self.template.org.name, theme: common_themes.join(','), guidance: guidance } + end + end + end + + return guidances + end ## # adds the given guidance to a hash indexed by a passed guidance group and theme @@ -150,73 +189,58 @@ # @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 - - ## - # finds the specified warning for the plan's project's organisation - # - # @param option_id [Integer] the id to find the OptionWarning associated - # @return [OptionWarning] the desired OptionWarning - def warning(option_id) - if project.organisation.nil? - return nil - else - return project.organisation.warning(option_id) - end - end + end ## # determines if the plan is editable by the specified user - # NOTE: This should be renamed to editable_by? # # @param user_id [Integer] the id for a user # @return [Boolean] true if user can edit the plan - def editable_by(user_id) - return project.editable_by(user_id) + def editable_by?(user_id) + role = roles.where(user_id: user_id).first + return role.present? && role.editor? end ## # determines if the plan is readable by the specified user - # NOTE: This shoudl be renamed to readable_by? + # 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) - if project.nil? - return false - else - return project.readable_by(user_id) - end + def readable_by?(user_id) + role = roles.where(user_id: user_id).first + return role.present? end ## # determines if the plan is administerable by the specified user - # NOTE: This should be renamed to administerable_by? # # @param user_id [Integer] the id for the user # @return [Boolean] true if the user can administer the plan - def administerable_by(user_id) - return project.readable_by(user_id) + def administerable_by?(user_id) + role = roles.where(user_id: user_id).first + return role.present? && role.administrator? end @@ -236,7 +260,7 @@ "space_used" => 0 # percentage of available space in pdf used } - space_used = height_of_text(self.project.title, 2, 2) + space_used = height_of_text(self.title, 2, 2) sections.each do |s| space_used += height_of_text(s.title, 1, 1) @@ -259,124 +283,128 @@ "answer_id" => answer.id, "answer_created_at" => answer.created_at.to_i, "answer_text" => answer.text, - "answer_option_ids" => answer.option_ids, + "answer_option_ids" => answer.question_options.pluck(:id), "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 - +# TODO: Guessing this isn't in use since it still refers to Project and Version +=begin ## # defines and returns the details for the plan # details consists of a hash of: project_title, phase_title, and for each section, # 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 +=end +# TODO: commenting this old lock stuff out since PlanSection is gone and we wanted to get rid of it +=begin ## # determines wether or not a specified section of a plan is locked to a specified user and returns a status hash # # @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 @@ -385,23 +413,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 @@ -409,65 +437,614 @@ # @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 +=end +# TODO: Commenting out because this method appears below as well so this one is overwritten +=begin ## # 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 +=end +# TODO: Guessing this isn't in use since it still refers to Project and Version +=begin ## # returns an array of hashes. Each hash contains the question's id, the answer_id, # the answer_text, the answer_timestamp, and the answer_options # # @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 +=end -private + + ## + # assigns the passed user_id to the creater_role for the project + # gives the user rights to read, edit, administrate, and defines them as creator + # + # @param user_id [Integer] the user to be given priveleges' id + def assign_creator(user_id) + add_user(user_id, true, true, true) + end + + + +# TODO: commenting these out because they are overriden by private methods below, so this +# is unreachable +=begin + ## + # 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.template.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 +=end + +# TODO: What are these used for? Should just be using self.org and self.org.funder? +=begin + ## + # sets a new funder for the project + # defaults to the first dmptemplate if the current template is nill and the funder has more than one dmptemplate + # + # @param new_funder_id [Integer] the id for a new funder + # @return [Organisation] the new funder + def funder_id=(new_funder_id) + if new_funder_id != "" then + new_funder = Org.find(new_funder_id); + if new_funder.templates.count >= 1 && self.template.nil? then + self.template = new_funder.templates.first + end + end + end + + ## + # returns the funder id for the plan + # + # @return [Integer, nil] the id for the funder + def funder_id + if self.template.nil? then + return nil + end + return self.template.org + end +=end + + ## + # returns the funder organisation for the project or nil if none is specified + # + # @return [Organisation, nil] the funder for project, or nil if none exists + def funder + template = self.template + if template.nil? then + return nil + end + + if template.customization_of + return template.customization_of.org + else + return template.org + end + end + +=begin + ## + # returns the name of the funder for the project + # + # @return [String] the name fo the funder for the project + def funder_name + if self.funder.nil? + return read_attribute(:funder_name) + else + return self.funder.name + end + end + + ## + # defines a new funder_name for the project. + # + # @param new_funder_name [String] the string name of the new funder + # @return [Integer, nil] the org_id of the new funder + def funder_name=(new_funder_name) + write_attribute(:funder_name, new_funder_name) + org_table = Org.arel_table + existing_org = Org.where(org_table[:name].matches(new_funder_name)) + if existing_org.nil? + existing_org = Org.where(org_table[:abbreviation].matches(new_funder_name)) + end + unless existing_org.empty? + self.funder_id=existing_org.id + end + end + + ## + # sets a new institution_id if there is no current organisation + # + # @param new_institution_id [Integer] the id for the new institution + # @return [Integer, Bool] false if an organisation exists, or the id of the set org if a new organisation is set + def institution_id=(new_institution_id) + if organisation.nil? then + self.organisation_id = new_institution_id + end + end + + ## + # returns the organisation which is root over the owning organisation + # + # @return [Integer, nil] the organisation_id or nil + def institution_id +# if organisation.nil? +# return nil +# else +# return organisation.root.id +# end + return template.org.id + end + + ## + # defines a new organisation_id for the project + # but is confusingly labled unit_id + # + # @param new_unit_id [Integer] + # @return [Integer, Boolean] the new organisation ID or false if no unit_id was passed + def unit_id=(new_unit_id) + unless new_unit_id.nil? ||new_unit_id == "" + self.organisation_id = new_unit_id + end + end + + ## + # returns the organisation_id or nil + # again seems redundant + # + # @return [nil, Integer] nil if no organisation, or the id if there is an organisation specified + def unit_id + if organisation.nil? || organisation.parent_id.nil? + return nil + else + return organisation_id + end + end +=end + + ## + # assigns the passed user_id as an editor for the project + # gives the user rights to read and edit + # + # @param user_id [Integer] the user to be given priveleges' id + def assign_editor(user_id) + add_user(user_id, true) + end + + ## + # assigns the passed user_id as a reader for the project + # gives the user rights to read + # + # @param user_id [Integer] the user to be given priveleges' id + def assign_reader(user_id) + add_user(user_id) + end + + ## + # assigns the passed user_id as an administrator for the project + # gives the user rights to read, adit, and administrate the project + # + # @param user_id [Integer] the user to be given priveleges' id + def assign_administrator(user_id) + add_user(user_id, true, true) + end + +# TODO: ProjectGroup doesn't exist anymore so commenting these out +=begin + ## + # returns the projects which the user can atleast read + # + # @param user_id [Integer] the user to lookup projects for + # @return [Array] list of all projects the user can atleast read + def self.projects_for_user(user_id) + projects = Array.new + groups = ProjectGroup.where("user_id = ?", user_id) + unless groups.nil? then + groups.each do |group| + unless group.project.nil? then + projects << group.project + end + end + end + return projects + end + + ## + # whether or not the specified user_id created this project + # should be renamed to created_by? + # + # @param user_id [Integer] the user to check the priveleges of + # @return [Boolean] true if the user created the project + def created_by(user_id) + user = project_groups.find_by_user_id(user_id) + if (! user.nil?) && user.project_creator then + return true + else + return false + end + end +=end + + ## + # the datetime for the latest update of this plan + # + # @return [DateTime] the time of latest update + def latest_update + latest_update = updated_at + phases.each do |phase| + if phase.updated_at > latest_update then + latest_update = phase.updated_at + end + end + return latest_update + end + + # Getters to match 'My plans' columns + + ## + # the title of the project + # + # @return [String] the title of the project + def name + self.title + end + + ## + # the owner of the project + # + # @return [User] the creater of the project + def owner + self.roles.each do |role| + if role.creator? + return role.user + end + end + return nil + end + + ## + # the time the project was last updated, formatted as a date + # + # @return [Date] last update as a date + def last_edited + self.latest_update.to_date + end + +# TODO: These next 2 reference defunct models so commenting out +=begin + ## + # whether or not the plan is shared with anybody + # + # @return [Boolean] true if the project has been shared + def shared? + self.project_groups.count > 1 + end + + alias_method :shared, :shared? + + ## + # the organisation who owns the project + # + # @return [Dmptemplate,Organisation,String] the template, it's owner, or it's owner's abreviation + def template_owner + self.dmptemplate.try(:organisation).try(:abbreviation) + end +=end + + + + ## + # + # The following method is to help optimise data access. + # Even using includes or joins the data access gets performed lazily + # and the caching appears to be forgotten at times over view/partial boundaries + # To get round it we can pull everything out into a hash and use that + # which guarantees no further DB accesses. + # + # The serializable_hash method only pulls in one level but this includes + # attributes which are "through" other attributes. So we do a basic + # conversion to hash and then a "fixup" which knits the pieces together into + # the structure which we really want. + # + def to_hash + plan_data = self.serializable_hash( + include: [ :template, :phases, :sections, + :answers, :notes, :roles, :users, :questions, + :plan_guidance_groups, :guidance_groups] + ) + + question_hash = {} + + plan_data["questions"].each do |q| + question_hash[q["id"]] = q + end + + question_ids = question_hash.keys + + suggested_answers = SuggestedAnswer.where(question_id: question_ids).where.not(text: '') + suggested_answers.each do |sa| + question_hash[sa.question_id]["suggested_answer"] = sa.serializable_hash + end + + qf_hash = {} + QuestionFormat.all.each do |qf| + qf_hash[qf.id] = qf.serializable_hash + end + question_hash.values.each do |q| + q["question_format"] = qf_hash[q["question_format_id"]] + end + + gg_ids = plan_data["plan_guidance_groups"].select{|pgg| pgg["selected"]}.map{|pgg| pgg["guidance_group_id"]} + gg_hash = {} + + theme_guidance = {} + + ggs = GuidanceGroup.find(gg_ids).each do |gg| + gg_hash[gg.id] = gg.serializable_hash + end + + guidances = Guidance.joins(:themes).select('guidances.guidance_group_id, guidances.text, themes.title').where(guidance_group: gg_ids).to_a + guidances.each do |g| + title = g.title + if !theme_guidance.has_key?(title) + theme_guidance[title] = Array.new + end + theme_guidance[title] << { + "text" => g.text, + "org" => gg_hash[g.guidance_group_id]["name"] + } + end + + plan_data["questions"].each do |q| + qg = {} + if q.has_key?("themes") + q["themes"].each do |t| + title = t["title"] + qg[title] = theme_guidance[title] if theme_guidance.has_key?(title) + end + q["theme_guidance"] = qg + end + end + + fixup_hash(plan_data) + + return plan_data + end + + + + private + + # reconnect the various parts of the hash so that: + # plan = { + # template: + # phases: + # sections: + # questions: + # answers + # } + # + # becomes a nested structure like so + # + # plan = { template: { + # phases: [ { + # sections: [ { + # questions: [ { + # answers: [...] + # + def fixup_hash(plan) + # sort out guidance first so we can add it to the questions + # before rolling up + ghash = {} + plan["guidance_groups"].map{|g| ghash[g["id"]] = g} + plan["plan_guidance_groups"].each do |pgg| + pgg["guidance_group"] = ghash[ pgg["guidance_group_id"] ] + end + + rollup(plan, "notes", "answer_id", "answers") + rollup(plan, "answers", "question_id", "questions") + rollup(plan, "questions", "section_id", "sections", true) + rollup(plan, "sections", "phase_id", "phases", true) + + plan["template"]["phases"] = plan.delete("phases") + plan["template"]["phases"].sort! { |x,y| x["number"].to_i <=> y["number"].to_i } + + plan["template"]["org"] = Org.find(plan["template"]["org_id"]).serializable_hash() + + # when editing phases we want the number of questions answered + # so calculate that now + plan["template"]["phases"].each do |phase| + phase["sections"].each do |section| + nanswers = 0 + section["questions"].each do |question| + if question.has_key?("answers") && question["answers"].first["text"].present? + nanswers += 1 + end + end + section["nanswers"] = nanswers + end + end + + end + + + # find all object under src_plan_key + # merge them into the items under obj_plan_key using + # super_id = id + # so we have answers which each have a question_id + # rollup(plan, "answers", "quesiton_id", "questions") + # will put the answers into the right questions. + # sort determines whether the items being rolled up should be sorted by number field + def rollup(plan, src_plan_key, super_id, obj_plan_key, sort = false) + id_to_obj = Hash.new() + plan[src_plan_key].each do |o| + id = o[super_id] + if !id_to_obj.has_key?(id) + id_to_obj[id] = Array.new + end + id_to_obj[id] << o + end + + plan[obj_plan_key].each do |o| + id = o["id"] + if id_to_obj.has_key?(id) + if sort + id_to_obj[ id ].sort! { |x,y| x["number"].to_i <=> y["number"].to_i } + end + o[src_plan_key] = id_to_obj[ id ] + end + end + plan.delete(src_plan_key) + end + + ## + # adds a user to the project + # if no flags are specified, the user is given read privleges + # + # @param user_id [Integer] the user to be given privleges + # @param is_editor [Boolean] whether or not the user can edit the project + # @param is_administrator [Boolean] whether or not the user can administrate the project + # @param is_creator [Boolean] wheter or not the user created the project + # @return [Array] + # + # TODO: change this to specifying uniqueness of user/plan association and handle + # that way + # + def add_user(user_id, is_editor = false, is_administrator = false, is_creator = false) + Role.where(plan_id: self.id, user_id: user_id).each do |r| + r.destroy + end + + role = Role.new + role.user_id = user_id + role.plan_id = id + + role.creator= is_creator + role.editor= is_editor + role.administrator= is_administrator + role.save + + # This is necessary because we're creating the associated record but not assigning it + # to roles. Auto-saving like this may be confusing when coding upstream in a controller, + # view or api. Should probably change this to: + # self.roles << role + # and then let the save be called manually via: + # plan.save! + #self.reload + end + + ## + # creates a plan for each phase in the dmptemplate associated with this project + # unless the phase is unpublished, it creates a new plan, and a new version of the plan and adds them to the project's plans + # + # @return [Array] + def create_plans + dmptemplate.phases.each do |phase| + latest_published_version = phase.latest_published_version + unless latest_published_version.nil? + new_plan = Plan.new + new_plan.version = latest_published_version + plans << new_plan + end + end + end + + ## # Based on the height of the text gathered so far and the available vertical diff --git a/app/models/plan_guidance_group.rb b/app/models/plan_guidance_group.rb new file mode 100644 index 0000000..7b76499 --- /dev/null +++ b/app/models/plan_guidance_group.rb @@ -0,0 +1,11 @@ +# Used to link plans to guidance groups +# the links are created at plan creation stage +# and link to all possible GGs +# then the selected field keeps track of which ones the user has turned on /off +# +class PlanGuidanceGroup < ActiveRecord::Base + belongs_to :plan + belongs_to :guidance_group + + attr_accessible :selected +end diff --git a/app/models/plan_section.rb b/app/models/plan_section.rb deleted file mode 100644 index 6a92a74..0000000 --- a/app/models/plan_section.rb +++ /dev/null @@ -1,9 +0,0 @@ -class PlanSection < ActiveRecord::Base - attr_accessible :plan_id, :release_time, :section_id, :user_id, :as => [:default, :admin] - - #associations between tables - belongs_to :section - belongs_to :plan - belongs_to :user - -end diff --git a/app/models/project.rb b/app/models/project.rb deleted file mode 100644 index f205429..0000000 --- a/app/models/project.rb +++ /dev/null @@ -1,359 +0,0 @@ -class Project < ActiveRecord::Base - include GlobalHelpers - - extend FriendlyId - - attr_accessible :dmptemplate_id, :title, :organisation_id, :unit_id, :guidance_group_ids, - :project_group_ids, :funder_id, :institution_id, :grant_number, :identifier, - :description, :principal_investigator, :principal_investigator_identifier, - :data_contact, :funder_name, :as => [:default, :admin] - - #associations between tables - belongs_to :dmptemplate - belongs_to :organisation - has_many :plans - has_many :project_groups, :dependent => :destroy - has_and_belongs_to_many :guidance_groups, join_table: "project_guidance" - - friendly_id :title, use: [:slugged, :history, :finders] - - ## - # returns the title of the project - # - # @return [String] the project's title - def to_s - "#{title}" - end - - after_create :create_plans - - ## - # sets a new funder for the project - # defaults to the first dmptemplate if the current template is nill and the funder has more than one dmptemplate - # - # @param new_funder_id [Integer] the id for a new funder - # @return [Organisation] the new funder - def funder_id=(new_funder_id) - if new_funder_id != "" then - new_funder = Organisation.find(new_funder_id); - if new_funder.dmptemplates.count >= 1 && self.dmptemplate.nil? then - self.dmptemplate = new_funder.dmptemplates.first - end - end - end - - ## - # returns the funder id for the project - # - # @return [Integer, nil] the id for the funder - def funder_id - if self.dmptemplate.nil? then - return nil - end - template_org = self.dmptemplate.organisation - if template_org.organisation_type.name == constant("organisation_types.funder").downcase - return template_org.id - else - return nil - end - end - - ## - # returns the funder organisation for the project or nil if none is specified - # - # @return [Organisation, nil] the funder for project, or nil if none exists - def funder - if self.dmptemplate.nil? then - return nil - end - template_org = self.dmptemplate.organisation - if template_org.organisation_type.name == constant("organisation_types.funder").downcase - return template_org - else - return nil - end - end - - ## - # returns the name of the funder for the project - # - # @return [String] the name fo the funder for the project - def funder_name - if self.funder.nil? - return read_attribute(:funder_name) - else - return self.funder.name - end - end - - ## - # defines a new funder_name for the project. - # - # @param new_funder_name [String] the string name of the new funder - # @return [Integer, nil] the org_id of the new funder - def funder_name=(new_funder_name) - write_attribute(:funder_name, new_funder_name) - org_table = Organisation.arel_table - existing_org = Organisation.where(org_table[:name].matches(new_funder_name)) - if existing_org.nil? - existing_org = Organisation.where(org_table[:abbreviation].matches(new_funder_name)) - end - unless existing_org.empty? - self.funder_id=existing_org.id - end - end - - ## - # sets a new institution_id if there is no current organisation - # - # @param new_institution_id [Integer] the id for the new institution - # @return [Integer, Bool] false if an organisation exists, or the id of the set org if a new organisation is set - def institution_id=(new_institution_id) - if organisation.nil? then - self.organisation_id = new_institution_id - end - end - - ## - # returns the organisation which is root over the owning organisation - # - # @return [Integer, nil] the organisation_id or nil - def institution_id - if organisation.nil? - return nil - else - return organisation.root.id - end - end - - ## - # defines a new organisation_id for the project - # but is confusingly labled unit_id - # - # @param new_unit_id [Integer] - # @return [Integer, Boolean] the new organisation ID or false if no unit_id was passed - def unit_id=(new_unit_id) - unless new_unit_id.nil? ||new_unit_id == "" - self.organisation_id = new_unit_id - end - end - - ## - # returns the organisation_id or nil - # again seems redundant - # - # @return [nil, Integer] nil if no organisation, or the id if there is an organisation specified - def unit_id - if organisation.nil? || organisation.parent_id.nil? - return nil - else - return organisation_id - end - end - - ## - # assigns the passed user_id to the creater_role for the project - # gives the user rights to read, edit, administrate, and defines them as creator - # - # @param user_id [Integer] the user to be given priveleges' id - def assign_creator(user_id) - add_user(user_id, true, true, true) - end - - ## - # assigns the passed user_id as an editor for the project - # gives the user rights to read and edit - # - # @param user_id [Integer] the user to be given priveleges' id - def assign_editor(user_id) - add_user(user_id, true) - end - - ## - # assigns the passed user_id as a reader for the project - # gives the user rights to read - # - # @param user_id [Integer] the user to be given priveleges' id - def assign_reader(user_id) - add_user(user_id) - end - - ## - # assigns the passed user_id as an administrator for the project - # gives the user rights to read, adit, and administrate the project - # - # @param user_id [Integer] the user to be given priveleges' id - def assign_administrator(user_id) - add_user(user_id, true, true) - end - - ## - # whether or not the current plan is administrable by the user - # - # @param user_id [Integer] the user to check if has privleges - # @return [Boolean] true if user can administer project, false otherwise - def administerable_by(user_id) - user = project_groups.find_by_user_id(user_id) - if (! user.nil?) && user.project_administrator then - return true - else - return false - end - end - - ## - # whether or not the current plan is editable by the user - # - # @param user_id [Integer] the user to check if has privleges - # @return [Boolean] true if user can edit project, false otherwise - def editable_by(user_id) - user = project_groups.find_by_user_id(user_id) - if (! user.nil?) && user.project_editor then - return true - else - return false - end - end - - ## - # whether or not the current plan is readable by the user - # should be renamed to readable_by? - # - # @param user_id [Integer] the user to check if has privleges - # @return [Boolean] true if user can read project, false otherwise - def readable_by(user_id) - user = project_groups.find_by_user_id(user_id) - if (! user.nil?) then - return true - else - return false - end - end - - ## - # returns the projects which the user can atleast read - # - # @param user_id [Integer] the user to lookup projects for - # @return [Array] list of all projects the user can atleast read - def self.projects_for_user(user_id) - projects = Array.new - groups = ProjectGroup.where("user_id = ?", user_id) - unless groups.nil? then - groups.each do |group| - unless group.project.nil? then - projects << group.project - end - end - end - return projects - end - - ## - # whether or not the specified user_id created this project - # should be renamed to created_by? - # - # @param user_id [Integer] the user to check the priveleges of - # @return [Boolean] true if the user created the project - def created_by(user_id) - user = project_groups.find_by_user_id(user_id) - if (! user.nil?) && user.project_creator then - return true - else - return false - end - end - - ## - # the datetime for the latest update of this project, or any plan it owns - # - # @return [DateTime] the time of latest update - def latest_update - latest_update = updated_at - plans.each do |plan| - if plan.latest_update > latest_update then - latest_update = plan.latest_update - end - end - return latest_update - end - - # Getters to match 'My plans' columns - - ## - # the title of the project - # - # @return [String] the title of the project - def name - self.title - end - - ## - # the owner of the project - # - # @return [User] the creater of the project - def owner - self.project_groups.find_by_project_creator(true).try(:user) - end - - ## - # the time the project was last updated, formatted as a date - # - # @return [Date] last update as a date - def last_edited - self.latest_update.to_date - end - - ## - # whether or not the plan is shared with anybody - # - # @return [Boolean] true if the project has been shared - def shared? - self.project_groups.count > 1 - end - - alias_method :shared, :shared? - - ## - # the organisation who owns the project - # - # @return [Dmptemplate,Organisation,String] the template, it's owner, or it's owner's abreviation - def template_owner - self.dmptemplate.try(:organisation).try(:abbreviation) - end - - private - - ## - # adds a user to the project - # if no flags are specified, the user is given read privleges - # - # @param user_id [Integer] the user to be given privleges - # @param is_editor [Boolean] whether or not the user can edit the project - # @param is_administrator [Boolean] whether or not the user can administrate the project - # @param is_creator [Boolean] wheter or not the user created the project - # @return [Array] - def add_user(user_id, is_editor = false, is_administrator = false, is_creator = false) - group = ProjectGroup.new - group.user_id = user_id - group.project_creator = is_creator - group.project_editor = is_editor - group.project_administrator = is_administrator - project_groups << group - end - - ## - # creates a plan for each phase in the dmptemplate associated with this project - # unless the phase is unpublished, it creates a new plan, and a new version of the plan and adds them to the project's plans - # - # @return [Array] - def create_plans - dmptemplate.phases.each do |phase| - latest_published_version = phase.latest_published_version - unless latest_published_version.nil? - new_plan = Plan.new - new_plan.version = latest_published_version - plans << new_plan - end - end - end -end diff --git a/app/models/project_group.rb b/app/models/project_group.rb deleted file mode 100644 index 05a4c1e..0000000 --- a/app/models/project_group.rb +++ /dev/null @@ -1,66 +0,0 @@ -class ProjectGroup < ActiveRecord::Base - - #associations between tables - belongs_to :project - belongs_to :user - - attr_accessible :project_creator, :project_editor, :project_administrator, :project_id, :user_id, :email, :access_level, :as => [:default, :admin] - - ## - # returns the user's email unless it is nil - # - # @return [Boolean, String] false if no email exists, the email otherwise - def email - unless user.nil? - return user.email - end - end - - ## - # define a new user for the project group by email - # - # @param new_email [String] the email of the new user for the project group - # @return [User] the new user - def email=(new_email) - unless User.find_by(email: email).nil? then - user = User.find_by(email: email) - end - end - - ## - # return the access level for the current project group - # 3 if the user is an administrator - # 2 if the user is an editor - # 1 if the user can only read - # - # @return [Integer] - def access_level - if project_administrator then - return 3 - elsif project_editor then - return 2 - else - return 1 - end - end - - ## - # define a new access level for the current project group - # if >=3, the user is a project administrator - # if >=2, the user is an editor - # - # @param new_access_level [Integer] the access level to give the user - def access_level=(new_access_level) - new_access_level = new_access_level.to_i - if new_access_level >= 3 then - project_administrator = true - else - project_administrator = false - end - if new_access_level >= 2 then - project_editor = true - else - project_editor = false - end - end -end diff --git a/app/models/project_partner.rb b/app/models/project_partner.rb deleted file mode 100644 index 3c82e18..0000000 --- a/app/models/project_partner.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ProjectPartner < ActiveRecord::Base - attr_accessible :leader_org, :organisation_id, :project_id, :as => [:default, :admin] -end diff --git a/app/models/question.rb b/app/models/question.rb index aed95fb..61eddd1 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -1,26 +1,40 @@ class Question < ActiveRecord::Base - #associations between tables + ## + # Associations has_many :answers, :dependent => :destroy - has_many :options, :dependent => :destroy + has_many :question_options, :dependent => :destroy has_many :suggested_answers, :dependent => :destroy - has_many :guidances - has_many :comments - - has_and_belongs_to_many :themes, join_table: "questions_themes" - - + has_and_belongs_to_many :themes, join_table: "questions_themes" belongs_to :section belongs_to :question_format + ## + # Nested Attributes + # TODO: evaluate if we need this accepts_nested_attributes_for :answers, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true -# accepts_nested_attributes_for :section -# accepts_nested_attributes_for :question_format - accepts_nested_attributes_for :options, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true + accepts_nested_attributes_for :question_options, :reject_if => lambda {|a| a[:text].blank? }, :allow_destroy => true accepts_nested_attributes_for :suggested_answers, :allow_destroy => true accepts_nested_attributes_for :themes - attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, :parent_id, :suggested_answer, :text, :section_id,:question_format_id,:options_attributes, :suggested_answers_attributes, :option_comment_display, :theme_ids, :as => [:default, :admin] + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :default_value, :dependency_id, :dependency_text, :guidance,:number, + :suggested_answer, :text, :section_id, :question_format_id, + :question_options_attributes, :suggested_answers_attributes, + :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 + # + # What do they do? do they do it efficiently, and do we need them? + + ## # returns the text from the question @@ -30,80 +44,51 @@ "#{text}" end - def select_text - cleantext = text.gsub(/<[^<]+>/, '') - if cleantext.length > 120 - cleantext = cleantext.slice(0,120) + ## + # deep copy the given question and all it's associations + # + # @params [Question] question to be deep copied + # @return [Question] the saved, copied question + def self.deep_copy(question) + question_copy = question.dup + question_copy.save! + question.question_options.each do |question_option| + question_option_copy = QuestionOption.deep_copy(question_option) + question_option_copy.question_id = question_copy.id + question_option_copy.save! end - cleantext + question.suggested_answers.each do |suggested_answer| + suggested_answer_copy = SuggestedAnswer.deep_copy(suggested_answer) + suggested_answer_copy.question_id = question_copy.id + suggested_answer_copy.save! + end + question.themes.each do |theme| + question_copy.themes << theme + end + return question_copy end - 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 - ## - # 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 + 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.includes(guidances: :themes).where(org_id: org.id).each do |group| + group.guidances.each do |g| + g.themes.each do |theme| + if theme_ids.include? theme.id + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{theme.title}"] = g end + 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 @@ -113,7 +98,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 b8ede7c..7f1a900 100644 --- a/app/models/question_format.rb +++ b/app/models/question_format.rb @@ -1,8 +1,22 @@ class QuestionFormat < ActiveRecord::Base - attr_accessible :title, :description, :as => [:default, :admin] - #associations between tables + ## + # 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, :option_based, :questions, :as => [:default, :admin] + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + ## # gives the title of the question_format # diff --git a/app/models/question_option.rb b/app/models/question_option.rb new file mode 100644 index 0000000..11552b0 --- /dev/null +++ b/app/models/question_option.rb @@ -0,0 +1,25 @@ +class QuestionOption < ActiveRecord::Base + ## + # Associations + belongs_to :question + has_and_belongs_to_many :answers, join_table: :answers_question_options + + ## + # 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, :question, + :as => [:default, :admin] + + validates :text, :question, :number, presence: true + + ## + # deep copy the given question_option and all it's associations + # + # @params [QuestionOption] question_option to be deep copied + # @return [QuestionOption] the saved, copied question_option + def self.deep_copy(question_option) + question_option_copy = question_option.dup + question_option_copy.save! + return question_option_copy + end +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/role.rb b/app/models/role.rb index dbe0a80..cf49c87 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,8 +1,64 @@ class Role < ActiveRecord::Base - has_and_belongs_to_many :users, :join_table => :users_roles + include FlagShihTzu + + before_validation :check_access_level + + ## + # Associations + belongs_to :user + belongs_to :plan + + ## + # Define Bit Field Values + # Column access + has_flags 1 => :creator, + 2 => :administrator, + 3 => :editor, + column: 'access' + + validates :user, :plan, :access, presence: true + validates :access, numericality: {greater_than: 0} + + ## + # return the access level for the current project group + # 3 if the user is an administrator + # 2 if the user is an editor + # 1 if the user can only read + # + # @return [Integer] + def access_level + if self.administrator? then + return 3 + elsif self.editor? then + return 2 + else + return 1 + end + end + + ## + # define a new access level for the current project group + # if >=3, the user is a project administrator + # if >=2, the user is an editor + # + # @param new_access_level [Integer] the access level to give the user + def access_level=(new_access_level) + new_access_level = new_access_level.to_i + if new_access_level >= 3 then + self.administrator = true + else + self.administrator = false + end + if new_access_level >= 2 then + self.editor = true + else + self.editor = false + end + self.creator = true unless self.administrator? || self.editor? + end - belongs_to :resource, :polymorphic => true - - attr_accessible :name, :role_in_plans, :resource_id, :resource_type, :as => [:default, :admin] - + # Ensures that the access attribute is set (will default to creator - see logic in access_level=) + def check_access_level + self.access_level = self.access_level + end end diff --git a/app/models/section.rb b/app/models/section.rb index fd1dcb7..87e98b6 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -1,16 +1,20 @@ class Section < ActiveRecord::Base - #associations between tables - belongs_to :version + ## + # Associations + 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 :phase_id, :description, :number, :title, :published, + :questions_attributes, :organisation, :phase, :modifiable, + :as => [:default, :admin] + + validates :phase, :title, :number, presence: true ## # return the title of the section @@ -20,8 +24,20 @@ "#{title}" end - amoeba do - include_association :questions + ## + # deep copy of the given section and all it's associations + # + # @params [Section] section to be deep copied + # @return [Section] the saved, copied section + def self.deep_copy(section) + section_copy = section.dup + section_copy.save! + section.questions.each do |question| + question_copy = Question.deep_copy(question) + question_copy.section_id = section_copy.id + question_copy.save! + end + return section_copy end end diff --git a/app/models/settings/dmptemplate.rb b/app/models/settings/dmptemplate.rb deleted file mode 100644 index 880dc4a..0000000 --- a/app/models/settings/dmptemplate.rb +++ /dev/null @@ -1,93 +0,0 @@ -module Settings - class Dmptemplate < RailsSettings::SettingObject - - #attr_accessible :var, :target, :target_id, :target_type - - VALID_FONT_FACES = [ - 'Arial, Helvetica, Sans-Serif', - '"Times New Roman", Times, Serif' - ] - - VALID_FONT_SIZE_RANGE = (8..14) - VALID_MARGIN_RANGE = (5..25) - - VALID_ADMIN_FIELDS = ['project_name', 'project_identifier', 'grant_title', 'principal_investigator', - 'project_data_contact', 'project_description', 'funder', 'institution', 'orcid'] - - DEFAULT_SETTINGS = { - formatting: { - margin: { # in millimeters - top: 20, - bottom: 20, - left: 20, - right: 20 - }, - font_face: VALID_FONT_FACES.first, - font_size: 12 # pt - }, - max_pages: 3, - fields: { - admin: VALID_ADMIN_FIELDS, - questions: :all - }, - title: "" - } - - validate do - formatting = value['formatting'] - max_pages = value['max_pages'] - fields = value['fields'] - - if formatting.present? - errs = [] - default_formatting = DEFAULT_SETTINGS[:formatting] - - unless (default_formatting.keys - formatting.keys).empty? - errs << :missing_key - else - unless formatting[:margin].is_a?(Hash) - errs << :invalid_margin - else - errs << :negative_margin if formatting[:margin].any? {|k,v| v.to_i < 0 } - errs << :unknown_margin unless (formatting[:margin].keys - default_formatting[:margin].keys).empty? - errs << :invalid_margin unless formatting[:margin].all? {|k,v| VALID_MARGIN_RANGE.member?(v) } - end - - errs << :invalid_font_size unless VALID_FONT_SIZE_RANGE.member?(formatting[:font_size]) - errs << :invalid_font_face unless VALID_FONT_FACES.member?(formatting[:font_face]) - errs << :unknown_key unless (formatting.keys - default_formatting.keys).empty? - end - - errs.map do |key| - errors.add(:formatting, I18n.t("helpers.settings.plans.errors.#{key}")) - end - - end - - if max_pages.present? && (!max_pages.is_a?(Integer) || max_pages <= 0) - errors.add(:max_pages, I18n.t('helpers.settings.plans.errors.invalid_max_pages')) - end - end - - before_validation do - self.formatting[:font_size] = self.formatting[:font_size].to_i if self.formatting[:font_size].present? - unless self.formatting[:margin].nil? or (not self.formatting[:margin].is_a?(Hash)) - self.formatting[:margin].each do |key, val| - self.formatting[:margin][key] = val.to_i - end - end - - self.fields.each do |key, val| - if val.is_a?(Hash) - val = key == :questions ? val.keys.map {|k| k.to_s.to_i } : val.keys - end - - self.fields[key] = val - end - - # Save empty arrays if we don't have any fields for them - self.fields[:admin] ||= [] - self.fields[:questions] ||= [] - end - end -end diff --git a/app/models/settings/plan_list.rb b/app/models/settings/plan_list.rb index 17e93a9..26f6ed5 100644 --- a/app/models/settings/plan_list.rb +++ b/app/models/settings/plan_list.rb @@ -5,12 +5,12 @@ # 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 cols = value["columns"] - + if cols.present? # columns can be empty, in which case they revert to defaults errors.add(:columns, I18n.t("helpers.settings.projects.errors.no_name")) unless cols.member?("name") errors.add(:columns, I18n.t("helpers.settings.projects.errors.duplicate")) unless cols.keys.uniq == cols.keys diff --git a/app/models/settings/template.rb b/app/models/settings/template.rb new file mode 100644 index 0000000..2956eac --- /dev/null +++ b/app/models/settings/template.rb @@ -0,0 +1,93 @@ +module Settings + class Template < RailsSettings::SettingObject + + #attr_accessible :var, :target, :target_id, :target_type + + VALID_FONT_FACES = [ + 'Arial, Helvetica, Sans-Serif', + '"Times New Roman", Times, Serif' + ] + + VALID_FONT_SIZE_RANGE = (8..14) + VALID_MARGIN_RANGE = (5..25) + + VALID_ADMIN_FIELDS = ['project_name', 'project_identifier', 'grant_title', 'principal_investigator', + 'project_data_contact', 'project_description', 'funder', 'institution', 'orcid'] + + DEFAULT_SETTINGS = { + formatting: { + margin: { # in millimeters + top: 20, + bottom: 20, + left: 20, + right: 20 + }, + font_face: VALID_FONT_FACES.first, + font_size: 12 # pt + }, + max_pages: 3, + fields: { + admin: VALID_ADMIN_FIELDS, + questions: :all + }, + title: "" + } + + validate do + formatting = value['formatting'] + max_pages = value['max_pages'] + fields = value['fields'] + + if formatting.present? + errs = [] + default_formatting = DEFAULT_SETTINGS[:formatting] + + unless (default_formatting.keys - formatting.keys).empty? + errs << :missing_key + else + unless formatting[:margin].is_a?(Hash) + errs << :invalid_margin + else + errs << :negative_margin if formatting[:margin].any? {|k,v| v.to_i < 0 } + errs << :unknown_margin unless (formatting[:margin].keys - default_formatting[:margin].keys).empty? + errs << :invalid_margin unless formatting[:margin].all? {|k,v| VALID_MARGIN_RANGE.member?(v) } + end + + errs << :invalid_font_size unless VALID_FONT_SIZE_RANGE.member?(formatting[:font_size]) + errs << :invalid_font_face unless VALID_FONT_FACES.member?(formatting[:font_face]) + errs << :unknown_key unless (formatting.keys - default_formatting.keys).empty? + end + + errs.map do |key| + errors.add(:formatting, I18n.t("helpers.settings.plans.errors.#{key}")) + end + + end + + if max_pages.present? && (!max_pages.is_a?(Integer) || max_pages <= 0) + errors.add(:max_pages, I18n.t('helpers.settings.plans.errors.invalid_max_pages')) + end + end + + before_validation do + self.formatting[:font_size] = self.formatting[:font_size].to_i if self.formatting[:font_size].present? + unless self.formatting[:margin].nil? or (not self.formatting[:margin].is_a?(Hash)) + self.formatting[:margin].each do |key, val| + self.formatting[:margin][key] = val.to_i + end + end + + self.fields.each do |key, val| + if val.is_a?(Hash) + val = key == :questions ? val.keys.map {|k| k.to_s.to_i } : val.keys + end + + self.fields[key] = val + end + + # Save empty arrays if we don't have any fields for them + self.fields[:admin] ||= [] + self.fields[:questions] ||= [] + end + end +end diff --git a/app/models/suggested_answer.rb b/app/models/suggested_answer.rb index 3bbefa8..91ce3aa 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -1,11 +1,24 @@ class SuggestedAnswer < ActiveRecord::Base - belongs_to :organisation + ## + # Associations + belongs_to :org belongs_to :question -# accepts_nested_attributes_for :question + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :org_id, :question_id, :text, :is_example, + :org, :question, :as => [:default, :admin] - attr_accessible :organisation_id, :question_id, :text, :is_example, :as => [:default, :admin] + + validates :question, :org, presence: true + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + ## # returns the text from the suggested_answer @@ -15,4 +28,15 @@ "#{text}" end + + ## + # deep copy the given question_option and all it's associations + # + # @params [QuestionOption] question_option to be deep copied + # @return [QuestionOption] the saved, copied question_option + def self.deep_copy(suggested_answer) + suggested_answer_copy = suggested_answer.dup + suggested_answer_copy.save! + return suggested_answer_copy + end end \ No newline at end of file diff --git a/app/models/template.rb b/app/models/template.rb new file mode 100644 index 0000000..9c59637 --- /dev/null +++ b/app/models/template.rb @@ -0,0 +1,181 @@ +class Template < ActiveRecord::Base + include GlobalHelpers + + ## + # Associations + belongs_to :org + has_many :plans + has_many :phases, dependent: :destroy + has_many :sections, through: :phases + has_many :questions, through: :sections + + has_many :customizations, class_name: 'Template', foreign_key: 'dmptemplate_id' + belongs_to :dmptemplate, class_name: 'Template' + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + 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| + s.key :export, defaults: Settings::Template::DEFAULT_SETTINGS + end + + validates :org, :title, :version, presence: true + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + ## + # deep copy the given template and all of it's associations + # + # @params [Template] template to be deep copied + # @return [Template] saved copied template + def self.deep_copy(template) + template_copy = template.dup + template_copy.save! + template.phases.each do |phase| + phase_copy = Phase.deep_copy(phase) + phase_copy.template_id = template_copy.id + phase_copy.save! + end + return template_copy + end + + ## + # takes a type or organisation and returns all published templates from + # organisations of that type + # + # @param ot [String] name of an organisation type e.g. founder + # @return [Array] list of published dmptemplates +=begin + def self.templates_org_type(ot) + # DISCUSS - This function other than the check for the template being published + # is a superclass for the below funders_templates + new_org_obejcts = OrganisationType.find_by( name: ot ).organisations + + org_templates = Array.new + new_org_obejcts.each do |neworg| + org_templates += neworg.dmptemplates.where("published = ?", true) + end + + return org_templates + end + + ## + # returns all templates from all organisations of the Organisation_Type funder + # + # @return [Array] all templates from funder organisations + def self.funders_templates + funder_orgs = Org.includes(:templates).funder + org_templates = Array.new + + funder_orgs.each do |neworg| + org_templates += neworg.templates + end + + return org_templates + end + + ## + # returns all institutional templates bellowing to the given organisation + # + # @param org_id [integer] the integer id for an organisation + # @return [Array] all templates from a user's organisation + def self.own_institutional_templates(org_id) + # DISCUSS - Why is this done by scanning organisation_id's from the templates + # yet all other calls are done by finding an organisation, and using the + # has_many relationship to find the dmptemplates? + # - A possible answer is that there may be deleted organisations which we are + # serching for templates for. + # - A standardised behavior on querries, wether through active reccord or the + # where, should maybe be thought of/decided upon + new_templates = self.where("org_id = ?", org_id) + return new_templates + end + + ## + # returns an array with all funders and of the given organisations's + # institutional templates + # + # @param org_id [integer] the integer id for an organisation + # @return [Array] all templates from the template's organisation + # or from a funder organisation + def self.funders_and_own_templates(org_id) + funders_templates = self.funders_templates + + #verify if org type is not a funder + current_org = Org.find(org_id) + if !current_org.funder? then + own_institutional_templates = self.own_institutional_templates(org_id) + else + own_institutional_templates = [] + end + + templates_list = Array.new + templates_list += own_institutional_templates + templates_list += funders_templates + templates_list = templates_list.sort_by { |f| f['title'].downcase } + + return templates_list + end + + ## + # Returns the string name of the organisation type of the organisation who + # owns this dmptemplate + # + # @return [string] the string name of an organisation type + def org_type + org_type = org.organisation_type + return org_type + end +=end + +# TODO: Why are we passing in an org and template here? + ## + # Verify if a template has customisation by given organisation + # + # @param org_id [integer] the integer id for an organisation + # @param temp [dmptemplate] a template object + # @return [Boolean] true if temp has customisation by the given organisation + def has_customisations?(org_id, temp) + modifiable = true + phases.each do |phase| + modifiable = modifiable && phase.modifiable + end + return !modifiable + # if temp.org_id != org_id then + # temp.phases.each do |phase| + # phase.versions.each do |version| + # version.sections.each do |section| + # return true if section.organisation_id == org_id + # end + # end + # return false + # end + # else + # return false + # end + end + +=begin + ## + # verify if there are any publish version for the template + # + # @return [Boolean] true if there is a published version for the template + def has_published_versions? + phases.each do |phase| + return true if !phase.latest_published_version.nil? + end + return false + end +=end + + # OLD CODE STARTS HERE + +end diff --git a/app/models/theme.rb b/app/models/theme.rb index 0b31f36..315dfe8 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -1,17 +1,26 @@ class Theme < ActiveRecord::Base - #associations between tables + ## + # Associations has_and_belongs_to_many :questions, join_table: "questions_themes" has_and_belongs_to_many :guidances, join_table: "themes_in_guidance" - -# accepts_nested_attributes_for :guidances -# accepts_nested_attributes_for :questions - + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :guidance_ids , :as => [:default, :admin] attr_accessible :question_ids, :as => [:default, :admin] attr_accessible :description, :title, :locale , :as => [:default, :admin] + + validates :title, presence: true + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + ## # returns the title of the theme # diff --git a/app/models/token_permission_type.rb b/app/models/token_permission_type.rb index 8d368b6..71f8186 100644 --- a/app/models/token_permission_type.rb +++ b/app/models/token_permission_type.rb @@ -1,13 +1,26 @@ class TokenPermissionType < ActiveRecord::Base + ## + # 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', unique: true + has_and_belongs_to_many :orgs, join_table: 'org_token_permissions', unique: true + ## + # Possibly needed for active_admin + # - relies on proetected_attributes gem as syntax depricated in rails 4.2 attr_accessible :token_type, :text_description, :as => [:default, :admin] - #associations between tables - #has_and_belongs_to_many :org_token_permissions, join_table: "org_token_permissions" - has_and_belongs_to_many :organisations, join_table: 'org_token_permissions' - + ## + # Validators validates :token_type, presence: true, uniqueness: true + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + ## # returns the token_type of the token_permission_type # diff --git a/app/models/user.rb b/app/models/user.rb index 78eb512..4cf42a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,73 +1,82 @@ class User < ActiveRecord::Base include GlobalHelpers - # Include default devise modules. Others available are: - # :token_authenticatable, :confirmable, - # :lockable, :timeoutable and :omniauthable - devise :invitable, :database_authenticatable, :registerable, :recoverable, - :rememberable, :trackable, :validatable, :confirmable, - :omniauthable, omniauth_providers: [:orcid] + ## + # Devise + # Include default devise modules. Others available are: + # :token_authenticatable, :confirmable, + # :lockable, :timeoutable and :omniauthable + devise :invitable, :database_authenticatable, :registerable, :recoverable, + :rememberable, :trackable, :validatable, :confirmable, :omniauthable, + :omniauth_providers => [:shibboleth, :orcid] - #associations between tables - belongs_to :user_type - belongs_to :user_status + ## + # Associations + has_and_belongs_to_many :perms, join_table: :users_perms + belongs_to :language + belongs_to :org has_many :answers - has_many :user_org_roles - has_many :project_groups, :dependent => :destroy - has_many :user_role_types, through: :user_org_roles - - has_many :user_identifiers - has_many :identifier_schemes, through: :user_identifiers - - belongs_to :language - belongs_to :organisation - - has_many :projects, through: :project_groups do + has_many :notes + has_many :exported_plans + has_many :roles, dependent: :destroy + has_many :plans, through: :roles do def filter(query) return self unless query.present? - t = self.arel_table q = "%#{query}%" - conditions = t[:title].matches(q) - columns = %i( grant_number identifier description principal_investigator data_contact ) columns = ['grant_number', 'identifier', 'description', 'principal_investigator', 'data_contact'] - columns.each {|col| conditions = conditions.or(t[col].matches(q)) } - self.where(conditions) end end + + has_many :user_identifiers + has_many :identifier_schemes, through: :user_identifiers - has_and_belongs_to_many :roles, :join_table => :users_roles - - has_many :plan_sections - + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 accepts_nested_attributes_for :roles - attr_accessible :password_confirmation, :encrypted_password, :remember_me, :id, :email, - :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, - :user_status_id, :surname, :user_type_id, :organisation_id, :skip_invitation, - :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, - :organisation, :language, :language_id + attr_accessible :password_confirmation, :encrypted_password, :remember_me, + :id, :email, :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, :org, :perms, + :confirmed_at, :org_id validates :email, email: true, allow_nil: true, uniqueness: true + ## + # Settings # FIXME: The duplication in the block is to set defaults. It might be better if # they could be set in Settings::PlanList itself, if possible. has_settings :plan_list, class_name: 'Settings::PlanList' do |s| s.key :plan_list, defaults: { columns: Settings::PlanList::DEFAULT_COLUMNS } end + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + + + ## # gives either the name of the user, or the email if name unspecified # # @param user_email [Boolean] defaults to true, allows the use of email if there is no firstname or surname # @return [String] the email or the firstname and surname of the user def name(use_email = true) - if ((firstname.nil? && surname.nil?) || (firstname.strip == "" && surname.strip == "")) && use_email then + if (firstname.blank? && surname.blank?) || use_email then return email else name = "#{firstname} #{surname}" @@ -84,17 +93,21 @@ user_identifiers.where(identifier_scheme: scheme).first end +# TODO: Check the logic here. Its deleting the permissions if the user does not have permission +# to change orgs and either the incoming or existing org is nil. +# We should also NOT be auto-saving here!!! ## # sets a new organisation id for the user - # if the user has any roles such as org_admin or admin, those are removed + # 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 # # @param new_organisation_id [Integer] the id for an organisation # @return [String] the empty string as a causality of setting api_token +=begin def organisation_id=(new_organisation_id) unless self.can_change_org? || new_organisation_id.nil? || self.organisation.nil? # rip all permissions from the user - self.roles.delete_all + self.perms.delete_all end # set the user's new organisation super(new_organisation_id) @@ -110,7 +123,8 @@ def organisation=(new_organisation) organisation_id = new_organisation.id unless new_organisation.nil? end - +=end + ## # checks if the user is a super admin # if the user has any privelege which requires them to see the super admin page @@ -118,7 +132,7 @@ # # @return [Boolean] true if the user is an admin def can_super_admin? - return self.can_add_orgs? || self.can_grant_api_to_orgs? || can_change_org? + return self.can_add_orgs? || self.can_grant_api_to_orgs? || self.can_change_org? end ## @@ -128,7 +142,8 @@ # # @return [Boolean] true if the user is an organisation admin def can_org_admin? - return self.can_grant_permissions? || self.can_modify_guidance? || self.can_modify_templates? || self.can_modify_org_details? + return self.can_grant_permissions? || self.can_modify_guidance? || + self.can_modify_templates? || self.can_modify_org_details? end ## @@ -136,7 +151,7 @@ # # @return [Boolean] true if the user can add new organisations def can_add_orgs? - roles.include? Role.find_by(name: constant("user_role_types.add_organisations")) + perms.include? Perm.find_by(name: constant("roles.add_organisations")) end ## @@ -144,7 +159,7 @@ # # @return [Boolean] true if the user can change their organisation affiliations def can_change_org? - roles.include? Role.find_by(name: constant("user_role_types.change_org_affiliation")) + perms.include? Perm.find_by(name: constant("roles.change_org_affiliation")) end ## @@ -152,7 +167,7 @@ # # @return [Boolean] true if the user can grant their permissions to others def can_grant_permissions? - roles.include? Role.find_by(name: constant("user_role_types.grant_permissions")) + perms.include? Perm.find_by(name: constant("roles.grant_permissions")) end ## @@ -160,7 +175,7 @@ # # @return [Boolean] true if the user can modify organisation templates def can_modify_templates? - roles.include? Role.find_by(name: constant("user_role_types.modify_templates")) + perms.include? Perm.find_by(name: constant("roles.modify_templates")) end ## @@ -168,7 +183,7 @@ # # @return [Boolean] true if the user can modify organistion guidance def can_modify_guidance? - roles.include? Role.find_by(name: constant("user_role_types.modify_guidance")) + perms.include? Perm.find_by(name: constant("roles.modify_guidance")) end ## @@ -176,7 +191,7 @@ # # @return [Boolean] true if the user can use the api def can_use_api? - roles.include? Role.find_by(name: constant("user_role_types.use_api")) + perms.include? Perm.find_by(name: constant("roles.use_api")) end ## @@ -184,15 +199,7 @@ # # @return [Boolean] true if the user can modify the org's details def can_modify_org_details? - roles.include? Role.find_by(name: constant("user_role_types.change_org_details")) - end - - ## - # checks if the user can grant the api to organisations - # - # @return [Boolean] true if the user can grant api permissions to organisations - def can_grant_api_to_orgs? - roles.include? Role.find_by(name: constant('user_role_types.grant_api_to_orgs')) + perms.include? Perm.find_by(name: constant("roles.change_org_details")) end @@ -201,18 +208,20 @@ # # @return [Boolean] true if the user can grant api permissions to organisations def can_grant_api_to_orgs? - roles.include? Role.find_by(name: constant('user_role_types.grant_api_to_orgs')) + perms.include? Perm.find_by(name: constant('roles.grant_api_to_orgs')) end ## # checks what type the user's organisation is # # @return [String] the organisation type +=begin def org_type - org_type = organisation.organisation_type.name + org_type = org.organisation_type return org_type end - +=end + ## # removes the api_token from the user # modifies the user model @@ -234,44 +243,7 @@ end self.save! # send an email to the user to notify them of their new api token - UserMailer.api_token_granted_notification(self) - end - end - - ## - # updates the user permissions to the new system. - # the old system only had admin and org-admin roles, which loosely map to the - # new permissions system. - def self.update_user_permissions - admin = Role.find_by(name: 'admin') - org_admin = Role.find_by(name: 'org_admin') - add_orgs = Role.find_by(name: 'add_organisations') - change_org_affiliation = Role.find_by(name: 'change_org_affiliation') - grant_api_to_orgs = Role.find_by(name: 'grant_api_to_orgs') - grant_permissions = Role.find_by(name: 'grant_permissions') - modify_templates = Role.find_by(name: 'modify_templates') - modify_guidance = Role.find_by(name: 'modify_guidance') - change_org_details = Role.find_by(name: 'change_org_details') - User.includes(:roles).all.each do |user| - if user.roles.include? admin - #add admin roles - user.roles << add_orgs unless user.roles.include? add_orgs - user.roles << change_org_affiliation unless user.roles.include? change_org_affiliation - user.roles << grant_api_to_orgs unless user.roles.include? grant_api_to_orgs - user.roles << grant_permissions unless user.roles.include? grant_permissions - user.roles.delete(admin) - user.save! - end - if user.roles.include? org_admin - #add org-admin roles - user.roles << grant_permissions unless user.roles.include? grant_permissions - user.roles << modify_templates unless user.roles.include? modify_templates - user.roles << modify_guidance unless user.roles.include? modify_guidance - user.roles << change_org_details unless user.roles.include? change_org_details - user.roles.delete(org_admin) - # save the user - user.save! - end + #UserMailer.api_token_granted_notification(self) end end @@ -289,9 +261,11 @@ end end +# TODO: Remove this, its never called. # this generates a reset password link for a given user # which can then be sent to them with the appropriate host # prepended. +=begin def reset_password_link raw, enc = Devise.token_generator.generate(self.class, :reset_password_token) self.reset_password_token = enc @@ -300,5 +274,6 @@ edit_user_password_path + '?reset_password_token=' + raw end - +=end + end diff --git a/app/models/user_identifier.rb b/app/models/user_identifier.rb index 644ec52..6623765 100644 --- a/app/models/user_identifier.rb +++ b/app/models/user_identifier.rb @@ -4,4 +4,6 @@ # 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/models/user_org_role.rb b/app/models/user_org_role.rb deleted file mode 100644 index 10fca3c..0000000 --- a/app/models/user_org_role.rb +++ /dev/null @@ -1,9 +0,0 @@ -class UserOrgRole < ActiveRecord::Base - attr_accessible :organisation_id, :user_id, :user_role_type_id, :as => [:default, :admin] - - #associations between tables - belongs_to :user - belongs_to :organisation - belongs_to :user_role_type - -end diff --git a/app/models/user_role_type.rb b/app/models/user_role_type.rb deleted file mode 100644 index e012aca..0000000 --- a/app/models/user_role_type.rb +++ /dev/null @@ -1,7 +0,0 @@ -class UserRoleType < ActiveRecord::Base - - #associations between tables - has_many :user_org_roles - - attr_accessible :description, :name, :as => [:default, :admin] -end diff --git a/app/models/user_status.rb b/app/models/user_status.rb deleted file mode 100644 index a8c4dcd..0000000 --- a/app/models/user_status.rb +++ /dev/null @@ -1,6 +0,0 @@ -class UserStatus < ActiveRecord::Base - attr_accessible :description, :name, :as => [:default, :admin] - - #associations between tables - has_many :users -end diff --git a/app/models/user_type.rb b/app/models/user_type.rb deleted file mode 100644 index 8ceb4d4..0000000 --- a/app/models/user_type.rb +++ /dev/null @@ -1,6 +0,0 @@ -class UserType < ActiveRecord::Base - attr_accessible :description, :name, :as => [:default, :admin] - - #associations between tables - has_many :users -end diff --git a/app/models/version.rb b/app/models/version.rb deleted file mode 100644 index db03966..0000000 --- a/app/models/version.rb +++ /dev/null @@ -1,41 +0,0 @@ -class Version < ActiveRecord::Base - - #associations between tables - belongs_to :phase - - has_many :sections, :dependent => :destroy - has_many :questions, :through => :sections, :dependent => :destroy - has_many :plans - - #Link the data -# accepts_nested_attributes_for :phase - accepts_nested_attributes_for :sections, :allow_destroy => true - - attr_accessible :id, :description, :number, :published, :title, :phase_id, - :sections_attributes, :as => [:default, :admin] - - ## - # returns the title of the version - # - # @return [String] the title of the version - def to_s - "#{title}" - end - - - ## - # returns all sections where the org_id is the same as this version's phase's org_id - # - # @return [Array
    ] - def global_sections - sections.where("organisation_id = ? ", phase.dmptemplate.organisation_id).load - end - - amoeba do - include_association :sections - include_association :questions - set :published => 'false' - prepend :title => "Copy of " - end - -end diff --git a/app/policies/answer_policy.rb b/app/policies/answer_policy.rb index 61f6989..805efac 100644 --- a/app/policies/answer_policy.rb +++ b/app/policies/answer_policy.rb @@ -9,7 +9,8 @@ end def create? - @answer.plan.editable_by(@user.id) + # is the plan editable by the user, and is the user_id that of the user + @answer.plan.editable_by(@user.id) && (@answer.user_id == @user.id) end end \ No newline at end of file diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index de9b7ba..c0664f3 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -13,7 +13,7 @@ end def show? - scope.where(:id => record.id).exists? + scope.where(id: record.id).exists? end def create? diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb deleted file mode 100644 index 570c0a1..0000000 --- a/app/policies/comment_policy.rb +++ /dev/null @@ -1,23 +0,0 @@ -class CommentPolicy < ApplicationPolicy - attr_reader :user - attr_reader :comment - - def initialize(user, comment) - raise Pundit::NotAuthorizedError, "must be logged in" unless user - @user = user - @comment = comment - end - - def create? - Plan.find(@comment.plan_id).readable_by(@user.id) - end - - def update? - Plan.find(@comment.plan_id).readable_by(@user.id) - end - - def archive? - Plan.find(@comment.plan_id).readable_by(@user.id) - end - -end \ No newline at end of file diff --git a/app/policies/dmptemplate_policy.rb b/app/policies/dmptemplate_policy.rb deleted file mode 100644 index c2dbe91..0000000 --- a/app/policies/dmptemplate_policy.rb +++ /dev/null @@ -1,124 +0,0 @@ -class DmptemplatePolicy < ApplicationPolicy - attr_reader :user, :dmptemplate - - def initialize(user, dmptemplate) - raise Pundit::NotAuthorizedError, "must be logged in" unless user - @user = user - @dmptemplate = dmptemplate - end - - def admin_index? - user.can_modify_templates? - end - - def admin_template? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_update? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_new? - user.can_modify_templates? - end - - def admin_create? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_destroy? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_phase? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_previewphase? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_addphase? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_createphase? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_updatephase? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_destroyphase? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_updateversion? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_cloneversion? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_destroyversion? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_createsection? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_updatesection? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_destroysection? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_createquestion? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_updatequestion? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_destroyquestion? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_createsuggestedanswer? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_updatesuggestedanswer? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_destroysuggestedanswer? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_createguidance? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_updateguidance? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - def admin_destroyguidance? - user.can_modify_templates? #&& (dmptemplate.organisation_id == user.organisation_id) - end - - class Scope < Scope - def resolve - scope.where(organisation_id: user.organisation_id) - end - end - -end \ No newline at end of file diff --git a/app/policies/guidance_group_policy.rb b/app/policies/guidance_group_policy.rb index 422ea26..bb514c3 100644 --- a/app/policies/guidance_group_policy.rb +++ b/app/policies/guidance_group_policy.rb @@ -8,19 +8,19 @@ end def admin_show? - user.can_modify_guidance? && (guidance_group.organisation_id == user.organisation_id) + user.can_modify_guidance? && (guidance_group.org_id == user.org_id) end def admin_edit? - user.can_modify_guidance? && (guidance_group.organisation_id == user.organisation_id) + user.can_modify_guidance? && (guidance_group.org_id == user.org_id) end def admin_update? - user.can_modify_guidance? && (guidance_group.organisation_id == user.organisation_id) + user.can_modify_guidance? && (guidance_group.org_id == user.org_id) end def admin_update_publish? - user.can_modify_guidance? && (guidance_group.organisation_id == user.organisation_id) + user.can_modify_guidance? && (guidance_group.org_id == user.org_id) end def admin_new? @@ -32,12 +32,12 @@ end def admin_destroy? - user.can_modify_guidance? && (guidance_group.organisation_id == user.organisation_id) + user.can_modify_guidance? && (guidance_group.org_id == user.org_id) end class Scope < Scope def resolve - scope.where(organisation_id: user.organisation_id) + scope.where(org_id: user.org_id) end end diff --git a/app/policies/guidance_policy.rb b/app/policies/guidance_policy.rb index e527c4a..725326c 100644 --- a/app/policies/guidance_policy.rb +++ b/app/policies/guidance_policy.rb @@ -8,15 +8,15 @@ end def admin_show? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def admin_edit? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def admin_update? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def admin_index? @@ -32,7 +32,7 @@ end def admin_destroy? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def update_phases? @@ -53,7 +53,7 @@ class Scope < Scope def resolve - scope = Guidance.by_organisation(user.organisation_id) + scope = Guidance.includes(:guidance_group, :themes).by_org(user.org_id) end end end \ No newline at end of file diff --git a/app/policies/note_policy.rb b/app/policies/note_policy.rb new file mode 100644 index 0000000..8ffe95a --- /dev/null +++ b/app/policies/note_policy.rb @@ -0,0 +1,23 @@ +class NotePolicy < ApplicationPolicy + attr_reader :user + attr_reader :note + + def initialize(user, note) + raise Pundit::NotAuthorizedError, "must be logged in" unless user + @user = user + @note = note + end + + def create? + @note.answer.plan.readable_by?(@user.id) + end + + def update? + Plan.find(@note.plan_id).readable_by?(@user.id) + end + + def archive? + Plan.find(@note.plan_id).readable_by?(@user.id) + end + +end diff --git a/app/policies/org_policy.rb b/app/policies/org_policy.rb new file mode 100644 index 0000000..311d389 --- /dev/null +++ b/app/policies/org_policy.rb @@ -0,0 +1,34 @@ +class OrgPolicy < ApplicationPolicy + attr_reader :user, :org + + def initialize(user, org) + raise Pundit::NotAuthorizedError, "must be logged in" unless user + @user = user + @org = org + end + + def admin_show? + user.can_modify_org_details? && (user.org_id == org.id) + end + + def admin_edit? + user.can_modify_org_details? && (user.org_id == org.id) + end + + def admin_update? + user.can_modify_org_details? && (user.org_id == org.id) + end + + def parent? + true + end + + def children? + true + end + + def templates? + true + end + +end \ No newline at end of file diff --git a/app/policies/organisation_policy.rb b/app/policies/organisation_policy.rb deleted file mode 100644 index 8fb3bb2..0000000 --- a/app/policies/organisation_policy.rb +++ /dev/null @@ -1,34 +0,0 @@ -class OrganisationPolicy < ApplicationPolicy - attr_reader :user, :organisation - - def initialize(user, organisation) - raise Pundit::NotAuthorizedError, "must be logged in" unless user - @user = user - @organisation = organisation - end - - def admin_show? - user.can_modify_org_details? && (user.organisation.id == organisation.id) - end - - def admin_edit? - user.can_modify_org_details? && (user.organisation.id == organisation.id) - end - - def admin_update? - user.can_modify_org_details? && (user.organisation.id == organisation.id) - end - - def parent? - true - end - - def children? - true - end - - def templates? - true - end - -end \ No newline at end of file diff --git a/app/policies/plan_policy.rb b/app/policies/plan_policy.rb index 2d4d08a..cb43258 100644 --- a/app/policies/plan_policy.rb +++ b/app/policies/plan_policy.rb @@ -7,52 +7,61 @@ @user = user @plan = plan end + + def show? + @plan.readable_by?(@user.id) + end def edit? - @plan.editable_by(@user.id) + @plan.editable_by?(@user.id) + end + + def update_guidance_choices? + @plan.editable_by?(@user.id) + end + + def share? + @plan.readable_by?(@user.id) end def export? - @plan.readable_by(@user.id) + @plan.readable_by?(@user.id) end def update? - @plan.editable_by(@user.id) + @plan.editable_by?(@user.id) end def status? - @plan.readable_by(@user.id) + @plan.readable_by?(@user.id) end def section_answers? - @plan.readable_by(@user.id) + @plan.readable_by?(@user.id) end def locked? - @plan.readable_by(@user.id) + @plan.readable_by?(@user.id) end def delete_recent_locks? - @plan.editable_by(@user.id) + @plan.editable_by?(@user.id) end def unlock_all_sections? - @plan.editable_by(@user.id) + @plan.editable_by?(@user.id) end def lock_section? - @plan.editable_by(@user.id) + @plan.editable_by?(@user.id) end def unlock_section? - @plan.editable_by(@user.id) + @plan.editable_by?(@user.id) end def answer? - @plan.readable_by(@user.id) + @plan.readable_by?(@user.id) end - def warning? - @plan.readable_by(@user.id) - end -end \ No newline at end of file +end diff --git a/app/policies/project_group_policy.rb b/app/policies/project_group_policy.rb deleted file mode 100644 index 595687e..0000000 --- a/app/policies/project_group_policy.rb +++ /dev/null @@ -1,22 +0,0 @@ -class ProjectGroupPolicy < ApplicationPolicy - attr_reader :user - attr_reader :project_group - - def initialize(user, project_group) - raise Pundit::NotAuthorizedError, "must be logged in" unless user - @user = user - @project_group = project_group - end - - def create? - @project_group.project.administerable_by(@user.id) - end - - def update? - @project_group.project.administerable_by(@user.id) - end - - def destroy? - @project_group.project.administerable_by(@user.id) - 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/role_policy.rb b/app/policies/role_policy.rb new file mode 100644 index 0000000..7aebf02 --- /dev/null +++ b/app/policies/role_policy.rb @@ -0,0 +1,22 @@ +class RolePolicy < ApplicationPolicy + attr_reader :user + attr_reader :role + + def initialize(user, role) + raise Pundit::NotAuthorizedError, "must be logged in" unless user + @user = user + @role = role + end + + def create? + @role.plan.administerable_by(@user.id) + end + + def update? + @role.plan.administerable_by(@user.id) + end + + def destroy? + @role.plan.administerable_by(@user.id) + end +end \ No newline at end of file diff --git a/app/policies/template_policy.rb b/app/policies/template_policy.rb new file mode 100644 index 0000000..1fd64f5 --- /dev/null +++ b/app/policies/template_policy.rb @@ -0,0 +1,128 @@ +class TemplatePolicy < ApplicationPolicy + attr_reader :user, :template + + def initialize(user, template) + raise Pundit::NotAuthorizedError, "must be logged in" unless user + @user = user + @template = template + end + + def admin_index? + user.can_modify_templates? + end + + def admin_template? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_update? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_new? + user.can_modify_templates? + end + + def admin_create? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_destroy? + 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 + + def admin_previewphase? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_addphase? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_createphase? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_updatephase? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_destroyphase? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_updateversion? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_cloneversion? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_destroyversion? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_createsection? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_updatesection? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_destroysection? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_createquestion? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_updatequestion? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_destroyquestion? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_createsuggestedanswer? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_updatesuggestedanswer? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_destroysuggestedanswer? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_createguidance? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_updateguidance? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + def admin_destroyguidance? + user.can_modify_templates? && (template.org_id == user.org_id) + end + + class Scope < Scope + def resolve + scope.where(org_id: user.org_id) + end + end + +end \ No newline at end of file diff --git a/app/policies/token_permission_type_policy.rb b/app/policies/token_permission_type_policy.rb index fb4699e..ee4a947 100644 --- a/app/policies/token_permission_type_policy.rb +++ b/app/policies/token_permission_type_policy.rb @@ -8,7 +8,7 @@ end def index? - user.can_use_api? && (user.organisation.token_permission_types.count > 0) + user.can_use_api? && (user.org.token_permission_types.count > 0) end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index bb44ae5..a97a91b 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -12,16 +12,16 @@ end def admin_grant_permissions? - @user.can_grant_permissions? && (@users.organisation_id == @user.organisation_id) + @user.can_grant_permissions? && (@users.org_id == @user.org_id) end def admin_update_permissions? - @user.can_grant_permissions? && (@users.organisation_id == @user.organisation_id) + @user.can_grant_permissions? && (@users.org_id == @user.org_id) end class Scope < Scope def resolve - scope.where(organisation_id: user.organisation_id) + scope.where(org_id: user.org_id) end 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/views/admin/dmptemplates/settings.html.erb b/app/views/admin/dmptemplates/settings.html.erb index 171d5bc..c955083 100644 --- a/app/views/admin/dmptemplates/settings.html.erb +++ b/app/views/admin/dmptemplates/settings.html.erb @@ -4,15 +4,15 @@ <%= form_for(@settings, url: update_settings_admin_dmptemplate_path(@template), method: :put, as: 'settings[export][formatting]', html: { class: 'formtastic' }) do |f| %>
    - <%= t("admin.formatting")%> + <%= _('Formatting') %>
    1. - <%= f.label(:font_face, t('helpers.settings.plans.font_face')) %> + <%= f.label(:font_face, _('Face')) %> <%= f.select(:font_face, options_for_select(Settings::Dmptemplate::VALID_FONT_FACES, @settings.formatting[:font_face]), as: 'formatting[font_face]') %> <%= f.select(:font_size, options_for_select((1..36).to_a, @settings.formatting[:font_size])) %>pt
    2. - <%= f.label(t('helpers.settings.plans.margin')) %> + <%= f.label(_('Margin')) %> <% ["top", "bottom", "left", "right"].each do |pos| %> <%= t("helpers.settings.plans.margins.#{pos}") -%> <%= select_tag("settings[export][formatting][margin][#{pos}]", options_for_select((0..100).to_a, @settings.formatting[:margin][pos])) %> @@ -22,17 +22,17 @@
    - <%= t("admin.max_pages")%> + <%= _('Max Pages')%>
    1. - <%= label_tag('settings_export_max_pages', t('helpers.settings.plans.max_pages')) %> + <%= label_tag('settings_export_max_pages', _('Maximum number of pages')) %> <%= select_tag('settings[export][max_pages]', options_for_select((1..10).to_a, @settings.max_pages)) %>
    - <%= submit_tag(t('helpers.save'), class: 'btn btn-primary') %> - <%= submit_tag(t('helpers.settings.plans.reset'), class: 'btn btn-primary') %> + <%= submit_tag(_('Save'), class: 'btn btn-primary') %> + <%= submit_tag(_('Reset'), class: 'btn btn-primary') %>
    <% end %> 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 33ebd74..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 Organisation.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/statistics/plans.json.jbuilder b/app/views/api/v0/statistics/plans.json.jbuilder index 1a05c9b..fe85ca8 100644 --- a/app/views/api/v0/statistics/plans.json.jbuilder +++ b/app/views/api/v0/statistics/plans.json.jbuilder @@ -1,25 +1,25 @@ json.prettify! -json.plans @org_projects.each do |project| - json.id project.id - json.grant_number project.grant_number - json.org_id project.organisation_id +json.plans @org_projects.each do |plan| + json.id plan.id + json.grant_number plan.grant_number + json.org_id plan.creator.org.id json.template do - json.title project.dmptemplate.title - json.id project.dmptemplate.id + json.title plan.template.title + json.id plan.template.id end json.project do - json.title project.title + json.title plan.title end json.funder do - json.name project.funder_name + json.name (plan.template.org.funder? ? plan.org.name : '') end json.principal_investigator do - json.name project.principal_investigator + json.name plan.principal_investigator end json.data_contact do - json.info project.data_contact + json.info plan.data_contact end - json.description project.description + json.description plan.description end \ No newline at end of file diff --git a/app/views/api/v0/statistics/plans_by_template.json.jbuilder b/app/views/api/v0/statistics/plans_by_template.json.jbuilder index 155bbba..d8d5485 100644 --- a/app/views/api/v0/statistics/plans_by_template.json.jbuilder +++ b/app/views/api/v0/statistics/plans_by_template.json.jbuilder @@ -1,14 +1,14 @@ json.prettify! templates = {} -@org_projects.each do |project| +@org_projects.each do |plan| # if hash exists - if templates[project.dmptemplate.title].blank? - templates[project.dmptemplate.title] = {} - templates[project.dmptemplate.title][:title] = project.dmptemplate.title - templates[project.dmptemplate.title][:id] = project.dmptemplate.id - templates[project.dmptemplate.title][:uses] = 1 + if templates[plan.template.title].blank? + templates[plan.template.title] = {} + templates[plan.template.title][:title] = plan.template.title + templates[plan.template.title][:id] = plan.template.id + templates[plan.template.title][:uses] = 1 else - templates[project.dmptemplate.title][:uses] += 1 + templates[plan.template.title][:uses] += 1 end 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 index 03c1588..bbc8d75 100644 --- a/app/views/devise/registrations/_external_identifier.html.erb +++ b/app/views/devise/registrations/_external_identifier.html.erb @@ -10,10 +10,15 @@ title: t("identifier_schemes.schemes.#{scheme.name}.connect_tooltip") %> <% 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") %> - + <% 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"), diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 3cbfab4..ae0c08c 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -3,140 +3,130 @@ <%= raw t("helpers.user_details_text_html") %>
    - <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:method => :put}) do |f| %> - <%= hidden_field_tag :unlink_flag, "false", :id => "unlink_flag" %> + <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}) do |f| %> + <%= hidden_field_tag :unlink_flag, "false", id: "unlink_flag" %>

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

    - - - - - - - - - - - - - - - - - - <% other_organisations = Array.new %> - <% Organisation.where("parent_id IS ? AND is_other = ?", nil, true).each do |org| %> - <% other_organisations << org.id %> - <% 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, - :organisation_id, Organisation.where("parent_id IS NULL").order("name"), - :id, :name, {include_blank: constant("organisation_types.organisation")}, - { :class => "typeahead org_sign_up" }) %>
    + + + + + + + + + + + + + + + + + "> + + + - - - <% @identifier_schemes.each do |scheme| %> - - - - - <% end %> - - - <% 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') %> - - - -
    <%= scheme.name %> - <%= render partial: 'external_identifier', - locals: {scheme: scheme, - id: current_user.identifier_for(scheme)} %> -
    <%= t("helpers.api_token") %><%= @user.api_token %>
    <%= t("helpers.api_info") %><%= link_to( t("helpers.api_use"), controller: "token_permission_types", action: "index")%>
    -
    -

    - <% 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" %> - <% else %> - <%= t("helpers.shibboleth_linked_text") %> - - <%= t("helpers.shibboleth_unlink_label")%> - - <% end %> + + + + + + <% @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" %> + <% else %> + <%= t("helpers.shibboleth_linked_text") %> + + <%= t("helpers.shibboleth_unlink_label")%> + + <% 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 %>
    diff --git a/app/views/dmptemplates/_add_guidance.html.erb b/app/views/dmptemplates/_add_guidance.html.erb deleted file mode 100644 index de49775..0000000 --- a/app/views/dmptemplates/_add_guidance.html.erb +++ /dev/null @@ -1,93 +0,0 @@ - -
    - <%= 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" %> -
    - -
    - <%= tinymce :content_css => asset_path("application.css") %> - <%end%> -
    - - - - - \ No newline at end of file diff --git a/app/views/dmptemplates/_add_question.html.erb b/app/views/dmptemplates/_add_question.html.erb deleted file mode 100644 index 1caf54c..0000000 --- a/app/views/dmptemplates/_add_question.html.erb +++ /dev/null @@ -1,179 +0,0 @@ - - -<% @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), - {}, :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/_add_section.html.erb b/app/views/dmptemplates/_add_section.html.erb deleted file mode 100644 index b445c85..0000000 --- a/app/views/dmptemplates/_add_section.html.erb +++ /dev/null @@ -1,54 +0,0 @@ - - -<% @new_section = Section.new %> -<% @new_section.number = version.sections.count + 1 %> - - -<%= form_for @new_section, :url => {:action => "admin_createsection"} do |f| %> - <%= f.hidden_field :version_id, :value => version.id %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> - -
    -
    -
    -
    - - <%= f.text_field :title, :as => :string, :class => "text_field", :placeholder => t("org_admin.templates.section_title_placeholder")%> -
    - - -
    - -
    -
    -
    - - - - - - - - - -
    <%= t("org_admin.templates.phase_order_label") %> - <%= f.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", "" , 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"))%> -
    -
    - -
    - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), "#", :id => "", :class => "btn cancel" %> -
    -
    -
    -
    -
    -<%end%> - - diff --git a/app/views/dmptemplates/_add_suggested_answer.html.erb b/app/views/dmptemplates/_add_suggested_answer.html.erb deleted file mode 100644 index 03e11b7..0000000 --- a/app/views/dmptemplates/_add_suggested_answer.html.erb +++ /dev/null @@ -1,25 +0,0 @@ - -<%= form_for :suggested_answer, :url => {:action => "admin_createsuggestedanswer"} do |f| %> - <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> - <%= f.hidden_field :question_id, :value => question.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 %> -
    • -
    -
    -
    - - -
    - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), "#", :id => "cancel_suugested_answer", :class => "btn cancel" %> -
    -<%end%> diff --git a/app/views/dmptemplates/_admin_nav_tabs.html.erb b/app/views/dmptemplates/_admin_nav_tabs.html.erb deleted file mode 100644 index 49c3c20..0000000 --- a/app/views/dmptemplates/_admin_nav_tabs.html.erb +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/app/views/dmptemplates/_edit_guidance.html.erb b/app/views/dmptemplates/_edit_guidance.html.erb deleted file mode 100644 index 8debbca..0000000 --- a/app/views/dmptemplates/_edit_guidance.html.erb +++ /dev/null @@ -1,26 +0,0 @@ - -<%= 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 %> - - - - - - -
    <%= 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%> diff --git a/app/views/dmptemplates/_edit_phase.html.erb b/app/views/dmptemplates/_edit_phase.html.erb deleted file mode 100644 index 1536a48..0000000 --- a/app/views/dmptemplates/_edit_phase.html.erb +++ /dev/null @@ -1,45 +0,0 @@ - - -<%= 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 diff --git a/app/views/dmptemplates/_edit_question.html.erb b/app/views/dmptemplates/_edit_question.html.erb deleted file mode 100644 index ab12c02..0000000 --- a/app/views/dmptemplates/_edit_question.html.erb +++ /dev/null @@ -1,174 +0,0 @@ - - -<%= form_for(question, :url => admin_updatequestion_dmptemplate_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_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.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 %> -
      -
    • <%= 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("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" %> -
    -
    - - - -<%= render :partial => "guidance_display", locals: {question: question}%> -<%end%> diff --git a/app/views/dmptemplates/_edit_section.html.erb b/app/views/dmptemplates/_edit_section.html.erb deleted file mode 100644 index 8f7f8b4..0000000 --- a/app/views/dmptemplates/_edit_section.html.erb +++ /dev/null @@ -1,116 +0,0 @@ - - - -<%= 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%> - - <%if @new_sec then%> - <% 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') %> - -
    -
    - -
    - - -
    -
    - - - - - - - - - -
    <%= 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} %> -
    - - -
    - - <%if question_left.to_i > 1 then %> -
    - <%else%> -
    - <%end%> - <% question_left = question_left - 1 %> - - <%end%> - <%end%> - - - <% if !section.version.published? || phase.dmptemplate.org_type == constant("organisation_types.funder") then%> - - <%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%> - -
    -
    -
    -
    diff --git a/app/views/dmptemplates/_edit_suggested_answer.html.erb b/app/views/dmptemplates/_edit_suggested_answer.html.erb deleted file mode 100644 index 2f78934..0000000 --- a/app/views/dmptemplates/_edit_suggested_answer.html.erb +++ /dev/null @@ -1,26 +0,0 @@ - -<%= 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 %> - - - - - - -
    <%= 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%> diff --git a/app/views/dmptemplates/_edit_template.html.erb b/app/views/dmptemplates/_edit_template.html.erb deleted file mode 100644 index dbea10a..0000000 --- a/app/views/dmptemplates/_edit_template.html.erb +++ /dev/null @@ -1,52 +0,0 @@ - - -<%= 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 diff --git a/app/views/dmptemplates/_edit_version.html.erb b/app/views/dmptemplates/_edit_version.html.erb deleted file mode 100644 index 416fdb7..0000000 --- a/app/views/dmptemplates/_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/dmptemplates/_guidance_display.html.erb b/app/views/dmptemplates/_guidance_display.html.erb deleted file mode 100644 index 4082baf..0000000 --- a/app/views/dmptemplates/_guidance_display.html.erb +++ /dev/null @@ -1,36 +0,0 @@ - - -
    -
    - <% 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 diff --git a/app/views/dmptemplates/_option_fields.html.erb b/app/views/dmptemplates/_option_fields.html.erb deleted file mode 100644 index 21f3e80..0000000 --- a/app/views/dmptemplates/_option_fields.html.erb +++ /dev/null @@ -1,7 +0,0 @@ - - - <%= 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/dmptemplates/_preview_question.html.erb b/app/views/dmptemplates/_preview_question.html.erb deleted file mode 100644 index fa75e30..0000000 --- a/app/views/dmptemplates/_preview_question.html.erb +++ /dev/null @@ -1,124 +0,0 @@ - - -
    - - - <% 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") %> - -
    -
    -
    - - - -<%= render :partial => "guidance_display", locals: {question: question}%> diff --git a/app/views/dmptemplates/_show_phase.html.erb b/app/views/dmptemplates/_show_phase.html.erb deleted file mode 100644 index 01117cf..0000000 --- a/app/views/dmptemplates/_show_phase.html.erb +++ /dev/null @@ -1,37 +0,0 @@ - - -

    - <%= 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.dmptemplate.org_type != constant("organisation_types.funder") then%> -
    - <%= 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 %>
    -
    diff --git a/app/views/dmptemplates/_show_phases_sections.html.erb b/app/views/dmptemplates/_show_phases_sections.html.erb deleted file mode 100644 index 19c603a..0000000 --- a/app/views/dmptemplates/_show_phases_sections.html.erb +++ /dev/null @@ -1,73 +0,0 @@ - - -
    - -
    -

    <%= 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 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%> - - -
    diff --git a/app/views/dmptemplates/_show_question.html.erb b/app/views/dmptemplates/_show_question.html.erb deleted file mode 100644 index df79c2b..0000000 --- a/app/views/dmptemplates/_show_question.html.erb +++ /dev/null @@ -1,153 +0,0 @@ - - -
    - - - - - - - - - - - - - - <%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 (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%> -
    -
    - <% 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} %> -
    - - - <%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%> -
    -
    - - - -<%= render :partial => 'guidance_display', locals: {question: question}%> diff --git a/app/views/dmptemplates/_show_section.html.erb b/app/views/dmptemplates/_show_section.html.erb deleted file mode 100644 index 1dbf719..0000000 --- a/app/views/dmptemplates/_show_section.html.erb +++ /dev/null @@ -1,43 +0,0 @@ - -<%if @open && @section_id == section.id then%> - <% toggle = 'accordion-body section-collapse in collapse'%> -<%else%> - <% toggle = 'accordion-body collapse section-collapse' %> -<%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}%> -
    - - <% if last_question_id == question.id then %> -
    - <% else %> -
    - <% end %> - - <%end%> -
    -
    -
    diff --git a/app/views/dmptemplates/_show_suggested_answer.html.erb b/app/views/dmptemplates/_show_suggested_answer.html.erb deleted file mode 100644 index 888dd45..0000000 --- a/app/views/dmptemplates/_show_suggested_answer.html.erb +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - -
    - <% 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 %>
    -
    - -
    - <%= 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/dmptemplates/_show_template.html.erb b/app/views/dmptemplates/_show_template.html.erb deleted file mode 100644 index 7cfec9d..0000000 --- a/app/views/dmptemplates/_show_template.html.erb +++ /dev/null @@ -1,43 +0,0 @@ - - -<% 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%> -
    - - - - - - - - - - - - - - - - - - - - - - -
    <%= 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 %>
    diff --git a/app/views/dmptemplates/_show_version.html.erb b/app/views/dmptemplates/_show_version.html.erb deleted file mode 100644 index 3e1456e..0000000 --- a/app/views/dmptemplates/_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/dmptemplates/_versions_table.html.erb b/app/views/dmptemplates/_versions_table.html.erb deleted file mode 100644 index e51dbfe..0000000 --- a/app/views/dmptemplates/_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/dmptemplates/admin_addphase.html.erb b/app/views/dmptemplates/admin_addphase.html.erb deleted file mode 100644 index 6e8a336..0000000 --- a/app/views/dmptemplates/admin_addphase.html.erb +++ /dev/null @@ -1,75 +0,0 @@ -<%- model_class = Phase -%> -<%= stylesheet_link_tag "admin" %> -<% javascript "admin.js" %> - -

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

    - -
    - - -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @dmptemplate, 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%> -
    -
    -
    -
    - -<%= tinymce :content_css => asset_path("application.css") %> \ No newline at end of file diff --git a/app/views/dmptemplates/admin_index.html.erb b/app/views/dmptemplates/admin_index.html.erb deleted file mode 100644 index b22018c..0000000 --- a/app/views/dmptemplates/admin_index.html.erb +++ /dev/null @@ -1,153 +0,0 @@ -<%= stylesheet_link_tag "admin" %> - -

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

    -
    -

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

    - -
    - <%= raw t('org_admin.templates.create_own_template_text_html')%> -
    -
    - -
    - <%= link_to t("org_admin.templates.create_template"), - admin_new_dmptemplate_path, - :class => 'btn btn-primary' %> -
    -
    -
    - - -<% if @dmptemplates_own.count > 0 then %> - - - - - - - - - - - - <% @dmptemplates_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.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_temp_updated = version.updated_at %> - <%end%> - <%end%> - <%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_dmptemplate_path(org_template), :class => "dmp_table_link"%> -
    - -<%end%> - -
    -
    - - -<% if current_user.org_type != constant("organisation_types.funder") then %> -

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

    - - - <% if @dmptemplates_funders.count > 0 then %> - - - - - - - - - - - - - - <% @dmptemplates_funders.each do |org_template| %> - <% if org_template.published? ||org_template.has_customisations?(current_user.organisation_id, org_template) then %> - - - - - - - - <%end%> - <%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')) %> - - <%if org_template.published? then %> - <%= org_template.published%> - <%else%> - <%= t("helpers.false_lowercase")%> - <%end%> - - <% 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 %> - - - <%if current_user.can_org_admin? then%> - <% if org_template.org_type == constant("organisation_types.funder") then %> - <%if org_template.has_customisations?(current_user.organisation_id, org_template) then%> - <% b_label = t("org_admin.templates.edit_customisation")%> - <%else%> - <% b_label = t("org_admin.templates.customise")%> - <%end%> - <%else%> - <% b_label = t("helpers.submit.edit")%> - <%end%> - <%else%> - <% b_label = t("helpers.view")%> - <%end%> - <%= link_to b_label, admin_template_dmptemplate_path(org_template), :class => "dmp_table_link"%> -
    - <%end%> -<%end%> diff --git a/app/views/dmptemplates/admin_new.html.erb b/app/views/dmptemplates/admin_new.html.erb deleted file mode 100644 index 798f855..0000000 --- a/app/views/dmptemplates/admin_new.html.erb +++ /dev/null @@ -1,48 +0,0 @@ -<%= stylesheet_link_tag "admin" %> -<% 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" %> -
    -

    - -
    -
    - -
    - <%= 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%> -
    -
    -<%= tinymce :content_css => asset_path("application.css") %> \ No newline at end of file diff --git a/app/views/dmptemplates/admin_phase.html.erb b/app/views/dmptemplates/admin_phase.html.erb deleted file mode 100644 index b85927b..0000000 --- a/app/views/dmptemplates/admin_phase.html.erb +++ /dev/null @@ -1,82 +0,0 @@ -<%- model_class = Phase -%> -<%= stylesheet_link_tag "admin" %> -<% javascript 'admin.js' %> - -<%= 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' %> -
    -

    - -
    - - -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @phase.dmptemplate, 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 => "versions_table", locals: {phase: @phase}%> - <%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 %> - - - - - -
    -
    - <%= link_to t('org_admin.add_section_label'),'#', :id => 'add_section_button', :class =>'btn btn-primary' %> -
    -
    - <%end%> - - diff --git a/app/views/dmptemplates/admin_previewphase.html.erb b/app/views/dmptemplates/admin_previewphase.html.erb deleted file mode 100644 index 12c2507..0000000 --- a/app/views/dmptemplates/admin_previewphase.html.erb +++ /dev/null @@ -1,64 +0,0 @@ -<%- model_class = Phase -%> -<%= 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' %> -
    -

    - -
    - - -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @version.phase.dmptemplate, active: @version.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 diff --git a/app/views/dmptemplates/admin_template.html.erb b/app/views/dmptemplates/admin_template.html.erb deleted file mode 100644 index 642fb15..0000000 --- a/app/views/dmptemplates/admin_template.html.erb +++ /dev/null @@ -1,61 +0,0 @@ -<%= stylesheet_link_tag "admin" %> -<% javascript 'admin.js' %> - -

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

    - -
    - - -<%= render :partial => "admin_nav_tabs", locals: {dmptemplate: @dmptemplate, 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%> -
    - -<%= tinymce :content_css => asset_path('application.css') %> diff --git a/app/views/dmptemplates/export.pdf.erb b/app/views/dmptemplates/export.pdf.erb deleted file mode 100644 index 3726b39..0000000 --- a/app/views/dmptemplates/export.pdf.erb +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - <%= @template.title %> - - - - -

    <%= @template.title %>

    - - \ No newline at end of file diff --git a/app/views/guidance_groups/admin_edit.html.erb b/app/views/guidance_groups/admin_edit.html.erb index 2ea27f8..f81dbfc 100644 --- a/app/views/guidance_groups/admin_edit.html.erb +++ b/app/views/guidance_groups/admin_edit.html.erb @@ -7,7 +7,7 @@
    <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => 'btn btn-primary' %> + class: 'btn btn-primary' %>
    @@ -16,7 +16,7 @@
    - <%= form_for(@guidance_group, :url => admin_update_guidance_group_path(@guidance_group), :html => {:method => :put}) do |f| %> + <%= form_for(@guidance_group, url: admin_update_guidance_group_path(@guidance_group), html: {method: :put}) do |f| %> @@ -24,34 +24,15 @@ - - - - <% if @guidance_group.published == true then %> @@ -74,7 +55,7 @@ <%= f.check_box :optional_subset %> <%= t('org_admin.guidance_group.subset_eg') %>
    - <%= link_to(image_tag('help_button.png'), '#', :class => 'guidance_group_subset_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.subset_option_help_text')) %> + <%= link_to(image_tag('help_button.png'), '#', class: 'guidance_group_subset_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.subset_option_help_text')) %>
    @@ -84,14 +65,14 @@
    - <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> <% if @guidance_group.published == false then %> - <%= f.submit t('helpers.submit.publish'), :name => "save_publish", :class => "btn btn-primary" %> + <%= f.submit t('helpers.submit.publish'), name: "save_publish", class: "btn btn-primary" %> <% end %> - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn cancel' %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %>

    <% end %> - + \ No newline at end of file diff --git a/app/views/guidance_groups/admin_new.html.erb b/app/views/guidance_groups/admin_new.html.erb index 4bd3367..712cf83 100644 --- a/app/views/guidance_groups/admin_new.html.erb +++ b/app/views/guidance_groups/admin_new.html.erb @@ -7,8 +7,8 @@
    <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => "btn btn-primary" %> -
    + class: "btn btn-primary" %> +
    @@ -16,31 +16,16 @@
    - <%= form_for :guidance_group, :url => {:action => "admin_create"} do |f| %> - + <%= form_for :guidance_group, url: {action: "admin_create"} do |f| %> +
    <%= f.text_field :name, - :as => :string, - :class => 'text_field' %> + as: :string, + class: 'text_field' %>
    - <%= link_to(image_tag('help_button.png'), '#', :class => 'guidance_group_title_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.title_help_text_html')) %> + <%= link_to(image_tag('help_button.png'), '#', class: 'guidance_group_title_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.title_help_text_html')) %>
    <%= t('org_admin.guidance.template') %> -
    - <% if @guidance_group.dmptemplate_ids == [] then %> - <% default_select = "" %> - <% else %> - <% default_select = @guidance_group.dmptemplate_ids %> - <% end %> - <%= f.select :dmptemplate_ids, options_for_select( - [['All templates', ""]].concat(Dmptemplate.funders_and_own_templates(current_user.organisation_id).collect { |g| [g.title, g.id] }), :selected => default_select), {}, - {:prompt => false, :multiple => true} %> -
    -
    - <%= link_to(image_tag('help_button.png'), '#', :class => 'guidance_group_template_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.template_help_text_html')) %> -
    - -
    - - - - @@ -50,22 +35,18 @@ <%= f.check_box :optional_subset %> <%= t('org_admin.guidance_group.subset_eg') %>
    - <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_subset_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.subset_option_help_text'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_group_subset_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.subset_option_help_text'))%>
    - -
    <%= t('org_admin.guidance_group.name_label') %>
    - <%= f.text_field :name, - :as => :string, - :class => "text_field" %> + <%= f.text_field :name, as: :string, class: "text_field" %>
    - <%= link_to( image_tag("help_button.png"), "#", :class => 'guidance_group_title_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t("org_admin.guidance_group.title_help_text_html"))%> -
    - -
    <%= t("org_admin.guidance.template") %>
    - <%= f.select :dmptemplate_ids, options_for_select( - [['All templates', ""]].concat( Dmptemplate.funders_and_own_templates(current_user.organisation_id).collect{ |g| [g.title, g.id] })),{} , - {:prompt => false , :multiple => true}%> -
    -
    - <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_template_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance_group.template_help_text_html'))%> + <%= link_to( image_tag("help_button.png"), "#", class: 'guidance_group_title_popover', rel: "popover", 'data-html' => "true", 'data-content' => t("org_admin.guidance_group.title_help_text_html"))%>
    - + -
    - <%= f.submit t("helpers.submit.save"), :name => "draft", :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.cancel"), :back, :class => "btn cancel btn-secondary" %> + <%= f.submit t("helpers.submit.save"), name: "draft", class: "btn btn-primary" %> + <%= link_to t("helpers.submit.cancel"), :back, class: "btn cancel btn-secondary" %>
    -
    - <%end%> + <% end %>
    -
    +
    diff --git a/app/views/guidance_groups/admin_show.html.erb b/app/views/guidance_groups/admin_show.html.erb index a5998ec..fba06cc 100644 --- a/app/views/guidance_groups/admin_show.html.erb +++ b/app/views/guidance_groups/admin_show.html.erb @@ -7,7 +7,7 @@
    <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => "btn btn-primary" %> + class: "btn btn-primary" %>
    @@ -23,39 +23,9 @@ <%= raw @guidance_group.name %> - - <% if @guidance_group.dmptemplates.count == 1 then %> - <%= t("org_admin.guidance.template") %> - <% else %> - <%= t("org_admin.guidance.templates") %> - <% end %> - - - <% i = 1 %> - <% if @guidance_group.dmptemplates.count == 0 then %> - <% list = Dmptemplate.funders_and_own_templates(current_user.organisation_id) %> - <% list.each do |tem| %> - <%= tem.title %> - <% if list.count > i then %> - , - <% i +=1 %> - <% end %> - <% end %> - <% else %> - <% @guidance_group.dmptemplates.each do |tem| %> - <%= tem.title %> - <% if @guidance_group.dmptemplates.count > i then %> - , - <% i +=1 %> - <% end %> - <% end %> - <% end %> - - - <%= t('org_admin.templates.published_label') %> - <% if @guidance_group.published.nil? || @guidance_group.published == false then %> + <% if @guidance_group.published.nil? || !@guidance_group.published then %> <%= t("helpers.no_label") %> <% else %> <%= t("helpers.yes_label") %> @@ -66,7 +36,7 @@ <%= t("org_admin.guidance_group.subset") %> - <% if @guidance_group.optional_subset.nil? || @guidance_group.optional_subset == false then %> + <% if @guidance_group.optional_subset.nil? || !@guidance_group.optional_subset then %> <%= t('helpers.no_label') %> <% else %> <%= t('helpers.yes_label') %> @@ -75,18 +45,18 @@ <%= t("org_admin.guidance.created") %> - <%= l @guidance_group.created_at.to_date, :formats => :short %> + <%= l @guidance_group.created_at.to_date, formats: :short %> <%= t("org_admin.guidance.last_updated") %> - <%= l @guidance_group.updated_at.to_date, :formats => :short %> + <%= l @guidance_group.updated_at.to_date, formats: :short %>
    - <%= link_to t("helpers.submit.edit"), admin_edit_guidance_group_path(@guidance_group.id), :class => "btn btn-primary" %> - <%= link_to t("helpers.submit.back"), :back, :class => "btn cancel" %> + <%= link_to t("helpers.submit.edit"), admin_edit_guidance_group_path(@guidance_group.id), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.back"), :back, class: "btn cancel" %>

    - \ No newline at end of file + \ No newline at end of file diff --git a/app/views/guidances/admin_edit.html.erb b/app/views/guidances/admin_edit.html.erb index e6a47f9..055334d 100644 --- a/app/views/guidances/admin_edit.html.erb +++ b/app/views/guidances/admin_edit.html.erb @@ -7,11 +7,11 @@
    <%= link_to t("org_admin.guidance.add_guidance"), admin_new_guidance_path, - :class => 'btn btn-primary' %> + class: 'btn btn-primary' %> <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => 'btn btn-primary' %> -
    + class: 'btn btn-primary' %> +
    @@ -19,8 +19,8 @@
    - <%= form_for(@guidance, :url => admin_update_guidance_path(@guidance), :html => { :method => :put , :id => 'edit_guidance_form'}) do |f| %> - + <%= form_for(@guidance, url: admin_update_guidance_path(@guidance), html: { method: :put , id: 'edit_guidance_form'}) do |f| %> + @@ -28,7 +28,7 @@ <%= text_area_tag("guidance-text", @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'))%> + <%= 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'))%>
    @@ -38,109 +38,69 @@ - + - - - - + + + + - - +
    <%= t('org_admin.guidance.text_label') %>
    <% if !@guidance.question_id.nil? then %> <% select_op = 2 %> - <% else%> + <% else %> <% select_op = 1%> - <%end%> - <%= hidden_field 'select_op' , :value => select_op, :id => 'edit_guid_ques_flag' %> - - <%= select_tag "g_options", options_for_select({t('org_admin.guidance.by_themes_label') => 1, + <% end %> + <%= hidden_field 'select_op', value: select_op, id: 'edit_guid_ques_flag' %> + + <%= select_tag "g_options", options_for_select({t('org_admin.guidance.by_themes_label') => 1, t('org_admin.guidance.by_question_label') => 2}, select_op) %>
    - <%= 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'))%> + <%= 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.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 => 'None'}, {:multiple => false})%> +
    +
    + <%= f.collection_select(:guidance_group_id, @guidance_groups, + :id, :name, {prompt: false, include_blank: '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'))%> + <%= 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' %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %>
    - +
    - <%= tinymce :content_css => asset_path('application.css') %> + <%= tinymce content_css: asset_path('application.css') %> <%end%>
    -
    + diff --git a/app/views/guidances/admin_index.html.erb b/app/views/guidances/admin_index.html.erb index 76acaf2..a660213 100644 --- a/app/views/guidances/admin_index.html.erb +++ b/app/views/guidances/admin_index.html.erb @@ -11,84 +11,62 @@
    - <%= link_to t("org_admin.guidance_group.add_guidance_group"), admin_new_guidance_group_path(), :class => "btn btn-primary" %> + <%= link_to t("org_admin.guidance_group.add_guidance_group"), admin_new_guidance_group_path(), class: "btn btn-primary" %>
    - + -<% if @guidance_groups.count > 0 then%> +<% if @guidance_groups.length > 0 then%> - - - - - - + + + + + <% !@guidance_groups.each do |guidance_gr| %> - - <% guidance_group_temp = guidance_gr.dmptemplate_ids %> - <% if guidance_group_temp != [] then %> - - <%else%> - - <%end%> - - - - - - - - <%end%> + + + + + + + + <% end %>
    <%= t("org_admin.guidance_group.name_label") %><%= t("org_admin.guidance.template") %><%= t("org_admin.guidance.published") %><%= t("org_admin.guidance_group.subset") %><%= t("org_admin.guidance.last_updated") %><%= t("org_admin.guidance.actions") %><%= t("org_admin.guidance_group.name_label") %><%= t("org_admin.guidance.published") %><%= t("org_admin.guidance_group.subset") %><%= t("org_admin.guidance.last_updated") %><%= t("org_admin.guidance.actions") %>
    - <%= guidance_gr.name %> - - <% i = 1 %> - <% guidance_group_temp.each do |t| %> - <% temp = Dmptemplate.find(t) %> - <%= temp.title %> - - <% if guidance_group_temp.count > i then%> - , - <% i +=1 %> - <% end %> - <%end%> - - <%= t("org_admin.guidance_group.all_temp")%> - - <%if guidance_gr.published.nil? || guidance_gr.published == false then%> - <%= t("helpers.no_label")%> - <%else%> - <%= t("helpers.yes_label")%> - <%end%> - - <%if guidance_gr.optional_subset.nil? || guidance_gr.optional_subset == false then%> - <%= t("helpers.no_label")%> - <%else%> - <%= t("helpers.yes_label")%> - <%end%> - - <%= l guidance_gr.updated_at.to_date, :formats => :short %> - - <%= link_to t("helpers.view"), admin_show_guidance_group_path(guidance_gr), :class => "dmp_table_link"%>
    - <%= link_to t("helpers.submit.edit"), admin_edit_guidance_group_path(guidance_gr), :class => "dmp_table_link"%>
    - <%= link_to t("helpers.submit.delete"), admin_destroy_guidance_group_path(guidance_gr), - :data => {:confirm => t("org_admin.guidance_group.delete_message", :guidance_group_name => guidance_gr.name )}, :method => :delete, :class => "dmp_table_link"%> -
    + <%= guidance_gr.name %> + + <% if guidance_gr.published.nil? || guidance_gr.published == false then%> + <%= t("helpers.no_label")%> + <% else %> + <%= t("helpers.yes_label")%> + <% end %> + + <% if guidance_gr.optional_subset.nil? || guidance_gr.optional_subset == false then%> + <%= t("helpers.no_label")%> + <% else %> + <%= t("helpers.yes_label")%> + <% end %> + + <%= l guidance_gr.updated_at.to_date, formats: :short %> + + <%= link_to t("helpers.view"), admin_show_guidance_group_path(guidance_gr), class: "dmp_table_link"%>
    + <%= link_to t("helpers.submit.edit"), admin_edit_guidance_group_path(guidance_gr), class: "dmp_table_link"%>
    + <%= link_to t("helpers.submit.delete"), admin_destroy_guidance_group_path(guidance_gr), data: {confirm: t("org_admin.guidance_group.delete_message", guidance_group_name: guidance_gr.name )}, method: :delete, class: "dmp_table_link"%> +
    -<%end%> +<%end%>

    - <%= t("org_admin.guidance.guidance_list") %> + <%= t("org_admin.guidance.guidance_list") %>

    @@ -99,14 +77,14 @@
    <%= link_to t("org_admin.guidance.add_guidance"), admin_new_guidance_path(), - :class => "btn btn-primary" %> + class: "btn btn-primary" %>
    -<% if @guidances.count > 0 then%> +<% if @guidances.length > 0 then%> @@ -120,55 +98,53 @@ <% @guidances.each do |guidance| %> - <% if guidance.in_group_belonging_to?(current_user.organisation_id) then %> + <% if guidance.in_group_belonging_to?(current_user.org_id) then %> - <% if guidance.themes != [] then %> + <% if guidance.themes.present? then %> - <%else%> + <% else %> - <%end%> + <% end %> <% if !guidance.question_id.nil? then %> - <%else%> + <% else %> - <%end%> - <% if guidance.guidance_groups != [] then %> - - <%else%> + <% end %> + <% if guidance.guidance_group.present? then %> + + <% else %> - <%end%> + - + + <% end %> - <%end%> - <%end%> + <% end %> + <% end %>
    <%= guidance.text.html_safe%> <% guidance.themes.each do |th| %> <%= th.title %> - <%end%> + <% end %> - <%= raw guidance.question.text.truncate(70, omission: t('helpers.truncate_continued')) %> - - <% guidance.guidance_groups.each do |p|%> - <%= p.name %> - <%end%> - + <%= guidance.guidance_group.name %> + - - - - <%= l guidance.updated_at.to_date, :formats => :short %> + <%= l guidance.updated_at.to_date, formats: :short %> - <%= link_to t("helpers.view"), admin_show_guidance_path(guidance), :class => "dmp_table_link"%>
    - <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(guidance), :class => "dmp_table_link"%>
    + <%= link_to t("helpers.view"), admin_show_guidance_path(guidance), class: "dmp_table_link"%>
    + <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(guidance), class: "dmp_table_link"%>
    <%= link_to t("helpers.submit.delete"), admin_destroy_guidance_path(guidance), - :data => {:confirm => t("org_admin.guidance.delete_message_html", :guidance_summary => truncate(sanitize(guidance.text,:tags => %w(br a)), :length => 20 , :omission => t('helpers.truncate_continued')) )}, :method => :delete, :class => "dmp_table_link"%> + data: {confirm: t("org_admin.guidance.delete_message_html", guidance_summary: truncate(sanitize(guidance.text,tags: %w(br a)), length: 20 , omission: t('helpers.truncate_continued')) )}, method: :delete, class: "dmp_table_link"%>
    -<%end%> +<% end %> diff --git a/app/views/guidances/admin_new.html.erb b/app/views/guidances/admin_new.html.erb index bf37fe1..43e620c 100644 --- a/app/views/guidances/admin_new.html.erb +++ b/app/views/guidances/admin_new.html.erb @@ -7,15 +7,15 @@
    <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => 'btn btn-primary' %> -
    + class: 'btn btn-primary' %> +
    - <%= form_for :guidance, :url => {:action => 'admin_create'}, :html => {:id => 'new_guidance_form'} do |f| %> + <%= form_for :guidance, url: {action: 'admin_create'}, html: {id: 'new_guidance_form'} do |f| %> @@ -23,7 +23,7 @@ <%= 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'))%> + <%= 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'))%>
    @@ -31,86 +31,82 @@ - +
    <%= t('org_admin.guidance.text_label') %>
    <%= t('org_admin.guidance.by_theme_or_by_question') %>
    - <%= select_tag "g_options", options_for_select([[t('org_admin.guidance.by_themes_label'), 1], + <%= 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'))%> + <%= 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%> + <%= f.check_box :published , as: :check_boxes%>
    - <%= link_to( image_tag('help_button.png'), '#', :class => 'guidance_group_subset_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_published_help_text_html'))%> + <%= link_to( image_tag('help_button.png'), '#', class: 'guidance_group_subset_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.guidance.guidance_group_published_help_text_html'))%>
    <%= 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 => 'None'}, {:multiple => false})%> + <%= f.collection_select(:guidance_group_id, @guidance_groups, + :id, :name, {prompt: false, include_blank: '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'))%> + <%= 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' %> + + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %>
    - +
    - <%= tinymce :content_css => asset_path('application.css') %> + <%= tinymce content_css: asset_path('application.css') %> <%end%>
    -
    + diff --git a/app/views/guidances/admin_show.html.erb b/app/views/guidances/admin_show.html.erb index a8f8d6e..14356f8 100644 --- a/app/views/guidances/admin_show.html.erb +++ b/app/views/guidances/admin_show.html.erb @@ -7,11 +7,11 @@
    <%= link_to t("org_admin.guidance.add_guidance"), admin_new_guidance_path, - :class => "btn btn-primary" %> + class: "btn btn-primary" %> <%= link_to t("org_admin.guidance.view_all_guidance"), admin_index_guidance_path, - :class => "btn btn-primary" %> -
    + class: "btn btn-primary" %> +
    @@ -19,7 +19,7 @@
    - + @@ -30,46 +30,45 @@ - <%end%> + <% end %> <% if !@guidance.question_id.nil? %> - <%end%> + <% end %> - - + - + - +
    <%= t("org_admin.guidance.text_label") %><%= t("org_admin.guidance.themes_label") %> <% @guidance.themes.each do |th|%> <%= th.title %> - <%end%> + <% end %>
    <%= t("org_admin.guidance.question_label") %> <%= raw @guidance.question.text %>
    <%= t("org_admin.guidance.guidance_group_label") %><% @guidance.guidance_groups.each do |p|%> - <%= p.name %> - <%end%> + + <%= @guidance.guidance_group.name %>
    <%= t("org_admin.guidance.published") %> <%if @guidance.published == false || @guidance.published.nil? then%> <%= t("helpers.no_label")%> - <%else%> - <%= t("helpers.yes_label")%> - <%end%> + <% else %> + <%= t("helpers.yes_label")%> + <% end %>
    <%= t("org_admin.guidance.created") %><%= l @guidance.created_at.to_date, :formats => :short %><%= l @guidance.created_at.to_date, formats: :short %>
    <%= t("org_admin.guidance.last_updated") %><%= l @guidance.updated_at.to_date, :formats => :short %><%= l @guidance.updated_at.to_date, formats: :short %>
    - <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(@guidance.id), :class => "btn btn-primary"%> - <%= link_to t("helpers.submit.back"), :back, :class => "btn cancel" %> + <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(@guidance.id), class: "btn btn-primary"%> + <%= link_to t("helpers.submit.back"), :back, class: "btn cancel" %>

    -
    \ No newline at end of file + \ No newline at end of file diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 4c03d50..40441b0 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -2,13 +2,10 @@
    -

    <%= raw t('welcome_title')%>

    - <%= raw t('welcome_text', - application_name: Rails.configuration.branding[:application][:name], - organisation_name: Rails.configuration.branding[:organisation][:name])%> - +

    <%= _('Welcome.')%>

    + <%= raw _('

    %{application_name} has been jointly developed by the %{organisation_name} to help you write data management plans.

    ') % {:application_name => Rails.configuration.branding[:application][:name], :organisation_name => Rails.configuration.branding[:organisation][:name]} %>
    -

    <%= t('screencast_text', application_name: Rails.configuration.branding[:application][:name]) %>

    +

    <%= _('Screencast on how to use %{application_name}') % {:application_name => Rails.configuration.branding[:application][:name]} %>

    @@ -30,7 +27,7 @@
    - <%= t('helpers.sign_in')%> + <%= _('Sign in')%>
    @@ -41,9 +38,9 @@
    - <%= t('helpers.sign_up') %> + <%= _('Sign up') %>

    - <%= t('helpers.sign_up_text', application_name: Rails.configuration.branding[:application][:name])%> + <%= _('New to %{application_name}? Sign up today.') % {:application_name => Rails.configuration.branding[:application][:name]} %>

    diff --git a/app/views/layouts/_branding.html.erb b/app/views/layouts/_branding.html.erb index 7c436ff..4774bee 100644 --- a/app/views/layouts/_branding.html.erb +++ b/app/views/layouts/_branding.html.erb @@ -1,19 +1,19 @@
    <% if user_signed_in? %> - <% if !current_user.organisation.nil? %> + <% if !current_user.org.nil? %> - <% if current_user.organisation.logo.present? %> + <% if current_user.org.logo.present? %> <% end %> - <% if current_user.organisation.banner_text.present? %> + <% if current_user.org.banner_text.present? %>
    - <%= raw current_user.organisation.banner_text %> + <%= raw current_user.org.banner_text %>
    <%end%> diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index f8728e7..897d824 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -3,9 +3,9 @@
  • + <% end %> + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c598adc..e8a3467 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,7 @@ - <%= t('tool_title', application_name: Rails.configuration.branding[:application][:name])%> + <%= _('%{application_name}') % { :application_name => Rails.configuration.branding[:application][:name] } %> <%= favicon_link_tag "favicon.ico" %> - - <% end %> - - <% end %> - <% end %> - - <%= submit_tag "Update API Privleges" %> - <% end %> - diff --git a/app/views/organisations/admin_edit.html.erb b/app/views/organisations/admin_edit.html.erb deleted file mode 100644 index 9a2548c..0000000 --- a/app/views/organisations/admin_edit.html.erb +++ /dev/null @@ -1,85 +0,0 @@ -<%= stylesheet_link_tag "admin" %> -<% javascript 'admin.js' %> - -

    - <%= t('org_admin.org_details_label') %> -

    - -
    - -
    - <%= form_for(@organisation, :url => admin_update_organisation_path(@organisation), :html => { :multipart => true, :id => "edit_org_details", :method => :put}) do |f| %> - - - - - - - - - - - - - - - <% if @organisation.logo.present? %> - - - - - - - - - <%end%> - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    <%= t('org_admin.org_name') %><%= f.text_field :name, :as => :string, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.name_help_text') %>
    <%= t('org_admin.org_abbr') %> -
    - <%= f.text_field :abbreviation, :as => :string, :class => 'text_field' %> -
    -
    -
    <%= t('org_admin.org_logo') %><%= image_tag @organisation.logo.url %>
    <%= f.check_box :remove_logo %>   <%= t('org_admin.remove_logo') %>
    <%= t('org_admin.new_org_logo') %><%= f.file_field :logo %>
    <%= t('org_admin.org_banner_text') %><%= text_area_tag("org_banner_text", @organisation.banner_text, class: "tinymce") %>
    <%= t('org_admin.org_target_url') %><%= f.text_field :target_url, :as => :string, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.target_url_help_text') %>
    <%= t('org_admin.org_contact_email') %><%= f.text_field :contact_email, :as => :string, :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.org_contact_email_help_text') %>
    <%= t('org_admin.org_type') %> - <%= @organisation.organisation_type.name %> -
    - -
    - - -
    - <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn btn-primary' %> -
    - <% end %> - -
    -
    - -<%= tinymce :content_css => asset_path('application.css') %> - diff --git a/app/views/organisations/admin_show.html.erb b/app/views/organisations/admin_show.html.erb deleted file mode 100644 index f853368..0000000 --- a/app/views/organisations/admin_show.html.erb +++ /dev/null @@ -1,78 +0,0 @@ -<%= stylesheet_link_tag "admin" %> - -

    - <%= t('org_admin.org_details_label') %> -

    -<%= t('org_admin.org_text')%> -
    -
    - -
    - -
    - - - - <% if @organisation.name.present? then%> - - - - - <% if @organisation.logo.present? then%> - - <%end%> - - <%end%> - <% if @organisation.abbreviation.present? then%> - - - - - <%end%> - <% if @organisation.banner_text.present? then%> - - - - - <%end%> - <% if @organisation.target_url.present? then%> - - - - - <%end%> - <% if @organisation.contact_email.present? then%> - - - - - <%end%> - <% if @organisation.organisation_type_id.present? then%> - - - - - <%end%> - <% if @organisation.parent_id.present? then%> - - - - - <%end%> - - - - -
    <%= t('org_admin.org_name') %><%= @organisation.name %>
    <%= t('org_admin.org_abbr') %><%= @organisation.abbreviation %>
    <%= t('org_admin.org_banner_text') %><%= raw @organisation.banner_text %>
    <%= t('org_admin.org_target_url') %><%= @organisation.target_url %>
    <%= t('org_admin.org_contact_email') %><%= @organisation.contact_email %>
    <%= t('org_admin.org_type') %><%= @organisation.organisation_type.name %>
    <%= t('org_admin.parent_org') %><%= @organisation.parent.name %>
    <%= t('org_admin.last_updated') %><%= l @organisation.updated_at.to_date, :formats => :short %>
    - -
    -
    - -
    - <%= link_to t("helpers.submit.edit"), admin_edit_organisation_path(current_user.organisation), :class => 'btn btn-primary'%> -
    -
    -
    -
    \ No newline at end of file diff --git a/app/views/orgs/admin_edit.html.erb b/app/views/orgs/admin_edit.html.erb new file mode 100644 index 0000000..67030c7 --- /dev/null +++ b/app/views/orgs/admin_edit.html.erb @@ -0,0 +1,83 @@ +<%= stylesheet_link_tag "admin" %> +<% javascript 'admin.js' %> + +

    + <%= t('org_admin.org_details_label') %> +

    + +
    + +
    + <%= form_for(@org, url: admin_update_org_path(@org), html: { multipart: true, id: "edit_org_details", method: :put}) do |f| %> + + + + + + + + + + + + + + + <% if @org.logo.present? %> + + + + + + + + + <%end%> + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= t('org_admin.org_name') %><%= f.text_field :name, as: :string, class: 'text_field has-tooltip', data_toggle: "tooltip", title: t('org_admin.name_help_text') %>
    <%= t('org_admin.org_abbr') %> +
    + <%= f.text_field :abbreviation, as: :string, class: 'text_field' %> +
    +
    +
    <%= t('org_admin.org_logo') %><%= image_tag @org.logo.url %>
    <%= f.check_box :remove_logo %>   <%= t('org_admin.remove_logo') %>
    <%= t('org_admin.new_org_logo') %><%= f.file_field :logo %>
    <%= t('org_admin.org_banner_text') %><%= text_area_tag("org_banner_text", @org.banner_text, class: "tinymce") %>
    <%= t('org_admin.org_target_url') %><%= f.text_field :target_url, as: :string, class: 'text_field has-tooltip', data_toggle: "tooltip", title: t('org_admin.target_url_help_text') %>
    <%= t('org_admin.org_contact_email') %><%= f.text_field :contact_email, as: :string, class: 'text_field has-tooltip', data_toggle: "tooltip", title: t('org_admin.org_contact_email_help_text') %>
    <%= t('org_admin.org_type') %><%= @org.organisation_type %>
    + +
    + + +
    + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn btn-primary' %> +
    + <% end %> + +
    +
    + +<%= tinymce content_css: asset_path('application.css') %> + diff --git a/app/views/orgs/admin_show.html.erb b/app/views/orgs/admin_show.html.erb new file mode 100644 index 0000000..55ed7b1 --- /dev/null +++ b/app/views/orgs/admin_show.html.erb @@ -0,0 +1,82 @@ +<%= stylesheet_link_tag "admin" %> + +

    + <%= t('org_admin.org_details_label') %> +

    +<%= t('org_admin.org_text')%> +
    +
    +
    + +
    + + + + <% if @org.name.present? then %> + + + + + <% if @org.logo.present? then %> + + <% end %> + + <% end %> + + <% if @org.abbreviation.present? then %> + + + + + <% end %> + + <% if @org.banner_text.present? then %> + + + + + <% end %> + + <% if @org.target_url.present? then %> + + + + + <% end %> + + <% if @org.contact_email.present? then %> + + + + + <% end %> + + <% if @org.org_type != 0 then %> + + + + + <% end %> + + <% if @org.parent_id.present? then %> + + + + + <% end %> + + + + + +
    <%= t('org_admin.org_name') %><%= @org.name %>
    <%= t('org_admin.org_abbr') %><%= @org.abbreviation %>
    <%= t('org_admin.org_banner_text') %><%= raw @org.banner_text %>
    <%= t('org_admin.org_target_url') %><%= @org.target_url %>
    <%= t('org_admin.org_contact_email') %><%= @org.contact_email %>
    <%= t('org_admin.org_type') %><%= @org.organisation_type %>
    <%= t('org_admin.parent_org') %><%= @org.parent.name %>
    <%= t('org_admin.last_updated') %><%= l @org.updated_at.to_date, formats: :short %>
    + +
    +
    + +
    + <%= link_to t("helpers.submit.edit"), admin_edit_org_path(current_user.org), class: 'btn btn-primary'%> +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/phases/_add_note.html.erb b/app/views/phases/_add_note.html.erb new file mode 100644 index 0000000..41d72f5 --- /dev/null +++ b/app/views/phases/_add_note.html.erb @@ -0,0 +1,28 @@ + + + +<% new_note = Note.new + if !answer.nil? + answerid = answer["id"] + else + answerid = answer_obj.id + end +%> + +<%= form_for :new_note, + :url => {:controller => :notes, :action => :create }, + :html=>{:method=>:post, :id => "new_note_form_#{answerid}", :class => "add_note_form"} do |f| %> + <%= f.hidden_field :user_id, :value => current_user.id %> + <%= f.hidden_field :answer_id, :value => answerid %> + <%= f.hidden_field :question_id, :value => question["id"] %> + <%= f.hidden_field :plan_id, :value => plan_data["id"] %> + + <%= text_area_tag("#{answerid}new_note_text".to_sym, "" , class: "tinymce") %> +
    + + +
    + <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary new_comment_submit_button" %> +
    +
    +<%end%> diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb new file mode 100644 index 0000000..74ae43a --- /dev/null +++ b/app/views/phases/_answer_form.html.erb @@ -0,0 +1,223 @@ + + +
    + + <% + q_format = question["question_format"] + answer = nil + answer_obj = nil + if question.has_key?("answers") + answer = question["answers"].first + answer_obj = Answer.find(answer["id"]) + else + answer_obj = Answer.new + end + question_obj = Question.find(question["id"]) + %> + +
    " class="question-form"> + <%= semantic_form_for answer_obj, :url => {:controller => :answers, :action => :update }, :html=>{:method=>:put}, :remote => true do |f| %> + <%= f.inputs do %> + <%= f.input :plan_id, :as => :hidden, :input_html => { :value => @plan_data["id"] } %> + <%= f.input :user_id, :as => :hidden, :input_html => { :value => current_user.id } %> + <%= f.input :question_id, :as => :hidden, :input_html => { :value => question["id"], :class => "question_id" } %> + + + + <%= raw question["text"] %> + + + <% if question.has_key?("suggested_answer") && question["suggested_answer"]["text"].present? %> + <% suggested_answer = question["suggested_answer"] %> +
    + + <% 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 [ @checkbox, @multi, @radio, @dropdown ].include?( q_format["id"] ) %> + <% options = question.options.order("number") %> + + + <% if q_format.id == @checkbox %> + <%= f.input :options, :as => :check_boxes, :collection => options, :label => false, :input_html => { :id => "options-#{question.id}" } %> + <% elsif q_format.id == @multi %> + <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => true , :id => "options-#{question.id}" } %> + <% elsif q_format.id == @radio %> +
      + <% options.each do |op| %> +
    1. + <% if answer.option_ids[0] == op.id then%> + <%= f.radio_button :option_ids, op.id, :checked => true, id: "answer_option_ids_#{op.id}"%> + <%else%> + <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> + <% end %> + <%= raw op.text %>
    2. + <% end %> +
    + <% elsif q_format.id == @dropdown %> + <%= f.input :options, :as => :select, :collection => options, :label => false, :input_html => { :multiple => false, :id => "options-#{question.id}" } %> + <% end %> + + + + <% if question.option_comment_display == true %> + <%= 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%> + <% end %> + + <% if q_format["id"] == @textfield %> + <%= text_field_tag("answer-text-#{question.id}".to_sym, strip_tags(answer.text), class: "question_text_field") %> + <% elsif q_format["id"] == @textarea %> + <%= text_area_tag("answer-text-#{question["id"]}".to_sym, answer_obj.text, class: "tinymce") %> + <% end %> + + <% end %> + + + <%= f.actions do %> + <%= f.action :submit, :label => t("helpers.save"), :button_html => { :class => "btn btn-primary"} %> +
  • " class="saving-message" style="display:none;"><%= t("helpers.saving")%>
  • + <% end %> + <% end %> +
    + + <% if answer.nil? || !answer.has_key?("created_at") || answer["created_at"].nil? %> + -status" class="label label-warning answer-status"><%= t("helpers.notanswered") %> + <% else %> + -status" class="label label-info answer-status"><%= t("helpers.answered_by")%><%= answer_obj.created_at %><%= t("helpers.answered_by_part2")%><%= answer_obj.user.name %> + <% end %> +
    + +-unsaved" class="label label-inverse answer-unsaved" style="display:none;"><%= t("helpers.unsaved") %> + + +
    + +
    " class="question_right_column_nav"> + <% comments = answer_obj.notes.all %> + <%= hidden_field_tag :question_id, question["id"], :class => "question_id" %> +
      + <% if (!question["guidance"].nil? && question["guidance"] != "") || question.has_key?("theme_guidance") 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%> +
    +
    + + + +
    " style="<%= css_style_guidance_div%>" > +
    -guidance"> + + + <% if question["guidance"].present? %> +
    + + + + + +
    " class="guidance-accordion-body collapse"> +
    <%= raw question["guidance"] %>
    +
    + +
    + <% end %> + + + + <% gnum = 0 %> + <% if question.has_key?("theme_guidance") %> + <% question["theme_guidance"].each_key do |theme| %> + <% question["theme_guidance"][theme].each do |guidance| %> + <% + orgname = guidance["org"] + gnum = gnum + 1 + text = guidance["text"] + %> + +
    + + + + + +
    " class="guidance-accordion-body collapse"> +
    <%= raw text %>
    +
    +
    + <% end %> + <% end %> + <% end %> + +
    +
    + + +
    " style="<%= css_style_comment_div%>"> + <%= render :partial => "note", locals: {question: question, answer_obj: answer_obj, answer: answer, plan: plan, plan_data: plan_data}%> +
    + +
    + + +<% if last_question_id == question["id"] then %> +
    +<% else %> +
    +<% end %> diff --git a/app/views/phases/_answer_form_ro.html.erb b/app/views/phases/_answer_form_ro.html.erb new file mode 100644 index 0000000..64a0fb0 --- /dev/null +++ b/app/views/phases/_answer_form_ro.html.erb @@ -0,0 +1,248 @@ + +<% 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.where(org_id: @plan.template.org_id).first %> + <% if suggested_answer.present? %> +
    + + <% 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 == 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 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 == t("helpers.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 == t("helpers.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 == t("helpers.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 == t("helpers.text_field") then %> + <%= text_field_tag("answer-text-#{question.id}".to_sym, strip_tags(answer.text), class: "question_text_field") %> + + <% elsif q_format.title == t("helpers.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 %> + <%= f.action :submit, :label => t("helpers.save"), :button_html => { :class => "btn btn-primary"} %> + <% end %> + + <% end %> + <% end %> +
    + <% end %> + +
    > +

    <%= question.text %>

    +
    + <% 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 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 = Notes.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%> +
    +
    + + + +
    +
    + + <% if !question.guidance.nil? && question.guidance != "" then %> + + <% end %> + + <% @question_guidances.each_pair do |group,themes| %> + <% themes.each_pair do |theme,guidances| %> + <% guidances.each do |guidance| %> + + <% end %> + <% end %> + <% end %> +
    +
    + + +
    + <%= render :partial => "comments", locals: {questionId: question.id, plan_id: answer.plan_id }%> +
    + + + +
    + +<% if last_question_id == question.id then %> +
    +<% else %> +
    +<% end %> diff --git a/app/views/phases/_archive_note.html.erb b/app/views/phases/_archive_note.html.erb new file mode 100644 index 0000000..daee904 --- /dev/null +++ b/app/views/phases/_archive_note.html.erb @@ -0,0 +1,23 @@ + +<%= form_for(Note.new, :url => {:controller => :notes, :action => :archive } , :html => { :method => :put, :class => "archive_note_form", :id => "archive_note_form_#{note["id"]}"}) do |f| %> + <%= f.hidden_field :id, :value => note["id"] %> + <%= f.hidden_field :archived_by, :value => current_user.id %> + + <%= render :partial => "view_note", locals: {note: note} %> + + <% if current_user.id == note["user_id"] then %> + <%= t('helpers.notes.archive_own_note_question')%> + <% button_label = t("helpers.notes.archive_own_comment_button_label") %> + <% else%> + <%= t("helpers.notes.archive_note_question")%> + <% button_label = t("helpers.notes.archive_comment_button_label") %> + <%end%> + + +
    + <%= hidden_field_tag :note_id, note["id"], :class => "comment_id" %> + <%= f.submit button_label, :class => "btn btn-primary archive_comment_submit_button" %> + <%= link_to t("helpers.submit.cancel"), "#", :class => "cancel_archive_comment btn cancel" %> +
    +
    +<%end%> diff --git a/app/views/phases/_edit_note.html.erb b/app/views/phases/_edit_note.html.erb new file mode 100644 index 0000000..366945f --- /dev/null +++ b/app/views/phases/_edit_note.html.erb @@ -0,0 +1,16 @@ + + +<%= form_for(Note.new, :url => {:controller => :notes, :action => :update } , :html => { :method => :put, :class => "edit_note_form", :id=> "edit_note_form_#{note["id"]}"}) do |f| %> + <%= f.hidden_field :id, :value => note["id"] %> + + <%= text_area_tag("#{note["id"]}_note_text".to_sym, note["text"] , class: "tinymce") %> +
    + + +
    + <%= hidden_field_tag :answer, note["answer_id"], :class => "answer_id" %> + <%= hidden_field_tag :note_id, note["id"], :class => "note_id" %> + <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary edit_note_submit_button" %> +
    +
    +<%end%> diff --git a/app/views/phases/_list_notes.html.erb b/app/views/phases/_list_notes.html.erb new file mode 100644 index 0000000..7d6315a --- /dev/null +++ b/app/views/phases/_list_notes.html.erb @@ -0,0 +1,91 @@ + + +<% if notes.count > 1 then%> + <% style_to_add = "height:150px; overflow-y:auto;" %> +<%else%> + <% style_to_add = "" %> +<%end%> + + +<% notes.sort! {|x,y| y["updated_at"] <=> x["updated_at"] } %> + +
    + +
    + + + <% notes.each do |c|%> + + + + + <%end%> + +
    + <% user = c["user"] %> + <% user = User.find(c["user_id"]) %> + <%= user["name"] %>
    + (<%= l c["updated_at"], format: :custom %>) +
    + + <% if c["archived"] %> + + <% if c["archived_by"] == current_user.id %> + <%= t("helpers.comments.retracted")%> + <% else %> + <% archived_by_user = User.find(c["archived_by"]) %> + <%= t("helpers.comments.clear_by")%> <%= archived_by_user.name %> + <%end%> + + <%else%> + + <%= link_to t("helpers.comments.view_label"),"#", :class => "dmp_table_link view_comment_button" %> + <%= hidden_field_tag :note_id, c["id"], :class => "comment_id" %> + + <% if current_user.id == c["user_id"] %> + <%= link_to t("helpers.comments.edit_label"),"#", :class => "dmp_table_link edit_comment_button" %> + <%= hidden_field_tag :note_id, c["id"], :class => "comment_id" %> + <%= link_to t("helpers.comments.retract_label"),"#", :class => "dmp_table_link archive_comment_button" %> + <% end%> + + <% if plan.administerable_by?(current_user.id) && current_user.id != c["user_id"] %> + <%= hidden_field_tag :note_id, c["id"], :class => "comment_id" %> + <%= link_to t("helpers.comments.clear_label"),"#", :class => "dmp_table_link archive_comment_button" %> + <% end%> + <%end%> + +
    +
    + +
    + + +<% notes_not_archived = notes.select { |n| n["archived"].nil? } %> +<% latest_note = notes_not_archived.sort { |x,y| y["updated_at"] <=> x["updated_at"] }.first %> +<% if !latest_note.nil? then%> +
    " class ="view_comment_class"> + <%= render :partial => "view_note", locals: {note: latest_note} %> +
    +
    +<%end%> + +<%notes.each do |com|%> + +
    " class ="view_comment_class" style="display: none"> + <%= render :partial => "view_note", locals: {note: com} %> +
    +
    + + +
    " class ="edit_comment_class" style="display: none"> + <%= render :partial => "edit_note", locals: {note: com} %> +
    +
    + + +
    " class ="archive_comment_class" style="display: none"> + <%= render :partial => "archive_note", locals: {note: com} %> +
    +
    + +<%end%> diff --git a/app/views/phases/_note.html.erb b/app/views/phases/_note.html.erb new file mode 100644 index 0000000..659738a --- /dev/null +++ b/app/views/phases/_note.html.erb @@ -0,0 +1,36 @@ + + + <% if answer.present? && answer.has_key?("notes") %> + <% notes = answer["notes"] %> + <% answerid = answer["id"] %> + <%= hidden_field_tag :answer_id, answer["id"] %> + + +
    + <%= link_to t("helpers.comments.add_comment_label"),'#', :class => "btn btn-primary add_comment_button" %> +
    + +
    + + + <%= render :partial => "list_notes", locals: {question: question, notes: notes, plan:plan} %> + +
    + + +
    + <%= link_to t("helpers.comments.add_comment_label"),'#', :class => "btn btn-primary add_comment_button" %> +
    + +
    + + + + + <% else%> + <%= t("helpers.comments.add_comment_text")%> + <%= render :partial => "add_note", locals: {answer: answer, answer_obj: answer_obj, question: question, plan_data: plan_data}%> + <% end%> diff --git a/app/views/phases/_view_note.html.erb b/app/views/phases/_view_note.html.erb new file mode 100644 index 0000000..2a1d14a --- /dev/null +++ b/app/views/phases/_view_note.html.erb @@ -0,0 +1,11 @@ + +<% user = User.find(note["user_id"]) %> +
    +
    +
    +
      +
    • <%= t("helpers.comments.commented_by")%>

    • +
    • <%= user.name%> (<%= l note["updated_at"], format: :custom %>)
    • +
    • <%= raw note["text"] %>
    • +
    +
    diff --git a/app/views/phases/edit.html.erb b/app/views/phases/edit.html.erb new file mode 100644 index 0000000..9b98568 --- /dev/null +++ b/app/views/phases/edit.html.erb @@ -0,0 +1,168 @@ +<%- model_class = Plan -%> +<% javascript "plans.js" %> + + + + + +<%= render :partial => "/plans/plan_title", locals: {plan: @plan, plan_data: @plan_data} %> + + + +<% status = @plan.status %> +
    + <%space_used = status["space_used"].to_i + space_title = t("helpers.plan.export.space_used", space_used: space_used, num_pages: @plan.template.settings(:export).max_pages) + answered = %(#{status["num_answers"]}/#{status["num_questions"]})%> +
    + <%= answered -%> <%= t("helpers.project.questions_answered")%> + ;" title="<%= answered -%> <%= t("helpers.project.questions_answered")%>"> +
    + +
    + +
    + = 100 ? "class=bar-full-text" : "" -%>><%= space_title -%> + " style="width: <%= space_used -%>%;" title="<%= space_title -%>"> +
    +
    + + + +<%= render :partial => "/plans/plan_nav_tabs", locals: {plan: @plan, plan_data: @plan_data, active: @phase.title } %> + + + +
    + +
    + <% @phase_data["sections"].each do |section| %> + + <% sectionid = section["id"] %> + + + <% if session[:question_id_comments].to_i != 0 then %> + <% question_from_comment = Question.find(session[:question_id_comments])%> + <% if sectionid == question_from_comment.section_id then %> + <%= hidden_field_tag :comment_section_id, question_from_comment.section_id, :class => "comment_section_id" %> + <%end%> + <% end%> + + + +
    + + + <% num_section_questions = section["questions"].count %> + <% num_section_answers = section["nanswers"] %> + <% question_word = "questions" %> + <% if num_section_questions == 1 then %> + <% question_word = "question" %> + <% end %> + <% section_status = "#{num_section_questions} #{question_word}, #{num_section_answers} answered" %> + + + + + +
    +
    + <%= raw section["description"] %> +
    + +
    + + + + + + + +
    + <% section["questions"].each do |question| %> + <% if question["id"] == session[:question_id_comments].to_i then id_css = "current_question" end %> +
    + <% partialname = "answer_form" + if @readonly + partialname += "_ro" + end + %> + + <% guidances = question["guidances"] %> + + <%= render partial: partialname, + locals: { + plan: @plan, + plan_data: @plan_data, + question: question, + last_question_id: section["questions"].last["id"] + } + %> +
    + <% end %> +
    +
    +
    +
    + + + + + <% end %> +
    + + <%= tinymce :content_css => asset_path("application.css"), :setup => "function(editor){editor.on('change', function(e){$.fn.check_textarea(editor)});}" %> +
    + + +<%= render :partial => "plans/export", locals: {plan: @plan, plan_data: @plan_data} %> + + +<% session.delete(:question_id_comments)%> diff --git a/app/views/plans/_add_comment.html.erb b/app/views/plans/_add_comment.html.erb deleted file mode 100644 index 0d8aa49..0000000 --- a/app/views/plans/_add_comment.html.erb +++ /dev/null @@ -1,20 +0,0 @@ - - -<% @new_comment = Comment.new %> - -<%= form_for :new_comment, :url => {:controller => :comments, :action => :create } , :html=>{:method=>:post, :id => "new_comment_form_#{questionId}", :class => "add_comment_form"} do |f| %> - <%= f.hidden_field :user_id, :value => current_user.id %> - <%= f.hidden_field :question_id, :value => questionId %> - <%= f.hidden_field :plan_id, :value => planId %> - - <%= text_area_tag("#{questionId}new_comment_text".to_sym, "" , class: "tinymce") %> -
    - <% question = Question.find(questionId)%> - -
    - <%= hidden_field_tag :section_id, question.section_id, :class => "section_id" %> - <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary new_comment_submit_button" %> -
    -
    -<%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 index 5f262ba..dd256e4 100644 --- a/app/views/plans/_answer_form.html.erb +++ b/app/views/plans/_answer_form.html.erb @@ -1,7 +1,7 @@ <% answer = @plan.answer(question.id) %> @@ -17,16 +17,16 @@ <%= 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 %> @@ -45,26 +45,29 @@ <% end %> - + - <% 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 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 == t("helpers.checkbox") then %> + <% 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 == t("helpers.multi_select_box") then %> + <% 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 == t("helpers.radio_buttons") then%> + <% elsif q_format.title == "Radio buttons" then%>
      <% options.each do |op| %>
    1. @@ -80,38 +83,29 @@ <% else %> <%= f.radio_button :option_ids, op.id, :checked => false, id: "answer_option_ids_#{op.id}"%> <% end %> - <%end%> + <% end %> <%= op.text %>
    2. - <%end%> + <% end %>
    - <% elsif q_format.title == t("helpers.dropdown") then%> + <% 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 == t("helpers.text_field") then %> + <% 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 == t("helpers.text_area") then%> + <% elsif q_format.title == "Text area" then%> <%= text_area_tag("answer-text-#{question.id}".to_sym, answer.text, class: "tinymce") %> <% end %> @@ -122,19 +116,22 @@ <% if readonly then %> <%= f.action :submit, :label => t("helpers.save"), :button_html => { :class => "btn btn-primary"}, :input_html => { :disabled => true } %> <% else %> - <%= f.action :submit, :label => t("helpers.save"), :button_html => { :class => "btn btn-primary"} %> + + <% end %> <% end %> <% end %> - <% end %> - - + <% end %> +
    >

    <%= question.text %>

    - <% 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 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 %>
    • @@ -150,20 +147,17 @@
    - <% 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" %> @@ -215,7 +209,7 @@ <%= t("helpers.policy_expectations")%> <%else%> <%= t("helpers.guidance")%> - <%end%> + <%end%>
    @@ -247,19 +241,16 @@ <% end %> <% end %> <% end %> - - - +
    <%= render :partial => "comments", locals: {questionId: question.id, plan_id: answer.plan_id }%> -
    - - + + <% if last_question_id == question.id then %> diff --git a/app/views/plans/_archive_comment.html.erb b/app/views/plans/_archive_comment.html.erb deleted file mode 100644 index 03ba05c..0000000 --- a/app/views/plans/_archive_comment.html.erb +++ /dev/null @@ -1,28 +0,0 @@ - - -<%= form_for(comment, :url => {:controller => :comments, :action => :archive } , :html => { :method => :put, :class => "archive_comment_form", :id => "archive_comment_form_#{comment.id}"}) do |f| %> - <%= f.hidden_field :id, :value => comment.id %> - <%= f.hidden_field :archived_by, :value => current_user.id %> - - <%= render :partial => "view_comment", locals: {comment: comment} %> - - <% if current_user.id == comment.user_id then %> - <%= t('helpers.comments.archive_own_comment_question')%> - <% button_label = t("helpers.comments.archive_own_comment_button_label") %> - <% else%> - <%= t("helpers.comments.archive_comment_question")%> - <% button_label = t("helpers.comments.archive_comment_button_label") %> - <%end%> - - -
    - <% question = Question.find(comment.question_id)%> - <%= hidden_field_tag :plan_id, comment.plan_id, :class => "plan_id" %> - <%= hidden_field_tag :comment_id, comment.id, :class => "comment_id" %> - <%= hidden_field_tag :section_id, question.section_id, :class => "section_id" %> - <%= f.submit button_label, :class => "btn btn-primary archive_comment_submit_button" %> - <%= hidden_field_tag :comment_id, comment.id, :class => "comment_id" %> - <%= link_to t("helpers.submit.cancel"), "#", :class => "cancel_archive_comment btn cancel" %> -
    -
    -<%end%> \ No newline at end of file diff --git a/app/views/plans/_comments.html.erb b/app/views/plans/_comments.html.erb deleted file mode 100644 index dc21608..0000000 --- a/app/views/plans/_comments.html.erb +++ /dev/null @@ -1,35 +0,0 @@ - - - - -<% @comments = Comment.where("question_id = ? AND plan_id = ?", questionId, plan_id) %> -<%= hidden_field_tag :question_id, questionId, :class => "question_id" %> - -<% if @comments.count > 0 then%> - -
    - <%= link_to t("helpers.comments.add_comment_label"),'#', :class => "btn btn-primary add_comment_button" %> - -
    -
    -
    - - <%= render :partial => "list_comments", locals: {comments: @comments}%> -
    -
    - -
    - <%= link_to t("helpers.comments.add_comment_label"),'#', :class => "btn btn-primary add_comment_button" %> -
    -
    -
    - - - -<% else%> - <%= t("helpers.comments.add_comment_text")%> - <%= render :partial => "add_comment", locals: {questionId: questionId, planId: plan_id}%> -<% end%> diff --git a/app/views/plans/_dropdowns_new_plan.html.erb b/app/views/plans/_dropdowns_new_plan.html.erb new file mode 100644 index 0000000..5413579 --- /dev/null +++ b/app/views/plans/_dropdowns_new_plan.html.erb @@ -0,0 +1,41 @@ + + +<%= semantic_form_for @plan, :url => {:controller => :plans, :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')%>

    +
    + + + + <% end %> + + + <%= f.actions do %> + <%= f.action :submit, + :as => :button, + :input_html => { :id => "create-plan-button", :class => "btn btn-primary"}, + :label => t('helpers.project.create') %> + <% end %> + +<% end %> diff --git a/app/views/plans/_edit_comment.html.erb b/app/views/plans/_edit_comment.html.erb deleted file mode 100644 index 5ea6c8b..0000000 --- a/app/views/plans/_edit_comment.html.erb +++ /dev/null @@ -1,18 +0,0 @@ - - -<%= form_for(comment, :url => {:controller => :comments, :action => :update } , :html => { :method => :put, :class => "edit_comment_form", :id=> "edit_comment_form_#{comment.id}"}) do |f| %> - <%= f.hidden_field :id, :value => comment.id %> - - <%= text_area_tag("#{comment.id}_comment_text".to_sym, comment.text , class: "tinymce") %> -
    - - -
    - <% question = Question.find(comment.question_id)%> - <%= hidden_field_tag :plan_id, comment.plan_id, :class => "plan_id" %> - <%= hidden_field_tag :comment_id, comment.id, :class => "comment_id" %> - <%= hidden_field_tag :section_id, question.section_id, :class => "section_id" %> - <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary edit_comment_submit_button" %> -
    -
    -<%end%> \ No newline at end of file diff --git a/app/views/plans/_export.html.erb b/app/views/plans/_export.html.erb index 6c0e8de..876ab64 100644 --- a/app/views/plans/_export.html.erb +++ b/app/views/plans/_export.html.erb @@ -1,9 +1,9 @@ \ No newline at end of file +
    diff --git a/app/views/plans/_list_comments.html.erb b/app/views/plans/_list_comments.html.erb deleted file mode 100644 index 84b9eef..0000000 --- a/app/views/plans/_list_comments.html.erb +++ /dev/null @@ -1,80 +0,0 @@ - -<% if comments.count > 1 then%> - <% style_to_add = "height:150px; overflow-y:auto;" %> -<%else%> - <% style_to_add = "" %> -<%end%> -
    -
    - - - <% comments.order("updated_at DESC").each do |c|%> - - - - - - <%end%> - -
    - <% user = User.find(c.user_id) %> - <%= user.name %>
    - (<%= l c.updated_at, format: :custom %>) -
    - <% if c.archived == true then %> - <% if c.archived_by == current_user.id then%> - <%= t("helpers.comments.retracted")%> - <% else %> - <% archived_by_user = User.find(c.archived_by) %> - <%= t("helpers.comments.clear_by")%> <%= archived_by_user.name %> - <%end%> - <%else%> - <%= link_to t("helpers.comments.view_label"),"#", :class => "dmp_table_link view_comment_button" %> - <%= hidden_field_tag :comment_id, c.id, :class => "comment_id" %> - <% if current_user.id == c.user_id then %> - <%= link_to t("helpers.comments.edit_label"),"#", :class => "dmp_table_link edit_comment_button" %> - - <%= hidden_field_tag :comment_id, c.id, :class => "comment_id" %> - <%= link_to t("helpers.comments.retract_label"),"#", :class => "dmp_table_link archive_comment_button" %> - <% end%> - <% project_id = Plan.find(c.plan_id).project_id%> - <% if (Project.find(project_id).administerable_by(current_user.id) && current_user.id != c.user_id )then%> - <%= hidden_field_tag :comment_id, c.id, :class => "comment_id" %> - <%= link_to t("helpers.comments.clear_label"),"#", :class => "dmp_table_link archive_comment_button" %> - <% end%> - <%end%> -
    -
    - -
    - - -<% comments_not_archived = comments.where("archived IS NULL") %> -<% latest_comment = comments_not_archived.order("updated_at DESC").first %> -<% if !latest_comment.nil? then%> -
    - <%= render :partial => "view_comment", locals: {comment: latest_comment} %> -
    -
    -<%end%> - -<%comments.order("updated_at DESC").each do |com|%> - - - - - - - - - - <%end%> diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb new file mode 100644 index 0000000..7a1466b --- /dev/null +++ b/app/views/plans/_plan_details.html.erb @@ -0,0 +1,319 @@ + +
    + + + + +
    "> + +
    +

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

    +
    + + +
    + + <%= semantic_form_for @plan, :url => {:controller => :plans, :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%> +
    + + + +
    "> +
    +

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

    +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + <% if !@plan.principal_investigator_identifier.nil? && @plan.principal_investigator_identifier != "" then %> + + + + + <%end%> + + + + + + + + +
    <%= t('helpers.project.project_name') %><%= @plan.title %>
    <%= t('helpers.project.project_identifier') %> + <% if !@plan.identifier.nil? && @plan.identifier != "" then %> + <%= @plan.identifier %> + <%else%> + - + <%end%> +
    <%= t('helpers.project.grant_title') %> + <% if !@plan.grant_number.nil? && @plan.grant_number!= "" then %> + <%= @plan.grant_number %> + <%else%> + - + <%end%> +
    <%= t('helpers.project.principal_investigator') %><% if !@plan.principal_investigator.nil? && @plan.principal_investigator != "" then %> + <%= @plan.principal_investigator %> + <%else%> + - + <%end%> +
    <%= t('helpers.project.principal_investigator_id') %> + <%= @plan.principal_investigator_identifier %> +
    <%= t('helpers.project.project_data_contact') %><% if !@plan.data_contact.nil? && @plan.data_contact != "" then%> + <%= @plan.data_contact %> + <%else%> + - + <%end%> +
    <%= t('helpers.desc') %><% if !@plan.description.nil? && @plan.description != "" then%> + <%= @plan.description %> + <%else%> + - + <%end%> +
    +
    +
    + + + +
    +
    + +
    +
    + <%= semantic_form_for @plan, :url => {:controller => :plans, :action => :update_guidance_choices }, :html=>{:method=>:put}, :remote => true do |f| %> + <%= f.inputs do %> + <%= f.input :plan_guidance_groups, + :as => :check_boxes, + :collection => selected_guidance_groups %> + <% end %> + + <%= f.actions do %> +
    + <%= f.submit t("helpers.submit.save"), :class => 'btn btn-primary' %> + <%= t("helpers.links.cancel") %> +
    + <%end%> + <%end%> +
    +
    +
    +
    + +
    + +

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

    + + + + <%if @plan_data["template"]["org"]["name"].present? %> + + + + + <%end%> + <%if @plan_data["template"]["customization_of"].present? %> + <%= " (Customised from " + @plan_data["template"]["customization_of"]["org"]["name"] + ")" %> + <%end%> +
    <%= constant("organisation_types.funder") %><%= @plan_data["template"]["org"]["name"] %>
    + +
    + + + <% phases = @plan_data["template"]["phases"] %> + <% if phases.any? %> + <% if phases.count == 1 then %> + <% phases.each do |phase| %> + +
    + <%= link_to t('helpers.answer_questions'), edit_plan_path(plan), :class => 'btn btn-primary' %> + <%= t('helpers.export') %> +
    + <%= render :partial => "plans/export", locals: {plan: plan, plan_data: plan_data} %> +
    +

    <%= raw phase["description"] %>

    + <% if phase["sections"].any? %> + + + + + + + + + <% phase["sections"].each do |section| %> + + + + + <%end%> + +
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    +

    <%= section["title"] %>

    +
    + <% if section["questions"].any? %> +
      + <% section["questions"].each do |ques|%> +
    • + <%= raw ques["text"] %> +
    • + <%end%> +
    + <%end%> +
    + <%end%> + <%end%> + <%else%> +
    + <%= raw plan_data["template"]["description"] %> +
    + <% phases.each do |phase| %> +
    +
    + +
    " class="accordion-project collapse"> +
    +
    + <%= link_to t('helpers.answer_questions'), edit_plan_path(plan), :class => 'btn btn-primary' %> + -export-dialog" data-toggle="modal" class='btn btn-primary'><%= t('helpers.export') %> +
    + <%= render :partial => "plans/export", locals: {plan: plan, plan_data: plan_data} %> +
    +

    <%= raw phase["description"] %> +

    + + <% if phase["sections"].any? %> + + + + + + + + + <% phase["sections"].each do |section| %> + + + + + <%end%> + +
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    +

    <%= section["title"] %>

    +
    + <% if section["questions"].any? %> +
      + <% section["questions"].each do |ques|%> +
    • + - <%= raw ques["text"] %> +
    • + <%end%> +
    + <%end%> +
    + <%end%> +
    +
    +
    +
    + <%end%> + <%end%> + <%end%> +
    diff --git a/app/views/plans/_plan_list_head.html.erb b/app/views/plans/_plan_list_head.html.erb new file mode 100644 index 0000000..c924411 --- /dev/null +++ b/app/views/plans/_plan_list_head.html.erb @@ -0,0 +1,6 @@ + + <% @selected_columns.each do |column| %> + <%= plan_list_column_heading(column) %> + <% end %> + <%= t("helpers.select_action")%> + diff --git a/app/views/plans/_plan_list_item.html.erb b/app/views/plans/_plan_list_item.html.erb new file mode 100644 index 0000000..5014813 --- /dev/null +++ b/app/views/plans/_plan_list_item.html.erb @@ -0,0 +1,27 @@ + + <% @selected_columns.each do |column| %> + <%= plan_list_column_body(column, plan) %> + <% end %> + + <% if plan.editable_by?(current_user.id) then %> + <%= link_to t(".edit", :default => t("helpers.links.edit")), plan_path(plan), :class => "dmp_table_link"%> + + <% if plan.administerable_by?(current_user.id) then %> + <%= link_to t("helpers.project.share.tab_share"), share_plan_path(plan), :class => "dmp_table_link"%> + <% end %> + + <%= link_to t("helpers.project.tab_export"), export_plan_path(plan), :class => "dmp_table_link"%> + + <% if plan.administerable_by?(current_user.id) then %> + <%= link_to t(".destroy", :default => t("helpers.links.destroy")), plan_path(plan), :class => "dmp_table_link", + :method => :delete, :data => { + :confirm => t("helpers.project.confirm_delete_text") + }%> + <% end %> + <% else %> + <%= link_to t(".view", :default => t("helpers.view")), plan_path(plan), :class => "dmp_table_link"%> + <%= link_to t("helpers.project.tab_export"), export_plan_path(plan), :class => "dmp_table_link"%> + <% end %> + + + diff --git a/app/views/plans/_plan_nav_tabs.html.erb b/app/views/plans/_plan_nav_tabs.html.erb new file mode 100644 index 0000000..77633b0 --- /dev/null +++ b/app/views/plans/_plan_nav_tabs.html.erb @@ -0,0 +1,38 @@ + + diff --git a/app/views/plans/_plan_title.html.erb b/app/views/plans/_plan_title.html.erb new file mode 100644 index 0000000..d134aa1 --- /dev/null +++ b/app/views/plans/_plan_title.html.erb @@ -0,0 +1,8 @@ + +
    +
    +

    + <%= plan.title %> +

    +
    +
    diff --git a/app/views/plans/_toolbar.html.erb b/app/views/plans/_toolbar.html.erb new file mode 100644 index 0000000..07ad94a --- /dev/null +++ b/app/views/plans/_toolbar.html.erb @@ -0,0 +1,12 @@ +
    +
    + <%= search_field_tag(:filter, params[:filter], placeholder: t('helpers.project.filter.placeholder')) %> + + <%= t('helpers.project.filter.cancel') -%> + + +
    + + + +
    diff --git a/app/views/plans/_view_comment.html.erb b/app/views/plans/_view_comment.html.erb deleted file mode 100644 index 2141349..0000000 --- a/app/views/plans/_view_comment.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - -<% user = User.find(comment.user_id) %> -
    -
    -
    -
      -
    • <%= t("helpers.comments.commented_by")%>

    • -
    • <%= user.name%> (<%= l comment.updated_at, format: :custom %>)
    • -
    • <%= raw comment.text %>
    • - -
    -
    diff --git a/app/views/plans/create.html.erb b/app/views/plans/create.html.erb new file mode 100644 index 0000000..b1ef328 --- /dev/null +++ b/app/views/plans/create.html.erb @@ -0,0 +1,14 @@ + +
    + +

    Choose one of these templates

    + +<%= debug @templates %> + +<% @templates.each do |t| %> +

    <%= t %> +<% end %> + +

    + + diff --git a/app/views/plans/edit.html.erb b/app/views/plans/edit.html.erb index 0bd9403..bd3de93 100644 --- a/app/views/plans/edit.html.erb +++ b/app/views/plans/edit.html.erb @@ -1,16 +1,19 @@ <%- model_class = Plan -%> <% javascript "plans.js" %> - + -<%= render :partial => "/projects/project_title", locals: {project: @plan.project} %> +<%= render :partial => "plan_title", locals: {plan: @plan} %> <% status = @plan.status %>
    <%space_used = status["space_used"].to_i - space_title = t("helpers.plan.export.space_used", space_used: space_used, num_pages: @plan.dmptemplate.settings(:export).max_pages) + space_title = t("helpers.plan.export.space_used", space_used: space_used, num_pages: @plan.template.settings(:export).max_pages) answered = %(#{status["num_answers"]}/#{status["num_questions"]})%>
    <%= answered -%> <%= t("helpers.project.questions_answered")%> @@ -23,27 +26,18 @@
    -<% readonly = nil %> -<% if ! @plan.editable_by(current_user.id) then %> - <% readonly = "always" %> -<% end %> - - -<%= render :partial => "/projects/project_nav_tabs", locals: {project: @plan.project, active: @plan.id} %> + +<%= render :partial => "plan_nav_tabs", locals: {plan: @plan, active: @phase.id } %> - +
    - <% sections = @plan.sections %> + <% sections = @phase.sections %> <% sections.each do |section| %> - <% locked = @plan.locked(section.id, current_user.id) %> - <% if readonly == nil && locked["locked"] then %> - <% readonly = "conditional" %> - <% end %> <% if session[:question_id_comments].to_i != 0 then %> @@ -56,59 +50,78 @@
    - <% num_section_questions = @plan.status["sections"][section.id]["num_questions"] %> - <% num_section_answers = @plan.status["sections"][section.id]["num_answers"] %> + + + <% num_section_questions = @section.status["sections"][section.id]["num_questions"] %> + <% num_section_answers = @section.status["sections"][section.id]["num_answers"] %> <% question_word = "questions" %> <% if num_section_questions == 1 then %> <% question_word = "question" %> <% end %> <% section_status = "#{num_section_questions} #{question_word}, #{num_section_answers} answered" %> + + + + -
    +
    + +
    - <%= raw section.description %> -
    + <%= raw section.description %> +
    + +

    <%= t ('helpers.loading')%>

    - -
    - + <% section.questions.order("number").each do |question| %> + <% if question.id == session[:question_id_comments].to_i then id_css = "current_question" end %> +
    + <% partialname = "answer_form" + if @readonly + partialname += "_ro" + end + %> + + <%= render partial: partialname, + locals: { + plan: @plan, + question: question, + last_question_id: section.questions.order("number DESC").first.id + } + %> +
    + <% end %> +
    + + + + + + +