2016-09-24 04:58:09 +00:00
|
|
|
# frozen_string_literal: true
|
2016-09-23 08:41:08 +00:00
|
|
|
class ExploreController < ApplicationController
|
2016-09-25 16:16:18 +00:00
|
|
|
before_action :require_authentication, only: [:mine, :shared, :starred]
|
2016-09-23 08:41:08 +00:00
|
|
|
before_action :authorize_explore
|
|
|
|
after_action :verify_authorized
|
|
|
|
after_action :verify_policy_scoped
|
|
|
|
|
|
|
|
respond_to :html, :json, :csv
|
|
|
|
|
|
|
|
# GET /explore/active
|
2016-09-23 09:07:06 +00:00
|
|
|
def active
|
2016-10-03 02:49:45 +00:00
|
|
|
@maps = map_scope(Map.where.not(name: 'Untitled Map'))
|
2016-09-23 08:41:08 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
# root url => main/home. main/home renders maps/activemaps view.
|
|
|
|
redirect_to(root_url) && return if authenticated?
|
|
|
|
respond_with(@maps, @user)
|
|
|
|
end
|
2016-09-24 06:35:23 +00:00
|
|
|
format.json { render json: @maps.to_json }
|
2016-09-23 08:41:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /explore/featured
|
2016-09-23 09:07:06 +00:00
|
|
|
def featured
|
2016-09-25 16:28:23 +00:00
|
|
|
@maps = map_scope(Map.where(featured: true))
|
2016-09-23 08:41:08 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { respond_with(@maps, @user) }
|
2016-09-24 06:35:23 +00:00
|
|
|
format.json { render json: @maps.to_json }
|
2016-09-23 08:41:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /explore/mine
|
2016-09-23 09:07:06 +00:00
|
|
|
def mine
|
2016-09-25 16:28:23 +00:00
|
|
|
@maps = map_scope(Map.where(user_id: current_user.id))
|
2016-09-23 08:41:08 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { respond_with(@maps, @user) }
|
2016-09-24 06:35:23 +00:00
|
|
|
format.json { render json: @maps.to_json }
|
2016-09-23 08:41:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /explore/shared
|
2016-09-23 09:07:06 +00:00
|
|
|
def shared
|
2016-09-25 16:28:23 +00:00
|
|
|
@maps = map_scope(Map.where(id: current_user.shared_maps.map(&:id)))
|
2016-09-23 08:41:08 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { respond_with(@maps, @user) }
|
2016-09-24 06:35:23 +00:00
|
|
|
format.json { render json: @maps.to_json }
|
2016-09-23 08:41:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /explore/starred
|
2016-09-23 09:07:06 +00:00
|
|
|
def starred
|
2016-09-25 16:28:23 +00:00
|
|
|
@maps = map_scope(Map.where(id: current_user.stars.map(&:map_id)))
|
2016-09-23 08:41:08 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { respond_with(@maps, @user) }
|
2016-09-24 06:35:23 +00:00
|
|
|
format.json { render json: @maps.to_json }
|
2016-09-23 08:41:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /explore/mapper/:id
|
2016-09-23 09:07:06 +00:00
|
|
|
def mapper
|
2016-09-23 08:41:08 +00:00
|
|
|
@user = User.find(params[:id])
|
2016-09-25 16:28:23 +00:00
|
|
|
@maps = map_scope(Map.where(user: @user))
|
2016-09-23 08:41:08 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { respond_with(@maps, @user) }
|
2016-09-24 06:35:23 +00:00
|
|
|
format.json { render json: @maps.to_json }
|
2016-09-23 08:41:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-09-25 16:28:23 +00:00
|
|
|
def map_scope(scope)
|
|
|
|
policy_scope(scope).order(updated_at: :desc).page(params[:page]).per(20)
|
|
|
|
end
|
|
|
|
|
2016-09-23 08:41:08 +00:00
|
|
|
def authorize_explore
|
|
|
|
authorize :Explore
|
|
|
|
end
|
2016-09-25 16:16:18 +00:00
|
|
|
|
|
|
|
def require_authentication
|
|
|
|
# skip_policy_scope
|
|
|
|
redirect_to explore_active_path unless authenticated?
|
|
|
|
end
|
2016-09-23 08:41:08 +00:00
|
|
|
end
|