move some methods to dossiers service
This commit is contained in:
parent
eb4b8b0f1e
commit
08d23a3118
@ -8,6 +8,7 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { NotificationType, NotificationTypeEnum } from '@models/notification-types';
|
||||
import { notificationsTranslations } from '../../translations/notifications-translations';
|
||||
import { DossiersService } from '../../modules/dossier/services/dossiers.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-notifications',
|
||||
@ -23,6 +24,7 @@ export class NotificationsComponent {
|
||||
private readonly _userService: UserService,
|
||||
private readonly _notificationControllerService: NotificationControllerService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _datePipe: DatePipe
|
||||
) {
|
||||
this._notificationControllerService.getNotifications(false).subscribe((response: NotificationResponse) => {
|
||||
@ -96,12 +98,12 @@ export class NotificationsComponent {
|
||||
}
|
||||
|
||||
private _getDossierName(dossierId: string | undefined) {
|
||||
const dossier = this._appStateService.getDossierById(dossierId);
|
||||
const dossier = this._dossiersService.find(dossierId);
|
||||
return dossier?.dossierName || this._translateService.instant(_('dossier'));
|
||||
}
|
||||
|
||||
private _getFileName(dossierId: string | undefined, fileId: string | undefined) {
|
||||
const file = this._appStateService.getFileById(dossierId, fileId);
|
||||
const file = this._dossiersService.find(dossierId, fileId);
|
||||
return file?.filename || this._translateService.instant(_('file'));
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { UserControllerService } from '@redaction/red-ui-http';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { LoadingService } from '@iqser/common-ui';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { User } from '@models/user';
|
||||
import { DossiersService } from '../../../dossier/services/dossiers.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-confirm-delete-users-dialog',
|
||||
@ -20,13 +20,13 @@ export class ConfirmDeleteUsersDialogComponent {
|
||||
dossiersCount: number;
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _userControllerService: UserControllerService,
|
||||
readonly dialogRef: MatDialogRef<ConfirmDeleteUsersDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) readonly users: User[]
|
||||
) {
|
||||
this.dossiersCount = this._appStateService.allDossiers.filter(dw => {
|
||||
this.dossiersCount = this._dossiersService.all.filter(dw => {
|
||||
for (const user of this.users) {
|
||||
if (dw.memberIds.indexOf(user.id) !== -1) {
|
||||
return true;
|
||||
|
||||
@ -5,6 +5,7 @@ import { DossiersDialogService } from '../../services/dossiers-dialog.service';
|
||||
import { AutoUnsubscribe } from '@iqser/common-ui';
|
||||
import { File } from '@models/file/file';
|
||||
import { FileAttributesService } from '../../services/file-attributes.service';
|
||||
import { DossiersService } from '../../services/dossiers.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-document-info',
|
||||
@ -13,12 +14,13 @@ import { FileAttributesService } from '../../services/file-attributes.service';
|
||||
})
|
||||
export class DocumentInfoComponent extends AutoUnsubscribe implements OnInit {
|
||||
@Input() file: File;
|
||||
@Output() closeDocumentInfoView = new EventEmitter();
|
||||
@Output() readonly closeDocumentInfoView = new EventEmitter();
|
||||
|
||||
fileAttributesConfig: FileAttributesConfig;
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _fileAttributesService: FileAttributesService,
|
||||
private readonly _dialogService: DossiersDialogService
|
||||
) {
|
||||
@ -26,7 +28,7 @@ export class DocumentInfoComponent extends AutoUnsubscribe implements OnInit {
|
||||
}
|
||||
|
||||
get dossier() {
|
||||
return this._appStateService.getDossierById(this.file.dossierId);
|
||||
return this._dossiersService.find(this.file.dossierId);
|
||||
}
|
||||
|
||||
get dossierTemplateName(): string {
|
||||
|
||||
@ -5,6 +5,7 @@ import { AppStateService } from '@state/app-state.service';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Dossier } from '@state/model/dossier';
|
||||
import { FileAttributesService } from '../../services/file-attributes.service';
|
||||
import { DossiersService } from '../../services/dossiers.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './document-info-dialog.component.html',
|
||||
@ -15,17 +16,18 @@ export class DocumentInfoDialogComponent implements OnInit {
|
||||
file: IFile;
|
||||
attributes: IFileAttributeConfig[];
|
||||
|
||||
private _dossier: Dossier;
|
||||
private readonly _dossier: Dossier;
|
||||
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _formBuilder: FormBuilder,
|
||||
private readonly _fileAttributesService: FileAttributesService,
|
||||
public dialogRef: MatDialogRef<DocumentInfoDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: IFile
|
||||
) {
|
||||
this.file = this.data;
|
||||
this._dossier = this._appStateService.getDossierById(this.file.dossierId);
|
||||
this._dossier = this._dossiersService.find(this.file.dossierId);
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
|
||||
@ -12,6 +12,7 @@ import { EditDossierAttributesComponent } from './attributes/edit-dossier-attrib
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { EditDossierDeletedDocumentsComponent } from './deleted-documents/edit-dossier-deleted-documents.component';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { DossiersService } from '../../services/dossiers.service';
|
||||
|
||||
type Section = 'dossierInfo' | 'downloadPackage' | 'dossierDictionary' | 'members' | 'dossierAttributes' | 'deletedDocuments';
|
||||
|
||||
@ -34,6 +35,7 @@ export class EditDossierDialogComponent {
|
||||
constructor(
|
||||
private readonly _toaster: Toaster,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _changeRef: ChangeDetectorRef,
|
||||
@Inject(MAT_DIALOG_DATA)
|
||||
private readonly _data: {
|
||||
@ -106,7 +108,7 @@ export class EditDossierDialogComponent {
|
||||
|
||||
updatedDossier() {
|
||||
this._toaster.success(_('edit-dossier-dialog.change-successful'), { params: { dossierName: this.dossier.dossierName } });
|
||||
this.dossier = this._appStateService.getDossierById(this.dossier.id);
|
||||
this.dossier = this._dossiersService.find(this.dossier.id);
|
||||
this._changeRef.detectChanges();
|
||||
this.afterSave();
|
||||
}
|
||||
|
||||
@ -12,12 +12,12 @@ import { List, MatchedDocument, SearchControllerService, SearchResult } from '@r
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { debounceTime, map, skip, switchMap, tap } from 'rxjs/operators';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { fileStatusTranslations } from '../../translations/file-status-translations';
|
||||
import { SearchPositions } from '@shared/components/page-header/models/search-positions.type';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { RouterHistoryService } from '@services/router-history.service';
|
||||
import { DossiersService } from '../../services/dossiers.service';
|
||||
|
||||
interface ListItem extends IListable {
|
||||
readonly dossierId: string;
|
||||
@ -65,7 +65,7 @@ export class SearchScreenComponent extends ListingComponent<ListItem> implements
|
||||
protected readonly _injector: Injector,
|
||||
private readonly _activatedRoute: ActivatedRoute,
|
||||
private readonly _loadingService: LoadingService,
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
readonly routerHistoryService: RouterHistoryService,
|
||||
private readonly _translateService: TranslateService,
|
||||
private readonly _searchControllerService: SearchControllerService
|
||||
@ -77,7 +77,7 @@ export class SearchScreenComponent extends ListingComponent<ListItem> implements
|
||||
label: this._translateService.instant('search-screen.filters.by-dossier'),
|
||||
filterceptionPlaceholder: this._translateService.instant('search-screen.filters.search-placeholder'),
|
||||
icon: 'red:folder',
|
||||
filters: this._appStateService.allDossiers.map(
|
||||
filters: this._dossiersService.all.map(
|
||||
dossier =>
|
||||
new NestedFilter({
|
||||
id: dossier.id,
|
||||
@ -135,7 +135,7 @@ export class SearchScreenComponent extends ListingComponent<ListItem> implements
|
||||
}
|
||||
|
||||
private _toListItem({ dossierId, fileId, unmatchedTerms, highlights }: MatchedDocument): ListItem {
|
||||
const file = this._appStateService.getFileById(dossierId, fileId);
|
||||
const file = this._dossiersService.find(dossierId, fileId);
|
||||
if (!file) {
|
||||
return undefined;
|
||||
}
|
||||
@ -147,7 +147,7 @@ export class SearchScreenComponent extends ListingComponent<ListItem> implements
|
||||
highlights,
|
||||
status: file.status,
|
||||
numberOfPages: file.numberOfPages,
|
||||
dossierName: this._appStateService.getDossierById(dossierId).dossierName,
|
||||
dossierName: this._dossiersService.find(dossierId).dossierName,
|
||||
filename: file.filename,
|
||||
searchKey: file.filename,
|
||||
routerLink: `/main/dossiers/${dossierId}/file/${fileId}`
|
||||
|
||||
@ -7,6 +7,7 @@ import { TEMPORARY_INJECTOR } from './injector';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { ActivationEnd, Router } from '@angular/router';
|
||||
import { BaseScreenComponent } from '@components/base-screen/base-screen.component';
|
||||
import { File } from '@models/file/file';
|
||||
|
||||
export interface IDossiersStats {
|
||||
totalPeople: number;
|
||||
@ -50,6 +51,17 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
|
||||
});
|
||||
}
|
||||
|
||||
find(dossierId: string): Dossier | undefined;
|
||||
find(dossierId: string, fileId: string): File | undefined;
|
||||
find(dossierId: string, fileId?: string): Dossier | File | undefined {
|
||||
const getDossier = () => this.all.find(dossier => dossier.dossierId === dossierId);
|
||||
if (!fileId) {
|
||||
return getDossier();
|
||||
}
|
||||
|
||||
return getDossier().files.find(file => file.fileId === fileId);
|
||||
}
|
||||
|
||||
get(): Observable<IDossier[]>;
|
||||
get(dossierId: string): Observable<IDossier>;
|
||||
get(dossierId?: string): Observable<IDossier | IDossier[]> {
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<div class="iqser-input-group w-200 mt-0">
|
||||
<mat-select [(ngModel)]="dossier" [disabled]="!compare">
|
||||
<mat-option [value]="selectDossier">{{ selectDossier.dossierName | translate }}</mat-option>
|
||||
<mat-option *ngFor="let dossier of dossiers" [value]="dossier">
|
||||
<mat-option *ngFor="let dossier of dossiersService.all$ | async" [value]="dossier">
|
||||
{{ dossier.dossierName }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
|
||||
import { AppStateService } from '@state/app-state.service';
|
||||
import { Debounce, IconButtonTypes, List } from '@iqser/common-ui';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { Dossier } from '@state/model/dossier';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
import { DictionaryService } from '@shared/services/dictionary.service';
|
||||
import { DossiersService } from '../../../dossier/services/dossiers.service';
|
||||
import ICodeEditor = monaco.editor.ICodeEditor;
|
||||
import IDiffEditor = monaco.editor.IDiffEditor;
|
||||
import IModelDeltaDecoration = monaco.editor.IModelDeltaDecoration;
|
||||
@ -44,7 +44,7 @@ export class DictionaryManagerComponent implements OnChanges, OnInit {
|
||||
private _decorations: string[] = [];
|
||||
private _searchDecorations: string[] = [];
|
||||
|
||||
constructor(private readonly _dictionaryService: DictionaryService, private readonly _appStateService: AppStateService) {}
|
||||
constructor(private readonly _dictionaryService: DictionaryService, readonly dossiersService: DossiersService) {}
|
||||
|
||||
private _dossier: Dossier = this.selectDossier as Dossier;
|
||||
|
||||
@ -72,10 +72,6 @@ export class DictionaryManagerComponent implements OnChanges, OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
get dossiers() {
|
||||
return this._appStateService.allDossiers;
|
||||
}
|
||||
|
||||
get editorValue(): string {
|
||||
return this.currentEntries.join('\n');
|
||||
}
|
||||
|
||||
@ -4,12 +4,17 @@ import { UserService } from './user.service';
|
||||
import { File } from '@models/file/file';
|
||||
import { Comment } from '@redaction/red-ui-http';
|
||||
import { Dossier } from '@state/model/dossier';
|
||||
import { DossiersService } from '../modules/dossier/services/dossiers.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class PermissionsService {
|
||||
constructor(private readonly _appStateService: AppStateService, private readonly _userService: UserService) {}
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _dossiersService: DossiersService
|
||||
) {}
|
||||
|
||||
private get _activeFile(): File | undefined {
|
||||
return this._appStateService.activeFile;
|
||||
@ -113,8 +118,8 @@ export class PermissionsService {
|
||||
return ['UNDER_REVIEW', 'UNDER_APPROVAL'].includes(file?.status) && this.isFileReviewer(file);
|
||||
}
|
||||
|
||||
canDownloadFiles(file = this._activeFile): boolean {
|
||||
const dossier = this._appStateService.getDossierById(file?.dossierId);
|
||||
canDownloadFiles(file: File): boolean {
|
||||
const dossier = this._dossiersService.find(file?.dossierId);
|
||||
if (!dossier) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { AppStateService } from './app-state.service';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { DossiersService } from '../modules/dossier/services/dossiers.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -9,6 +10,7 @@ import { UserService } from '@services/user.service';
|
||||
export class AppStateGuard implements CanActivate {
|
||||
constructor(
|
||||
private readonly _appStateService: AppStateService,
|
||||
private readonly _dossiersService: DossiersService,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _router: Router
|
||||
) {}
|
||||
@ -30,12 +32,12 @@ export class AppStateGuard implements CanActivate {
|
||||
|
||||
const { dossierId, fileId, dossierTemplateId, type } = route.params;
|
||||
|
||||
if (dossierId && !this._appStateService.getDossierById(dossierId)) {
|
||||
if (dossierId && !this._dossiersService.find(dossierId)) {
|
||||
await this._router.navigate(['main', 'dossiers']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fileId && !this._appStateService.getFileById(dossierId, fileId)) {
|
||||
if (fileId && !this._dossiersService.find(dossierId, fileId)) {
|
||||
await this._router.navigate(['main', 'dossiers', dossierId]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ export class AppStateService {
|
||||
}
|
||||
|
||||
get aggregatedFiles(): File[] {
|
||||
return this.allDossiers.reduce((acc, { files }) => [...acc, ...files], []);
|
||||
return this._dossiersService.all.reduce((acc, { files }) => [...acc, ...files], []);
|
||||
}
|
||||
|
||||
get activeDossierTemplateId(): string | undefined {
|
||||
@ -113,15 +113,7 @@ export class AppStateService {
|
||||
}
|
||||
|
||||
get activeDossier(): Dossier | undefined {
|
||||
return this.allDossiers.find(p => p.id === this.activeDossierId);
|
||||
}
|
||||
|
||||
get allDossiers(): Dossier[] {
|
||||
return this._appState.dossiers;
|
||||
}
|
||||
|
||||
get hasDossiers() {
|
||||
return this.allDossiers?.length > 0;
|
||||
return this._dossiersService.all.find(p => p.id === this.activeDossierId);
|
||||
}
|
||||
|
||||
get activeFile(): File | undefined {
|
||||
@ -194,14 +186,6 @@ export class AppStateService {
|
||||
return data ? data : this._dictionaryData[dossierTemplateId]['default'];
|
||||
}
|
||||
|
||||
getDossierById(id: string) {
|
||||
return this.allDossiers.find(dossier => dossier.id === id);
|
||||
}
|
||||
|
||||
getFileById(dossierId: string, fileId: string) {
|
||||
return this.getDossierById(dossierId)?.files.find(file => file.fileId === fileId);
|
||||
}
|
||||
|
||||
async loadAllDossiers(emitEvents = true) {
|
||||
const dossiers = await this._dossiersService.get().toPromise();
|
||||
if (!dossiers) {
|
||||
@ -267,7 +251,7 @@ export class AppStateService {
|
||||
|
||||
async updateDossierDictionary(dossierTemplateId: string, dossierId: string) {
|
||||
// dossier exists, load its dictionary
|
||||
const dossier = this.getDossierById(dossierId);
|
||||
const dossier = this._dossiersService.find(dossierId);
|
||||
try {
|
||||
dossier.type = await this._dictionaryService.getFor(dossierTemplateId, 'dossier_redaction', dossierId).toPromise();
|
||||
} catch (e) {
|
||||
@ -323,9 +307,10 @@ export class AppStateService {
|
||||
.toPromise()
|
||||
.then(
|
||||
() => {
|
||||
const index = this.allDossiers.findIndex(p => p.id === dossier.id);
|
||||
this._appState.dossiers.splice(index, 1);
|
||||
this._dossiersService.setEntities(this._appState.dossiers);
|
||||
const dossiers = this._dossiersService.all;
|
||||
const index = dossiers.findIndex(p => p.id === dossier.id);
|
||||
dossiers.splice(index, 1);
|
||||
this._dossiersService.setEntities([...dossiers]);
|
||||
},
|
||||
() => this._toaster.error(_('dossier-listing.delete.delete-failed'), { params: dossier })
|
||||
);
|
||||
@ -334,7 +319,7 @@ export class AppStateService {
|
||||
async createOrUpdateDossier(dossier: DossierRequest) {
|
||||
try {
|
||||
const updatedDossier = await this._dossiersService.createOrUpdate(dossier);
|
||||
let foundDossier = this.allDossiers.find(p => p.id === updatedDossier.dossierId);
|
||||
let foundDossier = this._dossiersService.find(updatedDossier.dossierId);
|
||||
if (foundDossier) {
|
||||
this._appState.dossiers.splice(this._appState.dossiers.indexOf(foundDossier), 1);
|
||||
foundDossier = new Dossier(updatedDossier, foundDossier.files);
|
||||
@ -389,7 +374,7 @@ export class AppStateService {
|
||||
}
|
||||
|
||||
async loadAllDossiersIfNecessary() {
|
||||
if (!this.allDossiers.length) {
|
||||
if (!this._dossiersService.all.length) {
|
||||
await this.loadAllDossiers();
|
||||
}
|
||||
}
|
||||
@ -660,7 +645,7 @@ export class AppStateService {
|
||||
}
|
||||
|
||||
private _getExistingFiles(dossierId: string): List<File> {
|
||||
const dossier = this.allDossiers.find(p => p.id === dossierId);
|
||||
const dossier = this._dossiersService.find(dossierId);
|
||||
return dossier?.files ?? [];
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user