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.

72 lines
2.0KB

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