-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |