|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { h, Component } from 'preact';
- import { route } from 'preact-router';
- import makeArvadosRequest from 'make-arvados-request';
- import WBTable from 'wb-table';
- import WBPagination from 'wb-pagination';
- import WBCheckboxes from 'wb-checkboxes';
- import wbFormatDate from 'wb-format-date';
- import wbFetchObjects from 'wb-fetch-objects';
- import WBNameAndUuid from 'wb-name-and-uuid';
- import WBProcessState from 'wb-process-state';
-
- function maskRows(rows) {
- return rows.map(r => r.map(c => '-'));
- }
-
- class WBProcessListing extends Component {
-
- constructor(...args) {
- super(...args);
- this.state.rows = [];
- this.state.numPages = 0;
- this.state.requestStates = [ 'Uncommitted', 'Committed', 'Final' ];
- this.state.reqStateMask = [ true, true, true ];
- }
-
- componentDidMount() {
- this.fetchItems();
- }
-
- prepareRows(requests, containerLookup, ownerLookup, outputLookup) {
- const { app, renderRenameLink, renderDeleteButton,
- renderSelectionCell, renderSharingButton } = this.props;
- return requests.map(item => {
- return ( [
- renderSelectionCell(item),
- (<div>
- <div>
- <a href={ '/process/' + item['uuid'] }>
- { item['name'] }
- </a> { renderRenameLink(item, () => this.fetchItems()) }
- </div>
- <div>{ item['uuid'] }</div>
- </div>),
- ( <WBProcessState app={ app } process={ item } /> ),
- ( <WBNameAndUuid app={ app } uuid={ item['owner_uuid'] } /> ),
- wbFormatDate(item['created_at']),
- ( <WBNameAndUuid app={ app } uuid={ item['output_uuid'] } /> ),
- (<div>
- { renderDeleteButton(item, () => this.fetchItems()) }
- { renderSharingButton(item) }
- </div>)
- ] );
- });
- }
-
- fetchItems() {
- const { arvHost, arvToken } = this.props.appState;
- const { requestStates, reqStateMask } = this.state;
- const { activePage, itemsPerPage, ownerUuid,
- requestingContainerUuid, waitForNextProps } = this.props;
-
- if (waitForNextProps)
- return;
-
- const filters = [
- [ 'requesting_container_uuid', '=', requestingContainerUuid ]
- ];
- if (!reqStateMask.reduce((a, b) => a & b))
- filters.push([ 'state', 'in', requestStates.filter((_, idx) => reqStateMask[idx]) ]);
- if (ownerUuid)
- filters.push([ 'owner_uuid', '=', ownerUuid ]);
-
- let prom = makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/container_requests?filters=' + encodeURIComponent(JSON.stringify(filters)) +
- '&limit=' + itemsPerPage +
- '&offset=' + (itemsPerPage * activePage));
-
- prom = prom.then(xhr =>
- this.setState({
- 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']),
- 'rows': this.prepareRows(xhr.response.items)
- }));
- }
-
- componentWillReceiveProps(nextProps, nextState) {
- this.props = nextProps;
- this.setState({ 'rows': maskRows(this.state.rows) });
- this.fetchItems();
- }
-
- render({ appState, ownerUuid, activePage, onPageChanged, getPageUrl },
- { rows, numPages, requestStates, containerStates,
- reqStateMask, contStateMask }) {
-
- return (
- <div>
- <WBCheckboxes items={ requestStates } checked={ reqStateMask }
- cssClass="float-left mx-2 my-2" title="Request State: "
- onChange={ () => this.fetchItems() } />
-
- <WBTable columns={ [ '', 'Name', 'Status', 'Owner', 'Created At', 'Output', 'Actions' ] }
- headerClasses={ [ 'w-1' ] }
- rows={ rows } />
-
- <WBPagination numPages={ numPages }
- activePage={ activePage }
- getPageUrl={ getPageUrl }
- onPageChanged={ onPageChanged } />
- </div>
- );
- }
- }
-
- WBProcessListing.defaultProps = {
- 'itemsPerPage': 100,
- 'ownerUuid': null,
- 'requestingContainerUuid': null,
- 'renderRenameLink': () => {},
- 'renderDeleteButton': () => {}
- };
-
- export default WBProcessListing;
|