Skip to content

Commit

Permalink
make recent activity work async a second way
Browse files Browse the repository at this point in the history
  • Loading branch information
fiveNinePlusR committed Jan 21, 2025
1 parent 982cfc1 commit 795b152
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
14 changes: 13 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def donate; end

def profile; end

def activity
def set_activities
submission_type = params[:filterActivity].blank? ? %w[new_lmx remove_machine new_condition new_msx confirm_location] : params[:filterActivity]

if @region
Expand All @@ -132,6 +132,18 @@ def activity
end
end

def recent_activity
set_activities
case request.request_method
when 'GET'
render 'pages/activity'
when 'POST'
render partial: 'pages/render_activity', object: @recent_activity
else
p "unknown request_method: #{request.request_method}"
end
end

def contact
redirect_to about_path
end
Expand Down
11 changes: 6 additions & 5 deletions app/views/pages/activity.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@
:javascript
$('#activity_filter').on('submit', function(e) {
e.preventDefault();
allVals = []
activeFilters = []
$("input:checkbox[name=filterActivity]:checked").each(function () {
allVals.push(this.value);
activeFilters.push(this.value);
});
$("#activity").html(loadingHTML());

$.ajax({
url: '/activity',
type: 'GET',
type: 'POST',
data: {
filterActivity: allVals
filterActivity: activeFilters
},
dataType: "html",
success: function(data) {
$("#activity").html(loadingHTML());
$("#activity").html(data);
}
});
Expand Down
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
get '.well-known/apple-app-site-association' => 'pages#apple_app_site_association'
get '/apple-app-site-association' => 'pages#apple_app_site_association'
get '/robots.txt' => 'pages#robots'
get '/activity' => 'pages#activity'
post '/activity' => 'pages#activity'
get '/activity' => 'pages#recent_activity'
post '/activity' => 'pages#recent_activity'

scope ':region', constraints: lambda { |request| Region.where('lower(name) = ?', request.params[:region].downcase).any? } do
get 'app' => redirect('/app')
Expand Down Expand Up @@ -131,8 +131,8 @@
get '/high_rollers' => 'pages#high_rollers'
get '/suggest' => 'pages#suggest_new_location'
post '/submitted_new_location' => 'pages#submitted_new_location'
get '/activity' => 'pages#activity', as: 'region_activity'
post '/activity' => 'pages#activity', as: 'region_post_activity'
get '/activity' => 'pages#recent_activity', as: 'region_activity'
post '/activity' => 'pages#recent_activity', as: 'region_post_activity'

get '*page', to: 'locations#unknown_route'
end
Expand Down

0 comments on commit 795b152

Please sign in to comment.