Skip to content

Commit c6c972b

Browse files
committed
Adding changes to show CreatedAt/UpdatedAt for admin.
Adding changes to fix user email/first and last name.
1 parent 7dac683 commit c6c972b

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using BackendConfiguration.Pn.Services.BackendConfigurationLocalizationService;
1010
using eFormCore;
1111
using JetBrains.Annotations;
12+
using Microsoft.AspNetCore.Identity;
1213
using Microsoft.EntityFrameworkCore;
1314
using Microting.eForm.Infrastructure;
1415
using Microting.eForm.Infrastructure.Constants;
@@ -23,6 +24,7 @@
2324
using Microting.TimePlanningBase.Infrastructure.Data.Entities;
2425
using Rebus.Bus;
2526
using Microsoft.Extensions.Logging;
27+
using Microting.eFormApi.BasePn.Infrastructure.Database.Entities;
2628

2729
namespace BackendConfiguration.Pn.Infrastructure.Helpers;
2830

@@ -253,6 +255,8 @@ await WorkOrderHelper.WorkorderFlowDeployEform(propertyWorkers, core, userServic
253255

254256
public static async Task<OperationResult> UpdateDeviceUser(DeviceUserModel deviceUserModel, Core core,
255257
int userId,
258+
IUserService userService,
259+
UserManager<EformUser> userManager,
256260
BackendConfigurationPnDbContext backendConfigurationPnDbContext,
257261
TimePlanningPnDbContext timePlanningDbContext,
258262
ILogger logger,
@@ -276,6 +280,7 @@ public static async Task<OperationResult> UpdateDeviceUser(DeviceUserModel devic
276280
var worker = await sdkDbContext.Workers.SingleOrDefaultAsync(x => x.MicrotingUid == siteDto.WorkerUid).ConfigureAwait(false);
277281
if (worker == null) return new OperationResult(false, "DeviceUserCouldNotBeObtained");
278282
{
283+
var oldEmail = worker.Email;
279284
if (sdkDbContext.Workers.Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid))
280285
{
281286
// this email is already in use
@@ -293,6 +298,16 @@ public static async Task<OperationResult> UpdateDeviceUser(DeviceUserModel devic
293298
worker.PhoneNumber = deviceUserModel.PhoneNumber;
294299
await worker.Update(sdkDbContext).ConfigureAwait(false);
295300

301+
var user = await userService.GetByUsernameAsync(oldEmail).ConfigureAwait(false);
302+
if (user != null)
303+
{
304+
user.Email = deviceUserModel.WorkerEmail;
305+
user.FirstName = deviceUserModel.UserFirstName;
306+
user.LastName = deviceUserModel.UserLastName;
307+
user.Locale = language.LanguageCode;
308+
var result = await userManager.UpdateAsync(user);
309+
}
310+
296311
if (isUpdated)
297312
{
298313
if (deviceUserModel.TaskManagementEnabled == true)

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
*/
2424

2525
#nullable enable
26+
using System;
2627
using System.Collections.Generic;
2728

2829
namespace BackendConfiguration.Pn.Infrastructure.Models;
@@ -92,9 +93,7 @@ public class DeviceUserModel
9293
public bool IsLocked { get; set; }
9394
public bool IsBackendUser { get; set; }
9495
public bool HasWorkOrdersAssigned { get; set; }
95-
9696
public string Manufacturer { get; set; }
97-
9897
public string Model { get; set; }
9998
public string Os { get; set; }
10099
public string OsVersion { get; set; }
@@ -107,6 +106,8 @@ public class DeviceUserModel
107106

108107
public string? WorkerEmail { get; set; }
109108
public string? PhoneNumber { get; set; }
109+
public DateTime? CreatedAt { get; set; }
110+
public DateTime? UpdatedAt { get; set; }
110111

111112
public static implicit operator DeviceUserModel(Microting.EformAngularFrontendBase.Infrastructure.Data.Models.DeviceUserModel model)
112113
{

eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
using BackendConfiguration.Pn.Infrastructure.Helpers;
2626
using BackendConfiguration.Pn.Infrastructure.Models;
2727
using BackendConfiguration.Pn.Services.RebusService;
28+
using Microsoft.AspNetCore.Identity;
2829
using Microsoft.Extensions.Logging;
30+
using Microting.eFormApi.BasePn.Infrastructure.Database.Entities;
2931
using Microting.EformBackendConfigurationBase.Infrastructure.Enum;
3032
using Microting.eFormCaseTemplateBase.Infrastructure.Data;
3133
using Microting.ItemsPlanningBase.Infrastructure.Data;
@@ -51,6 +53,7 @@ namespace BackendConfiguration.Pn.Services.BackendConfigurationAssignmentWorkerS
5153

5254
public class BackendConfigurationAssignmentWorkerService(
5355
IEFormCoreService coreHelper,
56+
UserManager<EformUser> userManager,
5457
IUserService userService,
5558
BackendConfigurationPnDbContext backendConfigurationPnDbContext,
5659
IBackendConfigurationLocalizationService backendConfigurationLocalizationService,
@@ -364,13 +367,17 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id
364367
site.WorkflowState,
365368
WorkerEmail = worker.Email,
366369
worker.PhoneNumber,
370+
site.CreatedAt,
371+
site.UpdatedAt
367372

368373
};
369374
sitesQuery = sitesQuery.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed);
370375

371376
var deviceUsers = await sitesQuery
372377
.Select(x => new DeviceUserModel
373378
{
379+
CreatedAt = x.CreatedAt,
380+
UpdatedAt = x.UpdatedAt,
374381
UserFirstName = x.UserFirstName,
375382
UserLastName = x.UserLastName,
376383
EmployeeNo = x.EmployeeNo,
@@ -490,13 +497,6 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id
490497
// Convert deviceUsers to IQueryable
491498
var deviceUsersQuery = deviceUsers.AsQueryable();
492499

493-
var tempList = deviceUsersQuery.ToList();
494-
495-
foreach (var deviceUserModel in tempList)
496-
{
497-
Console.WriteLine("Device user: " + deviceUserModel.SiteName + " with workerEmail: " + deviceUserModel.WorkerEmail + " and phone number: " + deviceUserModel.PhoneNumber);
498-
}
499-
500500
try
501501
{
502502
deviceUsersQuery = QueryHelper.AddFilterAndSortToQuery(deviceUsersQuery, requestModel, new List<string> { "SiteName", "WorkerEmail", "PhoneNumber", "EmployeeNo" });
@@ -526,7 +526,7 @@ public async Task<OperationResult> UpdateDeviceUser(DeviceUserModel deviceUserMo
526526
{
527527
var core = await coreHelper.GetCore().ConfigureAwait(false);
528528
var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(deviceUserModel, core,
529-
userService.UserId, backendConfigurationPnDbContext,
529+
userService.UserId, userService, userManager, backendConfigurationPnDbContext,
530530
timePlanningDbContext, logger, itemsPlanningPnDbContext);
531531

532532
return new OperationResult(result.Success, backendConfigurationLocalizationService.GetString(result.Message));

eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,18 @@
4646
</div>
4747
</ng-template>
4848

49+
<!--<ng-template #deviceUserIdTpl let-row let-i="index">-->
50+
<!-- <div class="deviceUserId" id="deviceUserId-{{i}}">{{row.siteId}}</div>-->
51+
<!--</ng-template>-->
52+
4953
<ng-template #deviceUserIdTpl let-row let-i="index">
50-
<div class="deviceUserId" id="deviceUserId-{{i}}">{{row.siteId}}</div>
54+
<div class="deviceUserId" id="deviceUserId-{{i}}">
55+
<ng-container *ngIf="selectAuthIsAdmin$ | async;">
56+
<span>{{row.siteId}}<small class="microting-uid"> ({{getFormattedDate(row.createdAt)}} / {{getFormattedDate(row.updatedAt)}})</small></span>
57+
</ng-container>
58+
<ng-container *ngIf="(selectAuthIsAdmin$ | async) !== true;">
59+
{{row.siteId}}
60+
</ng-container></div>
5161
</ng-template>
5262

5363
<ng-template #fullNameTpl let-row let-i="index">

eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ import {
1818
} from '../';
1919
import {dialogConfigHelper} from 'src/app/common/helpers';
2020
import {Store} from '@ngrx/store';
21-
import {selectCurrentUserClaimsDeviceUsersDelete, selectCurrentUserClaimsDeviceUsersUpdate} from 'src/app/state';
21+
import {
22+
selectAuthIsAdmin,
23+
selectCurrentUserClaimsDeviceUsersDelete,
24+
selectCurrentUserClaimsDeviceUsersUpdate
25+
} from 'src/app/state';
2226
import {
2327
selectPropertyWorkersNameFilters,
2428
selectPropertyWorkersPaginationIsSortDsc,
2529
selectPropertyWorkersPaginationSort
2630
} from '../../../../state';
31+
import {format} from "date-fns";
32+
import {AuthStateService} from "src/app/common/store";
2733

2834
@AutoUnsubscribe()
2935
@Component({
@@ -49,6 +55,7 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy {
4955
public selectPropertyWorkersPaginationSort$ = this.store.select(selectPropertyWorkersPaginationSort);
5056
public selectPropertyWorkersPaginationIsSortDsc$ = this.store.select(selectPropertyWorkersPaginationIsSortDsc);
5157
public selectPropertyWorkersNameFilters$ = this.store.select(selectPropertyWorkersNameFilters);
58+
public selectAuthIsAdmin$ = this.store.select(selectAuthIsAdmin);
5259

5360
get TaskWizardStatusesEnum() {
5461
return TaskWizardStatusesEnum;
@@ -57,6 +64,7 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy {
5764
constructor(
5865
private store: Store,
5966
private translateService: TranslateService,
67+
private authStateService: AuthStateService,
6068
public propertyWorkersStateService: PropertyWorkersStateService,
6169
private dialog: MatDialog,
6270
private overlay: Overlay,) {
@@ -299,4 +307,8 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy {
299307

300308
ngOnDestroy(): void {
301309
}
310+
311+
getFormattedDate(date: Date) {
312+
return format(date, 'P', {locale: this.authStateService.dateFnsLocale});
313+
}
302314
}

0 commit comments

Comments
 (0)