red-ui/apps/red-ui/src/app/modules/admin/services/admin-dialog.service.ts
2021-06-24 11:27:05 +03:00

280 lines
8.9 KiB
TypeScript

import { Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import {
Colors,
DictionaryControllerService,
DossierTemplateControllerService,
DossierTemplateModel,
FileAttributeConfig,
FileAttributesConfig,
FileManagementControllerService,
ManualRedactionControllerService,
SMTPConfigurationModel,
User
} from '@redaction/red-ui-http';
import { AddEditFileAttributeDialogComponent } from '../dialogs/add-edit-file-attribute-dialog/add-edit-file-attribute-dialog.component';
import { AddEditDictionaryDialogComponent } from '../dialogs/add-edit-dictionary-dialog/add-edit-dictionary-dialog.component';
import { AddEditDossierTemplateDialogComponent } from '../dialogs/add-edit-dossier-template-dialog/add-edit-dossier-template-dialog.component';
import { NotificationService } from '@services/notification.service';
import { ConfirmationDialogComponent } from '@shared/dialogs/confirmation-dialog/confirmation-dialog.component';
import { AppStateService } from '@state/app-state.service';
import { ConfirmDeleteFileAttributeDialogComponent } from '../dialogs/confirm-delete-file-attribute-dialog/confirm-delete-file-attribute-dialog.component';
import { EditColorDialogComponent } from '../dialogs/edit-color-dialog/edit-color-dialog.component';
import { TranslateService } from '@ngx-translate/core';
import { SmtpAuthDialogComponent } from '../dialogs/smtp-auth-dialog/smtp-auth-dialog.component';
import { AddEditUserDialogComponent } from '../dialogs/add-edit-user-dialog/add-edit-user-dialog.component';
import { ConfirmDeleteUsersDialogComponent } from '../dialogs/confirm-delete-users-dialog/confirm-delete-users-dialog.component';
import { FileAttributesCsvImportDialogComponent } from '../dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component';
import { TypeValueWrapper } from '../../../models/file/type-value.wrapper';
const largeDialogConfig = {
width: '90vw',
maxWidth: '90vw',
maxHeight: '90vh',
autoFocus: false
};
const dialogConfig = {
width: '662px',
maxWidth: '90vw',
autoFocus: false
};
@Injectable()
export class AdminDialogService {
constructor(
private readonly _dialog: MatDialog,
private readonly _translateService: TranslateService,
private readonly _appStateService: AppStateService,
private readonly _dossierTemplateControllerService: DossierTemplateControllerService,
private readonly _dictionaryControllerService: DictionaryControllerService,
private readonly _fileManagementControllerService: FileManagementControllerService,
private readonly _notificationService: NotificationService,
private readonly _manualRedactionControllerService: ManualRedactionControllerService
) {}
openDeleteDictionariesDialog(
$event: MouseEvent,
dictionaryTypes: string[],
dossierTemplateId: string,
cb?: Function
): MatDialogRef<ConfirmationDialogComponent> {
$event.stopPropagation();
const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig);
ref.afterClosed().subscribe(async result => {
if (result) {
await this._dictionaryControllerService
.deleteTypes(dictionaryTypes, dossierTemplateId)
.toPromise();
if (cb) cb();
}
});
return ref;
}
openDeleteDossierTemplateDialog(
$event: MouseEvent,
dossierTemplate: DossierTemplateModel,
cb?: Function
): MatDialogRef<ConfirmationDialogComponent> {
$event.stopPropagation();
const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig);
ref.afterClosed().subscribe(async result => {
if (result) {
if (cb) await cb();
}
});
return ref;
}
openBulkDeleteDossierTemplatesDialog(
$event: MouseEvent,
dossierTemplateIds: string[],
cb?: Function
): MatDialogRef<ConfirmationDialogComponent> {
$event.stopPropagation();
const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig);
ref.afterClosed().subscribe(async result => {
if (result) {
if (cb) await cb();
}
});
return ref;
}
openAddEditDictionaryDialog(
dictionary: TypeValueWrapper,
dossierTemplateId: string,
cb?: Function
): MatDialogRef<AddEditDictionaryDialogComponent> {
const ref = this._dialog.open(AddEditDictionaryDialogComponent, {
...dialogConfig,
data: { dictionary, dossierTemplateId },
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openEditColorsDialog(
colors: Colors,
colorKey: string,
dossierTemplateId: string,
cb?: Function
): MatDialogRef<EditColorDialogComponent> {
const ref = this._dialog.open(EditColorDialogComponent, {
...dialogConfig,
data: { colors, colorKey, dossierTemplateId },
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openAddEditDossierTemplateDialog(
dossierTemplate: DossierTemplateModel,
cb?: Function
): MatDialogRef<AddEditDossierTemplateDialogComponent> {
const ref = this._dialog.open(AddEditDossierTemplateDialogComponent, {
...dialogConfig,
width: '900px',
data: dossierTemplate,
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openImportFileAttributeCSVDialog(
csv: File,
dossierTemplateId: string,
existingConfiguration: FileAttributesConfig,
cb?: Function
): MatDialogRef<FileAttributesCsvImportDialogComponent> {
const ref = this._dialog.open(FileAttributesCsvImportDialogComponent, {
...largeDialogConfig,
data: { csv, dossierTemplateId, existingConfiguration }
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openAddEditFileAttributeDialog(
fileAttribute: FileAttributeConfig,
dossierTemplateId: string,
cb?: Function
): MatDialogRef<AddEditFileAttributeDialogComponent> {
const ref = this._dialog.open(AddEditFileAttributeDialogComponent, {
...dialogConfig,
data: { fileAttribute, dossierTemplateId },
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openConfirmDeleteFileAttributeDialog(
fileAttribute: FileAttributeConfig,
dossierTemplateId: string,
cb?: Function
): MatDialogRef<ConfirmDeleteFileAttributeDialogComponent> {
const ref = this._dialog.open(ConfirmDeleteFileAttributeDialogComponent, {
...dialogConfig,
data: fileAttribute,
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openSMTPAuthConfigDialog(
smtpConfig: SMTPConfigurationModel,
cb?: Function
): MatDialogRef<SmtpAuthDialogComponent> {
const ref = this._dialog.open(SmtpAuthDialogComponent, {
...dialogConfig,
data: smtpConfig,
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (cb) {
cb(result);
}
});
return ref;
}
openAddEditUserDialog(user?: User, cb?: Function): MatDialogRef<AddEditUserDialogComponent> {
const ref = this._dialog.open(AddEditUserDialogComponent, {
...dialogConfig,
data: user,
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
openConfirmDeleteUsersDialog(
users: User[],
cb?: Function
): MatDialogRef<ConfirmDeleteUsersDialogComponent> {
const ref = this._dialog.open(ConfirmDeleteUsersDialogComponent, {
...dialogConfig,
data: users,
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
});
return ref;
}
}