Skip to content

Commit

Permalink
feat(link-value): enter newly created value automatically (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelez committed Apr 8, 2022
1 parent c6fe803 commit 5ccd18d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Expand Up @@ -29,7 +29,7 @@ export class CreateLinkResourceComponent implements OnInit {
@Input() resourceClassDef: string;
@Input() currentOntoIri: string;

@Output() closeDialog: EventEmitter<any> = new EventEmitter<any>();
@Output() closeDialog: EventEmitter<ReadResource> = new EventEmitter<ReadResource>();

@ViewChild('selectProps') selectPropertiesComponent: SelectPropertiesComponent;

Expand Down Expand Up @@ -129,7 +129,7 @@ export class CreateLinkResourceComponent implements OnInit {

this._dspApiConnection.v2.res.createResource(createResource).subscribe(
(res: ReadResource) => {
this.closeDialog.emit();
this.closeDialog.emit(res);
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
Expand Down
Expand Up @@ -7,9 +7,11 @@ import {
OnDestroy,
OnInit,
Output,
SimpleChanges
SimpleChanges,
ViewChild
} from '@angular/core';
import { AbstractControl, FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import {
CreateLinkValue,
Expand Down Expand Up @@ -49,9 +51,10 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
@Input() currentOntoIri: string;

@Output() referredResourceClicked: EventEmitter<ReadLinkValue> = new EventEmitter();

@Output() referredResourceHovered: EventEmitter<ReadLinkValue> = new EventEmitter();

@ViewChild(MatAutocompleteTrigger) autocomplete: MatAutocompleteTrigger;

resources: ReadResource[] = [];
restrictToResourceClass: string;
valueFormControl: FormControl;
Expand Down Expand Up @@ -259,6 +262,16 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
disableClose: true
};

this._dialog.open(DialogComponent, dialogConfig);
const dialogRef = this._dialog.open(DialogComponent, dialogConfig);

dialogRef.afterClosed().subscribe((event: any) => {
const newResource = event as ReadResource;

// set value of value form control to the newly created resource
this.form.controls.value.setValue(newResource);

// hide the autocomplete results
this.autocomplete.closePanel();
});
}
}

0 comments on commit 5ccd18d

Please sign in to comment.