add user avatar to header

This commit is contained in:
Mads Rasmussen
2017-12-19 13:47:23 +01:00
parent 760d7897d8
commit 40b4976a22
2 changed files with 30 additions and 20 deletions

View File

@@ -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

View File

@@ -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) {