Skip to content

Commit

Permalink
Make public displays feature accessible to users (#4186)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldodds authored Jan 24, 2025
1 parent 1fb3e91 commit 06c934b
Show file tree
Hide file tree
Showing 21 changed files with 562 additions and 196 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
module Pupils
class PublicDisplaysController < ApplicationController
class DigitalSignageController < ApplicationController
load_resource :school

include SchoolAggregation
include ActionView::Helpers::TagHelper
include ActionView::Context

skip_before_action :authenticate_user!
before_action :set_fuel_type, except: :index
before_action :set_fuel_type
before_action :check_fuel_type, only: :charts
before_action :set_analysis_dates, except: :index
before_action :set_analysis_dates
after_action :allow_iframe, only: [:equivalences, :charts]

layout 'public_displays'
layout 'digital_signage'

CHART_TYPES = %i[last-week out-of-hours].freeze

rescue_from StandardError do |exception|
Rollbar.error(exception, school: @school.name, school_id: @school.id)
Expand All @@ -23,10 +25,6 @@ class PublicDisplaysController < ApplicationController
end
end

def index
render 'index', layout: 'application'
end

def equivalences
meter_types = case @fuel_type
when :electricity
Expand All @@ -42,18 +40,18 @@ def charts
raise 'Not data enabled' unless @school.data_enabled?
@chart_type = params.require(:chart_type).to_sym

# avoid showing stale date on weekly comparion chart, issue temporary redirect
# avoid showing stale date on weekly comparison chart, issue temporary redirect
# ensures pages don't break in case of lagging data or a meter fault
if lagging_data?(@chart_type)
redirect_to pupils_school_public_displays_equivalences_path(@school, @fuel_type) and return
redirect_to pupils_school_digital_signage_equivalences_path(@school, @fuel_type) and return
end
@chart = find_chart(@fuel_type, @chart_type)
end

private

def lagging_data?(chart_type)
return false if chart_type == :out_of_hours
return false if chart_type == :"out-of-hours"
(Time.zone.today - @analysis_dates.end_date) > 30
end

Expand Down Expand Up @@ -96,14 +94,14 @@ def find_chart(fuel_type, chart_type)
case fuel_type
when :electricity
case chart_type
when :out_of_hours
when :"out-of-hours"
:daytype_breakdown_electricity_tolerant
else
:public_displays_electricity_weekly_comparison
end
when :gas
case chart_type
when :out_of_hours
when :"out-of-hours"
:daytype_breakdown_gas_tolerant
else
:public_displays_gas_weekly_comparison
Expand Down
89 changes: 89 additions & 0 deletions app/controllers/school_groups/digital_signage_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module SchoolGroups
class DigitalSignageController < ApplicationController
load_and_authorize_resource :school_group

def index
end

def charts
send_data charts_csv, filename: csv_filename_for(:charts)
end

def equivalences
send_data equivalences_csv, filename: csv_filename_for(:equivalences)
end

private

def csv_filename_for(link_type)
title = I18n.t("pupils.digital_signage.index.school_group.links.#{link_type}")
"#{@school_group.name}-#{title}-#{Time.zone.now.strftime('%Y-%m-%d')}".parameterize + '.csv'
end

def equivalences_csv
CSV.generate do |csv|
csv << [
t('common.school'),
t('advice_pages.index.priorities.table.columns.fuel_type'),
t('pupils.digital_signage.table.columns.link')
]
schools.each do |school|
if school.has_electricity?
csv << [
school.name,
t('common.electricity'),
pupils_school_digital_signage_equivalences_url(school, :electricity)
]
end
if school.has_gas?
csv << [
school.name,
t('common.gas'),
pupils_school_digital_signage_equivalences_url(school, :gas)
]
end
end
end
end

def charts_csv
CSV.generate do |csv|
csv << [
t('common.school'),
t('advice_pages.index.priorities.table.columns.fuel_type'),
t('pupils.digital_signage.table.columns.chart_type'),
t('pupils.digital_signage.table.columns.description'),
t('pupils.digital_signage.table.columns.link')
]
schools.each do |school|
if school.has_electricity?
Pupils::DigitalSignageController::CHART_TYPES.each do |chart_type|
csv << [
school.name,
t('common.electricity'),
t("pupils.digital_signage.index.charts.#{chart_type}.title"),
t("pupils.digital_signage.index.charts.#{chart_type}.description"),
pupils_school_digital_signage_charts_url(school, :electricity, chart_type)
]
end
end
if school.has_gas?
Pupils::DigitalSignageController::CHART_TYPES.each do |chart_type|
csv << [
school.name,
t('common.gas'),
t("pupils.digital_signage.index.charts.#{chart_type}.title"),
t("pupils.digital_signage.index.charts.#{chart_type}.description"),
pupils_school_digital_signage_charts_url(school, :gas, chart_type)
]
end
end
end
end
end

def schools
@school_group.schools.active.data_enabled.where(data_sharing: :public).order(:name)
end
end
end
8 changes: 8 additions & 0 deletions app/controllers/schools/digital_signage_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Schools
class DigitalSignageController < ApplicationController
load_and_authorize_resource :school

def index
end
end
end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div class="row">
<div class="col-12">
<h1>
<%= t("pupils.public_displays.charts.#{@chart_type}.title", fuel_type: I18n.t("common.#{@fuel_type}").downcase) %>
<%= t("pupils.digital_signage.charts.#{@chart_type}.title", fuel_type: I18n.t("common.#{@fuel_type}").downcase) %>
</h1>
<h2>
<%= t("pupils.public_displays.charts.#{@chart_type}.intro") %>
<%= t("pupils.digital_signage.charts.#{@chart_type}.intro") %>
</h2>
</div>
</div>
Expand All @@ -24,7 +24,7 @@
<div class="col-12 d-flex justify-content-between align-items-center flex-wrap">
<h4>
<% display_dates = @analysis_dates.transform_values { |d| short_dates(d) } %>
<%= t("pupils.public_displays.charts.#{@chart_type}.dates", **display_dates) %>
<%= t("pupils.digital_signage.charts.#{@chart_type}.dates", **display_dates) %>
</h4>
<div class="public-display-logo">
<%= image_tag('navigation-brand-transparent-en.png') %>
Expand Down
96 changes: 0 additions & 96 deletions app/views/pupils/public_displays/index.html.erb

This file was deleted.

59 changes: 59 additions & 0 deletions app/views/school_groups/digital_signage/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<%= content_for :page_title, t('pupils.digital_signage.index.title') %>

<div class="row">
<div class="col-12">
<h1><%= t('pupils.digital_signage.index.title') %></h1>
</div>
</div>

<div class="row">
<div class="col-12">
<%= render PromptComponent.new status: :neutral, icon: 'info-circle' do |c| %>
<% c.with_link { link_to t('pupils.digital_signage.index.prompt.link_text'), 'mailto:[email protected]' } %>
<% c.with_title { t('pupils.digital_signage.index.prompt.title') } %>
<p>
<%= t('pupils.digital_signage.index.prompt.text') %>
</p>
<% end %>
</div>
</div>

<div class="row">
<div class="col-12">
<%= t('pupils.digital_signage.index.intro_html') %>
</div>
</div>

<div class="row">
<div class="col-12">
<h2><%= t('pupils.digital_signage.index.school_group.data_sharing.title') %></h2>
<%= t('pupils.digital_signage.index.public_data_html') %>
</div>
</div>

<div class="row">
<div class="col-12">
<h2><%= t('pupils.digital_signage.index.school_group.downloads.title') %></h2>
<%= t('pupils.digital_signage.index.school_group.downloads.intro_html') %>
</div>
</div>

<div class="row">
<div class="col-12" id='equivalences-downloads'>
<h2><%= t('pupils.digital_signage.index.equivalences.title') %></h2>
<p><%= t('pupils.digital_signage.index.equivalences.intro_html') %></p>
<p><%= link_to t('common.labels.download'),
equivalences_school_group_digital_signage_index_path(@school_group, format: :csv),
class: 'btn btn-sm btn-default' %></p>
</div>
</div>

<div class="row">
<div class="col-12" id='charts-downloads'>
<h2><%= t('pupils.digital_signage.index.charts.title') %></h2>
<p><%= t('pupils.digital_signage.index.charts.intro_html') %></p>
<p><%= link_to t('common.labels.download'),
charts_school_group_digital_signage_index_path(@school_group, format: :csv),
class: 'btn btn-sm btn-default' %></p>
</div>
</div>
Loading

0 comments on commit 06c934b

Please sign in to comment.