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!
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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