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.

79 lines
2.1KB

  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 WBTable from 'wb-table';
  9. import WBPagination from 'wb-pagination';
  10. import makeArvadosRequest from 'make-arvados-request';
  11. class WBBrowseDialogUserList extends Component {
  12. constructor(...args) {
  13. super(...args);
  14. this.state.rows = [];
  15. }
  16. componentDidMount() {
  17. this.fetchRows();
  18. }
  19. componentWillReceiveProps(nextProps) {
  20. this.props = nextProps;
  21. this.fetchRows();
  22. }
  23. prepareRows(items) {
  24. const { navigate } = this.props;
  25. return items.map(it => [
  26. (
  27. <a href="#" onclick={ e => { e.preventDefault();
  28. navigate('/browse-dialog/browse/' + it.uuid); } }>
  29. { it.last_name + ', ' + it.first_name }
  30. </a>
  31. ),
  32. it.uuid
  33. ]);
  34. }
  35. fetchRows() {
  36. const { arvHost, arvToken } = this.props.app.state;
  37. const { itemsPerPage, page, textSearch } = this.props;
  38. const order = ['last_name asc', 'first_name asc'];
  39. const filters = [];
  40. if (textSearch)
  41. filters.push([ 'any', 'ilike', '%' + textSearch + '%' ]);
  42. let prom = makeArvadosRequest(arvHost, arvToken,
  43. '/arvados/v1/users?order=' +
  44. encodeURIComponent(JSON.stringify(order)) +
  45. '&filters=' +
  46. encodeURIComponent(JSON.stringify(filters)) +
  47. '&limit=' + itemsPerPage +
  48. '&offset=' + (itemsPerPage * page));
  49. prom = prom.then(xhr => this.setState({
  50. 'rows': this.prepareRows(xhr.response.items),
  51. 'numPages': Math.ceil(xhr.response.items_available / itemsPerPage)
  52. }));
  53. }
  54. render({ page, navigate }, { rows, numPages }) {
  55. return (
  56. <div>
  57. <WBTable columns={ [ 'Name', 'UUID' ] }
  58. rows={ rows } />
  59. <WBPagination numPages={ numPages } activePage={ page }
  60. onPageChanged={ i => navigate({ 'topPage': i }) } />
  61. </div>
  62. );
  63. }
  64. }
  65. WBBrowseDialogUserList.defaultProps = {
  66. 'itemsPerPage': 20
  67. };
  68. export default WBBrowseDialogUserList;