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, ComponentRef} from '@angular/core';
22 import {ModalService} from 'app/ng2/services/modal.service';
23 import {ModalModel, ButtonModel} from 'app/models';
24 import {ServicePathCreatorComponent} from 'app/ng2/pages/service-path-creator/service-path-creator.component';
25 import {ModalComponent} from 'app/ng2/components/ui/modal/modal.component';
26 import ServicePathsListComponent from "app/ng2/pages/service-paths-list/service-paths-list.component";
27 import {Service} from "app/models/components/service";
30 selector: 'service-path',
31 templateUrl: './service-path.component.html',
32 styleUrls: ['service-path.component.less'],
33 providers: [ModalService]
36 export class ServicePathComponent {
37 showServicePathMenu: boolean = false;
38 modalInstance: ComponentRef<ModalComponent>;
39 @Input() service: Service;
40 @Input() onCreate: Function;
41 @Input() onSave: Function;
43 constructor(private ModalServiceNg2: ModalService) {}
45 onCreateServicePath = ():void => {
46 this.showServicePathMenu = false;
47 let cancelButton: ButtonModel = new ButtonModel('Cancel', 'outline white', this.ModalServiceNg2.closeCurrentModal);
48 let saveButton: ButtonModel = new ButtonModel('Create', 'blue', this.createPath, this.getDisabled );
49 let modalModel: ModalModel = new ModalModel('l', 'Create Service Path', '', [saveButton, cancelButton], 'standard', true);
50 this.modalInstance = this.ModalServiceNg2.createCustomModal(modalModel);
51 this.ModalServiceNg2.addDynamicContentToModal(this.modalInstance, ServicePathCreatorComponent, {service: this.service});
52 this.modalInstance.instance.open();
55 onListServicePath = ():void => {
56 this.showServicePathMenu = false;
57 let cancelButton: ButtonModel = new ButtonModel('Close', 'outline white', this.ModalServiceNg2.closeCurrentModal);
58 let modalModel: ModalModel = new ModalModel('md', 'Service Paths List','', [cancelButton], 'standard', true);
59 this.modalInstance = this.ModalServiceNg2.createCustomModal(modalModel);
60 this.ModalServiceNg2.addDynamicContentToModal(this.modalInstance, ServicePathsListComponent, {service: this.service,
61 onCreateServicePath: this.onCreateServicePath, onEditServicePath: this.onEditServicePath});
62 this.modalInstance.instance.open();
65 createPath = ():void => {
66 this.onCreate(this.modalInstance.instance.dynamicContent.instance.createServicePathData());
67 this.ModalServiceNg2.closeCurrentModal();
70 onEditServicePath = (id:string):void => {
71 let cancelButton: ButtonModel = new ButtonModel('Cancel', 'outline white', this.ModalServiceNg2.closeCurrentModal);
72 let saveButton: ButtonModel = new ButtonModel('Save', 'blue', this.createPath, this.getDisabled );
73 let modalModel: ModalModel = new ModalModel('l', 'Edit Path', '', [saveButton, cancelButton]);
74 this.modalInstance = this.ModalServiceNg2.createCustomModal(modalModel);
75 this.ModalServiceNg2.addDynamicContentToModal(this.modalInstance, ServicePathCreatorComponent, {service: this.service, pathId: id});
76 this.modalInstance.instance.open();
79 getDisabled = ():boolean => {
80 return !this.modalInstance.instance.dynamicContent.instance.checkFormValidForSubmit();