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 => 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] ?? [])), tap(values => (dict.entries = [...values.entries] ?? [])),
catchError(() => { catchError(() => {
dict.entries = []; dict.entries = [];

View File

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

View File

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

View File

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

View File

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

View File

@ -117,7 +117,7 @@ export class FileActionsComponent extends AutoUnsubscribe implements OnDestroy,
.catch(error => { .catch(error => {
this._toaster.error(_('error.http.generic'), { params: 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.actionPerformed.emit('delete');
this._loadingService.stop(); this._loadingService.stop();
}, },

View File

@ -111,7 +111,7 @@ export class DictionaryManagerComponent implements OnChanges {
} }
this._dictionaryService this._dictionaryService
.getFor(this._dictionary.dossierTemplateId, this._dictionary.type) .getForType(this._dictionary.dossierTemplateId, this._dictionary.type)
.pipe( .pipe(
tap(values => (this._dictionary.entries = [...values.entries] ?? [])), tap(values => (this._dictionary.entries = [...values.entries] ?? [])),
catchError(() => { catchError(() => {
@ -206,7 +206,7 @@ export class DictionaryManagerComponent implements OnChanges {
} }
private _onDossierChanged(dossierTemplateId: string, dossierId?: string, type = 'dossier_redaction'): Observable<string> { 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]))); 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 * Retrieves all dictionary entries of an entry type
*/ */
@Validate() @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; const queryParams = dossierId ? [{ key: 'dossierId', value: dossierId }] : undefined;
return this._getOne([type, dossierTemplateId], this._defaultModelPath, queryParams); return this._getOne([type, dossierTemplateId], this._defaultModelPath, queryParams);
} }

View File

@ -40,7 +40,7 @@ export class DossiersService extends EntitiesService<Dossier, IDossier> {
} }
loadAllIfChanged(): Observable<boolean> { 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() @Validate()

View File

@ -21,16 +21,6 @@ export class FilesService extends EntitiesService<File, IFile> {
return super._getOne([dossierId, fileId]); 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() @Validate()
setUnderApprovalFor(@RequiredParam() body: List, @RequiredParam() dossierId: string, approverId: string) { setUnderApprovalFor(@RequiredParam() body: List, @RequiredParam() dossierId: string, approverId: string) {
const url = `${this._defaultModelPath}/under-approval/${dossierId}/bulk`; const url = `${this._defaultModelPath}/under-approval/${dossierId}/bulk`;

View File

@ -40,7 +40,7 @@ export class NotificationsService extends GenericService<Notification> {
@Validate() @Validate()
getNotificationsIfChanged(@RequiredParam() includeSeen: boolean): Observable<Notification[]> { 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() @Validate()

View File

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

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