Skip to content

Commit 14f653f

Browse files
authored
Merge pull request #75 from NeuroJSON/dev-fan
Add .htaccess for routing, fix file size display, and enable download button in API tabs
2 parents 53db753 + b76b7dc commit 14f653f

File tree

11 files changed

+342
-137
lines changed

11 files changed

+342
-137
lines changed

public/.htaccess

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1+
RedirectMatch 404 /\.git
12
<IfModule mod_rewrite.c>
2-
3-
RewriteEngine on
4-
# RewriteBase /dev/dev-fan
5-
6-
# Don't rewrite files or directories
7-
RewriteCond %{REQUEST_FILENAME} -f [OR]
8-
RewriteCond %{REQUEST_FILENAME} -d
9-
RewriteRule ^ - [L]
10-
11-
# Rewrite everything else to index.html to allow html5 state links
12-
RewriteRule ^ /dev/dev-fan/index.html [L]
13-
14-
#RewriteCond %{REQUEST_FILENAME} (.*)/databases/.*$
15-
#RewriteRule ^(.*)/databases/.*  $1/index.html [QSA,L]
16-
</IfModule>
3+
RewriteEngine On
4+
RewriteBase /
5+
RewriteCond %{REQUEST_FILENAME} -f [OR]
6+
RewriteCond %{REQUEST_FILENAME} -d
7+
RewriteRule ^ - [L]
8+
RewriteRule ^ index.html [L]
9+
</IfModule>

public/img/about_page/api.png

8.95 KB
Loading

public/img/about_page/download.png

7.07 KB
Loading

public/img/about_page/preview.png

7.81 KB
Loading

public/img/about_page/search.png

8.13 KB
Loading
6.64 KB
Loading

public/img/section3_cards.png

-8.66 MB
Loading

src/components/DatasetDetailPage/LoadDatasetTabs.tsx

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import CloudDownloadIcon from "@mui/icons-material/CloudDownload";
12
import 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";
313
import { Colors } from "design/theme";
414
import React from "react";
515
import { useState } from "react";
@@ -26,6 +36,7 @@ interface LoadDatasetTabsProps {
2636
serverUrl: string;
2737
datasetDocument?: any;
2838
onekey: string;
39+
handleDownloadDataset: () => void;
2940
}
3041

3142
const 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}')
212231
links = 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}');
240265
links = 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"
299368
using json=nlohmann::ordered_json;
300369
301-
std::ifstream datafile("${docname}.json");
370+
std::ifstream datafile("${pagename}.json");
302371
json data(datafile);`}
303372
language="cpp"
304373
/>
@@ -327,7 +396,7 @@ json data(datafile);`}
327396
const jd = require("jda");
328397
global.atob = require("atob");
329398
330-
const fn = "${docname}.json";
399+
const fn = "${pagename}.json";
331400
var jstr = fs.readFileSync(fn).toString().replace(/\\n/g, "");
332401
var data = new jd(JSON.parse(jstr));
333402
data = data.decode();`}

src/components/HomePageComponents/Section3.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,10 @@ const Section3: React.FC<Section3Props> = ({ scrollToNext }) => {
115115
</IconButton>
116116

117117
<video controls style={{ width: "100%", borderRadius: "4px" }}>
118-
{/* <source
119-
src="https://neurojson.org/tutorials/overview/neurojsonio_volume_render_short.mp4"
118+
<source
119+
src="https://neurojson.io/video/preview_video.mp4"
120120
type="video/mp4"
121-
/> */}
122-
<source src="/video/preview_video.mp4" type="video/mp4" />
121+
/>
123122
Your browser does not support the video tag.
124123
</video>
125124
</Box>

0 commit comments

Comments
 (0)