Skip to content
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

Add navigation to school management forms #3910

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/components/manage_school_navigation_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ManageSchoolNavigationComponent < ApplicationComponent
attr_reader :school, :current_user

def initialize(school:, current_user: nil, classes: '')
super(id: 'page-nav', classes: classes)
@school = school
@current_user = current_user
end

def ability
@ability ||= Ability.new(@current_user)
end

def can?(permission, context)
ability.can?(permission, context)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<%= component 'page_nav', name: t('advice_pages.nav.overview'),
classes: classes,
icon: nil, href: settings_school_path(school),
options: { user: current_user, match_controller: true } do |c| %>

<% c.with_section name: t('components.manage_school_navigation.settings'),
icon: 'gear',
options: { match_controller: false } do |s| %>
<% s.with_item(name: t('manage_school_menu.edit_school_details'),
href: edit_school_path(school), classes: 'small') %>
<% s.with_item(name: t('manage_school_menu.your_school_estate'),
href: edit_school_your_school_estate_path(school), classes: 'small') %>
<% s.with_item(name: t('manage_school_menu.edit_school_times'),
href: edit_school_times_path(school), classes: 'small') %>
<% if school.calendar && can?(:show, school.calendar) %>
<% s.with_item(name: t('manage_school_menu.school_calendar'),
href: calendar_path(school.calendar), classes: 'small') %>
<% end %>
<% end %>

<% c.with_section name: t('components.manage_school_navigation.users'),
icon: 'users',
options: { match_controller: false } do |s| %>
<% s.with_item(name: t('manage_school_menu.manage_users'),
href: school_users_path(school), classes: 'small') %>
<% if can? :manage, Contact %>
<% s.with_item(name: t('manage_school_menu.manage_alert_contacts'),
href: school_contacts_path(school), classes: 'small') %>
<% end %>
<% end %>

<% c.with_section name: t('components.manage_school_navigation.metering'),
icon: 'gauge',
options: { match_controller: false } do |s| %>
<% if can? :index, Meter %>
<% s.with_item(name: t('manage_school_menu.manage_meters'),
href: school_meters_path(school), classes: 'small') %>
<% end %>
<% if can? :manage_solar_feed_configuration, School %>
<% s.with_item(name: t('schools.meters.index.manage_solar_api_feeds'),
href: school_solar_feeds_configuration_index_path(school), classes: 'small') %>
<% end %>
<% if can? :manage, MeterReview %>
<% s.with_item(name: t('schools.meters.index.meter_reviews'),
href: admin_school_meter_reviews_path(school), classes: 'small') %>
<% end %>
<% if can? :manage, EnergyTariff %>
<% s.with_item(name: t('manage_school_menu.manage_tariffs'),
href: school_energy_tariffs_path(school), classes: 'small') %>
<% end %>
<% s.with_item(name: t('schools.meters.index.school_downloads'),
href: school_downloads_path(school), classes: 'small') %>
<% end %>

<% c.with_section name: t('components.manage_school_navigation.admin'),
icon: 'lock',
visible: current_user.admin?,
options: { match_controller: false } do |s| %>

<% if can? :configure, school %>
<% s.with_item(name: t('manage_school_menu.school_configuration'),
href: edit_school_configuration_path(school), classes: 'small') %>
<% end %>
<% if can? :manage, SchoolMeterAttribute %>
<% s.with_item(name: t('manage_school_menu.meter_attributes'),
href: admin_school_meter_attributes_path(school), classes: 'small') %>
<% end %>
<% if can? :manage, Audit %>
<% s.with_item(name: t('manage_school_menu.manage_audits'),
href: school_audits_path(school), classes: 'small') %>
<% end %>
<% if can? :manage, SchoolPartner %>
<% s.with_item(name: t('manage_school_menu.manage_partners'),
href: admin_school_partners_path(school), classes: 'small') %>
<% end %>
<% if can? :manage, Cad %>
<% s.with_item(name: t('manage_school_menu.manage_cads'),
href: school_cads_path(school), classes: 'small') %>
<% end %>
<% if can? :manage, Issue %>
<% s.with_item(name: t('manage_school_menu.manage_issues'),
href: admin_school_issues_path(school), classes: 'small') %>
<% end %>
<% if can? :view_content_reports, school %>
<% s.with_item(name: t('manage_school_menu.batch_reports'),
href: school_reports_path(school), classes: 'small') %>
<% end %>
<% s.with_item(name: t('schools.meters.index.view_target_data'),
href: admin_school_target_data_path(school), classes: 'small') %>
<% if can?(:expert_analyse, school) && school.has_gas? %>
<% s.with_item(name: t('manage_school_menu.expert_analysis'),
href: admin_school_analysis_path(school), classes: 'small') %>
<% end %>
<% if can? :remove_school, school %>
<% s.with_item(name: t('manage_school_menu.remove_school'),
href: removal_admin_school_path(school), classes: 'small') %>
<% end %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/components/page_nav_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def id
end

def link_text
helpers.text_with_icon(name, icon, class: 'fuel') + content_tag(:span, helpers.toggler, class: 'float-right')
helpers.text_with_icon(name, icon, class: 'fuel fa-fw') + content_tag(:span, helpers.toggler, class: 'float-right')
end

def render?
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def destroy
end
end

def settings
authorize! :manage_settings, @school
render :settings, layout: 'dashboards'
end

private

def set_search_scope
Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def initialize(user)
# type of user
can %i[
show show_pupils_dash update manage_school_times manage_users
show_management_dash read start_programme read_restricted_analysis read_restricted_advice
show_management_dash read start_programme read_restricted_analysis read_restricted_advice manage_settings
], School, school_scope

can :manage, [EstimatedAnnualConsumption, SchoolTarget, Activity, Contact, Observation, TransportSurvey],
Expand Down
26 changes: 26 additions & 0 deletions app/views/schools/_school_page_with_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% content_for :page_title, "#{t(page_title)} | #{school.name}" %>

<% if Flipper.enabled?(:new_manage_school_pages, current_user) %>
<% content_for :dashboard_header do %>
<%# i18n-tasks-use t(page_title) %>
<%= component 'dashboard_header',
title: page_title,
intro: nil,
show_school: false,
school: @school %>
<% end %>

<div class="container">
<div class="row mt-2">
<div id="page-navigation" class="col-md-3 col-lg-3 col-xl-2">
<%= component 'manage_school_navigation', school: school, current_user: current_user %>
</div>

<div id="page-body" class="col-md-9 col-lg-9 col-xl-10">
<%= yield %>
</div>
</div>
</div>
<% else %>
<%= yield %>
<% end %>
3 changes: 2 additions & 1 deletion app/views/schools/meters/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

<% if can? :manage, MeterReview %>
<% if @school.meters.reviewed_dcc_meter.any? %>
<%= link_to t('schools.meters.index.meter_reviews'), admin_school_meter_reviews_path(@school), class: 'btn' %>
<%= link_to t('schools.meters.index.completed_meter_reviews'),
admin_school_meter_reviews_path(@school), class: 'btn' %>
<% end %>
<% if @pending_reviews %>
<%= link_to t('schools.meters.index.review_meters'), new_admin_school_meter_review_path(@school), class: 'btn' %>
Expand Down
117 changes: 117 additions & 0 deletions app/views/schools/settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<%= render 'schools/school_page_with_navigation', school: @school,
page_title: 'manage_school_menu.manage_school' do %>

<% if can? :manage, DashboardMessage %>
<%= render 'admin/shared/dashboard_message', messageable: @school %>
<% elsif @school.dashboard_message %>
<%= render PromptComponent.new(icon: 'info-circle', style: :compact, status: :negative) do |p| %>
<%= @school.dashboard_message.message %>
<% end %>
<% end %>

<%= render TitledSectionComponent.new(id: 'settings-section') do |section| %>
<% section.with_title do %>
<h2><%= t('components.manage_school_navigation.settings') %></h2>
<% end %>
<% section.with_body do %>
<%= render PromptComponent.new(icon: 'school', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.edit_school_details') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), edit_school_path(@school) } %>
<%= t('schools.settings.settings.edit_school_details') %>
<% end %>

<%= render PromptComponent.new(icon: 'building', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.your_school_estate') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), edit_school_your_school_estate_path(@school) } %>
<%= t('schools.settings.settings.your_school_estate') %>
<% end %>

<%= render PromptComponent.new(icon: 'clock', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.edit_school_times') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), edit_school_times_path(@school) } %>
<%= t('schools.settings.settings.edit_school_times') %>
<% unless @school.school_times.community_use.any? %>
<% p.with_pill do %>
<span class="badge badge-warning">
<%= t('schools.settings.settings.add_community_use') %>
</span>
<% end %>
<% end %>
<% end %>

<%= render PromptComponent.new(icon: 'calendar-days', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.school_calendar') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), calendar_path(@school.calendar) } %>
<%= t('schools.settings.settings.school_calendar') %>
<% end if @school.calendar && can?(:show, @school.calendar) %>

<% end %>
<% end %>

<%= render TitledSectionComponent.new(id: 'users-section') do |section| %>
<% section.with_title do %>
<h2><%= t('components.manage_school_navigation.users') %></h2>
<% end %>
<% section.with_body do %>
<%= render PromptComponent.new(icon: 'users', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.manage_users') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), school_users_path(@school) } %>
<%= t('schools.settings.users.manage_users') %>
<% unless @school.users.pupil.any? %>
<% p.with_pill do %>
<span class="badge badge-warning">
<%= t('schools.settings.users.add_pupil_login') %>
</span>
<% end %>
<% end %>
<% unless @school.users.alertable.any? %>
<% p.with_pill do %>
<span class="badge badge-danger">
<%= t('schools.settings.users.add_users') %>
</span>
<% end %>
<% end %>
<% end if can? :manage_users, @school %>

<%= render PromptComponent.new(icon: 'envelope', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.manage_alert_contacts') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), school_users_path(@school) } %>
<%= t('schools.settings.users.manage_alert_contacts') %>
<% unless @school.contacts.any? %>
<% p.with_pill do %>
<span class="badge badge-danger">
<%= t('schools.settings.users.add_alert_contacts') %>
</span>
<% end %>
<% end %>
<% end if can? :manage, Contact %>
<% end %>
<% end %>

<%= render TitledSectionComponent.new(id: 'metering-section') do |section| %>
<% section.with_title do %>
<h2><%= t('components.manage_school_navigation.metering') %></h2>
<% end %>
<% section.with_body do %>
<%= render PromptComponent.new(icon: 'gauge', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.manage_meters') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), school_meters_path(@school) } %>
<%= t('schools.settings.metering.manage_meters') %>
<% end if can? :index, Meter %>

<%= render PromptComponent.new(icon: 'sterling-sign', style: :compact, status: :none) do |p| %>
<% p.with_title { t('manage_school_menu.manage_tariffs') } %>
<% p.with_link { link_to t('schools.settings.manage_link'), school_energy_tariffs_path(@school) } %>
<%= t('schools.settings.metering.manage_tariffs') %>
<% end if can? :manage, EnergyTariff %>

<%= render PromptComponent.new(icon: 'download', style: :compact, status: :none) do |p| %>
<% p.with_title { t('schools.meters.index.school_downloads') } %>
<% p.with_link { link_to t('schools.settings.download_link'), school_downloads_path(@school) } %>
<%= t('schools.settings.metering.school_downloads') %>
<% end %>

<% end %>
<% end %>

<% end %>
8 changes: 8 additions & 0 deletions config/locales/views/components/manage_school_navigation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
en:
components:
manage_school_navigation:
admin: Admin
metering: Metering
settings: Settings
users: Users
22 changes: 21 additions & 1 deletion config/locales/views/schools/schools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ en:
active_pseudo_meters: Active pseudo meters
add_meter: Add meter
admin_meter_status: Meter status
completed_meter_reviews: Completed DCC meter reviews
data_processing_turned_on_message: Data processing must be turned on for this school before meter readings can be validated
data_source: Source
first: From
Expand All @@ -275,7 +276,7 @@ en:
latest: To
manage_solar_api_feeds: Manage Solar API feeds
meter: Meter
meter_reviews: Completed DCC meter reviews
meter_reviews: Meter reviews
meter_system: Meter system
mpan_warning_message: There are electricity meters with MPANs that don't appear to have the correct check digit
name: Name
Expand Down Expand Up @@ -582,6 +583,25 @@ en:
other: We have not received data for your %{out_of_date_fuel_types} usage for over thirty days. As a result your progress report will be out of date
schools:
compare_schools: Compare schools
settings:
download_link: View
manage_link: Manage
metering:
manage_meters: View and manage your school electricity and gas meters
manage_tariffs: Manage current and historical energy tariffs for your school
school_downloads: Download copies of your meter data
settings:
add_community_use: Add community use times
edit_school_details: School address, pupil numbers, floor area and other settings
edit_school_times: Manage school opening hours and community use times
school_calendar: Manage your school calendar, including term times and inset days
your_school_estate: Add details about your school buildings and heating sources
users:
add_alert_contacts: Add alert subscribers
add_pupil_login: Missing pupil login
add_users: Add school users
manage_alert_contacts: Manage subscribers to weekly energy analysis alerts
manage_users: Manage school users and pupil logins
show:
add_alert_contacts: Add alert contacts
add_consumption_estimate: Add an estimate of your annual %{fuels} consumption so we can provide you with a more detailed progress report to help you achieve your targets
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@
get 'analysis_page_finder/:urn/:analysis_class', to: 'analysis_page_finder#show', as: :analysis_page_finder

resources :schools do
member do
get :settings
end

resources :activities do
member do
get :completed
Expand Down
14 changes: 14 additions & 0 deletions lib/tasks/deployment/20241114162930_flipper_new_manage_pages.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace :after_party do
desc 'Deployment task: flipper_new_manage_pages'
task flipper_new_manage_pages: :environment do
puts "Running deploy task 'flipper_new_manage_pages'"

Flipper.add(:new_manage_school_pages)
Flipper.enable_group(:new_manage_school_pages, :admins)

# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end
Loading