Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | 7629cc4 | 2017-03-13 14:12:15 -0700 | [diff] [blame] | 19 | import {IXosServiceGraph} from '../interfaces'; |
| 20 | |
| 21 | export interface IXosServiceGraphReducers { |
| 22 | coarse: IXosServiceGraphReducer[]; |
| 23 | finegrained: IXosServiceGraphReducer[]; |
| 24 | } |
| 25 | |
| 26 | export interface IXosServiceGraphReducer { |
| 27 | name: string; |
| 28 | reducer: IXosServiceGraphReducerFn; |
| 29 | } |
| 30 | |
| 31 | export interface IXosServiceGraphReducerFn { |
| 32 | (graph: IXosServiceGraph): IXosServiceGraph; |
| 33 | } |
| 34 | |
| 35 | export interface IXosServiceGraphExtender { |
| 36 | register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean; |
| 37 | getCoarse(): IXosServiceGraphReducer[]; |
| 38 | getFinegrained(): IXosServiceGraphReducer[]; |
| 39 | } |
| 40 | |
| 41 | export 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 | } |