re base code
[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     providers: [TranslateService]
34 })
35 export class AutomatedUpgradeComponent {
36
37     @Input() componentsToUpgrade: Array<ServiceContainerToUpgradeUiObject>;
38     @Input() certificationStatusText: string;
39     @Input() informationText: string;
40     @Input() disabled: string;
41     private selectedComponentsToUpgrade: Array<string> = [];
42
43     constructor (@Inject(forwardRef(() => AutomatedUpgradeService)) private automatedUpgradeService: AutomatedUpgradeService) {
44     }
45
46     ngOnInit(): void  { // We need to check all elements that needed upgrade as default
47         this.selectedComponentsToUpgrade = _.filter(this.componentsToUpgrade, (componentToUpgrade:ServiceContainerToUpgradeUiObject) => {
48                 return !componentToUpgrade.isAlreadyUpgrade && !componentToUpgrade.isLock;
49         }).map(element => element.uniqueId)
50     }
51
52     onComponentSelected  = (uniqueId:string):void => {
53
54         if(this.selectedComponentsToUpgrade.indexOf(uniqueId) > -1) {
55             this.selectedComponentsToUpgrade = _.without(this.selectedComponentsToUpgrade, uniqueId);
56         } else  {
57             this.selectedComponentsToUpgrade.push(uniqueId);
58         }
59         if(this.selectedComponentsToUpgrade.length === 0) {
60             this.automatedUpgradeService.changeUpgradeButtonState(true);
61         } else {
62             this.automatedUpgradeService.changeUpgradeButtonState(false);
63         }
64     }
65 }