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
[#58522] add drop down selection to hierarchy cfs
Eric Schubert3b1ba8359d02
diff --git a/app/models/custom_value/hierarchy_strategy.rb b/app/models/custom_value/hierarchy_strategy.rbindex e87133e0fab..86d63d5145b 100644--- a/app/models/custom_value/hierarchy_strategy.rb+++ b/app/models/custom_value/hierarchy_strategy.rb@@ -28,11 +28,14 @@class CustomValue::HierarchyStrategy < CustomValue::ARObjectStrategydef validate_type_of_value- raise NotImplementedError- end+ item = CustomField::Hierarchy::Item.find_by(id: value)+ return :invalid if item.nil?++ parent = custom_field.hierarchy_root- def typed_value- raise NotImplementedError+ if persistence_service.descendant_of?(item:, parent:).failure?+ :inclusion+ endendprivate@@ -42,11 +45,15 @@ class CustomValue::HierarchyStrategy < CustomValue::ARObjectStrategyenddef ar_object(value)- option = CustomField::Hierarchy::Item.find_by(id: value.to_s)- if option.nil?+ item = CustomField::Hierarchy::Item.find_by(id: value.to_s)+ if item.nil?"#{value} #{I18n.t(:label_not_found)}"else- option.value+ item.labelendend++ def persistence_service+ @persistence_service ||= CustomFields::Hierarchy::HierarchicalItemService.new+ endenddiff --git a/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.htmlindex 3fbc41ef600..2800f07a2a8 100644--- a/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.html+++ b/frontend/src/app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component.html@@ -20,12 +20,13 @@(keydown)="keyPressed($event)"bindLabel="name"><ng-template ng-tag-tmp let-search="searchTerm">- <b [textContent]="text.add_new_action"></b>: {{search}}+ <b [textContent]="text.add_new_action"></b>: {{ search }}</ng-template><ng-template ng-option-tmp let-item="item" let-search="searchTerm"><span [ngOptionHighlight]="search"[textContent]="item.name"+ [ngStyle]="{'padding-left.px': item.depth * 16}"class="ng-option-label ellipsis"></span></ng-template>diff --git a/frontend/src/app/shared/components/fields/edit/edit-field.initializer.ts b/frontend/src/app/shared/components/fields/edit/edit-field.initializer.tsindex c1574f2a09e..4164daa06fb 100644--- a/frontend/src/app/shared/components/fields/edit/edit-field.initializer.ts+++ b/frontend/src/app/shared/components/fields/edit/edit-field.initializer.ts@@ -105,11 +105,13 @@ export function initializeCoreEditFields(editFieldService:EditFieldService, sele'TimeEntriesActivity','Category','CustomOption',+ 'CustomField::Hierarchy::Item',]).addFieldType(MultiSelectEditFieldComponent, 'multi-select', ['[]CustomOption','[]User','[]Version',+ '[]CustomField::Hierarchy::Item',]).addFieldType(FloatEditFieldComponent, 'float', ['Float']).addFieldType(WorkPackageEditFieldComponent, 'workPackage', ['WorkPackage'])diff --git a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.html b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.htmlindex ebe070a6c28..975542bd651 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.html+++ b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.html@@ -18,6 +18,13 @@[appendTo]="appendTo"[dropdownPosition]="'top'"[hideSelected]="true">+ <ng-template ng-option-tmp let-item="item">+ <span+ class="ng-option-label ellipsis"+ [textContent]="item.name"+ [ngStyle]="{'padding-left.px': item.depth * 16}"+ ></span>+ </ng-template><ng-template ng-footer-tmp *ngIf="showAddNewUserButton"><op-invite-user-button[projectId]="resource.project?.id"diff --git a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.tsindex 4311f7cdf35..d718bfc7e75 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.ts+++ b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.ts@@ -173,7 +173,7 @@ export class MultiSelectEditFieldComponent extends EditFieldComponent implements});}- this.availableOptions = availableValues || [];+ this.availableOptions = this.filterInvalidValues(availableValues || []);this._selectedOption = this.buildSelectedOption();this.checkCurrentValueValidity();@@ -207,6 +207,10 @@ export class MultiSelectEditFieldComponent extends EditFieldComponent implementsreturn Promise.resolve();}+ private filterInvalidValues(availableValues:HalResource[]) {+ return availableValues.filter((value) => !!value.name);+ }+private checkCurrentValueValidity() {if (this.value) {this.currentValueInvalid = !!(diff --git a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.tsindex b8e2080f9fd..3405647cfb4 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts+++ b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts@@ -26,19 +26,20 @@// See COPYRIGHT and LICENSE files for more details.//++-import { Component, InjectFlags, OnInit, } from '@angular/core';+import { ChangeDetectionStrategy, Component, InjectFlags, OnInit } from '@angular/core';+import { StateService, UIRouterGlobals } from '@uirouter/core';+import { from, Observable } from 'rxjs';+import { map, tap } from 'rxjs/operators';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';+import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import {- SelectAutocompleterRegisterService+ SelectAutocompleterRegisterService,} from 'core-app/shared/components/fields/edit/field-types/select-edit-field/select-autocompleter-register.service';-import { from, Observable, } from 'rxjs';-import { map, tap, } from 'rxjs/operators';-import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import {- CreateAutocompleterComponent+ CreateAutocompleterComponent,} from 'core-app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component';import { EditFormComponent } from 'core-app/shared/components/fields/edit/edit-form/edit-form.component';-import { StateService, UIRouterGlobals } from '@uirouter/core';import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { HalResourceSortingService } from 'core-app/features/hal/services/hal-resource-sorting.service';@@ -52,6 +53,7 @@ export interface ValueOption {@Component({templateUrl: './select-edit-field.component.html',+ changeDetection: ChangeDetectionStrategy.OnPush,})export class SelectEditFieldComponent extends EditFieldComponent implements OnInit {@InjectField() selectAutocompleterRegister:SelectAutocompleterRegisterService;@@ -151,7 +153,8 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn}private setValues(availableValues:HalResource[]) {- this.availableOptions = this.sortValues(availableValues);+ const sortedValues = this.sortValues(availableValues);+ this.availableOptions = this.filterInvalidValues(sortedValues);this.addEmptyOption();}@@ -285,6 +288,10 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInreturn this.halSorting.sort(availableValues);}+ private filterInvalidValues(availableValues:HalResource[]) {+ return availableValues.filter((value) => !!value.name);+ }+// Subclasses shall be able to override the filters with which the// allowed values are reduced in the backend.protected allowedValuesFilter(query?:string) {diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rbindex d07b1dc6ead..c90a77c4139 100644--- a/lib/api/v3/utilities/custom_field_injector.rb+++ b/lib/api/v3/utilities/custom_field_injector.rb@@ -51,7 +51,7 @@ module API"user" => ["users", "groups", "placeholder_users"],"version" => "versions","list" => "custom_options",- "hierarchy" => "hierarchical_items"+ "hierarchy" => "custom_field_items"}.freezeREPRESENTER_MAP = {diff --git a/lib/api/v3/utilities/custom_field_injector/link_value_getter.rb b/lib/api/v3/utilities/custom_field_injector/link_value_getter.rbindex 01c86d6eaef..54cc44c8924 100644--- a/lib/api/v3/utilities/custom_field_injector/link_value_getter.rb+++ b/lib/api/v3/utilities/custom_field_injector/link_value_getter.rb@@ -85,6 +85,8 @@ module APIderive_principal_path_method(custom_value)when "list":custom_option+ when "hierarchy"+ :custom_field_itemelsecustom_field.field_formatend