Skip to content

Commit 8c05fa4

Browse files
leio10josepjaume
authored andcommitted
Allow associating subscopes of any level when creating new resources (decidim#1746)
* Renamed Select2Filter to Select2Field to use it outside filter forms. * Select2 appearance adapted for frontend forms. * Fixed behavior on search scopes AJAX call when passing false to include_root param. * Using select2 for scope selection on proposals new form. * Using select2 for scope selection on features admin forms. * Fixed scope retrieval on scoped resources forms. Before decidim#1500, only processes with global scope (nil value) could have features with a scope. Now this is not true, so the scope retrieval should only use the process scope when there is no scope for the resource. * Scopes controller tests improved. * Remove unused code. * Rubocop offenses. * ESLint offense * ESLint offense * Select2 capybara tests fixed. * Ignore missing global scopetranslations in I18n tests on budgets, meetings and results engines. * Simplified logic on scopes search controller. * Defined matcher for scopes controller tests to improve readability. * Defined matcher for scopes controller tests to improve readability. * Temporary usability improvement on scopes management. * Scopes search controller tests improved.
1 parent 42ee442 commit 8c05fa4

File tree

29 files changed

+81
-50
lines changed

29 files changed

+81
-50
lines changed

decidim-admin/app/views/decidim/admin/scopes/index.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<%= scope.scope_type ? translated_attribute(scope.scope_type.name) : "-" %>
3030
</td>
3131
<td class="table-list__actions">
32+
<%= icon_link_to "zoom-in", scope_scopes_path(scope), t("actions.browse", scope: "decidim.admin"), class: "action-icon--browse", method: :get, data: {} %>
3233

3334
<% if can? :update, scope %>
3435
<%= icon_link_to "pencil", ['edit', scope], t("actions.edit", scope: "decidim.admin"), class: "action-icon--edit", method: :get, data: {} %>

decidim-admin/config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ en:
123123
actions:
124124
activate: Activate
125125
add: Add
126+
browse: Browse
126127
configure: Configure
127128
confirm_destroy: Are you sure you want to delete this?
128129
destroy: Destroy

decidim-budgets/app/forms/decidim/budgets/admin/project_form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def proposals
4040
end
4141

4242
def scope
43-
@scope ||= process_scope || current_organization.scopes.where(id: decidim_scope_id).first
43+
@scope ||= current_organization.scopes.where(id: decidim_scope_id).first || process_scope
4444
end
4545

4646
def category

decidim-budgets/app/views/decidim/budgets/admin/projects/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<% if current_participatory_process.has_subscopes? %>
2020
<div class="row column" >
21-
<%= form.collection_select :decidim_scope_id, subscopes_for(current_participatory_process), :id, :name %>
21+
<%= form.scopes_select :decidim_scope_id, prompt: I18n.t("decidim.scopes.global"), remote_path: decidim.scopes_search_path(root: current_participatory_process.scope) %>
2222
</div>
2323
<% end %>
2424

decidim-budgets/config/i18n-tasks.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ignore_unused:
66
- "decidim.features.budgets.actions.*"
77
- "activemodel.attributes.project.*"
88
- "decidim.resource_links.*"
9-
9+
ignore_missing:
10+
- decidim.scopes.global
1011
search:
1112
strict: false

decidim-budgets/spec/shared/manage_projects_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
)
8383
fill_in :project_budget, with: 22_000_000
8484

85-
select translated(scope.name), from: :project_decidim_scope_id
85+
select2 translated(scope.name), xpath: '//select[@id="project_decidim_scope_id"]/..', search: true
8686
select translated(category.name), from: :project_decidim_category_id
8787

8888
find("*[type=submit]").click

decidim-core/app/assets/javascripts/decidim.js.es6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// = require decidim/user_registrations
1313
// = require decidim/account_form
1414
// = require decidim/select2
15+
// = require decidim/select2.field
1516

1617
/* globals svg4everybody */
1718

decidim-core/app/assets/javascripts/decidim/form_filter.component.js.es6

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* eslint-disable no-div-regex, no-useless-escape, no-param-reassign, id-length */
22

3-
// = require ./select2.filter
4-
53
/**
64
* A plain Javascript component that handles the form filter.
75
* @class
@@ -53,7 +51,7 @@
5351
this.mounted = true;
5452
let select2Filters = this.select2Filters;
5553
this.$form.find('select.select2').each(function(index, select) {
56-
select2Filters.push(new window.Decidim.Select2Filter(select));
54+
select2Filters.push(new window.Decidim.Select2Field(select));
5755
});
5856
this.$form.on('change', 'input:not(.select2-search__field), select', this._onFormChange);
5957

decidim-core/app/assets/javascripts/decidim/form_filter.component.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ window.$ = require('jquery');
44
require('select2');
55

66
require('./history.js.es6');
7-
require('./select2.filter.js.es6');
7+
require('./select2.field.js.es6');
88
require('./form_filter.component.js.es6');
99

1010
const { Decidim: { FormFilterComponent } } = window;

decidim-core/app/assets/javascripts/decidim/select2.filter.js.es6 renamed to decidim-core/app/assets/javascripts/decidim/select2.field.js.es6

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
*/
44

55
((exports) => {
6-
class Select2Filter {
6+
class Select2Field {
77
constructor(element) {
88
const selectedLang = $("html").attr('lang') || 'en';
99

1010
let $element = $(element);
11+
1112
let options = {
1213
language: selectedLang,
1314
multiple: $element.attr("multiple")==="multiple",
@@ -42,5 +43,5 @@
4243
}
4344

4445
exports.Decidim = exports.Decidim || {};
45-
exports.Decidim.Select2Filter = Select2Filter;
46+
exports.Decidim.Select2Field = Select2Field;
4647
})(window);

0 commit comments

Comments
 (0)