From 864fe0d6eff8f03ab89a2feba0a5594ebc5bfbe4 Mon Sep 17 00:00:00 2001 From: paf <paf@titelfrei.de> Date: Mon, 4 Jan 2021 11:58:36 +0100 Subject: [PATCH] count stats of files --- .../workspace-admin/files/files.component.html | 2 ++ src/app/workspace-admin/files/files.component.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/app/workspace-admin/files/files.component.html b/src/app/workspace-admin/files/files.component.html index 7a1746ed..e5098f38 100644 --- a/src/app/workspace-admin/files/files.component.html +++ b/src/app/workspace-admin/files/files.component.html @@ -99,6 +99,8 @@ {{ i }} </p> + <pre>{{fileStats | json}}</pre> + <br/> </div> diff --git a/src/app/workspace-admin/files/files.component.ts b/src/app/workspace-admin/files/files.component.ts index 0d929880..766f2bef 100644 --- a/src/app/workspace-admin/files/files.component.ts +++ b/src/app/workspace-admin/files/files.component.ts @@ -34,6 +34,7 @@ export class FilesComponent implements OnInit { public checkInfos = []; @ViewChild(MatSort, { static: true }) sort: MatSort; + private fileStats: {[type: string]: number}; constructor( @Inject('SERVER_URL') private serverUrl: string, @@ -131,12 +132,27 @@ export class FilesComponent implements OnInit { (fileList: GetFileResponseData[]) => { this.serverfiles = new MatTableDataSource(fileList); this.serverfiles.sort = this.sort; + this.fileStats = FilesComponent.getStats(fileList); this.mds.setSpinnerOff(); } ); } } + private static getStats(fileList: GetFileResponseData[]): {[type: string]: number} { + const stats: {[type: string]: number} = {}; + // TODO filter validity + return fileList.reduce((carry, file) => { + if (typeof carry[file.type] === 'undefined') { + // eslint-disable-next-line no-param-reassign + carry[file.type] = 0; + } + // eslint-disable-next-line no-param-reassign + carry[file.type] += 1; + return carry; + }, stats); + } + download(element: GetFileResponseData): void { this.mds.setSpinnerOn(); this.bs.downloadFile(element.type, element.filename) -- GitLab