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.

83 line
2.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. }
  10. componentDidMount() {
  11. this.fetchRows();
  12. }
  13. componentWillReceiveProps(nextProps) {
  14. this.props = nextProps;
  15. this.setState({
  16. 'page': 0
  17. });
  18. this.fetchRows();
  19. }
  20. changePage(page) {
  21. this.setState({
  22. 'page': page
  23. });
  24. this.fetchRows();
  25. }
  26. prepareRows(items) {
  27. return items.map(it => [
  28. it.name,
  29. it.file_count,
  30. it.file_size_total
  31. ]);
  32. }
  33. fetchRows() {
  34. const { arvHost, arvToken } = this.props.app.state;
  35. const { textSearch, itemsPerPage } = this.props;
  36. const ownerUuid = ('ownerUuid' in this.state ?
  37. this.state.ownerUuid : this.props.ownerUuid);
  38. const { page } = this.state;
  39. const filters = [
  40. ['group_class', '=', 'project']
  41. ];
  42. if (ownerUuid)
  43. filters.push(['owner_uuid', '=', ownerUuid]);
  44. if (textSearch)
  45. filters.push(['name', 'ilike', '%' + textSearch + '%']);
  46. let prom = makeArvadosRequest(arvHost, arvToken,
  47. '/arvados/v1/groups?filters=' +
  48. encodeURIComponent(JSON.stringify(filters)) +
  49. '&limit=' + itemsPerPage +
  50. '&offset=' + (page * itemsPerPage));
  51. prom = prom.then(xhr => {
  52. this.setState({
  53. 'rows': this.prepareRows(xhr.response.items),
  54. 'numPages': xhr.response.items_available / itemsPerPage
  55. });
  56. });
  57. }
  58. render({ app }, { ownerUuid, textSearch, page, numPages, rows }) {
  59. return (
  60. <div>
  61. <WBTable columns={ ['Name', 'File Count', 'Size'] }
  62. rows={ rows } />
  63. <WBPagination numPages={ numPages } activePage={ page }
  64. onPageChanged={ i => this.changePage(i) } />
  65. </div>
  66. );
  67. }
  68. }
  69. WBBrowseDialogProjectList.defaultProps = {
  70. 'itemsPerPage': 5
  71. };
  72. export default WBBrowseDialogProjectList;