diff --git a/app/controllers/admin/programme_activity_groupings_controller.rb b/app/controllers/admin/programme_activity_groupings_controller.rb new file mode 100644 index 0000000000..421ed7c679 --- /dev/null +++ b/app/controllers/admin/programme_activity_groupings_controller.rb @@ -0,0 +1,14 @@ +module Admin + class ProgrammeActivityGroupingsController < Admin::ApplicationController + def find_resource(param) + ProgrammeActivityGrouping.find_by!(id: param) + end + + def resource_params + params.require(resource_class.model_name.param_key).permit( + dashboard.permitted_attributes(action_name), + web_copy: {} + ) + end + end +end diff --git a/app/dashboards/pathway_activity_dashboard.rb b/app/dashboards/pathway_activity_dashboard.rb index bd4347fa19..b6cb12704f 100644 --- a/app/dashboards/pathway_activity_dashboard.rb +++ b/app/dashboards/pathway_activity_dashboard.rb @@ -59,7 +59,7 @@ class PathwayActivityDashboard < BaseDashboard # Overwrite this method to customize how pathway activities are displayed # across all pages of the admin dashboard. # - # def display_resource(pathway_activity) - # "PathwayActivity ##{pathway_activity.id}" - # end + def display_resource(pathway_activity) + "#{pathway_activity.activity.stem_activity_code} - #{pathway_activity.activity.title}" + end end diff --git a/app/dashboards/programme_activity_dashboard.rb b/app/dashboards/programme_activity_dashboard.rb new file mode 100644 index 0000000000..7f6a013f76 --- /dev/null +++ b/app/dashboards/programme_activity_dashboard.rb @@ -0,0 +1,74 @@ +require "administrate/base_dashboard" + +class ProgrammeActivityDashboard < Administrate::BaseDashboard + # ATTRIBUTE_TYPES + # a hash that describes the type of each of the model's fields. + # + # Each different type represents an Administrate::Field object, + # which determines how the attribute is displayed + # on pages throughout the dashboard. + ATTRIBUTE_TYPES = { + id: Field::String, + activity: Field::BelongsTo, + legacy: Field::Boolean, + order: Field::Number, + programme: Field::BelongsTo, + programme_activity_grouping: Field::BelongsTo, + created_at: Field::DateTime, + updated_at: Field::DateTime + }.freeze + + # COLLECTION_ATTRIBUTES + # an array of attributes that will be displayed on the model's index page. + # + # By default, it's limited to four items to reduce clutter on index pages. + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = %i[ + activity + legacy + order + ].freeze + + # SHOW_PAGE_ATTRIBUTES + # an array of attributes that will be displayed on the model's show page. + SHOW_PAGE_ATTRIBUTES = %i[ + id + activity + legacy + order + programme + programme_activity_grouping + created_at + updated_at + ].freeze + + # FORM_ATTRIBUTES + # an array of attributes that will be displayed + # on the model's form (`new` and `edit`) pages. + FORM_ATTRIBUTES = %i[ + activity + legacy + order + programme + programme_activity_grouping + ].freeze + + # COLLECTION_FILTERS + # a hash that defines filters that can be used while searching via the search + # field of the dashboard. + # + # For example to add an option to search for open resources by typing "open:" + # in the search field: + # + # COLLECTION_FILTERS = { + # open: ->(resources) { resources.where(open: true) } + # }.freeze + COLLECTION_FILTERS = {}.freeze + + # Overwrite this method to customize how programme activities are displayed + # across all pages of the admin dashboard. + # + def display_resource(programme_activity) + programme_activity.activity.title + end +end diff --git a/app/dashboards/programme_activity_grouping_dashboard.rb b/app/dashboards/programme_activity_grouping_dashboard.rb new file mode 100644 index 0000000000..d2d85951df --- /dev/null +++ b/app/dashboards/programme_activity_grouping_dashboard.rb @@ -0,0 +1,81 @@ +require "administrate/base_dashboard" +require "administrate/field/jsonb" + +class ProgrammeActivityGroupingDashboard < Administrate::BaseDashboard + # ATTRIBUTE_TYPES + # a hash that describes the type of each of the model's fields. + # + # Each different type represents an Administrate::Field object, + # which determines how the attribute is displayed + # on pages throughout the dashboard. + ATTRIBUTE_TYPES = { + id: Field::String, + activities: Field::HasMany, + community: Field::Boolean, + programme: Field::BelongsTo, + programme_activities: Field::HasMany, + progress_bar_title: Field::String, + required_for_completion: Field::Number, + sort_key: Field::Number, + title: Field::String, + web_copy: ProgrammeActivityGroupingJsonViewerField, + created_at: Field::DateTime, + updated_at: Field::DateTime + }.freeze + + # COLLECTION_ATTRIBUTES + # an array of attributes that will be displayed on the model's index page. + # + # By default, it's limited to four items to reduce clutter on index pages. + # Feel free to add, remove, or rearrange items. + COLLECTION_ATTRIBUTES = %i[ + title + programme + activities + community + ].freeze + + # SHOW_PAGE_ATTRIBUTES + # an array of attributes that will be displayed on the model's show page. + SHOW_PAGE_ATTRIBUTES = %i[ + title + progress_bar_title + programme + community + programme_activities + web_copy + ].freeze + + # FORM_ATTRIBUTES + # an array of attributes that will be displayed + # on the model's form (`new` and `edit`) pages. + FORM_ATTRIBUTES = %i[ + title + activities + community + programme + programme_activities + progress_bar_title + required_for_completion + web_copy + ].freeze + + # COLLECTION_FILTERS + # a hash that defines filters that can be used while searching via the search + # field of the dashboard. + # + # For example to add an option to search for open resources by typing "open:" + # in the search field: + # + # COLLECTION_FILTERS = { + # open: ->(resources) { resources.where(open: true) } + # }.freeze + COLLECTION_FILTERS = {}.freeze + + # Overwrite this method to customize how programme activity groupings are displayed + # across all pages of the admin dashboard. + # + def display_resource(programme_activity_grouping) + programme_activity_grouping.title.to_s + end +end diff --git a/app/fields/programme_activity_grouping_json_viewer_field.rb b/app/fields/programme_activity_grouping_json_viewer_field.rb new file mode 100644 index 0000000000..40664e0ea5 --- /dev/null +++ b/app/fields/programme_activity_grouping_json_viewer_field.rb @@ -0,0 +1,3 @@ +require "administrate/field/base" + +class ProgrammeActivityGroupingJsonViewerField < Administrate::Field::Base; end diff --git a/app/views/fields/programme_activity_grouping_json_viewer_field/_form.html.erb b/app/views/fields/programme_activity_grouping_json_viewer_field/_form.html.erb new file mode 100644 index 0000000000..da5ec183a2 --- /dev/null +++ b/app/views/fields/programme_activity_grouping_json_viewer_field/_form.html.erb @@ -0,0 +1,14 @@ +
+ + <% field.data.each do |k, v| %> + + + + + <% end %> +
+ <%= f.label "web_copy[#{k}]", k.humanize %> + + <%= f.text_field "web_copy[#{k}]", value: v %> +
+
diff --git a/app/views/fields/programme_activity_grouping_json_viewer_field/_index.html.erb b/app/views/fields/programme_activity_grouping_json_viewer_field/_index.html.erb new file mode 100644 index 0000000000..5177ca4641 --- /dev/null +++ b/app/views/fields/programme_activity_grouping_json_viewer_field/_index.html.erb @@ -0,0 +1 @@ +<%= field.data %> diff --git a/app/views/fields/programme_activity_grouping_json_viewer_field/_show.html.erb b/app/views/fields/programme_activity_grouping_json_viewer_field/_show.html.erb new file mode 100644 index 0000000000..43dcffee58 --- /dev/null +++ b/app/views/fields/programme_activity_grouping_json_viewer_field/_show.html.erb @@ -0,0 +1,6 @@ +<% field.data.each do |v| %> + <%= content_tag :dl, class: ['attribute--nested'] do %> +
<%= v.first %>:
+
<%= "#{v.last}" %>
+ <% end %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 66e4946158..0e2263a064 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,7 @@ resources :pathways resources :pathway_activities resources :programmes, only: [:index, :show] + resources :programme_activity_groupings, only: %i[index show update edit] resources :reports, only: [:index] do collection do get :by_programme @@ -32,6 +33,7 @@ end resources :sent_emails, only: %i[index show] resources :support_audits, only: %i[index show update edit] + resources :users, only: %i[index create show edit perform_sync perform_reset update] do get "/perform_sync/:user_id", to: "users#perform_sync", as: :perform_sync get "/perform_reset/:user_id", to: "users#perform_reset_tests", as: :perform_reset diff --git a/spec/requests/admin/programme_activity_groupings_spec.rb b/spec/requests/admin/programme_activity_groupings_spec.rb new file mode 100644 index 0000000000..d8c3a6af95 --- /dev/null +++ b/spec/requests/admin/programme_activity_groupings_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe "Admin::ProgrammeActivityGroupingsController" do + let(:programme_activity_grouping) do + create(:programme_activity_grouping, + web_copy: { + course_requirements: "Complete this section", + aside_slug: "test-slug", + subtitle: "Complete the activities in this section", + step_number: "three" + }) + end + + before do + allow_any_instance_of(Admin::ApplicationController).to receive(:authenticate_admin).and_return("user@example.com") + end + + describe "GET #index" do + before do + get admin_programme_activity_groupings_path + end + + it "should render correct template" do + expect(response).to render_template("index") + end + end + + describe "GET #show" do + before do + get admin_programme_activity_grouping_path(programme_activity_grouping) + end + + it "should render correct template" do + expect(response).to render_template("show") + end + end + + describe "PUT #update" do + before do + put admin_programme_activity_grouping_path(programme_activity_grouping, params: { + programme_activity_grouping: {title: "test"} + }) + end + + it "should redirect to the show page" do + expect(response).to redirect_to(admin_programme_activity_grouping_path(programme_activity_grouping)) + end + end +end