Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 1 | export interface IXosNavigationRoute { |
| 2 | label: string; |
| 3 | state?: string; |
| 4 | url?: string; |
| 5 | } |
| 6 | |
| 7 | export interface IXosNavigationService { |
| 8 | query(): IXosNavigationRoute[]; |
| 9 | add(route: IXosNavigationRoute): void; |
| 10 | } |
| 11 | |
| 12 | export class NavigationService { |
| 13 | private routes: IXosNavigationRoute[]; |
| 14 | |
| 15 | constructor() { |
| 16 | this.routes = [ |
| 17 | { |
| 18 | label: 'Home', |
| 19 | state: 'xos.dashboard' |
| 20 | } |
| 21 | ]; |
| 22 | } |
| 23 | |
| 24 | query() { |
| 25 | return this.routes; |
| 26 | } |
| 27 | |
| 28 | add(route: IXosNavigationRoute) { |
Matteo Scandolo | a4a4711 | 2016-12-16 10:06:13 -0800 | [diff] [blame^] | 29 | if (angular.isDefined(route.state) && angular.isDefined(route.url)) { |
| 30 | throw new Error('[XosNavigation] You can\'t provide both state and url'); |
| 31 | } |
Matteo Scandolo | f2c3ed6 | 2016-12-15 14:32:50 -0800 | [diff] [blame] | 32 | this.routes.push(route); |
| 33 | } |
| 34 | } |