simplify explore controller a bit
This commit is contained in:
parent
a8b698b11c
commit
bb87c9c2db
1 changed files with 17 additions and 40 deletions
|
@ -1,19 +1,16 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class ExploreController < ApplicationController
|
class ExploreController < ApplicationController
|
||||||
|
before_action :require_authentication, only: [:mine, :shared, :starred]
|
||||||
before_action :authorize_explore
|
before_action :authorize_explore
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
after_action :verify_policy_scoped
|
after_action :verify_policy_scoped
|
||||||
|
|
||||||
respond_to :html, :json, :csv
|
respond_to :html, :json, :csv
|
||||||
|
|
||||||
# TODO: remove?
|
|
||||||
# autocomplete :map, :name, full: true, extra_data: [:user_id]
|
|
||||||
|
|
||||||
# GET /explore/active
|
# GET /explore/active
|
||||||
def active
|
def active
|
||||||
page = params[:page].present? ? params[:page] : 1
|
@maps = policy_scope(Map).order(updated_at: :desc)
|
||||||
@maps = policy_scope(Map).order('updated_at DESC')
|
.page(params[:page]).per(20)
|
||||||
.page(page).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
|
@ -27,11 +24,8 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/featured
|
# GET /explore/featured
|
||||||
def featured
|
def featured
|
||||||
page = params[:page].present? ? params[:page] : 1
|
@maps = policy_scope(Map).where(featured: true).order(updated_at: :desc)
|
||||||
@maps = policy_scope(
|
.page(params[:page]).per(20)
|
||||||
Map.where('maps.featured = ? AND maps.permission != ?',
|
|
||||||
true, 'private')
|
|
||||||
).order('updated_at DESC').page(page).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -41,15 +35,8 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/mine
|
# GET /explore/mine
|
||||||
def mine
|
def mine
|
||||||
unless authenticated?
|
@maps = policy_scope(Map).where(user_id: current_user.id)
|
||||||
skip_policy_scope
|
.order(updated_at: :desc).page(params[:page]).per(20)
|
||||||
return redirect_to explore_active_path
|
|
||||||
end
|
|
||||||
|
|
||||||
page = params[:page].present? ? params[:page] : 1
|
|
||||||
@maps = policy_scope(
|
|
||||||
Map.where('maps.user_id = ?', current_user.id)
|
|
||||||
).order('updated_at DESC').page(page).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -59,15 +46,8 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/shared
|
# GET /explore/shared
|
||||||
def shared
|
def shared
|
||||||
unless authenticated?
|
@maps = policy_scope(Map).where(id: current_user.shared_maps.map(&:id))
|
||||||
skip_policy_scope
|
.order(updated_at: :desc).page(params[:page]).per(20)
|
||||||
return redirect_to explore_active_path
|
|
||||||
end
|
|
||||||
|
|
||||||
page = params[:page].present? ? params[:page] : 1
|
|
||||||
@maps = policy_scope(
|
|
||||||
Map.where('maps.id IN (?)', current_user.shared_maps.map(&:id))
|
|
||||||
).order('updated_at DESC').page(page).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -77,16 +57,9 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/starred
|
# GET /explore/starred
|
||||||
def starred
|
def starred
|
||||||
unless authenticated?
|
|
||||||
skip_policy_scope
|
|
||||||
return redirect_to explore_active_path
|
|
||||||
end
|
|
||||||
|
|
||||||
page = params[:page].present? ? params[:page] : 1
|
|
||||||
stars = current_user.stars.map(&:map_id)
|
stars = current_user.stars.map(&:map_id)
|
||||||
@maps = policy_scope(
|
@maps = policy_scope(Map).where(id: stars).order(updated_at: :desc)
|
||||||
Map.where('maps.id IN (?)', stars)
|
.page(params[:page]).per(20)
|
||||||
).order('updated_at DESC').page(page).per(20)
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -96,10 +69,9 @@ class ExploreController < ApplicationController
|
||||||
|
|
||||||
# GET /explore/mapper/:id
|
# GET /explore/mapper/:id
|
||||||
def mapper
|
def mapper
|
||||||
page = params[:page].present? ? params[:page] : 1
|
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
@maps = policy_scope(Map.where(user: @user))
|
@maps = policy_scope(Map.where(user: @user))
|
||||||
.order('updated_at DESC').page(page).per(20)
|
.order(updated_at: :desc).page(params[:page]).per(20)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@maps, @user) }
|
format.html { respond_with(@maps, @user) }
|
||||||
|
@ -112,4 +84,9 @@ class ExploreController < ApplicationController
|
||||||
def authorize_explore
|
def authorize_explore
|
||||||
authorize :Explore
|
authorize :Explore
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def require_authentication
|
||||||
|
# skip_policy_scope
|
||||||
|
redirect_to explore_active_path unless authenticated?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue