Refresh files with check for changes

This commit is contained in:
Adina Țeudan 2021-11-18 21:16:19 +02:00
parent 916737f707
commit d7ed6fa1bc
14 changed files with 24 additions and 27 deletions

View File

@ -115,7 +115,7 @@ export class DictionaryListingScreenComponent extends ListingComponent<Dictionar
}
const dataObs = this.allEntities.map(dict =>
this._dictionaryService.getFor(this._dossierTemplatesService.activeDossierTemplateId, dict.type).pipe(
this._dictionaryService.getForType(this._dossierTemplatesService.activeDossierTemplateId, dict.type).pipe(
tap(values => (dict.entries = [...values.entries] ?? [])),
catchError(() => {
dict.entries = [];

View File

@ -150,7 +150,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple
private async _loadEntries() {
this._loadingService.start();
await this._dictionaryService
.getFor(this.dictionary.dossierTemplateId, this.dictionary.type)
.getForType(this.dictionary.dossierTemplateId, this.dictionary.type)
.toPromise()
.then(
data => {

View File

@ -115,7 +115,7 @@ export class EditDossierDeletedDocumentsComponent extends ListingComponent<FileL
const fileIds = files.map(f => f.fileId);
await this._fileManagementService.restore(fileIds, this.dossier.id).toPromise();
this._removeFromList(fileIds);
await this._appStateService.reloadDossierFiles();
await this._appStateService.reloadDossierFiles(files[0].dossierId);
this.updateDossier.emit();
}

View File

@ -75,6 +75,6 @@ export class EditDossierDictionaryComponent implements EditDossierSectionInterfa
private async _updateDossierDictionary() {
const { dossierId, dossierTemplateId } = this.dossier;
this.dossierDictionary = await this._dictionaryService.getFor(dossierTemplateId, 'dossier_redaction', dossierId).toPromise();
this.dossierDictionary = await this._dictionaryService.getForType(dossierTemplateId, 'dossier_redaction', dossierId).toPromise();
}
}

View File

@ -18,9 +18,10 @@ import { FileUploadService } from '@upload-download/services/file-upload.service
import { StatusOverlayService } from '@upload-download/services/status-overlay.service';
import * as moment from 'moment';
import { Observable, timer } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import { filter, switchMap, tap } from 'rxjs/operators';
import { convertFiles, Files, handleFileDrop } from '@utils/index';
import {
CHANGED_CHECK_INTERVAL,
CircleButtonTypes,
DefaultListingServices,
ListingComponent,
@ -46,6 +47,7 @@ import { LongPressEvent } from '@shared/directives/long-press.directive';
import { UserPreferenceService } from '@services/user-preference.service';
import { FilesMapService } from '@services/entity-services/files-map.service';
import { DossierStatsService } from '@services/entity-services/dossier-stats.service';
import { FilesService } from '@services/entity-services/files.service';
@Component({
templateUrl: './dossier-overview-screen.component.html',
@ -84,6 +86,7 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
private readonly _dossierTemplatesService: DossierTemplatesService,
private readonly _appConfigService: AppConfigService,
private readonly _fileUploadService: FileUploadService,
private readonly _filesService: FilesService,
private readonly _statusOverlayService: StatusOverlayService,
private readonly _fileDropOverlayService: FileDropOverlayService,
private readonly _dossierAttributesService: DossierAttributesService,
@ -158,8 +161,12 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
await this.calculateData();
this.addSubscription = timer(0, 20 * 1000)
.pipe(switchMap(() => this.reloadFiles()))
this.addSubscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL)
.pipe(
switchMap(() => this._filesService.hasChanges$(this.dossierId)),
filter(changed => changed),
switchMap(() => this.reloadFiles()),
)
.subscribe();
this.addSubscription = this.configService.listingMode$.subscribe(() => {

View File

@ -477,11 +477,11 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
case 'reanalyse':
await this._loadFileData(true);
this._updateCanPerformActions();
await this.appStateService.reloadDossierFiles();
await this.appStateService.reloadDossierFiles(this.dossierId);
return;
case 'exclude-pages':
await this.appStateService.reloadDossierFiles();
await this.appStateService.reloadDossierFiles(this.dossierId);
await this._loadFileData(true);
this._cleanupAndRedrawManualAnnotations$();
await this._stampPDF();

View File

@ -117,7 +117,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
.catch(error => {
this._toaster.error(_('error.http.generic'), { params: error });
});
await this.appStateService.reloadDossierFiles();
await this.appStateService.reloadDossierFiles(this.file.dossierId);
this.actionPerformed.emit('delete');
this._loadingService.stop();
},

View File

@ -111,7 +111,7 @@ export class DictionaryManagerComponent implements OnChanges {
}
this._dictionaryService
.getFor(this._dictionary.dossierTemplateId, this._dictionary.type)
.getForType(this._dictionary.dossierTemplateId, this._dictionary.type)
.pipe(
tap(values => (this._dictionary.entries = [...values.entries] ?? [])),
catchError(() => {
@ -206,7 +206,7 @@ export class DictionaryManagerComponent implements OnChanges {
}
private _onDossierChanged(dossierTemplateId: string, dossierId?: string, type = 'dossier_redaction'): Observable<string> {
const dictionary$ = this._dictionaryService.getFor(dossierTemplateId, type, dossierId);
const dictionary$ = this._dictionaryService.getForType(dossierTemplateId, type, dossierId);
return dictionary$.pipe(map(data => this._toString([...data.entries])));
}

View File

@ -19,7 +19,7 @@ export class DictionaryService extends EntitiesService<Dictionary, IDictionary>
* Retrieves all dictionary entries of an entry type
*/
@Validate()
getFor(@RequiredParam() dossierTemplateId: string, @RequiredParam() type: string, dossierId?: string) {
getForType(@RequiredParam() dossierTemplateId: string, @RequiredParam() type: string, dossierId?: string) {
const queryParams = dossierId ? [{ key: 'dossierId', value: dossierId }] : undefined;
return this._getOne([type, dossierTemplateId], this._defaultModelPath, queryParams);
}

View File

@ -40,7 +40,7 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
}
loadAllIfChanged(): Observable<boolean> {
return this._hasChanges$.pipe(switchMap(changed => iif(() => changed, this.loadAll()).pipe(mapTo(changed))));
return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.loadAll()).pipe(mapTo(changed))));
}
@Validate()

View File

@ -21,16 +21,6 @@ export class FilesService extends EntitiesService<File, IFile> {
return super._getOne([dossierId, fileId]);
}
getFor(dossierId: string): Observable<IFile[]>;
getFor(dossierIds: List): Observable<Record<string, IFile[]>>;
getFor(args: string | List) {
if (typeof args === 'string') {
return super.getAll(`${this._defaultModelPath}/${args}`);
}
return this._post<Record<string, IFile[]>>(args);
}
@Validate()
setUnderApprovalFor(@RequiredParam() body: List, @RequiredParam() dossierId: string, approverId: string) {
const url = `${this._defaultModelPath}/under-approval/${dossierId}/bulk`;

View File

@ -40,7 +40,7 @@ export class NotificationsService extends GenericService<Notification> {
@Validate()
getNotificationsIfChanged(@RequiredParam() includeSeen: boolean): Observable<Notification[]> {
return this._hasChanges$.pipe(switchMap(changed => iif(() => changed, this.getNotifications(includeSeen))));
return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.getNotifications(includeSeen))));
}
@Validate()

View File

@ -142,7 +142,7 @@ export class AppStateService {
this._appState.activeDictionaryType = null;
}
async reloadDossierFiles(dossierId = this._activeDossierId) {
async reloadDossierFiles(dossierId: string) {
if (dossierId) {
return this.getFiles(this._dossiersService.find(dossierId));
}

@ -1 +1 @@
Subproject commit b338dd9baa8fd67a83d2f8c5710f8b56b0e360cd
Subproject commit cdd20751dc8845f45258a033214a6fdf52b1a760