re base code
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / panel / panel-tabs / policies / policy-tabs.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 * as _ from "lodash";
22 import { Component, Inject, Input, Output, EventEmitter, AfterViewInit, OnChanges } from "@angular/core";
23 import { TranslateService } from './../../../../../shared/translator/translate.service';
24 import { PoliciesService } from "../../../../../services/policies.service";
25 import { Component as TopologyTemplate, ComponentInstance, IAppMenu } from "app/models";
26 import { PolicyInstance } from 'app/models/graph/zones/policy-instance';
27 import { GRAPH_EVENTS } from './../../../../../../utils/constants';
28 import { EventListenerService } from 'app/services/event-listener-service';
29 import { ZoneInstance } from 'app/models/graph/zones/zone-instance';
30 import { SimpleChanges } from "@angular/core/src/metadata/lifecycle_hooks";
31
32 @Component({
33     selector: 'policy-tabs',
34     templateUrl: './policy-tabs.component.html'
35 })
36 export class PolicyTabsComponent implements OnChanges {
37  
38     @Input() topologyTemplate:TopologyTemplate;
39     @Input() selectedZoneInstanceType:string;
40     @Input() selectedZoneInstanceId:string;
41     @Input() isViewOnly: boolean;
42     @Output() isLoading: EventEmitter<boolean> = new EventEmitter<boolean>();
43
44     private policy:PolicyInstance;
45
46     constructor(private translateService:TranslateService, 
47                 private policiesService:PoliciesService
48             ) {
49
50     }
51
52     ngOnChanges(changes: SimpleChanges): void {
53         this.initPolicy();
54     }
55
56     private initPolicy = ():void => {
57         this.isLoading.emit(true);
58         this.policiesService.getSpecificPolicy(this.topologyTemplate.componentType, this.topologyTemplate.uniqueId, this.selectedZoneInstanceId).subscribe(
59             policy => {
60                 this.policy = policy;
61                 console.log(JSON.stringify(policy));
62             },
63             error => console.log("Error getting policy!"),
64             () => this.isLoading.emit(false)
65         );
66     }
67
68     private setIsLoading = (value) :void => {
69         this.isLoading.emit(value);
70     }
71
72 }