diff --git a/app/admin/dmptemplate.rb b/app/admin/dmptemplate.rb deleted file mode 100644 index 8fdbcb3..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 => 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/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/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/role.rb b/app/admin/role.rb index 378fe2d..4fcf03b 100644 --- a/app/admin/role.rb +++ b/app/admin/role.rb @@ -5,56 +5,5 @@ # [+Copyright:+] Digital Curation Centre and University of California Curation Center ActiveAdmin.register Role 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( (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 - end - - f.actions - end - - controller do - def permitted_params - params.permit! - end - end + menu false 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/models/phase.rb b/app/models/phase.rb index f747b81..a9814b9 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -8,8 +8,8 @@ ## # Associations - belongs_to :template, dependant: :destroy - has_many :sections, dependant: :destroy + belongs_to :template, dependent: :destroy + has_many :sections, dependent: :destroy has_many :questions, :through => :sections, dependent: :destroy ## diff --git a/app/models/question.rb b/app/models/question.rb index 2e03489..8b162a9 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -13,7 +13,7 @@ # 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 :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 diff --git a/app/models/role.rb b/app/models/role.rb index c39da79..606fb62 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -71,4 +71,3 @@ end end end -end diff --git a/app/models/template.rb b/app/models/template.rb index 07206d9..5a7da96 100644 --- a/app/models/template.rb +++ b/app/models/template.rb @@ -15,8 +15,8 @@ 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::Dmptemplate' do |s| - s.key :export, defaults: Settings::template::DEFAULT_SETTINGS + has_settings :export, class_name: 'Settings::Template' do |s| + s.key :export, defaults: Settings::Template::DEFAULT_SETTINGS end