Skip to content

Commit cbc79b2

Browse files
committed
Intial work on adding programme activity grouping to administrate
1 parent 559e86c commit cbc79b2

File tree

10 files changed

+284
-3
lines changed

10 files changed

+284
-3
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Admin
2+
class ProgrammeActivitiesController < Admin::ApplicationController
3+
# Overwrite any of the RESTful controller actions to implement custom behavior
4+
# For example, you may want to send an email after a foo is updated.
5+
#
6+
# def update
7+
# super
8+
# send_foo_updated_email(requested_resource)
9+
# end
10+
11+
# Override this method to specify custom lookup behavior.
12+
# This will be used to set the resource for the `show`, `edit`, and `update`
13+
# actions.
14+
#
15+
# def find_resource(param)
16+
# Foo.find_by!(slug: param)
17+
# end
18+
19+
# The result of this lookup will be available as `requested_resource`
20+
21+
# Override this if you have certain roles that require a subset
22+
# this will be used to set the records shown on the `index` action.
23+
#
24+
# def scoped_resource
25+
# if current_user.super_admin?
26+
# resource_class
27+
# else
28+
# resource_class.with_less_stuff
29+
# end
30+
# end
31+
32+
# Override `resource_params` if you want to transform the submitted
33+
# data before it's persisted. For example, the following would turn all
34+
# empty values into nil values. It uses other APIs such as `resource_class`
35+
# and `dashboard`:
36+
#
37+
# def resource_params
38+
# params.require(resource_class.model_name.param_key).
39+
# permit(dashboard.permitted_attributes(action_name)).
40+
# transform_values { |value| value == "" ? nil : value }
41+
# end
42+
43+
# See https://administrate-demo.herokuapp.com/customizing_controller_actions
44+
# for more information
45+
end
46+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module Admin
2+
class ProgrammeActivityGroupingsController < Admin::ApplicationController
3+
# Overwrite any of the RESTful controller actions to implement custom behavior
4+
# For example, you may want to send an email after a foo is updated.
5+
#
6+
# def update
7+
# super
8+
# send_foo_updated_email(requested_resource)
9+
# end
10+
11+
# Override this method to specify custom lookup behavior.
12+
# This will be used to set the resource for the `show`, `edit`, and `update`
13+
# actions.
14+
#
15+
def find_resource(param)
16+
ProgrammeActivityGrouping.find_by!(id: param)
17+
end
18+
19+
# The result of this lookup will be available as `requested_resource`
20+
21+
# Override this if you have certain roles that require a subset
22+
# this will be used to set the records shown on the `index` action.
23+
#
24+
# def scoped_resource
25+
# if current_user.super_admin?
26+
# resource_class
27+
# else
28+
# resource_class.with_less_stuff
29+
# end
30+
# end
31+
32+
# Override `resource_params` if you want to transform the submitted
33+
# data before it's persisted. For example, the following would turn all
34+
# empty values into nil values. It uses other APIs such as `resource_class`
35+
# and `dashboard`:
36+
#
37+
def resource_params
38+
params.require(resource_class.model_name.param_key).permit(
39+
dashboard.permitted_attributes(action_name),
40+
web_copy: {}
41+
)
42+
end
43+
44+
# See https://administrate-demo.herokuapp.com/customizing_controller_actions
45+
# for more information
46+
end
47+
end

app/dashboards/pathway_activity_dashboard.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PathwayActivityDashboard < BaseDashboard
5959
# Overwrite this method to customize how pathway activities are displayed
6060
# across all pages of the admin dashboard.
6161
#
62-
# def display_resource(pathway_activity)
63-
# "PathwayActivity ##{pathway_activity.id}"
64-
# end
62+
def display_resource(pathway_activity)
63+
"#{pathway_activity.activity.stem_activity_code} - #{pathway_activity.activity.title}"
64+
end
6565
end
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require "administrate/base_dashboard"
2+
3+
class ProgrammeActivityDashboard < Administrate::BaseDashboard
4+
# ATTRIBUTE_TYPES
5+
# a hash that describes the type of each of the model's fields.
6+
#
7+
# Each different type represents an Administrate::Field object,
8+
# which determines how the attribute is displayed
9+
# on pages throughout the dashboard.
10+
ATTRIBUTE_TYPES = {
11+
id: Field::String,
12+
activity: Field::BelongsTo,
13+
legacy: Field::Boolean,
14+
order: Field::Number,
15+
programme: Field::BelongsTo,
16+
programme_activity_grouping: Field::BelongsTo,
17+
created_at: Field::DateTime,
18+
updated_at: Field::DateTime
19+
}.freeze
20+
21+
# COLLECTION_ATTRIBUTES
22+
# an array of attributes that will be displayed on the model's index page.
23+
#
24+
# By default, it's limited to four items to reduce clutter on index pages.
25+
# Feel free to add, remove, or rearrange items.
26+
COLLECTION_ATTRIBUTES = %i[
27+
activity
28+
legacy
29+
order
30+
].freeze
31+
32+
# SHOW_PAGE_ATTRIBUTES
33+
# an array of attributes that will be displayed on the model's show page.
34+
SHOW_PAGE_ATTRIBUTES = %i[
35+
id
36+
activity
37+
legacy
38+
order
39+
programme
40+
programme_activity_grouping
41+
created_at
42+
updated_at
43+
].freeze
44+
45+
# FORM_ATTRIBUTES
46+
# an array of attributes that will be displayed
47+
# on the model's form (`new` and `edit`) pages.
48+
FORM_ATTRIBUTES = %i[
49+
activity
50+
legacy
51+
order
52+
programme
53+
programme_activity_grouping
54+
].freeze
55+
56+
# COLLECTION_FILTERS
57+
# a hash that defines filters that can be used while searching via the search
58+
# field of the dashboard.
59+
#
60+
# For example to add an option to search for open resources by typing "open:"
61+
# in the search field:
62+
#
63+
# COLLECTION_FILTERS = {
64+
# open: ->(resources) { resources.where(open: true) }
65+
# }.freeze
66+
COLLECTION_FILTERS = {}.freeze
67+
68+
# Overwrite this method to customize how programme activities are displayed
69+
# across all pages of the admin dashboard.
70+
#
71+
def display_resource(programme_activity)
72+
programme_activity.activity.title
73+
end
74+
end
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
require "administrate/base_dashboard"
2+
require "administrate/field/jsonb"
3+
4+
class ProgrammeActivityGroupingDashboard < Administrate::BaseDashboard
5+
# ATTRIBUTE_TYPES
6+
# a hash that describes the type of each of the model's fields.
7+
#
8+
# Each different type represents an Administrate::Field object,
9+
# which determines how the attribute is displayed
10+
# on pages throughout the dashboard.
11+
ATTRIBUTE_TYPES = {
12+
id: Field::String,
13+
activities: Field::HasMany,
14+
community: Field::Boolean,
15+
metadata: Field::String.with_options(searchable: false),
16+
objectives: Field::String.with_options(searchable: false),
17+
programme: Field::BelongsTo,
18+
programme_activities: Field::HasMany,
19+
progress_bar_title: Field::String,
20+
required_for_completion: Field::Number,
21+
sort_key: Field::Number,
22+
title: Field::String,
23+
web_copy: ProgrammeActivityGroupingJsonViewerField,
24+
created_at: Field::DateTime,
25+
updated_at: Field::DateTime
26+
}.freeze
27+
28+
# COLLECTION_ATTRIBUTES
29+
# an array of attributes that will be displayed on the model's index page.
30+
#
31+
# By default, it's limited to four items to reduce clutter on index pages.
32+
# Feel free to add, remove, or rearrange items.
33+
COLLECTION_ATTRIBUTES = %i[
34+
title
35+
programme
36+
activities
37+
community
38+
].freeze
39+
40+
# SHOW_PAGE_ATTRIBUTES
41+
# an array of attributes that will be displayed on the model's show page.
42+
SHOW_PAGE_ATTRIBUTES = %i[
43+
title
44+
progress_bar_title
45+
programme
46+
web_copy
47+
community
48+
metadata
49+
objectives
50+
programme_activities
51+
].freeze
52+
53+
# FORM_ATTRIBUTES
54+
# an array of attributes that will be displayed
55+
# on the model's form (`new` and `edit`) pages.
56+
FORM_ATTRIBUTES = %i[
57+
title
58+
activities
59+
community
60+
metadata
61+
objectives
62+
programme
63+
programme_activities
64+
progress_bar_title
65+
required_for_completion
66+
sort_key
67+
web_copy
68+
].freeze
69+
70+
# COLLECTION_FILTERS
71+
# a hash that defines filters that can be used while searching via the search
72+
# field of the dashboard.
73+
#
74+
# For example to add an option to search for open resources by typing "open:"
75+
# in the search field:
76+
#
77+
# COLLECTION_FILTERS = {
78+
# open: ->(resources) { resources.where(open: true) }
79+
# }.freeze
80+
COLLECTION_FILTERS = {}.freeze
81+
82+
# Overwrite this method to customize how programme activity groupings are displayed
83+
# across all pages of the admin dashboard.
84+
#
85+
def display_resource(programme_activity_grouping)
86+
"#{programme_activity_grouping.title}"
87+
end
88+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require "administrate/field/base"
2+
3+
class ProgrammeActivityGroupingJsonViewerField < Administrate::Field::Base; end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="field-unit field-unit--jsonb field-unit--optional">
2+
<table>
3+
<% field.data.each do |k, v| %>
4+
<tr>
5+
<td>
6+
<%= f.label "web_copy[#{k}]", k.humanize %>
7+
</td>
8+
<td>
9+
<%= f.text_field "web_copy[#{k}]", value: v %>
10+
</td>
11+
</tr>
12+
<% end %>
13+
</table>
14+
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= field.data %>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<% field.data.each do |v| %>
2+
<%= content_tag :dl, class: ['attribute--nested'] do %>
3+
<dt class='attribute-label attribute--inline'><%= v.first %>:</dt>
4+
<dd class='attribute-data attribute-data--reduce-margin attribute--inline'><%= "#{v.last}" %></dd>
5+
<% end %>
6+
<% end %>

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
end
3333
resources :sent_emails, only: %i[index show]
3434
resources :support_audits, only: %i[index show update edit]
35+
resources :programme_activity_groupings
36+
3537
resources :users, only: %i[index create show edit perform_sync perform_reset update] do
3638
get "/perform_sync/:user_id", to: "users#perform_sync", as: :perform_sync
3739
get "/perform_reset/:user_id", to: "users#perform_reset_tests", as: :perform_reset

0 commit comments

Comments
 (0)