Fixes: U4-3492 Recent history list persist between logged in users

This commit is contained in:
Shannon
2014-05-14 15:26:52 +10:00
parent aa2375b8ba
commit 654efd1128
3 changed files with 69 additions and 53 deletions

View File

@@ -28,18 +28,25 @@
* </pre>
*/
angular.module('umbraco.services')
.factory('historyService', function ($rootScope, $timeout, angularHelper) {
.factory('historyService', function ($rootScope, $timeout, angularHelper, eventsService) {
var nArray = [];
function add(item) {
var any = _.where(nArray, {link: item.link});
if (!item) {
return null;
}
var listWithoutThisItem = _.reject(nArray, function(i) {
return i.link == item.link;
});
//put it at the top and reassign
listWithoutThisItem.splice(0, 0, item);
nArray = listWithoutThisItem;
return nArray[0];
if(any.length === 0){
nArray.splice(0,0,item);
return nArray[0];
}
}
return {
@@ -60,7 +67,9 @@ angular.module('umbraco.services')
add: function (item) {
var icon = item.icon || "icon-file";
angularHelper.safeApply($rootScope, function () {
return add({name: item.name, icon: icon, link: item.link, time: new Date() });
var result = add({ name: item.name, icon: icon, link: item.link, time: new Date() });
eventsService.emit("historyService.add", {added: result, all: nArray});
return result;
});
},
/**
@@ -75,7 +84,8 @@ angular.module('umbraco.services')
*/
remove: function (index) {
angularHelper.safeApply($rootScope, function() {
nArray.splice(index, 1);
var result = nArray.splice(index, 1);
eventsService.emit("historyService.remove", { removed: result, all: nArray });
});
},
@@ -89,21 +99,11 @@ angular.module('umbraco.services')
*/
removeAll: function () {
angularHelper.safeApply($rootScope, function() {
nArray = [];
nArray = [];
eventsService.emit("historyService.removeAll");
});
},
/**
* @ngdoc property
* @name umbraco.services.historyService#current
* @propertyOf umbraco.services.historyService
*
* @description
*
* @returns {Array} Array of history entries for the current user, newest items first
*/
current: nArray,
/**
* @ngdoc method
* @name umbraco.services.historyService#getCurrent

View File

@@ -1,10 +1,20 @@
angular.module("umbraco")
.controller("Umbraco.Dialogs.UserController", function ($scope, $location, $timeout, userService, historyService, eventsService) {
$scope.user = userService.getCurrentUser();
$scope.history = historyService.current;
$scope.history = historyService.getCurrent();
$scope.version = Umbraco.Sys.ServerVariables.application.version + " assembly: " + Umbraco.Sys.ServerVariables.application.assemblyVersion;
var evtHandlers = [];
evtHandlers.push(eventsService.on("historyService.add", function (e, args) {
$scope.history = args.all;
}));
evtHandlers.push(eventsService.on("historyService.remove", function (e, args) {
$scope.history = args.all;
}));
evtHandlers.push(eventsService.on("historyService.removeAll", function (e, args) {
$scope.history = [];
}));
$scope.logout = function () {
@@ -16,38 +26,44 @@ angular.module("umbraco")
});
//perform the path change, if it is successful then the promise will resolve otherwise it will fail
$location.path("/logout");
};
$location.path("/logout");
};
$scope.gotoHistory = function (link) {
$location.path(link);
$scope.hide();
};
$scope.gotoHistory = function (link) {
$location.path(link);
$scope.hide();
};
//Manually update the remaining timeout seconds
function updateTimeout() {
$timeout(function () {
if ($scope.remainingAuthSeconds > 0) {
$scope.remainingAuthSeconds--;
$scope.$digest();
//recurse
updateTimeout();
}
}, 1000, false); // 1 second, do NOT execute a global digest
}
//get the user
userService.getCurrentUser().then(function (user) {
$scope.user = user;
if ($scope.user) {
$scope.remainingAuthSeconds = $scope.user.remainingAuthSeconds;
$scope.canEditProfile = _.indexOf($scope.user.allowedSections, "users") > -1;
//set the timer
updateTimeout();
}
});
function updateTimeout() {
$timeout(function () {
if ($scope.remainingAuthSeconds > 0) {
$scope.remainingAuthSeconds--;
$scope.$digest();
//recurse
updateTimeout();
}
}, 1000, false); // 1 second, do NOT execute a global digest
}
//get the user
userService.getCurrentUser().then(function (user) {
$scope.user = user;
if ($scope.user) {
$scope.remainingAuthSeconds = $scope.user.remainingAuthSeconds;
$scope.canEditProfile = _.indexOf($scope.user.allowedSections, "users") > -1;
//set the timer
updateTimeout();
}
});
//remove all event handlers
$scope.$on('$destroy', function () {
for (var i = 0; i < evtHandlers.length; i++) {
evtHandlers[i]();
}
});
});

View File

@@ -34,7 +34,7 @@
<div class="umb-pane">
<h5><localize key="user_yourHistory" /></h5>
<ul class="umb-tree">
<li ng-repeat="item in history | orderBy:'time'">
<li ng-repeat="item in history | orderBy:'time':true">
<a ng-href="{{item.link}}" ng-click="gotoHistory(item.link)" prevent-default>
<i class="{{item.icon}}"></i> {{item.name}}</a>
</li>