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.

104 lines
3.2KB

  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. import WBNameAndUuid from 'wb-name-and-uuid';
  7. import urlForObject from 'url-for-object';
  8. class WBProjectListing extends Component {
  9. constructor(...args) {
  10. super(...args);
  11. this.state.rows = [];
  12. this.state.numPages = 0;
  13. }
  14. componentDidMount() {
  15. this.fetchItems();
  16. }
  17. prepareRows(items) {
  18. const { app, renderRenameLink, renderDeleteButton,
  19. renderSelectionCell, renderSharingButton,
  20. renderEditDescription } = this.props;
  21. return items.map(item => [
  22. renderSelectionCell(item),
  23. (<div>
  24. <div>
  25. <a href={ '/browse/' + item.uuid }>
  26. { item['name'] }
  27. </a> { renderRenameLink(item, () => this.fetchItems()) }
  28. </div>
  29. <div>{ item['uuid'] }</div>
  30. </div>),
  31. (<div>
  32. { item['description'] } { renderEditDescription(item, () => this.fetchItems()) }
  33. </div>),
  34. ( <WBNameAndUuid app={ app } uuid={ item['owner_uuid'] } lazy={ true } /> ),
  35. (<div>
  36. <a class="btn btn-outline-primary m-1" title="Properties"
  37. href={ urlForObject(item, 'properties') }>
  38. <i class="fas fa-list-ul"></i>
  39. </a>
  40. { renderDeleteButton(item, () => this.fetchItems()) }
  41. { renderSharingButton(item) }
  42. </div>)
  43. ]);
  44. }
  45. fetchItems() {
  46. let { activePage, mode, itemsPerPage, ownerUuid, app, textSearch } = this.props;
  47. let { arvHost, arvToken } = app.state;
  48. let filters = [
  49. [ 'group_class', '=', 'project' ]
  50. ];
  51. if (ownerUuid)
  52. filters.push([ 'owner_uuid', '=', ownerUuid ]);
  53. if (textSearch)
  54. filters.push([ 'any', 'ilike', '%' + textSearch + '%' ]);
  55. let prom = makeArvadosRequest(arvHost, arvToken,
  56. '/arvados/v1/groups' + (mode === 'shared-with-me' ? '/shared' : '') +
  57. '?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  58. '&limit=' + itemsPerPage +
  59. '&offset=' + (itemsPerPage * activePage));
  60. prom = prom.then(xhr =>
  61. this.setState({
  62. 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']),
  63. 'rows': this.prepareRows(xhr.response['items'])
  64. }));
  65. }
  66. componentWillReceiveProps(nextProps, nextState) {
  67. // this.setState({ 'rows': [] }); // .rows = [];
  68. this.props = nextProps;
  69. this.fetchItems();
  70. }
  71. render({ arvHost, arvToken, ownerUuid, activePage, getPageUrl }, { rows, numPages }) {
  72. return (
  73. <div>
  74. <WBTable columns={ [ '', 'Name', 'Description', 'Owner', 'Actions' ] }
  75. headerClasses={ [ 'w-1' ] }
  76. rows={ rows } />
  77. <WBPagination numPages={ numPages }
  78. activePage={ activePage }
  79. getPageUrl={ getPageUrl } />
  80. </div>
  81. );
  82. }
  83. }
  84. WBProjectListing.defaultProps = {
  85. 'itemsPerPage': 100,
  86. 'ownerUuid': null,
  87. 'renderRenameLink': () => null,
  88. 'renderDeleteButton': () => null,
  89. 'renderSelectionCell': () => null,
  90. 'renderEditDescription': () => null
  91. };
  92. export default WBProjectListing;