Add data type view/workspace
[sdc.git] / catalog-ui / src / app / ng2 / pages / type-workspace / type-workspace-general / type-workspace-general.component.ts
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright (C) 2022 Nordix Foundation.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 import {Component, Input, OnInit} from '@angular/core';
23 import {FormControl, FormGroup, Validators} from "@angular/forms";
24 import {DataTypeModel} from "../../../../models/data-types";
25 import { DEFAULT_MODEL_NAME } from "app/utils/constants";
26
27 @Component({
28   selector: 'app-type-workspace-general',
29   templateUrl: './type-workspace-general.component.html',
30   styleUrls: ['./type-workspace-general.component.less']
31 })
32 export class TypeWorkspaceGeneralComponent implements OnInit {
33   @Input() isViewOnly = true;
34   @Input() dataType: DataTypeModel = new DataTypeModel();
35
36   DEFAULT_MODEL_NAME = DEFAULT_MODEL_NAME;
37
38   type: FormControl = new FormControl(undefined, [Validators.required, Validators.minLength(1), Validators.maxLength(300)]);
39   derivedFrom: FormControl = new FormControl(undefined, [Validators.required, Validators.minLength(1)]);
40   description: FormControl = new FormControl(undefined, [Validators.required, Validators.minLength(1)]);
41   model: FormControl = new FormControl(undefined, [Validators.required]);
42   formGroup: FormGroup = new FormGroup({
43     'type': this.type,
44     'description': this.description,
45     'model': this.model,
46     'derivedFrom': this.derivedFrom
47   });
48
49   ngOnInit(): void {
50     this.initForm();
51   }
52
53   private initForm(): void {
54     if (!this.dataType) {
55       return;
56     }
57     this.type.setValue(this.dataType.name);
58     this.description.setValue(this.dataType.description);
59     this.model.setValue(this.dataType.model);
60     this.derivedFrom.setValue(this.dataType.derivedFrom);
61   }
62 }