Skip to content

Commit

Permalink
Merge pull request #359 from bchd/BCHDCC-101-admin-be-able-to-track-l…
Browse files Browse the repository at this point in the history
…ocation-updates

[BCHDCC-101] Admin - Be able to track location updates
  • Loading branch information
micaelacunhadev authored Jan 9, 2025
2 parents ec82f72 + ccb7563 commit c4afc0e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/admin/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def update
authorize @location

if @location.save
fire_location_update_event
redirect_to [:admin, @location],
notice: 'Location was successfully updated.'
else
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/ahoy_events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ def fire_location_view_event
ahoy.track("Location Visit", id: @location.id)
end

def fire_location_edit_event
def fire_location_update_event
ahoy.track("Location Update", id: @location.id)
end
end
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def number_of_visits(location_id)
visit_html_list.html_safe
end

def number_of_updates(location_id)
updates_last_thirty_days = AhoyQueries.get_number_of_updates_last_thirty_days(location_id)
updates = '<p>Updates in the last 30 days: ' + "#{updates_last_thirty_days}" + '</p>'
updates.html_safe
end

def upload_server
Rails.configuration.upload_server
end
Expand Down
5 changes: 5 additions & 0 deletions app/services/ahoy_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module AhoyQueries
LAST_12_MONTHS,
]

def get_number_of_updates_last_thirty_days(location_id)
interval = interval_by_date_range(LAST_30_DAYS)
Ahoy::Event.where(name: 'Location Update', properties: {id: location_id}, time: interval).count
end

def get_visits_by_location_and_date_range(location_id: , date_range:)
Ahoy::Event.where(name: 'Location Visit', properties: {id: location_id}, time: interval_by_date_range(date_range)).count
end
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/locations/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.content-box
%h2= @location.name == @org.try(:name) ? @location.name : "#{@org.try(:name)} / #{@location.name}"
= last_updated_at(@updated)
= number_of_updates(@location.id)
%p
Number of times visited:
%ul
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/admin/locations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@

expect(response).to redirect_to admin_location_url(@loc.reload.friendly_id)
end

it 'tracks update to location with ahoy' do
log_in_as_admin(:super_admin)

post :update, params: { id: @loc.id, location: { name: 'Updated location' } }

expect(AhoyQueries.get_number_of_updates_last_thirty_days(@loc.id)).to eq(1)
end
end

context 'when admin is regular admin without privileges' do
Expand Down
1 change: 0 additions & 1 deletion spec/features/admin/sign_up_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
scenario 'with custom mailer' do
reset_email
sign_up_admin('Moncef', '[email protected]', 'ohanatest', 'ohanatest')
expect(first_email.body).to include('Admin')
expect(first_email.body).to include('/admin')
expect(first_email.body).to_not include('documentation')
end
Expand Down

0 comments on commit c4afc0e

Please sign in to comment.