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;
42 @Input() isViewOnly:boolean;
44 constructor(private ModalServiceNg2: ModalService) {}
46 onCreateServicePath = ():void => {
47 this.showServicePathMenu = false;
48 let cancelButton: ButtonModel = new ButtonModel('Cancel', 'outline white', this.ModalServiceNg2.closeCurrentModal);
49 let saveButton: ButtonModel = new ButtonModel('Create', 'blue', this.createPath, this.getDisabled );
50 let modalModel: ModalModel = new ModalModel('l', 'Create Service Flow', '', [saveButton, cancelButton], 'standard', true);
51 this.modalInstance = this.ModalServiceNg2.createCustomModal(modalModel);
52 this.ModalServiceNg2.addDynamicContentToModal(this.modalInstance, ServicePathCreatorComponent, {service: this.service});
53 this.modalInstance.instance.open();
56 onListServicePath = ():void => {
57 this.showServicePathMenu = false;
58 let cancelButton: ButtonModel = new ButtonModel('Close', 'outline white', this.ModalServiceNg2.closeCurrentModal);
59 let modalModel: ModalModel = new ModalModel('md', 'Service Flows List','', [cancelButton], 'standard', true);
60 this.modalInstance = this.ModalServiceNg2.createCustomModal(modalModel);
61 this.ModalServiceNg2.addDynamicContentToModal(this.modalInstance, ServicePathsListComponent, {service: this.service,
62 onCreateServicePath: this.onCreateServicePath, onEditServicePath: this.onEditServicePath, isViewOnly: this.isViewOnly});
63 this.modalInstance.instance.open();
66 createPath = ():void => {
67 this.onCreate(this.modalInstance.instance.dynamicContent.instance.createServicePathData());
68 this.ModalServiceNg2.closeCurrentModal();
71 onEditServicePath = (id:string):void => {
72 let cancelButton: ButtonModel = new ButtonModel('Cancel', 'outline white', this.ModalServiceNg2.closeCurrentModal);
73 let saveButton: ButtonModel = new ButtonModel('Save', 'blue', this.createPath, this.getDisabled );
74 let modalModel: ModalModel = new ModalModel('l', 'Edit Path', '', [saveButton, cancelButton], 'standard', true);
75 this.modalInstance = this.ModalServiceNg2.createCustomModal(modalModel);
76 this.ModalServiceNg2.addDynamicContentToModal(this.modalInstance, ServicePathCreatorComponent, {service: this.service, pathId: id});
77 this.modalInstance.instance.open();
80 getDisabled = ():boolean => {
81 return this.isViewOnly || !this.modalInstance.instance.dynamicContent.instance.checkFormValidForSubmit();