Skip to content

Administrate improvement and updates #2436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
46 changes: 0 additions & 46 deletions app/controllers/admin/hub_regions_controller.rb

This file was deleted.

46 changes: 0 additions & 46 deletions app/controllers/admin/hubs_controller.rb

This file was deleted.

20 changes: 20 additions & 0 deletions app/controllers/admin/programmes_controller.rb
Original file line number Diff line number Diff line change
@@ -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)
Comment on lines +4 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raised an eyebrow at first, but I then realised this is just 5 records being sorted in memory, not 5 sets of records.

end

def show
@programme = Programme.includes(
programme_activity_groupings: :activities,
pathways: {pathway_activities: :activity}
).find(params[:id])
end
end
end
98 changes: 0 additions & 98 deletions app/dashboards/hub_dashboard.rb

This file was deleted.

66 changes: 0 additions & 66 deletions app/dashboards/hub_region_dashboard.rb

This file was deleted.

65 changes: 3 additions & 62 deletions app/dashboards/programme_dashboard.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/views/admin/programmes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<header class="main-content__header">
<h1 class="main-content__page-title">
Programmes
</h1>
</header>

<section class="main-content__body">
<ul>
<% @programmes.each do |programme| %>
<li><%= link_to programme.title, admin_programme_path(programme.id) %></li>
<% end %>
</ul>
</section>
Loading