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 addAllow(plugin_name
, allow
) {
72 if (!NAVIGATION
[plugin_name
]) {
73 NAVIGATION
[plugin_name
] = {};
75 NAVIGATION
[plugin_name
].allow
= allow
|| '*';
78 function addAdminFlag(plugin_name
, admin_link
) {
79 if (!NAVIGATION
[plugin_name
]) {
80 NAVIGATION
[plugin_name
] = {};
82 NAVIGATION
[plugin_name
].admin_link
= admin_link
|| false;
85 function getNavigation() {
89 function deleteNavigation(plugin_name
, route_id
) {
90 delete NAVIGATION
[plugin_name
]['routes'][route_id
];
93 function onNavigationDiscovered(plugin_name
, plugin
) {
94 addNavigation(plugin_name
, plugin
.routes
);
95 addOrder(plugin_name
, plugin
.order
);
96 addPriority(plugin_name
, plugin
.priority
);
97 addLabel(plugin_name
, plugin
.name
);
98 addAllow(plugin_name
, plugin
.allow
);
99 addAdminFlag(plugin_name
, plugin
.admin_link
);
103 skyquakeEmitter
.on('config_discoverer.navigation_discovered', onNavigationDiscovered
);
106 function config(config
) {
119 addNavigation
: addNavigation
,
120 getNavigation
: getNavigation