blob: a8669db24900a41566a45822d406c658fe8ffd13 [file] [log] [blame]
Simon Huntc2202d52014-12-16 13:30:15 -08001/*
Simon Hunt8ead3a22015-01-06 11:00:15 -08002 * Copyright 2014,2015 Open Networking Laboratory
Simon Huntc2202d52014-12-16 13:30:15 -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/*
Simon Huntdc6362a2014-12-18 19:55:23 -080018 ONOS GUI -- Main Application Module
Simon Huntc2202d52014-12-16 13:30:15 -080019
20 @author Simon Hunt
21 */
Simon Hunt1eecfa22014-12-16 14:46:29 -080022
Simon Huntc2202d52014-12-16 13:30:15 -080023(function () {
24 'use strict';
25
Simon Hunt6cc53692015-01-07 11:33:45 -080026 var moduleDependencies = [
27 // view modules...
28 // TODO: inject view dependencies server side
29 // {INJECTED-VIEW-MODULE-DEPENDENCIES}
30 // NOTE: 'ov' == 'Onos View'...
31 'ovSample',
32 'ovTopo',
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -080033 'ovDevice',
Simon Hunt6cc53692015-01-07 11:33:45 -080034 // (end of view modules)
35
36 // core modules...
Simon Huntef31fb22014-12-19 13:16:44 -080037 'ngRoute',
38 'onosUtil',
Simon Hunt6cc53692015-01-07 11:33:45 -080039 'onosSvg',
Simon Huntef31fb22014-12-19 13:16:44 -080040 'onosMast'
41 ];
42
Simon Hunt6cc53692015-01-07 11:33:45 -080043 var $log;
Simon Huntef31fb22014-12-19 13:16:44 -080044
Simon Hunt6cc53692015-01-07 11:33:45 -080045 angular.module('onosApp', moduleDependencies)
Simon Huntef31fb22014-12-19 13:16:44 -080046
Simon Hunt426bd862015-01-14 16:48:41 -080047 // Create a resize directive, that we can apply to elements to
48 // respond to window resize events.
49 .directive('resize', ['$window', function ($window) {
50 return function (scope, element, attrs) {
51 var w = angular.element($window);
52 scope.$watch(function () {
53 return {
54 h: window.innerHeight,
55 w: window.innerWidth
56 };
57 }, function (newVal, oldVal) {
58 scope.windowHeight = newVal.h;
59 scope.windowWidth = newVal.w;
60
61 scope.resizeWithOffset = function (offH, offW) {
62 var oh = offH || 0,
63 ow = offW || 0;
64 scope.$eval(attrs.notifier);
65 return {
66 height: (newVal.h - oh) + 'px',
67 width: (newVal.w - ow) + 'px'
68 };
69 };
70 }, true);
71
72 w.bind('resize', function () {
73 scope.$apply();
74 });
75 };
76 }])
77
Simon Huntef31fb22014-12-19 13:16:44 -080078 .controller('OnosCtrl', [
79 '$log', '$route', '$routeParams', '$location',
Simon Hunt6cc53692015-01-07 11:33:45 -080080 'KeyService', 'ThemeService', 'GlyphService',
Simon Huntef31fb22014-12-19 13:16:44 -080081
Simon Hunt6cc53692015-01-07 11:33:45 -080082 function (_$log_, $route, $routeParams, $location, ks, ts, gs) {
83 var self = this;
Simon Huntdc6362a2014-12-18 19:55:23 -080084
Simon Hunt6cc53692015-01-07 11:33:45 -080085 $log = _$log_;
Simon Huntef31fb22014-12-19 13:16:44 -080086 self.$route = $route;
87 self.$routeParams = $routeParams;
88 self.$location = $location;
Simon Huntdc6362a2014-12-18 19:55:23 -080089 self.version = '1.1.0';
90
Simon Hunt6cc53692015-01-07 11:33:45 -080091 // initialize services...
Yuta HIGUCHI4f39bcd2014-12-18 20:46:14 -080092 ts.init();
Simon Hunt420691a2014-12-16 20:16:28 -080093 ks.installOn(d3.select('body'));
Simon Hunt6cc53692015-01-07 11:33:45 -080094 gs.init();
Simon Huntdc6362a2014-12-18 19:55:23 -080095
96 $log.log('OnosCtrl has been created');
Simon Huntef31fb22014-12-19 13:16:44 -080097
98 $log.debug('route: ', self.$route);
99 $log.debug('routeParams: ', self.$routeParams);
100 $log.debug('location: ', self.$location);
101 }])
102
103 .config(['$routeProvider', function ($routeProvider) {
104 // TODO: figure out a way of handling contributed views...
105 $routeProvider
106 .when('/', {
107 controller: 'OvSampleCtrl',
108 controllerAs: 'ctrl',
109 templateUrl: 'view/sample/sample.html'
110 })
111 .when('/topo', {
112 controller: 'OvTopoCtrl',
113 controllerAs: 'ctrl',
114 templateUrl: 'view/topo/topo.html'
115 })
Bri Prebilic Cole7c92a3d2015-01-09 16:50:03 -0800116 .when('/device', {
117 controller: 'OvDeviceCtrl',
118 controllerAs: 'ctrl',
119 templateUrl: 'view/device/device.html'
120 })
Simon Huntef31fb22014-12-19 13:16:44 -0800121 .otherwise({
122 redirectTo: '/'
123 })
Simon Huntc2202d52014-12-16 13:30:15 -0800124 }]);
125
126}());