Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / framework / core / modules / navigation_manager.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
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
19 /**
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>
23 */
24
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');
31
32 /**
33 * navigation looks like:
34 * {
35 * "plugin_name": <{routes>}>
36 * }
37 */
38
39 var NAVIGATION = {};
40
41 function addNavigation(plugin_name, routes) {
42 if (!NAVIGATION[plugin_name]) {
43 NAVIGATION[plugin_name] = {};
44 }
45
46 if (!NAVIGATION[plugin_name].routes) {
47 NAVIGATION[plugin_name].routes = routes;
48 } else {
49 _.extend(NAVIGATION[plugin_name].routes, routes);
50 }
51 }
52 function addOrder(plugin_name, order) {
53 if (!NAVIGATION[plugin_name]) {
54 NAVIGATION[plugin_name] = {};
55 }
56 NAVIGATION[plugin_name].order = order || 5;
57 }
58 function addPriority(plugin_name, priority) {
59 if (!NAVIGATION[plugin_name]) {
60 NAVIGATION[plugin_name] = {};
61 }
62 NAVIGATION[plugin_name].priority = priority || 1;
63 }
64
65 function addLabel(plugin_name, label) {
66 if (!NAVIGATION[plugin_name]) {
67 NAVIGATION[plugin_name] = {};
68 }
69 NAVIGATION[plugin_name].label = label || 'RW.UI Plugin';
70 }
71
72 function getNavigation() {
73 return NAVIGATION;
74 }
75
76 function deleteNavigation(plugin_name, route_id) {
77 delete NAVIGATION[plugin_name]['routes'][route_id];
78 }
79
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);
85 }
86
87 function init() {
88 skyquakeEmitter.on('config_discoverer.navigation_discovered', onNavigationDiscovered);
89 }
90
91 function config(config) {
92
93 }
94
95 function run() {
96
97 }
98
99
100 module.exports = {
101 init: init,
102 config: config,
103 run: run,
104 addNavigation: addNavigation,
105 getNavigation: getNavigation
106 };