blob: 6dbd3d31c37fb902765f5ad73087a3dbcbb93425 [file] [log] [blame]
Simon Hunt86388b12015-01-09 14:23:26 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt86388b12015-01-09 14:23:26 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Navigation Module
Simon Hunt86388b12015-01-09 14:23:26 -080019 */
20(function () {
21 'use strict';
22
23 // injected dependencies
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070024 var $log, $location, $window, fs;
Simon Hunt86388b12015-01-09 14:23:26 -080025
26 // internal state
27 var navShown = false;
28
29 function updatePane() {
30 var vis = navShown ? 'visible' : 'hidden';
31 d3.select('#nav').style('visibility', vis);
32 }
33
34
35 function showNav() {
36 navShown = true;
37 updatePane();
38 }
39 function hideNav() {
40 navShown = false;
41 updatePane();
42 }
43 function toggleNav() {
44 navShown = !navShown;
45 updatePane();
46 }
Simon Hunt9d286562015-03-09 13:53:50 -070047 function hideIfShown() {
48 if (navShown) {
49 hideNav();
50 return true;
51 }
52 return false;
53 }
Simon Hunt86388b12015-01-09 14:23:26 -080054
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070055 function navTo(path, params) {
56 var url;
57 if (!path) {
58 $log.warn('Not a valid navigation path');
59 return null;
60 }
61 $location.url('/' + path);
62
63 if (fs.isO(params)) {
64 $location.search(params);
65 } else if (params !== undefined) {
66 $log.warn('Query params not an object', params);
67 }
68
69 url = $location.absUrl();
70 $log.log('Navigating to ', url);
71 $window.location.href = url;
72 }
73
Simon Hunt86388b12015-01-09 14:23:26 -080074 angular.module('onosNav', [])
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070075 .controller('NavCtrl', ['$log',
76
77 function (_$log_) {
Simon Hunt86388b12015-01-09 14:23:26 -080078 var self = this;
79 $log = _$log_;
80
81 self.hideNav = hideNav;
82 $log.log('NavCtrl has been created');
83 }
84 ])
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070085 .factory('NavService',
86 ['$log', '$location', '$window', 'FnService',
Simon Hunt86388b12015-01-09 14:23:26 -080087
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070088 function (_$log_, _$location_, _$window_, _fs_) {
89 $log = _$log_;
90 $location = _$location_;
91 $window = _$window_;
92 fs = _fs_;
93
94 return {
95 showNav: showNav,
96 hideNav: hideNav,
97 toggleNav: toggleNav,
98 hideIfShown: hideIfShown,
99 navTo: navTo
100 };
Simon Hunt86388b12015-01-09 14:23:26 -0800101 }]);
102
103}());