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