renamed forms to "form"

This commit is contained in:
Edi Cziszter 2021-11-19 11:06:32 +02:00
parent 35385db948
commit 195cb571f6
9 changed files with 63 additions and 64 deletions

View File

@ -39,14 +39,10 @@ export class NotificationsComponent extends AutoUnsubscribe implements OnInit {
) {
super();
this.notifications$ = this._notifications$.asObservable().pipe(shareLast());
this.groupedNotifications$ = this._groupedNotifications$;
this.groupedNotifications$ = this.notifications$.pipe(map(notifications => this._groupNotifications(notifications)));
this.hasUnreadNotifications$ = this._hasUnreadNotifications$;
}
async ngOnInit(): Promise<void> {
await this._loadData();
}
async ngOnInit(): Promise<void> {
await this._loadData();

View File

@ -1,5 +1,5 @@
<section class="dialog">
<form (submit)="saveDossier()" [formGroup]="dossierForm">
<form (submit)="saveDossier()" [formGroup]="form">
<div class="dialog-header heading-l" translate="add-dossier-dialog.header-new"></div>
<div class="dialog-content">

View File

@ -16,7 +16,7 @@ import { ReportTemplateService } from '@services/report-template.service';
export class AddDossierDialogComponent {
readonly iconButtonTypes = IconButtonTypes;
readonly dossierForm: FormGroup;
readonly form: FormGroup;
hasDueDate = false;
downloadTypes: { key: DownloadFileType; label: string }[] = ['ORIGINAL', 'PREVIEW', 'REDACTED'].map((type: DownloadFileType) => ({
key: type,
@ -33,7 +33,7 @@ export class AddDossierDialogComponent {
readonly dialogRef: MatDialogRef<AddDossierDialogComponent>,
) {
this._getDossierTemplates();
this.dossierForm = this._getForm();
this.form = this._getForm();
}
private _getForm(): FormGroup {
@ -58,19 +58,19 @@ export class AddDossierDialogComponent {
}
get reportTemplateIdsLength() {
return this.dossierForm.controls['reportTemplateIds']?.value?.length || 0;
return this.form.controls['reportTemplateIds']?.value?.length || 0;
}
get downloadFileTypesLength() {
return this.dossierForm.controls['downloadFileTypes']?.value?.length || 0;
return this.form.controls['downloadFileTypes']?.value?.length || 0;
}
get disabled() {
if (this.hasDueDate && this.dossierForm.get('dueDate').value === null) {
if (this.hasDueDate && this.form.get('dueDate').value === null) {
return true;
}
return this.dossierForm.invalid;
return this.form.invalid;
}
reportTemplateValueMapper = (reportTemplate: IReportTemplate) => reportTemplate.templateId;
@ -90,7 +90,7 @@ export class AddDossierDialogComponent {
this.availableReportTypes =
(await this._reportTemplateController.getAvailableReportTemplates(dossierTemplate.dossierTemplateId).toPromise()) || [];
// update dropdown values
this.dossierForm.patchValue(
this.form.patchValue(
{
downloadFileTypes: dossierTemplate.downloadFileTypes,
reportTemplateIds: [], // TODO DEFAULT
@ -99,7 +99,7 @@ export class AddDossierDialogComponent {
);
} else {
this.availableReportTypes = [];
this.dossierForm.patchValue(
this.form.patchValue(
{
downloadFileTypes: [],
reportTemplateIds: [],
@ -121,14 +121,14 @@ export class AddDossierDialogComponent {
private _formToObject(): IDossierRequest {
return {
dossierName: this.dossierForm.get('dossierName').value,
description: this.dossierForm.get('description').value,
dueDate: this.hasDueDate ? this.dossierForm.get('dueDate').value : undefined,
dossierTemplateId: this.dossierForm.get('dossierTemplateId').value,
downloadFileTypes: this.dossierForm.get('downloadFileTypes').value,
reportTemplateIds: this.dossierForm.get('reportTemplateIds').value,
watermarkEnabled: this.dossierForm.get('watermarkEnabled').value,
watermarkPreviewEnabled: this.dossierForm.get('watermarkPreviewEnabled').value,
dossierName: this.form.get('dossierName').value,
description: this.form.get('description').value,
dueDate: this.hasDueDate ? this.form.get('dueDate').value : undefined,
dossierTemplateId: this.form.get('dossierTemplateId').value,
downloadFileTypes: this.form.get('downloadFileTypes').value,
reportTemplateIds: this.form.get('reportTemplateIds').value,
watermarkEnabled: this.form.get('watermarkEnabled').value,
watermarkPreviewEnabled: this.form.get('watermarkPreviewEnabled').value,
};
}
}

View File

@ -21,7 +21,7 @@ class DialogData {
styleUrls: ['./assign-reviewer-approver-dialog.component.scss'],
})
export class AssignReviewerApproverDialogComponent {
form: FormGroup;
readonly form: FormGroup;
dossier: Dossier;
constructor(
@ -36,7 +36,7 @@ export class AssignReviewerApproverDialogComponent {
@Inject(MAT_DIALOG_DATA) readonly data: DialogData,
) {
this.dossier = this._dossiersService.find(this.data.files[0].dossierId);
this._loadData();
this.form = this._getForm();
}
get selectedUser(): string {
@ -102,20 +102,27 @@ export class AssignReviewerApproverDialogComponent {
* the id of the current reviewer of the files list if there is only one reviewer for all of them;
* or the id of the current user
**/
private _loadData() {
private get _uniqueReviewers(): Set<string> {
const uniqueReviewers = new Set<string>();
for (const file of this.data.files) {
if (file.currentReviewer) {
uniqueReviewers.add(file.currentReviewer);
}
}
let user: string = uniqueReviewers.size === 1 ? uniqueReviewers.values().next().value : this.userService.currentUser.id;
return uniqueReviewers;
}
private get _user(): string {
let user: string = this._uniqueReviewers.size === 1 ? this._uniqueReviewers.values().next().value : this.userService.currentUser.id;
user = this.userOptions.indexOf(user) >= 0 ? user : this.userOptions[0];
return user;
}
this.form = this._formBuilder.group({
private _getForm(): FormGroup {
return this._formBuilder.group({
// Allow a null reviewer if a previous reviewer exists (= it's not the first assignment) & current user is allowed to unassign
user: [user, this._canUnassignFiles && !user ? Validators.required : null],
user: [this._user, this._canUnassignFiles && !this._user ? Validators.required : null],
});
}
}

View File

@ -1,5 +1,5 @@
<section class="dialog">
<form (submit)="save()" [formGroup]="legalBasisForm">
<form (submit)="save()" [formGroup]="form">
<div class="dialog-header heading-l" translate="change-legal-basis-dialog.header"></div>
<div class="dialog-content">
@ -18,7 +18,7 @@
<div class="iqser-input-group w-400">
<label translate="change-legal-basis-dialog.content.legalBasis"></label>
<input [value]="legalBasisForm.get('reason').value?.legalBasis" disabled type="text" />
<input [value]="form.get('reason').value?.legalBasis" disabled type="text" />
</div>
<div [class.required]="!isDocumentAdmin" class="iqser-input-group w-300">
@ -28,7 +28,7 @@
</div>
<div class="dialog-actions">
<button [disabled]="!legalBasisForm.valid || !changed" color="primary" mat-flat-button type="submit">
<button [disabled]="!form.valid || !changed" color="primary" mat-flat-button type="submit">
{{ 'change-legal-basis-dialog.actions.save' | translate }}
</button>
<div class="all-caps-label cancel" mat-dialog-close translate="change-legal-basis-dialog.actions.cancel"></div>

View File

@ -17,7 +17,7 @@ export interface LegalBasisOption {
templateUrl: './change-legal-basis-dialog.component.html',
})
export class ChangeLegalBasisDialogComponent implements OnInit {
legalBasisForm: FormGroup;
form: FormGroup = this._getForm();
isDocumentAdmin: boolean;
legalOptions: LegalBasisOption[] = [];
@ -31,17 +31,10 @@ export class ChangeLegalBasisDialogComponent implements OnInit {
) {}
get changed(): boolean {
return this.legalBasisForm.get('reason').value.legalBasis !== this._data.annotations[0].legalBasis;
return this.form.get('reason').value.legalBasis !== this._data.annotations[0].legalBasis;
}
async ngOnInit() {
this.isDocumentAdmin = this._permissionsService.isApprover(this._data.dossier);
this.legalBasisForm = this._formBuilder.group({
reason: [null, Validators.required],
comment: this.isDocumentAdmin ? [null] : [null, Validators.required],
});
const data = await this._justificationsService.getForDossierTemplate(this._data.dossier.dossierTemplateId).toPromise();
this.legalOptions = data
@ -52,13 +45,13 @@ export class ChangeLegalBasisDialogComponent implements OnInit {
}))
.sort((a, b) => a.label.localeCompare(b.label));
this.legalBasisForm.patchValue({
this.form.patchValue({
reason: this.legalOptions.find(option => option.legalBasis === this._data.annotations[0].legalBasis),
});
}
private _getForm(): FormGroup {
this.isDocumentAdmin = this._permissionsService.isApprover();
this.isDocumentAdmin = this._permissionsService.isApprover(this._data.dossier);
return this._formBuilder.group({
reason: [null, Validators.required],
comment: this.isDocumentAdmin ? [null] : [null, Validators.required],
@ -67,8 +60,8 @@ export class ChangeLegalBasisDialogComponent implements OnInit {
save() {
this.dialogRef.close({
legalBasis: this.legalBasisForm.get('reason').value.legalBasis,
comment: this.legalBasisForm.get('comment').value,
legalBasis: this.form.get('reason').value.legalBasis,
comment: this.form.get('comment').value,
});
}
}

View File

@ -1,7 +1,7 @@
<section *ngIf="!!documentInfoForm" class="dialog">
<section *ngIf="!!form" class="dialog">
<div class="dialog-header heading-l" translate="document-info.title"></div>
<form (submit)="saveDocumentInfo()" [formGroup]="documentInfoForm">
<form (submit)="saveDocumentInfo()" [formGroup]="form">
<div class="dialog-content">
<div *ngFor="let attr of attributes" class="iqser-input-group w-300">
<label>{{ attr.label }}</label>
@ -9,7 +9,7 @@
</div>
</div>
<div class="dialog-actions">
<button [disabled]="documentInfoForm.invalid" color="primary" mat-flat-button type="submit">
<button [disabled]="form.invalid" color="primary" mat-flat-button type="submit">
{{ 'document-info.save' | translate }}
</button>
</div>

View File

@ -11,8 +11,7 @@ import { DossiersService } from '@services/entity-services/dossiers.service';
styleUrls: ['./document-info-dialog.component.scss'],
})
export class DocumentInfoDialogComponent implements OnInit {
documentInfoForm: FormGroup;
file: IFile;
form: FormGroup;
attributes: IFileAttributeConfig[];
private readonly _dossier: Dossier;
@ -25,31 +24,35 @@ export class DocumentInfoDialogComponent implements OnInit {
public dialogRef: MatDialogRef<DocumentInfoDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: IFile,
) {
this.file = this.data;
this._dossier = this._dossiersService.find(this.file.dossierId);
this._dossier = this._dossiersService.find(this.data.dossierId);
}
async ngOnInit() {
this.attributes = (
await this._fileAttributesService.getFileAttributesConfig(this._dossier.dossierTemplateId).toPromise()
).fileAttributeConfigs.filter(attr => attr.editable);
const formConfig = this.attributes.reduce(
(acc, attr) => ({
...acc,
[attr.id]: [this.file.fileAttributes?.attributeIdToValue[attr.id]],
}),
{},
this.form = this._getForm();
}
private _getForm(): FormGroup {
return this._formBuilder.group(
this.attributes.reduce(
(acc, attr) => ({
...acc,
[attr.id]: [this.data.fileAttributes?.attributeIdToValue[attr.id]],
}),
{},
),
);
this.documentInfoForm = this._formBuilder.group(formConfig);
}
async saveDocumentInfo() {
const attributeIdToValue = {
...this.file.fileAttributes?.attributeIdToValue,
...this.documentInfoForm.getRawValue(),
...this.data.fileAttributes?.attributeIdToValue,
...this.form.getRawValue(),
};
await this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.file.dossierId, this.file.fileId).toPromise();
this.file.fileAttributes = { attributeIdToValue };
await this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.data.dossierId, this.data.fileId).toPromise();
this.data.fileAttributes = { attributeIdToValue };
this.dialogRef.close(true);
}
}

View File

@ -62,8 +62,8 @@ export class ManualAnnotationDialogComponent implements OnInit {
private get _redactionDictionaries(): Dictionary[] {
const redactionDictionaries: Dictionary[] = [];
for (const key of Object.keys(this._appStateService.dictionaryData[data.dossier.dossierTemplateId])) {
const dictionaryData = this._appStateService.getDictionary(key, data.dossier.dossierTemplateId);
for (const key of Object.keys(this._appStateService.dictionaryData[this.data.dossier.dossierTemplateId])) {
const dictionaryData = this._appStateService.getDictionary(key, this.data.dossier.dossierTemplateId);
if (!dictionaryData.virtual && dictionaryData.addToDictionaryAction) {
redactionDictionaries.push(dictionaryData);
}