use file stats component

This commit is contained in:
Dan Percic 2021-11-16 10:39:54 +02:00
parent 33100f94da
commit 4c8e65573a
7 changed files with 46 additions and 65 deletions

View File

@ -11,7 +11,8 @@
</span> </span>
</div> </div>
</div> </div>
<ng-container *ngTemplateOutlet="statsTemplate; context: { entity: file }"></ng-container>
<redaction-file-stats [file]="file"></redaction-file-stats>
</div> </div>
<div class="cell"> <div class="cell">
@ -58,11 +59,11 @@
<iqser-status-bar <iqser-status-bar
*ngIf="!file.isError && !file.isPending" *ngIf="!file.isError && !file.isPending"
[configs]="[ [configs]="[
{ {
color: file.workflowStatus, color: file.workflowStatus,
length: 1 length: 1
} }
]" ]"
></iqser-status-bar> ></iqser-status-bar>
</div> </div>
<redaction-file-actions <redaction-file-actions

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, TemplateRef } from '@angular/core'; import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { File, IFileAttributeConfig } from '@red/domain'; import { File, IFileAttributeConfig } from '@red/domain';
import { Required } from '@iqser/common-ui'; import { Required } from '@iqser/common-ui';
@ -10,7 +10,6 @@ import { Required } from '@iqser/common-ui';
}) })
export class TableItemComponent { export class TableItemComponent {
@Input() @Required() file!: File; @Input() @Required() file!: File;
@Input() @Required() statsTemplate!: TemplateRef<unknown>;
@Input() @Required() displayedAttributes!: IFileAttributeConfig[]; @Input() @Required() displayedAttributes!: IFileAttributeConfig[];
@Output() readonly calculateData = new EventEmitter<string>(); @Output() readonly calculateData = new EventEmitter<string>();
} }

View File

@ -5,7 +5,7 @@
{{ file.filename }} {{ file.filename }}
</div> </div>
<ng-container *ngTemplateOutlet="statsTemplate; context: { entity: file }"></ng-container> <redaction-file-stats [file]="file"></redaction-file-stats>
</div> </div>
<div class="user"> <div class="user">

View File

@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, TemplateRef } from '@angular/core'; import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { File } from '@red/domain'; import { File } from '@red/domain';
@Component({ @Component({
@ -9,6 +9,5 @@ import { File } from '@red/domain';
}) })
export class WorkflowItemComponent { export class WorkflowItemComponent {
@Input() file: File; @Input() file: File;
@Input() statsTemplate: TemplateRef<unknown>;
@Output() readonly actionPerformed = new EventEmitter<string>(); @Output() readonly actionPerformed = new EventEmitter<string>();
} }

View File

@ -90,10 +90,7 @@
</section> </section>
<ng-template #bulkActions> <ng-template #bulkActions>
<redaction-dossier-overview-bulk-actions <redaction-dossier-overview-bulk-actions (reload)="reloadFiles()" [dossier]="dossier"></redaction-dossier-overview-bulk-actions>
(reload)="bulkActionPerformed()"
[dossier]="dossier"
></redaction-dossier-overview-bulk-actions>
</ng-template> </ng-template>
</ng-container> </ng-container>
@ -129,18 +126,9 @@
(calculateData)="actionPerformed($event)" (calculateData)="actionPerformed($event)"
[displayedAttributes]="displayedAttributes" [displayedAttributes]="displayedAttributes"
[file]="file" [file]="file"
[statsTemplate]="statsTemplate"
></redaction-table-item> ></redaction-table-item>
</ng-template> </ng-template>
<ng-template #workflowItemTemplate let-entity="entity"> <ng-template #workflowItemTemplate let-entity="entity">
<redaction-workflow-item <redaction-workflow-item (actionPerformed)="actionPerformed($event, entity)" [file]="entity"></redaction-workflow-item>
(actionPerformed)="actionPerformed($event, entity)"
[file]="entity"
[statsTemplate]="statsTemplate"
></redaction-workflow-item>
</ng-template>
<ng-template #statsTemplate let-file="entity">
<redaction-file-stats [file]="file"></redaction-file-stats>
</ng-template> </ng-template>

View File

@ -1,6 +1,5 @@
import { import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef,
Component, Component,
ElementRef, ElementRef,
forwardRef, forwardRef,
@ -20,7 +19,7 @@ import { StatusOverlayService } from '@upload-download/services/status-overlay.s
import * as moment from 'moment'; import * as moment from 'moment';
import { UserService } from '@services/user.service'; import { UserService } from '@services/user.service';
import { Observable, timer } from 'rxjs'; import { Observable, timer } from 'rxjs';
import { take, tap, withLatestFrom } from 'rxjs/operators'; import { switchMap, take, tap, withLatestFrom } from 'rxjs/operators';
import { convertFiles, Files, handleFileDrop } from '@utils/index'; import { convertFiles, Files, handleFileDrop } from '@utils/index';
import { DossiersDialogService } from '../../../services/dossiers-dialog.service'; import { DossiersDialogService } from '../../../services/dossiers-dialog.service';
import { import {
@ -51,7 +50,6 @@ import { DossierTemplatesService } from '@services/entity-services/dossier-templ
import { LongPressEvent } from '@shared/directives/long-press.directive'; import { LongPressEvent } from '@shared/directives/long-press.directive';
import { UserPreferenceService } from '@services/user-preference.service'; import { UserPreferenceService } from '@services/user-preference.service';
import { saveAsCSV } from '@utils/csv-utils'; import { saveAsCSV } from '@utils/csv-utils';
import { FilesService } from '@services/entity-services/files.service';
import { FilesMapService } from '@services/entity-services/files-map.service'; import { FilesMapService } from '@services/entity-services/files-map.service';
import { ReanalysisService } from '@services/reanalysis.service'; import { ReanalysisService } from '@services/reanalysis.service';
import { DossierStatsService } from '@services/entity-services/dossier-stats.service'; import { DossierStatsService } from '@services/entity-services/dossier-stats.service';
@ -99,7 +97,6 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
readonly routerHistoryService: RouterHistoryService, readonly routerHistoryService: RouterHistoryService,
private readonly _appConfigService: AppConfigService, private readonly _appConfigService: AppConfigService,
private readonly _dialogService: DossiersDialogService, private readonly _dialogService: DossiersDialogService,
private readonly _changeDetectorRef: ChangeDetectorRef,
private readonly _fileUploadService: FileUploadService, private readonly _fileUploadService: FileUploadService,
private readonly _statusOverlayService: StatusOverlayService, private readonly _statusOverlayService: StatusOverlayService,
private readonly _fileDropOverlayService: FileDropOverlayService, private readonly _fileDropOverlayService: FileDropOverlayService,
@ -107,7 +104,6 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
private readonly _fileAttributesService: FileAttributesService, private readonly _fileAttributesService: FileAttributesService,
private readonly _configService: ConfigService, private readonly _configService: ConfigService,
private readonly _userPreferenceService: UserPreferenceService, private readonly _userPreferenceService: UserPreferenceService,
private readonly _filesService: FilesService,
private readonly _fileMapService: FilesMapService, private readonly _fileMapService: FilesMapService,
private readonly _dossierStatsService: DossierStatsService, private readonly _dossierStatsService: DossierStatsService,
activatedRoute: ActivatedRoute, activatedRoute: ActivatedRoute,
@ -165,35 +161,35 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
.pipe(tap(files => this.entitiesService.setEntities(files))) .pipe(tap(files => this.entitiesService.setEntities(files)))
.subscribe(); .subscribe();
this._fileDropOverlayService.initFileDropHandling();
await this.calculateData();
this.addSubscription = timer(0, 20 * 1000)
.pipe(switchMap(() => this.reloadFiles()))
.subscribe();
this.addSubscription = this.listingMode$.subscribe(() => {
this._computeAllFilters();
});
this.addSubscription = this._dossierTemplatesService.entityChanged$.subscribe(() => {
this.fileAttributeConfigs = this._fileAttributesService.getFileAttributeConfig(
this.currentDossier.dossierTemplateId,
)?.fileAttributeConfigs;
});
this.addSubscription = this._tableComponent.scrollViewport.scrolledIndexChange
.pipe(tap(index => (this._lastScrolledIndex = index)))
.subscribe();
try { try {
this._fileDropOverlayService.initFileDropHandling();
await this.calculateData();
this.addSubscription = timer(0, 20 * 1000).subscribe(async () => {
await this.reloadFiles();
});
this.addSubscription = this.listingMode$.subscribe(() => {
this._computeAllFilters();
});
this.addSubscription = this._dossierTemplatesService.entityChanged$.subscribe(() => {
this.fileAttributeConfigs = this._fileAttributesService.getFileAttributeConfig(
this.currentDossier.dossierTemplateId,
)?.fileAttributeConfigs;
});
this.addSubscription = this._tableComponent.scrollViewport.scrolledIndexChange
.pipe(tap(index => (this._lastScrolledIndex = index)))
.subscribe();
this.dossierAttributes = await this._dossierAttributesService.getWithValues(this.currentDossier); this.dossierAttributes = await this._dossierAttributesService.getWithValues(this.currentDossier);
} catch (e) { } catch (e) {
console.log('Error from dossier overview screen: ', e); console.log('Error from dossier overview screen: ', e);
} finally {
this._loadingService.stop();
} }
this._loadingService.stop();
} }
ngOnDestroy(): void { ngOnDestroy(): void {
@ -202,8 +198,6 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
} }
async ngOnAttach() { async ngOnAttach() {
// await this._appStateService.reloadActiveDossierFiles();
// await this._loadEntitiesFromState();
await this.ngOnInit(); await this.ngOnInit();
this._tableComponent.scrollViewport.scrollToIndex(this._lastScrolledIndex, 'smooth'); this._tableComponent.scrollViewport.scrollToIndex(this._lastScrolledIndex, 'smooth');
} }
@ -230,14 +224,12 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
const files = await this._appStateService.getFiles(this.currentDossier); const files = await this._appStateService.getFiles(this.currentDossier);
await this._dossierStatsService.getFor([this.dossierId]).toPromise(); await this._dossierStatsService.getFor([this.dossierId]).toPromise();
this.entitiesService.setEntities(files); this.entitiesService.setEntities(files);
await this.calculateData(); this._computeAllFilters();
} }
async calculateData(): Promise<void> { async calculateData(): Promise<void> {
await this._loadEntitiesFromState(); await this._loadEntitiesFromState();
this._computeAllFilters(); this._computeAllFilters();
this._changeDetectorRef.markForCheck();
} }
@HostListener('drop', ['$event']) @HostListener('drop', ['$event'])
@ -286,13 +278,11 @@ export class DossierOverviewScreenComponent extends ListingComponent<File> imple
this._fileInput.nativeElement.value = null; this._fileInput.nativeElement.value = null;
} }
async bulkActionPerformed(): Promise<void> {
await this.reloadFiles();
}
openAssignDossierMembersDialog(): void { openAssignDossierMembersDialog(): void {
const data = { dossierId: this.dossierId, section: 'members' }; const data = { dossierId: this.dossierId, section: 'members' };
this._dialogService.openDialog('editDossier', null, data, async () => this.reloadFiles()); this._dialogService.openDialog('editDossier', null, data, async () => {
await this.reloadFiles();
});
} }
openDossierDictionaryDialog() { openDossierDictionaryDialog() {

View File

@ -33,7 +33,11 @@ export class DossierStatsService {
set(stats: DossierStats): void { set(stats: DossierStats): void {
if (!this._map.has(stats.dossierId)) { if (!this._map.has(stats.dossierId)) {
this._map.set(stats.dossierId, new BehaviorSubject<DossierStats>(stats)); this._map.set(stats.dossierId, new BehaviorSubject<DossierStats>(stats));
} else { return;
}
const old = this.get(stats.dossierId);
if (JSON.stringify(old) !== JSON.stringify(stats)) {
this._map.get(stats.dossierId).next(stats); this._map.get(stats.dossierId).next(stats);
} }
} }