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.

107 lines
3.1KB

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