From 40b4976a22b24a0ee2fceccb667dd80cb511c41d Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 19 Dec 2017 13:47:23 +0100 Subject: [PATCH] add user avatar to header --- .../application/umbappheader.directive.js | 31 ++++++++++++++++++- .../src/controllers/main.controller.js | 19 ------------ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbappheader.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbappheader.directive.js index aaf46d24db..29f327881b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbappheader.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/application/umbappheader.directive.js @@ -1,7 +1,7 @@ (function () { "use strict"; - function AppHeaderDirective(eventsService, appState) { + function AppHeaderDirective(eventsService, appState, userService) { function link(scope, el, attr, ctrl) { @@ -10,6 +10,7 @@ // the null is important because we do an explicit bool check on this in the view // the avatar is by default the umbraco logo scope.authenticated = null; + scope.user = null; scope.avatar = [ { value: "assets/img/application/logo.png" }, { value: "assets/img/application/logo@2x.png" }, @@ -19,11 +20,39 @@ // when a user logs out or timesout evts.push(eventsService.on("app.notAuthenticated", function() { scope.authenticated = false; + scope.user = null; })); // when the application is ready and the user is authorized setup the data evts.push(eventsService.on("app.ready", function(evt, data) { + scope.authenticated = true; + scope.user = data.user; + + if (scope.user.avatars) { + scope.avatar = []; + if (angular.isArray(scope.user.avatars)) { + for (var i = 0; i < scope.user.avatars.length; i++) { + scope.avatar.push({ value: scope.user.avatars[i] }); + } + } + } + + })); + + evts.push(eventsService.on("app.userRefresh", function(evt) { + userService.refreshCurrentUser().then(function(data) { + scope.user = data; + + if (scope.user.avatars) { + scope.avatar = []; + if (angular.isArray(scope.user.avatars)) { + for (var i = 0; i < scope.user.avatars.length; i++) { + scope.avatar.push({ value: scope.user.avatars[i] }); + } + } + } + }); })); // toggle the help dialog by raising the global app state to toggle the help drawer diff --git a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js index 70b729febf..c6600ed869 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js @@ -56,15 +56,6 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ if ($scope.user.locale) { tmhDynamicLocale.set($scope.user.locale); } - - if ($scope.user.avatars) { - $scope.avatar = []; - if (angular.isArray($scope.user.avatars)) { - for (var i = 0; i < $scope.user.avatars.length; i++) { - $scope.avatar.push({ value: $scope.user.avatars[i] }); - } - } - } }); })); @@ -110,16 +101,6 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ tmhDynamicLocale.set($scope.user.locale); } - if ($scope.user.avatars) { - - $scope.avatar = []; - if (angular.isArray($scope.user.avatars)) { - for (var i = 0; i < $scope.user.avatars.length; i++) { - $scope.avatar.push({ value: $scope.user.avatars[i] }); - } - } - - } })); evts.push(eventsService.on("app.ysod", function (name, error) {