-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of chart preview tool
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'dashboard' | ||
|
||
module Admin | ||
class ChartPreviewsController < AdminController | ||
before_action :set_school | ||
before_action :load_chart_list | ||
before_action :set_chart_type | ||
before_action :set_chart_titles | ||
before_action :set_controls | ||
|
||
def index | ||
@schools = School.data_enabled.by_name | ||
end | ||
|
||
private | ||
|
||
def set_school | ||
return nil unless chart_params[:school_id].present? | ||
@preview_school = School.friendly.find(chart_params[:school_id]) | ||
end | ||
|
||
def set_chart_type | ||
return nil unless chart_params[:chart_type].present? | ||
@chart_type = chart_params[:chart_type].to_sym | ||
end | ||
|
||
def set_chart_titles | ||
@title = chart_params[:title] || @preview_school.present? ? "School: #{@preview_school.name}" : '' | ||
@subtitle = chart_params[:subtitle] || @chart_type.present? ? "Chart: #{@chart_type}" : '' | ||
@footer = chart_params[:footer] | ||
end | ||
|
||
def set_controls | ||
@axis_controls = (chart_params[:axis_controls].nil? || chart_params[:axis_controls] == '1') | ||
@analysis_controls = (chart_params[:analysis_controls].nil? || chart_params[:analysis_controls] == '1') | ||
end | ||
|
||
def chart_params | ||
params[:preview_chart] || {} | ||
end | ||
|
||
def load_chart_list | ||
analysis_charts = DashboardConfiguration::DASHBOARD_PAGE_GROUPS.except(:simulator, :simulator_detail, :simulator_debug, :test, :pupil_analysis_page, :heating_model_fitting, :cost_unused).map do |top_level_key, config| | ||
["#{config[:name]} (#{top_level_key})", config.fetch(:charts) {[]}] | ||
end | ||
custom_activity_charts = [['Activity charts (custom)', ChartManager::STANDARD_CHART_CONFIGURATION.keys.grep(/^activities/)]] | ||
@chart_list = custom_activity_charts + analysis_charts | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<h1>Chart Previews</h1> | ||
|
||
<p> | ||
This page is intended to help with interactive testing and debugging of chart configurations. Using the options below you can select a school and | ||
run a specific chart using their data. | ||
</p> | ||
|
||
<%= simple_form_for :preview_chart, url: admin_chart_previews_path, method: "GET", html: { class: 'form' } do |f| %> | ||
<%= f.input :school_id, | ||
collection: @schools, | ||
label: 'Choose school', | ||
label_method: lambda {|k| k.name }, | ||
include_blank: false, | ||
selected: ( params[:preview_chart].present? ? params[:preview_chart]['school_id'] : nil ), | ||
input_html: { class: 'form-control select2' } | ||
%> | ||
|
||
<%= f.input :chart_type, | ||
as: :grouped_select, | ||
collection: @chart_list, | ||
label: 'Choose chart type', | ||
group_method: :last, | ||
group_label_method: :first, | ||
include_blank: false, | ||
selected: ( params[:preview_chart].present? ? params[:preview_chart]["chart_type"] : nil), | ||
input_html: { class: 'form-control select2'} | ||
%> | ||
|
||
<p> | ||
You can optionally provide a title, subtitle and footer for the chart to see | ||
how the chart will look when embedded into a page with other text around it. | ||
</p> | ||
|
||
<%= f.input :title, as: :string, input_html: {value: @title || ''} %> | ||
<%= f.input :subtitle, as: :string, input_html: {value: @subtitle || ''} %> | ||
<%= f.input :footer, as: :string, input_html: {value: @footer || ''} %> | ||
|
||
<p> | ||
You can optionally indicate whether the chart should have controls to switch axis and to | ||
navigate through the database. However these may be overridden by the chart configuration | ||
as some charts do not support navigation or switching axes. | ||
</p> | ||
|
||
<%= f.input :axis_controls, as: :boolean, input_html: { :checked => @axis_controls } %> | ||
<%= f.input :analysis_controls, as: :boolean, input_html: { :checked => @analysis_controls } %> | ||
|
||
<%= f.submit "Run chart", class: "btn btn-primary" %> | ||
<%= link_to 'Clear', admin_chart_previews_path, class: "btn btn-primary" %> | ||
<% end %> | ||
|
||
<div class="mt-4"> | ||
<% if @preview_school.present? && @chart_type.present? %> | ||
<%= component 'chart', chart_type: @chart_type, axis_controls: @axis_controls, analysis_controls: @analysis_controls, school: @preview_school do |c| %> | ||
<% if @title.present? %> | ||
<% c.with_title { @title } %> | ||
<% end %> | ||
<% if @subtitle.present? %> | ||
<% c.with_subtitle { @subtitle } %> | ||
<% end %> | ||
<% if @footer.present? %> | ||
<% c.with_footer { @footer } %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -479,6 +479,8 @@ | |
end | ||
end | ||
|
||
resources :chart_previews | ||
|
||
namespace :emails do | ||
resources :alert_mailers, only: :show | ||
end | ||
|