Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
</div>
</eform-new-subheader>

<div class="d-flex flex-row justify-content-between align-items-start">
<div [formGroup]="profileForm" class="d-flex flex-row justify-content-between align-items-start">
<mat-card class="p-3" *ngIf="selectCurrentUserIsAdmin$ | async">
<mat-card-header>
<mat-card-title>{{ 'Google Authenticator' | translate }}</mat-card-title>
</mat-card-header>
<div class="mb-1">
<mat-checkbox
id="2fauthForsed"
(change)="isTwoFactorEnabledCheckBoxChanged($event)"
[(ngModel)]="googleAuthInfoModel.isTwoFactorEnabled"
formControlName="isTwoFactorEnabled"
(change)="toggleTwoFactor()"
color="primary">
{{ 'Status' | translate }}
</mat-checkbox>
Expand Down Expand Up @@ -128,7 +128,7 @@
[bindLabel]="'name'"
[bindValue]="'languageCode'"
[clearable]="false"
[(ngModel)]="userSettingsModel.locale"
formControlName="locale"
[items]="activeLanguages">
</mtx-select>
</mat-form-field>
Expand All @@ -139,7 +139,7 @@
[bindLabel]="'text'"
[bindValue]="'id'"
[clearable]="false"
[(ngModel)]="userSettingsModel.formats"
formControlName="formats"
[items]="countries">
</mtx-select>
</mat-form-field>
Expand All @@ -150,14 +150,14 @@
[bindLabel]="'name'"
[bindValue]="'id'"
[clearable]="false"
[(ngModel)]="userSettingsModel.timeZone"
formControlName="timeZone"
[items]="timeZones.timeZoneModels">
</mtx-select>
</mat-form-field>
<div class="mb-1">
<mat-checkbox
id="darkTheme"
[(ngModel)]="userSettingsModel.darkTheme">
formControlName="darkTheme">
{{ 'Dark theme' | translate }}
</mat-checkbox>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, OnInit, inject } from '@angular/core';
import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { GoogleAuthInfoModel } from 'src/app/common/models/auth';
import { UserSettingsModel } from 'src/app/common/models/settings';
import {
Expand Down Expand Up @@ -32,6 +33,7 @@ import * as R from 'ramda';
standalone: false
})
export class ProfileSettingsComponent implements OnInit {
private fb = inject(FormBuilder);
authStateService = inject(AuthStateService);
private authStore = inject(Store);
private googleAuthService = inject(GoogleAuthService);
Expand All @@ -55,6 +57,14 @@ export class ProfileSettingsComponent implements OnInit {
public selectCurrentUserIsAdmin$ = this.authStore.select(selectCurrentUserIsAdmin);
private selectBearerToken$ = this.authStore.select(selectBearerToken);

profileForm: FormGroup = this.fb.group({
locale: new FormControl(''),
formats: new FormControl(''),
timeZone: new FormControl(''),
darkTheme: new FormControl(false),
isTwoFactorEnabled: new FormControl(false),
});

ngOnInit() {
this.getEnabledLanguages();
this.initializeUploaders();
Expand Down Expand Up @@ -94,12 +104,25 @@ export class ProfileSettingsComponent implements OnInit {
});
}

isTwoFactorEnabledCheckBoxChanged(e) {
if (e.target) {
this.googleAuthInfoModel.isTwoFactorEnabled = e.target.checked;
} else {
return;
}
// isTwoFactorEnabledCheckBoxChanged(e) {
// if (e.target) {
// this.googleAuthInfoModel.isTwoFactorEnabled = e.target.checked;
// } else {
// return;
// }
// this.googleAuthService
// .updateGoogleAuthenticatorInfo(this.googleAuthInfoModel)
// .subscribe((data) => {
// if (data.success) {
// this.authStateService.logout();
// }
// });
// }

toggleTwoFactor(): void {
const isEnabled = this.profileForm.get('isTwoFactorEnabled')?.value;
this.googleAuthInfoModel.isTwoFactorEnabled = isEnabled;

this.googleAuthService
.updateGoogleAuthenticatorInfo(this.googleAuthInfoModel)
.subscribe((data) => {
Expand All @@ -117,41 +140,106 @@ export class ProfileSettingsComponent implements OnInit {
});
}

// deleteGoogleAuthenticatorInfo() {
// this.googleAuthService.deleteGoogleAuthenticatorInfo().subscribe((data) => {
// if (data && data.success) {
// this.googleAuthInfoModel.psk = null;
// }
// });
// }

// updateUserProfileSettings() {
//
// if (this.profilePictureUploader.queue.length > 0) {
// this.profilePictureUploader.queue[0].upload();
// }
// this.userSettingsService
// .updateUserSettings(this.userSettingsModel)
// .subscribe((data) => {
// this.userSettings.getUserSettings().subscribe((data) => {
// this.userSettingsModel = data.model;
// this.store.dispatch(updateCurrentUserLocaleAndDarkTheme({
// darkTheme: this.userSettingsModel.darkTheme,
// locale: this.userSettingsModel.locale,
// languageId: this.userSettingsModel.languageId
// }));
// this.getUserSettings();
// });
// this.store.dispatch(loadAppMenu());
// });
// }

updateUserProfileSettings() {
const formValue = this.profileForm.value;

this.userSettingsModel.locale = formValue.locale;
this.userSettingsModel.formats = formValue.formats;
this.userSettingsModel.timeZone = formValue.timeZone;
this.userSettingsModel.darkTheme = formValue.darkTheme;

if (this.profilePictureUploader.queue.length > 0) {
this.profilePictureUploader.queue[0].upload();
}
this.userSettingsService
.updateUserSettings(this.userSettingsModel)
.subscribe((data) => {
this.userSettings.getUserSettings().subscribe((data) => {
this.userSettingsModel = data.model;
this.store.dispatch(updateCurrentUserLocaleAndDarkTheme({

this.userSettingsService.updateUserSettings(this.userSettingsModel).subscribe((data) => {
this.userSettings.getUserSettings().subscribe((data) => {
this.userSettingsModel = data.model;
this.store.dispatch(
updateCurrentUserLocaleAndDarkTheme({
darkTheme: this.userSettingsModel.darkTheme,
locale: this.userSettingsModel.locale,
languageId: this.userSettingsModel.languageId
}));
this.getUserSettings();
});
this.store.dispatch(loadAppMenu());
languageId: this.userSettingsModel.languageId,
})
);
this.getUserSettings();
});
this.store.dispatch(loadAppMenu());
});
}

// getEnabledLanguages() {
// this.getLanguagesSub$ = this.appSettingsStateService.getLanguages()
// .pipe(tap(data => {
// if (data && data.success && data.model) {
// this.appLanguages = data.model;
// this.activeLanguages = this.appLanguages.languages.filter((x) => x.isActive);
// this.getTimeZones();
// this.getGoogleAuthenticatorInfo();
// this.getUserSettings();
// }
// }))
// .subscribe();
// }

getEnabledLanguages() {
this.getLanguagesSub$ = this.appSettingsStateService.getLanguages()
.pipe(tap(data => {
if (data && data.success && data.model) {
this.appLanguages = data.model;
this.activeLanguages = this.appLanguages.languages.filter((x) => x.isActive);
this.getTimeZones();
this.getGoogleAuthenticatorInfo();
this.getUserSettings();
}
}))
.pipe(
tap((data) => {
if (data && data.success && data.model) {
this.appLanguages = data.model;
this.activeLanguages = this.appLanguages.languages.filter((x) => x.isActive);
this.getTimeZones();
this.getGoogleAuthenticatorInfo();

// Fetch user settings after languages are available
this.userSettingsService.getUserSettings().subscribe((data) => {
this.userSettingsModel = data.model;

this.profileForm.patchValue({
locale: this.userSettingsModel.locale,
formats: this.userSettingsModel.formats,
timeZone: this.userSettingsModel.timeZone,
darkTheme: this.userSettingsModel.darkTheme,
isTwoFactorEnabled: this.googleAuthInfoModel.isTwoFactorEnabled,
});
});
}
})
)
.subscribe();
}


get languages() {
return this.appLanguages.languages.filter((x) => x.isActive);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<h3 mat-dialog-title>{{ (edit ? 'Edit User' : 'New User') | translate }}</h3>
<div mat-dialog-content>
<form #form="ngForm" class="need-wrapper">
<form #form="ngForm" [formGroup]="userForm" class="need-wrapper">
<div class="d-flex flex-row">
<mat-form-field>
<mat-label>{{ 'First name' | translate }}</mat-label>
<input
matInput
type="text"
[disabled]="userModel.isDeviceUser"
[(ngModel)]="userModel.firstName"
[id]="edit ? 'editFirstName' : 'createFirstName'"
[name]="edit ? 'editFirstName' : 'createFirstName'"
matInput
type="text"
[disabled]="isDeviceUser"
formControlName="firstName"
[id]="edit ? 'editFirstName' : 'createFirstName'"
[name]="edit ? 'editFirstName' : 'createFirstName'"
>
</mat-form-field>
<mat-form-field>
<mat-label>{{ 'Last name' | translate }}</mat-label>
<input
matInput
type="text"
[disabled]="userModel.isDeviceUser"
[(ngModel)]="userModel.lastName"
[disabled]="isDeviceUser"
formControlName="lastName"
[name]="edit ? 'editLastName' : 'createLastName'"
[id]="edit ? 'editLastName' : 'createLastName'"
>
Expand All @@ -31,9 +31,8 @@ <h3 mat-dialog-title>{{ (edit ? 'Edit User' : 'New User') | translate }}</h3>
<input
matInput
required
#createEmail="ngModel"
type="text"
[(ngModel)]="userModel.email"
type="email"
formControlName="email"
[id]="edit ? 'emailEdit' : 'createEmail'"
[name]="edit ? 'emailEdit' : 'createEmail'"
>
Expand All @@ -44,7 +43,7 @@ <h3 mat-dialog-title>{{ (edit ? 'Edit User' : 'New User') | translate }}</h3>
matInput
required
type="password"
[(ngModel)]="userModel.password"
formControlName="password"
[id]="edit ? 'editPassword' : 'createPassword'"
[name]="edit ? 'editPassword' : 'createPassword'"
>
Expand All @@ -58,8 +57,7 @@ <h3 mat-dialog-title>{{ (edit ? 'Edit User' : 'New User') | translate }}</h3>
bindLabel="name"
bindValue="id"
[clearable]="false"
[(ngModel)]="userModel.role"
[name]="edit ? 'editRole' : 'createRole'"
formControlName="role"
[id]="edit ? 'editRole' : 'createRole'"
id="createRole"
appendTo="body"
Expand All @@ -69,14 +67,13 @@ <h3 mat-dialog-title>{{ (edit ? 'Edit User' : 'New User') | translate }}</h3>
]"
></mtx-select>
</mat-form-field>
<mat-form-field *ngIf="userModel.role !== 'admin'">
<mat-form-field *ngIf="userForm.get('role')?.value !== 'admin'">
<mat-label>{{ 'Group' | translate }}</mat-label>
<mtx-select
required
bindLabel="groupName"
bindValue="id"
[(ngModel)]="userModel.groupId"
[name]="edit ? 'editGroup' : 'createGroup'"
formControlName="groupId"
[id]="edit ? 'editGroup' : 'createGroup'"
appendTo="body"
[items]="availableGroups.entities"
Expand All @@ -87,11 +84,11 @@ <h3 mat-dialog-title>{{ (edit ? 'Edit User' : 'New User') | translate }}</h3>
</div>
<div mat-dialog-actions class="d-flex flex-row justify-content-end">
<button
[disabled]="!form.form.valid"
mat-raised-button
color="accent"
type="submit"
(click)="edit ? updateUser() : createUser()"
[disabled]="userForm.invalid"
(click)="submit()"
[id]="edit ? 'editUserSaveBtn' : 'createAdministrationUserBtn'"
>
{{ (edit ? 'Save' : 'Create') | translate }}
Expand Down
Loading
Loading