Sha256: cba1ba49375b2015291432712162fb59f63f04c69e60b1eaf6949229e91ba71b

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

class Kaui::TagsController < Kaui::EngineController

  def index
    @search_query = params[:q]

    @limit = 50
    if @search_query.blank?
      max_nb_records = Kaui::Tag.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records
      @offset = [0, max_nb_records - @limit].max
      @ordering = 'desc'
    else
      @offset = 0
      @ordering = 'asc'
    end
  end

  def pagination
    searcher = lambda do |search_key, offset, limit|
      Kaui::Tag.list_or_search(search_key, offset, limit, options_for_klient)
    end

    data_extractor = lambda do |tag, column|
      [
          tag.tag_id,
          tag.object_id,
          tag.object_type,
          tag.tag_definition_name
      ][column]
    end

    formatter = lambda do |tag|
      url_for_object = view_context.url_for_object(tag.object_id, tag.object_type)
      [
          tag.tag_id,
          url_for_object ? view_context.link_to(tag.object_id, url_for_object) : tag.object_id,
          tag.object_type,
          tag.tag_definition_name
      ]
    end

    paginate searcher, data_extractor, formatter
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kaui-0.15.3 app/controllers/kaui/tags_controller.rb
kaui-0.15.2 app/controllers/kaui/tags_controller.rb
kaui-0.15.1 app/controllers/kaui/tags_controller.rb