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!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.3KB

  1. //
  2. // Copyright (C) Stanislaw Adaszewski, 2020
  3. // Contact: s.adaszewski@gmail.com
  4. // Website: https://adared.ch/wba
  5. // License: GNU Affero General Public License, Version 3
  6. //
  7. import { h, Component } from 'preact';
  8. import WBTable from 'wb-table';
  9. import WBPagination from 'wb-pagination';
  10. import makeArvadosRequest from 'make-arvados-request';
  11. class WBBrowseDialogCollectionList extends Component {
  12. constructor(...args) {
  13. super(...args);
  14. this.state.rows = [];
  15. }
  16. componentDidMount() {
  17. this.fetchRows();
  18. }
  19. componentWillReceiveProps(nextProps) {
  20. this.props = nextProps;
  21. this.fetchRows();
  22. }
  23. prepareRows(items) {
  24. const { navigate, selectWhat, makeSelectionCell } = this.props;
  25. return items.map(it => [
  26. ([].concat(selectWhat).indexOf('directory') !== -1 ? makeSelectionCell(it.uuid + '/') : null),
  27. (
  28. <a href="#" onclick={ e => { e.preventDefault();
  29. navigate('/browse-dialog/content/' + it.uuid + '////'); } }>{ it.name }</a>
  30. ),
  31. it.uuid
  32. ]);
  33. }
  34. fetchRows() {
  35. const { arvHost, arvToken } = this.props.app.state;
  36. const { ownerUuid, textSearch, page, itemsPerPage } = this.props;
  37. const filters = [];
  38. if (ownerUuid)
  39. filters.push(['owner_uuid', '=', ownerUuid]);
  40. if (textSearch)
  41. filters.push(['name', 'ilike', '%' + textSearch + '%']);
  42. let prom = makeArvadosRequest(arvHost, arvToken,
  43. '/arvados/v1/collections?filters=' +
  44. encodeURIComponent(JSON.stringify(filters)) +
  45. '&limit=' + itemsPerPage +
  46. '&offset=' + (itemsPerPage * page));
  47. prom = prom.then(xhr => this.setState({
  48. 'rows': this.prepareRows(xhr.response.items),
  49. 'numPages': Math.ceil(xhr.response.items_available / itemsPerPage)
  50. }));
  51. return prom;
  52. }
  53. render({ selectWhat, page, navigate }, { rows, numPages }) {
  54. return (
  55. <div>
  56. <WBTable columns={ ['', 'Name', 'UUID'] }
  57. headerClasses={ ['w-1'] }
  58. rows={ rows } />
  59. <WBPagination activePage={ page } numPages={ numPages }
  60. onPageChanged={ i => navigate({ 'bottomPage': i }) } />
  61. </div>
  62. );
  63. }
  64. }
  65. WBBrowseDialogCollectionList.defaultProps = {
  66. 'itemsPerPage': 20
  67. };
  68. export default WBBrowseDialogCollectionList;