mirror of
https://github.com/edcommonwealth/Dashboard.git
synced 2026-03-07 21:38:14 -08:00
dirty commit: can't get references to work correctly between any tables
This commit is contained in:
parent
e1f0b78236
commit
a4fddbeced
183 changed files with 5461 additions and 5 deletions
59
app/controllers/dashboard/home_controller.rb
Normal file
59
app/controllers/dashboard/home_controller.rb
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dashboard
|
||||
class HomeController < ApplicationController
|
||||
helper HeaderHelper
|
||||
|
||||
def index
|
||||
@districts = districts
|
||||
@district = district
|
||||
|
||||
@schools = schools
|
||||
@school = school
|
||||
|
||||
@year = year
|
||||
@categories = Category.sorted.map { |category| CategoryPresenter.new(category:) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def districts
|
||||
District.all.order(:name).map do |district|
|
||||
[district.name, district.id]
|
||||
end
|
||||
end
|
||||
|
||||
def district
|
||||
return District.find(params[:district]) if params[:district].present?
|
||||
|
||||
District.first
|
||||
end
|
||||
|
||||
def schools
|
||||
if district.present?
|
||||
district.dashboard_schools.order(:name).map do |school|
|
||||
[school.name, school.id]
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def school
|
||||
School.find(params[:school]) if params[:school].present?
|
||||
end
|
||||
|
||||
def year
|
||||
return nil unless school.present?
|
||||
|
||||
academic_year = AcademicYear.all.order(range: :DESC).find do |ay|
|
||||
Subcategory.all.any? do |subcategory|
|
||||
rate = subcategory.response_rate(school:, academic_year: ay)
|
||||
rate.meets_student_threshold || rate.meets_teacher_threshold
|
||||
end
|
||||
end
|
||||
|
||||
academic_year&.range || AcademicYear.order("range DESC").first.range
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue