DMP Editor. Organizations identifier query params patch.

This commit is contained in:
Kristian Ntavidi 2021-04-30 16:14:13 +03:00
parent a155f2cbec
commit b82398d97e
5 changed files with 26 additions and 4 deletions

View File

@ -2,4 +2,5 @@ import { BaseCriteria } from "../base-criteria";
export class OrganisationCriteria extends BaseCriteria {
public labelLike: string;
public like?: string;
}

View File

@ -5,7 +5,7 @@
<input matInput formControlName="reference" [placeholder]="'DMP-EDITOR.MAIN-INFO.UNIQUE-IDENTIFIER' | translate" required>
<mat-error *ngIf="formGroup.get('reference').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
<i matSuffix class="fa fa-spinner fa-spin" *ngIf="formGroup.get('reference').pending !referenceExists"></i>
<mat-error *ngIf="formGroup.get('reference').hasError('organizationIdentifierExists')">{{'DMP-EDITOR.MAIN-INFO.ORGANISATION-IDENTIFIER-EXISTS' | translate}}</mat-error>
<mat-error *ngIf="formGroup.get('reference').hasError('organizationIdentifierExists')">{{'DMP-EDITOR.MAIN-INFO.ORGANISATION-IDENTIFIER-EXSTS' | translate}}</mat-error>
<mat-icon *ngIf="!formGroup.get('reference').pending && formGroup.get('reference').dirty && formGroup.get('reference').valid && !referenceExists" class="text-success" matSuffix>check</mat-icon>
<mat-icon *ngIf="!formGroup.get('reference').pending && formGroup.get('reference').dirty && formGroup.get('reference').invalid || referenceExists" class="text-danger" matSuffix>clear</mat-icon>
<small *ngIf="referenceExists" class="text-danger">{{'DMP-EDITOR.MAIN-INFO.IDENTIFIER-EXISTS-ORGANISATION-LIST' | translate}}</small>

View File

@ -29,6 +29,7 @@ export class AddOrganizationComponent extends BaseComponent implements OnInit {
private externalSourcesService: ExternalSourcesService,
private externalResearcherService: ExternalResearcherService,
public dialogRef: MatDialogRef<AddOrganizationComponent>,
private organizationService: OrganisationService,
@Inject(MAT_DIALOG_DATA) public data: any
) {
super();
@ -64,11 +65,11 @@ export class AddOrganizationComponent extends BaseComponent implements OnInit {
return (control: AbstractControl) :Observable<ValidationErrors | null> =>{
return control.valueChanges.pipe(
debounceTime(600),
mergeMap(value=>this.externalSourcesService.searchDMPOrganizations('',this._REFERENCE_PREFIX +value)),
mergeMap(value=>this.organizationService.searchGeneralOrganisations({criteria:{labelLike:'', like: this._REFERENCE_PREFIX +value}})),
takeUntil(this._destroyed),
map((response)=>{
if(response && response.length){
const internalOrganizations = (response as Array<any>).filter(organization=> organization.key === this._KEY);
const internalOrganizations = (response as Array<any>).filter(organization=> organization.key === this._KEY).filter(organization=> organization.reference === this._REFERENCE_PREFIX + control.value);
if(internalOrganizations && internalOrganizations.length){
return {organizationIdentifierExists:true};

View File

@ -53,6 +53,12 @@ export class FundingInfoComponent extends BaseComponent implements OnInit {
private readonly _GRANT_PREFIX = "dmp:";
private readonly _PROJECT_PREFIX = "dmp:";
private readonly _KEY = "Internal";
private initialFunderIdentifier:string;
private initialGrantIdentifier:string;
private initialProjectIdentifier:string;
constructor(
private grantService: GrantService,
private projectService: ProjectService,
@ -76,6 +82,11 @@ export class FundingInfoComponent extends BaseComponent implements OnInit {
this.configureAutoCompletes();
this.initialFunderIdentifier = this.funderFormGroup.get('reference').value;
this.initialGrantIdentifier = this.grantformGroup.get('reference').value;
this.initialProjectIdentifier = this.projectFormGroup.get('reference').value;
this.initializeReferenceValidators();
this.isCreateNew = (this.grantformGroup.get('label').value != null && this.grantformGroup.get('label').value.length > 0);
@ -123,6 +134,9 @@ export class FundingInfoComponent extends BaseComponent implements OnInit {
)
.subscribe(error=>{
this.isFunderPending = false;
if(this.initialFunderIdentifier === this.funderFormGroup.get('reference').value){
error = null;
}
this.funderFormGroup.get('reference').setErrors(error);
if(!error && this.funderFormGroup.get('reference').validator){
const validator = this.funderFormGroup.get('reference').validator({} as AbstractControl);
@ -158,6 +172,9 @@ export class FundingInfoComponent extends BaseComponent implements OnInit {
)
.subscribe(error=>{
this.isGrantPending = false;
if(this.initialGrantIdentifier === this.grantformGroup.get('reference').value){
error = null;
}
this.grantformGroup.get('reference').setErrors(error);
if(!error && this.grantformGroup.get('reference').validator){
const validator = this.grantformGroup.get('reference').validator({} as AbstractControl);
@ -192,6 +209,9 @@ export class FundingInfoComponent extends BaseComponent implements OnInit {
)
.subscribe(error=>{
this.isProjectPending = false;
if(this.initialProjectIdentifier === this.projectFormGroup.get('reference').value){
error = null;
}
this.projectFormGroup.get('reference').setErrors(error);
if(!error && this.projectFormGroup.get('reference').validator){
const validator = this.projectFormGroup.get('reference').validator({} as AbstractControl);

View File

@ -147,7 +147,7 @@ export class MainInfoComponent extends BaseComponent implements OnInit {
}
filterOrganisations(value: string): Observable<ExternalSourceItemModel[]> {
return this.organizationService.searchGeneralOrganisations({ criteria: { labelLike: value, like: value } });
return this.organizationService.searchGeneralOrganisations({ criteria: { labelLike: value } });
}
cantAddOrganizations(): boolean {