Tags organisation is factorised

This commit is contained in:
echarp 2016-02-20 16:53:54 +01:00
parent 9854295420
commit 55b5545a0f

View File

@ -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