Sha256: 450adc0fb660be28a6a8be125319757136fbfe9be637470452073480fbe545cf

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Arclight
  # Controller for our /repositories index page
  class RepositoriesController < ApplicationController
    def index
      @repositories = Arclight::Repository.all
      load_collection_counts
    end

    def show
      @repository = Arclight::Repository.find_by!(slug: params[:id])
      search_service = Blacklight.repository_class.new(blacklight_config)
      @response = search_service.search(
        q: "level_sim:Collection repository_sim:\"#{@repository.name}\"",
        rows: 100
      )
      @collections = @response.documents
    end

    private

    def load_collection_counts
      counts = fetch_collection_counts
      @repositories.each do |repository|
        repository.collection_count = counts[repository.name] || 0
      end
    end

    def fetch_collection_counts
      search_service = Blacklight.repository_class.new(blacklight_config)
      results = search_service.search(
        q: 'level_sim:Collection',
        'facet.field': 'repository_sim',
        rows: 0
      )
      Hash[*results.facet_fields['repository_sim']]
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
arclight-0.5.0 app/controllers/arclight/repositories_controller.rb
arclight-0.4.0 app/controllers/arclight/repositories_controller.rb
arclight-0.3.3 app/controllers/arclight/repositories_controller.rb
arclight-0.3.2 app/controllers/arclight/repositories_controller.rb
arclight-0.3.1 app/controllers/arclight/repositories_controller.rb
arclight-0.3.0 app/controllers/arclight/repositories_controller.rb
arclight-0.2.0 app/controllers/arclight/repositories_controller.rb
arclight-0.1.4 app/controllers/arclight/repositories_controller.rb
arclight-0.1.3 app/controllers/arclight/repositories_controller.rb
arclight-0.1.2 app/controllers/arclight/repositories_controller.rb
arclight-0.1.1 app/controllers/arclight/repositories_controller.rb
arclight-0.1.0 app/controllers/arclight/repositories_controller.rb