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
[35354]Harmonize work package autocompleters (adding board list modal) (#9301)
Behrokh Satarnejad7127638db622
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 32e811af821..3c6490e4cf6 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -104,6 +104,7 @@ en:button_update: "Update"button_export-pdf: "Download PDF"button_export-atom: "Download Atom"+ button_create: "Create"calendar:title: 'Calendar'diff --git a/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.tsindex 622deb56b87..7c106bb8b7d 100644--- a/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.ts+++ b/frontend/src/app/modules/autocompleter/op-autocompleter/op-autocompleter.component.ts@@ -37,6 +37,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft@Input() public searchKey?:string = '';@Input() public defaulData?:boolean = false;@Input() public focusDirectly?:boolean = true;+ @Input() public fetchDataDirectly?:boolean = false;@Input() public labelRequired?:boolean = true;@Input() public name?:string;@Input() public required?:boolean = false;@@ -155,7 +156,11 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements AftdistinctUntilChanged(),switchMap(queryString => this.getOptionsFn(queryString))));-+ if (this.fetchDataDirectly) {+ this.results$ = this.defaulData+ ? (this.opAutocompleterService.loadData('', this.resource, this.filters, this.searchKey))+ : (this.getOptionsFn(''));+ }if(this.openDirectly) {this.ngSelectInstance.open();this.ngSelectInstance.focus();diff --git a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.tsindex 34c4e952971..19fd3ef3fd1 100644--- a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts+++ b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.component.ts@@ -26,7 +26,7 @@// See docs/COPYRIGHT.rdoc for more details.//++-import { ChangeDetectorRef, Component, ElementRef, Inject, OnInit } from "@angular/core";+import { ChangeDetectorRef, Component, ElementRef, Inject, OnInit, ViewChild} from "@angular/core";import { OpModalLocalsMap } from "core-app/modules/modal/modal.types";import { OpModalComponent } from "core-app/modules/modal/modal.component";import { OpModalLocalsToken } from "core-app/modules/modal/modal.service";@@ -38,21 +38,33 @@ import { BoardActionsRegistryService } from "core-app/modules/boards/board/boardimport { BoardActionService } from "core-app/modules/boards/board/board-actions/board-action.service";import { HalResource } from "core-app/modules/hal/resources/hal-resource";import { AngularTrackingHelpers } from "core-components/angular/tracking-functions";-import { CreateAutocompleterComponent } from "core-app/modules/autocompleter/create-autocompleter/create-autocompleter.component";+import { Observable, of } from "rxjs";import { DebouncedRequestSwitchmap, errorNotificationHandler } from "core-app/helpers/rxjs/debounced-input-switchmap";import { ValueOption } from "core-app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component";import { HalResourceNotificationService } from "core-app/modules/hal/services/hal-resource-notification.service";+import {OpAutocompleterComponent} from "core-app/modules/autocompleter/op-autocompleter/op-autocompleter.component";+import { APIV3Service } from "core-app/modules/apiv3/api-v3.service";+import { CurrentProjectService } from "core-components/projects/current-project.service";+import { tap } from "rxjs/operators";@Component({templateUrl: './add-list-modal.html'})export class AddListModalComponent extends OpModalComponent implements OnInit {- /** Keep a switchmap for search term and loading state */- public requests = new DebouncedRequestSwitchmap<string, ValueOption>(- (searchTerm:string) => this.actionService.loadAvailable(this.board, this.active, searchTerm),- errorNotificationHandler(this.halNotification),- true- );++ @ViewChild(OpAutocompleterComponent, { static: true }) public ngSelectComponent:OpAutocompleterComponent;++ getAutocompleterData = (searchTerm:string):Observable<HalResource[]> => {++ // Remove prefix # from search+ searchTerm = searchTerm.replace(/^#/, '');+ return this.actionService.loadAvailable(this.board, this.active, searchTerm).pipe(tap((values) => this.warnIfNoOptions(values)));+ };++ public autocompleterOptions = {+ resource:"",+ getOptionsFn: this.getAutocompleterData+ };public showClose:boolean;@@ -83,6 +95,7 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {public text:any = {title: this.I18n.t('js.boards.add_list'),button_add: this.I18n.t('js.button_add'),+ button_create: this.I18n.t('js.button_create'),button_cancel: this.I18n.t('js.button_cancel'),close_popup: this.I18n.t('js.close_popup_title'),@@ -95,16 +108,6 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {placeholder: this.I18n.t('js.placeholders.selection'),};- public referenceOutputs = {- onCreate: (value:HalResource) => this.onNewActionCreated(value),- onOpen: () => this.requests.input$.next(''),- onChange: (value:HalResource) => this.onModelChange(value),- onAfterViewInit: (component:CreateAutocompleterComponent) => component.focusInputField()- };-- /** The loaded available values */- availableValues:any;-/** Whether the no results warning is displayed */showWarning = false;@@ -115,48 +118,19 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {readonly halNotification:HalResourceNotificationService,readonly state:StateService,readonly boardService:BoardService,- readonly I18n:I18nService) {+ readonly I18n:I18nService,+ readonly apiV3Service:APIV3Service,+ readonly currentProject:CurrentProjectService) {super(locals, cdRef, elementRef);}ngOnInit() {super.ngOnInit();-this.board = this.locals.board;this.active = new Set(this.locals.active as string[]);this.actionService = this.boardActions.get(this.board.actionAttribute!);--- this- .requests- .output$- .pipe(- this.untilDestroyed()- )- .subscribe((values:unknown[]) => {- let hasMember = false;- if (values.length === 0) {- if (this.requests.lastRequestedValue !== undefined && this.requests.lastRequestedValue !== '') {- hasMember = true;- } else {- hasMember = false;- }- } else {- hasMember = false;- }- this.actionService- .warningTextWhenNoOptionsAvailable(hasMember)- .then((text) => {- this.warningText = text;- });- this.availableValues = values;- this.showWarning = this.requests.lastRequestedValue !== undefined && (values.length === 0);- this.cdRef.detectChanges();- });-- // Request an empty value to load warning early on- this.requests.input$.next('');+ this.autocompleterOptions.resource=this.actionService.localizedName.toLowerCase();}onModelChange(element:HalResource) {@@ -176,13 +150,49 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {.catch(() => this.inFlight = false);}- onNewActionCreated(newValue:HalResource) {- this.selectedAttribute = newValue;- this.create();+ onNewActionCreated() {+ this+ .apiV3Service+ .versions+ .post(this.getVersionPayload(this.ngSelectComponent.ngSelectInstance.searchTerm))+ .subscribe(+ version => { this.selectedAttribute = version;+ this.create();},+ error => {+ this.ngSelectComponent.closeSelect();+ this.halNotification.handleRawError(error);+ });++ }+ private getVersionPayload(name:string) {+ const payload:any = {};+ payload['name'] = name;+ payload['_links'] = {+ definingProject: {+ href: this.apiV3Service.projects.id(this.currentProject.id!).path+ }+ };++ return payload;}- autocompleterComponent() {- return this.actionService.autocompleterComponent();+ private warnIfNoOptions(values:unknown[]) {+ let hasMember = false;+ if (values.length === 0) {+ if (this.ngSelectComponent.ngSelectInstance.searchTerm !== undefined && this.ngSelectComponent.ngSelectInstance.searchTerm !== '') {+ hasMember = true;+ } else {+ hasMember = false;+ }+ } else {+ hasMember = false;+ }+ this.actionService+ .warningTextWhenNoOptionsAvailable(hasMember)+ .then((text) => {+ this.warningText = text;+ });+ this.showWarning = this.ngSelectComponent.ngSelectInstance.searchTerm !== undefined && (values.length === 0);+ this.cdRef.detectChanges();}}-diff --git a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.html b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.htmlindex 7afdd3e214a..4da6dd3fa7e 100644--- a/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.html+++ b/frontend/src/app/modules/boards/board/add-list-modal/add-list-modal.html@@ -16,15 +16,27 @@<div class="form--field-container"><div class="form--select-container"><label class="form--label" [textContent]="actionService.label"></label>- <ndc-dynamic [ndcDynamicComponent]="autocompleterComponent()"- [ndcDynamicInputs]="{ availableValues: availableValues,- typeahead: requests.input$,- appendTo: 'body',- model: '',- classes: 'new-list--action-select',- finishedLoading: true}"- [ndcDynamicOutputs]="referenceOutputs">- </ndc-dynamic>+ <op-autocompleter #select+ classes="new-list--action-select"+ appendTo="body"+ [resource]="autocompleterOptions.resource"+ [openDirectly]="true"+ [fetchDataDirectly]="true"+ [getOptionsFn]=autocompleterOptions.getOptionsFn+ (change)="onModelChange($event)">+ <ng-template op-autocompleter-footer-tmp *ngIf="autocompleterOptions.resource=='version'" let-search>+ <button+ class="op-select-footer--label"+ type="button"+ (click)="onNewActionCreated()">+ <span class="icon-context">+ <op-icon icon-classes="icon-plus icon-context"></op-icon>+ {{text.button_create}} {{ngSelectComponent.ngSelectInstance.searchTerm}}+ </span>+ </button>++ </ng-template>+ </op-autocompleter></div></div></div>diff --git a/modules/boards/spec/features/support/board_page.rb b/modules/boards/spec/features/support/board_page.rbindex bc16c18234e..576384d4dfb 100644--- a/modules/boards/spec/features/support/board_page.rb+++ b/modules/boards/spec/features/support/board_page.rb@@ -191,7 +191,7 @@ module Pagesexpect(page).to have_selector('.board-list--container', count: count + 1)elseopen_and_fill_add_list_modal query- page.find('.ng-option-label', text: option, wait: 10).click+ page.find('.ng-option', text: option, wait: 10).clickclick_on 'Add'endend@@ -199,7 +199,7 @@ module Pagesdef add_list_with_new_value(name)open_and_fill_add_list_modal name- page.find('.ng-option', text: 'Create: ' + name).click+ page.find('.op-select-footer--label', text: 'Create ' + name).clickenddef save@@ -216,7 +216,7 @@ module Pagesenddef expect_list(name)- expect(page).to have_selector('.board-list--header', text: name)+ expect(page).to have_selector('.board-list--header', text: name, wait: 10)enddef expect_no_list(name)@@ -253,9 +253,9 @@ module Pagesopen_and_fill_add_list_modal nameif present- expect(page).to have_selector('.ng-option-label', text: name)+ expect(page).to have_selector('.ng-option', text: name)else- expect(page).not_to have_selector('.ng-option-label', text: name)+ expect(page).not_to have_selector('.ng-option', text: name)endfind('body').send_keys [:escape]end