|
- import { h, Component } from 'preact';
- import WBTable from 'wb-table';
- import WBBreadcrumbs from 'wb-breadcrumbs';
- import { WBManifestReader } from 'wb-collection-manifest';
- import makeArvadosRequest from 'make-arvados-request';
- import wbDownloadFile from 'wb-download-file';
-
- class WBCollectionContent extends Component {
- constructor(...args) {
- super(...args);
- this.state.rows = [];
- this.state.manifestReader = null;
- }
-
- getUrl(params) {
- let res = '/collection-browse/' +
- (params.uuid || this.props.uuid) + '/' +
- encodeURIComponent(params.collectionPath || this.props.collectionPath) + '/' +
- (params.page || this.props.page);
- return res;
- }
-
- componentDidMount() {
- let { arvHost, arvToken } = this.props.app.state;
- let { uuid } = this.props;
-
- let select = [ 'manifest_text' ];
- let prom = makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/collections/' + uuid +
- '?select=' + encodeURIComponent(JSON.stringify(select)));
- prom = prom.then(xhr => {
- this.state.manifestReader = new WBManifestReader(xhr.response.manifest_text);
- this.prepareRows();
- });
- }
-
- componentWillReceiveProps(nextProps) {
- this.props = nextProps;
- this.prepareRows();
- }
-
- prepareRows() {
- let { manifestReader } = this.state;
- let { collectionPath } = this.props;
- let { arvHost, arvToken } = this.props.app.state;
-
- //path = path.split('/');
- //path = [ '.' ].concat(path);
-
- let listing = manifestReader.listDirectory('.' + collectionPath);
-
- this.setState({
- 'rows': listing.map(item => (
- (item[0] === 'd') ? [
- (<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1] }) }>{ item[1] }/</a>),
- 'Directory',
- null,
- (<div></div>)
- ] : [
- (<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1] }) }>{ item[1] }</a>),
- 'File',
- filesize(item[2]),
- (<div>
- <button class="btn btn-outline-primary mx-1" title="Download"
- onclick={ () => wbDownloadFile(arvHost, arvToken, manifestReader,
- '.' + collectionPath + '/' + item[1]) }><i class="fas fa-download"></i></button>
- <button class="btn btn-outline-primary mx-1" title="View"
- onclick={ () => wbDownloadFile(arvHost, arvToken, manifestReader,
- '.' + collectionPath + '/' + item[1]) }><i class="far fa-eye"></i></button>
- </div>)
- ]
- ))
- });
- }
-
- render({ collectionPath }, { rows }) {
- return (
- <div>
- <WBBreadcrumbs items={ ('.' + collectionPath).split('/') } />
-
- <WBTable columns={ [ 'Name', 'Type', 'Size', 'Actions' ] }
- rows={ rows } />
- </div>
- );
- }
- }
-
- WBCollectionContent.defaultProps = {
- 'collectionPath': '',
- 'page': 0
- };
-
- export default WBCollectionContent;
|