1+ import CloudDownloadIcon from "@mui/icons-material/CloudDownload" ;
12import ContentCopyIcon from "@mui/icons-material/ContentCopy" ;
2- import { Tabs , Tab , Box , Typography , IconButton , Tooltip } from "@mui/material" ;
3+ import {
4+ Tabs ,
5+ Tab ,
6+ Box ,
7+ Typography ,
8+ IconButton ,
9+ Tooltip ,
10+ Link ,
11+ Button ,
12+ } from "@mui/material" ;
313import { Colors } from "design/theme" ;
414import React from "react" ;
515import { useState } from "react" ;
@@ -26,6 +36,7 @@ interface LoadDatasetTabsProps {
2636 serverUrl : string ;
2737 datasetDocument ?: any ;
2838 onekey : string ;
39+ handleDownloadDataset : ( ) => void ;
2940}
3041
3142const flashcardStyles = {
@@ -68,6 +79,7 @@ const LoadDatasetTabs: React.FC<LoadDatasetTabsProps> = ({
6879 serverUrl,
6980 datasetDocument,
7081 onekey,
82+ handleDownloadDataset,
7183} ) => {
7284 const [ tabIndex , setTabIndex ] = useState ( 0 ) ;
7385 const handleTabChange = ( event : React . SyntheticEvent , newValue : number ) => {
@@ -79,8 +91,15 @@ const LoadDatasetTabs: React.FC<LoadDatasetTabsProps> = ({
7991 const datasetName = datasetDesc ?. Name ?. includes ( " - " )
8092 ? datasetDesc . Name . split ( " - " ) [ 1 ]
8193 : datasetDesc ?. Name || datasetDocument ?. _id || docname ;
94+ console . log ( "datasetName" , datasetName ) ;
95+ console . log ( "dbname" , dbname ) ;
96+ console . log ( "pagename" , pagename ) ;
97+ console . log ( "onekey" , onekey ) ;
98+ // const datasetUrl = datasetName
99+ // ? `${serverUrl}${dbname}/${encodeURIComponent(datasetName)}/`
100+ // : `${serverUrl}${dbname}/`;
82101 const datasetUrl = datasetName
83- ? `${ serverUrl } ${ dbname } /${ encodeURIComponent ( datasetName ) } / `
102+ ? `${ serverUrl } ${ dbname } /${ pagename } `
84103 : `${ serverUrl } ${ dbname } /` ;
85104
86105 const TabPanel = ( {
@@ -186,8 +205,8 @@ const LoadDatasetTabs: React.FC<LoadDatasetTabsProps> = ({
186205 >
187206 < Tab label = "Python (REST API)" />
188207 < Tab label = "MATLAB (REST API)" />
189- < Tab label = "MATLAB/Octave (Local)" />
190208 < Tab label = "Python (Local)" />
209+ < Tab label = "MATLAB/Octave (Local)" />
191210 < Tab label = "C++" />
192211 < Tab label = "Node.js" />
193212 </ Tabs >
@@ -212,7 +231,7 @@ data = jd.loadurl('${datasetUrl}')
212231links = jd.jsonpath(data, '$.._DataLink_')
213232
214233# Download & cache anatomical nii.gz data for sub-01/sub-02
215- jd.jdlink(links, {'regex': 'anat/sub-0[12]_.*\\ .nii'})` }
234+ jd.jdlink(links, {'regex': 'anat/sub-0[12]_.*\.nii'})` }
216235 language = "python"
217236 />
218237 </ Box >
@@ -225,10 +244,16 @@ jd.jdlink(links, {'regex': 'anat/sub-0[12]_.*\\.nii'})`}
225244 Load by URL with REST-API in MATLAB
226245 </ Typography >
227246 < Typography > Install:</ Typography >
228- < CopyableCodeBlock
229- code = { `Download and addpath to JSONLab` }
230- language = "text"
231- />
247+ < Typography >
248+ Download and addpath to{ " " }
249+ < Link
250+ href = "https://github.com/NeuroJSON/jsonlab"
251+ target = "_blank"
252+ rel = "noopener noreferrer"
253+ >
254+ JSONLab
255+ </ Link >
256+ </ Typography >
232257 < Typography > Load from URL:</ Typography >
233258 < CopyableCodeBlock
234259 code = { `data = loadjson('${ datasetUrl } ');
@@ -240,45 +265,79 @@ data = webread('${datasetUrl}');
240265links = jsonpath(data, '$.._DataLink_');
241266
242267% Download & cache anatomical nii.gz data for sub-01/sub-02
243- niidata = jdlink(links, 'regex', 'anat/sub-0[12]_.*\\ .nii');` }
268+ niidata = jdlink(links, 'regex', 'anat/sub-0[12]_.*\.nii');` }
244269 language = "matlab"
245270 />
246271 </ Box >
247272 </ TabPanel >
248273
249- { /* FLASHCARD 3: MATLAB/Octave */ }
274+ { /* FLASHCARD 3: Python Local */ }
250275 < TabPanel value = { tabIndex } index = { 2 } >
251276 < Box style = { flashcardStyles . flashcard } >
252277 < Typography variant = "h6" style = { flashcardStyles . flashcardTitle } >
253- Use in MATLAB/Octave
278+ Use in Python
254279 </ Typography >
280+
281+ < Typography sx = { { marginBottom : 1 } } > Download dataset</ Typography >
282+ < Button
283+ variant = "contained"
284+ startIcon = { < CloudDownloadIcon /> }
285+ onClick = { handleDownloadDataset }
286+ sx = { {
287+ backgroundColor : Colors . purple ,
288+ color : Colors . lightGray ,
289+ mb : 2 ,
290+ "&:hover" : {
291+ backgroundColor : Colors . secondaryPurple ,
292+ } ,
293+ } }
294+ >
295+ Download Metadata
296+ </ Button >
255297 < Typography > Load:</ Typography >
256298 < CopyableCodeBlock
257- code = { `data = loadjd('${ docname } .json');` }
258- language = "matlab"
299+ code = { `import jdata as jd
300+ data = jd.load('${ pagename } .json')` }
301+ language = "python"
259302 />
260303 < Typography > Read value:</ Typography >
261- < CopyableCodeBlock
262- code = { `data.(encodevarname('${ onekey } '))` }
263- language = "matlab"
264- />
304+ < CopyableCodeBlock code = { `data["${ onekey } "]` } language = "python" />
265305 </ Box >
266306 </ TabPanel >
267307
268- { /* FLASHCARD 4: Python Local */ }
308+ { /* FLASHCARD 4: MATLAB/Octave */ }
269309 < TabPanel value = { tabIndex } index = { 3 } >
270310 < Box style = { flashcardStyles . flashcard } >
271311 < Typography variant = "h6" style = { flashcardStyles . flashcardTitle } >
272- Use in Python
312+ Use in MATLAB/Octave
273313 </ Typography >
314+ < Typography sx = { { marginBottom : 1 } } > Download dataset</ Typography >
315+ < Button
316+ variant = "contained"
317+ startIcon = { < CloudDownloadIcon /> }
318+ onClick = { handleDownloadDataset }
319+ sx = { {
320+ backgroundColor : Colors . purple ,
321+ color : Colors . lightGray ,
322+ mb : 2 ,
323+ "&:hover" : {
324+ backgroundColor : Colors . secondaryPurple ,
325+ } ,
326+ } }
327+ >
328+ Download Metadata
329+ </ Button >
274330 < Typography > Load:</ Typography >
275331 < CopyableCodeBlock
276- code = { `import jdata as jd
277- data = jd.load ('${ docname } .json')` }
278- language = "python "
332+ // code={`data = loadjd('${docname}.json');`}
333+ code = { ` data = loadjd ('${ pagename } .json'); `}
334+ language = "matlab "
279335 />
280336 < Typography > Read value:</ Typography >
281- < CopyableCodeBlock code = { `data["${ onekey } "]` } language = "python" />
337+ < CopyableCodeBlock
338+ code = { `data.(encodevarname('${ onekey } '))` }
339+ language = "matlab"
340+ />
282341 </ Box >
283342 </ TabPanel >
284343
@@ -289,16 +348,26 @@ data = jd.load('${docname}.json')`}
289348 Use in C++
290349 </ Typography >
291350 < Typography > Install:</ Typography >
292- < CopyableCodeBlock
351+ { /* <CopyableCodeBlock
293352 code={`Download JSON for Modern C++ json.hpp`}
294353 language="text"
295- />
354+ /> */ }
355+ < Typography >
356+ Download{ " " }
357+ < Link
358+ href = "https://raw.githubusercontent.com/nlohmann/json/v3.11.3/single_include/nlohmann/json.hpp"
359+ target = "_blank"
360+ rel = "noopener noreferrer"
361+ >
362+ JSON for Modern C++ json.hpp
363+ </ Link >
364+ </ Typography >
296365 < Typography > Load:</ Typography >
297366 < CopyableCodeBlock
298367 code = { `#include "json.hpp"
299368using json=nlohmann::ordered_json;
300369
301- std::ifstream datafile("${ docname } .json");
370+ std::ifstream datafile("${ pagename } .json");
302371json data(datafile);` }
303372 language = "cpp"
304373 />
@@ -327,7 +396,7 @@ json data(datafile);`}
327396const jd = require("jda");
328397global.atob = require("atob");
329398
330- const fn = "${ docname } .json";
399+ const fn = "${ pagename } .json";
331400var jstr = fs.readFileSync(fn).toString().replace(/\\n/g, "");
332401var data = new jd(JSON.parse(jstr));
333402data = data.decode();` }
0 commit comments