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!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

170 Zeilen
5.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. class WBProcessListing extends Component {
  11. constructor(...args) {
  12. super(...args);
  13. this.state.rows = [];
  14. this.state.numPages = 0;
  15. this.state.requestStates = [ 'Uncommitted', 'Committed', 'Final' ];
  16. // this.state.containerStates = [ 'Queued', 'Locked', 'Running', 'Cancelled', 'Complete' ];
  17. this.state.reqStateMask = [ true, true, true ];
  18. // this.state.contStateMask = [ true, true, true, true, true ];
  19. }
  20. componentDidMount() {
  21. this.fetchItems();
  22. }
  23. prepareRows(requests, containerLookup, ownerLookup, outputLookup) {
  24. const { renderRenameLink, renderDeleteButton } = this.props;
  25. return requests.map(item => {
  26. const container = item.container_uuid in containerLookup ?
  27. containerLookup[item.container_uuid] : null;
  28. const runtimeStatus = container ? container.runtime_status : null;
  29. const error = runtimeStatus ? runtimeStatus.error : null;
  30. const warning = runtimeStatus ? runtimeStatus.warning : null;
  31. return ( [
  32. (<div>
  33. <div>
  34. <a href={ '/process/' + item['uuid'] }>
  35. { item['name'] }
  36. </a> { renderRenameLink(item, () => this.fetchItems()) }
  37. </div>
  38. <div>{ item['uuid'] }</div>
  39. </div>),
  40. ( <div>
  41. { item['state'] }
  42. { item.container_uuid ?
  43. container ?
  44. [ " / ", container.state ] :
  45. [ " / ", <i>Container Not Found</i> ] :
  46. null }
  47. { !(error || warning) && container && container.state === 'Complete' ? " / Success" : null }
  48. { error ? [" / ", <a href={ '/container/' + container.uuid }
  49. title={ error }>E</a> ] : null }
  50. { warning ? [ " / ", <a href={ '/container/' + container.uuid }
  51. title={ warning }>W</a> ] : null }
  52. </div> ),
  53. ( <WBNameAndUuid uuid={ item['owner_uuid'] } lookup={ ownerLookup } /> ),
  54. wbFormatDate(item['created_at']),
  55. ( <WBNameAndUuid uuid={ item['output_uuid'] } lookup={ outputLookup } /> ),
  56. (<div>
  57. { renderDeleteButton(item, () => this.fetchItems()) }
  58. </div>)
  59. ] );
  60. });
  61. }
  62. fetchItems() {
  63. const { arvHost, arvToken } = this.props.appState;
  64. const { requestStates, reqStateMask } = this.state;
  65. const { activePage, itemsPerPage, ownerUuid,
  66. requestingContainerUuid } = this.props;
  67. const filters = [
  68. [ 'requesting_container_uuid', '=', requestingContainerUuid ]
  69. ];
  70. if (!reqStateMask.reduce((a, b) => a & b))
  71. filters.push([ 'state', 'in', requestStates.filter((_, idx) => reqStateMask[idx]) ]);
  72. if (ownerUuid)
  73. filters.push([ 'owner_uuid', '=', ownerUuid ]);
  74. //if (requestingContainerUuid)
  75. //filters.push();
  76. let prom = makeArvadosRequest(arvHost, arvToken,
  77. '/arvados/v1/container_requests?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  78. '&limit=' + itemsPerPage +
  79. '&offset=' + (itemsPerPage * activePage));
  80. let requests;
  81. let numPages;
  82. prom = prom.then(xhr => {
  83. requests = xhr.response.items;
  84. numPages = Math.ceil(xhr.response['items_available'] / xhr.response['limit']);
  85. /* container_uuids = requests.map(r => r.container_uuid);
  86. container_uuids = container_uuids.filter(uuid => uuid);
  87. const filters_1 = [
  88. [ 'uuid', 'in', container_uuids ]
  89. ];
  90. return makeArvadosRequest(arvHost, arvToken,
  91. '/arvados/v1/containers?filters=' +
  92. encodeURIComponent(JSON.stringify(filters_1)));*/
  93. return wbFetchObjects(arvHost, arvToken,
  94. requests.map(r => r.container_uuid).filter(uuid => uuid));
  95. });
  96. let containerLookup;
  97. prom = prom.then(lookup => {
  98. containerLookup = lookup;
  99. // const containers = xhr.response.items;
  100. // containers.map(c => (containerLookup[c.uuid] = c));
  101. return wbFetchObjects(arvHost, arvToken,
  102. requests.map(r => r.owner_uuid).filter(uuid => uuid));
  103. });
  104. let ownerLookup;
  105. prom = prom.then(lookup => {
  106. ownerLookup = lookup;
  107. return wbFetchObjects(arvHost, arvToken,
  108. requests.map(r => r.output_uuid).filter(uuid => uuid));
  109. });
  110. let outputLookup;
  111. prom = prom.then(lookup => (outputLookup = lookup));
  112. // prom = prom.then(() => makeArvadosRequest(arvHost, arvToken,
  113. // '/arvados/v1/'))
  114. prom = prom.then(() =>
  115. this.setState({
  116. 'numPages': numPages,
  117. 'rows': this.prepareRows(requests, containerLookup,
  118. ownerLookup, outputLookup)
  119. }));
  120. }
  121. componentWillReceiveProps(nextProps, nextState) {
  122. // this.setState({ 'rows': [] }); // .rows = [];
  123. this.props = nextProps;
  124. this.fetchItems();
  125. }
  126. render({ appState, ownerUuid, activePage, onPageChanged },
  127. { rows, numPages, requestStates, containerStates,
  128. reqStateMask, contStateMask }) {
  129. return (
  130. <div>
  131. <WBCheckboxes items={ requestStates } checked={ reqStateMask }
  132. cssClass="float-left mx-2 my-2" title="Request State: "
  133. onChange={ () => this.fetchItems() } />
  134. <WBTable columns={ [ 'Name', 'Status', 'Owner', 'Created At', 'Output', 'Actions' ] }
  135. rows={ rows } />
  136. <WBPagination numPages={ numPages }
  137. activePage={ activePage }
  138. onPageChanged={ i => onPageChanged(i) } />
  139. </div>
  140. );
  141. }
  142. }
  143. WBProcessListing.defaultProps = {
  144. 'itemsPerPage': 100,
  145. 'ownerUuid': null,
  146. 'requestingContainerUuid': null
  147. };
  148. export default WBProcessListing;