From 60184ea91481e73d1395e753a2f4a59260466ac2 Mon Sep 17 00:00:00 2001 From: Suhas Vishwanath Date: Thu, 21 Sep 2023 18:51:44 +0530 Subject: [PATCH 1/5] avniproject/avni-media#152 | Vinay/Suhas | Fix wording of alert message and selection message --- client/components/ImageList.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/components/ImageList.tsx b/client/components/ImageList.tsx index cb14a09..a98367c 100644 --- a/client/components/ImageList.tsx +++ b/client/components/ImageList.tsx @@ -401,10 +401,7 @@ export default function ImageList() { const [showModal, setShowModal] = useState(false); const handleSendSelectedImages = async (inputValue: any) => { - alert( - `We are processing your download request. Once the download is ready, it will be available under Available Downloads. - A maxiumim of 1000 images will be included in the download bundle.` - ); + alert(`We are processing your download request. Once the download is ready, it will be available under Available Downloads. At most 1000 media items will be included in the download bundle.`); if (selectAllPages) { const options = { headers: { @@ -898,8 +895,9 @@ export default function ImageList() { indeterminate={selectAllInPage[currentPage] === SOME_SELECTED} disabled={selectAllPages} />} /> - {(selectAllInPage[currentPage] === ALL_SELECTED) && - {selectAllPages ? "CLEAR SELECTION" : "SELECT ALL PAGES"}} + {(selectAllInPage[currentPage] === ALL_SELECTED) && <> + {selectAllPages ? "Clear selection" : "Select all media matching filter"} + } From 082712bdd33cde752cdcd6606cf445f1482ac6d8 Mon Sep 17 00:00:00 2001 From: Suhas Vishwanath Date: Mon, 25 Sep 2023 17:02:13 +0530 Subject: [PATCH 2/5] avniproject/avni-media#152 - Fix QA issue of needing to click select all twice on page 2 and beyond. Default to NONE_SELECTED on new page open --- client/components/ImageList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/ImageList.tsx b/client/components/ImageList.tsx index a98367c..934c9ef 100644 --- a/client/components/ImageList.tsx +++ b/client/components/ImageList.tsx @@ -361,7 +361,7 @@ export default function ImageList() { const toggleCheckAllImagesInCurrentPage = () => { setSelectAllInPage((oldValue: any) => { - const currentValue = oldValue[currentPage]; + const currentValue = oldValue[currentPage] || NONE_SELECTED; const nextValue = (currentValue === NONE_SELECTED || currentValue === SOME_SELECTED) ? ALL_SELECTED: NONE_SELECTED; return {...oldValue, [currentPage]: nextValue} }); From 2f63a48bf70bfeb5e1920a547a0c3e555b0f5706 Mon Sep 17 00:00:00 2001 From: Suhas Vishwanath Date: Mon, 25 Sep 2023 18:02:22 +0530 Subject: [PATCH 3/5] avniproject/avni-media#152 | Show message on image selection --- client/components/ImageList.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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

+ }
From 7567abfb9de10508c4878a423a6ac56682360f66 Mon Sep 17 00:00:00 2001 From: Suhas Vishwanath Date: Tue, 26 Sep 2023 11:56:47 +0530 Subject: [PATCH 4/5] avniproject/avni-media#152 | Replace / with - in media directory path parts --- server/src/utils/file-utility.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/utils/file-utility.ts b/server/src/utils/file-utility.ts index eb475b7..2b1adef 100644 --- a/server/src/utils/file-utility.ts +++ b/server/src/utils/file-utility.ts @@ -37,16 +37,16 @@ export class FileUtility{ locationHierarchy: { name: any; }[] ): Promise { const address = metadata.address; - const conceptType = metadata.conceptName; - const subjectType = metadata.subjectTypeName; - const encounterType = metadata.encounterTypeName; + const conceptType = metadata.conceptName.replace("/", "-"); + const subjectType = metadata.subjectTypeName.replace("/", "-"); + const encounterType = metadata.encounterTypeName.replace("/", "-"); const keys = locationHierarchy.map((index: { name: any; }) => index.name); - const jsonadd = JSON.parse(address); + const jsonAddress = JSON.parse(address); const addressArray = []; let val ='' for (const key of keys) { val= key.toString() - addressArray.push(jsonadd[val]); + addressArray.push(jsonAddress[val].replace("/", "-")); } let directoryPath = '' await Promise.all( From 761e70e334ba4d572ab6b361678361f9a07d99c7 Mon Sep 17 00:00:00 2001 From: Suhas Vishwanath Date: Tue, 26 Sep 2023 12:28:38 +0530 Subject: [PATCH 5/5] avniproject/avni-media#152 | Fix prettier errors and cleanup foldrer structure creation code --- server/src/utils/file-utility.ts | 164 ++++++++++++------------------- 1 file changed, 65 insertions(+), 99 deletions(-) diff --git a/server/src/utils/file-utility.ts b/server/src/utils/file-utility.ts index 2b1adef..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.replace("/", "-"); - const subjectType = metadata.subjectTypeName.replace("/", "-"); - const encounterType = metadata.encounterTypeName.replace("/", "-"); - const keys = locationHierarchy.map((index: { name: any; }) => index.name); - const jsonAddress = JSON.parse(address); - const addressArray = []; - let val ='' - for (const key of keys) { - val= key.toString() - addressArray.push(jsonAddress[val].replace("/", "-")); - } - 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; + } +}