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!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

76 行
2.1KB

  1. import { h, Component } from 'preact';
  2. import { route } from 'preact-router';
  3. import makeArvadosRequest from 'make-arvados-request';
  4. import WBTable from 'wb-table';
  5. import WBPagination from 'wb-pagination';
  6. class WBProjectListing extends Component {
  7. constructor(...args) {
  8. super(...args);
  9. this.state.rows = [];
  10. this.state.numPages = 0;
  11. }
  12. componentDidMount() {
  13. this.fetchItems();
  14. }
  15. prepareRows(items) {
  16. return items.map(item => [
  17. (<div>
  18. <div>
  19. <a href="#"
  20. onclick={ e => { e.preventDefault(); route('/browse/' + item['uuid']) }}>{ item['name'] }</a>
  21. </div>
  22. <div>{ item['uuid'] }</div>
  23. </div>),
  24. item['description'],
  25. item['owner_uuid']
  26. ]);
  27. }
  28. fetchItems() {
  29. let i = this.props.activePage;
  30. let filters = [
  31. [ 'group_class', '=', 'project' ]
  32. ];
  33. if (this.props.ownerUuid)
  34. filters.push([ 'owner_uuid', '=', this.props.ownerUuid ]);
  35. let prom = makeArvadosRequest(this.props.arvHost, this.props.arvToken,
  36. '/arvados/v1/groups?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  37. '&limit=' + encodeURIComponent(this.props.itemsPerPage) +
  38. '&offset=' + encodeURIComponent(this.props.itemsPerPage * i));
  39. prom = prom.then(xhr =>
  40. this.setState({
  41. 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']),
  42. 'rows': this.prepareRows(xhr.response['items'])
  43. }));
  44. }
  45. componentWillReceiveProps(nextProps, nextState) {
  46. // this.setState({ 'rows': [] }); // .rows = [];
  47. this.props = nextProps;
  48. this.fetchItems();
  49. }
  50. render({ arvHost, arvToken, ownerUuid, activePage, onPageChanged }, { rows, numPages }) {
  51. return (
  52. <div>
  53. <WBTable columns={ [ 'Name', 'Description', 'Owner' ] }
  54. rows={ rows } />
  55. <WBPagination numPages={ numPages }
  56. activePage={ activePage }
  57. onPageChanged={ i => onPageChanged(i) } />
  58. </div>
  59. );
  60. }
  61. }
  62. WBProjectListing.defaultProps = {
  63. 'itemsPerPage': 100,
  64. 'ownerUuid': null
  65. };
  66. export default WBProjectListing;