|
@@ -2,6 +2,7 @@ import { h, Component } from 'preact'; |
|
|
import WBTable from 'wb-table';
|
|
|
import WBTable from 'wb-table';
|
|
|
import WBBreadcrumbs from 'wb-breadcrumbs';
|
|
|
import WBBreadcrumbs from 'wb-breadcrumbs';
|
|
|
import { WBManifestReader } from 'wb-collection-manifest';
|
|
|
import { WBManifestReader } from 'wb-collection-manifest';
|
|
|
|
|
|
import WBPagination from 'wb-pagination';
|
|
|
import makeArvadosRequest from 'make-arvados-request';
|
|
|
import makeArvadosRequest from 'make-arvados-request';
|
|
|
import wbDownloadFile from 'wb-download-file';
|
|
|
import wbDownloadFile from 'wb-download-file';
|
|
|
|
|
|
|
|
@@ -10,13 +11,15 @@ class WBCollectionContent extends Component { |
|
|
super(...args);
|
|
|
super(...args);
|
|
|
this.state.rows = [];
|
|
|
this.state.rows = [];
|
|
|
this.state.manifestReader = null;
|
|
|
this.state.manifestReader = null;
|
|
|
|
|
|
this.state.loaded = 0;
|
|
|
|
|
|
this.state.total = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
getUrl(params) {
|
|
|
getUrl(params) {
|
|
|
let res = '/collection-browse/' +
|
|
|
let res = '/collection-browse/' +
|
|
|
(params.uuid || this.props.uuid) + '/' +
|
|
|
|
|
|
encodeURIComponent(params.collectionPath || this.props.collectionPath) + '/' +
|
|
|
|
|
|
(params.page || this.props.page);
|
|
|
|
|
|
|
|
|
('uuid' in params ? params.uuid : this.props.uuid) + '/' +
|
|
|
|
|
|
encodeURIComponent('collectionPath' in params ? params.collectionPath : this.props.collectionPath) + '/' +
|
|
|
|
|
|
('page' in params ? params.page : this.props.page);
|
|
|
return res;
|
|
|
return res;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@@ -27,7 +30,10 @@ class WBCollectionContent extends Component { |
|
|
let select = [ 'manifest_text' ];
|
|
|
let select = [ 'manifest_text' ];
|
|
|
let prom = makeArvadosRequest(arvHost, arvToken,
|
|
|
let prom = makeArvadosRequest(arvHost, arvToken,
|
|
|
'/arvados/v1/collections/' + uuid +
|
|
|
'/arvados/v1/collections/' + uuid +
|
|
|
'?select=' + encodeURIComponent(JSON.stringify(select)));
|
|
|
|
|
|
|
|
|
'?select=' + encodeURIComponent(JSON.stringify(select)),
|
|
|
|
|
|
{ 'onProgress': e => {
|
|
|
|
|
|
this.setState({ 'loaded': e.loaded, 'total': e.total });
|
|
|
|
|
|
} });
|
|
|
prom = prom.then(xhr => {
|
|
|
prom = prom.then(xhr => {
|
|
|
this.state.manifestReader = new WBManifestReader(xhr.response.manifest_text);
|
|
|
this.state.manifestReader = new WBManifestReader(xhr.response.manifest_text);
|
|
|
this.prepareRows();
|
|
|
this.prepareRows();
|
|
@@ -41,23 +47,27 @@ class WBCollectionContent extends Component { |
|
|
|
|
|
|
|
|
prepareRows() {
|
|
|
prepareRows() {
|
|
|
let { manifestReader } = this.state;
|
|
|
let { manifestReader } = this.state;
|
|
|
let { collectionPath } = this.props;
|
|
|
|
|
|
|
|
|
let { collectionPath, page, itemsPerPage } = this.props;
|
|
|
let { arvHost, arvToken } = this.props.app.state;
|
|
|
let { arvHost, arvToken } = this.props.app.state;
|
|
|
|
|
|
|
|
|
//path = path.split('/');
|
|
|
//path = path.split('/');
|
|
|
//path = [ '.' ].concat(path);
|
|
|
//path = [ '.' ].concat(path);
|
|
|
|
|
|
|
|
|
let listing = manifestReader.listDirectory('.' + collectionPath);
|
|
|
|
|
|
|
|
|
let listing = manifestReader.listDirectory('.' + collectionPath)
|
|
|
|
|
|
const numPages = Math.ceil(listing.length / itemsPerPage);
|
|
|
|
|
|
listing = listing.slice(page * itemsPerPage,
|
|
|
|
|
|
page * itemsPerPage + itemsPerPage);
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
this.setState({
|
|
|
|
|
|
'numPages': numPages,
|
|
|
'rows': listing.map(item => (
|
|
|
'rows': listing.map(item => (
|
|
|
(item[0] === 'd') ? [
|
|
|
(item[0] === 'd') ? [
|
|
|
(<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1] }) }>{ item[1] }/</a>),
|
|
|
|
|
|
|
|
|
(<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1], 'page': 0 }) }>{ item[1] }/</a>),
|
|
|
'Directory',
|
|
|
'Directory',
|
|
|
null,
|
|
|
null,
|
|
|
(<div></div>)
|
|
|
(<div></div>)
|
|
|
] : [
|
|
|
] : [
|
|
|
(<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1] }) }>{ item[1] }</a>),
|
|
|
|
|
|
|
|
|
(<a href={ this.getUrl({ 'collectionPath': collectionPath + '/' + item[1], 'page': 0 }) }>{ item[1] }</a>),
|
|
|
'File',
|
|
|
'File',
|
|
|
filesize(item[2]),
|
|
|
filesize(item[2]),
|
|
|
(<div>
|
|
|
(<div>
|
|
@@ -73,13 +83,23 @@ class WBCollectionContent extends Component { |
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
render({ collectionPath }, { rows }) {
|
|
|
|
|
|
|
|
|
render({ collectionPath, page }, { manifestReader, rows, numPages, loaded, total }) {
|
|
|
return (
|
|
|
return (
|
|
|
<div>
|
|
|
<div>
|
|
|
<WBBreadcrumbs items={ ('.' + collectionPath).split('/') } />
|
|
|
<WBBreadcrumbs items={ ('.' + collectionPath).split('/') } />
|
|
|
|
|
|
|
|
|
<WBTable columns={ [ 'Name', 'Type', 'Size', 'Actions' ] }
|
|
|
|
|
|
rows={ rows } />
|
|
|
|
|
|
|
|
|
{ manifestReader ? (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<WBTable columns={ [ 'Name', 'Type', 'Size', 'Actions' ] }
|
|
|
|
|
|
rows={ rows } />
|
|
|
|
|
|
|
|
|
|
|
|
<WBPagination activePage={ page } numPages={ numPages }
|
|
|
|
|
|
getPageUrl={ page => this.getUrl({ 'page': page }) } />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div>Downloading manifest: { filesize(loaded) }</div>
|
|
|
|
|
|
) }
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -87,7 +107,8 @@ class WBCollectionContent extends Component { |
|
|
|
|
|
|
|
|
WBCollectionContent.defaultProps = {
|
|
|
WBCollectionContent.defaultProps = {
|
|
|
'collectionPath': '',
|
|
|
'collectionPath': '',
|
|
|
'page': 0
|
|
|
|
|
|
|
|
|
'page': 0,
|
|
|
|
|
|
'itemsPerPage': 20
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
export default WBCollectionContent;
|
|
|
export default WBCollectionContent;
|