2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import { Component, Input, AfterViewInit, SimpleChanges, OnInit, OnChanges } from "@angular/core";
22 import { SdcUiComponents } from "sdc-ui/lib/angular";
23 import { IModalConfig } from 'sdc-ui/lib/angular/modals/models/modal-config';
24 import { ZoneInstanceType } from 'app/models/graph/zones/zone-instance';
25 import { ValueEditComponent } from './../../../../components/ui/forms/value-edit/value-edit.component';
26 import { Component as TopologyTemplate, ComponentInstance, IAppMenu } from "app/models";
27 import { PoliciesService } from '../../../../services/policies.service';
28 import { GroupsService } from '../../../../services/groups.service';
29 import {IZoneService} from "../../../../../models/graph/zones/zone";
30 import { EventListenerService, LoaderService } from "../../../../../services";
31 import { GRAPH_EVENTS, EVENTS } from "../../../../../utils";
32 import { UIZoneInstanceObject } from "../../../../../models/ui-models/ui-zone-instance-object";
33 import { ModalButtonComponent } from "sdc-ui/lib/angular/components";
36 selector: 'ng2-composition-panel-header',
37 templateUrl: './panel-header.component.html',
38 styleUrls: ['./panel-header.component.less']
40 export class CompositionPanelHeaderComponent implements OnInit, OnChanges {
42 @Input() topologyTemplate: TopologyTemplate;
43 @Input() selectedZoneInstanceType: ZoneInstanceType;
44 @Input() selectedZoneInstanceId: string;
45 @Input() name: string;
46 @Input() nonCertified: boolean;
47 @Input() isViewOnly: boolean;
48 @Input() isLoading: boolean;
50 constructor(private groupsService:GroupsService, private policiesService: PoliciesService,
51 private modalService:SdcUiComponents.ModalService, private eventListenerService:EventListenerService) { }
53 private service:IZoneService;
54 private iconClassName: string;
60 ngOnChanges (changes:SimpleChanges):void {
61 if(changes.selectedZoneInstanceId){
70 private init = (): void => {
71 if (this.selectedZoneInstanceType === ZoneInstanceType.POLICY) {
72 this.iconClassName = "sprite-policy-icons policy";
73 this.service = this.policiesService;
74 } else if (this.selectedZoneInstanceType === ZoneInstanceType.GROUP) {
75 this.iconClassName = "sprite-group-icons group";
76 this.service = this.groupsService;
78 this.iconClassName = "sprite-resource-icons defaulticon";
82 private renameInstance = (): void => {
87 testId: "renameInstanceModal",
89 {id: 'saveButton', text: 'OK', size: 'xsm', callback: this.saveInstanceName, closeModal: false},
90 {id: 'cancelButton', text: 'Cancel', size: 'sm', closeModal: true}
91 ] as ModalButtonComponent[]
93 this.modalService.openCustomModal(modalConfig, ValueEditComponent, {name: this.name, validityChangedCallback: this.enableOrDisableSaveButton});
96 private enableOrDisableSaveButton = (shouldEnable: boolean): void => {
97 let saveButton: ModalButtonComponent = this.modalService.getCurrentInstance().getButtonById('saveButton');
98 saveButton.disabled = !shouldEnable;
101 private saveInstanceName = ():void => {
102 let currentModal = this.modalService.getCurrentInstance();
103 let nameFromModal:string = currentModal.innerModalContent.instance.name;
105 if(nameFromModal != this.name){
106 currentModal.buttons[0].disabled = true;
107 this.service.updateName(this.topologyTemplate.componentType, this.topologyTemplate.uniqueId, this.selectedZoneInstanceId, nameFromModal).subscribe((success)=>{
108 this.eventListenerService.notifyObservers(GRAPH_EVENTS.ON_ZONE_INSTANCE_NAME_CHANGED, nameFromModal);
109 this.modalService.closeModal();
111 currentModal.buttons[0].disabled = false;
114 this.modalService.closeModal();
118 private deleteInstance = (): void => {
119 let title:string = "Delete Confirmation";
120 let message:string = "Are you sure you would like to delete "+ this.name + "?";
121 this.modalService.openAlertModal(title, message, "OK", this.deleteInstanceConfirmed, "deleteInstanceModal");
124 private deleteInstanceConfirmed = () => {
125 this.eventListenerService.notifyObservers(EVENTS.SHOW_LOADER_EVENT + 'composition-graph');
126 this.service.deleteZoneInstance(this.topologyTemplate.componentType, this.topologyTemplate.uniqueId, this.selectedZoneInstanceId).finally(()=> {
127 this.eventListenerService.notifyObservers(EVENTS.HIDE_LOADER_EVENT + 'composition-graph');
129 let deletedItem:UIZoneInstanceObject = new UIZoneInstanceObject(this.selectedZoneInstanceId, this.selectedZoneInstanceType, this.name);
130 this.eventListenerService.notifyObservers(GRAPH_EVENTS.ON_DELETE_ZONE_INSTANCE, deletedItem);