IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

94 lines
2.9KB

  1. import { h, Component } from 'preact';
  2. import WBTable from 'wb-table';
  3. import WBBreadcrumbs from 'wb-breadcrumbs';
  4. import { WBManifestReader } from 'wb-collection-manifest';
  5. import makeArvadosRequest from 'make-arvados-request';
  6. import wbDownloadFile from 'wb-download-file';
  7. class WBCollectionContent extends Component {
  8. constructor(...args) {
  9. super(...args);
  10. this.state.rows = [];
  11. this.state.manifestReader = null;
  12. }
  13. getUrl(params) {
  14. let res = '/collection-browse/' +
  15. (params.uuid || this.props.uuid) + '/' +
  16. encodeURIComponent(params.collectionPath || this.props.collectionPath) + '/' +
  17. (params.page || this.props.page);
  18. return res;
  19. }
  20. componentDidMount() {
  21. let { arvHost, arvToken } = this.props.app.state;
  22. let { uuid } = this.props;
  23. let select = [ 'manifest_text' ];
  24. let prom = makeArvadosRequest(arvHost, arvToken,
  25. '/arvados/v1/collections/' + uuid +
  26. '?select=' + encodeURIComponent(JSON.stringify(select)));
  27. prom = prom.then(xhr => {
  28. this.state.manifestReader = new WBManifestReader(xhr.response.manifest_text);
  29. this.prepareRows();
  30. });
  31. }
  32. componentWillReceiveProps(nextProps) {
  33. this.props = nextProps;
  34. this.prepareRows();
  35. }
  36. prepareRows() {
  37. let { manifestReader } = this.state;
  38. let { collectionPath } = this.props;
  39. let { arvHost, arvToken } = this.props.app.state;
  40. //path = path.split('/');
  41. //path = [ '.' ].concat(path);
  42. let listing = manifestReader.listDirectory('.' + collectionPath);
  43. this.setState({
  44. 'rows': listing.map(item => (
  45. (item[0] === 'd') ? [
  46. (<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1] }) }>{ item[1] }/</a>),
  47. 'Directory',
  48. null,
  49. (<div></div>)
  50. ] : [
  51. (<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1] }) }>{ item[1] }</a>),
  52. 'File',
  53. filesize(item[2]),
  54. (<div>
  55. <button class="btn btn-outline-primary mx-1" title="Download"
  56. onclick={ () => wbDownloadFile(arvHost, arvToken, manifestReader,
  57. '.' + collectionPath + '/' + item[1]) }><i class="fas fa-download"></i></button>
  58. <button class="btn btn-outline-primary mx-1" title="View"
  59. onclick={ () => wbDownloadFile(arvHost, arvToken, manifestReader,
  60. '.' + collectionPath + '/' + item[1]) }><i class="far fa-eye"></i></button>
  61. </div>)
  62. ]
  63. ))
  64. });
  65. }
  66. render({ collectionPath }, { rows }) {
  67. return (
  68. <div>
  69. <WBBreadcrumbs items={ ('.' + collectionPath).split('/') } />
  70. <WBTable columns={ [ 'Name', 'Type', 'Size', 'Actions' ] }
  71. rows={ rows } />
  72. </div>
  73. );
  74. }
  75. }
  76. WBCollectionContent.defaultProps = {
  77. 'collectionPath': '',
  78. 'page': 0
  79. };
  80. export default WBCollectionContent;