Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014,2015 Open Networking Laboratory |
| 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 | |
| 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 Hunt | 9d28656 | 2015-03-09 13:53:50 -0700 | [diff] [blame] | 47 | function hideIfShown() { |
| 48 | if (navShown) { |
| 49 | hideNav(); |
| 50 | return true; |
| 51 | } |
| 52 | return false; |
| 53 | } |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 54 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 55 | 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 Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 74 | angular.module('onosNav', []) |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 75 | .controller('NavCtrl', ['$log', |
| 76 | |
| 77 | function (_$log_) { |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 78 | var self = this; |
| 79 | $log = _$log_; |
| 80 | |
| 81 | self.hideNav = hideNav; |
| 82 | $log.log('NavCtrl has been created'); |
| 83 | } |
| 84 | ]) |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 85 | .factory('NavService', |
| 86 | ['$log', '$location', '$window', 'FnService', |
Simon Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 87 | |
Bri Prebilic Cole | 8f07f0d | 2015-04-23 13:28:43 -0700 | [diff] [blame] | 88 | 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 Hunt | 86388b1 | 2015-01-09 14:23:26 -0800 | [diff] [blame] | 101 | }]); |
| 102 | |
| 103 | }()); |