agenda-libre-ruby/app/controllers/tags_controller.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

2016-02-20 16:53:54 +01:00
# Manage event and organisation tags
2014-01-05 22:10:11 +01:00
class TagsController < InheritedResources::Base
has_scope :region, :locality, :daylimit
has_scope :tag, as: :id
before_action :set_orgas, if: -> { params[:id].present? }
2014-01-05 22:10:11 +01:00
def index
@tags = ActsAsTaggableOn::Tag.where('taggings_count > ?',
Rails.configuration.cloud_threshold)
if params[:term]
# Used to autocomplete tags
@tags = @tags.select(:id, :name, 'name AS label')
.where('name LIKE ?', "#{params[:term]}%")
end
respond_to do |format|
format.html
format.json { render json: @tags }
end
2014-01-05 22:10:11 +01:00
end
def show
@events_future = apply_scopes Event.moderated.future
@events_past = apply_scopes Event.moderated.past
2016-03-27 14:34:34 +02:00
respond_to do |format|
format.html
format.json { render json: @events_future + @events_past }
end
2014-01-05 22:10:11 +01:00
end
2016-02-20 16:53:54 +01:00
private
# Splits, groups, rejects the less used
def set_orgas
@orgas = (apply_scopes(Orga.moderated.active) +
Orga.moderated.active
.where(
2020-02-08 15:16:57 +01:00
'lower(orgas.name) like lower(?)',
"%#{params[:id].tr '-', '%'}%"
)
).uniq
2016-02-20 16:53:54 +01:00
end
2014-01-05 22:10:11 +01:00
end