blob: a601e875c55e3dc332d4e738e98de998119da8bf [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolo7629cc42017-03-13 14:12:15 -070019import {IXosServiceGraph} from '../interfaces';
20
21export interface IXosServiceGraphReducers {
22 coarse: IXosServiceGraphReducer[];
23 finegrained: IXosServiceGraphReducer[];
24}
25
26export interface IXosServiceGraphReducer {
27 name: string;
28 reducer: IXosServiceGraphReducerFn;
29}
30
31export interface IXosServiceGraphReducerFn {
32 (graph: IXosServiceGraph): IXosServiceGraph;
33}
34
35export interface IXosServiceGraphExtender {
36 register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean;
37 getCoarse(): IXosServiceGraphReducer[];
38 getFinegrained(): IXosServiceGraphReducer[];
39}
40
41export class XosServiceGraphExtender implements IXosServiceGraphExtender {
42
43 static $inject = ['$log'];
44
45 private reducers: IXosServiceGraphReducers = {
46 coarse: [],
47 finegrained: []
48 };
49
50 constructor (
51 private $log: ng.ILogService
52 ) {
53 }
54
55 public getCoarse(): IXosServiceGraphReducer[] {
56 return this.reducers.coarse;
57 }
58
59 public getFinegrained(): IXosServiceGraphReducer[] {
60 return this.reducers.finegrained;
61 }
62
63 // NOTE
64 // as now extender support:
65 // - nodes property: x, y, d3Class (applied to the group element)
66 // - links propery: d3Class (applied to the line element, there's no group for now)
67 public register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean {
68 this.$log.debug(`[XosServiceGraphExtender] Registering ${name} reducer in ${type} list`);
69 this.reducers[type].push({
70 name,
71 reducer
72 });
73 return false;
74 }
75}