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.

111 lines
3.4KB

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