-
Notifications
You must be signed in to change notification settings - Fork 6
/
create-list-item-dialog.component.ts
74 lines (65 loc) · 2.31 KB
/
create-list-item-dialog.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { StringLiteral } from '@dasch-swiss/dsp-js';
import { ListApiService } from '@dasch-swiss/vre/shared/app-api';
import { ProjectService } from '@dasch-swiss/vre/shared/app-helper-services';
import { MultiLanguages } from '@dasch-swiss/vre/shared/app-string-literal';
import { ListItemForm } from '../list-item-form.type';
export interface CreateListItemDialogProps {
nodeIri: string;
parentIri: string;
projectIri: string;
position: number;
}
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'app-create-list-item-dialog',
template: `
<app-dialog-header title="Insert new child node"></app-dialog-header>
<div mat-dialog-content>
<app-reusable-list-item-form
[formData]="initialFormValue"
(afterFormInit)="form = $event"></app-reusable-list-item-form>
</div>
<div mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button>
<button
mat-raised-button
color="primary"
appLoadingButton
[isLoading]="loading"
[disabled]="form.invalid"
(click)="createChildNode()">
Submit
</button>
</div>
`,
})
export class CreateListItemDialogComponent {
form: ListItemForm;
loading = false;
initialFormValue = { labels: [] as MultiLanguages, comments: [] as MultiLanguages };
constructor(
@Inject(MAT_DIALOG_DATA)
public data: CreateListItemDialogProps,
public dialogRef: MatDialogRef<CreateListItemDialogComponent, boolean>,
private _listApiService: ListApiService
) {}
createChildNode() {
this.loading = true;
const payload = {
parentNodeIri: this.data.parentIri,
projectIri: this.data.projectIri,
labels: this.form.value.labels as StringLiteral[],
comments: this.form.value.comments as StringLiteral[],
position: this.data.position,
name: `${ProjectService.IriToUuid(this.data.projectIri)}-${Math.random().toString(36).substring(2)}${Math.random()
.toString(36)
.substring(2)}`,
};
this._listApiService.createChildNode(payload.parentNodeIri, payload).subscribe(() => {
this.loading = false;
this.dialogRef.close(true);
});
}
}