diff --git a/Gemfile b/Gemfile index 6ccc952..7fa51b3 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ # ------------------------------------------------ # DATABASE/SERVER gem 'pg' -gem 'mysql2', '~> 0.3.18' +gem 'flag_shih_tzu' # Allows for bitfields in activereccord # ------------------------------------------------ # JS <-> RUBY BRIDGE @@ -109,6 +109,8 @@ 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 d2532a9..432daf6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -135,6 +135,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) @@ -211,7 +212,6 @@ ruby-progressbar multi_json (1.12.1) multipart-post (2.0.0) - mysql2 (0.3.21) nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) @@ -230,6 +230,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) @@ -341,6 +343,7 @@ devise_invitable dragonfly feedjira + flag_shih_tzu friendly_id htmltoword i18n-js (>= 3.0.0.rc11) @@ -351,12 +354,12 @@ libv8 minitest-rails-capybara minitest-reporters - mysql2 (~> 0.3.18) omniauth omniauth-shibboleth pg protected_attributes pundit + rack-mini-profiler rack-test rails (= 4.2.7) railties @@ -382,4 +385,4 @@ ruby 2.2.2p95 BUNDLED WITH - 1.13.2 + 1.13.7 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/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/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/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index e157e76..e16f81b 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -1,37 +1,45 @@ class AnswersController < ApplicationController after_action :verify_authorized + respond_to :html + ## # POST /answers + # current implimentation creates a new answer each time one is submitted + # + # Probably should rename from from create to update + # Maybe better to just update the existing answer rather than generate a new + # one. Especiall since comments connect to answers def create + # create a new answer based off the passed params @answer = Answer.new(params[:answer]) authorize @answer + # find the prevous answer to this question for this plan (created_at: "DESC").first old_answer = @answer.plan.answer(@answer.question_id, false) proceed = false + # confused why we are passing the text through like this if we have clearly passed the answer's other attr through plainly + # We can re-name it as it's defined in app/views/plans/_answer_form.html.erb @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 + # Is this validation necissary? + 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 - 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 + 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 else - respond_to do |format| - format.html { redirect_to :back, notice: I18n.t('helpers.project.answer_no_change') } - end + redirect_to :back, notice: I18n.t('helpers.project.answer_no_change') end end end \ No newline at end of file diff --git a/app/controllers/api/v0/base_controller.rb b/app/controllers/api/v0/base_controller.rb index 7e939fd..b36bfa8 100644 --- a/app/controllers/api/v0/base_controller.rb +++ b/app/controllers/api/v0/base_controller.rb @@ -131,7 +131,7 @@ # end # end # end - OrgTokenPermission.where(organisation_id: @user.organisation_id).find_each do |org_token_permission| + OrgTokenPermission.where(org_id: @user.org_id).find_each do |org_token_permission| logger.debug "#{org_token_permission.token_permission_type.token_type}" if org_token_permission.token_permission_type.token_type == auth_type auth= true diff --git a/app/controllers/api/v0/dmptemplates_controller.rb b/app/controllers/api/v0/dmptemplates_controller.rb deleted file mode 100644 index 0e0a256..0000000 --- a/app/controllers/api/v0/dmptemplates_controller.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Api - module V0 - class DmptemplatesController < Api::V0::BaseController - before_action :authenticate - - - ## - # GET - # @return a list of templates ordered by organisation - def index - # check if the user has permissions to use the templates API - if has_auth(constant("api_endpoint_types.templates")) - @all_templates = Dmptemplate.all - respond_with @all_templates - else - #render unauthorised - render json: I18n.t("api.no_auth_for_endpoint"), status: 401 - end - - end - end - end -end \ No newline at end of file diff --git a/app/controllers/api/v0/plans_controller.rb b/app/controllers/api/v0/plans_controller.rb new file mode 100644 index 0000000..ad76c3d --- /dev/null +++ b/app/controllers/api/v0/plans_controller.rb @@ -0,0 +1,104 @@ +module Api + module V0 + class ProjectsController < Api::V0::BaseController + before_action :authenticate + + swagger_controller :projects, 'Plans' + + swagger_api :create do |api| + summary 'Returns a single guidance group item' + notes 'Notes...' + param :header, 'Authentication-Token', :string, :required, 'Authentication-Token' + response :unauthorized + response :not_found + end + + ## + # Creates a new project based on the information passed in JSON to the API + def create + # find the user's api_token permissions + # then ensure that they have the permission associated with creating plans + if has_auth(constant("api_endpoint_types.plans")) + #params[:organization_id] = Org.where(name: params[:template][:organization]) + # find_by returns nil if none found, find_by! raises an ActiveRecord error + organization = Org.find_by name: params[:template][:organisation] + + # if organization exists + if !organization.nil? + # if organization is funder + if organization.organisation_type == (OrganisationType.find_by(name: constant("organisation_types.funder"))) + # if organization has only 1 template + if organization.dmptemplates.length == 1 + # set template id + dmptemplate = organization.dmptemplates.first + # else if params.template.name specified && params.template.name == one of organization's tempates + elsif !organization.dmptemplates.find_by title: params[:template][:name].nil? + # set template id + dmptemplate = organization.templates.find_by title: params[:template][:name] + # else error: organization has more than one template and template name unspecified + else + render json: I18n.t("api.org_multiple_templates"), status: 400 and return + end + # else error: organization specified is not a funder + else + render json: I18n.t("api.org_not_funder"), status: 400 and return + end + # else error: organization does not exist + else + render json: I18n.t("api.org_dosent_exist"), status: 400 and return + end + + all_groups = [] + # Check to see if the user specified guidances + if !params[:guidance].nil? + # for each specified guidance, see if it exists + params[:guidance][:name].each do |guidance_name| + group = GuidanceGroup.find_by(name: guidance_name) + # if it exists, add it to the guidances for the new project + if !group.nil? + all_groups = all_groups + [group] + end + end + end + + # cant invite a user without having a current user because of devise :ivitable + # after we have auth, will be able to assign an :invited_by_id + user = User.find_by email: params[:project][:email] + # if user does not exist + if user.nil? + # invite user to DMPRoadmap + User.invite!({email: params[:project][:email]}, ( @user)) + # set project owner to user associated w/email + user = (User.find_by email: params[:project][:email]) + end + + # create new project with specified parameters + @project = Project.new + @project.title = params[:project][:title] + @project.dmptemplate = dmptemplate + @project.slug = params[:project][:title] + @project.organisation = @user.organisations.first + @project.assign_creator(user.id) + @project.guidance_groups = all_groups + + # if save successful, render success, otherwise show error + if @project.save + #render json: @project ,status: :created + render :show, status: :created + else + render json: get_resource.errors, status: :unprocessable_entity + end + else + + render json: I18n.t("api.no_auth_for_endpoint"), status: 400 and return + end + end + + # private + # def project_params + # params.require(:template).permit(:organisation, :name) + # params.require(:project).permit(:title, :email) + # end + end + end +end diff --git a/app/controllers/api/v0/projects_controller.rb b/app/controllers/api/v0/projects_controller.rb deleted file mode 100644 index 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/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..6564cb5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -32,8 +32,8 @@ 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 + elsif user_signed_in? and current_user.org.present? and !current_user.org[:language_id].nil? + I18n.locale = Language.find_by_id(current_user.org[:language_id]).abbreviation # use user's organization language, keep in mine the "OTHER ORG" edge case which should use default language else 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..da3e685 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 @@ -68,14 +60,12 @@ @guidance_group = GuidanceGroup.find(params[:id]) authorize @guidance_group @guidance_group.organisation_id = current_user.organisation_id - @guidance_group.published = true + @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..81ea8c9 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -1,51 +1,40 @@ 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) @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 +45,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 +87,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..713dda5 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,5 +1,13 @@ 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) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb new file mode 100644 index 0000000..9ebd6d3 --- /dev/null +++ b/app/controllers/notes_controller.rb @@ -0,0 +1,56 @@ +class NotesController < ApplicationController + after_action :verify_authorized + respond_to :html + + ## + # POST /notes + def create + @note = Note.new(params[:new_note]) + @note.text = params["#{params[:new_note][:question_id]}new_note_text"] + @note.question_id = params[:new_note][:question_id] + @note.user_id = params[:new_note][:user_id] + @note.plan_id = params[:new_note][:plan_id] + authorize @note + + @plan = Plan.find(@note.plan_id) + @project = Project.find(@plan.project_id) + + if @note.save + session[:question_id_notes] = @note.question_id + redirect_to edit_project_plan_path(@project, @plan), 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/plans_controller.rb b/app/controllers/plans_controller.rb index f5125d6..8e8c70d 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -154,18 +154,6 @@ 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 export @plan = Plan.find(params[:id]) authorize @plan 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 3ab6078..4e88ca8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -61,16 +61,16 @@ @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 + + 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 # GET /projects/1/edit # Should this be removed? @@ -201,57 +201,59 @@ # 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]) - else - funder = nil - end - if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then - institution = Organisation.find(params[:institution]) - else - institution = nil - end - templates = {} - unless funder.nil? then - funder.published_templates.each do |t| - templates[t.id] = t.title - end - end - if templates.count == 0 && !institution.nil? then - institution.published_templates.each do |t| - templates[t.id] = t.title - end - institution.children.each do |o| - o.published_templates.each do |t| - templates[t.id] = t.title - end - end - end - respond_to do |format| - format.json { render json: templates.to_json } - end - end + + # GET /projects/possible_templates.json + def possible_templates + if !params[:funder].nil? && params[:funder] != "" && params[:funder] != "undefined" then + funder = Org.find(params[:funder]) + else + funder = nil + end + if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then + institution = Org.find(params[:institution]) + else + institution = nil + end + templates = {} + unless funder.nil? then + funder.published_templates.each do |t| + templates[t.id] = t.title + end + end + if templates.count == 0 && !institution.nil? then + institution.published_templates.each do |t| + templates[t.id] = t.title + end + institution.children.each do |o| + o.published_templates.each do |t| + templates[t.id] = t.title + end + end + end + respond_to do |format| + format.json { render json: templates.to_json } + end + end # returns to AJAX call from frontend # difficult to secure as it passes through params, and dosent curate data based # 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]) - 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")) - guidance_groups = {} - ggs = GuidanceGroup.guidance_groups_excluding(excluded_orgs) + + if !params[:template].nil? && params[:template] != "" && params[:template] != "undefined" then + template = Dmptemplate.find(params[:template]) + else + template = nil + end + if !params[:institution].nil? && params[:institution] != "" && params[:institution] != "undefined" then + institution = Org.find(params[:institution]) + else + institution = nil + end + excluded_orgs = orgs_of_type(constant("organisation_types.funder")) + orgs_of_type(constant("organisation_types.institution")) + Org.orgs_with_parent_of_type(constant("organisation_types.institution")) + guidance_groups = {} + ggs = GuidanceGroup.guidance_groups_excluding(excluded_orgs) ggs.each do |gg| guidance_groups[gg.id] = gg.name @@ -336,7 +338,7 @@ # Exclude Funders, Institutions, or children of Institutions 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 diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index ec550a3..0f74a00 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -3,6 +3,8 @@ def edit @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) end # POST /resource @@ -13,35 +15,39 @@ 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) + 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 @@ -51,8 +57,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) @@ -66,7 +71,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 @@ -74,13 +79,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 @@ -90,21 +95,15 @@ 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: 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 aa0b716..2bf4305 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -2,8 +2,7 @@ # 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/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 feaf769..211b4f0 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,7 +11,7 @@ def contact_us end - + def roadmap end diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb new file mode 100644 index 0000000..385493e --- /dev/null +++ b/app/controllers/templates_controller.rb @@ -0,0 +1,275 @@ +# [+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) + current_templates = {} + all_versions_own_templates.each do |temp| + if current_templates[temp.dmptemplate_id].nil? + current_templates[temp.dmptemplate_id] = temp + end + end + @templates_own = current_templates.values + #funders templates + @templates_funders = Template.funders_templates + end + + + # GET /dmptemplates/1 + def admin_template + @template = Template.find(params[:id]) + authorize @template + end + + + # PUT /dmptemplates/1 + def admin_update + @template = Template.find(params[:id]) + authorize @template + @template.description = params["template-desc"] + if @template.update_attributes(params[:template]) + redirect_to admin_template_template_path(params[:template]), notice: I18n.t('org_admin.templates.updated_message') + else + render action: "edit" + end + end + + + # GET /dmptemplates/new + def admin_new + authorize Template + end + + + # POST /dmptemplates + def admin_create + @template = Template.new(params[:template]) + @template.org_id = current_user.org_id + @template.description = params['template-desc'] + 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 + + + + # 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 then + @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) 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 + end + + + #preview a phase + def admin_previewphase + @template = Template.find(params[:id]) + authorize @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"] + 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_shibboleth_request_controller.rb b/app/controllers/users/omniauth_shibboleth_request_controller.rb index 7cb8368..43e363d 100644 --- a/app/controllers/users/omniauth_shibboleth_request_controller.rb +++ b/app/controllers/users/omniauth_shibboleth_request_controller.rb @@ -1,5 +1,5 @@ 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? 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/models/answer.rb b/app/models/answer.rb index cadb66d..131b67b 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -1,16 +1,13 @@ class Answer < ActiveRecord::Base - - #associations between tables + ## + # Associations belongs_to :question belongs_to :user belongs_to :plan + 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] - - + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids , :as => [:default, :admin] 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 2ea784b..d062473 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -92,18 +92,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_upload.rb b/app/models/file_upload.rb index 7cf325c..eef1ca3 100644 --- a/app/models/file_upload.rb +++ b/app/models/file_upload.rb @@ -1,7 +1,5 @@ class FileUpload < ActiveRecord::Base - #attr_accessible :file_type_id, :description, :location, :name, :published, :size, :title - - #associations between tables + ## + # Associations belongs_to :file_type - end diff --git a/app/models/guidance.rb b/app/models/guidance.rb index ac1e886..b6048f4 100644 --- a/app/models/guidance.rb +++ b/app/models/guidance.rb @@ -9,22 +9,22 @@ 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] - + ## + # Associations + belongs_to :guidance_group belongs_to :question - - #belongs_to :dmptemplate - #belongs_to :theme - - has_and_belongs_to_many :guidance_groups, join_table: "guidance_in_group" 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? + + ## @@ -32,11 +32,9 @@ # # @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 + def in_group_belonging_to?(org_id) + if guidance_group.org_id == org_id + return true end return false end @@ -48,8 +46,9 @@ # @return [Array] list of guidance def self.by_organisation(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 @@ -88,15 +87,14 @@ 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| - - if guidance_group.organisation.id == organisation.id + user.org do |org| + if guidance_group.org.id == org.id 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 + if guidance_group.organisation.id == Org.find_by( name: GlobalHelpers.constant("organisation_types.managing_organisation")).id viewable = true end @@ -119,7 +117,7 @@ # @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.find_by name: GlobalHelpers.constant("organisation_types.managing_organisation")).guidance_groups # find all groups owned by a Funder organisation funder_groups = [] funders = OrganisationType.find_by( name: GlobalHelpers.constant("organisation_types.funder")) diff --git a/app/models/guidance_group.rb b/app/models/guidance_group.rb index d9102a4..34524ab 100644 --- a/app/models/guidance_group.rb +++ b/app/models/guidance_group.rb @@ -1,19 +1,30 @@ class GuidanceGroup < ActiveRecord::Base include GlobalHelpers + ## + # 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" - #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 - + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :organisation_id, :name, :optional_subset, :published, :as => [:default, :admin] attr_accessible :dmptemplate_ids, :as => [:default, :admin] + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + + + + ## # Converts a guidance group to a string containing the display name # @@ -70,7 +81,7 @@ 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| + Org.where( name: GlobalHelpers.constant("organisation_types.managing_organisation")).find_each do |managing_group| if guidance_group.organisation.id == managing_group.id viewable = true end @@ -95,7 +106,7 @@ 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 @@ -106,7 +117,7 @@ funder_groups = funder_groups + funder.guidance_groups end organisation_groups = [user.organisation.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} diff --git a/app/models/language.rb b/app/models/language.rb index 65477be..a2bdaa0 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -1,5 +1,9 @@ class Language < ActiveRecord::Base + ## + # Associations has_many :users - + + ## + # Validations validates :abbreviation, presence: true, uniqueness: true end \ No newline at end of file diff --git a/app/models/new_plan.rb b/app/models/new_plan.rb new file mode 100644 index 0000000..1dac7cd --- /dev/null +++ b/app/models/new_plan.rb @@ -0,0 +1,5 @@ +class NewPlan < ActiveRecord::Base + belongs_to :template + has_many :roles + has_many :users, through: :roles +end diff --git a/app/models/note.rb b/app/models/note.rb new file mode 100644 index 0000000..cc2f472 --- /dev/null +++ b/app/models/note.rb @@ -0,0 +1,11 @@ +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 :question_id, :text, :user_id, :archived, :plan_id, :archived_by, :as => [:default, :admin] +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..b75f6d8 --- /dev/null +++ b/app/models/org.rb @@ -0,0 +1,216 @@ +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" + + ## + # 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 + + ## + # 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' + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + + ## + # 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 @org.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] + 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 + + ## + # 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 index c00a248..894f84f 100644 --- a/app/models/org_token_permission.rb +++ b/app/models/org_token_permission.rb @@ -1,8 +1,11 @@ class OrgTokenPermission < ActiveRecord::Base - attr_accessible :organisation_id, :token_permission_type_id, :organisation, :token_permission_type, :as => [:default, :admin] - - #associations between tables + ## + # Associations belongs_to :organisation belongs_to :token_permission_type + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :organisation_id, :token_permission_type_id, :organisation, :token_permission_type, :as => [:default, :admin] 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 index 20df31d..d69aa48 100644 --- a/app/models/organisation_type.rb +++ b/app/models/organisation_type.rb @@ -1,7 +1,14 @@ class OrganisationType < ActiveRecord::Base + ## + # Attributes + has_many :orgs + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :description, :organisations, :name, :as => [:default, :admin] - has_many :organisations - + ## + # Validators 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..7d17efb --- /dev/null +++ b/app/models/perm.rb @@ -0,0 +1,10 @@ +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] +end diff --git a/app/models/phase.rb b/app/models/phase.rb index 155a86f..e5cb352 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -4,24 +4,38 @@ # [+Created:+] 03/09/2014 # [+Copyright:+] Digital Curation Centre and University of California Curation Center class Phase < ActiveRecord::Base - extend FriendlyId - #associations between tables - belongs_to :dmptemplate + ## + # Associations + belongs_to :template + has_many :sections, dependent: :destroy + has_many :questions, :through => :sections, dependent: :destroy - has_many :versions, :dependent => :destroy - has_many :sections, :through => :versions, :dependent => :destroy - has_many :questions, :through => :sections, :dependent => :destroy + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :description, :number, :title, :template_id, :as => [:default, :admin] - #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] - + ## + # sluggable title 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 # diff --git a/app/models/plan.rb b/app/models/plan.rb index f25998c..b631651 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -1,29 +1,56 @@ 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 :answers + has_many :notes, through: :answers + has_many :users, through: :roles + ## + # 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, :as => [:default, :admin] + # public is a Ruby keyword so using publicly + enum visibility: [:organisationally_visible, :publicly_visible, :is_test, :privately_visible] + + ## + # 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 - #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 + ## + # 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 + + + + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + # Special note, these are both the methods in the old plan, and in the old project + + + + + + + + + ## # 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. @@ -173,19 +200,6 @@ 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 - - ## # determines if the plan is editable by the specified user # NOTE: This should be renamed to editable_by? # @@ -522,4 +536,341 @@ (num_lines * font_height) + vertical_margin + leading end + + + # BEGIN METHODS FROM PROJECT + # + + + + ## + # 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.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 = 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 + 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/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 2b326b6..0000000 --- a/app/models/project.rb +++ /dev/null @@ -1,357 +0,0 @@ -class Project < ActiveRecord::Base - include GlobalHelpers - - extend FriendlyId - - #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] - - # public is a Ruby keyword so using publicly - enum visibility: [:organisationally_visible, :publicly_visible, :is_test, :privately_visible] - - ## - # 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..d6ec73e 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -1,26 +1,34 @@ 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, :as => [:default, :admin] + + + + # 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 @@ -84,26 +92,19 @@ # @param question [Question] the question to find guidance for # @param org_admin [Organisation] the organisation 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 + def guidance_for_question(question, org) + # pulls together guidance from various sources for question + guidances = {} + theme_ids = question.theme_ids - GuidanceGroup.where("organisation_id = ?", org_admin.id).each do |group| - group.guidances.each do |g| - g.themes.where("id IN (?)", theme_ids).each do |gg| - guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g - end - end + GuidanceGroup.where(org_id: org.id).each do |group| + group.guidances.each do |g| + g.themes.where("id IN (?)", theme_ids).each do |gg| + guidances["#{group.name} " + I18n.t('admin.guidance_lowercase_on') + " #{gg.title}"] = g end - # 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 +114,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..29ad3b8 100644 --- a/app/models/question_format.rb +++ b/app/models/question_format.rb @@ -1,8 +1,20 @@ class QuestionFormat < ActiveRecord::Base + + ## + # Associations + has_many :questions + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 attr_accessible :title, :description, :as => [:default, :admin] - #associations between tables - has_many :questions + + # 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..b16b0d9 --- /dev/null +++ b/app/models/question_option.rb @@ -0,0 +1,11 @@ +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, :as => [:default, :admin] +end diff --git a/app/models/role.rb b/app/models/role.rb index dbe0a80..282802d 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -1,8 +1,86 @@ class Role < ActiveRecord::Base - has_and_belongs_to_many :users, :join_table => :users_roles - - belongs_to :resource, :polymorphic => true - - attr_accessible :name, :role_in_plans, :resource_id, :resource_type, :as => [:default, :admin] - + include FlagShihTzu + + ## + # Associations + belongs_to :user + belongs_to :plan + + ## + # Define Bit Field Values + # Column access + has_flags 1 => :creator, + 2 => :administrator, + 3 => :editor, + column: 'access' + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + # These functions are from the old project_groups model + + + + ## + # 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 + self.save! + 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 self.administrator? then + return 3 + elsif self.editor? then + return 2 + else + return 1 + end + self.save! + 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.save! + end end diff --git a/app/models/section.rb b/app/models/section.rb index fd1dcb7..48b83ae 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -1,16 +1,16 @@ 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 :organisation_id, :description, :number, :title, :published, :questions_attributes, :as => [:default, :admin] ## # return the title of the section diff --git a/app/models/settings/dmptemplate.rb b/app/models/settings/dmptemplate.rb deleted file mode 100644 index a5ce2de..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'] - - 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/template.rb b/app/models/settings/template.rb new file mode 100644 index 0000000..7bc1968 --- /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'] + + 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..b4df355 100644 --- a/app/models/suggested_answer.rb +++ b/app/models/suggested_answer.rb @@ -1,11 +1,21 @@ 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, :as => [:default, :admin] - attr_accessible :organisation_id, :question_id, :text, :is_example, :as => [:default, :admin] + + # 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 diff --git a/app/models/template.rb b/app/models/template.rb new file mode 100644 index 0000000..1ddcb9d --- /dev/null +++ b/app/models/template.rb @@ -0,0 +1,157 @@ +class Template < ActiveRecord::Base + include GlobalHelpers + + ## + # Associations + belongs_to :org + has_many :plans + has_many :phases + has_many :sections, through: :phases + has_many :questions, through: :sections + + ## + # Possibly needed for active_admin + # -relies on protected_attributes gem as syntax depricated in rails 4.2 + attr_accessible :id, :organisation_id, :description, :published, :title, :locale, :is_default, :guidance_group_ids, :as => [:default, :admin] + + # 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 + + + + # EVALUATE CLASS AND INSTANCE METHODS BELOW + # + # What do they do? do they do it efficiently, and do we need them? + + + + ## + # 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 + 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 + + ## + # 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 = modifable && 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 + + ## + # 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 + + + # OLD CODE STARTS HERE + +end diff --git a/app/models/theme.rb b/app/models/theme.rb index 0b31f36..11cc32e 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -1,17 +1,24 @@ 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] + + # 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..0d1f291 100644 --- a/app/models/token_permission_type.rb +++ b/app/models/token_permission_type.rb @@ -1,13 +1,25 @@ class TokenPermissionType < ActiveRecord::Base - - attr_accessible :token_type, :text_description, :as => [:default, :admin] - - #associations between tables + ## + # 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' + ## + # 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] + + ## + # 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 f6fbde2..5697e32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,61 +1,66 @@ class User < ActiveRecord::Base include GlobalHelpers - - # Include default devise modules. Others available are: - # :token_authenticatable, :confirmable, - # :lockable, :timeoutable and :omniauthable + ## + # 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] - #associations between tables - belongs_to :user_type - belongs_to :user_status - has_many :answers - has_many :user_org_roles - has_many :project_groups, :dependent => :destroy - has_many :user_role_types, through: :user_org_roles - belongs_to :language - - belongs_to :organisation - - has_many :projects, through: :project_groups 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 + ## + # Associations + has_and_belongs_to_many :perms, join_table: :users_perms + belongs_to :language + belongs_to :org + has_many :answers + has_many :notes + has_many :roles, dependent: :destroy + has_many :projects, 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_and_belongs_to_many :roles, :join_table => :users_roles + ## + # 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, :org_id, :skip_invitation, + :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, + :organisation, :language, :language_id - has_many :plan_sections + validates :email, email: true, allow_nil: true, uniqueness: true - 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 + ## + # 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 - validates :email, email: true, allow_nil: true, uniqueness: true - # 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 @@ -73,7 +78,7 @@ ## # 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 @@ -81,7 +86,7 @@ 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) @@ -123,7 +128,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("user_role_types.add_organisations")) end ## @@ -131,7 +136,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("user_role_types.change_org_affiliation")) end ## @@ -139,7 +144,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("user_role_types.grant_permissions")) end ## @@ -147,7 +152,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("user_role_types.modify_templates")) end ## @@ -155,7 +160,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("user_role_types.modify_guidance")) end ## @@ -163,7 +168,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("user_role_types.use_api")) end ## @@ -171,7 +176,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")) + perms.include? Perm.find_by(name: constant("user_role_types.change_org_details")) end ## @@ -179,7 +184,7 @@ # # @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('user_role_types.grant_api_to_orgs')) end @@ -188,7 +193,7 @@ # # @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('user_role_types.grant_api_to_orgs')) end ## @@ -196,7 +201,7 @@ # # @return [String] the organisation type def org_type - org_type = organisation.organisation_type.name + org_type = org.organisation_type return org_type end @@ -221,44 +226,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 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/users_perm.rb b/app/models/users_perm.rb new file mode 100644 index 0000000..38a6cd3 --- /dev/null +++ b/app/models/users_perm.rb @@ -0,0 +1,4 @@ +class UsersPerm < ActiveRecord::Base + belongs_to :user + belongs_to :perm +end \ No newline at end of file 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..4aa8245 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, :question, :themes).by_organisation(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..49b9766 --- /dev/null +++ b/app/policies/note_policy.rb @@ -0,0 +1,23 @@ +class NotePolicy < ApplicationPolicy + attr_reader :user + attr_reader :note + + def initialize(user, comment) + raise Pundit::NotAuthorizedError, "must be logged in" unless user + @user = user + @note = note + end + + def create? + Plan.find(@note.plan_id).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 \ No newline at end of file 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..585e2ac 100644 --- a/app/policies/plan_policy.rb +++ b/app/policies/plan_policy.rb @@ -52,7 +52,4 @@ @plan.readable_by(@user.id) end - def warning? - @plan.readable_by(@user.id) - end end \ No newline at end of file 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/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..3524c40 --- /dev/null +++ b/app/policies/template_policy.rb @@ -0,0 +1,124 @@ +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_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/email_validator.rb b/app/validators/email_validator.rb index d47e7c1..a3cc4ed 100644 --- a/app/validators/email_validator.rb +++ b/app/validators/email_validator.rb @@ -1,7 +1,7 @@ class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i - record.errors[attribute] << (options[:message] || "is not a valid email address") + #record.errors[attribute] << (options[:message] || "is not a valid email address") end end end \ No newline at end of file diff --git a/app/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/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/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 5ff15d9..9e320e7 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -3,8 +3,8 @@ <%= 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" %>
    @@ -13,14 +13,14 @@ - + - @@ -28,8 +28,8 @@ @@ -37,19 +37,15 @@ + { class: "typeahead org_sign_up" }) %> - <% other_organisations = Array.new %> - <% Organisation.where("parent_id IS ? AND is_other = ?", nil, true).each do |org| %> - <% other_organisations << org.id %> - <% end %> - "> + "> + as: :string, + class: "text_field has-tooltip reg-input", "data-toggle" => "tooltip", "data-container" => "body", "title" => t("helpers.org_type.other_org_help_text") %> @@ -60,15 +56,15 @@ <% end %> - + + as: :string, + autocomplete: "off" , + class: "text_field has-tooltip", "data-toggle" => "tooltip", "data-html" => "true", "title" => t("helpers.orcid_html") %> <% unless @user.api_token.blank? %> @@ -83,16 +79,16 @@
    <%= (t("helpers.email") + " *") %><%= f.email_field :email, :as => :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", + <%= 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", + 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"), + :org_id, @orgs, :id, :name, {include_blank: constant("organisation_types.organisation")}, - { :class => "typeahead org_sign_up" }) %>
    <%= t('helpers.user_details_language') %>
    <%= t("helpers.orcid_id") %> <%= f.text_field :orcid_id , - :as => :string, - :autocomplete => "off" , - :class => "text_field has-tooltip", "data-toggle" => "tooltip", "data-html" => "true", "title" => t("helpers.orcid_html") %>

    - <% 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 %> + <% 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 %>


    @@ -102,35 +98,29 @@

    <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> -
    <%= t('custom_devise.waiting_for_confirmation') %><%= resource.unconfirmed_email %>
    +
    <%= t('custom_devise.waiting_for_confirmation') %><%= resource.unconfirmed_email %>
    <% end %> - - +
    <%= t("helpers.current_password") %> - <%= f.password_field :current_password, :as => :password %> + <%= f.password_field :current_password, as: :password %>
    <%= t("helpers.new_password") %><%= f.password_field :password, :as => :password, :autocomplete => "off" %> + <%= f.password_field :password, as: :password, autocomplete: "off" %>
    <%= t("helpers.password_conf") %><%= f.password_field :password_confirmation, :as => :password, :autocomplete => "off" %><%= 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" %> + <%= 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 index 1caf54c..b9bbfc8 100644 --- a/app/views/dmptemplates/_add_question.html.erb +++ b/app/views/dmptemplates/_add_question.html.erb @@ -38,7 +38,11 @@
    <%= 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), + #options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, QuestionFormat.find_by_title(t("helpers.text_area")).id), + # the above was the line but it doesn't work because in the DB + # the QuestionFormat title is in English (Text area) + # but the above uses the Fr translation and so gets a nil + options_from_collection_for_select(QuestionFormat.all.order("title"), :id, :title, QuestionFormat.find_by_title("Text area").id), {}, :id => "new-select-format-#{section.id}"%>
    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 index 49c3c20..e2237ea 100644 --- a/app/views/dmptemplates/_admin_nav_tabs.html.erb +++ b/app/views/dmptemplates/_admin_nav_tabs.html.erb @@ -10,7 +10,7 @@ <%= link_to t('org_admin.templates.template_details'), admin_template_dmptemplate_path(dmptemplate) %>
  • - <% dmptemplate.phases.each do |phase| %> + <% dmptemplate.phases.order(:number).each do |phase| %> <% if active == phase.id then %>
  • <% else %> 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/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/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index c7b02b5..4f6dead 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -9,12 +9,12 @@ <% if (user_signed_in? && current_user.can_org_admin? && ( action_name.include? "admin_" ) ) %> <% if current_user.can_modify_templates? %> - <% if namespace == "dmptemplates" then %> + <% if namespace == "templates" then %>
  • <% else %>
  • <% end %> - <%= link_to t("org_admin.template_label"), admin_index_dmptemplate_path(current_user.organisation_id) %> + <%= link_to t("org_admin.template_label"), admin_index_template_path(current_user.org_id) %>
  • <% end %> <% if current_user.can_modify_guidance? %> @@ -23,16 +23,16 @@ <% else %>
  • <% end %> - <%= link_to t("org_admin.guidance_label"), admin_index_guidance_path(current_user.organisation_id)%> + <%= link_to t("org_admin.guidance_label"), admin_index_guidance_path(current_user.org_id)%>
  • <% end %> <% if current_user.can_modify_org_details? %> - <% if namespace == "organisations" then %> + <% if namespace == "orgs" then %>
  • <% else %>
  • <% end %> - <%= link_to t("org_admin.org_details_label"), admin_show_organisation_path(current_user.organisation_id)%> + <%= link_to t("org_admin.org_details_label"), admin_show_org_path(current_user.org_id)%>
  • <% end %> <% if current_user.can_grant_permissions? %> @@ -41,7 +41,7 @@ <% else %>
  • <% end %> - <%= link_to t("org_admin.user_list_label"), admin_index_users_path, :class => "main_nav_last_li"%> + <%= link_to t("org_admin.user_list_label"), "/org/admin/users/admin_index", class: "main_nav_last_li"%>
  • <% end %> <% else %> @@ -125,6 +125,6 @@ <% end %> - <%end%> + <% end %> diff --git a/app/views/layouts/_signin_signout.html.erb b/app/views/layouts/_signin_signout.html.erb index f4d79bb..f4a8b59 100644 --- a/app/views/layouts/_signin_signout.html.erb +++ b/app/views/layouts/_signin_signout.html.erb @@ -1,31 +1,31 @@ diff --git a/app/views/organisation_users/admin_index.html.erb b/app/views/organisation_users/admin_index.html.erb deleted file mode 100644 index 933defc..0000000 --- a/app/views/organisation_users/admin_index.html.erb +++ /dev/null @@ -1,65 +0,0 @@ -<%= stylesheet_link_tag "admin" %> - -

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

    - -<%= raw t('org_admin.user_text_html')%> -<% @user_roles = current_user.organisation.user_org_roles %> - -<% @user_roles = @user_roles.uniq_by {|u| u.user_id } %> - - - - - - - - <% if current_user.organisation.token_permission_types.count > 0 %> - - <% end %> - - - <% form_tag admin_index_organisation_users_path, method: :put do %> - - <% @user_roles.each do |user_id| %> - <% if !user_id.user.nil? then%> - - - - - - <% if current_user.organisation.token_permission_types.count > 0 %> - - <% end %> - - <% end %> - <% end %> - - <%= submit_tag "Update API Privleges" %> - <% end %> -
    <%= t('org_admin.user_full_name') %><%= t('org_admin.user_name') %><%= t('org_admin.last_logged_in') %><%= t('org_admin.how_many_plans') %><%= t('org_admin.api_privleges') %>
    - <% if !user_id.user.name.nil? then%> - <%= user_id.user.name %> - <% end %> - - <%= user_id.user.email %> - - <% if !user_id.user.last_sign_in_at.nil? then%> - <%= l user_id.user.last_sign_in_at.to_date, :formats => :short %> - <% end %> - - <% if !user_id.user.project_groups.nil? then%> - <%= user_id.user.project_groups.count %> - <% end %> - - <%= check_box_tag "user_ids[]", user_id %> - -
    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/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/_add_note.html.erb b/app/views/plans/_add_note.html.erb new file mode 100644 index 0000000..957e0ef --- /dev/null +++ b/app/views/plans/_add_note.html.erb @@ -0,0 +1,20 @@ + + +<% @new_note = Note.new %> + +<%= form_for :new_note, :url => {:controller => :notes, :action => :create } , :html=>{:method=>:post, :id => "new_note_form_#{questionId}", :class => "add_note_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_note_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..be53b78 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 %> @@ -128,13 +122,15 @@ <% 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 +146,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 +208,7 @@ <%= t("helpers.policy_expectations")%> <%else%> <%= t("helpers.guidance")%> - <%end%> + <%end%>
    @@ -247,19 +240,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/_archive_note.html.erb b/app/views/plans/_archive_note.html.erb new file mode 100644 index 0000000..a101e30 --- /dev/null +++ b/app/views/plans/_archive_note.html.erb @@ -0,0 +1,28 @@ + + +<%= form_for(note, :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%> + + +
    + <% question = Question.find(note.question_id)%> + <%= hidden_field_tag :plan_id, note.plan_id, :class => "plan_id" %> + <%= hidden_field_tag :note_id, note.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 :note_id, note.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/_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/_edit_note.html.erb b/app/views/plans/_edit_note.html.erb new file mode 100644 index 0000000..6294200 --- /dev/null +++ b/app/views/plans/_edit_note.html.erb @@ -0,0 +1,18 @@ + + +<%= form_for(note, :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") %> +
    + + +
    + <% question = Question.find(note.question_id)%> + <%= hidden_field_tag :plan_id, note.plan_id, :class => "plan_id" %> + <%= hidden_field_tag :note_id, note.id, :class => "note_id" %> + <%= hidden_field_tag :section_id, question.section_id, :class => "section_id" %> + <%= f.submit t("helpers.submit.save"), :class => "btn btn-primary edit_note_submit_button" %> +
    +
    +<%end%> \ 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/_list_notes.html.erb b/app/views/plans/_list_notes.html.erb new file mode 100644 index 0000000..10a16f0 --- /dev/null +++ b/app/views/plans/_list_notes.html.erb @@ -0,0 +1,79 @@ + +<% if notes.count > 1 then%> + <% style_to_add = "height:150px; overflow-y:auto;" %> +<%else%> + <% style_to_add = "" %> +<%end%> +
    +
    + + + <% notes.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 :note_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 :note_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 :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.where("archived IS NULL") %> +<% latest_note = notes_not_archived.order("updated_at DESC").first %> +<% if !latest_note.nil? then%> +
    + <%= render :partial => "view_note", locals: {note: latest_note} %> +
    +
    +<%end%> + +<%notes.order("updated_at DESC").each do |com|%> + + + + + + + + + + <%end%> diff --git a/app/views/plans/_note.html.erb b/app/views/plans/_note.html.erb new file mode 100644 index 0000000..a6ed343 --- /dev/null +++ b/app/views/plans/_note.html.erb @@ -0,0 +1,35 @@ + + + + +<% @notes = Note.where("question_id = ? AND plan_id = ?", questionId, plan_id) %> +<%= hidden_field_tag :question_id, questionId, :class => "question_id" %> + +<% if @notes.count > 0 then%> + +
    + <%= link_to t("helpers.comments.add_comment_label"),'#', :class => "btn btn-primary add_comment_button" %> + +
    +
    +
    + + <%= render :partial => "list_notes", locals: {notes: @notes}%> +
    +
    + +
    + <%= 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: {questionId: questionId, planId: plan_id}%> +<% end%> 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/_view_note.html.erb b/app/views/plans/_view_note.html.erb new file mode 100644 index 0000000..6b7737f --- /dev/null +++ b/app/views/plans/_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/projects/_project_nav_tabs.html.erb b/app/views/projects/_project_nav_tabs.html.erb index 9e860f6..07200bd 100644 --- a/app/views/projects/_project_nav_tabs.html.erb +++ b/app/views/projects/_project_nav_tabs.html.erb @@ -9,8 +9,9 @@ <% end %> <%= link_to t("helpers.project.tab_plan"), project_path(project) %> - - <% project.plans.each do |plan| %> + + <% pplans = project.plans.sort { |x,y| x.version.phase.number <=> y.version.phase.number} %> + <% pplans.each do |plan| %> <% if active == plan.id then %>
  • <% else %> @@ -42,4 +43,4 @@ <%= link_to t("helpers.project.tab_export"), ["export",project] %>
  • - \ No newline at end of file + diff --git a/app/views/projects/share.html.erb b/app/views/projects/share.html.erb index 22a3a32..cec0df7 100644 --- a/app/views/projects/share.html.erb +++ b/app/views/projects/share.html.erb @@ -6,16 +6,16 @@ <%= render :partial => "project_nav_tabs", locals: {project: @project, active: "share_project"} %>
    - + <%= raw t('helpers.project.share.share_text_html', application_name: Rails.configuration.branding[:application][:name])%> - +

    <%= t('helpers.project.share.collaborators')%>

    -
    - <% if @project.project_groups.any? then %> - +
    + <% if @project.roles.any? then %> + @@ -25,7 +25,7 @@ - <% project_people = @project.project_groups.all.select {|pu| pu.user_id != nil}%> + <% project_people = @project.roles.all.select {|pu| pu.user_id != nil}%> <% project_people.each do |group| %> @@ -33,7 +33,7 @@ <% if group.project_creator then %> <%= t("helpers.project.share.owner")%> <% else %> - <%= form_for group, :url => {:controller => :project_groups, :action => :update, :id => group.id }, :html=>{:method=>:put} do |f| %> + <%= form_for group, :url => {:controller => :roles, :action => :update, :id => group.id }, :html=>{:method=>:put} do |f| %> <%= f.select :access_level, {t('helpers.project.share.co_owner') => 3, t('helpers.project.share.edit') => 2, t('helpers.project.share.read_only') => 1}, {}, {:id => "#{group.id}-can-edit", :class => "toggle-existing-user-access has-tooltip", 'data-toggle' => "tooltip", 'title' => t('helpers.project.share.permissions_desc') } %> <% end %> <% end %> @@ -49,14 +49,14 @@
    <%= group.user.name %>
    <% end %>
    - +

    <%= t('helpers.project.share.add_collaborator')%>

    - +
    - <% new_project_group = ProjectGroup.new %> - <% new_project_group.project = @project %> - <%= semantic_form_for new_project_group, :url => {:controller => :project_groups, :action => :create }, :html=>{:method=>:post} do |f| %> + <% new_role = Role.new %> + <% new_role.project = @project %> + <%= semantic_form_for new_role, :url => {:controller => :roles, :action => :create }, :html=>{:method=>:post} do |f| %> <%= f.inputs do %> <%= f.input :project_id, :as => :hidden %> <%= f.email_field :email, :label => false, placeholder: t('helpers.email') %> diff --git a/app/views/settings/plans/_export_formatting_form.html.erb b/app/views/settings/plans/_export_formatting_form.html.erb index 632a9b1..ffa3cb2 100644 --- a/app/views/settings/plans/_export_formatting_form.html.erb +++ b/app/views/settings/plans/_export_formatting_form.html.erb @@ -10,8 +10,8 @@ <%= form_for(@export_settings, url: settings_plan_path(plan), method: :put, as: :export, remote: true) do |f| %>
    - <%= submit_tag(t("helpers.settings.plans.reset"), class: "btn btn-primary") %> - <%= submit_tag(t("helpers.save"), class: "btn btn-primary", "data-toggle" => "collapse", "data-target" => "#settings-accordion-plan-#{plan.version.phase.id}") %> + <%= submit_tag(t("helpers.settings.plans.reset"), class: "resetbutton btn btn-primary") %> + <%= submit_tag(t("helpers.save"), class: "savebutton btn btn-primary", "data-toggle" => "collapse", "data-target" => "#settings-accordion-plan-#{plan.version.phase.id}") %>
    diff --git a/app/views/settings/plans/show.html.erb b/app/views/settings/plans/show.html.erb index 8f73a1b..3e27a09 100644 --- a/app/views/settings/plans/show.html.erb +++ b/app/views/settings/plans/show.html.erb @@ -1,6 +1,6 @@ -

    <%= t('helpers.settings.plans.title') -%> - <%= @plan.project.title -%>

    +

    <%= t('helpers.settings.plans.title') -%> - <%= @plan.title -%>

    <%= t('helpers.settings.plans.description') -%>

    <%= render "export_formatting_form" %> diff --git a/app/views/shared/_register_form.html.erb b/app/views/shared/_register_form.html.erb index b026327..462083a 100644 --- a/app/views/shared/_register_form.html.erb +++ b/app/views/shared/_register_form.html.erb @@ -21,11 +21,11 @@ <% end %>
  • - <%= collection_select(:user, :organisation_id, Organisation.where("parent_id IS NULL").order("sort_name ASC, name ASC"), :id, :name, {include_blank: constant("organisation_types.organisation")}, { :class => 'typeahead org_sign_up' }) %> + <%= collection_select(:user, :organisation_id, Org.where("parent_id IS NULL").order("sort_name ASC, name ASC"), :id, :name, {include_blank: constant("organisation_types.organisation")}, { :class => 'typeahead org_sign_up' }) %>
  • <% other_organisations = Array.new %> - <% Organisation.where("parent_id IS ? AND is_other = ?", nil, true).each do |org| %> + <% Org.where("parent_id IS ? AND is_other = ?", nil, true).each do |org| %> <% other_organisations << org.id %> <% end %>
    <%= raw t("about_page.body_text_tab_2_html", diff --git a/app/views/templates/_add_guidance.html.erb b/app/views/templates/_add_guidance.html.erb new file mode 100644 index 0000000..de49775 --- /dev/null +++ b/app/views/templates/_add_guidance.html.erb @@ -0,0 +1,93 @@ + +
    + <%= form_for :guidance, :url => {:action => "admin_create"}, :html => {:id => "new_guidance_form"} do |f| %> + + + + + + + + + + + + + + + + + +
    <%= t("org_admin.guidance.text_label") %>
    + <%= text_area_tag("guidance-text", "", class: "tinymce") %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", :class => "guidance_text_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.text_help_text_html"))%> +
    +
    +
    <%= t("org_admin.guidance.by_theme_or_by_question") %>
    + <%= select_tag "g_options", options_for_select([[t("org_admin.guidance.by_themes_label"), 1], + [t("org_admin.guidance.by_question_label"), 2]]) %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", :class => "guidance_apply_to_popover", :rel => "popover", "data-html" => "true", "data-content" => t("org_admin.guidance.apply_to_help_text_html"))%> +
    +
    + + +
    <%= 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/templates/_add_question.html.erb b/app/views/templates/_add_question.html.erb new file mode 100644 index 0000000..62232bd --- /dev/null +++ b/app/views/templates/_add_question.html.erb @@ -0,0 +1,182 @@ + + +<% @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 :org_id, value: current_user.org_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/templates/_add_section.html.erb b/app/views/templates/_add_section.html.erb new file mode 100644 index 0000000..a6bfd97 --- /dev/null +++ b/app/views/templates/_add_section.html.erb @@ -0,0 +1,53 @@ + + +<% @new_section = Section.new %> +<% @new_section.number = phase.sections.count + 1 %> + + +<%= form_for @new_section, url: {action: "admin_createsection"} do |f| %> + <%= f.hidden_field :phase_id, value: phase.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/templates/_add_suggested_answer.html.erb b/app/views/templates/_add_suggested_answer.html.erb new file mode 100644 index 0000000..8969086 --- /dev/null +++ b/app/views/templates/_add_suggested_answer.html.erb @@ -0,0 +1,25 @@ + +<%= form_for :suggested_answer, url: {action: "admin_createsuggestedanswer"} do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_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/templates/_admin_nav_tabs.html.erb b/app/views/templates/_admin_nav_tabs.html.erb new file mode 100644 index 0000000..a4b8ad8 --- /dev/null +++ b/app/views/templates/_admin_nav_tabs.html.erb @@ -0,0 +1,32 @@ + + \ No newline at end of file diff --git a/app/views/templates/_edit_guidance.html.erb b/app/views/templates/_edit_guidance.html.erb new file mode 100644 index 0000000..8debbca --- /dev/null +++ b/app/views/templates/_edit_guidance.html.erb @@ -0,0 +1,26 @@ + +<%= form_for(suggested_answer, :url => admin_updatesuggestedanswer_dmptemplate_path(suggested_answer), :html => { :method => :put}) do |f| %> + <%= f.hidden_field :organisation_id, :value => current_user.organisation.id %> + + + + + + +
    <%= 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/templates/_edit_phase.html.erb b/app/views/templates/_edit_phase.html.erb new file mode 100644 index 0000000..1aefe61 --- /dev/null +++ b/app/views/templates/_edit_phase.html.erb @@ -0,0 +1,45 @@ + + +<%= form_for(phase, url: admin_updatephase_template_path(phase), html: { method: :put}) do |f| %> + +

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

    +
    + <%= raw t('org_admin.templates.phase_details_text_html')%> +
    +
    +
    + + + + + + + + + + + + + + +
    <%= t('org_admin.templates.title_label') %><%= f.text_field :title, + as: :string, + class: 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_title_help_text') %>
    <%= t('org_admin.templates.phase_order_label') %><%= f.number_field :number, in: 0..5, class: "number_field has-tooltip", 'data-toggle' => "tooltip", 'title' => t('org_admin.templates.phase_number_help_text') %>
    <%= t('org_admin.templates.desc_label') %> +
    + <%= text_area_tag("phase-desc", phase.description, class: "tinymce") %> +
    +
    + <%= link_to( image_tag('help_button.png'), '#', class: 'phase_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.phase_desc_help_text_html'))%> +
    +
    +
    + + +
    + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), admin_phase_template_path(phase), class: 'btn cancel' %> +
    + +<% end %> \ No newline at end of file diff --git a/app/views/templates/_edit_question.html.erb b/app/views/templates/_edit_question.html.erb new file mode 100644 index 0000000..9f93a84 --- /dev/null +++ b/app/views/templates/_edit_question.html.erb @@ -0,0 +1,174 @@ + + +<%= form_for(question, url: admin_updatequestion_template_path(question), html: { method: :put}) do |f| %> +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    <%= t("org_admin.questions.question_number_label")%><%= f.number_field :number, in: 1..50, class: "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.questions.number_help_text") %> +
    +
    <%= t("org_admin.questions.question_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_org_id(current_user.org.id) %> + <% if suggested_answer.nil? %> + <% suggested_answer = question.suggested_answers.build %> + <% end %> + <%= f.fields_for :suggested_answers, suggested_answer do |s|%> + <%= s.hidden_field :org_id, value: current_user.org.id %> +
      +
    • <%= 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.phase.template.published?%> + <%= link_to t("helpers.submit.delete"), admin_destroyquestion_template_path(question_id: question.id), + confirm: t("org_admin.questions.delete_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <% end %> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t("helpers.submit.cancel"), "#", class: "btn cancel cancel_edit_question" %> +
    +
    + + + +<%= render partial: "guidance_display", locals: {question: question}%> +<% end %> diff --git a/app/views/templates/_edit_section.html.erb b/app/views/templates/_edit_section.html.erb new file mode 100644 index 0000000..0cf9752 --- /dev/null +++ b/app/views/templates/_edit_section.html.erb @@ -0,0 +1,116 @@ + + + +<%= form_for(section, url: admin_updatesection_template_path(section, phase: phase, edit: edit), html: { method: :put}) do |s| %> + <% if @open && @section_id == section.id then%> + <% toggle = 'accordion-body section-collapse in collapse'%> + <% else %> + <% toggle = 'accordion-body collapse section-collapse' %> + <% end %> + + <% if @new_sec %> + <% 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.modifiable then%> + <%= link_to t("helpers.submit.delete"), admin_destroysection_template_path(section_id: section.id), + confirm: t("org_admin.templates.section_delete_message", section_title: section.title ), method: :delete, class: "btn btn-primary"%> + <% end %> + <%= link_to t('helpers.submit.cancel'), :back, class: 'btn cancel' %> +
    +<% end %> +
    + <% @questions = section.questions.order("number")%> + <% if @questions.count > 0 %> + <% question_left = @questions.count %> + <% @questions.each do |question| %> +
    +
    "> + + <%= render partial: 'show_question', locals: {question: question} %> +
    + + +
    + + <% if question_left.to_i > 1 then %> +
    + <% else %> +
    + <% end %> + <% question_left = question_left - 1 %> + + <% end %> + <% end %> + + + <% if section.modifiable 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/templates/_edit_suggested_answer.html.erb b/app/views/templates/_edit_suggested_answer.html.erb new file mode 100644 index 0000000..8e1b496 --- /dev/null +++ b/app/views/templates/_edit_suggested_answer.html.erb @@ -0,0 +1,26 @@ + +<%= form_for(suggested_answer, url: admin_updatesuggestedanswer_template_path(suggested_answer), html: { method: :put}) do |f| %> + <%= f.hidden_field :org_id, value: current_user.org_id %> + + + + + + +
    <%= t('org_admin.questions.suggested_or_example_answer_label')%> +
      +
    • <%= f.select :is_example, {t('org_admin.questions.example_answer_label') => true, t('org_admin.questions.suggested_answer_label') => false} %>
    • +
    • <%= f.text_area :text, rows: 5 %>
    • +
    +
    +
    + + +
    + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t("helpers.submit.delete"), admin_destroysuggestedanswer_template_path(suggested_answer: suggested_answer.id), + confirm: t("org_admin.questions.delete_suggested_answer_message", question_text: question.text ), method: :delete, class: "btn btn-primary"%> + <%= hidden_field_tag :question_id, question.id, class: "question_id" %> + <%= link_to t('helpers.submit.cancel'), '#', class: 'btn cancel cancel_edit_suggested_answer' %> +
    +<%end%> diff --git a/app/views/templates/_edit_template.html.erb b/app/views/templates/_edit_template.html.erb new file mode 100644 index 0000000..10c33ea --- /dev/null +++ b/app/views/templates/_edit_template.html.erb @@ -0,0 +1,52 @@ + + +<%= form_for(template, url: admin_update_template_path(template), html: { method: :put}) do |f| %> +
    + + + + + + + + + + + + + + + + + + + + + +
    <%= t('org_admin.templates.title_label') %><%= f.text_field :title, as: :string, + class: 'text_field has-tooltip', 'data-toggle' => "tooltip", title: t('org_admin.templates.title_help_text') %>
    <%= t('org_admin.templates.desc_label') %>
    + <%= text_area_tag("template-desc", template.description, class: "tinymce") %> +
    +
    + <%= link_to( image_tag('help_button.png'), '#', class: 'template_desc_popover', rel: "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.desc_help_text_html'))%> +
    +
    <%= t('org_admin.templates.published_label') %><%if template.published? then%> + <%= f.check_box :published, as: :check_boxes %> + <%else%> + <%= t('org_admin.templates.cannot_publish')%> + <%end%> +
    <%= t('org_admin.templates.created') %> + <%= l template.created_at.to_date, formats: :short %> +
    <%= t('org_admin.templates.last_updated') %> + <%= l template.updated_at.to_date, formats: :short %> +
    + + +
    + <%= f.submit t('helpers.submit.save'), class: 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), admin_template_template_path(template), class: 'btn cancel' %> +
    + +
    + +<%end%> \ No newline at end of file diff --git a/app/views/templates/_edit_version.html.erb b/app/views/templates/_edit_version.html.erb new file mode 100644 index 0000000..416fdb7 --- /dev/null +++ b/app/views/templates/_edit_version.html.erb @@ -0,0 +1,47 @@ + + + +<%= form_for(version, :url => admin_updateversion_dmptemplate_path(version, :edit => edit, :phase => phase), :html => { :method => :put}) do |f| %> + +

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

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

    + <%= raw suggested_answer.text %> +

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

    + <%= raw suggested_answer.text %> +

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

    + <%= t('org_admin.templates.phase_details_label')%> + + + <% if @phase.modifiable %> +
    + <%= link_to t("org_admin.templates.edit_phase_details_label"), '#', class: "btn btn-primary", id: "edit_phase_button"%> +
    + <% end %> +

    + +<% if @phase.template.org.not_funder %> +
    + <%= raw t('org_admin.templates.phase_details_text_html')%> +
    +<% end %> + +
    +
    + + + + + + + + + + + + + + +
    <%= t('org_admin.templates.title_label') %><%= @phase.title %>
    <%= t('org_admin.templates.phase_order_label') %><%= @phase.number %>
    <%= t('org_admin.templates.desc_label') %><%= raw @phase.description %>
    +
    diff --git a/app/views/templates/_show_phases_sections.html.erb b/app/views/templates/_show_phases_sections.html.erb new file mode 100644 index 0000000..2ef08fd --- /dev/null +++ b/app/views/templates/_show_phases_sections.html.erb @@ -0,0 +1,62 @@ + + +
    + +
    +

    <%= raw phase.description %>

    +
    + + + +
    + + + <% if phase.sections.length > 0 then %> + <%= link_to t("helpers.preview"), admin_previewphase_template_path(phase), class: 'btn btn-primary'%> + <% end %> + <% if !phase.template.published? then%> + <%= link_to t("helpers.submit.delete"), admin_destroyphase_template_path(:phase_id => phase.id), + confirm: t("org_admin.templates.phase_delete_message", phase_title: phase.title ), method: :delete, class: "btn btn-primary"%> + <% end %> + <% if phase.template.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_template_path(phase), class: "btn btn-primary" %> + +
    + <% if phase.sections.any? then %> + + + + + + + + + <% phase.sections.order("number ASC").each do |section| %> + + + + + <% end %> + +
    <%= t('helpers.sections_label')%><%= t('helpers.questions_label')%>
    +

    <%= section.title %>

    +
    + <% if section.questions.any? %> + <% questions = section.questions.order("number ASC") %> +
      + <% questions.each do |ques|%> +
    • + - <%= raw ques.text %> +
    • + <% end %> +
    + <% end %> +
    + <% end %> + + +
    diff --git a/app/views/templates/_show_question.html.erb b/app/views/templates/_show_question.html.erb new file mode 100644 index 0000000..6ac50fc --- /dev/null +++ b/app/views/templates/_show_question.html.erb @@ -0,0 +1,153 @@ + + +
    + + + + + + + + + + + + + + <% if q_format.title == t("helpers.text_field") || q_format.title == t("helpers.text_area") %> + <% if !question.default_value.nil? %> + + + + + <% end %> + <% end %> + + + + + + + + <% if question.section.phase.template.org_type != constant("organisation_types.funder") %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if !suggested_answer.nil? && suggested_answer.text != "" %> + + + + + <% end %> + <% end %> + + <% if !question.guidance.nil? %> + + + + + <% end %> + + <% themes_q = question.themes %> + <% if !themes_q.nil? %> + + + + + <% 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") %> +
      + <% if question.question_options.is_a? QuestionOption %> +
    • - <%= question.question_options.text %>
    • + <% else %> + <% if !question.question_options.to_a.nil? %> + <% question.question_options.to_a.sort_by{|op| op['number']}.each do |o| %> +
    • - <%= o.text %>
    • + <% end %> + <% end %> + <% end %> +
    + <% end %> +
    +
    <%= t('org_admin.questions.default_value_label')%><%= raw question.default_value %>
    <%= t('org_admin.questions.answer_format_label')%><%= q_format.title %> +
    + <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") %> + <% if question.question_option_comment_display == true %> + <%= t("org_admin.questions.option_comment_display")%> + <% else %> + <%= t("org_admin.questions.option_comment_hide")%> + <% end %> + <% end %> +
    +
    + <% if suggested_answer.is_example? %> + <%= 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 %> + , + <% i +=1 %> + <% end %> + <% end %> +
    +
    + + <% if !question.modifiable %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if !suggested_answer.nil? && suggested_answer.text != "" %> +
    + <%= render :partial => 'show_suggested_answer', locals: {suggested_answer: suggested_answer, question: question} %> +
    + + + <% end %> + + + + + + <% end %> + +
    + + <% if (@edit == 'true' && question.modifiable) %> +
    + <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> + <%= link_to t("org_admin.questions.question_edit_button"), '# ', :class => "btn btn-primary edit_question_button"%> + <% if !question.section.published? %> + <%= link_to t("org_admin.questions.question_delete_button"), admin_destroyquestion_template_path(:question_id => question.id), + :confirm => t("org_admin.questions.delete_message", :question_text => question.text ), :method => :delete, :class => "btn btn-primary"%> + <% end %> +
    + <% elsif @edit == 'false' && question.modifiable %> + <% suggested_answer = question.get_suggested_answer(current_user.org_id) %> + <% if suggested_answer.nil? %> +
    +
    + <%= hidden_field_tag :question_id, question.id, :class => "question_id" %> + <%= link_to t("org_admin.questions.suggested_or_example_answer_button"), '# ', :class => "btn btn-primary add_suggested_answer_button"%> +
    +
    + <% end %> + <% end %> +
    +
    + + + +<%= render :partial => 'guidance_display', locals: {question: question}%> diff --git a/app/views/templates/_show_section.html.erb b/app/views/templates/_show_section.html.erb new file mode 100644 index 0000000..1dbf719 --- /dev/null +++ b/app/views/templates/_show_section.html.erb @@ -0,0 +1,43 @@ + +<%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/templates/_show_suggested_answer.html.erb b/app/views/templates/_show_suggested_answer.html.erb new file mode 100644 index 0000000..888dd45 --- /dev/null +++ b/app/views/templates/_show_suggested_answer.html.erb @@ -0,0 +1,19 @@ + + + + + + +
    + <% 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/templates/_show_template.html.erb b/app/views/templates/_show_template.html.erb new file mode 100644 index 0000000..cd60ea3 --- /dev/null +++ b/app/views/templates/_show_template.html.erb @@ -0,0 +1,43 @@ + + +<% if template.org.not_funder? || current_user.org.funder? then %> +

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

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

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

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

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

    +

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

    + + + + + + + + + + + + + + <% phase.versions.each do |v|%> + + + + + + + + + + + + + <%end%> + +
    <%= t('org_admin.templates.title_label')%><%= t('org_admin.templates.published_label')%><%= t('org_admin.templates.created')%><%= t('org_admin.templates.last_updated') %><%= t('org_admin.templates.actions') %>
    + <%= v.title %> + + <%= v.published %> + + <%= l v.created_at.to_date, :formats => :short %> + + <%= l v.updated_at.to_date, :formats => :short %> + + <%= link_to t("helpers.view"), admin_phase_dmptemplate_path( :version_id => v.id, :id => phase.id , :edit => 'false'), :class => "dmp_table_link"%> + <% if v.published? then%> + + <%= t('org_admin.versions.edit_label')%> + + <%= link_to t("helpers.preview"), admin_previewphase_dmptemplate_path(v), :class => "dmp_table_link" %> + <%else%> + <%= link_to t("org_admin.versions.edit_label"), admin_phase_dmptemplate_path(phase, :version_id => v.id, :edit => 'true'), :class => "dmp_table_link" %> + <%= link_to t("helpers.preview"), admin_previewphase_dmptemplate_path(v), :class => "dmp_table_link" %> + <%#= link_to t("helpers.submit.delete"), admin_destroyversion_dmptemplate_path(:version_id => v.id, :phase => phase , :edit => 'false'), + :confirm => t("org_admin.versions.delete_message", :version_title => v.title ), :method => :delete, :class => "dmp_table_link"%> + <%end%> +
    +
    + + + +<%end%> diff --git a/app/views/templates/admin_addphase.html.erb b/app/views/templates/admin_addphase.html.erb new file mode 100644 index 0000000..65a3e6c --- /dev/null +++ b/app/views/templates/admin_addphase.html.erb @@ -0,0 +1,75 @@ +<%- model_class = Phase -%> +<%= stylesheet_link_tag "admin" %> +<% javascript "admin.js" %> + +

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

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

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

    + <%= raw t("org_admin.templates.phase_new_text_html")%> +
    +
    + <%= f.hidden_field :template_id, value: @template.id%> + + + + + + + + + + + + + +
    <%= t("org_admin.templates.title_label") %><%= f.text_field :title, + as: :string, + class: "text_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.phase_title_help_text") %>
    <%= t("org_admin.templates.phase_order_label") %><%= f.number_field :number, in: 1..5, class: "number_field has-tooltip", "data-toggle" => "tooltip", "title" => t("org_admin.templates.phase_number_help_text") %>
    <%= t("org_admin.templates.desc_label") %> +
    + <%= text_area_tag("phase-desc","" , class: "tinymce") %> +
    +
    + <%= link_to( image_tag("help_button.png"), "#", class: "phase_desc_popover", rel: "popover", "data-html" => "true", "data-content" => t("org_admin.templates.phase_desc_help_text_html"))%> +
    +
    +
    +
    + + +
    + <%= f.submit t("helpers.submit.save"), class: "btn btn-primary" %> + <%= link_to t("helpers.submit.cancel"), admin_template_template_path(@template), class: "btn cancel" %> +
    + + <%end%> +
    +
    +
    +
    + +<%= tinymce content_css: asset_path("application.css") %> \ No newline at end of file diff --git a/app/views/templates/admin_index.html.erb b/app/views/templates/admin_index.html.erb new file mode 100644 index 0000000..89ef362 --- /dev/null +++ b/app/views/templates/admin_index.html.erb @@ -0,0 +1,140 @@ +<%= 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_template_path, + class: 'btn btn-primary' %> +
    +
    +
    + + +<% if @templates_own.length > 0 then %> + + + + + + + + + + + + <% @templates_own.each do |org_template| %> + + + + + + + + + <%end%> + +
    <%= t('org_admin.templates.title_label') %><%= t('org_admin.templates.desc_label') %><%= t('org_admin.templates.published_label') %><%= t('org_admin.templates.last_updated') %><%= t('org_admin.templates.actions') %>
    + <%= org_template.title%> + + <%= raw org_template.description.truncate(90, omission: t('helpers.truncate_continued')) %> + + <%= org_template.published %> + + <% last_temp_updated = org_template.updated_at %> + <% org_template.phases.each do |phase|%> + <% if org_template.updated_at.to_date < phase.updated_at.to_date then %> + <% last_temp_updated = phase.updated_at %> + <% end %> + <% end %> + <%= l last_temp_updated.to_date, formats: :short %> + + <%if current_user.can_org_admin? then%> + <% b_label = t('helpers.submit.edit')%> + <%else%> + <% b_label = t('helpers.view')%> + <%end%> + <%= link_to b_label, admin_template_template_path(org_template), class: "dmp_table_link"%> +
    + +<%end%> + +
    +
    + + +<% if !current_user.org.funder? then %> +

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

    + + + <% if @templates_funders.length > 0 then %> + + + + + + + + + + + + + + <% @templates_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 %> + <%= 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.org_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_template_path(org_template), class: "dmp_table_link"%> +
    + <%end%> +<%end%> diff --git a/app/views/templates/admin_new.html.erb b/app/views/templates/admin_new.html.erb new file mode 100644 index 0000000..61566b7 --- /dev/null +++ b/app/views/templates/admin_new.html.erb @@ -0,0 +1,47 @@ +<%= stylesheet_link_tag "admin" %> +<% javascript "admin.js" %> + +

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

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

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

    + +
    + + +<%= render partial: "admin_nav_tabs", locals: {template: @phase.template, active: @phase.id} %> + + +
    +
    + + +
    +
    + + +
    + <%= render partial: "show_phase", locals: {phase: @phase}%> +
    + <% if @phase.modifiable then %> + + <% end %> +
    +
    + + + <% @sections.order("number ASC").each do |section| %> + <% if @edit && section.modifiable %> + <%= render partial: 'edit_section', locals: {section: section, edit: @edit, phase: @phase} %> + <% else %> + <%= render partial: 'show_section', locals: {section: section}%> + <% end %> + <% end %> + +
    +
    + + + + <% if !@phase.template.published %> + + + + + +
    +
    + <%= link_to t('org_admin.add_section_label'),'#', id: 'add_section_button', aclass: 'btn btn-primary' %> +
    +
    + <%end%> + + diff --git a/app/views/templates/admin_previewphase.html.erb b/app/views/templates/admin_previewphase.html.erb new file mode 100644 index 0000000..12c2507 --- /dev/null +++ b/app/views/templates/admin_previewphase.html.erb @@ -0,0 +1,64 @@ +<%- 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/templates/admin_template.html.erb b/app/views/templates/admin_template.html.erb new file mode 100644 index 0000000..b8d0506 --- /dev/null +++ b/app/views/templates/admin_template.html.erb @@ -0,0 +1,61 @@ +<%= stylesheet_link_tag "admin" %> +<% javascript 'admin.js' %> + +

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

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

    <%= @template.title %>

    + + \ No newline at end of file diff --git a/app/views/user_mailer/api_token_granted_notification.html.erb b/app/views/user_mailer/api_token_granted_notification.html.erb index e72d6f2..bf43579 100644 --- a/app/views/user_mailer/api_token_granted_notification.html.erb +++ b/app/views/user_mailer/api_token_granted_notification.html.erb @@ -2,5 +2,5 @@

    -<% t('helpers.api_granted') %>"<%= link_to t('helpers.api_view_token'), controller: "users", action: "edit") %>". +<% t('helpers.api_granted') %>"<%= link_to t('helpers.api_view_token'), controller: "users", action: "edit" %>".

    diff --git a/app/views/users/admin_api_update.html.erb b/app/views/users/admin_api_update.html.erb deleted file mode 100644 index 3f26ec2..0000000 --- a/app/views/users/admin_api_update.html.erb +++ /dev/null @@ -1,60 +0,0 @@ -<%= stylesheet_link_tag "admin" %> - -

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

    - -<%= raw t('org_admin.user_text_html')%> -<% @users = current_user.organisation.users %> - - - - - - - - - <% if current_user.organisation.token_permission_types.count > 0 %> - - <% end %> - - - - - <%= form_tag( admin_api_update_users_path, method: :put) do %> - <% @users.each do |user| %> - <% if !user.nil? then%> - - - - - - - <% if current_user.organisation.token_permission_types.count > 0 %> - - <% end %> - - <% end %> - <% end %> - - <%= submit_tag "Update Users" %> - <% end %> -
    <%= t('org_admin.user_full_name') %><%= t('org_admin.user_name') %><%= t('org_admin.last_logged_in') %><%= t('org_admin.how_many_plans') %><%= t('org_admin.is_org_admin') %><%= t('org_admin.api_privleges') %>
    - <% if !user.name.nil? then%> - <%= user.name %> - <% end %> - - <%= user.email %> - - <% if !user.last_sign_in_at.nil? then%> - <%= l user.last_sign_in_at.to_date, :formats => :short %> - <% end %> - - <% if !user.project_groups.nil? then%> - <%= user.project_groups.count %> - <% end %> - - <%= check_box_tag "org_admin_ids[]", user.id, user.is_org_admin? %> - - <%= check_box_tag "api_user_ids[]", user.id, user.api_token !="" %> -
    \ No newline at end of file diff --git a/app/views/users/admin_grant_permissions.html.erb b/app/views/users/admin_grant_permissions.html.erb index ca5a170..dc42fb1 100644 --- a/app/views/users/admin_grant_permissions.html.erb +++ b/app/views/users/admin_grant_permissions.html.erb @@ -9,16 +9,16 @@ - <% @roles.each do |role| %> - + <% @perms.each do |perm| %> + <% end %> - <% @roles.each do |role| %> + <% @perms.each do |perm| %> <% end %> diff --git a/app/views/users/admin_index.html.erb b/app/views/users/admin_index.html.erb index c914f49..bad7dfc 100644 --- a/app/views/users/admin_index.html.erb +++ b/app/views/users/admin_index.html.erb @@ -33,8 +33,8 @@ <% end %>
    <%= role.name %> <%= perm.name %>
    - <%= check_box_tag "role_ids[]", role.id, @user.roles.include?(role) %> + <%= check_box_tag "perm_ids[]", perm.id, @user.perms.include?(perm) %>
    - <% if !user.project_groups.nil? then%> - <%= user.project_groups.length %> + <% if !user.roles.nil? then%> + <%= user.roles.length %> <% end %> diff --git a/config/base_site.html b/config/base_site.html new file mode 100644 index 0000000..e20fabe --- /dev/null +++ b/config/base_site.html @@ -0,0 +1,28 @@ + + + + + + + + Bootstrap 101 Template + + + + + + + + + +

    Hello, world!

    + + + + + + + \ No newline at end of file diff --git a/config/branding.yml b/config/branding.yml index 578347c..5649562 100644 --- a/config/branding.yml +++ b/config/branding.yml @@ -26,4 +26,4 @@ <<: *defaults production: - <<: *defaults \ No newline at end of file + <<: *defaults diff --git a/config/environments/development.rb b/config/environments/development.rb index 0978811..6e02253 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -48,4 +48,9 @@ config.action_mailer.perform_deliveries = false BetterErrors::Midleware.allow_ip! "10.0.2.2" if defined?(BetterErrors) && Rails.env == :development + + config.after_initialize do + ActiveRecord::Base.logger = Rails.logger.clone + ActiveRecord::Base.logger.level = Logger::INFO + end end diff --git a/config/initializers/wicked_pdf.rb.example b/config/initializers/wicked_pdf.rb.example new file mode 100644 index 0000000..103b3e5 --- /dev/null +++ b/config/initializers/wicked_pdf.rb.example @@ -0,0 +1,9 @@ +module DMPRoadmap + class Application < Rails::Application + + WickedPdf.config = { + :exe_path => '/usr/local/bin/wkhtmltopdf' + } + + end +end \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index 3e41730..392e073 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -99,20 +99,20 @@ template_label: "Vorlagen" user_list_label: "Nutzer" org_details_label: "Organisations-Details" - org_text: "Grundlegende Informationen über ihre Organisation." + org_text: "Grundlegende Informationen über ihre Org." org_abbr_help_text_html: "Dies wird als Bezeichnung an Ihrer Anleitung angezeigt, z.B. 'Kieler Hilfestellung für Metadaten'. Am besten eine Abkürzung oder ein Namenskürzel." users_list: "Liste der Nutzer" user_full_name: "Name" user_name: "E-Mail-Adresse" last_logged_in: "Zuletzt angemeldet" how_many_plans: "Wie viele Pläne?" - user_text_html: "Folgend findet sich die Liste von Benutzern registriert bzgl. Ihrer Organisation. Sie können diese Liste bzgl. aller Felder sortieren." + user_text_html: "Folgend findet sich die Liste von Benutzern registriert bzgl. Ihrer Org. Sie können diese Liste bzgl. aller Felder sortieren." org_name: "Name" org_abbr: "Abkürzung" org_logo_failed_message: "Logo Upload fehlgeschlagen." org_logo: "Logo" org_contact_email: "Kontakt Email" - org_contact_email_help_text: "Die E-Mail -Adresse des Administrators in Ihrer Organisation. Ihre Benutzer werden diese Adresse verwenden, wenn sie Fragen haben." + org_contact_email_help_text: "Die E-Mail -Adresse des Administrators in Ihrer Org. Ihre Benutzer werden diese Adresse verwenden, wenn sie Fragen haben." new_org_logo: "Laden Sie ein neues Logo-Datei" remove_logo: "Wenn Sie die Standard DMPRoadmap Logo verwenden entscheiden , prüfen Sie bitte dieses Feld Ihre aktuelle Logo zu entfernen." org_desc: "Beschreibung" @@ -120,7 +120,7 @@ org_type: "Organisationsart" parent_org: "Übergeordnete Organisation" last_updated: "Zuletzt aktualisiert" - desc_help_text_html: "
    Bitte beschreibenden Sie Ihre Organisation.
    " + desc_help_text_html: "
    Bitte beschreibenden Sie Ihre Org.
    " abbre_help_text: "Bitte geben Sie eine Abkürzung für Ihre Organisation an." template_desc_help_text_html: "
    Geben Sie eine Beschreibung ein, die Ihnen bei der Unterscheidung von Vorlagen hilft, falls Sie z.B. welche für unterschiedliche Zielgruppen besitzen.
    " target_url_help_text: "Bitte prüfen Sie die Korrektheit ihrer Web-Adresse." diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 5becc4b..3f02ef9 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -19,7 +19,7 @@ day_names: [dimanche, lundi, mardi, mercredi, jeudi, vendredi, samedi] abbr_day_names: [DIM, LUN, MAR, MER, JEU, VEN, SAM] - # Don't forget the nil at the beginning; there's no such thing as a 0th month + # Dont forget the nil at the beginning; theres no such thing as a 0th month month_names: [~, janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre] abbr_month_names: [~, JAN, FEV, MAR, AVR, MAI, JUN, JUL, AOU, SEP, OCT, NOV, DEC] # Used in date_select and datetime_select. @@ -42,23 +42,23 @@ dmponline3_text: "Version précédente de DMPonline" dcc_name: "Digital Curation Centre" welcome_title: "Bienvenue !" - welcome_text: "

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

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