mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Use CategoryPresenter in welcome page instead of SqmCategory
This commit is contained in:
parent
05c3f42718
commit
332043c6fb
9 changed files with 29 additions and 50 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<div>
|
||||
<div class="subcategory-card border-radius-8">
|
||||
<div class="subcategory-card__benchmark-list">
|
||||
<% 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 %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<h1 class="sub-header font-bitter color-red"><%= @category.name %></h1>
|
||||
<p class="col-8 body-large"><%= @category.description %></p>
|
||||
|
||||
<% @category.subcategories.each do |subcategory| %>
|
||||
<% @category.subcategories(academic_year: @academic_year, school: @school).each do |subcategory| %>
|
||||
<section class="subcategory-section">
|
||||
<div class="p-7">
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue