-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmetadata-input-modal.component.ts
69 lines (64 loc) · 1.83 KB
/
metadata-input-modal.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
import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormControl, Validators } from "@angular/forms";
import { MatDialogRef } from "@angular/material/dialog";
import { MetadataInputBase, Type } from "../base-classes/metadata-input-base";
export interface InputObject {
parent: string;
type: string;
child: string;
value: any;
unit?: string;
}
@Component({
selector: "metadata-input-modal",
templateUrl: "./metadata-input-modal.component.html",
styleUrls: ["./metadata-input-modal.component.scss"],
})
export class MetadataInputModalComponent
extends MetadataInputBase
implements OnInit
{
constructor(
private formBuilder: FormBuilder,
public dialogRef: MatDialogRef<MetadataInputModalComponent>,
) {
super();
}
ngOnInit(): void {
this.metadataForm = this.initilizeFormControl();
}
initilizeFormControl() {
const field = this.formBuilder.group({
parent: new FormControl("", [
Validators.required,
Validators.minLength(2),
]),
type: new FormControl("", [Validators.required]),
child: new FormControl("", [
Validators.required,
Validators.minLength(2),
]),
value: new FormControl("", [
Validators.required,
Validators.minLength(1),
]),
date: new FormControl("", [Validators.required, this.dateValidator()]),
unit: new FormControl("", [Validators.required, this.unitValidator()]),
});
return field;
}
onSave(): void {
const { parent, type, child, value, date, unit } = this.metadataForm.value;
const data: InputObject = {
parent,
type,
child,
value: type === Type.date ? new Date(date).toISOString() : value, // Date input could be string or Date
unit,
};
this.dialogRef.close(data);
}
onClose(): void {
this.dialogRef.close();
}
}