Sha256: 29e562c7391a3a45956050495123827a0a8af50053a8851b57ba363530617fdd

Contents?: true

Size: 1.17 KB

Versions: 18

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Decidim
  # Exposes the scopes text search so users can choose a scope writing its name.
  class ScopesController < Decidim::ApplicationController
    skip_before_action :store_current_location

    def search
      authorize! :search, Scope
      root = Scope.where(id: params[:root], organization: current_organization).first
      scopes = if params[:term].present?
                 FreetextScopes.for(current_organization, I18n.locale, params[:term], root)
               elsif root
                 root.children
               else
                 current_organization.top_scopes
               end
      root_option = if params[:include_root] == "true" && !params[:term].present?
                      if root
                        [{ id: root.id.to_s, text: root.name[I18n.locale.to_s] }]
                      else
                        [{ id: "global", text: I18n.t("decidim.scopes.global") }]
                      end
                    else
                      []
                    end

      render json: { results: root_option + scopes.map { |scope| { id: scope.id.to_s, text: scope.name[I18n.locale.to_s] } } }
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
decidim-core-0.6.8 app/controllers/decidim/scopes_controller.rb
decidim-0.6.8 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.7 app/controllers/decidim/scopes_controller.rb
decidim-0.6.7 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.6 app/controllers/decidim/scopes_controller.rb
decidim-0.6.6 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.5 app/controllers/decidim/scopes_controller.rb
decidim-0.6.5 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.4 app/controllers/decidim/scopes_controller.rb
decidim-0.6.4 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.3 app/controllers/decidim/scopes_controller.rb
decidim-0.6.3 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.2 app/controllers/decidim/scopes_controller.rb
decidim-0.6.2 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.1 app/controllers/decidim/scopes_controller.rb
decidim-0.6.1 decidim-core/app/controllers/decidim/scopes_controller.rb
decidim-core-0.6.0 app/controllers/decidim/scopes_controller.rb
decidim-0.6.0 decidim-core/app/controllers/decidim/scopes_controller.rb