From 8dc503f4543cc59780eb1b0dc55245eb47a8410f Mon Sep 17 00:00:00 2001 From: Nelson Jovel Date: Thu, 27 Jun 2024 10:58:45 -0700 Subject: [PATCH] feat: restore hotwire functionality on analyze page --- app/controllers/analyze_controller.rb | 1 + .../controllers/analyze_controller.js | 149 ++---------------- app/models/academic_year.rb | 4 + app/models/gender.rb | 4 + app/presenters/analyze/graph/all_data.rb | 9 ++ .../analyze/graph/column/all_teacher.rb | 4 +- .../graph/column/ell_column/ell_count.rb | 4 +- .../column/gender_column/gender_count.rb | 4 +- .../analyze/graph/column/grade/grade_count.rb | 4 +- .../column/grouped_bar_column_presenter.rb | 4 - .../column/income_column/disadvantaged.rb | 1 - .../column/income_column/income_count.rb | 4 +- .../column/income_column/not_disadvantaged.rb | 1 - .../graph/column/income_column/unknown.rb | 1 - .../graph/column/race_column/race_count.rb | 4 +- .../graph/column/sped_column/sped_count.rb | 4 +- .../analyze/graph/students_and_teachers.rb | 12 +- .../analyze/graph/students_by_ell.rb | 8 + .../analyze/graph/students_by_gender.rb | 8 + .../analyze/graph/students_by_grade.rb | 8 + .../analyze/graph/students_by_income.rb | 8 + .../analyze/graph/students_by_race.rb | 8 + .../analyze/graph/students_by_sped.rb | 8 + app/presenters/analyze/group/ell.rb | 4 + app/presenters/analyze/group/gender.rb | 8 +- app/presenters/analyze/group/grade.rb | 8 +- app/presenters/analyze/group/income.rb | 8 +- app/presenters/analyze/group/race.rb | 8 +- app/presenters/analyze/group/sped.rb | 4 + app/presenters/analyze/presenter.rb | 118 +++++++------- app/presenters/analyze/slice/all_data.rb | 10 +- .../analyze/slice/students_and_teachers.rb | 8 +- .../analyze/slice/students_by_group.rb | 15 +- app/presenters/analyze/source/all_data.rb | 5 +- app/presenters/analyze/source/survey_data.rb | 5 +- app/views/analyze/_checkboxes.html.erb | 14 +- app/views/analyze/_data_filters.html.erb | 84 ++++++---- app/views/analyze/_focus_area.html.erb | 54 +++++-- app/views/analyze/_group_selectors.html.erb | 63 ++++++-- app/views/analyze/_grouped_bar_chart.html.erb | 1 - .../analyze/_grouped_bar_column.html.erb | 2 +- app/views/analyze/_school_years.html.erb | 18 ++- .../20240607195831_add_slug_to_gender.rb | 6 + ...0240607205816_add_slug_to_academic_year.rb | 6 + db/schema.rb | 6 +- 45 files changed, 383 insertions(+), 334 deletions(-) create mode 100644 db/migrate/20240607195831_add_slug_to_gender.rb create mode 100644 db/migrate/20240607205816_add_slug_to_academic_year.rb diff --git a/app/controllers/analyze_controller.rb b/app/controllers/analyze_controller.rb index f46fa907..d50837ea 100644 --- a/app/controllers/analyze_controller.rb +++ b/app/controllers/analyze_controller.rb @@ -4,5 +4,6 @@ class AnalyzeController < SqmApplicationController def index @presenter = Analyze::Presenter.new(params:, school: @school, academic_year: @academic_year) @background ||= BackgroundPresenter.new(num_of_columns: @presenter.graph.columns.count) + @academic_year = @presenter.selected_academic_years&.first || AcademicYear.last end end diff --git a/app/javascript/controllers/analyze_controller.js b/app/javascript/controllers/analyze_controller.js index e839be5f..45ea0905 100644 --- a/app/javascript/controllers/analyze_controller.js +++ b/app/javascript/controllers/analyze_controller.js @@ -1,152 +1,25 @@ import { Controller } from "@hotwired/stimulus"; +import debounce from "debounce"; // Connects to data-controller="analyze" export default class extends Controller { - connect() { } - refresh(event) { - let base_url = event.target.value; - let target = event.target; - console.log(this.selected_slice(target)) - console.log(target.name) + static targets = ["category", "subcategory"] - let url = - base_url + - "&academic_years=" + - this.selected_years().join(",") + - "&source=" + - this.selected_source(target) + - "&slice=" + - this.selected_slice(target) + - "&group=" + - this.selected_group() + - "&graph=" + - this.selected_graph(target) + - "&races=" + - this.selected_items("race").join(",") + - "&genders=" + - this.selected_items("gender").join(",") + - "&incomes=" + - this.selected_items("income").join(",") + - "&grades=" + - this.selected_items("grade").join(",") + - "&ells=" + - this.selected_items("ell").join(",") + - "&speds=" + - this.selected_items("sped").join(","); - - this.go_to(url); - } - - go_to(location) { - window.location = location; - } - - selected_years() { - let year_checkboxes = [...document.getElementsByName("year-checkbox")]; - let years = year_checkboxes - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id; - }); - - return years; + initialize() { + this.submit = debounce(this.submit.bind(this), 300) } - selected_group() { - let groups = [...document.getElementsByName("group-option")]; - let selected_group = groups - .filter((item) => { - return item.selected; - }) - .map((item) => { - return item.id; - }); - - return selected_group[0]; - } + connect() { + const collection = document.getElementsByClassName("popover"); - selected_source(target) { - if (target.name === 'source') { - return target.id; + for (let i = 0; i < collection.length; i++) { + collection[i].parentNode.removeChild(collection[i]); } - if (target.name === 'slice' || target.name === 'group') { - return 'survey-data-only'; - } - - return window.source; - } - - selected_slice(target) { - if (target.name === 'source' && target.id === 'all-data') { - return 'all-data'; - } - if (target.name === 'source' && target.id === 'survey-data-only') { - return 'students-and-teachers'; - } - - if (target.name === 'group') { - return 'students-by-group'; - } - - if (target.name === 'source' || target.name === 'slice') { - let slices = [...document.getElementsByName("slice")]; - let selected_slice = slices - .filter((item) => { - return item.id != "all-data"; - }) - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id; - }); - - return selected_slice[0]; - } - - return window.slice; - } - - selected_graph(target) { - if (target.name === 'source' && target.id === 'all-data') { - return 'all-data' - } - if (target.name === 'source' && target.id === 'survey-data-only') { - return 'students-and-teachers' - } - - let graphs = [...document.getElementsByName("slice")]; - let selected_slice = graphs - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id; - })[0]; - - if (target.name === 'slice' || target.name === 'group') { - if (selected_slice === 'students-and-teachers') { - return 'students-and-teachers'; - } - return `students-by-${this.selected_group()}`; - } - - return window.graph; - } - selected_items(type) { - let checkboxes = [...document.getElementsByName(`${type}-checkbox`)] - let items = checkboxes - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id.replace(`${type}-`, ''); - }); + submit() { + console.log("Submitting form"); - return items; + this.element.requestSubmit(); } } diff --git a/app/models/academic_year.rb b/app/models/academic_year.rb index 8e7d1f24..5732d80a 100644 --- a/app/models/academic_year.rb +++ b/app/models/academic_year.rb @@ -3,6 +3,9 @@ require "date" class AcademicYear < ActiveRecord::Base + include FriendlyId + friendly_id :range, use: [:slugged] + scope :by_range, -> { all.map { |academic_year| [academic_year.range, academic_year] }.to_h } scope :of_year, ->(range) { all.select { |ay| ay.range.start_with?(range) } } @@ -58,3 +61,4 @@ class AcademicYear < ActiveRecord::Base end AcademicYearRange = Struct.new(:start, :end, :season) + diff --git a/app/models/gender.rb b/app/models/gender.rb index e32bdcdc..91a34a4f 100644 --- a/app/models/gender.rb +++ b/app/models/gender.rb @@ -1,4 +1,7 @@ class Gender < ApplicationRecord + include FriendlyId + friendly_id :designation, use: [:slugged] + scope :by_qualtrics_code, lambda { all.map { |gender| [gender.qualtrics_code, gender] }.to_h } @@ -32,3 +35,4 @@ class Gender < ApplicationRecord end end end + diff --git a/app/presenters/analyze/graph/all_data.rb b/app/presenters/analyze/graph/all_data.rb index 99194d86..9b0f7270 100644 --- a/app/presenters/analyze/graph/all_data.rb +++ b/app/presenters/analyze/graph/all_data.rb @@ -4,6 +4,7 @@ module Analyze module Graph class AllData include Analyze::Graph::Column + def to_s "All Data" end @@ -15,6 +16,14 @@ module Analyze def columns [AllStudent, AllTeacher, AllAdmin, Analyze::Graph::Column::AllData] end + + def source + Analyze::Source::AllData.new(slices: [slice]) + end + + def slice + Analyze::Slice::AllData.new + end end end end diff --git a/app/presenters/analyze/graph/column/all_teacher.rb b/app/presenters/analyze/graph/column/all_teacher.rb index bce18c72..4495bfe5 100644 --- a/app/presenters/analyze/graph/column/all_teacher.rb +++ b/app/presenters/analyze/graph/column/all_teacher.rb @@ -32,9 +32,9 @@ module Analyze :teacher end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(survey_item: measure.teacher_survey_items, school:, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).pluck(:response_id).uniq.count end end end diff --git a/app/presenters/analyze/graph/column/ell_column/ell_count.rb b/app/presenters/analyze/graph/column/ell_column/ell_count.rb index 66c0ca79..582d7221 100644 --- a/app/presenters/analyze/graph/column/ell_column/ell_count.rb +++ b/app/presenters/analyze/graph/column/ell_column/ell_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(ell:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/column/gender_column/gender_count.rb b/app/presenters/analyze/graph/column/gender_column/gender_count.rb index 874c7cde..ad0c4e72 100644 --- a/app/presenters/analyze/graph/column/gender_column/gender_count.rb +++ b/app/presenters/analyze/graph/column/gender_column/gender_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(gender:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/column/grade/grade_count.rb b/app/presenters/analyze/graph/column/grade/grade_count.rb index 42ed3a23..a12aeba7 100644 --- a/app/presenters/analyze/graph/column/grade/grade_count.rb +++ b/app/presenters/analyze/graph/column/grade/grade_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(grade:, survey_item: measure.student_survey_items, school:, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb b/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb index fd4b8ce0..08480c57 100644 --- a/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb +++ b/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb @@ -34,10 +34,6 @@ module Analyze raise NotImplementedError end - def basis - "" - end - def show_irrelevancy_message? raise NotImplementedError end diff --git a/app/presenters/analyze/graph/column/income_column/disadvantaged.rb b/app/presenters/analyze/graph/column/income_column/disadvantaged.rb index ea079577..6765d641 100644 --- a/app/presenters/analyze/graph/column/income_column/disadvantaged.rb +++ b/app/presenters/analyze/graph/column/income_column/disadvantaged.rb @@ -27,4 +27,3 @@ module Analyze end end end - diff --git a/app/presenters/analyze/graph/column/income_column/income_count.rb b/app/presenters/analyze/graph/column/income_column/income_count.rb index a61bdc61..886459d1 100644 --- a/app/presenters/analyze/graph/column/income_column/income_count.rb +++ b/app/presenters/analyze/graph/column/income_column/income_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(income:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/column/income_column/not_disadvantaged.rb b/app/presenters/analyze/graph/column/income_column/not_disadvantaged.rb index aea9ce83..cfca2baf 100644 --- a/app/presenters/analyze/graph/column/income_column/not_disadvantaged.rb +++ b/app/presenters/analyze/graph/column/income_column/not_disadvantaged.rb @@ -27,4 +27,3 @@ module Analyze end end end - diff --git a/app/presenters/analyze/graph/column/income_column/unknown.rb b/app/presenters/analyze/graph/column/income_column/unknown.rb index bc8c6d2c..7a03580e 100644 --- a/app/presenters/analyze/graph/column/income_column/unknown.rb +++ b/app/presenters/analyze/graph/column/income_column/unknown.rb @@ -27,4 +27,3 @@ module Analyze end end end - diff --git a/app/presenters/analyze/graph/column/race_column/race_count.rb b/app/presenters/analyze/graph/column/race_column/race_count.rb index b46d3de1..17a59f55 100644 --- a/app/presenters/analyze/graph/column/race_column/race_count.rb +++ b/app/presenters/analyze/graph/column/race_column/race_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.joins("JOIN student_races on survey_item_responses.student_id = student_races.student_id JOIN students on students.id = student_races.student_id").where( - school:, academic_year: academic_years[year_index], + school:, academic_year:, survey_item: measure.student_survey_items ).where("student_races.race_id": race.id).select(:response_id).distinct.count end diff --git a/app/presenters/analyze/graph/column/sped_column/sped_count.rb b/app/presenters/analyze/graph/column/sped_column/sped_count.rb index 61975708..eb88311a 100644 --- a/app/presenters/analyze/graph/column/sped_column/sped_count.rb +++ b/app/presenters/analyze/graph/column/sped_column/sped_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(sped:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/students_and_teachers.rb b/app/presenters/analyze/graph/students_and_teachers.rb index 482f817e..8d29538b 100644 --- a/app/presenters/analyze/graph/students_and_teachers.rb +++ b/app/presenters/analyze/graph/students_and_teachers.rb @@ -5,16 +5,24 @@ module Analyze class StudentsAndTeachers include Analyze::Graph::Column def to_s - 'Students & Teachers' + "Students & Teachers" end def slug - 'students-and-teachers' + "students-and-teachers" end def columns [AllStudent, AllTeacher, AllSurveyData] end + + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsAndTeachers.new + end end end end diff --git a/app/presenters/analyze/graph/students_by_ell.rb b/app/presenters/analyze/graph/students_by_ell.rb index 7431faad..1188d405 100644 --- a/app/presenters/analyze/graph/students_by_ell.rb +++ b/app/presenters/analyze/graph/students_by_ell.rb @@ -28,6 +28,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_ell_code(code:) diff --git a/app/presenters/analyze/graph/students_by_gender.rb b/app/presenters/analyze/graph/students_by_gender.rb index 97d33634..ccd1d2a5 100644 --- a/app/presenters/analyze/graph/students_by_gender.rb +++ b/app/presenters/analyze/graph/students_by_gender.rb @@ -28,6 +28,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_gender_code(code:) diff --git a/app/presenters/analyze/graph/students_by_grade.rb b/app/presenters/analyze/graph/students_by_grade.rb index a59e71b6..1723e240 100644 --- a/app/presenters/analyze/graph/students_by_grade.rb +++ b/app/presenters/analyze/graph/students_by_grade.rb @@ -27,6 +27,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_grade_code(code:) diff --git a/app/presenters/analyze/graph/students_by_income.rb b/app/presenters/analyze/graph/students_by_income.rb index e72b6efb..d28be884 100644 --- a/app/presenters/analyze/graph/students_by_income.rb +++ b/app/presenters/analyze/graph/students_by_income.rb @@ -26,6 +26,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_income_code(code:) diff --git a/app/presenters/analyze/graph/students_by_race.rb b/app/presenters/analyze/graph/students_by_race.rb index 74a7cb8f..d3e3507c 100644 --- a/app/presenters/analyze/graph/students_by_race.rb +++ b/app/presenters/analyze/graph/students_by_race.rb @@ -26,6 +26,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_race_code(code:) diff --git a/app/presenters/analyze/graph/students_by_sped.rb b/app/presenters/analyze/graph/students_by_sped.rb index 6129d62c..bc5c4289 100644 --- a/app/presenters/analyze/graph/students_by_sped.rb +++ b/app/presenters/analyze/graph/students_by_sped.rb @@ -27,6 +27,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_sped_code(code:) diff --git a/app/presenters/analyze/group/ell.rb b/app/presenters/analyze/group/ell.rb index 512b3d5b..628ef0ca 100644 --- a/app/presenters/analyze/group/ell.rb +++ b/app/presenters/analyze/group/ell.rb @@ -8,6 +8,10 @@ module Analyze def slug "ell" end + + def graph + Analyze::Graph::StudentsByEll.new(ells: nil) + end end end end diff --git a/app/presenters/analyze/group/gender.rb b/app/presenters/analyze/group/gender.rb index 901d24d8..9810d893 100644 --- a/app/presenters/analyze/group/gender.rb +++ b/app/presenters/analyze/group/gender.rb @@ -2,11 +2,15 @@ module Analyze module Group class Gender def name - 'Gender' + "Gender" end def slug - 'gender' + "gender" + end + + def graph + Analyze::Graph::StudentsByGender.new(genders: nil) end end end diff --git a/app/presenters/analyze/group/grade.rb b/app/presenters/analyze/group/grade.rb index 9504469c..67149012 100644 --- a/app/presenters/analyze/group/grade.rb +++ b/app/presenters/analyze/group/grade.rb @@ -2,11 +2,15 @@ module Analyze module Group class Grade def name - 'Grade' + "Grade" end def slug - 'grade' + "grade" + end + + def graph + Analyze::Graph::StudentsByGrade.new(grades: nil) end end end diff --git a/app/presenters/analyze/group/income.rb b/app/presenters/analyze/group/income.rb index 21e364b4..74ba80c0 100644 --- a/app/presenters/analyze/group/income.rb +++ b/app/presenters/analyze/group/income.rb @@ -2,11 +2,15 @@ module Analyze module Group class Income def name - 'Income' + "Income" end def slug - 'income' + "income" + end + + def graph + Analyze::Graph::StudentsByIncome.new(incomes: nil) end end end diff --git a/app/presenters/analyze/group/race.rb b/app/presenters/analyze/group/race.rb index 1155d1c4..fec01545 100644 --- a/app/presenters/analyze/group/race.rb +++ b/app/presenters/analyze/group/race.rb @@ -2,11 +2,15 @@ module Analyze module Group class Race def name - 'Race' + "Race" end def slug - 'race' + "race" + end + + def graph + Analyze::Graph::StudentsByRace.new(races: nil) end end end diff --git a/app/presenters/analyze/group/sped.rb b/app/presenters/analyze/group/sped.rb index 6f4b2216..cfe1e76e 100644 --- a/app/presenters/analyze/group/sped.rb +++ b/app/presenters/analyze/group/sped.rb @@ -8,6 +8,10 @@ module Analyze def slug "sped" end + + def graph + Analyze::Graph::StudentsBySped.new(speds: nil) + end end end end diff --git a/app/presenters/analyze/presenter.rb b/app/presenters/analyze/presenter.rb index af0cd0d4..94e753e2 100644 --- a/app/presenters/analyze/presenter.rb +++ b/app/presenters/analyze/presenter.rb @@ -5,7 +5,6 @@ module Analyze def initialize(params:, school:, academic_year:) @params = params @school = school - @academic_year = academic_year end def category @@ -34,10 +33,16 @@ module Analyze def selected_academic_years @selected_academic_years ||= begin - year_params = params[:academic_years] - return [] unless year_params + array = [] - year_params.split(",").map { |year| AcademicYear.find_by_range(year) }.compact + keys = params.keys.select { |key| key.start_with? "academic_year" } + keys.each do |key| + year_params = params[key]&.chomp + next if year_params.nil? + + array << AcademicYear.find_by_range(year_params) + end + array end end @@ -46,12 +51,7 @@ module Analyze end def selected_races - @selected_races ||= begin - race_params = params[:races] - return races unless race_params - - race_params.split(",").map { |race| Race.find_by_slug race }.compact - end + @selected_races ||= selected_items(name: "race", list: races) end def ells @@ -59,12 +59,15 @@ module Analyze end def selected_ells - @selected_ells ||= begin - ell_params = params[:ells] - return ells unless ell_params + @selected_ells ||= selected_items(name: "ell", list: ells) + end - ell_params.split(",").map { |ell| Ell.find_by_slug ell }.compact - end + def selected_items(name:, list:) + selected_params = params.select { |key, _| key.start_with?(name) && key.end_with?("checkbox") } + return list unless selected_params.keys.length.positive? + + selected_params.values + .map { |slug| list.find { |item| item.slug == slug } } end def speds @@ -72,47 +75,20 @@ module Analyze end def selected_speds - @selected_speds ||= begin - sped_params = params[:speds] - return speds unless sped_params - - sped_params.split(",").map { |sped| Sped.find_by_slug sped }.compact - end - end - - def graphs - @graphs ||= [Analyze::Graph::AllData.new, - Analyze::Graph::StudentsAndTeachers.new, - Analyze::Graph::StudentsByRace.new(races: selected_races), - Analyze::Graph::StudentsByGrade.new(grades:), - Analyze::Graph::StudentsByGender.new(genders: selected_genders), - Analyze::Graph::StudentsByIncome.new(incomes: selected_incomes), - Analyze::Graph::StudentsByEll.new(ells: selected_ells), - Analyze::Graph::StudentsBySped.new(speds: selected_speds)] - end - - def graph - @graph ||= graphs.reduce(graphs.first) do |acc, graph| - graph.slug == params[:graph] ? graph : acc - end + @selected_speds ||= selected_items(name: "sped", list: speds) end def selected_grades @selected_grades ||= begin - grade_params = params[:grades] - return grades unless grade_params + selected_params = params.select { |key, _| key.start_with?("grade") && key.end_with?("checkbox") } + return grades unless selected_params.keys.length.positive? - grade_params.split(",").map(&:to_i) + selected_params.values.map(&:to_i) end end def selected_genders - @selected_genders ||= begin - gender_params = params[:genders] - return genders unless gender_params - - gender_params.split(",").sort.map { |gender| Gender.find_by_designation(gender) }.compact - end + @selected_genders ||= selected_items(name: "gender", list: genders) end def genders @@ -131,33 +107,53 @@ module Analyze end def slice - @slice ||= slices.reduce(slices.first) do |acc, slice| - slice.slug == params[:slice] ? slice : acc - end + @slice ||= graph.slice || slices.first end def slices - source.slices + graphs.map { |graph| graph.slice }.uniq end def source - @source ||= sources.reduce(sources.first) do |acc, source| - source.slug == params[:source] ? source : acc - end + @source ||= graph&.source || sources.first end def sources - all_data_slices = [Analyze::Slice::AllData.new] + all_data_slice = Analyze::Slice::AllData.new + all_data_slice.graph = Analyze::Graph::AllData.new + all_data_slices = [all_data_slice] + all_data_source = Analyze::Source::AllData.new(slices: all_data_slices) + all_data_source.graph = Analyze::Graph::AllData.new students_and_teachers = Analyze::Slice::StudentsAndTeachers.new - students_by_group = Analyze::Slice::StudentsByGroup.new(races:, grades:) + students_by_group = Analyze::Slice::StudentsByGroup.new + students_by_group.graph = Analyze::Graph::StudentsByEll.new(ells: selected_ells) + survey_data_slices = [students_and_teachers, students_by_group] survey_data_source = Analyze::Source::SurveyData.new(slices: survey_data_slices) + survey_data_source.graph = Analyze::Graph::StudentsAndTeachers.new @sources = [all_data_source, survey_data_source] end + def graphs + @graphs ||= [Analyze::Graph::AllData.new, + Analyze::Graph::StudentsAndTeachers.new, + Analyze::Graph::StudentsByRace.new(races: selected_races), + Analyze::Graph::StudentsByGrade.new(grades: selected_grades), + Analyze::Graph::StudentsByGender.new(genders: selected_genders), + Analyze::Graph::StudentsByIncome.new(incomes: selected_incomes), + Analyze::Graph::StudentsByEll.new(ells: selected_ells), + Analyze::Graph::StudentsBySped.new(speds: selected_speds)] + end + + def graph + @graph ||= graphs.find do |graph| + graph.slug == params[:graph] + end || graphs.first + end + def grades @grades ||= SurveyItemResponse.where(school:, academic_year: academic_years) .where.not(grade: nil) @@ -174,16 +170,12 @@ module Analyze end def selected_incomes - @selected_incomes ||= begin - income_params = params[:incomes] - return incomes unless income_params - - income_params.split(",").map { |income| Income.find_by_slug(income) }.compact - end + @selected_incomes ||= selected_items(name: "income", list: incomes) end def cache_objects - [subcategory, + [category, + subcategory, selected_academic_years, graph, selected_races, diff --git a/app/presenters/analyze/slice/all_data.rb b/app/presenters/analyze/slice/all_data.rb index 10137a78..326af4b2 100644 --- a/app/presenters/analyze/slice/all_data.rb +++ b/app/presenters/analyze/slice/all_data.rb @@ -1,16 +1,14 @@ module Analyze module Slice class AllData + attr_accessor :graph + def to_s - 'All Data' + "All Data" end def slug - 'all-data' - end - - def graphs - [Analyze::Graph::AllData.new] + "all-data" end end end diff --git a/app/presenters/analyze/slice/students_and_teachers.rb b/app/presenters/analyze/slice/students_and_teachers.rb index 75eb921b..e14ef29e 100644 --- a/app/presenters/analyze/slice/students_and_teachers.rb +++ b/app/presenters/analyze/slice/students_and_teachers.rb @@ -2,15 +2,15 @@ module Analyze module Slice class StudentsAndTeachers def to_s - 'Students & Teachers' + "Students & Teachers" end def slug - 'students-and-teachers' + "students-and-teachers" end - def graphs - [Analyze::Graph::StudentsAndTeachers.new] + def graph + Analyze::Graph::StudentsAndTeachers.new end end end diff --git a/app/presenters/analyze/slice/students_by_group.rb b/app/presenters/analyze/slice/students_by_group.rb index af62be61..ae91d060 100644 --- a/app/presenters/analyze/slice/students_by_group.rb +++ b/app/presenters/analyze/slice/students_by_group.rb @@ -1,23 +1,14 @@ module Analyze module Slice class StudentsByGroup - attr_reader :races, :grades - - def initialize(races:, grades:) - @races = races - @grades = grades - end + attr_accessor :graph def to_s - 'Students by Group' + "Students by Group" end def slug - 'students-by-group' - end - - def graphs - [Analyze::Graph::StudentsByRace.new(races:), Analyze::Graph::StudentsByGrade.new(grades:)] + "students-by-group" end end end diff --git a/app/presenters/analyze/source/all_data.rb b/app/presenters/analyze/source/all_data.rb index 72889904..181a8947 100644 --- a/app/presenters/analyze/source/all_data.rb +++ b/app/presenters/analyze/source/all_data.rb @@ -2,6 +2,7 @@ module Analyze module Source class AllData attr_reader :slices + attr_accessor :graph include Analyze::Slice @@ -10,11 +11,11 @@ module Analyze end def to_s - 'All Data' + "All Data" end def slug - 'all-data' + "all-data" end end end diff --git a/app/presenters/analyze/source/survey_data.rb b/app/presenters/analyze/source/survey_data.rb index 654020b6..8510999f 100644 --- a/app/presenters/analyze/source/survey_data.rb +++ b/app/presenters/analyze/source/survey_data.rb @@ -2,6 +2,7 @@ module Analyze module Source class SurveyData attr_reader :slices + attr_accessor :graph include Analyze::Slice @@ -10,11 +11,11 @@ module Analyze end def to_s - 'Survey Data Only' + "Survey Data Only" end def slug - 'survey-data-only' + "survey-data-only" end end end diff --git a/app/views/analyze/_checkboxes.html.erb b/app/views/analyze/_checkboxes.html.erb index d64d7e6b..eba16e09 100644 --- a/app/views/analyze/_checkboxes.html.erb +++ b/app/views/analyze/_checkboxes.html.erb @@ -1,17 +1,13 @@
-checkbox" + value="<%= item %>" <%= selected_items.include?(item) ? "checked" : "" %> - <%= @presenter.graph.slug == 'students-and-teachers' || @presenter.source.slug == 'all-data' ? "disabled" : "" %> - <%= @presenter.group.slug == name ? "" : "hidden" %>> - -
diff --git a/app/views/analyze/_data_filters.html.erb b/app/views/analyze/_data_filters.html.erb index 0cba336f..01466b54 100644 --- a/app/views/analyze/_data_filters.html.erb +++ b/app/views/analyze/_data_filters.html.erb @@ -1,41 +1,61 @@

Data Filters

-
+
<% @presenter.sources.each do |source| %> +<%= form_with(url: district_school_analyze_index_path, + method: :get, + data: { + turbo_frame: "results", + turbo_action: "advance", + controller: "analyze", + action: "input->analyze#submit" + }) do |f| %> + + <% params.reject{|key,_| key == "graph"}.each do |key, value| %> + + <% end %> > - - - <% source.slices.each do | slice | %> -
- - <%= slice.slug == "all-data" ? "hidden" : "" %>> - - -
- <% end %> - <% end %> - - <%= render partial: "group_selectors" %> -
+ + + <% end %> + + - +<%= form_with(url: district_school_analyze_index_path, + method: :get, + data: { + turbo_frame: "results", + turbo_action: "advance", + controller: "analyze", + action: "input->analyze#submit" + }) do |f| %> + + <% params.reject{|key,_| key == "graph"}.each do |key, value| %> + + <% end %> + + <% source.slices.each do | slice | %> +
+ + <%= slice.slug == "all-data" ? "hidden" : "" %>> + + +
+ <% end %> + <% end %> +<% end %> + <%= render partial: "group_selectors" %> +
diff --git a/app/views/analyze/_focus_area.html.erb b/app/views/analyze/_focus_area.html.erb index 4887ddd6..d72753c5 100644 --- a/app/views/analyze/_focus_area.html.erb +++ b/app/views/analyze/_focus_area.html.erb @@ -1,14 +1,44 @@ -

Focus Area

-

Select a category & subcategory to analyze measure-level results

- <% end %> - - + <% categories.each do |category| %> + + <% end %> + +<% end %> + +<%= form_with(url: district_school_analyze_index_path, + method: :get, + data: { + turbo_frame: "results", + turbo_action: "advance", + controller: "analyze", + action: "input->analyze#submit" + }) do |f| %> + <% params.each do |key, value| %> + <% end %> - + + +<% end %> diff --git a/app/views/analyze/_group_selectors.html.erb b/app/views/analyze/_group_selectors.html.erb index e8bbd84c..5b85c945 100644 --- a/app/views/analyze/_group_selectors.html.erb +++ b/app/views/analyze/_group_selectors.html.erb @@ -1,31 +1,60 @@ - <% end %> - -

Select a group

+ + + + +

Select a group

+ +<% if @presenter.graph.slug == 'students-by-race' %> + <% @presenter.races.each_with_index do |race, index| %> + <%= render(partial: "checkboxes", locals: {id: "race-#{}#{race.slug}", item: race.slug, selected_items: @presenter.selected_races.map(&:slug), name: "race", label_text: race.designation, index: index })%> + <% end %> +<% end %> -<% @presenter.races.each do |race| %> - <%= render(partial: "checkboxes", locals: {id: "race-#{race.slug}", item: race, selected_items: @presenter.selected_races, name: "race", label_text: race.designation}) %> +<% if @presenter.graph.slug == 'students-by-grade' %> + <% @presenter.grades.each_with_index do |grade, index| %> + <%= render(partial: "checkboxes", locals: {id: "grade-#{grade}", item: grade, selected_items: @presenter.selected_grades, name: "grade", label_text: grade, index: index }) %> + <% end %> <% end %> -<% @presenter.grades.each do |grade| %> - <%= render(partial: "checkboxes", locals: {id: "grade-#{grade}", item: grade, selected_items: @presenter.selected_grades, name: "grade", label_text: grade}) %> +<% if @presenter.graph.slug == 'students-by-gender' %> + <% @presenter.genders.each_with_index do |gender, index| %> + <%= render(partial: "checkboxes", locals: {id: "gender-#{gender.designation}", item: gender.slug, selected_items: @presenter.selected_genders.map(&:slug), name: "gender", label_text: gender.designation, index: index }) %> + <% end %> <% end %> -<% @presenter.genders.each do |gender| %> - <%= render(partial: "checkboxes", locals: {id: "gender-#{gender.designation}", item: gender, selected_items: @presenter.selected_genders, name: "gender", label_text: gender.designation}) %> +<% if @presenter.graph.slug == 'students-by-income' %> + <% @presenter.incomes.each_with_index do |income, index| %> + <%= render(partial: "checkboxes", locals: {id: "income-#{income.slug}", item: income.slug, selected_items: @presenter.selected_incomes.map(&:slug), name: "income", label_text: income.label, index: index })%> + <% end %> <% end %> -<% @presenter.incomes.each do |income| %> - <%= render(partial: "checkboxes", locals: {id: "income-#{income.slug}", item: income, selected_items: @presenter.selected_incomes, name: "income", label_text: income.label}) %> +<% if @presenter.graph.slug == 'students-by-ell' %> + <% @presenter.ells.each_with_index do |ell, index| %> + <%= render(partial: "checkboxes", locals: {id: "ell-#{ell.slug}", item: ell.slug, selected_items: @presenter.selected_ells.map(&:slug), name: "ell", label_text: ell.designation, index: index}) %> + <% end %> <% end %> -<% @presenter.ells.each do |ell| %> - <%= render(partial: "checkboxes", locals: {id: "ell-#{ell.slug}", item: ell, selected_items: @presenter.selected_ells, name: "ell", label_text: ell.designation}) %> +<% if @presenter.graph.slug == 'students-by-sped' %> + <% @presenter.speds.each_with_index do |sped, index| %> + <%= render(partial: "checkboxes", locals: {id: "sped-#{sped.slug}", item: sped.slug, selected_items: @presenter.selected_speds.map(&:slug), name: "sped", label_text: sped.designation, index: index}) %> + <% end %> <% end %> -<% @presenter.speds.each do |sped| %> - <%= render(partial: "checkboxes", locals: {id: "sped-#{sped.slug}", item: sped, selected_items: @presenter.selected_speds, name: "sped", label_text: sped.designation}) %> <% end %> diff --git a/app/views/analyze/_grouped_bar_chart.html.erb b/app/views/analyze/_grouped_bar_chart.html.erb index 47feb8eb..944cde5a 100644 --- a/app/views/analyze/_grouped_bar_chart.html.erb +++ b/app/views/analyze/_grouped_bar_chart.html.erb @@ -6,5 +6,4 @@ <% p = column.new(measure: measure, school: @school, academic_years: @presenter.selected_academic_years, position: index , number_of_columns:) %> <%= render partial: "grouped_bar_column", locals: {column: p} %> <% end %> - diff --git a/app/views/analyze/_grouped_bar_column.html.erb b/app/views/analyze/_grouped_bar_column.html.erb index 17bce6f4..2970e436 100644 --- a/app/views/analyze/_grouped_bar_column.html.erb +++ b/app/views/analyze/_grouped_bar_column.html.erb @@ -5,7 +5,7 @@ <% if column.show_popover? %> data-bs-toggle="popover" data-bs-placement="right" - data-bs-content="<%= column.popover_content(index) %>" + data-bs-content="<%= column.popover_content(bar.academic_year) %>" <% end %> data-for-academic-year="<%= bar.academic_year.range %>" diff --git a/app/views/analyze/_school_years.html.erb b/app/views/analyze/_school_years.html.erb index 968000ce..3b7b432a 100644 --- a/app/views/analyze/_school_years.html.erb +++ b/app/views/analyze/_school_years.html.erb @@ -1,13 +1,24 @@ +<%= form_with(url: district_school_analyze_index_path, + method: :get, + data: { + turbo_frame: "results", + turbo_action: "advance", + controller: "form", + action: "input->form#submit" + }) do |f| %> + <% params.reject{|key,_| key.start_with?("academic_year")}.each do |key, value| %> + +<% end %> +

School Years

<% available_academic_years.each_with_index do | year, index | %>
- data-action="click->analyze#refresh" <% empty_dataset = empty_dataset?(measures: measures, school: school, academic_year: year) %> <% empty_survey_dataset = empty_survey_dataset?(measures: measures, school: school, academic_year: year) %> <% if graph.slug == 'all-data' %> @@ -32,3 +43,4 @@ <% end %>
<% end %> +<% end %> diff --git a/db/migrate/20240607195831_add_slug_to_gender.rb b/db/migrate/20240607195831_add_slug_to_gender.rb new file mode 100644 index 00000000..0604b363 --- /dev/null +++ b/db/migrate/20240607195831_add_slug_to_gender.rb @@ -0,0 +1,6 @@ +class AddSlugToGender < ActiveRecord::Migration[7.1] + def change + add_column :genders, :slug, :string + add_index :genders, :slug, unique: true + end +end diff --git a/db/migrate/20240607205816_add_slug_to_academic_year.rb b/db/migrate/20240607205816_add_slug_to_academic_year.rb new file mode 100644 index 00000000..09adcdf0 --- /dev/null +++ b/db/migrate/20240607205816_add_slug_to_academic_year.rb @@ -0,0 +1,6 @@ +class AddSlugToAcademicYear < ActiveRecord::Migration[7.1] + def change + add_column :academic_years, :slug, :string + add_index :academic_years, :slug, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 64ca755a..37ddcaac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_12_27_183313) do +ActiveRecord::Schema[7.1].define(version: 2024_06_07_205816) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -19,7 +19,9 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_27_183313) do t.string "range", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "slug" t.index ["range"], name: "index_academic_years_on_range", unique: true + t.index ["slug"], name: "index_academic_years_on_slug", unique: true end create_table "admin_data_items", force: :cascade do |t| @@ -83,6 +85,8 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_27_183313) do t.string "designation" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "slug" + t.index ["slug"], name: "index_genders_on_slug", unique: true end create_table "incomes", force: :cascade do |t|