File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,12 +12,19 @@ def index
1212 params [ :date ] ,
1313 params [ :date ]
1414 ) . order ( :start_date ) . limit ( params [ :limit ] ||= 10 ) . offset ( params [ :offset ] ||= 0 )
15-
1615 else
17- @activities = Activity . where ( '(end_date IS NULL AND start_date >= ?) OR end_date >= ?' ,
18- Date . today , Date . today ) . order ( :start_date ) . where ( is_viewable : true )
19- @activities . limit! ( params [ :limit ] ) . offset ( params [ :offset ] ||= 0 ) if params [ :limit ] . present?
20- @activities = @activities . reject ( &:ended? )
16+ from = params [ :from ] . present? ? Date . parse ( params [ :from ] ) : Date . today
17+ @activities = Activity . where ( 'start_date >= ?' , from )
18+ . order ( :start_date )
19+ . where ( is_viewable : true )
20+
21+ # Allow nil to mean no limit on the end date
22+ @activities = @activities . where ( 'end_date <= ?' , Date . parse ( params [ :to ] ) ) if params [ :to ] . present?
23+
24+ @activities = @activities . limit! ( params [ :limit ] ) . offset ( params [ :offset ] ||= 0 ) if params [ :limit ] . present?
25+
26+ @activities = @activities . reject ( &:ended? ) if params [ :from ] . blank?
27+ @activities
2128 end
2229 end
2330
You can’t perform that action at this time.
0 commit comments