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.

116 line
3.7KB

  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 } = this.props;
  52. const filters = [
  53. [ 'requesting_container_uuid', '=', requestingContainerUuid ]
  54. ];
  55. if (!reqStateMask.reduce((a, b) => a & b))
  56. filters.push([ 'state', 'in', requestStates.filter((_, idx) => reqStateMask[idx]) ]);
  57. if (ownerUuid)
  58. filters.push([ 'owner_uuid', '=', ownerUuid ]);
  59. let prom = makeArvadosRequest(arvHost, arvToken,
  60. '/arvados/v1/container_requests?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  61. '&limit=' + itemsPerPage +
  62. '&offset=' + (itemsPerPage * activePage));
  63. prom = prom.then(xhr =>
  64. this.setState({
  65. 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']),
  66. 'rows': this.prepareRows(xhr.response.items)
  67. }));
  68. }
  69. componentWillReceiveProps(nextProps, nextState) {
  70. this.props = nextProps;
  71. this.setState({ 'rows': maskRows(this.state.rows) });
  72. this.fetchItems();
  73. }
  74. render({ appState, ownerUuid, activePage, onPageChanged, getPageUrl },
  75. { rows, numPages, requestStates, containerStates,
  76. reqStateMask, contStateMask }) {
  77. return (
  78. <div>
  79. <WBCheckboxes items={ requestStates } checked={ reqStateMask }
  80. cssClass="float-left mx-2 my-2" title="Request State: "
  81. onChange={ () => this.fetchItems() } />
  82. <WBTable columns={ [ 'Name', 'Status', 'Owner', 'Created At', 'Output', 'Actions' ] }
  83. rows={ rows } />
  84. <WBPagination numPages={ numPages }
  85. activePage={ activePage }
  86. getPageUrl={ getPageUrl }
  87. onPageChanged={ onPageChanged } />
  88. </div>
  89. );
  90. }
  91. }
  92. WBProcessListing.defaultProps = {
  93. 'itemsPerPage': 100,
  94. 'ownerUuid': null,
  95. 'requestingContainerUuid': null,
  96. 'renderRenameLink': () => {},
  97. 'renderDeleteButton': () => {}
  98. };
  99. export default WBProcessListing;