diff --git a/client/components/ImageList.tsx b/client/components/ImageList.tsx index 934c9ef..9881081 100644 --- a/client/components/ImageList.tsx +++ b/client/components/ImageList.tsx @@ -898,8 +898,15 @@ export default function ImageList() { {(selectAllInPage[currentPage] === ALL_SELECTED) && <> {selectAllPages ? "Clear selection" : "Select all media matching filter"} } - - + { + (selectAllPages || checkedImage.length > 0) && + } + { + (!selectAllPages && checkedImage.length > 0) &&

Selected {checkedImage.length} media items

+ } + { + selectAllPages &&

Selected all media items in all pages

+ }
diff --git a/server/src/utils/file-utility.ts b/server/src/utils/file-utility.ts index eb475b7..a80517d 100644 --- a/server/src/utils/file-utility.ts +++ b/server/src/utils/file-utility.ts @@ -1,103 +1,69 @@ -import { Injectable } from "@nestjs/common"; +import { Injectable } from '@nestjs/common'; import * as fs from 'fs'; -Injectable() -export class FileUtility{ - getFileSizeText(fileSizeInBytes: number): string { - const BYTE_TO_KB = 1024; - const KB_TO_MB = 1024; - const MB_TO_GB = 1024; - - if (!Number.isFinite(fileSizeInBytes) || fileSizeInBytes < 0) { - throw new Error('Invalid file size'); - } - - let size: string | number; - let unit: string; - - if (fileSizeInBytes < BYTE_TO_KB) { - size = fileSizeInBytes; - unit = 'bytes'; - } else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB) { - size = (fileSizeInBytes / BYTE_TO_KB).toFixed(2); - unit = 'KB'; - } else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB * MB_TO_GB) { - size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB).toFixed(2); - unit = 'MB'; - } else { - size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB / MB_TO_GB).toFixed(2); - unit = 'GB'; - } - - return `${size} ${unit}`; - } +Injectable(); - async folderStructure( - metadata: any, - locationHierarchy: { name: any; }[] - ): Promise { - const address = metadata.address; - const conceptType = metadata.conceptName; - const subjectType = metadata.subjectTypeName; - const encounterType = metadata.encounterTypeName; - const keys = locationHierarchy.map((index: { name: any; }) => index.name); - const jsonadd = JSON.parse(address); - const addressArray = []; - let val ='' - for (const key of keys) { - val= key.toString() - addressArray.push(jsonadd[val]); - } - let directoryPath = '' - await Promise.all( - addressArray.map(async (addressPart) => { - if (addressPart) { - if (directoryPath) { - directoryPath = `${directoryPath}/${addressPart}`; - } else { - directoryPath = `${addressPart}`; - } - if (!fs.existsSync(directoryPath)) { - fs.mkdirSync(directoryPath); - } - } - }), - ); - - if (subjectType) { - if (directoryPath) { - directoryPath = `${directoryPath}/${subjectType}`; - } else { - directoryPath = `${subjectType}`; - } - if (!fs.existsSync(directoryPath)) { - fs.mkdirSync(directoryPath); - } - } - - if (encounterType) { - if (directoryPath) { - directoryPath = `${directoryPath}/${encounterType}`; - } else { - directoryPath = `${encounterType}`; - } - if (!fs.existsSync(directoryPath)) { - fs.mkdirSync(directoryPath); - } - } - - if (conceptType) { - if (directoryPath) { - directoryPath = `${directoryPath}/${conceptType}`; - } else { - directoryPath = `${conceptType}`; - } - if (!fs.existsSync(directoryPath)) { - fs.mkdirSync(directoryPath); - } - } - - return directoryPath; - } +export class FileUtility { + getFileSizeText(fileSizeInBytes: number): string { + const BYTE_TO_KB = 1024; + const KB_TO_MB = 1024; + const MB_TO_GB = 1024; + + if (!Number.isFinite(fileSizeInBytes) || fileSizeInBytes < 0) { + throw new Error('Invalid file size'); + } + + let size: string | number; + let unit: string; -} \ No newline at end of file + if (fileSizeInBytes < BYTE_TO_KB) { + size = fileSizeInBytes; + unit = 'bytes'; + } else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB) { + size = (fileSizeInBytes / BYTE_TO_KB).toFixed(2); + unit = 'KB'; + } else if (fileSizeInBytes < BYTE_TO_KB * KB_TO_MB * MB_TO_GB) { + size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB).toFixed(2); + unit = 'MB'; + } else { + size = (fileSizeInBytes / BYTE_TO_KB / KB_TO_MB / MB_TO_GB).toFixed(2); + unit = 'GB'; + } + + return `${size} ${unit}`; + } + + async folderStructure( + metadata: any, + locationHierarchy: { name: any }[], + ): Promise { + const address = metadata.address; + const conceptType = metadata.conceptName; + const subjectType = metadata.subjectTypeName; + const encounterType = metadata.encounterTypeName; + const keys = locationHierarchy.map((index: { name: any }) => index.name); + const jsonAddress = JSON.parse(address); + const pathPartsArray = []; + let val = ''; + for (const key of keys) { + val = key.toString(); + if (jsonAddress[val]) { + pathPartsArray.push(jsonAddress[val].replace('/', '-')); + } + } + if (subjectType) { + pathPartsArray.push(subjectType.replace('/', '-')); + } + if (encounterType) { + pathPartsArray.push(encounterType.replace('/', '-')); + } + if (conceptType) { + pathPartsArray.push(conceptType.replace('/', '-')); + } + const directoryPath = pathPartsArray.join('/'); + if (!fs.existsSync(directoryPath)) { + fs.mkdirSync(directoryPath, { recursive: true }); + } + return directoryPath; + } +}