From d9826095bc207a478cedf0e9bdc4328854a6f29c Mon Sep 17 00:00:00 2001 From: Kristan Ntavidi Date: Fri, 11 Jun 2021 15:35:47 +0300 Subject: [PATCH] Dmp editor. Fix issue on selecting grant after search. --- .../single-auto-complete-configuration.ts | 4 ++-- .../single/single-auto-complete.component.ts | 24 +++++++++++++++---- .../dataset-wizard.component.html | 2 +- .../funding-info/funding-info.component.html | 2 +- .../funding-info/funding-info.component.ts | 21 +++++++++++----- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts index fbb609e3c..2b4c9561a 100644 --- a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts +++ b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete-configuration.ts @@ -32,8 +32,8 @@ export interface SingleAutoCompleteConfiguration { // Selected value formating template selectedValueTemplate?: TemplateRef; - // To revert: "We set the items observable on focus to avoid the request being executed on component load." - forceFocus?: boolean; + // // To revert: "We set the items observable on focus to avoid the request being executed on component load." + // forceFocus?: boolean; autoSelectFirstOptionOnBlur?: boolean; } diff --git a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts index bbcd65fa8..ea9f77e24 100644 --- a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts +++ b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts @@ -219,12 +219,21 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple } _onInputFocus() { - // We set the items observable on focus to avoid the request being executed on component load. - if (!this._items || this.forceFocus) { + if (!this._items) { this._items = this._inputSubject.pipe( startWith(null), debounceTime(this.requestDelay), - distinctUntilChanged(), + distinctUntilChanged((oldvalue, newvalue)=>{ + if(oldvalue === newvalue){ + if(this._refreshFlag){ + this._refreshFlag = false; + return false; + } + return true; + } + this._refreshFlag = false; + return false + }), switchMap(query => this.filter(query))); if (this.configuration.groupingFn) { this._groupedItems = this._items.pipe(map(items => this.configuration.groupingFn(items))); } @@ -328,7 +337,12 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple return this.configuration.autoSelectFirstOptionOnBlur != null ? this.configuration.autoSelectFirstOptionOnBlur : false; } - get forceFocus(): boolean { - return this.configuration.forceFocus != null ? this.configuration.forceFocus : false; + // get forceFocus(): boolean { + // return this.configuration.forceFocus != null ? this.configuration.forceFocus : false; + // } + public refresh(){ + this._refreshFlag = true; + this._inputSubject.next(this.inputValue); } + private _refreshFlag = false; } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html index 912ec5bab..ca513b5b7 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html @@ -33,11 +33,11 @@
- +
diff --git a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html index 7dfd317d6..932a2889a 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.html @@ -65,7 +65,7 @@
- +
diff --git a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts index 588bc2c0a..e4040e68e 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/funding-info/funding-info.component.ts @@ -1,5 +1,5 @@ import { BaseComponent } from '@common/base/base.component'; -import { OnInit, Component, Input, EventEmitter, Output } from '@angular/core'; +import { OnInit, Component, Input, EventEmitter, Output, ViewChild } from '@angular/core'; import { AbstractControl, FormGroup, Validators } from '@angular/forms'; import { TranslateService } from '@ngx-translate/core'; import { GrantTabModel } from '../grant-tab/grant-tab-model'; @@ -12,9 +12,9 @@ import { GrantCriteria } from '@app/core/query/grant/grant-criteria'; import { ProjectCriteria } from '@app/core/query/project/project-criteria'; import { FunderCriteria } from '@app/core/query/funder/funder-criteria'; import { debounceTime, filter, map, switchMap, takeUntil, tap } from 'rxjs/operators'; -import { GrantEditorModel } from '@app/ui/grant/editor/grant-editor.model'; import { isNullOrUndefined } from '@swimlane/ngx-datatable'; +import { SingleAutoCompleteComponent } from '@app/library/auto-complete/single/single-auto-complete.component'; @Component({ selector: 'funding-info', templateUrl: './funding-info.component.html', @@ -22,6 +22,7 @@ import { isNullOrUndefined } from '@swimlane/ngx-datatable'; }) export class FundingInfoComponent extends BaseComponent implements OnInit { + @ViewChild('grantSingleAutoComplete', {static: false}) grantSingeAutoComplete :SingleAutoCompleteComponent; // @Input() formGroup: FormGroup = null; @Input() isUserOwner: boolean; @Input() isNew: boolean; @@ -39,7 +40,7 @@ export class FundingInfoComponent extends BaseComponent implements OnInit { isCreateNewProject = false; isCreateNewFunder = false; grant: GrantTabModel; - forceFocus = false; + // forceFocus = false; grantAutoCompleteConfiguration: SingleAutoCompleteConfiguration; projectAutoCompleteConfiguration: SingleAutoCompleteConfiguration; @@ -219,7 +220,6 @@ export class FundingInfoComponent extends BaseComponent implements OnInit { displayFn: (item) => item['label'] + this.getGrantIdText(item), titleFn: (item) => item['label'] + this.getGrantIdText(item), subtitleFn: (item) => item['source'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['source'] : (item['key'] ? this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.SOURCE:') + item['key'] : this.language.instant('TYPES.EXTERNAL-DATASET-TYPE.NO-SOURCE')), - forceFocus: this.forceFocus, } // this.forceFocus = false; @@ -236,7 +236,7 @@ export class FundingInfoComponent extends BaseComponent implements OnInit { const grantRequestItem: RequestItem = new RequestItem(); grantRequestItem.criteria = new GrantCriteria(); grantRequestItem.criteria.like = query; - if (this.funderFormGroup.get('existFunder').value) { + if (this.funderFormGroup.get('existFunder').value && !this.isCreateNewFunder) { grantRequestItem.criteria.funderReference = this.funderFormGroup.controls['existFunder'].value.reference; } return this.grantService.getWithExternal(grantRequestItem); @@ -272,6 +272,9 @@ export class FundingInfoComponent extends BaseComponent implements OnInit { createFunder() { if (this.isNewVersion) { return }; this.isCreateNewFunder = !this.isCreateNewFunder; + if(this.isCreateNewFunder){ + this._refreshGrants(this.grantSingeAutoComplete); + } this.setFunderValidators(); } @@ -418,7 +421,10 @@ export class FundingInfoComponent extends BaseComponent implements OnInit { || (funder.existFunder !== null && funder.existFunder !== undefined && funder.existFunder.id !== undefined)) { this.grantformGroup.reset(); this.grantformGroup.enable(); - this.forceFocus = true; + // this.forceFocus = true; + if(!this.isCreateNewFunder){ + this._refreshGrants(this.grantSingeAutoComplete); + } this.setGrantValidators(); } else { this.grantformGroup.reset(); @@ -434,6 +440,9 @@ export class FundingInfoComponent extends BaseComponent implements OnInit { showToggleButton() { return (!this.isFinalized && this.isUserOwner) || this.isClone; } + private _refreshGrants(autocompleteComponent:SingleAutoCompleteComponent){ + autocompleteComponent.refresh(); + } // private grantUniqueIdentifier(): AsyncValidatorFn{ // return (control: AbstractControl) :Observable =>{