Skip to content
14 changes: 14 additions & 0 deletions app/controllers/admin/programme_activity_groupings_controller.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions app/dashboards/pathway_activity_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 74 additions & 0 deletions app/dashboards/programme_activity_dashboard.rb
Original file line number Diff line number Diff line change
@@ -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
81 changes: 81 additions & 0 deletions app/dashboards/programme_activity_grouping_dashboard.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app/fields/programme_activity_grouping_json_viewer_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "administrate/field/base"

class ProgrammeActivityGroupingJsonViewerField < Administrate::Field::Base; end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="field-unit field-unit--jsonb field-unit--optional">
<table>
<% field.data.each do |k, v| %>
<tr>
<th>
<%= f.label "web_copy[#{k}]", k.humanize %>
</th>
<td>
<%= f.text_field "web_copy[#{k}]", value: v %>
</td>
</tr>
<% end %>
</table>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= field.data %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% field.data.each do |v| %>
<%= content_tag :dl, class: ['attribute--nested'] do %>
<dt class='attribute-label attribute--inline'><%= v.first %>:</dt>
<dd class='attribute-data attribute-data--reduce-margin attribute--inline'><%= "#{v.last}" %></dd>
<% end %>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
49 changes: 49 additions & 0 deletions spec/requests/admin/programme_activity_groupings_spec.rb
Original file line number Diff line number Diff line change
@@ -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("[email protected]")
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