blob: 30881d7a1f8a99cc3cde9d19d3f57d1f2643dfbe [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
Simon Hunt86388b12015-01-09 14:23:26 -080034 function showNav() {
35 navShown = true;
36 updatePane();
37 }
38 function hideNav() {
39 navShown = false;
40 updatePane();
41 }
42 function toggleNav() {
43 navShown = !navShown;
44 updatePane();
45 }
Simon Hunt9d286562015-03-09 13:53:50 -070046 function hideIfShown() {
47 if (navShown) {
48 hideNav();
49 return true;
50 }
51 return false;
52 }
Simon Hunt86388b12015-01-09 14:23:26 -080053
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070054 function navTo(path, params) {
55 var url;
56 if (!path) {
57 $log.warn('Not a valid navigation path');
58 return null;
59 }
60 $location.url('/' + path);
61
62 if (fs.isO(params)) {
63 $location.search(params);
64 } else if (params !== undefined) {
65 $log.warn('Query params not an object', params);
66 }
67
68 url = $location.absUrl();
69 $log.log('Navigating to ', url);
70 $window.location.href = url;
71 }
72
Simon Hunt86388b12015-01-09 14:23:26 -080073 angular.module('onosNav', [])
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070074 .controller('NavCtrl', ['$log',
75
76 function (_$log_) {
Simon Hunt86388b12015-01-09 14:23:26 -080077 var self = this;
78 $log = _$log_;
79
80 self.hideNav = hideNav;
81 $log.log('NavCtrl has been created');
Steven Burrows46c5f102017-07-14 16:52:46 +010082 },
Simon Hunt86388b12015-01-09 14:23:26 -080083 ])
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070084 .factory('NavService',
85 ['$log', '$location', '$window', 'FnService',
Simon Hunt86388b12015-01-09 14:23:26 -080086
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070087 function (_$log_, _$location_, _$window_, _fs_) {
88 $log = _$log_;
89 $location = _$location_;
90 $window = _$window_;
91 fs = _fs_;
92
93 return {
94 showNav: showNav,
95 hideNav: hideNav,
96 toggleNav: toggleNav,
97 hideIfShown: hideIfShown,
Steven Burrows46c5f102017-07-14 16:52:46 +010098 navTo: navTo,
Bri Prebilic Cole8f07f0d2015-04-23 13:28:43 -070099 };
Simon Hunt86388b12015-01-09 14:23:26 -0800100 }]);
101
102}());