mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Expand the Measured Dashboard to All Schools and Districts. [Finishes #179727798]
This commit is contained in:
parent
87f268dd7a
commit
cc2f3f9352
6 changed files with 115 additions and 6 deletions
34
app/assets/javascripts/dashboard.js
Normal file
34
app/assets/javascripts/dashboard.js
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
const selectSchoolElement = document.querySelector('#select-school');
|
||||||
|
|
||||||
|
selectSchoolElement.addEventListener('change', (event) => {
|
||||||
|
change_school(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectDistrictElement = document.querySelector('#select-district');
|
||||||
|
|
||||||
|
selectDistrictElement.addEventListener('change', (event) => {
|
||||||
|
change_district(event);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function change_school(event) {
|
||||||
|
const school_slug = event.target.value;
|
||||||
|
|
||||||
|
const district_regex = /districts\/(.+)\/schools/;
|
||||||
|
const district_slug = window.location.pathname.match(district_regex)[1];
|
||||||
|
|
||||||
|
const year_range_regex = /year=(.+)/;
|
||||||
|
const year_range = window.location.search.match(year_range_regex)[1];
|
||||||
|
|
||||||
|
window.location = `/districts/${district_slug}/schools/${school_slug}/dashboard?year=${year_range}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
function change_district(event) {
|
||||||
|
const district_slug = event.target.value;
|
||||||
|
|
||||||
|
const year_range_regex = /year=(.+)/;
|
||||||
|
const year_range = window.location.search.match(year_range_regex)[1];
|
||||||
|
|
||||||
|
window.location = `/districts/${district_slug}/schools/first/dashboard?year=${year_range}`;
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
class DashboardController < ApplicationController
|
class DashboardController < ApplicationController
|
||||||
def index
|
def index
|
||||||
|
schools
|
||||||
|
districts
|
||||||
authenticate(district.name.downcase, "#{district.name.downcase}!")
|
authenticate(district.name.downcase, "#{district.name.downcase}!")
|
||||||
@measure_graph_row_presenters = measure_ids
|
@measure_graph_row_presenters = measure_ids
|
||||||
.map { |measure_id| Measure.find_by_measure_id measure_id }
|
.map { |measure_id| Measure.find_by_measure_id measure_id }
|
||||||
|
|
@ -23,13 +25,22 @@ class DashboardController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def school
|
def school
|
||||||
|
@school = schools.first if params[:school_id] == "first"
|
||||||
@school ||= School.find_by_slug school_slug
|
@school ||= School.find_by_slug school_slug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def schools
|
||||||
|
@schools = School.where(district: district).sort_by { | school| school.name }
|
||||||
|
end
|
||||||
|
|
||||||
def district
|
def district
|
||||||
@district ||= District.find_by_slug district_slug
|
@district ||= District.find_by_slug district_slug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def districts
|
||||||
|
@districts = District.all.sort_by {|district| district.name}
|
||||||
|
end
|
||||||
|
|
||||||
def district_slug
|
def district_slug
|
||||||
params[:district_id]
|
params[:district_id]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
class SurveyResponseAggregator
|
class SurveyResponseAggregator
|
||||||
|
# Returns an average score for all SurveyItemResponses for the given AcademicYear, School, and Measure
|
||||||
def self.score(academic_year:, school:, measure:)
|
def self.score(academic_year:, school:, measure:)
|
||||||
SurveyItemResponse
|
SurveyItemResponse
|
||||||
.where(academic_year: academic_year, school: school)
|
.where(academic_year: academic_year, school: school)
|
||||||
|
|
@ -6,4 +7,11 @@ class SurveyResponseAggregator
|
||||||
.map { |survey_item_response| survey_item_response.likert_score }
|
.map { |survey_item_response| survey_item_response.likert_score }
|
||||||
.average
|
.average
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns an array of SurveyItemResponses for the given AcademicYear, School, and Measure
|
||||||
|
def self.find_responses_by_measure(academic_year:, school:, measure:)
|
||||||
|
SurveyItemResponse
|
||||||
|
.where(academic_year: academic_year, school: school)
|
||||||
|
.joins(:survey_item).where('survey_items.measure_id': measure.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,20 @@
|
||||||
<option value="<%= @academic_year %>" selected><%= format_academic_year(@academic_year) %></option>
|
<option value="<%= @academic_year %>" selected><%= format_academic_year(@academic_year) %></option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select class="ml-3 custom-select-lg" name="district">
|
<select id="select-district" class="ml-3 custom-select-lg" name="district">
|
||||||
<option value="<%= @district.slug %>" selected><%= @district.name %></option>
|
<% @districts.each do |district| %>
|
||||||
|
<option class="district-options" value="<%= district.slug %>" <%= @district.slug == district.slug ? "selected" : nil %>>
|
||||||
|
<%= district.name %>
|
||||||
|
</option>
|
||||||
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select class="ml-3 custom-select-lg" name="school">
|
<select id="select-school" class="ml-3 custom-select-lg" name="school">
|
||||||
<option value="<%= @school.slug %>" selected><%= @school.name %></option>
|
<% @schools.each do |school| %>
|
||||||
|
<option class="school-options" value="<%= school.slug %>" <%= @school.slug == school.slug ? "selected" : nil %> >
|
||||||
|
<%= school.name %>
|
||||||
|
</option>
|
||||||
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ require 'rails_helper'
|
||||||
feature 'School dashboard', type: feature do
|
feature 'School dashboard', type: feature do
|
||||||
let(:district) { District.find_by_slug 'winchester' }
|
let(:district) { District.find_by_slug 'winchester' }
|
||||||
let(:school) { School.find_by_slug 'winchester-high-school' }
|
let(:school) { School.find_by_slug 'winchester-high-school' }
|
||||||
|
let(:school_in_same_district) { School.find_by_slug 'muraco-elementary-school' }
|
||||||
|
|
||||||
let(:measure_1A_i) { Measure.find_by_measure_id('1A-i') }
|
let(:measure_1A_i) { Measure.find_by_measure_id('1A-i') }
|
||||||
let(:measure_2A_i) { Measure.find_by_measure_id('2A-i') }
|
let(:measure_2A_i) { Measure.find_by_measure_id('2A-i') }
|
||||||
|
|
@ -19,6 +20,9 @@ feature 'School dashboard', type: feature do
|
||||||
|
|
||||||
let(:ay_2020_21) { AcademicYear.find_by_range '2020-21' }
|
let(:ay_2020_21) { AcademicYear.find_by_range '2020-21' }
|
||||||
|
|
||||||
|
let(:username) { 'winchester' }
|
||||||
|
let(:password) { 'winchester!' }
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
SurveyItemResponse.create response_id: rand.to_s, academic_year: ay_2020_21, school: school,
|
SurveyItemResponse.create response_id: rand.to_s, academic_year: ay_2020_21, school: school,
|
||||||
survey_item: survey_item_1_for_measure_1A_i, likert_score: 4
|
survey_item: survey_item_1_for_measure_1A_i, likert_score: 4
|
||||||
|
|
@ -76,6 +80,43 @@ feature 'School dashboard', type: feature do
|
||||||
expect(professional_qualifications_row_index).to be < problem_solving_emphasis_row_index
|
expect(professional_qualifications_row_index).to be < problem_solving_emphasis_row_index
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:username) { 'winchester' }
|
# visit photos_path
|
||||||
let(:password) { 'winchester!' }
|
# assert_selector 'h1', text: 'Photos'
|
||||||
|
# assert_equal 1, all('.photo-deletable').count
|
||||||
|
# click_on 'Delete'
|
||||||
|
# page.driver.browser.switch_to.alert.accept
|
||||||
|
scenario 'user sees schools in the same district' do
|
||||||
|
page.driver.browser.basic_authorize(username, password)
|
||||||
|
visit "/districts/#{district.slug}/schools/#{school.slug}/dashboard?year=#{ay_2020_21.range}"
|
||||||
|
|
||||||
|
assert_selector "h1", text: school.name
|
||||||
|
|
||||||
|
expected_num_of_schools = district.schools.count
|
||||||
|
expect(page.all('.school-options').count).to eq expected_num_of_schools
|
||||||
|
expect(page.all('.school-options[selected]').count).to eq 1
|
||||||
|
expect(page.all('.school-options[selected]')[0].text).to eq 'Winchester High School'
|
||||||
|
|
||||||
|
school_options = page.all('.school-options')
|
||||||
|
school_options.each_with_index do |school , index|
|
||||||
|
break if index == school_options.length-1
|
||||||
|
expect(school.text).to be < school_options[index+1].text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'user sees all districts in dropdown menu' do
|
||||||
|
page.driver.browser.basic_authorize(username, password)
|
||||||
|
visit "/districts/#{district.slug}/schools/#{school.slug}/dashboard?year=#{ay_2020_21.range}"
|
||||||
|
|
||||||
|
expected_num_of_districts = District.count
|
||||||
|
expect(page.all('.district-options').count).to eq expected_num_of_districts
|
||||||
|
expect(page.all('.district-options[selected]').count).to eq 1
|
||||||
|
expect(page.all('.district-options[selected]')[0].text).to eq 'Winchester'
|
||||||
|
|
||||||
|
district_options = page.all('.district-options')
|
||||||
|
district_options.each_with_index do |district , index|
|
||||||
|
break if index == district_options.length-1
|
||||||
|
expect(district.text).to be < district_options[index+1].text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,11 @@ describe SurveyResponseAggregator do
|
||||||
expect(SurveyResponseAggregator.score(academic_year: ay_2021_22, school: school_b, measure: measure_b)).to eq 4.0
|
expect(SurveyResponseAggregator.score(academic_year: ay_2021_22, school: school_b, measure: measure_b)).to eq 4.0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.find_responses_by_measure' do
|
||||||
|
it 'returns all survey item responses corresponding to a year school and measure' do
|
||||||
|
expect(SurveyResponseAggregator.find_responses_by_measure(academic_year: ay_2020_21, school: school_a, measure: measure_a).count).to eq 2
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue