diff --git a/app/helpers/concerns/decidim/scopes_helper_extend.rb b/app/helpers/concerns/decidim/scopes_helper_extend.rb new file mode 100644 index 00000000..47ea7f11 --- /dev/null +++ b/app/helpers/concerns/decidim/scopes_helper_extend.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Decidim + module ScopesHelperExtend + extend ActiveSupport::Concern + included do + private + + def ancestors(organization = current_organization) + @ancestors ||= Decidim::Scope.where(parent_id: nil, organization: organization).sort_by do |scope| + translated_attribute(scope.name) + end + end + + def children_after_parent(ancestor, array, prefix) + array << ["#{prefix} #{translated_attribute(ancestor.name)}", ancestor.id] + children = ancestor.children.sort_by do |scope| + translated_attribute(scope.name) + end + children.each do |child| + children_after_parent(child, array, "#{prefix}-") + end + end + end + end +end diff --git a/config/application.rb b/config/application.rb index 12fe1ffe..b726117c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -49,6 +49,8 @@ class Application < Rails::Application end config.after_initialize do + Decidim::ScopesHelper.include Decidim::ScopesHelperExtend + Decidim::GraphiQL::Rails.config.tap do |config| config.initial_query = "{\n deployment {\n version\n branch\n remote\n upToDate\n currentCommit\n latestCommit\n locallyModified\n }\n}".html_safe end diff --git a/spec/helpers/decidim/scopes_helper_spec.rb b/spec/helpers/decidim/scopes_helper_spec.rb new file mode 100644 index 00000000..8c4e8c3c --- /dev/null +++ b/spec/helpers/decidim/scopes_helper_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + describe ScopesHelper, type: :helper do + describe "scopes_picker_tag" do + let(:scope) { create(:scope) } + + it "works wrong" do + actual = helper.scopes_picker_tag("my_scope_input", scope.id) + + expected = <<~HTML +