Sha256: bbde59354fcebee730a9e96bf0e69568515272a2839adf34fa0d30b357ec0fcd

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

require 'pact_broker/ui/controllers/base_controller'
require 'pact_broker/ui/view_models/index_items'
require 'haml'

module PactBroker
  module UI
    module Controllers
      class Index < Base
        include PactBroker::Services

        get "/" do
          set_headers
          tags = nil
          if params[:tags]
            tags = params[:tags] == 'true' ? true : [*params[:tags]].compact
          end
          page_number = params[:page]&.to_i || 1
          # Make page size smaller for data intensive query
          page_size = params[:pageSize]&.to_i || (tags == true ? 30 : 100)
          options = {
            tags: tags,
            page_number: page_number,
            page_size: page_size
          }

          # TODO remove this code when verified
          options[:optimised] = true unless params[:optimised] == 'false'
          index_items = ViewDomain::IndexItems.new(index_service.find_index_items(options), base_url: base_url)

          page = tags ? :'index/show-with-tags' : :'index/show'
          locals = {
            title: "Pacts",
            index_items: index_items,
            page_number: page_number,
            page_size: page_size,
            pagination_record_count: index_items.pagination_record_count,
            current_page_size: index_items.size,
            base_url: base_url
          }

          haml page, {locals: locals, layout: :'layouts/main'}
        end

        def set_headers
          response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
          response.headers["Pragma"] = "no-cache"
          response.headers["Expires"] = "0"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pact_broker-2.58.0 lib/pact_broker/ui/controllers/index.rb
pact_broker-2.57.0 lib/pact_broker/ui/controllers/index.rb
pact_broker-2.56.1 lib/pact_broker/ui/controllers/index.rb
pact_broker-2.56.0 lib/pact_broker/ui/controllers/index.rb
pact_broker-2.55.0 lib/pact_broker/ui/controllers/index.rb