refactor state updates
This commit is contained in:
parent
34b6d96869
commit
f4a71b9b88
@ -182,7 +182,11 @@ export class DossierOverviewBulkActionsComponent {
|
||||
}
|
||||
|
||||
assignToMe() {
|
||||
this._performBulkAction(from(this._fileActionService.assignToMe(this.selectedFiles)));
|
||||
this._fileActionService.assignToMe(this.selectedFiles).then(() => {
|
||||
this._loadingService.start();
|
||||
this.reload.emit();
|
||||
this._loadingService.stop();
|
||||
});
|
||||
}
|
||||
|
||||
assign() {
|
||||
|
||||
@ -88,14 +88,12 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD
|
||||
ngOnInit(): void {
|
||||
if (this.fileStatus) {
|
||||
this.screen = 'dossier-overview';
|
||||
this._setup();
|
||||
return;
|
||||
} else {
|
||||
this.fileStatus = this.appStateService.activeFile;
|
||||
this.screen = 'file-preview';
|
||||
}
|
||||
|
||||
this.fileStatus = this.appStateService.activeFile;
|
||||
this.screen = 'file-preview';
|
||||
this._setup();
|
||||
|
||||
this.addSubscription = this.appStateService.fileChanged$
|
||||
.pipe(filter(file => file.fileId === this.fileStatus?.fileId))
|
||||
.subscribe(fileStatus => {
|
||||
@ -155,13 +153,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD
|
||||
|
||||
setFileUnderApproval($event: MouseEvent) {
|
||||
if (this.appStateService.activeDossier.approverIds.length > 1) {
|
||||
this._fileActionService.assignFile(
|
||||
'approver',
|
||||
$event,
|
||||
this.fileStatus,
|
||||
() => this.actionPerformed.emit('assign-reviewer'),
|
||||
true
|
||||
);
|
||||
this._fileActionService.assignFile('approver', $event, this.fileStatus, () => this.reloadDossiers('assign-reviewer'), true);
|
||||
} else {
|
||||
this.addSubscription = this._fileActionService.setFileUnderApproval(this.fileStatus).subscribe(() => {
|
||||
this.reloadDossiers('set-under-approval');
|
||||
@ -188,7 +180,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnInit, OnD
|
||||
'reviewer',
|
||||
$event,
|
||||
this.fileStatus,
|
||||
() => this.actionPerformed.emit('assign-reviewer'),
|
||||
() => this.reloadDossiers('assign-reviewer'),
|
||||
ignoreDialogChanges
|
||||
);
|
||||
}
|
||||
|
||||
@ -84,11 +84,6 @@ export class AssignReviewerApproverDialogComponent {
|
||||
)
|
||||
.toPromise();
|
||||
}
|
||||
|
||||
for (const file of this.data.files) {
|
||||
file.currentReviewer = selectedUser;
|
||||
file.reviewerName = this.userService.getNameForId(selectedUser);
|
||||
}
|
||||
} catch (error) {
|
||||
this._toaster.error('Failed: ' + error.error ? error.error.message : error);
|
||||
}
|
||||
|
||||
@ -43,22 +43,28 @@ export class FileActionService {
|
||||
}
|
||||
|
||||
async assignToMe(fileStatus?: FileStatusWrapper | FileStatusWrapper[], callback?: Function) {
|
||||
if (!isArray(fileStatus)) {
|
||||
fileStatus = [fileStatus];
|
||||
}
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
if (!isArray(fileStatus)) {
|
||||
fileStatus = [fileStatus];
|
||||
}
|
||||
|
||||
const atLeastOneFileHasReviewer = fileStatus.reduce((acc, fs) => acc || !!fs.currentReviewer, false);
|
||||
if (atLeastOneFileHasReviewer) {
|
||||
const data = new ConfirmationDialogInput({
|
||||
title: _('confirmation-dialog.assign-file-to-me.title'),
|
||||
question: _('confirmation-dialog.assign-file-to-me.question')
|
||||
});
|
||||
this._dialogService.openDialog('confirm', null, data, async () => {
|
||||
await this._assignReviewerToCurrentUser(fileStatus, callback);
|
||||
});
|
||||
} else {
|
||||
await this._assignReviewerToCurrentUser(fileStatus, callback);
|
||||
}
|
||||
const atLeastOneFileHasReviewer = fileStatus.reduce((acc, fs) => acc || !!fs.currentReviewer, false);
|
||||
if (atLeastOneFileHasReviewer) {
|
||||
const data = new ConfirmationDialogInput({
|
||||
title: _('confirmation-dialog.assign-file-to-me.title'),
|
||||
question: _('confirmation-dialog.assign-file-to-me.question')
|
||||
});
|
||||
this._dialogService.openDialog('confirm', null, data, () => {
|
||||
this._assignReviewerToCurrentUser(fileStatus, callback)
|
||||
.then(() => resolve())
|
||||
.catch(() => reject());
|
||||
});
|
||||
} else {
|
||||
this._assignReviewerToCurrentUser(fileStatus, callback)
|
||||
.then(() => resolve())
|
||||
.catch(() => reject());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setFileUnderApproval(fileStatus: FileStatusWrapper | FileStatusWrapper[], approverId?: string) {
|
||||
@ -111,7 +117,6 @@ export class FileActionService {
|
||||
const files = file ? [file] : [this._appStateService.activeFile];
|
||||
const data = { mode, files, ignoreChanged };
|
||||
this._dialogService.openDialog('assignFile', $event, data, async () => {
|
||||
await this._appStateService.reloadActiveDossierFiles();
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
@ -129,7 +134,6 @@ export class FileActionService {
|
||||
this._userService.currentUser.id
|
||||
)
|
||||
.toPromise();
|
||||
await this._appStateService.reloadActiveDossierFiles();
|
||||
if (callback) {
|
||||
await callback();
|
||||
}
|
||||
|
||||
@ -681,6 +681,8 @@ export class AppStateService {
|
||||
this._userService.getNameForId(file.currentReviewer),
|
||||
this._appState.fileAttributesConfig[dossier.dossierTemplateId]
|
||||
);
|
||||
fileStatusWrapper.lastOpened =
|
||||
fileStatusWrapper.fileId === this._userPreferenceService.getLastOpenedFileForDossier(dossier.dossierId);
|
||||
if (JSON.stringify(oldFile) !== JSON.stringify(fileStatusWrapper)) {
|
||||
fileStatusChangedEvent.push(fileStatusWrapper);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user