Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / components / forms / env-params / env-params.component.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
22 import { SdcUiCommon, SdcUiServices } from 'onap-ui-angular';
23 import { Subject } from 'rxjs/Rx';
24 import { ArtifactModel } from '../../../../models/artifacts';
25 import { CacheService } from '../../../services/cache.service';
26
27 export interface IPoint {
28     x: number;
29     y: number;
30 }
31
32 @Component({
33     selector: 'env-params',
34     templateUrl: './env-params.component.html',
35     styleUrls: ['../../../../../assets/styles/table-style.less', './env-params.component.less']
36 })
37 export class EnvParamsComponent implements OnInit {
38
39     @Input() public artifact: ArtifactModel;
40     @Input() public isInstanceSelected: boolean;
41     @Input() public isViewOnly: boolean;
42
43     @ViewChild('textArea') textArea: ElementRef;
44     private copiedWorkingArtifactHeatParameters = [];
45     private onValidationChange: Subject<boolean> = new Subject();
46     private displayRegexValid = SdcUiCommon.RegexPatterns.numberOrEmpty;
47
48     // Deployment timeout in minutes
49     private maxDeploymentTimeout: number = 120;
50     private minDeploymentTimeout: number = 1;
51     private defaultDeploymentTimeout: number = 60;
52
53     constructor(private cacheService: CacheService, private popoverService: SdcUiServices.PopoverService) {
54         const configuration = cacheService.get('UIConfiguration');
55         if (configuration && configuration.heatDeploymentTimeout) {
56             this.maxDeploymentTimeout = configuration.heatDeploymentTimeout.maxMinutes;
57             this.minDeploymentTimeout = configuration.heatDeploymentTimeout.minMinutes;
58             this.defaultDeploymentTimeout = configuration.heatDeploymentTimeout.defaultMinutes;
59         }
60     }
61
62     ngOnInit(): void {
63         this.copiedWorkingArtifactHeatParameters = [...this.artifact.heatParameters];
64     }
65
66     public clearCurrentValue = (name: string) => {
67         this.artifact.heatParameters.filter((param) => param.name === name)[0].currentValue = '';
68     }
69
70     public timeoutChanged(timeout) {
71         this.artifact.timeout = timeout;
72     }
73
74     updateFilter(event) {
75         const val = event.target.value.toLowerCase();
76         // filter our data
77         const temp = this.copiedWorkingArtifactHeatParameters.filter((param) => {
78             return !val || param.name ? param.name.toLowerCase().indexOf(val) !== -1 : -1 || param.currentValue ? param.currentValue.toLowerCase().indexOf(val) !== -1 : -1;
79         });
80         // update the rows
81         this.artifact.heatParameters = temp;
82     }
83
84     private openPopOver = (title: string, content: string, positionOnPage: IPoint, location: string) => {
85         this.popoverService.createPopOver(title, content, positionOnPage, location);
86     }
87
88     private onValidityChange = (isValid: boolean): void => {
89         this.onValidationChange.next(isValid);
90     }
91 }