11# Root component for Dr. Rai Reports
22class Dashboard ::DrRaiReport < ApplicationComponent
3- # FIXME(:selected_period): Write out JS for this component's interactivity.
4- # The whole current period thing only works onMount — sticking to frontend
5- # terms here — after then, it's useless. This is because a view-component in
6- # Rails, which this is, is technically a server-side render scoped to its own
7- # local variables, and exposing methods as callable from the view. It doesn't
8- # handle state. This means interactivity cannot be handled at the view
9- # component layer. In lay man's terms, when someone selects another quarter
10- # to view, we need to do a full page refresh if we are depending on the view
11- # component; a full page refresh passing in the selected quarter. We need JS
12-
13- attr_reader :quarterlies
3+ attr_reader :quarterlies , :indicators , :region , :action_plans
144 attr_accessor :selected_period
155
16- def initialize ( quarterlies , region , selected_quarter = nil )
6+ def initialize ( quarterlies , region_slug , selected_quarter = nil )
177 @quarterlies = quarterlies
18- @region = region
8+ @region = Region . find_by ( slug : region_slug )
199 @selected_period = if selected_quarter . nil?
20- current_period
10+ Period . new ( type : :quarter , value : current_period . value . to_s )
2111 else
2212 Period . new ( type : :quarter , value : selected_quarter )
2313 end
24- @goals = { }
14+ @action_plans = DrRai ::ActionPlan
15+ . includes ( :dr_rai_target )
16+ . where (
17+ region : @region ,
18+ dr_rai_target : { period : @selected_period . value . to_s }
19+ )
20+ @indicators = DrRai ::Indicator . all
21+ end
22+
23+ def indicator_previous_numerator ( indicator )
24+ indicator . numerator ( region , selected_period . previous )
25+ end
26+
27+ def indicator_denominator ( indicator )
28+ indicator . denominator ( region , selected_period )
2529 end
2630
2731 def current_period
2832 Period . current . to_quarter_period
2933 end
3034
35+ def current_period?
36+ current_period == selected_period
37+ end
38+
3139 def start_of period
3240 period . begin . strftime ( "%b-%-d" )
3341 end
@@ -38,15 +46,11 @@ def end_of period
3846
3947 def classes_for_period period
4048 raise "#{ period } is not a Period" unless period . is_a? Period
41- candidates = [ "actions-header -button" ]
42- candidates << "action-header- selected" if period == selected_period
49+ candidates = [ "period -button" ]
50+ candidates << "selected" if period == selected_period
4351 candidates . join ( " " )
4452 end
4553
46- def period_goals
47- @goals [ selected_period ]
48- end
49-
5054 def human_readable thing
5155 case thing
5256 when Period
0 commit comments