Skip to content

Commit

Permalink
fixup! Update admin general timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Oct 19, 2023
1 parent 8b7b9a8 commit ec7e691
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
16 changes: 7 additions & 9 deletions app/controllers/admin_general_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ def debug
private

def get_events_title
return "#{current_event_type}, all time" unless start_date
"#{current_event_type} in the last #{current_time_filter.downcase}"
if current_time_filter == 'All time'
"#{current_event_type}, all time"
else
"#{current_event_type} in the last #{current_time_filter.downcase}"
end
end

def get_timestamps
Expand All @@ -185,19 +188,14 @@ def get_timestamps

authority_change_scope = PublicBody.versioned_class.
select("id, 'PublicBodyVersion', updated_at AS timestamp").
where(updated_at: start_date...).
order(timestamp: :desc)

info_request_event_scope = InfoRequestEvent.
select("id, 'InfoRequestEvent', created_at AS timestamp").
where(created_at: start_date...).
order(timestamp: :desc)

if start_date
authority_change_scope = authority_change_scope.
where(updated_at: start_date...)
info_request_event_scope = info_request_event_scope.
where(created_at: start_date...)
end

case params[:event_type]
when 'authority_change'
connection.select_rows(authority_change_scope.to_sql)
Expand Down
12 changes: 3 additions & 9 deletions app/helpers/admin_general_timeline_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
module AdminGeneralTimelineHelper
def start_date
params[:start_date]&.to_datetime
params[:start_date]&.to_datetime || 2.days.ago
end

def time_filters
Expand All @@ -14,18 +14,12 @@ def time_filters
'2 days' => 2.days.ago,
'Week' => 1.week.ago,
'Month' => 1.month.ago,
'All time' => nil
'All time' => Time.utc(1970, 1, 1)
}
end

def current_time_filter
return 'All time' unless start_date

filter = time_filters.compact.min_by do |_, time|
(time - start_date).abs
end

filter&.first
time_filters.compact.min_by { |_, time| (time - start_date).abs }&.first
end

def event_types
Expand Down

0 comments on commit ec7e691

Please sign in to comment.