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
|
||||
has_scope :region, :locality, :daylimit
|
||||
has_scope :period, type: :hash, using: [:year, :week]
|
||||
has_scope :tag, as: :id
|
||||
|
||||
def index
|
||||
@tags = apply_scopes(Event.moderated)
|
||||
.pluck(:tags).map(&:split).flatten
|
||||
.group_by { |i| i }
|
||||
.map { |k, v| [k, v.size] }
|
||||
.sort
|
||||
@tags = organise_tags apply_scopes(Event.moderated)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
@ -23,15 +19,22 @@ class TagsController < InheritedResources::Base
|
||||
end
|
||||
|
||||
def orgas
|
||||
@tags = apply_scopes(Orga.moderated)
|
||||
.pluck(:tags).map(&:split).flatten
|
||||
.group_by { |i| i }
|
||||
.map { |k, v| [k, v.size] }
|
||||
.sort
|
||||
@tags = organise_tags apply_scopes(Orga.moderated)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render json: @tags }
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user