Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 3 | * |
| 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 Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 19 | */ |
| 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
| 23 | // injected dependencies |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 24 | var $log, $location, $window, fs; |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 25 | |
| 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 Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 34 | 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 Hunt | 9d28656 | 2015-03-09 13:53:50 -0700 | [diff] [blame] | 46 | function hideIfShown() { |
| 47 | if (navShown) { |
| 48 | hideNav(); |
| 49 | return true; |
| 50 | } |
| 51 | return false; |
| 52 | } |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 53 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 54 | 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 Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 73 | angular.module('onosNav', []) |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 74 | .controller('NavCtrl', ['$log', |
| 75 | |
| 76 | function (_$log_) { |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 77 | var self = this; |
| 78 | $log = _$log_; |
| 79 | |
| 80 | self.hideNav = hideNav; |
| 81 | $log.log('NavCtrl has been created'); |
| 82 | } |
| 83 | ]) |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 84 | .factory('NavService', |
| 85 | ['$log', '$location', '$window', 'FnService', |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 86 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 87 | 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, |
| 98 | navTo: navTo |
| 99 | }; |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 100 | }]); |
| 101 | |
| 102 | }()); |