CSIT Fix for SDC-2585
[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     isViewOnly: boolean;
42
43     constructor(private serviceService:ServiceServiceNg2) {
44         this.headers = ['Flow Name','Actions'];
45     }
46
47     ngOnInit() {
48         _.forEach(this.input.service.forwardingPaths, (path: ForwardingPath)=> {
49             this.paths[this.paths.length] = path;
50         });
51         this.paths.sort((a:ForwardingPath, b:ForwardingPath)=> {
52             return a.name.localeCompare(b.name);
53         });
54         this.onAddServicePath = this.input.onCreateServicePath;
55         this.onEditServicePath = this.input.onEditServicePath;
56         this.isViewOnly =  this.input.isViewOnly;
57     }
58
59     deletePath = (id:string):void =>   {
60         this.serviceService.deleteServicePath(this.input.service, id).subscribe((res:any) => {
61             delete this.input.service.forwardingPaths[id];
62             this.paths = this.paths.filter(function(path){
63                 return path.uniqueId !== id;
64             });
65         });
66     };
67
68 }