From 6764024cd250971d1f6e38172ccc9aff257b15df Mon Sep 17 00:00:00 2001 From: Nelson Jovel Date: Mon, 30 May 2022 16:44:18 -0700 Subject: [PATCH] Show subcategory data when user selects different subcategory from analyze dropdown. Finishes #182277850 --- app/controllers/analyze_controller.rb | 5 +++-- app/helpers/analyze_helper.rb | 4 ++++ app/javascript/controllers/analyze_controller.js | 2 +- app/presenters/grouped_bar_column_presenter.rb | 6 ++++++ app/views/analyze/_grouped_bar_column.html.erb | 4 ++-- app/views/analyze/index.html.erb | 7 ++++++- spec/system/journey_spec.rb | 16 ++++++++++++++-- spec/views/analyze/index.html.erb_spec.rb | 2 ++ 8 files changed, 38 insertions(+), 8 deletions(-) diff --git a/app/controllers/analyze_controller.rb b/app/controllers/analyze_controller.rb index 0fd74c04..06ccca8b 100644 --- a/app/controllers/analyze_controller.rb +++ b/app/controllers/analyze_controller.rb @@ -3,8 +3,9 @@ class AnalyzeController < SqmApplicationController @category ||= Category.find_by_category_id(params[:category]) @categories = Category.all.order(:category_id) - @subcategory ||= @category.subcategories.order(:subcategory_id).first - @subcategory ||= Subcategory.order(:subcategory_id).includes(%i[measures]).first + @subcategories = @category.subcategories.order(:subcategory_id) + @subcategory ||= Subcategory.find_by_subcategory_id(params[:subcategory]) + @subcategory ||= @subcategories.first @measures = @subcategory.measures.order(:measure_id).includes(%i[scales admin_data_items]) end diff --git a/app/helpers/analyze_helper.rb b/app/helpers/analyze_helper.rb index 43ad3382..9a6968af 100644 --- a/app/helpers/analyze_helper.rb +++ b/app/helpers/analyze_helper.rb @@ -62,4 +62,8 @@ module AnalyzeHelper def analyze_category_link(district:, school:, academic_year:, category:) "/districts/#{district.slug}/schools/#{school.slug}/analyze?year=#{academic_year.range}&category=#{category.category_id}" end + + def analyze_subcategory_link(district:, school:, academic_year:, category:, subcategory:) + "/districts/#{district.slug}/schools/#{school.slug}/analyze?year=#{academic_year.range}&category=#{category.category_id}&subcategory=#{subcategory.subcategory_id}" + end end diff --git a/app/javascript/controllers/analyze_controller.js b/app/javascript/controllers/analyze_controller.js index 705a265d..ed0d0ae2 100644 --- a/app/javascript/controllers/analyze_controller.js +++ b/app/javascript/controllers/analyze_controller.js @@ -3,7 +3,7 @@ import { Controller } from "@hotwired/stimulus" // Connects to data-controller="analyze" export default class extends Controller { connect() { } - change_category(event) { + refresh(event) { window.location = event.target.value } } diff --git a/app/presenters/grouped_bar_column_presenter.rb b/app/presenters/grouped_bar_column_presenter.rb index fdc90017..38adfab1 100644 --- a/app/presenters/grouped_bar_column_presenter.rb +++ b/app/presenters/grouped_bar_column_presenter.rb @@ -69,6 +69,12 @@ class GroupedBarColumnPresenter end end + def basis + return '' if type == :all + + type + end + def show_irrelevancy_message? return true if type == :student && !@measure.includes_student_survey_items? diff --git a/app/views/analyze/_grouped_bar_column.html.erb b/app/views/analyze/_grouped_bar_column.html.erb index e0b5689a..b066cfbb 100644 --- a/app/views/analyze/_grouped_bar_column.html.erb +++ b/app/views/analyze/_grouped_bar_column.html.erb @@ -14,8 +14,8 @@ measure not - based on - <%= presenter.type %> surveys + based on + <%= presenter.basis %> surveys <% elsif presenter.show_insufficient_data_message? %> diff --git a/app/views/analyze/index.html.erb b/app/views/analyze/index.html.erb index 7ec0bab9..994dc543 100644 --- a/app/views/analyze/index.html.erb +++ b/app/views/analyze/index.html.erb @@ -14,11 +14,16 @@

Focus Area

Select a category & subcategory to analyze measure-level results

- <% @categories.each do |category| %> <% end %> +
diff --git a/spec/system/journey_spec.rb b/spec/system/journey_spec.rb index 34d455c7..95b7e7f4 100644 --- a/spec/system/journey_spec.rb +++ b/spec/system/journey_spec.rb @@ -10,6 +10,7 @@ describe 'District Admin', js: true do let(:category) { Category.find_by_name('Teachers & Leadership') } let(:different_category) { Category.find_by_name('School Culture') } let(:subcategory) { Subcategory.find_by_name('Teachers & The Teaching Environment') } + let(:different_subcategory) { Subcategory.find_by_name('Relationships') } let(:measures_for_subcategory) { Measure.where(subcategory:) } let(:scales_for_subcategory) { Scale.where(measure: measures_for_subcategory) } let(:survey_items_for_subcategory) { SurveyItem.where(scale: scales_for_subcategory) } @@ -107,6 +108,9 @@ describe 'District Admin', js: true do go_to_different_category(different_category) district_admin_sees_category_change + go_to_different_subcategory(different_subcategory) + district_admin_sees_subcategory_change + click_on 'Browse' district_admin_sees_browse_content @@ -199,10 +203,18 @@ def district_admin_sees_analyze_content expect(page).to have_text('1:Teachers & Leadership > 1A:Teachers & The Teaching Environment') end -def go_to_different_category(_category) - select different_category.name, from: 'select-category' +def go_to_different_category(category) + select category.name, from: 'select-category' end def district_admin_sees_category_change expect(page).to have_text '2A:Safety' end + +def go_to_different_subcategory(subcategory) + select subcategory.name, from: 'select-subcategory' +end + +def district_admin_sees_subcategory_change + expect(page).to have_text('Relationships') +end diff --git a/spec/views/analyze/index.html.erb_spec.rb b/spec/views/analyze/index.html.erb_spec.rb index 23c8717b..f3c03ecc 100644 --- a/spec/views/analyze/index.html.erb_spec.rb +++ b/spec/views/analyze/index.html.erb_spec.rb @@ -53,6 +53,7 @@ describe 'analyze/index' do assign :category, category assign :categories, [category] assign :subcategory, subcategory + assign :subcategories, category.subcategories assign :measures, [support_for_teaching, effective_leadership, professional_qualifications] render @@ -94,6 +95,7 @@ describe 'analyze/index' do it 'displays user interface controls' do expect(subject).to have_text 'Focus Area' expect(subject).to have_css '#select-category' + expect(subject).to have_css '#select-subcategory' end end end