Sync Integ to Master
[sdc.git] / catalog-ui / src / app / ng2 / components / logic / service-path / service-path.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 {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";
28
29 @Component({
30     selector: 'service-path',
31     templateUrl: './service-path.component.html',
32     styleUrls: ['service-path.component.less'],
33     providers: [ModalService]
34 })
35
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
43         constructor(private ModalServiceNg2: ModalService) {}
44
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();
53         };
54
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();
63         };
64
65         createPath  = ():void => {
66                 this.onCreate(this.modalInstance.instance.dynamicContent.instance.createServicePathData());
67                 this.ModalServiceNg2.closeCurrentModal();
68         };
69
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();
77         };
78
79         getDisabled = ():boolean =>  {
80                 return !this.modalInstance.instance.dynamicContent.instance.checkFormValidForSubmit();
81         };
82 }
83