refresh dossier stats when files change
This commit is contained in:
parent
89a9b1680d
commit
02d1080e5d
@ -1,19 +1,21 @@
|
||||
<div class="cell">
|
||||
<redaction-dossiers-listing-dossier-name [dossierStats]="stats" [dossier]="dossier"></redaction-dossiers-listing-dossier-name>
|
||||
</div>
|
||||
<ng-container *ngIf="stats$ | async as stats">
|
||||
<div class="cell">
|
||||
<redaction-dossiers-listing-dossier-name [dossierStats]="stats" [dossier]="dossier"></redaction-dossiers-listing-dossier-name>
|
||||
</div>
|
||||
|
||||
<div class="cell">
|
||||
<redaction-dossier-workload-column [dossierStats]="stats" [dossier]="dossier"></redaction-dossier-workload-column>
|
||||
</div>
|
||||
<div class="cell">
|
||||
<redaction-dossier-workload-column [dossierStats]="stats" [dossier]="dossier"></redaction-dossier-workload-column>
|
||||
</div>
|
||||
|
||||
<div class="cell user-column">
|
||||
<redaction-initials-avatar [user]="dossier.ownerId" [withName]="true"></redaction-initials-avatar>
|
||||
</div>
|
||||
<div class="cell user-column">
|
||||
<redaction-initials-avatar [user]="dossier.ownerId" [withName]="true"></redaction-initials-avatar>
|
||||
</div>
|
||||
|
||||
<div class="cell status-container">
|
||||
<redaction-dossiers-listing-actions
|
||||
(actionPerformed)="calculateData.emit()"
|
||||
[dossier]="dossier"
|
||||
[stats]="stats"
|
||||
></redaction-dossiers-listing-actions>
|
||||
</div>
|
||||
<div class="cell status-container">
|
||||
<redaction-dossiers-listing-actions
|
||||
(actionPerformed)="calculateData.emit()"
|
||||
[dossier]="dossier"
|
||||
[stats]="stats"
|
||||
></redaction-dossiers-listing-actions>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
@ -1,23 +1,43 @@
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
|
||||
import { Dossier, DossierStats } from '@red/domain';
|
||||
import { Required } from '@iqser/common-ui';
|
||||
import { DossierStatsService } from '@services/entity-services/dossier-stats.service';
|
||||
import { BehaviorSubject, merge, Observable, timer } from 'rxjs';
|
||||
import { filter, switchMap } from 'rxjs/operators';
|
||||
import { CHANGED_CHECK_INTERVAL } from '@iqser/common-ui';
|
||||
import { FilesService } from '@services/entity-services/files.service';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-table-item',
|
||||
selector: 'redaction-table-item [dossier]',
|
||||
templateUrl: './table-item.component.html',
|
||||
styleUrls: ['./table-item.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class TableItemComponent implements OnChanges {
|
||||
@Input() @Required() dossier!: Dossier;
|
||||
@Input() dossier!: Dossier;
|
||||
@Output() readonly calculateData = new EventEmitter();
|
||||
|
||||
stats: DossierStats;
|
||||
readonly stats$: Observable<DossierStats>;
|
||||
private readonly _ngOnChanges$ = new BehaviorSubject<string>(undefined);
|
||||
|
||||
constructor(readonly dossierStatsService: DossierStatsService) {}
|
||||
constructor(readonly dossierStatsService: DossierStatsService, readonly filesService: FilesService) {
|
||||
const hasChanges$ = this._hasChanges$;
|
||||
this.stats$ = merge(this._ngOnChanges$, hasChanges$).pipe(
|
||||
filter(() => !!this.dossier),
|
||||
switchMap(() => this.dossierStatsService.watch$(this.dossier.dossierId)),
|
||||
);
|
||||
}
|
||||
|
||||
private get _hasChanges$() {
|
||||
// I used switchMap instead of switchMapTo because I want to check dossierId every time
|
||||
return timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL).pipe(
|
||||
filter(() => !!this.dossier),
|
||||
switchMap(() => this.filesService.hasChanges$(this.dossier.dossierId)),
|
||||
filter(changed => changed),
|
||||
switchMap(() => this.dossierStatsService.getFor([this.dossier.dossierId])),
|
||||
);
|
||||
}
|
||||
|
||||
ngOnChanges() {
|
||||
this.stats = this.dossierStatsService.get(this.dossier.dossierId);
|
||||
this._ngOnChanges$.next(this.dossier.dossierId);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user