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.

99 lines
3.0KB

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