diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 09176f8d..867fa2d6 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -7,12 +7,7 @@ class DashboardController < SqmApplicationController .sort .reverse - @category_presenters = SqmCategory.all.map { |sqm_category| CategoryPresenter.new( - category: sqm_category, - academic_year: academic_year, - school: school, - )} - + @category_presenters = SqmCategory.all.map { |sqm_category| CategoryPresenter.new(category: sqm_category) } end private @@ -22,7 +17,7 @@ class DashboardController < SqmApplicationController end def presenter_for_measure(measure) - score = SurveyItemResponse.score_for_measure(measure: measure, school: school, academic_year: academic_year) + score = SurveyItemResponse.score_for_measure(measure: measure, school: @school, academic_year: @academic_year) MeasureGraphRowPresenter.new(measure: measure, score: score) end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index a2dc76ad..b1e94b75 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,6 +3,6 @@ class HomeController < ActionController::Base @districts = District.all.order(:name) @schools = School.all - @categories = SqmCategory.all + @categories = SqmCategory.all.order(:sort_index).map { |category| CategoryPresenter.new(category: category) } end end diff --git a/app/controllers/sqm_application_controller.rb b/app/controllers/sqm_application_controller.rb index 36ef16b1..f3c45307 100644 --- a/app/controllers/sqm_application_controller.rb +++ b/app/controllers/sqm_application_controller.rb @@ -1,29 +1,21 @@ class SqmApplicationController < ActionController::Base protect_from_forgery with: :exception, prepend: true layout "sqm/application" - before_action :authenticate_district before_action :set_schools_and_districts + before_action :authenticate_district private - attr_reader :academic_year - def authenticate_district - authenticate(district.name.downcase, "#{district.name.downcase}!") + authenticate(@district.name.downcase, "#{@district.name.downcase}!") end def set_schools_and_districts - @schools = School.where(district: district).sort_by(&:name) + @district = District.find_by_slug district_slug @districts = District.all.sort_by(&:name) - @academic_year ||= AcademicYear.find_by_range params[:year] - end - - def district - @district ||= District.find_by_slug district_slug - end - - def school - @school ||= School.find_by_slug school_slug + @school = School.find_by_slug school_slug + @schools = School.where(district: @district).sort_by(&:name) + @academic_year = AcademicYear.find_by_range params[:year] end def district_slug diff --git a/app/controllers/sqm_categories_controller.rb b/app/controllers/sqm_categories_controller.rb index 627b6251..bcfe8b24 100644 --- a/app/controllers/sqm_categories_controller.rb +++ b/app/controllers/sqm_categories_controller.rb @@ -1,19 +1,9 @@ class SqmCategoriesController < SqmApplicationController def show - @categories = SqmCategory.all.order(:sort_index).map do |category| - CategoryPresenter.new( - category: category, - academic_year: academic_year, - school: school, - ) - end + @categories = SqmCategory.all.order(:sort_index).map { |category| CategoryPresenter.new(category: category) } - @category = CategoryPresenter.new( - category: SqmCategory.find_by_slug(params[:id]), - academic_year: academic_year, - school: school, - ) + @category = CategoryPresenter.new(category: SqmCategory.find_by_slug(params[:id])) end end diff --git a/app/presenters/category_presenter.rb b/app/presenters/category_presenter.rb index f285a69f..1326acb8 100644 --- a/app/presenters/category_presenter.rb +++ b/app/presenters/category_presenter.rb @@ -1,10 +1,8 @@ class CategoryPresenter attr_reader :category - def initialize(category:, academic_year:, school:) + def initialize(category:) @category = category - @academic_year = academic_year - @school = school end def name @@ -15,6 +13,10 @@ class CategoryPresenter @category.description end + def slug + @category.slug + end + def icon case name when 'Teachers & Leadership' @@ -30,12 +32,12 @@ class CategoryPresenter end end - def subcategories + def subcategories(academic_year:, school:) @category.subcategories.map do |subcategory| SubcategoryPresenter.new( subcategory: subcategory, - academic_year: @academic_year, - school: @school + academic_year: academic_year, + school: school ) end end diff --git a/app/views/dashboard/_quality_framework_indicators.erb b/app/views/dashboard/_quality_framework_indicators.erb index e3077426..63163693 100644 --- a/app/views/dashboard/_quality_framework_indicators.erb +++ b/app/views/dashboard/_quality_framework_indicators.erb @@ -16,7 +16,7 @@
- <% category_presenter.subcategories.each do |subcategory| %> + <% category_presenter.subcategories(academic_year: @academic_year, school: @school).each do |subcategory| %> <%= render partial: 'subcategory_card', locals: { presenter: subcategory.subcategory_card_presenter, subcategory: subcategory } %> <% end %>
diff --git a/app/views/sqm_categories/show.html.erb b/app/views/sqm_categories/show.html.erb index 9cabf837..541e9255 100644 --- a/app/views/sqm_categories/show.html.erb +++ b/app/views/sqm_categories/show.html.erb @@ -13,7 +13,7 @@

<%= @category.name %>

<%= @category.description %>

-<% @category.subcategories.each do |subcategory| %> +<% @category.subcategories(academic_year: @academic_year, school: @school).each do |subcategory| %>
diff --git a/spec/presenters/category_presenter_spec.rb b/spec/presenters/category_presenter_spec.rb index 5757f005..badce4d5 100644 --- a/spec/presenters/category_presenter_spec.rb +++ b/spec/presenters/category_presenter_spec.rb @@ -6,32 +6,32 @@ describe CategoryPresenter do subcategory2 = Subcategory.new(name: 'Another subcategory') category = SqmCategory.new(name: 'Some Category', subcategories: [subcategory1, subcategory2], description: 'A description for some Category') - return CategoryPresenter.new(category: category, academic_year: AcademicYear.new, school: School.new) + return CategoryPresenter.new(category: category) end let(:teachers_and_leadership_presenter) do category = SqmCategory.find_by_name("Teachers & Leadership") - return CategoryPresenter.new(category: category, academic_year: AcademicYear.new, school: School.new) + return CategoryPresenter.new(category: category) end let(:school_culture_presenter) do category = SqmCategory.find_by_name("School Culture") - return CategoryPresenter.new(category: category, academic_year: AcademicYear.new, school: School.new) + return CategoryPresenter.new(category: category) end let(:resources_presenter) do category = SqmCategory.find_by_name("Resources") - return CategoryPresenter.new(category: category, academic_year: AcademicYear.new, school: School.new) + return CategoryPresenter.new(category: category) end let(:academic_learning_presenter) do category = SqmCategory.find_by_name("Academic Learning") - return CategoryPresenter.new(category: category, academic_year: AcademicYear.new, school: School.new) + return CategoryPresenter.new(category: category) end let(:community_and_wellbeing_presenter) do category = SqmCategory.find_by_name("Community & Wellbeing") - return CategoryPresenter.new(category: category, academic_year: AcademicYear.new, school: School.new) + return CategoryPresenter.new(category: category) end it 'returns the name and description of the category' do @@ -40,7 +40,7 @@ describe CategoryPresenter do end it 'maps subcategories to subcategory presenters' do - expect(category_presenter.subcategories.map(&:name)).to eq ['A subcategory', 'Another subcategory'] + expect(category_presenter.subcategories(academic_year: AcademicYear.new, school: School.new).map(&:name)).to eq ['A subcategory', 'Another subcategory'] end it 'returns the correct icon for the given category' do diff --git a/spec/views/sqm_categories/show.html.erb_spec.rb b/spec/views/sqm_categories/show.html.erb_spec.rb index 46b7067b..1925559f 100644 --- a/spec/views/sqm_categories/show.html.erb_spec.rb +++ b/spec/views/sqm_categories/show.html.erb_spec.rb @@ -6,7 +6,7 @@ describe 'sqm_categories/show.html.erb' do school = create(:school, name: 'Best School') category = create(:sqm_category, name: 'Some Category', description: 'Some description of the category') - category_presenter = CategoryPresenter.new(category: category, academic_year: academic_year, school: school) + category_presenter = CategoryPresenter.new(category: category) subcategory1 = create(:subcategory, sqm_category: category, name: 'A subcategory', description: 'Some description of the subcategory') subcategory2 = create(:subcategory_with_measures, sqm_category: category, name: 'Another subcategory', description: 'Another description of the subcategory')