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.

132 lines
4.3KB

  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 WBManifestReader from 'wb-manifest-reader';
  6. import WBPagination from 'wb-pagination';
  7. import makeArvadosRequest from 'make-arvados-request';
  8. import wbDownloadFile from 'wb-download-file';
  9. class WBCollectionContent extends Component {
  10. constructor(...args) {
  11. super(...args);
  12. this.state.rows = [];
  13. this.state.manifestReader = null;
  14. this.state.loaded = 0;
  15. this.state.total = 0;
  16. }
  17. getUrl(params) {
  18. let res = '/collection-browse/' +
  19. ('uuid' in params ? params.uuid : this.props.uuid) + '/' +
  20. encodeURIComponent('collectionPath' in params ? params.collectionPath : this.props.collectionPath) + '/' +
  21. ('page' in params ? params.page : this.props.page);
  22. return res;
  23. }
  24. componentDidMount() {
  25. let { arvHost, arvToken } = this.props.app.state;
  26. let { uuid } = this.props;
  27. let select = [ 'manifest_text' ];
  28. let prom = makeArvadosRequest(arvHost, arvToken,
  29. '/arvados/v1/collections/' + uuid +
  30. '?select=' + encodeURIComponent(JSON.stringify(select)),
  31. { 'onProgress': e => {
  32. this.setState({ 'loaded': e.loaded, 'total': e.total });
  33. } });
  34. prom = prom.then(xhr => {
  35. this.state.manifestReader = new WBManifestReader(xhr.response.manifest_text);
  36. this.prepareRows();
  37. });
  38. }
  39. componentWillReceiveProps(nextProps) {
  40. this.props = nextProps;
  41. this.prepareRows();
  42. }
  43. prepareRows() {
  44. let { manifestReader } = this.state;
  45. let { collectionPath, page, itemsPerPage } = this.props;
  46. let { arvHost, arvToken } = this.props.app.state;
  47. //path = path.split('/');
  48. //path = [ '.' ].concat(path);
  49. let listing = manifestReader.listDirectory('.' + collectionPath)
  50. const numPages = Math.ceil(listing.length / itemsPerPage);
  51. listing = listing.slice(page * itemsPerPage,
  52. page * itemsPerPage + itemsPerPage);
  53. this.setState({
  54. 'numPages': numPages,
  55. 'rows': listing.map(item => (
  56. (item[0] === 'd') ? [
  57. (<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1], 'page': 0 }) }>{ item[1] }/</a>),
  58. 'Directory',
  59. null,
  60. (<div></div>)
  61. ] : [
  62. item[1],
  63. 'File',
  64. filesize(item[2]),
  65. (<div>
  66. <button class="btn btn-outline-primary mx-1" title="Download"
  67. onclick={ () => {
  68. let prom = wbDownloadFile(arvHost, arvToken, manifestReader,
  69. '.' + collectionPath + '/' + item[1]);
  70. prom = prom.then(blocks => {
  71. const blob = new Blob(blocks);
  72. const a = document.createElement('a');
  73. a.name = item[1];
  74. a.href = window.URL.createObjectURL(blob);
  75. a.click();
  76. });
  77. } }><i class="fas fa-download"></i></button>
  78. <button class="btn btn-outline-primary mx-1" title="View"
  79. onclick={ () => {
  80. let prom = wbDownloadFile(arvHost, arvToken, manifestReader,
  81. '.' + collectionPath + '/' + item[1]);
  82. prom = prom.then(blocks => {
  83. const blob = new Blob(blocks);
  84. window.open(window.URL.createObjectURL(blob));
  85. });
  86. } }><i class="far fa-eye"></i></button>
  87. </div>)
  88. ]
  89. ))
  90. });
  91. }
  92. render({ collectionPath, page }, { manifestReader, rows, numPages, loaded, total }) {
  93. return (
  94. <div>
  95. <WBBreadcrumbs items={ ('.' + collectionPath).split('/') } />
  96. { manifestReader ? (
  97. <div>
  98. <WBTable columns={ [ 'Name', 'Type', 'Size', 'Actions' ] }
  99. rows={ rows } />
  100. <WBPagination activePage={ page } numPages={ numPages }
  101. getPageUrl={ page => this.getUrl({ 'page': page }) } />
  102. </div>
  103. ) : (
  104. <div>Downloading manifest: { filesize(loaded) }</div>
  105. ) }
  106. </div>
  107. );
  108. }
  109. }
  110. WBCollectionContent.defaultProps = {
  111. 'collectionPath': '',
  112. 'page': 0,
  113. 'itemsPerPage': 20
  114. };
  115. export default WBCollectionContent;