Skip to content

Commit

Permalink
release: Add simple proposals and Awesome private fields for proposals (
Browse files Browse the repository at this point in the history
#45)

* add simple proposals

* Add simple proposal and decidim awesome's correct branch

The simple proposal module is on my personal fork because modifications to the position of the field were necessary. 

The decidim awesome one is on an octree fork because the private proposals feature is yet to be merge into the main decidim awesome repo

* fix Gemfile for decidim-simple_proposal overload

* Rubocop & ERB Lint

* Add missing migration

* rubocop

* Fix proposal creation for SimpleProposal x Awesome proposal private fields
- remove old proposals_controller.rb overload
- overload SimpleProposals proposals_controller_override.rb

* Fix i18n locales

* Fix tests i18n

* rubocop

* fix: Remove exports from Phone AH

* fix: Deactivate factory_bot

* lint: Fix rubocop offense

* fix: reversibility private body

* fix: Move address field in edit form

* fix: Add missing simple proposal translation

* fix: Scopes order in dropdown (#44)

* fix: Scopes order in dropdown

* fix: Ensure scopes are only those in current_organization

---------

Co-authored-by: Simonas <[email protected]>
Co-authored-by: quentinchampenois <[email protected]>
Co-authored-by: Lucie Grau <[email protected]>
  • Loading branch information
4 people authored Nov 8, 2023
1 parent 1aade3c commit 2b6ff4a
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/helpers/concerns/decidim/scopes_helper_extend.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions spec/helpers/decidim/scopes_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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
<div id="my_scope_input" class="data-picker picker-single" data-picker-name="my_scope_input">
<div class="picker-values">
<div>
<a href="/scopes/picker?current=#{scope.id}&amp;field=my_scope_input" data-picker-value="#{scope.id}">
#{scope.name["en"]} (#{scope.scope_type.name["en"]})
</a>
</div>
</div>
<div class="picker-prompt">
<a href="/scopes/picker?field=my_scope_input" role="button" aria-label="Select a scope (currently: Global scope)">Global scope</a>
</div>
</div>
HTML

expect(actual).to have_equivalent_markup_to(expected)
end
end

describe "#ancestors" do
let!(:organization) { create(:organization) }
let!(:last_scope) { create(:scope, name: { en: "ZZZ scope" }, organization: organization) }
let!(:first_scope) { create(:scope, name: { en: "AAA scope" }, organization: organization) }
let!(:first_subscope) { create(:scope, name: { en: "AAA subscope" }, parent: first_scope, organization: organization) }
let!(:last_subscope) { create(:scope, name: { en: "ZZZ subscope" }, parent: first_scope, organization: organization) }
let!(:middle_subscope) { create(:scope, name: { en: "DDD subscope" }, parent: first_scope, organization: organization) }
let(:expected) { [first_scope, last_scope] }
let!(:not_in_organization) { create(:scope) }

it "returns the scopes with no parent" do
actual = helper.send(:ancestors, organization)

expect(actual.count).to eq(2)
expect(actual).to eq(expected)
expect(actual).not_to include(not_in_organization)
end
end

describe "#children_after_parent" do
let!(:organization) { create(:organization) }
let!(:last_scope) { create(:scope, name: { en: "ZZZ scope" }, organization: organization) }
let!(:first_scope) { create(:scope, name: { en: "AAA scope" }, organization: organization) }
let!(:first_subscope) { create(:scope, name: { en: "AAA subscope" }, parent: first_scope, organization: organization) }
let!(:last_subscope) { create(:scope, name: { en: "ZZZ subscope" }, parent: first_scope, organization: organization) }
let!(:middle_subscope) { create(:scope, name: { en: "DDD subscope" }, parent: first_scope, organization: organization) }
let(:expected) { [[" AAA scope", first_scope.id], ["- AAA subscope", first_subscope.id], ["- DDD subscope", middle_subscope.id], ["- ZZZ subscope", last_subscope.id]] }

it "returns the scopes with children" do
array = []
helper.send(:children_after_parent, first_scope, array, "")
expect(array).to eq(expected)
end
end
end
end

0 comments on commit 2b6ff4a

Please sign in to comment.