Tags organisation is factorised
This commit is contained in:
parent
9854295420
commit
55b5545a0f
@ -1,15 +1,11 @@
|
|||||||
# Manage event tags
|
# Manage event and organisation tags
|
||||||
class TagsController < InheritedResources::Base
|
class TagsController < InheritedResources::Base
|
||||||
has_scope :region, :locality, :daylimit
|
has_scope :region, :locality, :daylimit
|
||||||
has_scope :period, type: :hash, using: [:year, :week]
|
has_scope :period, type: :hash, using: [:year, :week]
|
||||||
has_scope :tag, as: :id
|
has_scope :tag, as: :id
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tags = apply_scopes(Event.moderated)
|
@tags = organise_tags apply_scopes(Event.moderated)
|
||||||
.pluck(:tags).map(&:split).flatten
|
|
||||||
.group_by { |i| i }
|
|
||||||
.map { |k, v| [k, v.size] }
|
|
||||||
.sort
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
@ -23,15 +19,22 @@ class TagsController < InheritedResources::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def orgas
|
def orgas
|
||||||
@tags = apply_scopes(Orga.moderated)
|
@tags = organise_tags apply_scopes(Orga.moderated)
|
||||||
.pluck(:tags).map(&:split).flatten
|
|
||||||
.group_by { |i| i }
|
|
||||||
.map { |k, v| [k, v.size] }
|
|
||||||
.sort
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
format.json { render json: @tags }
|
format.json { render json: @tags }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Splits, groups, rejects the less used
|
||||||
|
def organise_tags(tags)
|
||||||
|
tags.pluck(:tags).map(&:split).flatten
|
||||||
|
.group_by { |i| i }
|
||||||
|
.map { |k, v| [k, v.size] }
|
||||||
|
.reject { |_k, v| v <= 3 }
|
||||||
|
.sort
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user