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