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.

149 lines
4.9KB

  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. cancelProcess(uuid) {
  26. const { app } = this.props;
  27. const { arvHost, arvToken } = app.state;
  28. let prom = makeArvadosRequest(arvHost, arvToken,
  29. '/arvados/v1/container_requests/' + encodeURIComponent(uuid),
  30. { method: 'PUT', data: JSON.stringify({ priority: 0 }) });
  31. prom = prom.then(() => {
  32. this.setState({ rows: maskRows(this.state.rows) });
  33. this.fetchItems();
  34. });
  35. }
  36. prepareRows(requests, containerLookup, ownerLookup, outputLookup) {
  37. const { app, renderRenameLink, renderDeleteButton,
  38. renderSelectionCell, renderSharingButton,
  39. renderEditDescription } = this.props;
  40. return requests.map(item => {
  41. return ( [
  42. renderSelectionCell(item),
  43. (<div>
  44. <div>
  45. <a href={ '/process/' + item['uuid'] }>
  46. { item['name'] }
  47. </a> { renderRenameLink(item, () => this.fetchItems()) }
  48. </div>
  49. <div>{ item['uuid'] }</div>
  50. <div class="mt-2">
  51. { item.description } { renderEditDescription(item, () => this.fetchItems()) }
  52. </div>
  53. </div>),
  54. ( <WBProcessState app={ app } process={ item } lazy={ true } /> ),
  55. ( <WBNameAndUuid app={ app } uuid={ item['owner_uuid'] } lazy={ true } /> ),
  56. wbFormatDate(item['created_at']),
  57. ( <WBNameAndUuid app={ app } uuid={ item['output_uuid'] } lazy={ true } /> ),
  58. (<div>
  59. <button class="btn btn-outline-warning m-1" onclick={ () => this.cancelProcess(item.uuid) }>
  60. <i class="fas fa-stop-circle"></i>
  61. </button>
  62. { renderDeleteButton(item, () => this.fetchItems()) }
  63. { renderSharingButton(item) }
  64. </div>)
  65. ] );
  66. });
  67. }
  68. fetchItems() {
  69. const { arvHost, arvToken } = this.props.appState;
  70. const { requestStates, reqStateMask } = this.state;
  71. const { activePage, itemsPerPage, ownerUuid,
  72. requestingContainerUuid, waitForNextProps,
  73. textSearch } = this.props;
  74. if (waitForNextProps)
  75. return;
  76. const filters = [
  77. [ 'requesting_container_uuid', '=', requestingContainerUuid ]
  78. ];
  79. if (!reqStateMask.reduce((a, b) => a & b))
  80. filters.push([ 'state', 'in', requestStates.filter((_, idx) => reqStateMask[idx]) ]);
  81. if (ownerUuid)
  82. filters.push([ 'owner_uuid', '=', ownerUuid ]);
  83. if (textSearch)
  84. filters.push([ 'any', 'ilike', '%' + textSearch + '%' ])
  85. let prom = makeArvadosRequest(arvHost, arvToken,
  86. '/arvados/v1/container_requests?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  87. '&limit=' + itemsPerPage +
  88. '&offset=' + (itemsPerPage * activePage));
  89. prom = prom.then(xhr =>
  90. this.setState({
  91. 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']),
  92. 'rows': this.prepareRows(xhr.response.items)
  93. }));
  94. }
  95. componentWillReceiveProps(nextProps, nextState) {
  96. this.props = nextProps;
  97. this.setState({ 'rows': maskRows(this.state.rows) });
  98. this.fetchItems();
  99. }
  100. render({ appState, ownerUuid, activePage, onPageChanged, getPageUrl },
  101. { rows, numPages, requestStates, containerStates,
  102. reqStateMask, contStateMask }) {
  103. return (
  104. <div>
  105. <WBCheckboxes items={ requestStates } checked={ reqStateMask }
  106. cssClass="float-left mx-2 my-2" title="Request State: "
  107. onChange={ () => this.fetchItems() } />
  108. <WBTable columns={ [ '', 'Name', 'Status', 'Owner', 'Created At', 'Output', 'Actions' ] }
  109. headerClasses={ [ 'w-1' ] }
  110. rows={ rows } />
  111. <WBPagination numPages={ numPages }
  112. activePage={ activePage }
  113. getPageUrl={ getPageUrl }
  114. onPageChanged={ onPageChanged } />
  115. </div>
  116. );
  117. }
  118. }
  119. WBProcessListing.defaultProps = {
  120. itemsPerPage: 100,
  121. ownerUuid: null,
  122. requestingContainerUuid: null,
  123. renderRenameLink: () => null,
  124. renderDeleteButton: () => null,
  125. renderSelectionCell: () => null,
  126. renderSharingButton: () => null,
  127. renderEditDescription: () => null
  128. };
  129. export default WBProcessListing;