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.

85 lines
2.4KB

  1. import { h, Component } from 'preact';
  2. import { route } from 'preact-router';
  3. import makeArvadosRequest from 'make-arvados-request';
  4. import WBTable from 'wb-table';
  5. import WBPagination from 'wb-pagination';
  6. class WBProjectListing extends Component {
  7. constructor(...args) {
  8. super(...args);
  9. this.state.rows = [];
  10. this.state.numPages = 0;
  11. }
  12. componentDidMount() {
  13. this.fetchItems();
  14. }
  15. prepareRows(items) {
  16. let { app } = this.props;
  17. return items.map(item => [
  18. (<div>
  19. <div>
  20. <a href="#"
  21. onclick={ e => { e.preventDefault(); route('/browse/' + item['uuid']) }}>{ item['name'] }</a>
  22. </div>
  23. <div>{ item['uuid'] }</div>
  24. </div>),
  25. item['description'],
  26. item['owner_uuid'],
  27. (<div>
  28. <button class="btn btn-outline-warning m-1" title="Add to Toolbox"
  29. onclick={ () => (app.addToToolbox(item.uuid)) }>
  30. <i class="fas fa-toolbox"></i>
  31. </button>
  32. </div>)
  33. ]);
  34. }
  35. fetchItems() {
  36. let i = this.props.activePage;
  37. let filters = [
  38. [ 'group_class', '=', 'project' ]
  39. ];
  40. if (this.props.ownerUuid)
  41. filters.push([ 'owner_uuid', '=', this.props.ownerUuid ]);
  42. let prom = makeArvadosRequest(this.props.arvHost, this.props.arvToken,
  43. '/arvados/v1/groups?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  44. '&limit=' + encodeURIComponent(this.props.itemsPerPage) +
  45. '&offset=' + encodeURIComponent(this.props.itemsPerPage * i));
  46. prom = prom.then(xhr =>
  47. this.setState({
  48. 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']),
  49. 'rows': this.prepareRows(xhr.response['items'])
  50. }));
  51. }
  52. componentWillReceiveProps(nextProps, nextState) {
  53. // this.setState({ 'rows': [] }); // .rows = [];
  54. this.props = nextProps;
  55. this.fetchItems();
  56. }
  57. render({ arvHost, arvToken, ownerUuid, activePage, onPageChanged }, { rows, numPages }) {
  58. return (
  59. <div>
  60. <WBTable columns={ [ 'Name', 'Description', 'Owner', 'Actions' ] }
  61. rows={ rows } />
  62. <WBPagination numPages={ numPages }
  63. activePage={ activePage }
  64. onPageChanged={ i => onPageChanged(i) } />
  65. </div>
  66. );
  67. }
  68. }
  69. WBProjectListing.defaultProps = {
  70. 'itemsPerPage': 100,
  71. 'ownerUuid': null
  72. };
  73. export default WBProjectListing;