use generic service for dossiers

This commit is contained in:
Dan Percic 2021-09-26 23:58:12 +03:00
parent f186f766ec
commit 91efc6fd0e
8 changed files with 65 additions and 52 deletions

View File

@ -29,11 +29,7 @@ interface DossierListItem extends IDossier, IListable {
templateUrl: './trash-screen.component.html', templateUrl: './trash-screen.component.html',
styleUrls: ['./trash-screen.component.scss'], styleUrls: ['./trash-screen.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
providers: [ providers: [...DefaultListingServices, { provide: ListingComponent, useExisting: forwardRef(() => TrashScreenComponent) }]
...DefaultListingServices,
DossiersService,
{ provide: ListingComponent, useExisting: forwardRef(() => TrashScreenComponent) }
]
}) })
export class TrashScreenComponent extends ListingComponent<DossierListItem> implements OnInit { export class TrashScreenComponent extends ListingComponent<DossierListItem> implements OnInit {
readonly circleButtonTypes = CircleButtonTypes; readonly circleButtonTypes = CircleButtonTypes;

View File

@ -1,33 +1,45 @@
import { Injectable } from '@angular/core'; import { Injectable, Injector } from "@angular/core";
import { IDossier, DossierControllerService } from '@redaction/red-ui-http'; import { IDossier } from "@redaction/red-ui-http";
import { EntitiesService, FilterService, SearchService } from "@iqser/common-ui";
import { Dossier } from "@state/model/dossier";
/**
* This should be removed when refactoring is done
* @param injector
* @constructor
*/
const TEMPORARY_INJECTOR = injector =>
Injector.create({
providers: [
{ provide: FilterService, useClass: FilterService },
{ provide: SearchService, useClass: SearchService }
],
parent: injector
});
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class DossiersService { export class DossiersService extends EntitiesService<Dossier, IDossier> {
constructor(private readonly _dossierControllerService: DossierControllerService) {} constructor(protected readonly _injector: Injector) {
super(TEMPORARY_INJECTOR(_injector), 'dossier');
}
createOrUpdate(dossier: IDossier): Promise<IDossier> { createOrUpdate(dossier: IDossier): Promise<IDossier> {
return this._dossierControllerService.createOrUpdateDossier(dossier).toPromise(); return this.post(dossier).toPromise();
}
delete(dossierId: string): Promise<unknown> {
return this._dossierControllerService.deleteDossier(dossierId).toPromise();
}
getAll(): Promise<IDossier[]> {
return this._dossierControllerService.getDossiers().toPromise();
} }
getDeleted(): Promise<IDossier[]> { getDeleted(): Promise<IDossier[]> {
return this._dossierControllerService.getDeletedDossiers().toPromise(); return this.getAll<IDossier>('deleted-dossiers').toPromise();
} }
restore(dossierIds: Array<string>): Promise<unknown> { restore(dossierIds: Array<string>): Promise<unknown> {
return this._dossierControllerService.restoreDossiers(dossierIds).toPromise(); const body = dossierIds.map<[string, string]>(id => ['dossierId', id]);
return this.post(body, 'deleted-dossiers/restore').toPromise();
} }
hardDelete(dossierIds: Array<string>): Promise<unknown> { hardDelete(dossierIds: Array<string>): Promise<unknown> {
return this._dossierControllerService.hardDeleteDossiers(dossierIds).toPromise(); const body = dossierIds.map<[string, string]>(id => ['dossierId', id]);
return this.delete(body, 'deleted-dossiers/hard-delete').toPromise();
} }
} }

View File

@ -216,7 +216,7 @@ export class AppStateService {
} }
async loadAllDossiers(emitEvents: boolean = true) { async loadAllDossiers(emitEvents: boolean = true) {
const dossiers = await this._dossiersService.getAll(); const dossiers = await this._dossiersService.get().toPromise();
if (!dossiers) { if (!dossiers) {
return; return;
} }
@ -334,13 +334,16 @@ export class AppStateService {
} }
deleteDossier(dossier: Dossier) { deleteDossier(dossier: Dossier) {
return this._dossiersService.delete(dossier.id).then( return this._dossiersService
() => { .delete(dossier.id)
const index = this.allDossiers.findIndex(p => p.id === dossier.id); .toPromise()
this._appState.dossiers.splice(index, 1); .then(
}, () => {
() => this._toaster.error(_('dossier-listing.delete.delete-failed'), { params: dossier }) const index = this.allDossiers.findIndex(p => p.id === dossier.id);
); this._appState.dossiers.splice(index, 1);
},
() => this._toaster.error(_('dossier-listing.delete.delete-failed'), { params: dossier })
);
} }
async createOrUpdateDossier(dossier: IDossier) { async createOrUpdateDossier(dossier: IDossier) {

View File

@ -3,7 +3,6 @@ import { Dictionary, DossierStatus, DownloadFileType, IDossier, List } from '@re
import { IListable } from '@iqser/common-ui'; import { IListable } from '@iqser/common-ui';
export class Dossier implements IDossier, IListable { export class Dossier implements IDossier, IListable {
readonly id: string;
readonly dossierId: string; readonly dossierId: string;
readonly ownerId: string; readonly ownerId: string;
readonly memberIds: List; readonly memberIds: List;
@ -37,7 +36,6 @@ export class Dossier implements IDossier, IListable {
type?: Dictionary; type?: Dictionary;
constructor(dossier: IDossier, private _files: File[] = []) { constructor(dossier: IDossier, private _files: File[] = []) {
this.id = dossier.dossierId;
this.dossierId = dossier.dossierId; this.dossierId = dossier.dossierId;
this.approverIds = dossier.approverIds; this.approverIds = dossier.approverIds;
this.date = dossier.date; this.date = dossier.date;
@ -59,6 +57,14 @@ export class Dossier implements IDossier, IListable {
this._recomputeFileStatus(); this._recomputeFileStatus();
} }
get id(): string {
return this.dossierId;
}
get routerLink(): string {
return `/main/dossiers/${this.dossierId}`;
}
get searchKey(): string { get searchKey(): string {
return this.dossierName; return this.dossierName;
} }

View File

@ -6,7 +6,6 @@ import { AuditControllerService } from './api/auditController.service';
import { DictionaryControllerService } from './api/dictionaryController.service'; import { DictionaryControllerService } from './api/dictionaryController.service';
import { DigitalSignatureControllerService } from './api/digitalSignatureController.service'; import { DigitalSignatureControllerService } from './api/digitalSignatureController.service';
import { DossierAttributesControllerService } from './api/dossierAttributesController.service'; import { DossierAttributesControllerService } from './api/dossierAttributesController.service';
import { DossierControllerService } from './api/dossierController.service';
import { DossierTemplateControllerService } from './api/dossierTemplateController.service'; import { DossierTemplateControllerService } from './api/dossierTemplateController.service';
import { DownloadControllerService } from './api/downloadController.service'; import { DownloadControllerService } from './api/downloadController.service';
import { FileAttributesControllerService } from './api/fileAttributesController.service'; import { FileAttributesControllerService } from './api/fileAttributesController.service';
@ -40,7 +39,6 @@ import { NotificationControllerService } from './api/notificationController.serv
DictionaryControllerService, DictionaryControllerService,
DigitalSignatureControllerService, DigitalSignatureControllerService,
DossierAttributesControllerService, DossierAttributesControllerService,
DossierControllerService,
DossierTemplateControllerService, DossierTemplateControllerService,
DownloadControllerService, DownloadControllerService,
FileAttributesControllerService, FileAttributesControllerService,

View File

@ -6,7 +6,6 @@ import { InfoControllerService } from './infoController.service';
import { LegalBasisMappingControllerService } from './legalBasisMappingController.service'; import { LegalBasisMappingControllerService } from './legalBasisMappingController.service';
import { LicenseReportControllerService } from './licenseReportController.service'; import { LicenseReportControllerService } from './licenseReportController.service';
import { ManualRedactionControllerService } from './manualRedactionController.service'; import { ManualRedactionControllerService } from './manualRedactionController.service';
import { DossierControllerService } from './dossierController.service';
import { ReanalysisControllerService } from './reanalysisController.service'; import { ReanalysisControllerService } from './reanalysisController.service';
import { RedactionLogControllerService } from './redactionLogController.service'; import { RedactionLogControllerService } from './redactionLogController.service';
import { DossierTemplateControllerService } from './dossierTemplateController.service'; import { DossierTemplateControllerService } from './dossierTemplateController.service';
@ -95,7 +94,6 @@ export const APIS = [
LegalBasisMappingControllerService, LegalBasisMappingControllerService,
LicenseReportControllerService, LicenseReportControllerService,
ManualRedactionControllerService, ManualRedactionControllerService,
DossierControllerService,
ReanalysisControllerService, ReanalysisControllerService,
RedactionLogControllerService, RedactionLogControllerService,
DossierTemplateControllerService, DossierTemplateControllerService,

View File

@ -1,27 +1,27 @@
export interface ConfigurationParameters { export interface ConfigurationParameters {
apiKeys?: { [key: string]: string }; readonly apiKeys?: { [key: string]: string };
username?: string; readonly username?: string;
password?: string; readonly password?: string;
accessToken?: string | (() => string); readonly accessToken?: string | (() => string);
basePath?: string; readonly basePath?: string;
withCredentials?: boolean; readonly withCredentials?: boolean;
} }
export class Configuration { export class Configuration implements ConfigurationParameters {
apiKeys?: { [key: string]: string }; readonly apiKeys?: { [key: string]: string };
username?: string; readonly username?: string;
password?: string; readonly password?: string;
accessToken?: string | (() => string); readonly accessToken?: string | (() => string);
basePath?: string; readonly basePath: string;
withCredentials?: boolean; readonly withCredentials: boolean;
constructor(configurationParameters: ConfigurationParameters = {}) { constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys; this.apiKeys = configurationParameters.apiKeys;
this.username = configurationParameters.username; this.username = configurationParameters.username;
this.password = configurationParameters.password; this.password = configurationParameters.password;
this.accessToken = configurationParameters.accessToken; this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath; this.basePath = configurationParameters.basePath ?? '';
this.withCredentials = configurationParameters.withCredentials; this.withCredentials = !!configurationParameters.withCredentials;
} }
/** /**
@ -73,7 +73,7 @@ export class Configuration {
* @return True if the given MIME is JSON, false otherwise. * @return True if the given MIME is JSON, false otherwise.
*/ */
public isJsonMime(mime: string): boolean { public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); const jsonMime = new RegExp('^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
} }
} }

View File

@ -26,7 +26,7 @@
"lint": "nx workspace-lint && nx lint", "lint": "nx workspace-lint && nx lint",
"lint-fix": "nx workspace-lint --fix && nx lint --fix", "lint-fix": "nx workspace-lint --fix && nx lint --fix",
"nx": "nx", "nx": "nx",
"start": "nx serve --hmr", "start": "nx serve",
"test": "nx test", "test": "nx test",
"update": "nx migrate latest", "update": "nx migrate latest",
"migrate": "nx migrate --run-migrations", "migrate": "nx migrate --run-migrations",