Commit add23dab authored by Kristian Ntavidi's avatar Kristian Ntavidi
Browse files

Grant search fix.

* Change the way the single auto complete refreshes.
* Remove some unnecessary code.
parent d9826095
......@@ -223,17 +223,7 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple
this._items = this._inputSubject.pipe(
startWith(null),
debounceTime(this.requestDelay),
distinctUntilChanged((oldvalue, newvalue)=>{
if(oldvalue === newvalue){
if(this._refreshFlag){
this._refreshFlag = false;
return false;
}
return true;
}
this._refreshFlag = false;
return false
}),
distinctUntilChanged(),
switchMap(query => this.filter(query)));
if (this.configuration.groupingFn) { this._groupedItems = this._items.pipe(map(items => this.configuration.groupingFn(items))); }
......@@ -267,6 +257,7 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple
if (value != null) { this.getSelectedItems(value); } else {
if (this.autocompleteInput && this.autocompleteInput.nativeElement && this.autocompleteInput.nativeElement.value) { this.autocompleteInput.nativeElement.value = ''; }
this.inputValue = null;
this._items = null;
}
}
pushChanges(value: any) { this.onChange(value); }
......@@ -340,9 +331,4 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple
// 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;
}
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { ChangeDetectorRef, Inject, OnDestroy } from '@angular/core';
import { OnDestroy } from '@angular/core';
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { FormArray, FormGroup } from '@angular/forms';
import { FieldEditorModel } from '@app/ui/admin/dataset-profile/admin/field-editor-model';
import { FieldSetEditorModel } from '@app/ui/admin/dataset-profile/admin/field-set-editor-model';
import { SectionEditorModel } from '@app/ui/admin/dataset-profile/admin/section-editor-model';
import { BaseComponent } from '@common/base/base.component';
import { Guid } from '@common/types/guid';
import { DragulaService } from 'ng2-dragula';
import { Subscription } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { ToCEntry, ToCEntryType } from '../../../table-of-contents/table-of-contents-entry';
@Component({
......
import { of as observableOf, Observable, combineLatest, BehaviorSubject,of } from 'rxjs';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { AfterViewInit, Component, ElementRef, OnChanges, OnInit, QueryList, SimpleChanges, ViewChild } from '@angular/core';
import { AbstractControl, Form, FormArray, FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
import { Component, OnInit, QueryList, ViewChild } from '@angular/core';
import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { MatHorizontalStepper, MatStep } from '@angular/material/stepper';
import { MatHorizontalStepper} from '@angular/material/stepper';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { debounce, debounceTime, filter, map, mergeMap, takeUntil, tap } from 'rxjs/operators';
import { debounceTime, filter, map, mergeMap, takeUntil, tap } from 'rxjs/operators';
import * as FileSaver from 'file-saver';
import { BaseComponent } from '@common/base/base.component';
import { DatasetProfileEditorModel } from '@app/ui/admin/dataset-profile/editor/dataset-profile-editor-model';
......@@ -26,7 +26,6 @@ import { LanguageInfo } from '@app/core/model/language-info';
import { LanguageInfoService } from '@app/core/services/culture/language-info-service';
import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { Link, LinkToScroll } from '@app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents';
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
import { NewEntryType, ToCEntry, ToCEntryType } from '../table-of-contents/table-of-contents-entry';
......@@ -36,20 +35,13 @@ import { Guid } from '@common/types/guid';
import { FieldEditorModel } from '../admin/field-editor-model';
import { VisibilityRulesService } from '@app/ui/misc/dataset-description-form/visibility-rules/visibility-rules.service';
import { CdkStep, StepperSelectionEvent } from '@angular/cdk/stepper';
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionFieldEditorModel, DatasetDescriptionFormEditorModel, DatasetDescriptionPageEditorModel, DatasetDescriptionSectionEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionFieldEditorModel, DatasetDescriptionSectionEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
import { Rule } from '@app/core/model/dataset-profile-definition/rule';
import { DatasetProfileFieldViewStyle } from '@app/core/common/enum/dataset-profile-field-view-style';
import { invalid } from '@angular/compiler/src/render3/view/util';
import { SideNavService } from '@app/core/services/sidenav/side-nav.sevice';
import { EditorCustomValidators, EditorCustomValidatorsEnum } from './custom-validators/editor-custom-validators';
import { CustomErrorValidator } from '@common/forms/validation/custom-validator';
import { GENERAL_ANIMATIONS, STEPPER_ANIMATIONS } from './animations/animations';
import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type';
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
import { DmpInvitationUser } from '@app/core/model/dmp/invitation/dmp-invitation-user';
import { RequestItem } from '@app/core/query/request-item';
import { DmpInvitationUserCriteria } from '@app/core/query/dmp/dmp-invitation-user-criteria';
import { DmpInvitationService } from '@app/core/services/dmp/dmp-invitation.service';
import { UserService } from '@app/core/services/user/user.service';
import { MatInput } from '@angular/material';
......
......@@ -65,7 +65,7 @@
<div class="grant-form">
<div *ngIf="!isCreateNew">
<mat-form-field appearance="outline">
<app-single-auto-complete #grantSingleAutoComplete required='true' [formControl]="grantformGroup.get('existGrant')" placeholder="{{'DMP-EDITOR.FIELDS.GRANT' | translate}}" [configuration]="grantAutoCompleteConfiguration">
<app-single-auto-complete required='true' [formControl]="grantformGroup.get('existGrant')" placeholder="{{'DMP-EDITOR.FIELDS.GRANT' | translate}}" [configuration]="grantAutoCompleteConfiguration">
</app-single-auto-complete>
</mat-form-field>
</div>
......
......@@ -14,7 +14,6 @@ import { FunderCriteria } from '@app/core/query/funder/funder-criteria';
import { debounceTime, filter, map, switchMap, takeUntil, tap } from 'rxjs/operators';
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,7 +21,6 @@ import { SingleAutoCompleteComponent } from '@app/library/auto-complete/single/s
})
export class FundingInfoComponent extends BaseComponent implements OnInit {
@ViewChild('grantSingleAutoComplete', {static: false}) grantSingeAutoComplete :SingleAutoCompleteComponent;
// @Input() formGroup: FormGroup = null;
@Input() isUserOwner: boolean;
@Input() isNew: boolean;
......@@ -236,7 +234,8 @@ export class FundingInfoComponent extends BaseComponent implements OnInit {
const grantRequestItem: RequestItem<GrantCriteria> = new RequestItem();
grantRequestItem.criteria = new GrantCriteria();
grantRequestItem.criteria.like = query;
if (this.funderFormGroup.get('existFunder').value && !this.isCreateNewFunder) {
const existFunderValue = this.funderFormGroup.get('existFunder').value;
if (existFunderValue && !this.isCreateNewFunder && (existFunderValue.key != this._KEY)) {
grantRequestItem.criteria.funderReference = this.funderFormGroup.controls['existFunder'].value.reference;
}
return this.grantService.getWithExternal(grantRequestItem);
......@@ -272,9 +271,6 @@ 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();
}
......@@ -417,14 +413,10 @@ export class FundingInfoComponent extends BaseComponent implements OnInit {
}
funderValueChanged(funder: any) {
if ((funder.label !== "" && funder.label !== null && funder.label !== undefined)
if ((funder.label !== "" && funder.label !== null && funder.label !== undefined && !isNullOrUndefined(funder.reference) && funder.reference.length )
|| (funder.existFunder !== null && funder.existFunder !== undefined && funder.existFunder.id !== undefined)) {
this.grantformGroup.reset();
this.grantformGroup.enable();
// this.forceFocus = true;
if(!this.isCreateNewFunder){
this._refreshGrants(this.grantSingeAutoComplete);
}
this.setGrantValidators();
} else {
this.grantformGroup.reset();
......@@ -440,124 +432,6 @@ 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<ValidationErrors | null> =>{
// return control.valueChanges.pipe(
// debounceTime(600),
// distinctUntilChanged(),
// mergeMap(value=>{
// const requestItem = new RequestItem<GrantCriteria>();
// requestItem.criteria = new GrantCriteria();
// requestItem.criteria.exactReference = value;
// return this.grantService.getWithExternal(requestItem);
// }),
// takeUntil(this._destroyed),
// map((response)=>{
// if(response && response.length){
// const internalGrants = (response as Array<any>).filter(grant=> grant.key === "Internal");
// if(internalGrants && internalGrants.length){
// return {grantIdentifierExists:true};
// }
// }
// return null;
// // return response && response.length? {grantIdentifierExists:true} : null;
// })
// ).pipe(first())
// }
// }
// private funderUniqueIdentifier(): AsyncValidatorFn{
// return (control: AbstractControl) :Observable<ValidationErrors | null> =>{
// if(!control.valueChanges){
// return of(null);
// }
// return control.valueChanges.pipe(
// debounceTime(600),
// // distinctUntilChanged(),
// switchMap(value=>{
// const requestItem = new RequestItem<FunderCriteria>();
// requestItem.criteria = new FunderCriteria();
// requestItem.criteria.exactReference = value;
// console.log('perasame mia fora');
// return this.funderService.getWithExternal(requestItem);
// }),
// takeUntil(this._destroyed),
// map((response)=>{
// console.log('pername map');
// //got response
// if(response && response.length){
// const internalFunders = (response as Array<any>).filter(funder=> funder.key === 'Internal');
// if(internalFunders && internalFunders.length){
// return {funderIdentifierExists:true};
// }
// return null;
// }
// return null;
// }
// ),
// first()
// )
// // const requestItem = new RequestItem<FunderCriteria>();
// // requestItem.criteria = new FunderCriteria();
// // requestItem.criteria.exactReference = control.value;
// // return this.funderService.getWithExternal(requestItem).pipe(
// // takeUntil(this._destroyed),
// // map((response)=>{
// // if(response && response.length){
// // const internalFunders = (response as Array<any>).filter(funder=> funder.key === 'Internal');
// // if(internalFunders && internalFunders.length){
// // return {funderIdentifierExists:true};
// // }
// // return null;
// // }
// // return null;
// // })
// // )
// }
// }
// private grantProjectIdentifier(): AsyncValidatorFn{
// return (control: AbstractControl) :Observable<ValidationErrors | null> =>{
// return control.valueChanges.pipe(
// debounceTime(600),
// distinctUntilChanged(),
// mergeMap(value=>{
// const requestItem = new RequestItem<ProjectCriteria>();
// requestItem.criteria = new ProjectCriteria();
// requestItem.criteria.exactReference = value;
// // return this.grantService.getWithExternal(requestItem);
// return this.projectService.getWithExternal(requestItem);
// }),
// takeUntil(this._destroyed),
// map((response)=>{
// if(response && response.length){
// const internalProjects = (response as Array<any>).filter(grant=> grant.key === "Internal");
// if(internalProjects && internalProjects.length){
// return {projectIdentifierExists:true};
// }
// }
// return null;
// // return response && response.length? {grantIdentifierExists:true} : null;
// })
// ).pipe(first())
// }
// }
private consoleForm(){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment