Skip to content

Commit 9758045

Browse files
committed
VCST-2698: full functionality for displaying user icons in the header
1 parent a3dffdc commit 9758045

File tree

8 files changed

+29
-10
lines changed

8 files changed

+29
-10
lines changed

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

+1
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/Model/Profiles/UserProfile.cs

+1
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/wwwroot/css/themes/main/sass/modules/_header.sass

+6-1
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/security/services/auth.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
angular.module('platformWebApp')
2-
.factory('platformWebApp.authService', ['$http', '$rootScope', '$state', '$interpolate', '$q', '$window', 'platformWebApp.authDataStorage', 'platformWebApp.externalSignInStorage', 'platformWebApp.modulesApi', function ($http, $rootScope, $state, $interpolate, $q, $window, authDataStorage, externalSignInStorage, modulesApi) {
2+
.factory('platformWebApp.authService', ['$http', '$rootScope', '$interpolate', '$q', '$window', 'platformWebApp.authDataStorage', 'platformWebApp.externalSignInStorage', 'platformWebApp.modulesApi', function ($http, $rootScope, $interpolate, $q, $window, authDataStorage, externalSignInStorage, modulesApi) {
33
var serviceBase = 'api/platform/security/';
44
var authContext = {
55
userId: null,
@@ -174,5 +174,9 @@ angular.module('platformWebApp')
174174
);
175175
};
176176

177+
$rootScope.$on("memberIconChanged", function (event, url) {
178+
authContext.iconUrl = url;
179+
});
180+
177181
return authContext;
178182
}]);

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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', ['$http', '$rootScope', '$scope', 'platformWebApp.i18n', 'platformWebApp.userProfile', 'platformWebApp.common.languages', 'platformWebApp.common.locales', 'platformWebApp.common.timeZones', 'platformWebApp.userProfileApi', 'platformWebApp.moduleHelper',
3+
function ($http, $rootScope, $scope, i18n, userProfile, languages, locales, timeZones, userProfileApi, moduleHelper) {
54
var blade = $scope.blade;
65
blade.headIcon = 'fa fa-user';
76
blade.title = 'platform.blades.user-profile.title';
@@ -11,6 +10,7 @@ angular.module('platformWebApp')
1110
blade.currentTimeZone = i18n.getTimeZone();
1211
blade.currentTimeAgoSettings = i18n.getTimeAgoSettings();
1312
blade.currentTimeSettings = i18n.getTimeSettings();
13+
blade.currentEntity = {};
1414

1515
userProfile.load().then(function () {
1616
initializeBlade();
@@ -53,6 +53,14 @@ angular.module('platformWebApp')
5353
blade.currentTimeZone = getNameByCode($scope.timeZones, blade.currentTimeZone);
5454
blade.currentTimeAgoSettings = userProfile.timeAgoSettings;
5555
blade.currentTimeSettings = userProfile.timeSettings;
56+
57+
if (userProfile.memberId && _.any(moduleHelper.modules, module => module.id === 'VirtoCommerce.Customer')) {
58+
$http.get('api/members/' + userProfile.memberId).then(function (memberResponse) {
59+
blade.currentEntity = memberResponse.data;
60+
// This flag is used to save icon immediately in the MemberIcon blade of the Customer model
61+
blade.saveIconImmediately = true;
62+
});
63+
}
5664
}
5765

5866
function isLoading() {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
</div>
6666
</div>
6767
</div>
68-
<div class="form-group">
69-
<va-widget-container group="userProfile" blade="blade" gridster-opts="{columns: 3}"></va-widget-container>
68+
<div class="form-group" ng-if="userProfile.memberId">
69+
<va-widget-container group="userProfileDetail" blade="blade" gridster-opts="{columns: 3}"></va-widget-container>
7070
</div>
7171
</form>
7272
</div>
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+
}]);

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

+1-1
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)