You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by de...@apache.org on 2017/05/01 16:39:53 UTC
[1/2] incubator-trafficcontrol git commit: This closes #529
Repository: incubator-trafficcontrol
Updated Branches:
refs/heads/master d15c6d496 -> 49aaa5c3d
This closes #529
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/49aaa5c3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/49aaa5c3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/49aaa5c3
Branch: refs/heads/master
Commit: 49aaa5c3d35ef61d03f3020971e631020464b22d
Parents: 5d3004b
Author: Dewayne Richardson <de...@apache.org>
Authored: Mon May 1 10:39:43 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Mon May 1 10:39:43 2017 -0600
----------------------------------------------------------------------
----------------------------------------------------------------------
[2/2] incubator-trafficcontrol git commit: fixes bug in change log
poller. had to move it into a persistent model so the $interval would not get
crushed. it is needed to cancel the interval.
Posted by de...@apache.org.
fixes bug in change log poller. had to move it into a persistent model so the $interval would not get crushed. it is needed to cancel the interval.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/5d3004b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/5d3004b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/5d3004b3
Branch: refs/heads/master
Commit: 5d3004b3645fb91953a28115ddfa4debef98f423
Parents: d15c6d4
Author: Jeremy Mitchell <mi...@gmail.com>
Authored: Fri Apr 28 11:47:28 2017 -0600
Committer: Dewayne Richardson <de...@apache.org>
Committed: Mon May 1 10:39:43 2017 -0600
----------------------------------------------------------------------
.../ui/app/src/common/api/AuthService.js | 6 ++-
.../ui/app/src/common/models/ChangeLogModel.js | 54 ++++++++++++++++++++
.../ui/app/src/common/models/index.js | 1 +
.../common/modules/header/HeaderController.js | 33 ++----------
.../src/common/modules/header/header.tpl.html | 2 +-
5 files changed, 63 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5d3004b3/traffic_ops/experimental/ui/app/src/common/api/AuthService.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/api/AuthService.js b/traffic_ops/experimental/ui/app/src/common/api/AuthService.js
index c2168e9..b9975e7 100644
--- a/traffic_ops/experimental/ui/app/src/common/api/AuthService.js
+++ b/traffic_ops/experimental/ui/app/src/common/api/AuthService.js
@@ -17,13 +17,14 @@
* under the License.
*/
-var AuthService = function($http, $state, $location, $q, $state, httpService, userModel, messageModel, ENV) {
+var AuthService = function($rootScope, $http, $state, $location, $q, $state, httpService, userModel, messageModel, ENV) {
this.login = function(username, password) {
userModel.resetUser();
return httpService.post(ENV.api['root'] + 'user/login', { u: username, p: password })
.then(
function(result) {
+ $rootScope.$broadcast('authService::login');
var redirect = decodeURIComponent($location.search().redirect);
if (redirect !== 'undefined') {
$location.search('redirect', null); // remove the redirect query param
@@ -48,6 +49,7 @@ var AuthService = function($http, $state, $location, $q, $state, httpService, us
httpService.post(ENV.api['root'] + 'user/logout').
then(
function(result) {
+ $rootScope.$broadcast('authService::logout');
if ($state.current.name == 'trafficOps.public.login') {
messageModel.setMessages(result.alerts, false);
} else {
@@ -65,5 +67,5 @@ var AuthService = function($http, $state, $location, $q, $state, httpService, us
};
-AuthService.$inject = ['$http', '$state', '$location', '$q', '$state', 'httpService', 'userModel', 'messageModel', 'ENV'];
+AuthService.$inject = ['$rootScope', '$http', '$state', '$location', '$q', '$state', 'httpService', 'userModel', 'messageModel', 'ENV'];
module.exports = AuthService;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5d3004b3/traffic_ops/experimental/ui/app/src/common/models/ChangeLogModel.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/models/ChangeLogModel.js b/traffic_ops/experimental/ui/app/src/common/models/ChangeLogModel.js
new file mode 100644
index 0000000..225f8eb
--- /dev/null
+++ b/traffic_ops/experimental/ui/app/src/common/models/ChangeLogModel.js
@@ -0,0 +1,54 @@
+var ChangeLogModel = function($rootScope, $interval, changeLogService, userModel) {
+
+ var newLogCount = 0,
+ pollingIntervalInSecs = 30,
+ changeLogInterval;
+
+ this.newLogCount = function() {
+ return newLogCount;
+ };
+
+ var createChangeLogInterval = function() {
+ killChangeLogInterval();
+ changeLogInterval = $interval(function() { getNewLogCount() }, (pollingIntervalInSecs*1000)); // every X minutes
+ };
+
+ var killChangeLogInterval = function() {
+ if (angular.isDefined(changeLogInterval)) {
+ $interval.cancel(changeLogInterval);
+ changeLogInterval = undefined;
+ }
+ };
+
+ var getNewLogCount = function() {
+ changeLogService.getNewLogCount()
+ .then(function(result) {
+ newLogCount = result.data.response.newLogcount;
+ });
+ };
+
+ $rootScope.$on('authService::login', function() {
+ getNewLogCount();
+ createChangeLogInterval();
+ });
+
+ $rootScope.$on('authService::logout', function() {
+ killChangeLogInterval();
+ });
+
+ $rootScope.$on('changeLogService::getChangeLogs', function() {
+ newLogCount = 0;
+ });
+
+ var init = function () {
+ if (userModel.loaded) {
+ getNewLogCount();
+ createChangeLogInterval();
+ }
+ };
+ init();
+
+};
+
+ChangeLogModel.$inject = ['$rootScope', '$interval', 'changeLogService', 'userModel'];
+module.exports = ChangeLogModel;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5d3004b3/traffic_ops/experimental/ui/app/src/common/models/index.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/models/index.js b/traffic_ops/experimental/ui/app/src/common/models/index.js
index de009a7..8001b09 100644
--- a/traffic_ops/experimental/ui/app/src/common/models/index.js
+++ b/traffic_ops/experimental/ui/app/src/common/models/index.js
@@ -18,5 +18,6 @@
*/
module.exports = angular.module('trafficOps.models', [])
+ .service('changeLogModel', require('./ChangeLogModel'))
.service('messageModel', require('./MessageModel'))
.service('userModel', require('./UserModel'));
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5d3004b3/traffic_ops/experimental/ui/app/src/common/modules/header/HeaderController.js
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/modules/header/HeaderController.js b/traffic_ops/experimental/ui/app/src/common/modules/header/HeaderController.js
index 31cd123..1070b7b 100644
--- a/traffic_ops/experimental/ui/app/src/common/modules/header/HeaderController.js
+++ b/traffic_ops/experimental/ui/app/src/common/modules/header/HeaderController.js
@@ -17,7 +17,7 @@
* under the License.
*/
-var HeaderController = function($rootScope, $scope, $log, $state, $anchorScroll, $interval, locationUtils, authService, changeLogService, trafficOpsService, userModel) {
+var HeaderController = function($rootScope, $scope, $state, $anchorScroll, locationUtils, authService, trafficOpsService, changeLogService, changeLogModel, userModel) {
$scope.isCollapsed = true;
@@ -28,7 +28,7 @@ var HeaderController = function($rootScope, $scope, $log, $state, $anchorScroll,
*/
$scope.user = angular.copy(userModel.user);
- $scope.newLogCount = 0;
+ $scope.newLogCount = changeLogModel.newLogCount;
$scope.changeLogs = [];
@@ -58,27 +58,6 @@ var HeaderController = function($rootScope, $scope, $log, $state, $anchorScroll,
$scope.navigateToPath = locationUtils.navigateToPath;
- var changeLogInterval,
- increment = 1;
-
- var createChangeLogInterval = function() {
- killChangeLogInterval();
- changeLogInterval = $interval(function() { getNewLogCount() }, (increment*60*1000)); // every X minutes
- };
-
- var killChangeLogInterval = function() {
- if (angular.isDefined(changeLogInterval)) {
- $interval.cancel(changeLogInterval);
- changeLogInterval = undefined;
- }
- };
-
- var getNewLogCount = function() {
- changeLogService.getNewLogCount()
- .then(function(result) {
- $scope.newLogCount = result.data.response.newLogcount;
- });
- };
var scrollToTop = function() {
$anchorScroll(); // hacky?
@@ -123,18 +102,12 @@ var HeaderController = function($rootScope, $scope, $log, $state, $anchorScroll,
$scope.user = angular.copy(userModel.user);
});
- $scope.$on('changeLogService::getChangeLogs', function() {
- $scope.newLogCount = 0;
- });
-
var init = function () {
scrollToTop();
initToggleMenu();
- getNewLogCount();
- createChangeLogInterval();
};
init();
};
-HeaderController.$inject = ['$rootScope', '$scope', '$log', '$state', '$anchorScroll', '$interval', 'locationUtils', 'authService', 'changeLogService', 'trafficOpsService', 'userModel'];
+HeaderController.$inject = ['$rootScope', '$scope', '$state', '$anchorScroll', 'locationUtils', 'authService', 'trafficOpsService', 'changeLogService', 'changeLogModel', 'userModel'];
module.exports = HeaderController;
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/5d3004b3/traffic_ops/experimental/ui/app/src/common/modules/header/header.tpl.html
----------------------------------------------------------------------
diff --git a/traffic_ops/experimental/ui/app/src/common/modules/header/header.tpl.html b/traffic_ops/experimental/ui/app/src/common/modules/header/header.tpl.html
index c9e9bf3..06c5ed1 100644
--- a/traffic_ops/experimental/ui/app/src/common/modules/header/header.tpl.html
+++ b/traffic_ops/experimental/ui/app/src/common/modules/header/header.tpl.html
@@ -39,7 +39,7 @@ under the License.
<div class="btn-group" uib-dropdown is-open="alerts.isopen">
<button id="alertsButton" type="button" class="btn btn-link" ng-click="getChangeLogs()" uib-dropdown-toggle>
<i class="fa fa-comment-o"></i>
- <span class="badge bg-green">{{newLogCount}}</span>
+ <span class="badge bg-green">{{newLogCount()}}</span>
</button>
<ul class="uib-dropdown-menu list-unstyled msg_list animated fadeInDown" role="menu">
<li ng-repeat="changeLog in changeLogs">