Bri Prebilic Cole

ONOS-1936 - CORD-GUI -- Bundle race condition fixed with refactor. Nav buttons r…

…efresh page when clicked.

Change-Id: Ie01ea77b1bf10b84b8bd8dadb02fa775e122b416
...@@ -28,13 +28,13 @@ ...@@ -28,13 +28,13 @@
28 transition: background-color 0.4s; 28 transition: background-color 0.4s;
29 } 29 }
30 .nav li:hover { 30 .nav li:hover {
31 - background-color: #CE5650; 31 + background-color: #BD5643;
32 32
33 } 33 }
34 .nav li.selected { 34 .nav li.selected {
35 font-weight: bold; 35 font-weight: bold;
36 color: white; 36 color: white;
37 - background: linear-gradient(#CE5650, #ce3630); 37 + background: linear-gradient(#A56151, #BD5643);
38 letter-spacing: 0.03em; 38 letter-spacing: 0.03em;
39 } 39 }
40 40
......
...@@ -17,13 +17,16 @@ ...@@ -17,13 +17,16 @@
17 <div class="nav"> 17 <div class="nav">
18 <ul> 18 <ul>
19 <a href="#/home"> 19 <a href="#/home">
20 - <li ng-class="{selected: page === 'dashboard'}">Dashboard</li> 20 + <li ng-class="{selected: page === 'dashboard'}"
21 + ng-click="$route.reload()">Dashboard</li>
21 </a> 22 </a>
22 <a href="#/user"> 23 <a href="#/user">
23 - <li ng-class="{selected: page === 'user'}">Users</li> 24 + <li ng-class="{selected: page === 'user'}"
25 + ng-click="$route.reload()">Users</li>
24 </a> 26 </a>
25 <a href="#/bundle"> 27 <a href="#/bundle">
26 - <li ng-class="{selected: page === 'bundle'}">Bundles</li> 28 + <li ng-class="{selected: page === 'bundle'}"
29 + ng-click="$route.reload()">Bundles</li>
27 </a> 30 </a>
28 </ul> 31 </ul>
29 </div> 32 </div>
......
1 -<div id="available" ng-controller="CordAvailable as ctrl"> 1 +<div id="available">
2 <h3>{{available.name}}</h3> 2 <h3>{{available.name}}</h3>
3 <p>{{available.desc}}</p> 3 <p>{{available.desc}}</p>
4 - <button type="button">Apply</button> 4 + <button ng-click="changeBundle(available.id)">Apply</button>
5 </div> 5 </div>
......
...@@ -17,91 +17,56 @@ ...@@ -17,91 +17,56 @@
17 (function () { 17 (function () {
18 'use strict'; 18 'use strict';
19 19
20 - var $log, $resource;
21 -
22 var url = 'http://localhost:8080/rs/bundle'; 20 var url = 'http://localhost:8080/rs/bundle';
23 21
24 var basic = 'basic', 22 var basic = 'basic',
25 - family = 'family', 23 + family = 'family';
26 - current,
27 - bundleScope,
28 - avScope,
29 - avCb;
30 24
31 - function setAndRefresh(resource, scope) { 25 + angular.module('cordBundle', [])
32 - current = resource.bundle.id; 26 + .controller('CordBundleCtrl', ['$log', '$scope', '$resource',
33 - scope.name = resource.bundle.name; 27 + function ($log, $scope, $resource) {
34 - scope.desc = resource.bundle.desc; 28 + var BundleData, resource,
35 - scope.funcs = resource.bundle.functions; 29 + getData;
36 - // emit event will say when avCb should be invoked 30 + $scope.page = 'bundle';
37 - avCb(resource);
38 - }
39 31
40 - // TODO: figure out timing issues with bundle page 32 + getData = function (id) {
41 - // available bundles sometimes is loaded before avCb and avScope is created? 33 + if (!id) { id = ''; }
42 - // emit event that avCb can be called upon
43 34
44 - angular.module('cordBundle', []) 35 + BundleData = $resource(url + '/' + id);
45 - .controller('CordAvailable', ['$scope', 36 + resource = BundleData.get({},
46 - function ($scope) { 37 + // success
47 - avScope = $scope; 38 + function () {
48 - avCb = function (resource) { 39 + var current, availId;
49 - $scope.id = (current === basic) ? family : basic; 40 + current = resource.bundle.id;
50 - $scope.bundles = resource.bundles; 41 + $scope.name = resource.bundle.name;
42 + $scope.desc = resource.bundle.desc;
43 + $scope.funcs = resource.bundle.functions;
51 44
52 - $scope.bundles.forEach(function (bundle) { 45 + availId = (current === basic) ? family : basic;
53 - if (bundle.id === $scope.id) { 46 + resource.bundles.forEach(function (bundle) {
54 - $scope.available = bundle; 47 + if (bundle.id === availId) {
55 - } 48 + $scope.available = bundle;
56 - }); 49 + }
50 + });
51 + },
52 + // error
53 + function () {
54 + $log.error('Problem with resource', resource);
55 + });
57 }; 56 };
58 57
59 - $log.debug('Cord Available Ctrl has been created.'); 58 + getData();
60 - }])
61 59
62 - .controller('CordBundleCtrl', ['$log', '$scope', '$resource', 60 + $scope.changeBundle = function (id) {
63 - function (_$log_, $scope, _$resource_) { 61 + getData(id);
64 - var BundleData, resource; 62 + };
65 - $scope.page = 'bundle';
66 - bundleScope = $scope;
67 - $log = _$log_;
68 - $resource = _$resource_;
69 -
70 - BundleData = $resource(url);
71 - resource = BundleData.get({},
72 - // success
73 - function () {
74 - setAndRefresh(resource, $scope);
75 - },
76 - // error
77 - function () {
78 - $log.error('Problem with resource', resource);
79 - });
80 63
81 $log.debug('Cord Bundle Ctrl has been created.'); 64 $log.debug('Cord Bundle Ctrl has been created.');
82 }]) 65 }])
83 66
84 - .directive('bundleAvailable', ['$resource', function ($resource) { 67 + .directive('bundleAvailable', [function () {
85 return { 68 return {
86 - templateUrl: 'app/view/bundle/available.html', 69 + templateUrl: 'app/view/bundle/available.html'
87 - link: function (scope, elem) {
88 - var button = $(elem).find('button'),
89 - ApplyData, resource;
90 -
91 - button.click(function () {
92 - ApplyData = $resource(url + '/' + avScope.available.id);
93 - resource = ApplyData.get({},
94 - // success
95 - function () {
96 - setAndRefresh(resource, bundleScope);
97 - },
98 - // error
99 - function () {
100 - $log.error('Problem with resource', resource);
101 - }
102 - );
103 - });
104 - }
105 }; 70 };
106 }]); 71 }]);
107 }()); 72 }());
......