Pull request #155: RED-1294 RED-1296 RED-1295

Merge in RED/ui from ui-fixes to master

* commit 'b8c12979df5fe37c6dd7b17172f6710651996c1d':
  RED-1294 RED-1296 RED-1295
This commit is contained in:
Timo Bejan 2021-04-16 11:58:27 +02:00
commit c39bcc8770
5 changed files with 64 additions and 39 deletions

View File

@ -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<void> {
async save(): Promise<void> {
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;
}
}
}

View File

@ -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;
}

View File

@ -19,7 +19,7 @@
<div class="red-input-group required w-400">
<mat-form-field floatLabel="always">
<mat-label>{{ 'project-listing.add-edit-dialog.form.template' | translate }}</mat-label>
<mat-select formControlName="ruleSet" style="width: 100%;">
<mat-select formControlName="ruleSet" style="width: 100%;" (valueChange)="ruleSetChanged($event)">
<mat-option
*ngFor="let ruleSet of ruleSets"
[value]="ruleSet.ruleSetId"
@ -36,10 +36,7 @@
<mat-form-field floatLabel="always">
<mat-label>{{ 'project-listing.add-edit-dialog.form.download-file-types.label' | translate }}</mat-label>
<mat-select formControlName="downloadFileTypes" style="width: 100%;" multiple>
<mat-option
*ngFor="let type of downloadTypesEnum"
[value]="type"
>
<mat-option *ngFor="let type of downloadTypesEnum" [value]="type">
{{ humanize(type) }}
</mat-option>
</mat-select>
@ -50,10 +47,7 @@
<mat-form-field floatLabel="always">
<mat-label>{{ 'project-listing.add-edit-dialog.form.report-types.label' | translate }}</mat-label>
<mat-select formControlName="reportTypes" style="width: 100%;" multiple>
<mat-option
*ngFor="let type of reportTypesEnum"
[value]="type"
>
<mat-option *ngFor="let type of reportTypesEnum" [value]="type">
{{ humanize(type) }}
</mat-option>
</mat-select>

View File

@ -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 }
);
}
}
}
}

View File

@ -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;
}