From b8c12979df5fe37c6dd7b17172f6710651996c1d Mon Sep 17 00:00:00 2001 From: Timo Date: Fri, 16 Apr 2021 11:28:03 +0300 Subject: [PATCH] RED-1294 RED-1296 RED-1295 --- .../user-profile-screen.component.ts | 59 ++++++++++--------- .../add-edit-rule-set-dialog.component.ts | 6 +- .../add-edit-project-dialog.component.html | 12 +--- .../add-edit-project-dialog.component.ts | 18 ++++++ apps/red-ui/src/app/services/user.service.ts | 8 +++ 5 files changed, 64 insertions(+), 39 deletions(-) diff --git a/apps/red-ui/src/app/components/user-profile/user-profile-screen.component.ts b/apps/red-ui/src/app/components/user-profile/user-profile-screen.component.ts index cb1e9b5fb..e9887aec7 100644 --- a/apps/red-ui/src/app/components/user-profile/user-profile-screen.component.ts +++ b/apps/red-ui/src/app/components/user-profile/user-profile-screen.component.ts @@ -4,7 +4,7 @@ import { UserService } from '../../services/user.service'; import { PermissionsService } from '../../services/permissions.service'; import { LanguageService } from '../../i18n/language.service'; import { TranslateService } from '@ngx-translate/core'; -import { User, UserControllerService } from '@redaction/red-ui-http'; +import { UserControllerService } from '@redaction/red-ui-http'; interface ProfileModel { email: string; @@ -21,8 +21,7 @@ interface ProfileModel { export class UserProfileScreenComponent implements OnInit { public viewReady = false; public formGroup: FormGroup; - private _initialValue: ProfileModel; - private _user: User; + private _profileModel: ProfileModel; constructor( public readonly permissionsService: PermissionsService, @@ -41,35 +40,19 @@ export class UserProfileScreenComponent implements OnInit { } ngOnInit() { - this._loadData(); + this._initializeForm(); } - private _loadData(): void { - try { - this._user = this._userService.getUserById(this._userService.userId); - this._initialValue = { - email: this._user.email, - firstName: this._user.firstName, - lastName: this._user.lastName, - language: this._languageService.currentLanguage - }; - this.formGroup.patchValue(this._initialValue, { emitEvent: false }); - } catch (e) { - } finally { - this.viewReady = true; - } + get languageChanged(): boolean { + return this._profileModel['language'] !== this.formGroup.get('language').value; } - public get languageChanged(): boolean { - return this._initialValue['language'] !== this.formGroup.get('language').value; - } - - public get profileChanged(): boolean { + get profileChanged(): boolean { const keys = Object.keys(this.formGroup.getRawValue()); keys.splice(keys.indexOf('language'), 1); for (const key of keys) { - if (this._initialValue[key] !== this.formGroup.get(key).value) { + if (this._profileModel[key] !== this.formGroup.get(key).value) { return true; } } @@ -77,11 +60,11 @@ export class UserProfileScreenComponent implements OnInit { return false; } - public get languages(): string[] { + get languages(): string[] { return this._translateService.langs; } - public async save(): Promise { + async save(): Promise { this.viewReady = false; if (this.languageChanged) { @@ -97,9 +80,29 @@ export class UserProfileScreenComponent implements OnInit { ...value }) .toPromise(); + + await this._userService.loadCurrentUser(); } - this._initialValue = this.formGroup.value; - this.viewReady = true; + this._initializeForm(); + } + + private _initializeForm(): void { + try { + this._profileModel = { + email: this._userService.user.email, + firstName: this._userService.user.firstName, + lastName: this._userService.user.lastName, + language: this._languageService.currentLanguage + }; + if (this._userService.user.email) { + // disable email if it's already set + this.formGroup.get('email').disable(); + } + this.formGroup.patchValue(this._profileModel, { emitEvent: false }); + } catch (e) { + } finally { + this.viewReady = true; + } } } diff --git a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts index a426c55dd..1a1eb9c49 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/add-edit-rule-set-dialog/add-edit-rule-set-dialog.component.ts @@ -28,8 +28,10 @@ export class AddEditRuleSetDialogComponent { description: [this.ruleSet?.description], validFrom: [this.ruleSet?.validFrom], validTo: [this.ruleSet?.validTo], - downloadFileTypes: [this.ruleSet?.downloadFileTypes], - reportTypes: [this.ruleSet?.reportTypes] + downloadFileTypes: [this.ruleSet ? this.ruleSet.downloadFileTypes : ['PREVIEW', 'REDACTED']], + reportTypes: [ + this.ruleSet ? this.ruleSet.reportTypes : ['WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE', 'WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE', 'EXCEL_MULTI_FILE'] + ] }); this.hasValidFrom = !!this.ruleSet?.validFrom && !!this.ruleSet?.validTo; } diff --git a/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.html b/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.html index fddaad184..16f159f92 100644 --- a/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.html +++ b/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.html @@ -19,7 +19,7 @@
{{ 'project-listing.add-edit-dialog.form.template' | translate }} - + {{ 'project-listing.add-edit-dialog.form.download-file-types.label' | translate }} - + {{ humanize(type) }} @@ -50,10 +47,7 @@ {{ 'project-listing.add-edit-dialog.form.report-types.label' | translate }} - + {{ humanize(type) }} diff --git a/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.ts b/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.ts index 8813893bb..689ed4212 100644 --- a/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.ts +++ b/apps/red-ui/src/app/modules/projects/dialogs/add-edit-project-dialog/add-edit-project-dialog.component.ts @@ -105,4 +105,22 @@ export class AddEditProjectDialogComponent { this.dialogRef.close({ addMembers: true, project: savedProject }); } } + + ruleSetChanged(ruleSetId) { + // if project doesn't yet exist -> add mode + if (!this.project?.projectId) { + // get current selected ruleSet + const ruleSet = this.ruleSets.find((r) => r.ruleSetId === ruleSetId); + if (ruleSet) { + // update dropdown values + this.projectForm.patchValue( + { + downloadFileTypes: ruleSet.downloadFileTypes, + reportTypes: ruleSet.reportTypes + }, + { emitEvent: false } + ); + } + } + } } diff --git a/apps/red-ui/src/app/services/user.service.ts b/apps/red-ui/src/app/services/user.service.ts index 9a376387c..bd76834ce 100644 --- a/apps/red-ui/src/app/services/user.service.ts +++ b/apps/red-ui/src/app/services/user.service.ts @@ -18,6 +18,14 @@ export class UserWrapper { return this._currentUser.email; } + get firstName() { + return this._currentUser.firstName; + } + + get lastName() { + return this._currentUser.lastName; + } + get isManager() { return this.roles.indexOf('RED_MANAGER') >= 0; }