OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Get rid of decorated select altogether
Oliver Günthere3d02dc5047b
diff --git a/app/models/custom_actions/actions/base.rb b/app/models/custom_actions/actions/base.rbindex 8b64662449b..4995d3c9371 100644--- a/app/models/custom_actions/actions/base.rb+++ b/app/models/custom_actions/actions/base.rb@@ -43,6 +43,12 @@ class CustomActions::Actions::Baseraise NotImplementedErrorend+ def value_objects+ values.map do |value|+ allowed_values.find { |v| v[:value] == value }+ end+ end+def typeraise NotImplementedErrorenddiff --git a/app/models/custom_actions/conditions/base.rb b/app/models/custom_actions/conditions/base.rbindex 93828f8d388..ddd0a58fdd3 100644--- a/app/models/custom_actions/conditions/base.rb+++ b/app/models/custom_actions/conditions/base.rb@@ -45,6 +45,12 @@ class CustomActions::Conditions::Base.map { |value, label| { value:, label: } }end+ def value_objects+ values.map do |value|+ allowed_values.find { |v| v[:value] == value }+ end+ end+def human_nameWorkPackage.human_attribute_name(self.class.key)enddiff --git a/app/views/augmented/_autocomplete_select_decoration.html.erb b/app/views/augmented/_autocomplete_select_decoration.html.erbdeleted file mode 100644index 62f4ad43bb8..00000000000--- a/app/views/augmented/_autocomplete_select_decoration.html.erb+++ /dev/null@@ -1,9 +0,0 @@-<div class="autocomplete-select-decoration--wrapper" hidden>- <%= angular_component_tag(- 'opce-select-decoration',- inputs: inputs.merge(- options: select_options,- )- ) %>- <!-- Mapped values are being input as hidden fields here -->-</div>diff --git a/app/views/custom_actions/_form.html.erb b/app/views/custom_actions/_form.html.erbindex 1858ded3b32..2791dd2fdf5 100644--- a/app/views/custom_actions/_form.html.erb+++ b/app/views/custom_actions/_form.html.erb@@ -32,18 +32,17 @@}%><% else %>- <% selected_values = condition.values- select_options = condition.allowed_values.map { |v| { label: v[:label], value: v[:value], selected: selected_values.include?(v[:value]) } } %>- <%= render partial: 'augmented/autocomplete_select_decoration',- locals: {- select_options:,- inputs: {- inputName: input_name,- inputId: "custom_action_conditions_#{condition.key}",- multiple: true,- key: condition.key.to_s- }- } %>+ <%= angular_component_tag 'opce-autocompleter',+ inputs: {+ multiple: true,+ defaultData: false,+ items: condition.allowed_values.map { |v| { id: v[:value], name: v[:label] } },+ model: condition.value_objects.map { |v| { id: v[:value], name: v[:label] } },+ inputName: input_name,+ inputId: "custom_action_conditions_#{condition.key}",+ appendTo: "body",+ }+ %><% end %></div></div>@@ -79,18 +78,17 @@}%><% else %>- <% selected_values = action.values- select_options = action.allowed_values.map { |v| { label: v[:label], value: v[:value], selected: selected_values.include?(v[:value]) } } %>- <%= render partial: 'augmented/autocomplete_select_decoration',- locals: {- select_options:,- inputs: {- inputName: input_name,- inputId: "custom_action_actions_#{action.key}",- multiple: action.multi_value?,- key: action.key.to_s- }- } %>+ <%= angular_component_tag 'opce-autocompleter',+ inputs: {+ multiple: true,+ defaultData: false,+ items: action.allowed_values.map { |v| { id: v[:value], name: v[:label] } },+ model: action.value_objects.map { |v| { id: v[:value], name: v[:label] } },+ inputName: input_name,+ inputId: "custom_action_conditions_#{action.key}",+ appendTo: "body",+ }+ %><% end %></div></div>diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.tsindex 51d14017301..dc2e45c2eea 100644--- a/frontend/src/app/app.module.ts+++ b/frontend/src/app/app.module.ts@@ -123,9 +123,6 @@ import {import {ProjectAutocompleterComponent,} from 'core-app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component';-import {- AutocompleteSelectDecorationComponent,-} from 'core-app/shared/components/autocompleter/autocomplete-select-decoration/autocomplete-select-decoration.component';import {MembersAutocompleterComponent,} from 'core-app/shared/components/autocompleter/members-autocompleter/members-autocompleter.component';@@ -426,7 +423,6 @@ export class OpenProjectModule implements DoBootstrap {registerCustomElement('opce-global-search', GlobalSearchInputComponent, { injector });registerCustomElement('opce-autocompleter', OpAutocompleterComponent, { injector });registerCustomElement('opce-project-autocompleter', ProjectAutocompleterComponent, { injector });- registerCustomElement('opce-select-decoration', AutocompleteSelectDecorationComponent, { injector });registerCustomElement('opce-members-autocompleter', MembersAutocompleterComponent, { injector });registerCustomElement('opce-user-autocompleter', UserAutocompleterComponent, { injector });registerCustomElement('opce-macro-attribute-value', AttributeValueMacroComponent, { injector });diff --git a/frontend/src/app/shared/components/autocompleter/autocomplete-select-decoration/autocomplete-select-decoration.component.ts b/frontend/src/app/shared/components/autocompleter/autocomplete-select-decoration/autocomplete-select-decoration.component.tsdeleted file mode 100644index 897fdbb3dee..00000000000--- a/frontend/src/app/shared/components/autocompleter/autocomplete-select-decoration/autocomplete-select-decoration.component.ts+++ /dev/null@@ -1,134 +0,0 @@-//-- copyright-// OpenProject is an open source project management software.-// Copyright (C) the OpenProject GmbH-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License version 3.-//-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-// Copyright (C) 2006-2013 Jean-Philippe Lang-// Copyright (C) 2010-2013 the ChiliProject Team-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License-// as published by the Free Software Foundation; either version 2-// of the License, or (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-//-// See COPYRIGHT and LICENSE files for more details.-//++--import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core';-import { NgSelectComponent } from '@ng-select/ng-select';-import {- IAutocompleteItem,- OpAutocompleterComponent,-} from 'core-app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component';-import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs';--type SelectItem = { label:string, value:string, selected?:boolean };--export const autocompleteSelectDecorationSelector = 'autocomplete-select-decoration';--@Component({- template: `- <ng-select- [items]="options"- [labelForId]="labelForId"- bindLabel="label"- [multiple]="multiple"- [virtualScroll]="true"- [ngModel]="selected"- [appendTo]="appendTo"- [placeholder]="text.placeholder"- (ngModelChange)="updateSelection($event)">- <ng-template ng-option-tmp let-item="item" let-index="index">- {{ item.label }}- </ng-template>- </ng-select>- `,- selector: autocompleteSelectDecorationSelector,-})-export class AutocompleteSelectDecorationComponent extends OpAutocompleterComponent<IAutocompleteItem> implements OnInit, AfterViewInit {- @ViewChild(NgSelectComponent) public ngSelectComponent:NgSelectComponent;-- public options:SelectItem[];-- /** Get the selected options */- public selected:SelectItem|SelectItem[];-- /** The field key (e.g. status, type, or project) */- @Input() key:string;-- text = {- placeholder: this.I18n.t('js.placeholders.selection'),- };-- ngOnInit():void {- populateInputsFromDataset(this);- const element = this.elementRef.nativeElement as HTMLElement;-- // Add Rails multiple identifier if multiple- if (this.multiple) {- this.inputName += '[]';- }-- // Prepare and build the options- // Expected array of objects with id, name, select- const data:SelectItem[] = JSON.parse(element.dataset.options!);-- // Set initial selection- this.setInitialSelection(data);-- if (!this.multiple) {- this.selected = (this.selected as SelectItem[])[0];- }-- this.options = data;-- // Unhide the parent- element.parentElement!.hidden = false;- }-- // eslint-disable-next-line @angular-eslint/no-empty-lifecycle-method- ngAfterViewInit():void {- // do nothing and prevent the parent hook to be called- }-- setInitialSelection(data:SelectItem[]):void {- this.updateSelection(data.filter((element) => element.selected));- }-- updateSelection(items:SelectItem|SelectItem[]):void {- this.selected = items;- items = _.castArray(items);-- this.removeCurrentSyncedFields();- items.forEach((el:SelectItem) => {- this.createSyncedField(el.value);- });- }-- createSyncedField(value:string):void {- const element = jQuery(this.elementRef.nativeElement);- element- .parent()- .append(`<input type="hidden" name="${this.inputName || ''}" value="${value}" />`);- }-- removeCurrentSyncedFields():void {- const element = jQuery(this.elementRef.nativeElement);- element- .parent()- .find(`input[name="${this.inputName}"]`)- .remove();- }-}diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.tsindex 87a41864d2c..210d04678aa 100644--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts@@ -146,7 +146,7 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet@Input() public items?:IOPAutocompleterOption[]|HalResource[];- private items$ = new BehaviorSubject(null);+ private items$ = new BehaviorSubject<IOPAutocompleterOption[]|null>(null);@Input() public clearSearchOnAdd?:boolean = true;@@ -314,6 +314,10 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocompletthis.typeahead = new BehaviorSubject<string>('');}+ if (this.items) {+ this.items$.next(this.items as IOPAutocompleterOption[]);+ }+if (this.inputValue && !this.model) {this.opAutocompleterService@@ -328,8 +332,7 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocompletngOnChanges(changes:SimpleChanges):void {if (changes.items) {- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument- this.items$.next(changes.items.currentValue);+ this.items$.next(changes.items.currentValue as IOPAutocompleterOption[]);}}diff --git a/frontend/src/app/shared/components/autocompleter/openproject-autocompleter.module.ts b/frontend/src/app/shared/components/autocompleter/openproject-autocompleter.module.tsindex 08f5778d227..6ef1a651a5f 100644--- a/frontend/src/app/shared/components/autocompleter/openproject-autocompleter.module.ts+++ b/frontend/src/app/shared/components/autocompleter/openproject-autocompleter.module.ts@@ -18,9 +18,6 @@ import {import {TimeEntryWorkPackageAutocompleterComponent,} from 'core-app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component';-import {- AutocompleteSelectDecorationComponent,-} from 'core-app/shared/components/autocompleter/autocomplete-select-decoration/autocomplete-select-decoration.component';import {VersionAutocompleterComponent,} from 'core-app/shared/components/autocompleter/version-autocompleter/version-autocompleter.component';@@ -67,7 +64,6 @@ export const OPENPROJECT_AUTOCOMPLETE_COMPONENTS = [ProjectAutocompleterComponent,ProjectAutocompleterTemplateComponent,ColorsAutocompleterComponent,- AutocompleteSelectDecorationComponent,OpAutocompleterComponent,OpAutocompleterOptionTemplateDirective,OpAutocompleterLabelTemplateDirective,diff --git a/frontend/src/global_styles/content/_augmented.sass b/frontend/src/global_styles/content/_augmented.sassdeleted file mode 100644index 306dc5d35eb..00000000000--- a/frontend/src/global_styles/content/_augmented.sass+++ /dev/null@@ -1,30 +0,0 @@-//-- copyright-// OpenProject is an open source project management software.-// Copyright (C) the OpenProject GmbH-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License version 3.-//-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-// Copyright (C) 2006-2013 Jean-Philippe Lang-// Copyright (C) 2010-2013 the ChiliProject Team-//-// This program is free software; you can redistribute it and/or-// modify it under the terms of the GNU General Public License-// as published by the Free Software Foundation; either version 2-// of the License, or (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-//-// See COPYRIGHT and LICENSE files for more details.-//++--.autocomplete-select-decoration--wrapper- position: relativediff --git a/frontend/src/global_styles/content/_index.sass b/frontend/src/global_styles/content/_index.sassindex 5e3ab924f63..2ea87144d61 100644--- a/frontend/src/global_styles/content/_index.sass+++ b/frontend/src/global_styles/content/_index.sass@@ -2,7 +2,6 @@@import accounts_mobile@import api_docs@import avatar-@import augmented@import badges@import blockquotes@import context_menudiff --git a/lib/primer/open_project/forms/autocompleter.html.erb b/lib/primer/open_project/forms/autocompleter.html.erbindex 6dd2b014ab4..8a8139b0473 100644--- a/lib/primer/open_project/forms/autocompleter.html.erb+++ b/lib/primer/open_project/forms/autocompleter.html.erb@@ -1,31 +1,9 @@<%= render(FormControl.new(input: @input, data: @wrapper_data_attributes)) do %><%= content_tag(:div, **@field_wrap_arguments) do %>- <% if decorated_select? %>- <%= render partial: '/augmented/autocomplete_select_decoration',- formats: %i[html],- locals: {- inputs: @autocomplete_options.merge(- classes: "ng-select--primerized #{@input.invalid? ? '-error' : ''}",- inputName: @autocomplete_options.fetch(:inputName) { builder.field_name(@input.name) },- inputId: @autocomplete_options.fetch(:inputId) { builder.field_id(@input.name) },- inputValue: @autocomplete_options.fetch(:inputValue) { builder.object.send(@input.name) },- key: @autocomplete_options.fetch(:resource, ''),- defaultData: @autocomplete_options.fetch(:defaultData) { true }- ),- select_options: select_options.map(&:to_h),- } %>- <% else %>- <%= content_tag(:div, class: ("projects-autocomplete-with-search-icon" if @autocomplete_options.delete(:with_search_icon))) do %>- <%= angular_component_tag @autocomplete_options.fetch(:component),- data: @autocomplete_options.delete(:data) { {} },- inputs: @autocomplete_options.merge(- classes: "ng-select--primerized #{@input.invalid? ? '-error' : ''}",- inputName: @autocomplete_options.fetch(:inputName) { builder.field_name(@input.name) },- inputValue: @autocomplete_options.fetch(:inputValue) { builder.object.send(@input.name) },- defaultData: @autocomplete_options.fetch(:defaultData) { true }- )- %>- <% end %>+ <%= content_tag(:div, class: ("projects-autocomplete-with-search-icon" if @with_search_icon)) do %>+ <%= angular_component_tag(@autocomplete_component,+ data: @autocomplete_data,+ inputs: @autocomplete_inputs) %><% end %><% end %><% end %>diff --git a/lib/primer/open_project/forms/autocompleter.rb b/lib/primer/open_project/forms/autocompleter.rbindex f2d35812d62..c274e944973 100644--- a/lib/primer/open_project/forms/autocompleter.rb+++ b/lib/primer/open_project/forms/autocompleter.rb@@ -8,17 +8,37 @@ module Primerinclude AngularHelperprepend WrappedInput- delegate :builder, :form, :select_options, to: :@input+ delegate :builder, :form, to: :@inputdef initialize(input:, autocomplete_options:, wrapper_data_attributes: {})super()@input = input- @autocomplete_options = autocomplete_options+ @with_search_icon = autocomplete_options.delete(:with_search_icon) { false }+ @autocomplete_component = autocomplete_options.delete(:component) { "opce-autocompleter" }+ @autocomplete_data = autocomplete_options.delete(:data) { {} }+ @autocomplete_inputs = extend_autocomplete_inputs(autocomplete_options)@wrapper_data_attributes = wrapper_data_attributesend- def decorated_select?- @autocomplete_options[:decorated]+ def extend_autocomplete_inputs(inputs) # rubocop:disable Metrics/AbcSize+ inputs[:classes] = "ng-select--primerized #{@input.invalid? ? '-error' : ''}"+ inputs[:inputName] ||= builder.field_name(@input.name)+ inputs[:inputValue] ||= builder.object.send(@input.name)+ inputs[:defaultData] ||= true++ if inputs.delete(:decorated)+ inputs[:items] = @input.select_options.map(&:to_h)+ inputs[:model] = selected_options+ inputs[:defaultData] = false+ end++ inputs+ end++ def selected_options+ @input.select_options.filter_map do |item|+ item.value if item.selected+ endendendenddiff --git a/lib/primer/open_project/forms/dsl/autocompleter_input.rb b/lib/primer/open_project/forms/dsl/autocompleter_input.rbindex 497658f27d9..11cf87d366a 100644--- a/lib/primer/open_project/forms/dsl/autocompleter_input.rb+++ b/lib/primer/open_project/forms/dsl/autocompleter_input.rb@@ -18,9 +18,8 @@ module Primerdef to_h{- label:,- value:,- selected:+ id: value,+ name: label}endenddiff --git a/spec/support/pages/admin/custom_actions/form.rb b/spec/support/pages/admin/custom_actions/form.rbindex 41054956c73..f700f0d551c 100644--- a/spec/support/pages/admin/custom_actions/form.rb+++ b/spec/support/pages/admin/custom_actions/form.rb@@ -118,7 +118,7 @@ module Pagesif has_selector?(".form--selected-value--container", wait: 0)find(".form--selected-value--container").clickautocomplete = true- elsif has_selector?(".autocomplete-select-decoration--wrapper", wait: 0)+ elsif has_selector?("op-autocompleter", wait: 0)autocomplete = trueend