update dialogs

This commit is contained in:
Dan Percic 2021-06-23 21:22:20 +03:00
parent b556c0f982
commit f5c42fe771
11 changed files with 73 additions and 107 deletions

View File

@ -40,18 +40,16 @@ export class DossierTemplateActionsComponent {
);
}
openDeleteDossierTemplateDialog($event: any) {
this._dialogService.openDeleteDossierTemplateDialog(
$event,
this.dossierTemplate,
async () => {
await this._appStateService.loadAllDossierTemplates();
await this._appStateService.loadDictionaryData();
await this._router.navigate(['main', 'admin']);
if (this.loadDossierTemplatesData) {
this.loadDossierTemplatesData.emit();
}
openDeleteDossierTemplateDialog($event?: MouseEvent) {
$event?.stopPropagation();
this._dialogService.openDeleteDossierTemplateDialog(this.dossierTemplate, async () => {
await this._appStateService.loadAllDossierTemplates();
await this._appStateService.loadDictionaryData();
await this._router.navigate(['main', 'admin']);
if (this.loadDossierTemplatesData) {
this.loadDossierTemplatesData.emit();
}
);
});
}
}

View File

@ -115,7 +115,7 @@ export class AddEditDossierTemplateDialogComponent {
.toPromise();
await this._appStateService.loadAllDossierTemplates();
await this._appStateService.loadDictionaryData();
this.dialogRef.close({ dossierTemplate });
this.dialogRef.close(dossierTemplate);
}
private _applyValidityIntervalConstraints(value): boolean {

View File

@ -22,14 +22,14 @@ export class EditColorDialogComponent {
private readonly _dictionaryControllerService: DictionaryControllerService,
private readonly _notificationService: NotificationService,
private readonly _translateService: TranslateService,
public dialogRef: MatDialogRef<EditColorDialogComponent>,
private readonly _dialogRef: MatDialogRef<EditColorDialogComponent>,
@Inject(MAT_DIALOG_DATA)
public data: { colors: Colors; colorKey: string; dossierTemplateId: string }
private readonly _data: { colors: Colors; colorKey: string; dossierTemplateId: string }
) {
this.colors = data.colors;
this.colorKey = data.colorKey;
this._dossierTemplateId = data.dossierTemplateId;
this._initialColor = data.colors[this.colorKey];
this.colors = _data.colors;
this.colorKey = _data.colorKey;
this._dossierTemplateId = _data.dossierTemplateId;
this._initialColor = _data.colors[this.colorKey];
this.colorForm = this._formBuilder.group({
color: [this.colors[this.colorKey], [Validators.required, Validators.minLength(7)]]
@ -50,7 +50,7 @@ export class EditColorDialogComponent {
await this._dictionaryControllerService
.setColors(colors, this._dossierTemplateId)
.toPromise();
this.dialogRef.close(true);
this._dialogRef.close(true);
this._notificationService.showToastNotification(
this._translateService.instant('edit-color-dialog.success', {
color: this._translateService.instant(

View File

@ -28,25 +28,17 @@ export class DefaultColorsScreenComponent extends BaseListingComponent<{
protected readonly _injector: Injector
) {
super(_injector);
this._appStateService.activateDossierTemplate(
_activatedRoute.snapshot.params.dossierTemplateId
);
_appStateService.activateDossierTemplate(_activatedRoute.snapshot.params.dossierTemplateId);
this._loadColors();
}
async loadDossierTemplatesData(): Promise<void> {
await this._appStateService.loadAllDossierTemplates();
}
openEditColorDialog($event: any, color: { key: string; value: string }) {
$event.stopPropagation();
this._dialogService.openEditColorsDialog(
this._colorsObj,
color.key,
this._appStateService.activeDossierTemplateId,
async () => {
this._loadColors();
}
async () => this._loadColors()
);
}

View File

@ -30,21 +30,16 @@
</div>
<span class="all-caps-label">
{{
'dictionary-listing.table-header.title'
| translate: { length: displayedEntities.length }
}}
{{ tableHeader }}
</span>
<ng-container *ngIf="areSomeEntitiesSelected && !loading">
<redaction-circle-button
(action)="openDeleteDictionariesDialog($event)"
*ngIf="permissionsService.isAdmin()"
icon="red:trash"
tooltip="dictionary-listing.bulk.delete"
type="dark-bg"
></redaction-circle-button>
</ng-container>
<redaction-circle-button
(action)="openDeleteDictionariesDialog($event)"
*ngIf="areSomeEntitiesSelected && !loading && permissionsService.isAdmin()"
icon="red:trash"
tooltip="dictionary-listing.bulk.delete"
type="dark-bg"
></redaction-circle-button>
<mat-spinner *ngIf="loading" diameter="15"></mat-spinner>
@ -160,25 +155,21 @@
></redaction-annotation-icon>
</div>
<div class="actions-container">
<div class="actions-container" *ngIf="permissionsService.isAdmin()">
<div class="action-buttons">
<redaction-circle-button
(action)="openDeleteDictionariesDialog($event, [dict.type])"
*ngIf="permissionsService.isAdmin()"
icon="red:trash"
tooltip="dictionary-listing.action.delete"
type="dark-bg"
>
</redaction-circle-button>
></redaction-circle-button>
<redaction-circle-button
(action)="openAddEditDictionaryDialog($event, dict)"
*ngIf="permissionsService.isAdmin()"
icon="red:edit"
tooltip="dictionary-listing.action.edit"
type="dark-bg"
>
</redaction-circle-button>
></redaction-circle-button>
</div>
</div>
<div class="scrollbar-placeholder"></div>

View File

@ -9,6 +9,7 @@ import { ActivatedRoute } from '@angular/router';
import { AdminDialogService } from '../../services/admin-dialog.service';
import { BaseListingComponent } from '@shared/base/base-listing.component';
import { TypeValueWrapper } from '../../../../models/file/type-value.wrapper';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'redaction-dictionary-listing-screen',
@ -31,6 +32,7 @@ export class DictionaryListingScreenComponent
private readonly _dictionaryControllerService: DictionaryControllerService,
private readonly _activatedRoute: ActivatedRoute,
private readonly _appStateService: AppStateService,
private readonly _translateService: TranslateService,
readonly permissionsService: PermissionsService,
protected readonly _injector: Injector
) {
@ -40,6 +42,12 @@ export class DictionaryListingScreenComponent
);
}
get tableHeader(): string {
return this._translateService.instant('dictionary-listing.table-header.title', {
length: this.displayedEntities.length
});
}
ngOnInit(): void {
this._loadDictionaryData();
}
@ -47,7 +55,6 @@ export class DictionaryListingScreenComponent
openDeleteDictionariesDialog($event?: MouseEvent, types = this.selectedEntitiesIds) {
$event?.stopPropagation();
this._dialogService.openDeleteDictionariesDialog(
$event,
types,
this._appStateService.activeDossierTemplateId,
async () => {
@ -77,17 +84,14 @@ export class DictionaryListingScreenComponent
private _loadDictionaryData() {
const appStateDictionaryData =
this._appStateService.dictionaryData[this._appStateService.activeDossierTemplateId];
this.allEntities = Object.keys(appStateDictionaryData)
.map(key => appStateDictionaryData[key])
.filter(d => !d.virtual);
this.allEntities = Object.values(appStateDictionaryData).filter(d => !d.virtual);
this.displayedEntities = [...this.allEntities];
const dataObs = this.allEntities.map(dict =>
this._dictionaryControllerService
.getDictionaryForType(this._appStateService.activeDossierTemplateId, dict.type)
.pipe(
tap(values => {
dict.entries = values.entries ? values.entries : [];
}),
tap(values => (dict.entries = values.entries ?? [])),
catchError(() => {
console.log('error');
dict.entries = [];
@ -95,24 +99,24 @@ export class DictionaryListingScreenComponent
})
)
);
forkJoin(dataObs)
.pipe(defaultIfEmpty(null))
.subscribe(() => {
this._calculateData();
});
.subscribe(() => this._calculateData());
}
private _calculateData() {
this.chartData = [];
for (const dict of this.allEntities) {
this.chartData.push({
value: dict.entries ? dict.entries.length : 0,
color: dict.hexColor,
label: dict.label,
key: dict.type
});
}
private _calculateData(): void {
this.chartData = this.allEntities.map(dict => this._toChartConfig(dict));
this.chartData.sort((a, b) => (a.label < b.label ? -1 : 1));
this.viewReady = true;
}
private _toChartConfig(dict: TypeValueWrapper): DoughnutChartConfig {
return {
value: dict.entries ? dict.entries.length : 0,
color: dict.hexColor,
label: dict.label,
key: dict.type
};
}
}

View File

@ -10,8 +10,7 @@
tooltip="dictionary-overview.action.delete"
tooltipPosition="below"
type="dark-bg"
>
</redaction-circle-button>
></redaction-circle-button>
<redaction-circle-button
(action)="openEditDictionaryDialog($event)"
@ -20,8 +19,7 @@
tooltip="dictionary-overview.action.edit"
tooltipPosition="below"
type="dark-bg"
>
</redaction-circle-button>
></redaction-circle-button>
<redaction-circle-button
(action)="download()"

View File

@ -64,14 +64,15 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple
);
}
openDeleteDictionaryDialog($event: any) {
openDeleteDictionaryDialog($event?: MouseEvent) {
$event?.stopPropagation();
this._dialogService.openDeleteDictionariesDialog(
$event,
[this.dictionary.type],
this.dictionary.dossierTemplateId,
async () => {
await this._appStateService.loadDictionaryData();
this._router.navigate([
await this._router.navigate([
'/main',
'admin',
'dossier-templates',

View File

@ -36,8 +36,8 @@ export class DossierTemplatesListingScreenComponent
openDeleteTemplatesDialog($event?: MouseEvent) {
$event?.stopPropagation();
this._dialogService.openBulkDeleteDossierTemplatesDialog(
$event,
this.selectedEntitiesIds,
async () => {
this.selectedEntitiesIds = [];

View File

@ -7,20 +7,16 @@ import {
DossierTemplateModel,
FileAttributeConfig,
FileAttributesConfig,
FileManagementControllerService,
ManualRedactionControllerService,
SMTPConfigurationModel,
TypeValue,
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';
@ -44,22 +40,15 @@ const dialogConfig = {
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
private readonly _dictionaryControllerService: DictionaryControllerService
) {}
openDeleteDictionariesDialog(
$event: MouseEvent,
dictionaryTypes: string[],
dossierTemplateId: string,
cb?: Function
cb?: () => void
): MatDialogRef<ConfirmationDialogComponent> {
$event.stopPropagation();
const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig);
ref.afterClosed().subscribe(async result => {
if (result) {
@ -73,11 +62,9 @@ export class AdminDialogService {
}
openDeleteDossierTemplateDialog(
$event: MouseEvent,
dossierTemplate: DossierTemplateModel,
cb?: Function
cb?: () => void
): MatDialogRef<ConfirmationDialogComponent> {
$event.stopPropagation();
const ref = this._dialog.open(ConfirmationDialogComponent, dialogConfig);
ref.afterClosed().subscribe(async result => {
if (result) {
@ -88,11 +75,9 @@ export class AdminDialogService {
}
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) {
@ -105,7 +90,7 @@ export class AdminDialogService {
openAddEditDictionaryDialog(
dictionary: TypeValueWrapper,
dossierTemplateId: string,
cb?: Function
cb?: (newDictionary: TypeValue | null) => void
): MatDialogRef<AddEditDictionaryDialogComponent> {
const ref = this._dialog.open(AddEditDictionaryDialogComponent, {
...dialogConfig,
@ -113,10 +98,9 @@ export class AdminDialogService {
autoFocus: true
});
ref.afterClosed().subscribe(result => {
if (result && cb) {
cb(result);
}
ref.afterClosed().subscribe((newDictionary: TypeValue) => {
if (newDictionary && cb) cb(newDictionary);
else if (cb) cb(null);
});
return ref;
@ -126,7 +110,7 @@ export class AdminDialogService {
colors: Colors,
colorKey: string,
dossierTemplateId: string,
cb?: Function
cb?: (result: boolean) => void
): MatDialogRef<EditColorDialogComponent> {
const ref = this._dialog.open(EditColorDialogComponent, {
...dialogConfig,
@ -134,7 +118,7 @@ export class AdminDialogService {
autoFocus: true
});
ref.afterClosed().subscribe(result => {
ref.afterClosed().subscribe((result: boolean) => {
if (result && cb) {
cb(result);
}

View File

@ -17,7 +17,7 @@ export type ScreenName =
providedIn: 'root'
})
export class SortingService {
private _options: { [key: string]: SortingOption } = {
private readonly _options: { [key: string]: SortingOption } = {
'dossier-listing': { column: 'dossier.dossierName', order: 'asc' },
'dossier-overview': { column: 'filename', order: 'asc' },
'dictionary-listing': { column: 'label', order: 'asc' },
@ -26,8 +26,6 @@ export class SortingService {
'file-attributes-listing': { column: 'label', order: 'asc' }
};
constructor() {}
toggleSort(screen: ScreenName, column: string) {
if (this._options[screen].column === column) {
const currentOrder = this._options[screen].order;