Skip to content

Commit

Permalink
upload multiple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
erasta committed Nov 12, 2024
1 parent 6f0f558 commit 07b9351
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions client/src/IO/UploadDevices/UploadDevicesButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export const UploadDevicesButton = ({ data, experiment, setData }) => {
throw "empty file";
}

setDevicesToUpload([]);
const alldevs = [];
for (const file of files) {
const devices = await obtainDevicesFromFile(file);
setDevicesToUpload(prev => [...prev, ...devices])
alldevs.push(...devices);
}
setDevicesToUpload(alldevs);
} catch (error) {
setErrors([error?.message || error]);
}
Expand Down
7 changes: 5 additions & 2 deletions client/src/IO/UploadDevices/UploadDevicesFieldsDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { groupBy } from "lodash";
import { UploadDevicesTypeFieldsMatcher } from "./UploadDevicesTypeFieldsMatcher";
import { useState } from "react";
import { changeDeviceOnTrial } from "./changeDeviceOnTrial";
import { FIELD_UNASSIGNED, LOCATION_FIELDS } from "./uploadDefs";
import { FIELD_TYPE, FIELD_UNASSIGNED, LOCATION_FIELDS } from "./uploadDefs";

export const UploadDevicesFieldsDialog = ({ devicesToUpload, setDevicesToUpload, data, setData, experiment }) => {

Expand All @@ -18,7 +18,7 @@ export const UploadDevicesFieldsDialog = ({ devicesToUpload, setDevicesToUpload,
setDevicesToUpload(_ => []);
};

const devicesByType = Object.values(groupBy(devicesToUpload, x => x[1]));
const devicesByType = Object.values(groupBy(devicesToUpload, x => x[FIELD_TYPE]));

let disabled = false;
for (const a of Object.values(attrMatch)) {
Expand All @@ -29,6 +29,9 @@ export const UploadDevicesFieldsDialog = ({ devicesToUpload, setDevicesToUpload,
}
}

console.log(devicesToUpload)
console.log(devicesByType)

return (
<Dialog
open={true}
Expand Down
6 changes: 4 additions & 2 deletions client/src/IO/UploadDevices/obtainDevicesFromFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ export const obtainDevicesFromFile = async (file: File): Promise<DevicesFromFile
}

if (ext === 'zip') {
const devices = [];
const devices: DevicesFromFile[] = [];

const zip = await JSZip().loadAsync(file);
for (const z of Object.values(zip.files)) {
const zext = z?.name?.split('.')?.pop()?.toLowerCase() || '';

if (zext === 'csv' || zext?.endsWith('json')) {
const text = await z.async('text');
return obtainDeviceFromText(zext, text) || [];
const currdevs = obtainDeviceFromText(zext, text) || [];
devices.push(...currdevs);
}
}

Expand Down

0 comments on commit 07b9351

Please sign in to comment.