2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
class MapsController < ApplicationController
|
2020-05-11 18:38:50 +00:00
|
|
|
include Controllers::Nonprofit::Current
|
|
|
|
include Controllers::Nonprofit::Authorization
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
before_action :authenticate_super_associate!, only: :all_supporters
|
|
|
|
before_action :authenticate_nonprofit_user!, only: %i[all_npo_supporters specific_npo_supporters]
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# used on admin/nonprofits_map and front page
|
|
|
|
def all_npos
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :root }
|
|
|
|
format.json { @map_data = Nonprofit.where('latitude IS NOT NULL').last(1000) }
|
|
|
|
end
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# used on admin/supporters_map
|
|
|
|
def all_supporters
|
|
|
|
@map_data = Supporter.where('latitude IS NOT NULL').last(1000)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# used on npo dashboard
|
|
|
|
def all_npo_supporters
|
|
|
|
@map_data = Nonprofit.find(params['npo_id']).supporters.where('latitude IS NOT NULL').last(100)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
# used on supporter dashboard
|
|
|
|
def specific_npo_supporters
|
|
|
|
supporter_ids = params['supporter_ids'].split(',').map(&:to_i)
|
|
|
|
supporters = Nonprofit.find(params['npo_id']).supporters.find(supporter_ids).last(500)
|
|
|
|
@map_data = supporters.map { |s| s if s.latitude != '' }
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|