Sha256: 00656ae0753bfd3147dd1ce84b32581138f1e6f01409ea7c8387bb0aba62657d

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Kaui
  class TagsController < Kaui::EngineController
    def index
      @search_query = params[:q]

      @ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc')
      @offset = params[:offset] || 0
      @limit = params[:limit] || 50

      @max_nb_records = @search_query.blank? ? Kaui::Tag.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records : 0
    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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kaui-3.0.5 app/controllers/kaui/tags_controller.rb
kaui-3.0.4 app/controllers/kaui/tags_controller.rb
kaui-3.0.2 app/controllers/kaui/tags_controller.rb
kaui-2.2.1 app/controllers/kaui/tags_controller.rb
kaui-3.0.1 app/controllers/kaui/tags_controller.rb