Sync Integ to Master
[sdc.git] / catalog-ui / src / app / ng2 / pages / service-paths-list / service-paths-list.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, ComponentRef} from '@angular/core';
23 import {ForwardingPath} from "app/models/forwarding-path";
24 import {ServiceServiceNg2} from "app/ng2/services/component-services/service.service";
25 import {ModalService} from "app/ng2/services/modal.service";
26 import {ModalComponent} from "app/ng2/components/ui/modal/modal.component";
27
28 @Component({
29     selector: 'service-paths-list',
30     templateUrl: './service-paths-list.component.html',
31     styleUrls:['service-paths-list.component.less'],
32     providers: [ServiceServiceNg2, ModalService]
33 })
34 export default class ServicePathsListComponent {
35     modalInstance: ComponentRef<ModalComponent>;
36     headers: Array<string> = [];
37     paths: Array<ForwardingPath> = [];
38     input:any;
39     onAddServicePath: Function;
40     onEditServicePath: Function;
41
42     constructor(private serviceService:ServiceServiceNg2) {
43         this.headers = ['Path Name','Actions'];
44     }
45
46     ngOnInit() {
47         _.forEach(this.input.service.forwardingPaths, (path: ForwardingPath)=> {
48             this.paths[this.paths.length] = path;
49         });
50         this.paths.sort((a:ForwardingPath, b:ForwardingPath)=> {
51             return a.name.localeCompare(b.name);
52         });
53         this.onAddServicePath = this.input.onCreateServicePath;
54         this.onEditServicePath = this.input.onEditServicePath;
55     }
56
57     deletePath = (id:string):void =>   {
58         this.serviceService.deleteServicePath(this.input.service, id).subscribe((res:any) => {
59             delete this.input.service.forwardingPaths[id];
60             this.paths = this.paths.filter(function(path){
61                 return path.uniqueId !== id;
62             });
63         });
64     };
65
66 }