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.

119 lines
3.8KB

  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. import WBCheckboxes from 'wb-checkboxes';
  7. import wbFormatDate from 'wb-format-date';
  8. import wbFetchObjects from 'wb-fetch-objects';
  9. import WBNameAndUuid from 'wb-name-and-uuid';
  10. import WBProcessState from 'wb-process-state';
  11. function maskRows(rows) {
  12. return rows.map(r => r.map(c => '-'));
  13. }
  14. class WBProcessListing extends Component {
  15. constructor(...args) {
  16. super(...args);
  17. this.state.rows = [];
  18. this.state.numPages = 0;
  19. this.state.requestStates = [ 'Uncommitted', 'Committed', 'Final' ];
  20. this.state.reqStateMask = [ true, true, true ];
  21. }
  22. componentDidMount() {
  23. this.fetchItems();
  24. }
  25. prepareRows(requests, containerLookup, ownerLookup, outputLookup) {
  26. const { app, renderRenameLink, renderDeleteButton } = this.props;
  27. return requests.map(item => {
  28. return ( [
  29. (<div>
  30. <div>
  31. <a href={ '/process/' + item['uuid'] }>
  32. { item['name'] }
  33. </a> { renderRenameLink(item, () => this.fetchItems()) }
  34. </div>
  35. <div>{ item['uuid'] }</div>
  36. </div>),
  37. ( <WBProcessState app={ app } process={ item } /> ),
  38. ( <WBNameAndUuid app={ app } uuid={ item['owner_uuid'] } /> ),
  39. wbFormatDate(item['created_at']),
  40. ( <WBNameAndUuid app={ app } uuid={ item['output_uuid'] } /> ),
  41. (<div>
  42. { renderDeleteButton(item, () => this.fetchItems()) }
  43. </div>)
  44. ] );
  45. });
  46. }
  47. fetchItems() {
  48. const { arvHost, arvToken } = this.props.appState;
  49. const { requestStates, reqStateMask } = this.state;
  50. const { activePage, itemsPerPage, ownerUuid,
  51. requestingContainerUuid, waitForNextProps } = this.props;
  52. if (waitForNextProps)
  53. return;
  54. const filters = [
  55. [ 'requesting_container_uuid', '=', requestingContainerUuid ]
  56. ];
  57. if (!reqStateMask.reduce((a, b) => a & b))
  58. filters.push([ 'state', 'in', requestStates.filter((_, idx) => reqStateMask[idx]) ]);
  59. if (ownerUuid)
  60. filters.push([ 'owner_uuid', '=', ownerUuid ]);
  61. let prom = makeArvadosRequest(arvHost, arvToken,
  62. '/arvados/v1/container_requests?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  63. '&limit=' + itemsPerPage +
  64. '&offset=' + (itemsPerPage * activePage));
  65. prom = prom.then(xhr =>
  66. this.setState({
  67. 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']),
  68. 'rows': this.prepareRows(xhr.response.items)
  69. }));
  70. }
  71. componentWillReceiveProps(nextProps, nextState) {
  72. this.props = nextProps;
  73. this.setState({ 'rows': maskRows(this.state.rows) });
  74. this.fetchItems();
  75. }
  76. render({ appState, ownerUuid, activePage, onPageChanged, getPageUrl },
  77. { rows, numPages, requestStates, containerStates,
  78. reqStateMask, contStateMask }) {
  79. return (
  80. <div>
  81. <WBCheckboxes items={ requestStates } checked={ reqStateMask }
  82. cssClass="float-left mx-2 my-2" title="Request State: "
  83. onChange={ () => this.fetchItems() } />
  84. <WBTable columns={ [ 'Name', 'Status', 'Owner', 'Created At', 'Output', 'Actions' ] }
  85. rows={ rows } />
  86. <WBPagination numPages={ numPages }
  87. activePage={ activePage }
  88. getPageUrl={ getPageUrl }
  89. onPageChanged={ onPageChanged } />
  90. </div>
  91. );
  92. }
  93. }
  94. WBProcessListing.defaultProps = {
  95. 'itemsPerPage': 100,
  96. 'ownerUuid': null,
  97. 'requestingContainerUuid': null,
  98. 'renderRenameLink': () => {},
  99. 'renderDeleteButton': () => {}
  100. };
  101. export default WBProcessListing;