ONOS-1936 - CORD-GUI -- Bundle race condition fixed with refactor. Nav buttons r…
…efresh page when clicked. Change-Id: Ie01ea77b1bf10b84b8bd8dadb02fa775e122b416
Showing
4 changed files
with
39 additions
and
71 deletions
| ... | @@ -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 | - | ||
| 31 | - function setAndRefresh(resource, scope) { | ||
| 32 | - current = resource.bundle.id; | ||
| 33 | - scope.name = resource.bundle.name; | ||
| 34 | - scope.desc = resource.bundle.desc; | ||
| 35 | - scope.funcs = resource.bundle.functions; | ||
| 36 | - // emit event will say when avCb should be invoked | ||
| 37 | - avCb(resource); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - // TODO: figure out timing issues with bundle page | ||
| 41 | - // available bundles sometimes is loaded before avCb and avScope is created? | ||
| 42 | - // emit event that avCb can be called upon | ||
| 43 | 24 | ||
| 44 | angular.module('cordBundle', []) | 25 | angular.module('cordBundle', []) |
| 45 | - .controller('CordAvailable', ['$scope', | ||
| 46 | - function ($scope) { | ||
| 47 | - avScope = $scope; | ||
| 48 | - avCb = function (resource) { | ||
| 49 | - $scope.id = (current === basic) ? family : basic; | ||
| 50 | - $scope.bundles = resource.bundles; | ||
| 51 | - | ||
| 52 | - $scope.bundles.forEach(function (bundle) { | ||
| 53 | - if (bundle.id === $scope.id) { | ||
| 54 | - $scope.available = bundle; | ||
| 55 | - } | ||
| 56 | - }); | ||
| 57 | - }; | ||
| 58 | - | ||
| 59 | - $log.debug('Cord Available Ctrl has been created.'); | ||
| 60 | - }]) | ||
| 61 | - | ||
| 62 | .controller('CordBundleCtrl', ['$log', '$scope', '$resource', | 26 | .controller('CordBundleCtrl', ['$log', '$scope', '$resource', |
| 63 | - function (_$log_, $scope, _$resource_) { | 27 | + function ($log, $scope, $resource) { |
| 64 | - var BundleData, resource; | 28 | + var BundleData, resource, |
| 29 | + getData; | ||
| 65 | $scope.page = 'bundle'; | 30 | $scope.page = 'bundle'; |
| 66 | - bundleScope = $scope; | ||
| 67 | - $log = _$log_; | ||
| 68 | - $resource = _$resource_; | ||
| 69 | 31 | ||
| 70 | - BundleData = $resource(url); | 32 | + getData = function (id) { |
| 33 | + if (!id) { id = ''; } | ||
| 34 | + | ||
| 35 | + BundleData = $resource(url + '/' + id); | ||
| 71 | resource = BundleData.get({}, | 36 | resource = BundleData.get({}, |
| 72 | // success | 37 | // success |
| 73 | function () { | 38 | function () { |
| 74 | - setAndRefresh(resource, $scope); | 39 | + var current, availId; |
| 40 | + current = resource.bundle.id; | ||
| 41 | + $scope.name = resource.bundle.name; | ||
| 42 | + $scope.desc = resource.bundle.desc; | ||
| 43 | + $scope.funcs = resource.bundle.functions; | ||
| 44 | + | ||
| 45 | + availId = (current === basic) ? family : basic; | ||
| 46 | + resource.bundles.forEach(function (bundle) { | ||
| 47 | + if (bundle.id === availId) { | ||
| 48 | + $scope.available = bundle; | ||
| 49 | + } | ||
| 50 | + }); | ||
| 75 | }, | 51 | }, |
| 76 | // error | 52 | // error |
| 77 | function () { | 53 | function () { |
| 78 | $log.error('Problem with resource', resource); | 54 | $log.error('Problem with resource', resource); |
| 79 | }); | 55 | }); |
| 56 | + }; | ||
| 57 | + | ||
| 58 | + getData(); | ||
| 59 | + | ||
| 60 | + $scope.changeBundle = function (id) { | ||
| 61 | + getData(id); | ||
| 62 | + }; | ||
| 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 | }()); | ... | ... |
-
Please register or login to post a comment