diff --git a/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.html b/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.html
index 6365667ae..373ceaa0f 100644
--- a/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.html
+++ b/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.html
@@ -12,8 +12,14 @@
{{field}}
-
+
{{'GENERAL.VALIDATION.REQUIRED' | translate}}
+
+
+ check
+ clear
+ {{'REFERENCE-FIELD.REFERENCE-DIALOG-EDITOR.IDENTIFIER-EXISTS' | translate}}
+
@@ -22,17 +28,16 @@
{{field.label}}
-
+
{{'GENERAL.VALIDATION.REQUIRED' | translate}}
- {{formGroup.value | json}}
diff --git a/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.ts b/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.ts
index ced2a056b..c7298a3df 100644
--- a/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.ts
+++ b/dmp-frontend/src/app/ui/reference/reference-field/editor/reference-dialog-editor.component.ts
@@ -19,6 +19,13 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
referenceType: ReferenceType;
systemFields: string[];
label: string = null
+ private existingReferences: string[] = [];
+
+ get referenceExists(){
+ const reference = this.formGroup.get(this.systemFields[0]).value;
+
+ return this.existingReferences.find((r)=>r === reference)
+ }
constructor(
private referenceTypeService: ReferenceTypeService,
@@ -29,6 +36,7 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
) {
super();
this.label = data.label;
+ this.existingReferences = data.existingReferences;
this.formGroup = this.fb.group({});
}
@@ -59,6 +67,10 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
}
+ isFormValid() {
+ return this.formGroup.valid && !this.referenceExists;
+ }
+
send() {
this.formService.touchAllFormFields(this.formGroup);
if (!this.formGroup.valid) { return; }
diff --git a/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts b/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts
index 99957ce50..c01fde684 100644
--- a/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts
+++ b/dmp-frontend/src/app/ui/reference/reference-field/reference-field.component.ts
@@ -9,7 +9,10 @@ import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/sing
import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/operators';
import { ReferenceDialogEditorComponent } from './editor/reference-dialog-editor.component';
-import { ReferencePersist } from '@app/core/model/reference/reference';
+import { Reference, ReferencePersist } from '@app/core/model/reference/reference';
+import { ReferenceSearchLookup } from '@app/core/query/reference-search.lookup';
+import { Guid } from '@common/types/guid';
+import { nameof } from 'ts-simple-nameof';
@Component({
selector: 'app-reference-field-component',
@@ -44,25 +47,43 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit {
}
addReference() {
- const dialogRef = this.dialog.open(ReferenceDialogEditorComponent, {
- width: '500px',
- restoreFocus: false,
- data: {
- referenceTypeId: this.referenceType.id,
- label: this.label ?? this.referenceType.name
- },
- });
- dialogRef.afterClosed()
- .pipe(takeUntil(this._destroyed))
- .subscribe(newResult => {
- if (!newResult) { return; }
- // const dataRepositoryModel = new ExternalDataRepositoryEditorModel(result.id, result.name, result.abbreviation, result.uri, result.pid, result.source);
- // (this.formGroup.get('dataRepositories')).push(dataRepositoryModel.buildForm());
- let results = this.form.value as ReferencePersist[];
- if (results == undefined) results = [];
- results.push(newResult);
- this.form.setValue(results);
- });
+ this.referenceService.searchWithDefinition(this.buildAutocompleteSearchLookup(this.referenceType.id))
+ .pipe(takeUntil(this._destroyed))
+ .subscribe(
+ references => {
+ const dialogRef = this.dialog.open(ReferenceDialogEditorComponent, {
+ width: '500px',
+ restoreFocus: false,
+ data: {
+ referenceTypeId: this.referenceType.id,
+ label: this.label ?? this.referenceType.name,
+ existingReferences: references.map(x => x.reference)
+ },
+ });
+ dialogRef.afterClosed()
+ .pipe(takeUntil(this._destroyed))
+ .subscribe(newResult => {
+ if (!newResult) { return; }
+ let results = this.form.value as ReferencePersist[];
+ if (results == undefined) results = [];
+ results.push(newResult);
+ this.form.setValue(results);
+ });
+ }
+ );
+ }
+
+ private buildAutocompleteSearchLookup(typeId: Guid): ReferenceSearchLookup {
+ const lookup: ReferenceSearchLookup = new ReferenceSearchLookup();
+ lookup.page = { size: 100, offset: 0 };
+ lookup.project = {
+ fields: [
+ nameof(x => x.reference),
+ ]
+ };
+ lookup.typeId = typeId;
+ lookup.order = { items: [nameof(x => x.label)] };
+ return lookup;
}
}
diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json
index 6cc4950c9..4b310778a 100644
--- a/dmp-frontend/src/assets/i18n/en.json
+++ b/dmp-frontend/src/assets/i18n/en.json
@@ -1354,7 +1354,8 @@
"INSERT-MANUALLY": "Insert it manually"
},
"REFERENCE-DIALOG-EDITOR": {
- "TITLE": "Add a"
+ "TITLE": "Add a",
+ "IDENTIFIER-EXISTS": "Reference Identifier Exists!"
}
},
"DMP-CLONE-DIALOG": {