diff --git a/app/controllers/admin/hub_regions_controller.rb b/app/controllers/admin/hub_regions_controller.rb deleted file mode 100644 index 50915bcaa9..0000000000 --- a/app/controllers/admin/hub_regions_controller.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Admin - class HubRegionsController < Admin::ApplicationController - # Overwrite any of the RESTful controller actions to implement custom behavior - # For example, you may want to send an email after a foo is updated. - # - # def update - # super - # send_foo_updated_email(requested_resource) - # end - - # Override this method to specify custom lookup behavior. - # This will be used to set the resource for the `show`, `edit`, and `update` - # actions. - # - # def find_resource(param) - # Foo.find_by!(slug: param) - # end - - # The result of this lookup will be available as `requested_resource` - - # Override this if you have certain roles that require a subset - # this will be used to set the records shown on the `index` action. - # - # def scoped_resource - # if current_user.super_admin? - # resource_class - # else - # resource_class.with_less_stuff - # end - # end - - # Override `resource_params` if you want to transform the submitted - # data before it's persisted. For example, the following would turn all - # empty values into nil values. It uses other APIs such as `resource_class` - # and `dashboard`: - # - # def resource_params - # params.require(resource_class.model_name.param_key). - # permit(dashboard.permitted_attributes). - # transform_values { |value| value == "" ? nil : value } - # end - - # See https://administrate-prototype.herokuapp.com/customizing_controller_actions - # for more information - end -end diff --git a/app/controllers/admin/hubs_controller.rb b/app/controllers/admin/hubs_controller.rb deleted file mode 100644 index 6c6275be9f..0000000000 --- a/app/controllers/admin/hubs_controller.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Admin - class HubsController < Admin::ApplicationController - # Overwrite any of the RESTful controller actions to implement custom behavior - # For example, you may want to send an email after a foo is updated. - # - # def update - # super - # send_foo_updated_email(requested_resource) - # end - - # Override this method to specify custom lookup behavior. - # This will be used to set the resource for the `show`, `edit`, and `update` - # actions. - # - # def find_resource(param) - # Foo.find_by!(slug: param) - # end - - # The result of this lookup will be available as `requested_resource` - - # Override this if you have certain roles that require a subset - # this will be used to set the records shown on the `index` action. - # - # def scoped_resource - # if current_user.super_admin? - # resource_class - # else - # resource_class.with_less_stuff - # end - # end - - # Override `resource_params` if you want to transform the submitted - # data before it's persisted. For example, the following would turn all - # empty values into nil values. It uses other APIs such as `resource_class` - # and `dashboard`: - # - # def resource_params - # params.require(resource_class.model_name.param_key). - # permit(dashboard.permitted_attributes). - # transform_values { |value| value == "" ? nil : value } - # end - - # See https://administrate-prototype.herokuapp.com/customizing_controller_actions - # for more information - end -end diff --git a/app/controllers/admin/programmes_controller.rb b/app/controllers/admin/programmes_controller.rb new file mode 100644 index 0000000000..61333a1e41 --- /dev/null +++ b/app/controllers/admin/programmes_controller.rb @@ -0,0 +1,20 @@ +module Admin + class ProgrammesController < Admin::ApplicationController + def index + @programmes = [ + Programme.cs_accelerator, + Programme.primary_certificate, + Programme.secondary_certificate, + Programme.i_belong, + Programme.a_level + ].compact.sort_by(&:title) + end + + def show + @programme = Programme.includes( + programme_activity_groupings: :activities, + pathways: {pathway_activities: :activity} + ).find(params[:id]) + end + end +end diff --git a/app/dashboards/hub_dashboard.rb b/app/dashboards/hub_dashboard.rb deleted file mode 100644 index 65fc52eda7..0000000000 --- a/app/dashboards/hub_dashboard.rb +++ /dev/null @@ -1,98 +0,0 @@ -class HubDashboard < 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 = { - hub_region: Field::BelongsTo, - id: Field::String, - name: Field::String, - subdeliverer_id: Field::String, - address: Field::String, - postcode: Field::String, - email: Field::String, - phone: Field::String, - website: Field::String, - twitter: Field::String, - facebook: Field::String, - linkedin: Field::String, - instagram: Field::String, - latitude: Field::Number.with_options(decimals: 2), - longitude: Field::Number.with_options(decimals: 2), - created_at: FORMATTED_DATE_TIME, - updated_at: FORMATTED_DATE_TIME - }.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[ - hub_region - name - ].freeze - - # SHOW_PAGE_ATTRIBUTES - # an array of attributes that will be displayed on the model's show page. - SHOW_PAGE_ATTRIBUTES = %i[ - hub_region - id - name - subdeliverer_id - address - postcode - email - phone - website - twitter - facebook - linkedin - instagram - latitude - longitude - 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[ - hub_region - name - subdeliverer_id - address - postcode - email - phone - website - twitter - facebook - linkedin - instagram - latitude - longitude - ].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 hubs are displayed - # across all pages of the admin dashboard. - # - def display_resource(hub) - hub.name - end -end diff --git a/app/dashboards/hub_region_dashboard.rb b/app/dashboards/hub_region_dashboard.rb deleted file mode 100644 index a185c1c9a3..0000000000 --- a/app/dashboards/hub_region_dashboard.rb +++ /dev/null @@ -1,66 +0,0 @@ -class HubRegionDashboard < 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 = { - hubs: Field::HasMany, - id: Field::String, - name: Field::String, - order: Field::Number, - created_at: FORMATTED_DATE_TIME, - updated_at: FORMATTED_DATE_TIME - }.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[ - name - order - hubs - ].freeze - - # SHOW_PAGE_ATTRIBUTES - # an array of attributes that will be displayed on the model's show page. - SHOW_PAGE_ATTRIBUTES = %i[ - hubs - id - name - order - 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[ - hubs - name - order - ].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 hub regions are displayed - # across all pages of the admin dashboard. - # - def display_resource(hub_region) - hub_region.name - end -end diff --git a/app/dashboards/programme_dashboard.rb b/app/dashboards/programme_dashboard.rb index bd9abe130c..45b10ad42a 100644 --- a/app/dashboards/programme_dashboard.rb +++ b/app/dashboards/programme_dashboard.rb @@ -1,67 +1,8 @@ -class ProgrammeDashboard < 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 = { - pathways: Field::HasMany, - id: Field::String.with_options(searchable: false), - title: Field::String, - slug: Field::String, - description: Field::Text, - enrollable: Field::Boolean, - type: Field::Text, - created_at: FORMATTED_DATE_TIME, - updated_at: FORMATTED_DATE_TIME - }.freeze +require "administrate/custom_dashboard" - # 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 - slug - ].freeze +class ProgrammeDashboard < Administrate::CustomDashboard + resource "Programmes" - # SHOW_PAGE_ATTRIBUTES - # an array of attributes that will be displayed on the model's show page. - SHOW_PAGE_ATTRIBUTES = %i[ - id - title - slug - description - enrollable - ].freeze - - # FORM_ATTRIBUTES - # an array of attributes that will be displayed - # on the model's form (`new` and `edit`) pages. - FORM_ATTRIBUTES = %i[ - title - slug - description - pathways - ].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 programmes are displayed - # across all pages of the admin dashboard. - # def display_resource(programme) programme.title end diff --git a/app/views/admin/programmes/index.html.erb b/app/views/admin/programmes/index.html.erb new file mode 100644 index 0000000000..ed9c95283b --- /dev/null +++ b/app/views/admin/programmes/index.html.erb @@ -0,0 +1,13 @@ +
+

+ Programmes +

+
+ +
+ +
diff --git a/app/views/admin/programmes/show.html.erb b/app/views/admin/programmes/show.html.erb new file mode 100644 index 0000000000..83810311cc --- /dev/null +++ b/app/views/admin/programmes/show.html.erb @@ -0,0 +1,82 @@ +
+

<%= @programme.title %>

+ <%= link_to "Back", admin_programmes_path, class: "button" %> +
+ +<% if @programme.programme_activity_groupings.any? %> +
+

Programme activity groupings

+ + + + + + + + <% @programme.programme_activity_groupings.each do |grouping| %> + + + + + + + <% end %> +
TitleActivity countActivitiesRequired for completion
<%= grouping.title %><%= grouping.activities.size %> + + <%= grouping.required_for_completion %>
+
+<% end %> + +<% if @programme.pathways.any? && @programme != Programme::primary_certificate %> +
+

Pathways

+ + + + + + + <% @programme.pathways.each do |pathway| %> + + + + + + <% end %> +
TitleActivity countActivities
<%= pathway.title %><%= pathway.pathway_activities.size %> + +
+
+<% end %> + +<% if @programme.assessment.present? %> +
+

Programme assessments

+ + + + + + + + + + + +
Classmarker test IDAssessment linkRequired pass percentage
<%= @programme.assessment.class_marker_test_id %><%= link_to @programme.assessment.link, @programme.assessment.link %><%= @programme.assessment.required_pass_percentage.to_i %>%
+
+<% end %> diff --git a/app/views/admin/reports/by_programme.html.erb b/app/views/admin/reports/by_programme.html.erb index 78707f1d17..30a1d6ae4e 100644 --- a/app/views/admin/reports/by_programme.html.erb +++ b/app/views/admin/reports/by_programme.html.erb @@ -1,13 +1,13 @@

- Programme Report: <%= @programme.title %> + Programme Report: <%= @programme.title %>

+ <%= link_to "Back", admin_reports_path, class: "button"%>
- <%= form_with(url: report_results_admin_reports_path(programme_id: @programme.id), local: true) do |form| %> - <%= fields_for :query do |qform| %> + <%= fields_for :query do |qform| %>
<%= qform.label :enrolled %> <%= qform.check_box :enrolled %> @@ -25,10 +25,6 @@
<% end %> <% end %> - <%= form.submit "Run Query" %> - <% end %> - -
diff --git a/app/views/admin/reports/report_results.html.erb b/app/views/admin/reports/report_results.html.erb index 2e440a2b87..39a6983c5c 100644 --- a/app/views/admin/reports/report_results.html.erb +++ b/app/views/admin/reports/report_results.html.erb @@ -1,11 +1,11 @@

- Programme Report: <%= @programme.title %> + Programme Report: <%= @programme.title %>

+ <%= link_to "Back", by_programme_admin_reports_path(programme_id: @programme.id), class: "button" %>
- <%= link_to "Back", by_programme_admin_reports_path(programme_id: @programme.id) %> <% if @users %>

Results

Matching users: <%= @users.uniq.count %>

@@ -23,7 +23,6 @@ <% end %> - <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 902e0cd72a..66e4946158 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,34 +8,22 @@ end end namespace :admin do - root to: "pathways#index" - resources :badges - resources :activities - resources :pathways - resources :pathway_activities - resources :hubs - resources :hub_regions - resources :support_audits, only: %i[index show update edit] + root to: "achievements#index" - 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 - get "/generate_assessment_attempt", to: "users#generate_assessment_attempt", as: :generate_assessment_attempt unless Rails.env.production? - post "/process_assessment_attempt", to: "users#process_assessment_attempt", as: :process_assessment_attempt unless Rails.env.production? - end - resources :user_programme_enrolments, only: %i[index show edit update] do - member do - get :generate_certificate - end - end achievement_actions = Rails.env.production? ? %i[index show] : %i[index show create new destroy update] resources :achievements, only: achievement_actions do member do post :reject_evidence end end + + resources :activities resources :assessment_attempts, only: %i[index show] resources :assessment_attempt_transitions + resources :badges + resources :pathways + resources :pathway_activities + resources :programmes, only: [:index, :show] resources :reports, only: [:index] do collection do get :by_programme @@ -43,6 +31,18 @@ end 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 + get "/generate_assessment_attempt", to: "users#generate_assessment_attempt", as: :generate_assessment_attempt unless Rails.env.production? + post "/process_assessment_attempt", to: "users#process_assessment_attempt", as: :process_assessment_attempt unless Rails.env.production? + end + resources :user_programme_enrolments, only: %i[index show edit update] do + member do + get :generate_certificate + end + end end namespace :api do diff --git a/spec/requests/admin/hub_regions_spec.rb b/spec/requests/admin/hub_regions_spec.rb deleted file mode 100644 index 7355112d5c..0000000000 --- a/spec/requests/admin/hub_regions_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "rails_helper" - -RSpec.describe "Admin::HubRegionsController" do - let(:hub_region) { create(:hub_region) } - - 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_hub_regions_path - end - - it "should render correct template" do - expect(response).to render_template("index") - end - end - - describe "GET #show" do - before do - get admin_hub_region_path(hub_region) - end - - it "should render correct template" do - expect(response).to render_template("show") - end - end - - describe "PUT #update" do - before do - put admin_hub_region_path(hub_region, params: { - hub_region: {name: "test"} - }) - end - - it "should redirect to the show page" do - expect(response).to redirect_to(admin_hub_region_path(hub_region)) - end - end -end diff --git a/spec/requests/admin/hubs_spec.rb b/spec/requests/admin/hubs_spec.rb deleted file mode 100644 index f165ecb5db..0000000000 --- a/spec/requests/admin/hubs_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require "rails_helper" - -RSpec.describe "Admin::HubsController" do - let(:hub) { create(:hub) } - - 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_hubs_path - end - - it "should render correct template" do - expect(response).to render_template("index") - end - end - - describe "GET #show" do - before do - get admin_hub_path(hub) - end - - it "should render correct template" do - expect(response).to render_template("show") - end - end - - describe "PUT #update" do - before do - put admin_hub_path(hub, params: { - hub: {name: "test"} - }) - end - - it "should redirect to the show page" do - expect(response).to redirect_to(admin_hub_path(hub)) - end - end -end diff --git a/spec/requests/admin/programmes_spec.rb b/spec/requests/admin/programmes_spec.rb new file mode 100644 index 0000000000..e69a16f5f4 --- /dev/null +++ b/spec/requests/admin/programmes_spec.rb @@ -0,0 +1,117 @@ +require "rails_helper" + +RSpec.describe "Admin::ProgrammesController" do + let(:programme) { create(:programme) } + let!(:programme_activity_grouping) { create(:programme_activity_grouping, programme:) } + let!(:assessment) { create(:assessment, programme:) } + let(:activities) do + create_list(:activity, 4).map do |activity| + create( + :programme_activity, + programme_activity_grouping: [programme_activity_grouping], + programme: programme, + activity: activity + ) + end + end + let!(:pathway) { create(:pathway, programme:) } + let(:pathway_activities) do + create_list(:pathway_activity, 4).map do |activity| + create( + pathway: pathway, + activity: activity + ) + end + 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_programmes_path + end + + it "should render correct template" do + expect(response).to render_template("index") + end + + it "displays all available programmes" do + programmes = [ + Programme.cs_accelerator, + Programme.primary_certificate, + Programme.secondary_certificate, + Programme.i_belong, + Programme.a_level + ].compact.sort_by(&:title) + + programmes.each do |programme| + expected_link = link_to(programme.title, admin_programme_path(programme.id)) + expect(response.body).to include(expected_link) + end + end + end + + describe "GET #show" do + before do + get admin_programme_path(programme) + end + + it "should render correct template" do + expect(response).to render_template("show") + end + + context "programme activity groupings" do + it "should render programme activity grouping title" do + expect(response.body).to include(programme.programme_activity_groupings.first.title) + end + + it "should render programme activity groupings activity count" do + expect(response.body).to include(programme.programme_activity_groupings.first.activities.size.to_s) + end + + it "should render activities" do + programme.programme_activity_groupings.first.activities.each do |activity| + expect(response.body).to include(strip_tags(activity.title)) + expect(response.body).to include(activity.category) + end + end + + it "should render programme activity groupings required for completion" do + expect(response.body).to include(programme.programme_activity_groupings.first.required_for_completion.to_s) + end + end + + context "pathways" do + it "should render pathway title" do + expect(response.body).to include(programme.pathways.first.title) + end + + it "should render pathway activity count" do + expect(response.body).to include(programme.pathways.first.pathway_activities.size.to_s) + end + + it "should render activities" do + programme.pathways.first.pathway_activities.each do |activity| + expect(response.body).to include(strip_tags(activity.title)) + expect(response.body).to include(activity.category) + end + end + end + + context "assessments" do + it "should render the classmarker test ID" do + expect(response.body).to include(programme.assessment.class_marker_test_id) + end + + it "should render the classmarker assessment link" do + expect(response.body).to include(programme.assessment.link) + end + + it "should render the required pass percentage" do + expect(response.body).to include(programme.assessment.required_pass_percentage.to_i.to_s) + end + end + end +end