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
] = {};
45 if (!NAVIGATION
[plugin_name
].routes
) {
46 NAVIGATION
[plugin_name
].routes
= routes
;
48 _
.extend(NAVIGATION
[plugin_name
].routes
, routes
);
51 function addOrder(plugin_name
, order
) {
52 if (!NAVIGATION
[plugin_name
]) {
53 NAVIGATION
[plugin_name
] = {};
55 NAVIGATION
[plugin_name
].order
= order
|| 5;
57 function addPriority(plugin_name
, priority
) {
58 if (!NAVIGATION
[plugin_name
]) {
59 NAVIGATION
[plugin_name
] = {};
61 NAVIGATION
[plugin_name
].priority
= priority
|| 1;
64 function addLabel(plugin_name
, label
) {
65 if (!NAVIGATION
[plugin_name
]) {
66 NAVIGATION
[plugin_name
] = {};
68 NAVIGATION
[plugin_name
].label
= label
|| 'RW.UI Plugin';
71 function getNavigation() {
75 function deleteNavigation(plugin_name
, route_id
) {
76 delete NAVIGATION
[plugin_name
]['routes'][route_id
];
79 function onNavigationDiscovered(plugin_name
, plugin
) {
80 addNavigation(plugin_name
, plugin
.routes
);
81 addOrder(plugin_name
, plugin
.order
);
82 addPriority(plugin_name
, plugin
.priority
);
83 addLabel(plugin_name
, plugin
.name
);
87 skyquakeEmitter
.on('config_discoverer.navigation_discovered', onNavigationDiscovered
);
90 function config(config
) {
103 addNavigation
: addNavigation
,
104 getNavigation
: getNavigation