3 * Copyright 2016 RIFT.IO Inc
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * navigation_manager module. manages navigation state for a skyquake instance
21 * @module framework/core/modules/navigation_manager
22 * @author Kiran Kashalkar <kiran.kashalkar@riftio.com>
25 var path
= require('path');
26 var fs
= require('fs');
27 var util
= require('util');
28 var skyquakeEmitter
= require('./skyquakeEmitter');
29 require('require-json');
30 var _
= require('lodash');
33 * navigation looks like:
35 * "plugin_name": <{routes>}>
41 function addNavigation(plugin_name
, routes
) {
42 if (!NAVIGATION
[plugin_name
]) {
43 NAVIGATION
[plugin_name
] = {};
46 if (!NAVIGATION
[plugin_name
].routes
) {
47 NAVIGATION
[plugin_name
].routes
= routes
;
49 _
.extend(NAVIGATION
[plugin_name
].routes
, routes
);
52 function addOrder(plugin_name
, order
) {
53 if (!NAVIGATION
[plugin_name
]) {
54 NAVIGATION
[plugin_name
] = {};
56 NAVIGATION
[plugin_name
].order
= order
|| 5;
58 function addPriority(plugin_name
, priority
) {
59 if (!NAVIGATION
[plugin_name
]) {
60 NAVIGATION
[plugin_name
] = {};
62 NAVIGATION
[plugin_name
].priority
= priority
|| 1;
65 function addLabel(plugin_name
, label
) {
66 if (!NAVIGATION
[plugin_name
]) {
67 NAVIGATION
[plugin_name
] = {};
69 NAVIGATION
[plugin_name
].label
= label
|| 'RW.UI Plugin';
72 function getNavigation() {
76 function deleteNavigation(plugin_name
, route_id
) {
77 delete NAVIGATION
[plugin_name
]['routes'][route_id
];
80 function onNavigationDiscovered(plugin_name
, plugin
) {
81 addNavigation(plugin_name
, plugin
.routes
);
82 addOrder(plugin_name
, plugin
.order
);
83 addPriority(plugin_name
, plugin
.priority
);
84 addLabel(plugin_name
, plugin
.name
);
88 skyquakeEmitter
.on('config_discoverer.navigation_discovered', onNavigationDiscovered
);
91 function config(config
) {
104 addNavigation
: addNavigation
,
105 getNavigation
: getNavigation