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.

114 lines
3.3KB

  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 makeArvadosRequest from 'make-arvados-request';
  9. import WBPagination from 'wb-pagination';
  10. import WBTable from 'wb-table';
  11. class WBBrowseDialogProjectList extends Component {
  12. constructor(...args) {
  13. super(...args);
  14. this.state.rows = [];
  15. this.state.history = [];
  16. }
  17. componentDidMount() {
  18. this.fetchRows();
  19. }
  20. componentWillReceiveProps(nextProps) {
  21. this.props = nextProps;
  22. this.fetchRows();
  23. }
  24. prepareRows(items) {
  25. const { navigate, selectWhat, makeSelectionCell } = this.props;
  26. return items.map(it => ([].concat(selectWhat).indexOf('owner') !== -1 ? [ makeSelectionCell(it.uuid, 'project') ] : []).concat([
  27. (
  28. <a href="#" onclick={ e => {
  29. e.preventDefault();
  30. navigate('/browse-dialog/browse/' + it.uuid);
  31. } }>{ it.name }</a>
  32. ),
  33. it.uuid
  34. ]));
  35. }
  36. fetchSharedWithMe() {
  37. const { arvHost, arvToken, currentUser } = this.props.app.state;
  38. const { textSearch, itemsPerPage, page } = this.props;
  39. const filters = [
  40. ['group_class', '=', 'project']
  41. ];
  42. if (textSearch)
  43. filters.push([ 'name', 'ilike', '%' + textSearch + '%']);
  44. const prom = makeArvadosRequest(arvHost, arvToken,
  45. '/arvados/v1/groups/shared?filters=' +
  46. encodeURIComponent(JSON.stringify(filters)) +
  47. '&limit=' + itemsPerPage +
  48. '&offset=' + (itemsPerPage * page));
  49. return prom;
  50. }
  51. fetchOwned() {
  52. const { arvHost, arvToken } = this.props.app.state;
  53. const { ownerUuid, page, textSearch, itemsPerPage } = this.props;
  54. const filters = [
  55. ['group_class', '=', 'project']
  56. ];
  57. if (ownerUuid)
  58. filters.push(['owner_uuid', '=', ownerUuid]);
  59. if (textSearch)
  60. filters.push(['name', 'ilike', '%' + textSearch + '%']);
  61. let prom = makeArvadosRequest(arvHost, arvToken,
  62. '/arvados/v1/groups?filters=' +
  63. encodeURIComponent(JSON.stringify(filters)) +
  64. '&limit=' + itemsPerPage +
  65. '&offset=' + (page * itemsPerPage));
  66. return prom;
  67. }
  68. fetchRows() {
  69. const { mode, itemsPerPage } = this.props;
  70. let prom = (mode === 'shared-with-me') ?
  71. this.fetchSharedWithMe() :
  72. this.fetchOwned();
  73. prom = prom.then(xhr => {
  74. this.setState({
  75. 'rows': this.prepareRows(xhr.response.items),
  76. 'numPages': Math.ceil(xhr.response.items_available / itemsPerPage)
  77. });
  78. });
  79. return prom;
  80. }
  81. render({ app, navigate, page, selectWhat }, { numPages, rows }) {
  82. return (
  83. <div>
  84. <WBTable columns={ ([].concat(selectWhat).indexOf('owner') !== -1 ? [''] : []).concat(['Name', 'UUID']) }
  85. headerClasses={ [].concat(selectWhat).indexOf('owner') !== -1 ? ['col-sm-1', 'col-sm-4', 'col-sm-4'] : [] }
  86. rows={ rows } />
  87. <WBPagination numPages={ numPages } activePage={ page }
  88. onPageChanged={ i => navigate({ 'topPage': i }) }
  89. chunkSize="3" />
  90. </div>
  91. );
  92. }
  93. }
  94. WBBrowseDialogProjectList.defaultProps = {
  95. 'itemsPerPage': 5,
  96. 'resetSearch': () => {}
  97. };
  98. export default WBBrowseDialogProjectList;