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.description %>
-<% @category.subcategories.each do |subcategory| %> +<% @category.subcategories(academic_year: @academic_year, school: @school).each do |subcategory| %>