Skip to content

Commit

Permalink
add pathdb button
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed Nov 20, 2023
1 parent 5758564 commit cac7603
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 12 deletions.
22 changes: 11 additions & 11 deletions config/wines.csv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
,fixed acidity,volatile acidity,citric acid,residual sugar,chlorides,free sulfur dioxide,total sulfur dioxide,density,pH,sulphates,alcohol,quality,wine_type,quality_label
0,7.0,0.17,0.74,12.8,0.045,24.0,126.0,0.9942,3.26,0.38,12.2,8,white,high
1,7.7,0.64,0.21,2.2,0.077,32.0,133.0,0.9956,3.27,0.45,9.9,5,red,low
2,6.8,0.39,0.34,7.4,0.02,38.0,133.0,0.99212,3.18,0.44,12.0,7,white,medium
3,6.3,0.28,0.47,11.2,0.04,61.0,183.0,0.99592,3.12,0.51,9.5,6,white,medium
4,7.4,0.35,0.2,13.9,0.054,63.0,229.0,0.99888,3.11,0.5,8.9,6,white,medium
5,7.2,0.53,0.14,2.1,0.064,15.0,29.0,0.99323,3.35,0.61,12.1,6,red,medium
6,7.5,0.27,0.31,17.7,0.051,33.0,173.0,0.999,3.09,0.64,10.2,5,white,low
7,6.8,0.11,0.27,8.6,0.044,45.0,104.0,0.99454,3.2,0.37,9.9,6,white,medium
8,9.0,0.44,0.49,2.4,0.078,26.0,121.0,0.9978,3.23,0.58,9.2,5,red,low
9,7.1,0.23,0.3,2.6,0.034,62.0,148.0,0.99121,3.03,0.56,11.3,7,white,medium
pathdbid,fixed acidity,volatile acidity,citric acid,residual sugar,chlorides,free sulfur dioxide,total sulfur dioxide,density,pH,sulphates,alcohol,quality,wine_type,quality_label
21550,7.0,0.17,0.74,12.8,0.045,24.0,126.0,0.9942,3.26,0.38,12.2,8,white,high
21551,7.7,0.64,0.21,2.2,0.077,32.0,133.0,0.9956,3.27,0.45,9.9,5,red,low
21552,6.8,0.39,0.34,7.4,0.02,38.0,133.0,0.99212,3.18,0.44,12.0,7,white,medium
21553,6.3,0.28,0.47,11.2,0.04,61.0,183.0,0.99592,3.12,0.51,9.5,6,white,medium
21554,7.4,0.35,0.2,13.9,0.054,63.0,229.0,0.99888,3.11,0.5,8.9,6,white,medium
21555,7.2,0.53,0.14,2.1,0.064,15.0,29.0,0.99323,3.35,0.61,12.1,6,red,medium
21556,7.5,0.27,0.31,17.7,0.051,33.0,173.0,0.999,3.09,0.64,10.2,5,white,low
21557,6.8,0.11,0.27,8.6,0.044,45.0,104.0,0.99454,3.2,0.37,9.9,6,white,medium
21558,9.0,0.44,0.49,2.4,0.078,26.0,121.0,0.9978,3.23,0.58,9.2,5,red,low
21559,7.1,0.23,0.3,2.6,0.034,62.0,148.0,0.99121,3.03,0.56,11.3,7,white,medium
10,7.4,0.28,0.42,19.8,0.066,53.0,195.0,1.0,2.96,0.44,9.1,5,white,low
11,7.8,0.28,0.22,1.4,0.056,24.0,130.0,0.9944,3.28,0.48,9.5,5,white,low
12,6.2,0.21,0.28,5.7,0.028,45.0,121.0,0.99168,3.21,1.08,12.15,7,white,medium
Expand Down
5 changes: 5 additions & 0 deletions config/wines.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"UNIT_OF_GRID_VIEW": [230, 210],
"MARGIN_OF_GRID_VIEW": [10, 10],
"RESIZABLE" : 0,
"DOWNLOAD_FIELD": "pathdbid",
"DRAGGABLE" : 0,
"HAS_SETTINGS" : 0,
"DATA_RESOURCE_URL": "./config/wines.csv",
Expand Down Expand Up @@ -89,6 +90,10 @@
"description": "Showing Collection Data",
"chartType": "VIS_DATA_TABLE",
"fields": [
{
"dataKey": "pathdbid",
"label": "ID"
},
{
"dataKey": "wine_type",
"label": "Wine Type"
Expand Down
4 changes: 3 additions & 1 deletion source/components/ESNavbar/ESNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import Form from 'react-bootstrap/Form';
import Nav from 'react-bootstrap/Nav';
import PropTypes from 'prop-types';
import DownloadButton from '../DownloadButton';
import PathdbDownloadButton from '../PathdbDownloadButton';
import HomeButton from '../HomeButton';
import Settings from '../Settings/Settings';

function ESNavbar(props) {
const {
url, title, max, now, progressLabel, data, color,
url, title, max, now, progressLabel, data, color, externalDownloadField,
} = props;
document.title = title || 'Eaglescope';

Expand All @@ -24,6 +25,7 @@ function ESNavbar(props) {
>
{url ? <HomeButton url={url} /> : null}
<DownloadButton data={data} title={title} />
<PathdbDownloadButton data={data} title={title} field={externalDownloadField} />
<Navbar.Brand href={url || '#'}>{title || 'Eaglescope'}</Navbar.Brand>
<Nav className="mr-auto" />
<Form inline="true">
Expand Down
1 change: 1 addition & 0 deletions source/components/Eaglescope/Eaglescope.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function Eaglescope() {
progressLabel={progressAttrs.label}
data={[filteredData, data]}
color={config.THEME_COLOR}
externalDownloadField={config.DOWNLOAD_FIELD}
/>
<SearchBar filterAdded={addFiltersHandler} filterRemove={removeFiltersHandler} />
<FilterOperationPanel filters={filters} filterRemove={removeFiltersHandler} />
Expand Down
65 changes: 65 additions & 0 deletions source/components/PathdbDownloadButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { PureComponent } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import Button from 'react-bootstrap/Button';
import PropTypes from 'prop-types';

class PathdbDownloadButton extends PureComponent {
download() {
let data = this.props.data[0];
if (data.length === 0) {
data = this.props.data[1];
}
let limitedData = data.slice(0, 10);
// trigger downloads from pathdb
for (let record of limitedData){
if (record[this.props.field]){
console.log("trying to get metadata for slide with pathdb id", record[this.props.field])
fetch("/node/" + record[this.props.field] + "?_format=json", {mode: "cors"}).then(x=>x.json()).then(x=>{
console.log("got something for pathdb id", x['field_wsiimage'][0]['url'])
let link = document.createElement('a');
link.href = x['field_wsiimage'][0]['url']
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}).catch(console.error)
}
}
const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
const href = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = href;
link.download = this.props.title || 'download.json';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(href);
}

render() {
if (this.props.field){
return (
<Button
size="lg"
style={{
background: 'none',
border: 'none',
}}
id={this.id}
onClick={() => {
this.download();
}}
>
<FontAwesomeIcon size="1x" icon="images" />
</Button>
);
}
}
}

export default PathdbDownloadButton;

PathdbDownloadButton.propTypes = {
title: PropTypes.string.isRequired,
data: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.shape({}))).isRequired,
field: PropTypes.string.isRequired,
};

0 comments on commit cac7603

Please sign in to comment.