diff --git a/src/Umbraco.Web.UI.Client/src/common/services/history.service.js b/src/Umbraco.Web.UI.Client/src/common/services/history.service.js index 21764c59bf..88200cf086 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/history.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/history.service.js @@ -28,18 +28,25 @@ * */ 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 diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js index 0ab78896ad..0da1a271b8 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.controller.js @@ -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](); + } + + }); - - }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html index 1e86630486..ff71cec524 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html @@ -34,7 +34,7 @@