Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / automated-upgrade / automated-upgrade.component.ts
1 /**
2  * Created by ob0695 on 4/18/2018.
3  */
4 /*-
5  * ============LICENSE_START=======================================================
6  * SDC
7  * ================================================================================
8  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 import {Component, Input, Inject, forwardRef} from "@angular/core";
25 import {TranslateService} from "../../shared/translator/translate.service";
26 import {ServiceContainerToUpgradeUiObject} from "./automated-upgrade-models/ui-component-to-upgrade";
27 import {AutomatedUpgradeService} from "./automated-upgrade.service";
28
29 @Component({
30     selector: 'upgrade-vsp',
31     templateUrl: './automated-upgrade.component.html',
32     styleUrls: ['./automated-upgrade.component.less']
33 })
34 export class AutomatedUpgradeComponent {
35
36     @Input() componentsToUpgrade: Array<ServiceContainerToUpgradeUiObject>;
37     @Input() certificationStatusText: string;
38     @Input() informationText: string;
39     @Input() disabled: string;
40     private selectedComponentsToUpgrade: Array<string> = [];
41
42     constructor (@Inject(forwardRef(() => AutomatedUpgradeService)) private automatedUpgradeService: AutomatedUpgradeService) {
43     }
44
45     ngOnInit(): void  { // We need to check all elements that needed upgrade as default
46         this.selectedComponentsToUpgrade = _.filter(this.componentsToUpgrade, (componentToUpgrade:ServiceContainerToUpgradeUiObject) => {
47                 return !componentToUpgrade.isAlreadyUpgrade && !componentToUpgrade.isLock;
48         }).map(element => element.uniqueId)
49     }
50
51     onComponentSelected  = (uniqueId:string):void => {
52
53         if(this.selectedComponentsToUpgrade.indexOf(uniqueId) > -1) {
54             this.selectedComponentsToUpgrade = _.without(this.selectedComponentsToUpgrade, uniqueId);
55         } else  {
56             this.selectedComponentsToUpgrade.push(uniqueId);
57         }
58         if(this.selectedComponentsToUpgrade.length === 0) {
59             this.automatedUpgradeService.changeUpgradeButtonState(true);
60         } else {
61             this.automatedUpgradeService.changeUpgradeButtonState(false);
62         }
63     }
64 }