Skip to content

Commit 52723ef

Browse files
VCST-2698: Add member icon to the header (#2891)
Co-authored-by: Artem Dudarev <artem@virtoworks.com>
1 parent eea1cd1 commit 52723ef

File tree

14 files changed

+88
-22
lines changed

14 files changed

+88
-22
lines changed

src/VirtoCommerce.Platform.Web/Controllers/Api/ProfilesController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public async Task<ActionResult> GetCurrentUserProfileAsync()
4444
{
4545
var userProfile = AbstractTypeFactory<UserProfile>.TryCreateInstance();
4646
userProfile.Id = currentUser.Id;
47+
userProfile.MemberId = currentUser.MemberId;
4748
await _settingsManager.DeepLoadSettingsAsync(userProfile);
4849

4950
// Main menu settings at initial boot

src/VirtoCommerce.Platform.Web/Controllers/Api/SecurityController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public async Task<ActionResult<UserDetail>> GetCurrentUser()
182182
Permissions = user.Roles.SelectMany(x => x.Permissions).Select(x => x.Name).Distinct().ToArray(),
183183
AuthenticationMethod = HttpContext.User.GetAuthenticationMethod(),
184184
IsSsoAuthenticationMethod = HttpContext.User.IsExternalSignIn(),
185+
MemberId = user.MemberId,
185186
};
186187

187188
// Password never expired with SSO

src/VirtoCommerce.Platform.Web/Model/Profiles/UserProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public class UserProfile : Entity, IHasSettings
88
{
99
public virtual ICollection<ObjectSettingEntry> Settings { get; set; } = new List<ObjectSettingEntry>();
1010
public virtual string TypeName => GetType().Name;
11+
public virtual string MemberId { get; set; }
1112
}
1213
}

src/VirtoCommerce.Platform.Web/Model/Security/UserDetail.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public class UserDetail : Entity
1212
public int DaysTillPasswordExpiry { get; set; }
1313
public string AuthenticationMethod { get; set; }
1414
public bool IsSsoAuthenticationMethod { get; set; }
15+
public string MemberId { get; set; }
1516
}
1617
}

src/VirtoCommerce.Platform.Web/wwwroot/css/themes/main/sass/modules/_header.sass

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@
9090
padding: 0 15px
9191
width: 325px
9292
&__img
93-
background-color: $whiteColor
9493
border-radius: 34px
9594
height: 34px
9695
margin-right: 15px
9796
width: 34px
97+
img
98+
border-radius: 34px
99+
object-fit: contain
100+
object-position: center
101+
width: 34px
102+
height: 34px
98103
&__name,
99104
&__role
100105
color: $whiteColor

src/VirtoCommerce.Platform.Web/wwwroot/js/app/navigation/blade/bladeContainer.tpl.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
</div>
4343

4444
<div class="blade-header">
45-
<i ng-if="!blade.currentEntity.iconUrl" ng-class="blade.headIcon ? blade.headIcon : 'fa fa-folder'" class="blade-header__icon"></i>
45+
<span ng-if="!blade.iconUrl && !blade.currentEntity.iconUrl" ng-class="blade.headIcon ? blade.headIcon : 'fa fa-folder'" class="blade-header__icon"></span>
4646

47-
<img ng-if="blade.currentEntity.iconUrl" ng-src="{{ blade.currentEntity.iconUrl }}" fallback-src="{{ blade.fallbackIconUrl }}" class="blade-header__img" />
47+
<img ng-if="blade.iconUrl || blade.currentEntity.iconUrl" ng-src="{{ blade.iconUrl || blade.currentEntity.iconUrl }}" fallback-src="{{ blade.fallbackIconUrl }}" class="blade-header__img" />
4848

4949
<div class="blade-header__title">{{ blade.title | translate: blade.titleValues }}</div>
5050

51-
<span ng-if="pageSettings.totalItems" class="vc-badge">{{ pageSettings.totalItems | number: 0 }}</ span>
51+
<span ng-if="pageSettings.totalItems" class="vc-badge">{{ pageSettings.totalItems | number: 0 }}</span>
5252
</div>
5353

5454
<div class="blade-toolbar">

src/VirtoCommerce.Platform.Web/wwwroot/js/app/security/login/headerUserProfileWidget.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
angular.module('platformWebApp')
2-
.directive('vaHeaderUserProfileWidget', ['$document', '$state', 'platformWebApp.authService', 'platformWebApp.dialogService', 'platformWebApp.login',
3-
function ($document, $state, authService, dialogService, loginResources) {
2+
.directive('vaHeaderUserProfileWidget', [
3+
'$document', '$state', 'platformWebApp.authService', 'platformWebApp.dialogService', 'platformWebApp.login', 'platformWebApp.userProfileIconService',
4+
function ($document, $state, authService, dialogService, loginResources, userProfileIconService) {
45

56
return {
67
restrict: 'E',
@@ -28,6 +29,7 @@ angular.module('platformWebApp')
2829
scope.userType = '';
2930
scope.isAdministrator = false;
3031
scope.isSsoAuthenticationMethod = false;
32+
scope.userIconUrl = userProfileIconService.getUserIconUrl();
3133

3234
function handleClickEvent(event) {
3335
var dropdownElement = $document.find('[userProfileWidget]');
@@ -69,6 +71,12 @@ angular.module('platformWebApp')
6971
scope.isSsoAuthenticationMethod = authService.isSsoAuthenticationMethod;
7072
});
7173

74+
scope.$watch(function () {
75+
return userProfileIconService.iconUrlChanged;
76+
}, function () {
77+
scope.userIconUrl = userProfileIconService.getUserIconUrl();
78+
});
79+
7280
$document.bind('click', handleClickEvent);
7381

7482
scope.$on('$destroy', function () {

src/VirtoCommerce.Platform.Web/wwwroot/js/app/security/login/headerUserProfileWidget.tpl.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<span class="account-user" va-tooltip tooltip="{{'platform.menu.user-profile' | translate}}"
44
tooltip-placement="bottom" tooltip-animation="false" tooltip-popup-delay="{{$parent.tooltipPopupDelay}}">
55
<span class="account-user__img">
6-
<img src="/images/userpic.svg" alt="" class="account-user__pic">
6+
<img src="{{userIconUrl ? userIconUrl : '/images/userpic.svg'}}" alt="" class="account-user__pic">
77
</span>
88
<span class="account-user__info">
99
<span class="account-user__name">{{fullName || userLogin}}</span>
10-
<span class="account-user__role">{{isAdministrator ? 'Administrator' : userType }}</span>
10+
<span class="account-user__role">{{isAdministrator ? 'Administrator' : userType}}</span>
1111
</span>
1212
<span class="account-user__carret"></span>
1313
</span>

src/VirtoCommerce.Platform.Web/wwwroot/js/app/security/services/auth.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
angular.module('platformWebApp')
2-
.factory('platformWebApp.authService', ['$http', '$rootScope', '$state', '$interpolate', '$q', '$window', 'platformWebApp.authDataStorage', 'platformWebApp.externalSignInStorage', function ($http, $rootScope, $state, $interpolate, $q, $window, authDataStorage, externalSignInStorage) {
2+
.factory('platformWebApp.authService', [
3+
'$http', '$rootScope', '$interpolate', '$q', '$window', 'platformWebApp.authDataStorage', 'platformWebApp.externalSignInStorage',
4+
function ($http, $rootScope, $interpolate, $q, $window, authDataStorage, externalSignInStorage) {
35
var serviceBase = 'api/platform/security/';
46
var authContext = {
57
userId: null,
68
userLogin: null,
79
fullName: null,
810
permissions: null,
9-
isAuthenticated: false
11+
isAuthenticated: false,
12+
memberId: null
1013
};
1114

1215
authContext.fillAuthData = function () {
@@ -116,21 +119,21 @@ angular.module('platformWebApp')
116119
};
117120

118121
authContext.checkPermission = function (permission, securityScopes) {
119-
//first check admin permission
122+
// First check admin permission
120123
// var hasPermission = $.inArray('admin', authContext.permissions) > -1;
121124
var hasPermission = authContext.isAdministrator;
122125
if (!hasPermission && permission) {
123126
permission = permission.trim();
124-
//first check global permissions
127+
// First check global permissions
125128
hasPermission = $.inArray(permission, authContext.permissions) > -1;
126129
if (!hasPermission && securityScopes) {
127130
if (typeof securityScopes === 'string' || angular.isArray(securityScopes)) {
128131
securityScopes = angular.isArray(securityScopes) ? securityScopes : securityScopes.split(',');
129-
//Check permissions in scope
132+
// Check permissions in scope
130133
hasPermission = _.some(securityScopes, function (x) {
131134
var permissionWithScope = permission + ":" + x;
132135
var retVal = $.inArray(permissionWithScope, authContext.permissions) > -1;
133-
//console.log(permissionWithScope + "=" + retVal);
136+
// console.log(permissionWithScope + "=" + retVal);
134137
return retVal;
135138
});
136139
}
@@ -144,14 +147,17 @@ angular.module('platformWebApp')
144147
authContext.userLogin = user.userName;
145148
authContext.fullName = user.userLogin;
146149
authContext.isAuthenticated = user.userName != null;
150+
authContext.memberId = user.memberId;
147151

148-
//Interpolate permissions to replace some template to real value
152+
// Interpolate permissions to replace some template to real value
149153
if (authContext.permissions) {
150154
authContext.permissions = _.map(authContext.permissions, function (x) {
151155
return $interpolate(x)(authContext);
152156
});
153157
}
158+
154159
$rootScope.$broadcast('loginStatusChanged', authContext);
155160
}
161+
156162
return authContext;
157163
}]);

src/VirtoCommerce.Platform.Web/wwwroot/js/app/userProfile/blades/userProfile.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
angular.module('platformWebApp')
2-
.controller('platformWebApp.userProfile.userProfileController', ['$rootScope', '$scope', 'platformWebApp.bladeNavigationService', 'platformWebApp.settings', 'platformWebApp.settings.helper',
3-
'platformWebApp.i18n', 'platformWebApp.userProfile', 'platformWebApp.common.languages', 'platformWebApp.common.locales', 'platformWebApp.common.timeZones', 'platformWebApp.userProfileApi',
4-
function ($rootScope, $scope, bladeNavigationService, settings, settingsHelper, i18n, userProfile, languages, locales, timeZones, userProfileApi) {
2+
.controller('platformWebApp.userProfile.userProfileController', [
3+
'$rootScope', '$scope',
4+
'platformWebApp.i18n', 'platformWebApp.userProfile', 'platformWebApp.common.languages', 'platformWebApp.common.locales', 'platformWebApp.common.timeZones',
5+
'platformWebApp.userProfileApi', 'platformWebApp.userProfileIconService',
6+
function ($rootScope, $scope, i18n, userProfile, languages, locales, timeZones, userProfileApi, userProfileIconService) {
57
var blade = $scope.blade;
68
blade.headIcon = 'fa fa-user';
79
blade.title = 'platform.blades.user-profile.title';
10+
blade.iconUrl = userProfileIconService.getUserIconUrl();
811

912
blade.currentLanguage = i18n.getLanguage();
1013
blade.currentRegionalFormat = i18n.getRegionalFormat();
@@ -53,6 +56,7 @@ angular.module('platformWebApp')
5356
blade.currentTimeZone = getNameByCode($scope.timeZones, blade.currentTimeZone);
5457
blade.currentTimeAgoSettings = userProfile.timeAgoSettings;
5558
blade.currentTimeSettings = userProfile.timeSettings;
59+
blade.currentMemberId = userProfile.memberId;
5660
}
5761

5862
function isLoading() {
@@ -113,4 +117,10 @@ angular.module('platformWebApp')
113117
userProfile.save();
114118
}
115119
}
120+
121+
$scope.$watch(function () {
122+
return userProfileIconService.iconUrlChanged;
123+
}, function () {
124+
blade.iconUrl = userProfileIconService.getUserIconUrl();
125+
});
116126
}]);

src/VirtoCommerce.Platform.Web/wwwroot/js/app/userProfile/blades/userProfile.tpl.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
</div>
6666
</div>
6767
</div>
68-
</form>
68+
<div class="form-group" ng-if="userProfile.memberId">
69+
<va-widget-container group="userProfileDetail" blade="blade" gridster-opts="{columns: 3}"></va-widget-container>
70+
</div>
71+
</form>
6972
</div>
7073
</div>
7174
</div>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
angular.module('platformWebApp')
1+
angular.module('platformWebApp')
22
.factory('platformWebApp.userProfileApi', ['$resource', function ($resource) {
33
return $resource('api/platform/profiles/currentuser', { }, {
44
getLocales: { url: 'api/platform/localization/locales', isArray: true },
55
getRegionalFormats: { url: 'api/platform/localization/regionalformats', isArray: true }
66
});
7-
}]);
7+
}]);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
angular.module('platformWebApp')
2+
.factory('platformWebApp.userProfileIconService', ['$rootScope', function ($rootScope) {
3+
4+
var currentMemberId = null;
5+
var userIconUrl = null;
6+
7+
$rootScope.$on("loginStatusChanged", function (event, authContext) {
8+
if (!authContext.memberId) {
9+
setUserIconUrl(currentMemberId, null);
10+
}
11+
currentMemberId = authContext.memberId;
12+
});
13+
14+
var service = {
15+
iconUrlChanged: Date.now(),
16+
setUserIconUrl: setUserIconUrl,
17+
getUserIconUrl: function () {
18+
return userIconUrl;
19+
}
20+
};
21+
22+
function setUserIconUrl (memberId, url) {
23+
if (currentMemberId === memberId) {
24+
userIconUrl = url;
25+
service.iconUrlChanged = Date.now();
26+
}
27+
}
28+
29+
return service;
30+
}]);

src/VirtoCommerce.Platform.Web/wwwroot/js/app/userProfile/userProfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ angular.module('platformWebApp')
44
.state('workspace.userProfile', {
55
url: '/userProfile',
66
templateUrl: '$(Platform)/Scripts/common/templates/home.tpl.html',
7-
controller: ['$scope', 'platformWebApp.bladeNavigationService', function ($scope, bladeNavigationService) {
7+
controller: ['platformWebApp.bladeNavigationService', function (bladeNavigationService) {
88
var blade = {
99
id: 'userProfile',
1010
controller: 'platformWebApp.userProfile.userProfileController',

0 commit comments

Comments
 (0)