RED-1799 & some refactoring

This commit is contained in:
Adina Țeudan 2021-07-13 15:55:27 +03:00
parent 21b59d9a71
commit f17be15a8a
15 changed files with 101 additions and 245 deletions

View File

@ -107,14 +107,14 @@ export class SmtpConfigScreenComponent implements OnInit {
'smtpAuthConfig',
null,
this.configForm.getRawValue(),
null,
authConfig => {
if (authConfig) {
this.configForm.patchValue(authConfig);
} else if (!skipDisableOnCancel) {
this.configForm.patchValue({ auth: false }, { emitEvent: false });
}
},
false
}
);
}

View File

@ -1,4 +1,4 @@
<ng-container *ngIf="areSomeFilesSelected && !loading">
<ng-container *ngIf="areSomeFilesSelected">
<redaction-circle-button
(action)="delete()"
*ngIf="canDelete"
@ -84,7 +84,3 @@
type="dark-bg"
></redaction-circle-button>
</ng-container>
<ng-container *ngIf="loading">
<mat-spinner diameter="15"></mat-spinner>
</ng-container>

View File

@ -11,6 +11,8 @@ import { FileActionService } from '../../services/file-action.service';
import { from, Observable } from 'rxjs';
import { StatusOverlayService } from '@upload-download/services/status-overlay.service';
import { DossiersDialogService } from '../../services/dossiers-dialog.service';
import { LoadingService } from '../../../../services/loading.service';
import { ConfirmationDialogInput } from '../../../shared/dialogs/confirmation-dialog/confirmation-dialog.component';
@Component({
selector: 'redaction-dossier-overview-bulk-actions',
@ -23,8 +25,6 @@ export class DossierOverviewBulkActionsComponent {
@Output()
reload = new EventEmitter();
loading = false;
constructor(
private readonly _appStateService: AppStateService,
private readonly _userService: UserService,
@ -34,7 +34,8 @@ export class DossierOverviewBulkActionsComponent {
private readonly _permissionsService: PermissionsService,
private readonly _fileActionService: FileActionService,
private readonly _statusOverlayService: StatusOverlayService,
private readonly _changeDetectorRef: ChangeDetectorRef
private readonly _changeDetectorRef: ChangeDetectorRef,
private readonly _loadingService: LoadingService
) {}
get dossier() {
@ -172,15 +173,22 @@ export class DossierOverviewBulkActionsComponent {
}
delete() {
this.loading = true;
this._dialogService.openDeleteFilesDialog(
this._dialogService.openDialog(
'confirm',
null,
this._appStateService.activeDossierId,
this.selectedFileIds,
() => {
new ConfirmationDialogInput({
title: 'confirmation-dialog.delete-file.title',
question: 'confirmation-dialog.delete-file.question'
}),
async () => {
this._loadingService.start();
await this._fileManagementControllerService
.deleteFiles(this.selectedFileIds, this._appStateService.activeDossierId)
.toPromise();
await this._appStateService.reloadActiveDossierFiles();
this.reload.emit();
this.loading = false;
this.selectedFileIds.splice(0, this.selectedFileIds.length);
this._loadingService.stop();
}
);
}
@ -188,7 +196,7 @@ export class DossierOverviewBulkActionsComponent {
setToUnderApproval() {
// If more than 1 approver - show dialog and ask who to assign
if (this._appStateService.activeDossier.approverIds.length > 1) {
this.loading = true;
this._loadingService.start();
const files = this.selectedFileIds.map(fileId =>
this._appStateService.getFileById(this._appStateService.activeDossierId, fileId)
);
@ -198,7 +206,7 @@ export class DossierOverviewBulkActionsComponent {
'approver',
() => {
this.reload.emit();
this.loading = false;
this._loadingService.stop();
},
true
);
@ -241,7 +249,7 @@ export class DossierOverviewBulkActionsComponent {
}
assign() {
this.loading = true;
this._loadingService.start();
const files = this.selectedFileIds.map(fileId =>
this._appStateService.getFileById(this._appStateService.activeDossierId, fileId)
);
@ -250,15 +258,15 @@ export class DossierOverviewBulkActionsComponent {
this._dialogService.openAssignFileToUserDialog(files, mode, () => {
this.reload.emit();
this.loading = false;
this._loadingService.stop();
});
}
private _performBulkAction(obs: Observable<any>) {
this.loading = true;
this._loadingService.start();
obs.subscribe().add(() => {
this.reload.emit();
this.loading = false;
this._loadingService.stop();
});
}
}

View File

@ -30,6 +30,6 @@ export class DocumentInfoComponent {
}
edit() {
this._dialogService.openDocumentInfoDialog(this.file);
this._dialogService.openDialog('document-info', null, this.file);
}
}

View File

@ -23,9 +23,12 @@ export class DossierListingActionsComponent {
private readonly _fileManagementControllerService: FileManagementControllerService
) {}
openEditDossierDialog($event: MouseEvent, dossier: DossierWrapper) {
this._dialogService.openEditDossierDialog($event, dossier, () => {
this.actionPerformed.emit();
openEditDossierDialog($event: MouseEvent, dossierWrapper: DossierWrapper) {
this._dialogService.openDialog('edit-dossier', $event, {
dossierWrapper,
afterSave: () => {
this.actionPerformed.emit();
}
});
}

View File

@ -4,6 +4,9 @@ import { FileStatusWrapper } from '@models/file/file-status.wrapper';
import { AppStateService } from '@state/app-state.service';
import { FileActionService } from '../../services/file-action.service';
import { DossiersDialogService } from '../../services/dossiers-dialog.service';
import { ConfirmationDialogInput } from '../../../shared/dialogs/confirmation-dialog/confirmation-dialog.component';
import { LoadingService } from '../../../../services/loading.service';
import { FileManagementControllerService } from '@redaction/red-ui-http';
@Component({
selector: 'redaction-file-actions',
@ -23,7 +26,9 @@ export class FileActionsComponent implements OnInit {
readonly permissionsService: PermissionsService,
readonly appStateService: AppStateService,
private readonly _dialogService: DossiersDialogService,
private readonly _fileActionService: FileActionService
private readonly _fileActionService: FileActionService,
private readonly _loadingService: LoadingService,
private readonly _fileManagementControllerService: FileManagementControllerService
) {}
get statusBarConfig() {
@ -110,11 +115,22 @@ export class FileActionsComponent implements OnInit {
}
openDeleteFileDialog($event: MouseEvent) {
this._dialogService.openDeleteFilesDialog(
this._dialogService.openDialog(
'confirm',
$event,
this.fileStatus.dossierId,
[this.fileStatus.fileId],
() => this.actionPerformed.emit('delete')
new ConfirmationDialogInput({
title: 'confirmation-dialog.delete-file.title',
question: 'confirmation-dialog.delete-file.question'
}),
async () => {
this._loadingService.start();
await this._fileManagementControllerService
.deleteFiles([this.fileStatus.fileId], this.fileStatus.dossierId)
.toPromise();
await this.appStateService.reloadActiveDossierFiles();
this.actionPerformed.emit('delete');
this._loadingService.stop();
}
);
}

View File

@ -11,12 +11,14 @@ import { TranslateService } from '@ngx-translate/core';
import { EditDossierDictionaryComponent } from './dictionary/edit-dossier-dictionary.component';
import { EditDossierTeamMembersComponent } from './team-members/edit-dossier-team-members.component';
type Section = 'dossier-info' | 'download-package' | 'dossier-dictionary' | 'members';
@Component({
templateUrl: './edit-dossier-dialog.component.html',
styleUrls: ['./edit-dossier-dialog.component.scss']
})
export class EditDossierDialogComponent {
navItems: { key: string; title?: string }[] = [
navItems: { key: Section; title?: string }[] = [
{ key: 'dossier-info', title: 'general-info' },
{ key: 'download-package', title: 'choose-download' },
{ key: 'dossier-dictionary', title: 'dossier-dictionary' },
@ -25,7 +27,7 @@ export class EditDossierDialogComponent {
// { key: 'dossier-attributes' },
// { key: 'report-attributes' }
];
activeNav = 'dossier-info';
activeNav: Section;
dossierWrapper: DossierWrapper;
@ViewChild(EditDossierGeneralInfoComponent)
@ -43,9 +45,14 @@ export class EditDossierDialogComponent {
private readonly _changeRef: ChangeDetectorRef,
private readonly _dialogRef: MatDialogRef<EditDossierDialogComponent>,
@Inject(MAT_DIALOG_DATA)
private readonly _data: { dossierWrapper: DossierWrapper; afterSave: Function }
private readonly _data: {
dossierWrapper: DossierWrapper;
afterSave: Function;
section?: Section;
}
) {
this.dossierWrapper = _data.dossierWrapper;
this.activeNav = _data.section || 'dossier-info';
}
get activeNavItem(): { key: string; title?: string } {
@ -89,7 +96,7 @@ export class EditDossierDialogComponent {
this.activeComponent.revert();
}
changeTab(key: string) {
changeTab(key: Section) {
if (this.activeComponent.changed) {
this._notificationService.showToastNotification(
this._translateService.instant('edit-dossier-dialog.unsaved-changes'),

View File

@ -1,32 +0,0 @@
<section class="dialog">
<div class="dialog-header heading-l" translate="assign-dossier-owner.dialog.title"></div>
<div class="dialog-content no-padding-bottom">
<redaction-team-members-manager
(save)="save($event)"
[dossierWrapper]="data.dossierWrapper"
></redaction-team-members-manager>
</div>
<div class="dialog-actions">
<button
(click)="managerComponent.saveMembers()"
[disabled]="!managerComponent.valid || !managerComponent.changed"
color="primary"
mat-flat-button
>
{{ 'assign-dossier-owner.dialog.save' | translate }}
</button>
<div
class="all-caps-label pointer cancel"
mat-dialog-close
translate="assign-dossier-owner.dialog.cancel"
></div>
</div>
<redaction-circle-button
class="dialog-close"
icon="red:close"
mat-dialog-close
></redaction-circle-button>
</section>

View File

@ -1,8 +0,0 @@
.no-padding-bottom {
padding-bottom: 0;
}
::ng-deep redaction-team-members-manager .members-list {
max-height: 220px;
height: 220px;
}

View File

@ -1,31 +0,0 @@
import { Component, Inject, ViewChild } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { AppStateService } from '@state/app-state.service';
import { NotificationService } from '@services/notification.service';
import { DossierWrapper } from '@state/model/dossier.wrapper';
import { TeamMembersManagerComponent } from '../../components/team-members-manager/team-members-manager.component';
class DialogData {
dossierWrapper?: DossierWrapper;
}
@Component({
selector: 'redaction-team-members-dialog',
templateUrl: './team-members-dialog.component.html',
styleUrls: ['./team-members-dialog.component.scss']
})
export class TeamMembersDialogComponent {
@ViewChild(TeamMembersManagerComponent, { static: true })
managerComponent: TeamMembersManagerComponent;
constructor(
private readonly _notificationService: NotificationService,
private readonly _appStateService: AppStateService,
public dialogRef: MatDialogRef<TeamMembersDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: DialogData
) {}
async save(result) {
this.dialogRef.close(result);
}
}

View File

@ -43,7 +43,6 @@ import { UserPreferenceControllerService } from '@redaction/red-ui-http';
import { EditDossierDictionaryComponent } from './dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component';
import { EditDossierTeamMembersComponent } from './dialogs/edit-dossier-dialog/team-members/edit-dossier-team-members.component';
import { TeamMembersManagerComponent } from './components/team-members-manager/team-members-manager.component';
import { TeamMembersDialogComponent } from './dialogs/team-members-dialog/team-members-dialog.component';
import { ScrollButtonComponent } from './components/scroll-button/scroll-button.component';
import { ChangeLegalBasisDialogComponent } from './dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component';
import { PageExclusionComponent } from './components/page-exclusion/page-exclusion.component';
@ -58,7 +57,6 @@ const screens = [
const dialogs = [
AddDossierDialogComponent,
EditDossierDialogComponent,
TeamMembersDialogComponent,
ManualAnnotationDialogComponent,
ForceRedactionDialogComponent,
RemoveAnnotationsDialogComponent,

View File

@ -196,15 +196,14 @@ export class DossierListingScreenComponent
this._calculateData();
await this._router.navigate([`/main/dossiers/${addResponse.dossier.dossierId}`]);
if (addResponse.addMembers) {
this.openAssignDossierOwnerDialog(null, addResponse.dossier);
this._dialogService.openDialog('edit-dossier', null, {
dossierWrapper: addResponse.dossier,
section: 'members'
});
}
});
}
openAssignDossierOwnerDialog($event: MouseEvent, dossier: DossierWrapper) {
this._dialogService.openAssignTeamMembersDialog($event, dossier);
}
actionPerformed() {
this._calculateData();
}

View File

@ -293,13 +293,23 @@ export class DossierOverviewScreenComponent
}
openEditDossierDialog($event: MouseEvent) {
this._dialogService.openEditDossierDialog($event, this.activeDossier);
this._dialogService.openDialog('edit-dossier', $event, {
dossierWrapper: this.activeDossier
});
}
openAssignDossierMembersDialog(): void {
this._dialogService.openAssignTeamMembersDialog(null, this.activeDossier, () => {
this.reloadDossiers();
});
this._dialogService.openDialog(
'edit-dossier',
null,
{
dossierWrapper: this.activeDossier,
section: 'members'
},
() => {
this.reloadDossiers();
}
);
}
openDossierDictionaryDialog() {

View File

@ -4,12 +4,11 @@ import {
DictionaryControllerService,
DossierTemplateControllerService,
FileManagementControllerService,
FileStatus,
ManualRedactionControllerService
} from '@redaction/red-ui-http';
import { AddDossierDialogComponent } from '../dialogs/add-dossier-dialog/add-dossier-dialog.component';
import { RemoveAnnotationsDialogComponent } from '../dialogs/remove-annotations-dialog/remove-annotations-dialog.component';
import { NotificationService, NotificationType } from '@services/notification.service';
import { NotificationService } from '@services/notification.service';
import { ForceRedactionDialogComponent } from '../dialogs/force-redaction-dialog/force-redaction-dialog.component';
import { AnnotationWrapper } from '@models/file/annotation.wrapper';
import {
@ -28,7 +27,6 @@ import { DossierDictionaryDialogComponent } from '../dialogs/dossier-dictionary-
import { EditDossierDialogComponent } from '../dialogs/edit-dossier-dialog/edit-dossier-dialog.component';
import { FileStatusWrapper } from '../../../models/file/file-status.wrapper';
import { AssignReviewerApproverDialogComponent } from '../dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component';
import { TeamMembersDialogComponent } from '../dialogs/team-members-dialog/team-members-dialog.component';
import { AppConfigService } from '../../app-config/app-config.service';
import { ChangeLegalBasisDialogComponent } from '../dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component';
import { RecategorizeImageDialogComponent } from '../dialogs/recategorize-image-dialog/recategorize-image-dialog.component';
@ -41,7 +39,9 @@ const dialogConfig = {
autoFocus: false
};
type DialogType = 'confirm';
// TODO: Continue refactor
type DialogType = 'confirm' | 'document-info' | 'edit-dossier';
@Injectable()
export class DossiersDialogService extends DialogService<DialogType> {
@ -53,6 +53,14 @@ export class DossiersDialogService extends DialogService<DialogType> {
} = {
confirm: {
component: ConfirmationDialogComponent
},
'document-info': {
component: DocumentInfoDialogComponent,
dialogConfig: { autoFocus: true }
},
'edit-dossier': {
component: EditDossierDialogComponent,
dialogConfig: { ...this._largeDialogConfig, autoFocus: true }
}
};
@ -71,43 +79,6 @@ export class DossiersDialogService extends DialogService<DialogType> {
super(_dialog);
}
openDeleteFilesDialog(
$event: MouseEvent,
dossierId: string,
fileIds: string[],
cb?: Function
): MatDialogRef<ConfirmationDialogComponent> {
$event?.stopPropagation();
const ref = this._dialog.open(ConfirmationDialogComponent, {
...dialogConfig,
data: new ConfirmationDialogInput({
title: 'confirmation-dialog.delete-file.title',
question: 'confirmation-dialog.delete-file.question'
})
});
ref.afterClosed().subscribe(async result => {
if (result) {
try {
await this._fileManagementControllerService
.deleteFiles(fileIds, dossierId)
.toPromise();
await this._appStateService.reloadActiveDossierFiles();
if (cb) cb();
} catch (e) {
this._notificationService.showToastNotification(
this._translateService.instant('delete-files-error'),
null,
NotificationType.ERROR
);
}
}
});
return ref;
}
openManualAnnotationDialog(
$event: ManualRedactionEntryWrapper,
cb?: Function
@ -274,24 +245,6 @@ export class DossiersDialogService extends DialogService<DialogType> {
return ref;
}
openAssignTeamMembersDialog(
$event: MouseEvent,
dossierWrapper: DossierWrapper,
cb?: Function
): MatDialogRef<TeamMembersDialogComponent> {
$event?.stopPropagation();
const ref = this._dialog.open(TeamMembersDialogComponent, {
...dialogConfig,
data: { dossierWrapper }
});
ref.afterClosed().subscribe(result => {
if (cb) {
cb(result);
}
});
return ref;
}
openDossierDictionaryDialog(
$event: MouseEvent,
dossier: DossierWrapper,
@ -358,40 +311,6 @@ export class DossiersDialogService extends DialogService<DialogType> {
return ref;
}
openEditDossierDialog(
$event: MouseEvent,
dossierWrapper: DossierWrapper,
cb?: Function
): MatDialogRef<EditDossierDialogComponent> {
$event.stopPropagation();
return this._dialog.open(EditDossierDialogComponent, {
...dialogConfig,
width: '90vw',
height: '90vh',
autoFocus: true,
data: { dossierWrapper, afterSave: cb }
});
}
openDocumentInfoDialog(
file: FileStatus,
cb?: Function
): MatDialogRef<DocumentInfoDialogComponent> {
const ref = this._dialog.open(DocumentInfoDialogComponent, {
...dialogConfig,
data: file,
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openRemoveAnnotationModal(
$event: MouseEvent,
annotation: AnnotationWrapper,
@ -418,37 +337,4 @@ export class DossiersDialogService extends DialogService<DialogType> {
return ref;
}
openCompareFileConfirmationDialog(
$event: MouseEvent,
fileName: string,
currentDocumentPageCount: number,
compareDocumentPageCount: number,
callback?: Function
): MatDialogRef<ConfirmationDialogComponent> {
$event?.stopPropagation();
const ref = this._dialog.open(ConfirmationDialogComponent, {
...dialogConfig,
data: new ConfirmationDialogInput({
title: 'confirmation-dialog.compare-file.title',
question: 'confirmation-dialog.compare-file.question',
translateParams: {
fileName: fileName,
currentDocumentPageCount,
compareDocumentPageCount
}
})
});
ref.afterClosed().subscribe(result => {
if (result) {
if (callback) {
callback();
}
}
});
return ref;
}
}

View File

@ -33,7 +33,7 @@ export class DialogService<T extends string> {
$event: MouseEvent,
data: any,
cb?: Function,
checkForResult = true
finallyCb?: Function
): MatDialogRef<any> {
const config = this._config[type];
@ -44,9 +44,13 @@ export class DialogService<T extends string> {
data
});
ref.afterClosed().subscribe(async result => {
if ((result || !checkForResult) && cb) {
if (result && cb) {
await cb(result);
}
if (finallyCb) {
await finallyCb(result);
}
});
return ref;
}