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.

98 lines
2.9KB

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