diff --git a/frontend/src/js/misc/arvados-type-name.js b/frontend/src/js/misc/arvados-type-name.js index 59c486c..e30f741 100644 --- a/frontend/src/js/misc/arvados-type-name.js +++ b/frontend/src/js/misc/arvados-type-name.js @@ -3,7 +3,9 @@ const typeIdToName = { 'j7d0g': 'group', 'xvhdp': 'container_request', 'dz642': 'container', - '7fd4e': 'workflow' + '7fd4e': 'workflow', + 'ozdt8': 'api_client', + '4zz18': 'collection' }; function arvadosTypeName(id) { diff --git a/frontend/src/js/misc/detect-uuids.js b/frontend/src/js/misc/detect-uuids.js new file mode 100644 index 0000000..3b72248 --- /dev/null +++ b/frontend/src/js/misc/detect-uuids.js @@ -0,0 +1,27 @@ +function detectUuids(obj) { + let Q = [ obj ]; + let matches = {}; + + while (Q.length > 0) { + let item = Q.pop(); + + if (!item) + continue; + + if (typeof(item) === 'string') { + // use regexes + let rx = /[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/g; + for (let m = rx.exec(item); m; m = rx.exec(item)) + matches[m[0]] = true; + + } else if (typeof(item) === 'object') { + Object.keys(item).map(k => Q.push(item[k])); + } + } + + matches = Object.keys(matches); + + return matches; +} + +export default detectUuids; diff --git a/frontend/src/js/misc/url-for-object.js b/frontend/src/js/misc/url-for-object.js new file mode 100644 index 0000000..b2258e7 --- /dev/null +++ b/frontend/src/js/misc/url-for-object.js @@ -0,0 +1,19 @@ +import arvadosTypeName from 'arvados-type-name'; + +function urlForObject(item) { + let objectType = arvadosTypeName(item.uuid.split('-')[1]); + if (objectType === 'user') + return ('/browse/' + item.uuid); + else if (objectType === 'group' && item.group_class === 'project') + return ('/browse/' + item.uuid); + else if (objectType === 'container_request') + return ('/process/' + item.uuid); + else if (objectType === 'workflow') + return ('https://wb.arkau.roche.com/workflows/' + item.uuid); + else if (objectType === 'collection') + return ('https://wb.arkau.roche.com/collections/' + item.uuid); + else if (objectType === 'container') + return ('https://wb.arkau.roche.com/containers/' + item.uuid); +} + +export default urlForObject; diff --git a/frontend/src/js/page/wb-process-view.js b/frontend/src/js/page/wb-process-view.js index 655b11e..8e05b3c 100644 --- a/frontend/src/js/page/wb-process-view.js +++ b/frontend/src/js/page/wb-process-view.js @@ -1,16 +1,81 @@ import { h, Component } from 'preact'; import WBNavbarCommon from 'wb-navbar-common'; import WBArvadosCrumbs from 'wb-arvados-crumbs'; +import makeArvadosRequest from 'make-arvados-request'; +import detectUuids from 'detect-uuids'; +import arvadosTypeName from 'arvados-type-name'; +import urlForObject from 'url-for-object'; class WBProcessView extends Component { - render({ app, uuid }) { + constructor(...args) { + super(...args); + this.state.objectUrls = []; + } + + componentDidMount() { + let { arvHost, arvToken } = this.props.app.state; + let prom = makeArvadosRequest(arvHost, arvToken, + '/arvados/v1/container_requests/' + this.props.uuid); + let req; + let cont; + prom = prom.then(xhr => { + req = xhr.response; + if (req.container_uuid) { + let prom_1 = makeArvadosRequest(arvHost, arvToken, + '/arvados/v1/containers/' + req.container_uuid); + prom_1 = prom_1.then(xhr => (cont = xhr.response)); + return prom_1; + } + }); + //prom = prom.then(xhr => (cont = xhr.response)); + prom = prom.then(() => { + let uuids = detectUuids([ req, cont ]); + let objectTypes = uuids.map(u => arvadosTypeName(u.split('-')[1]) + 's'); + let objQueries = {}; + objectTypes.map(t => (objQueries[t] = [])); + uuids.map((u, idx) => (objQueries[objectTypes[idx]].push(u))); + let prom_1 = new Promise(accept => accept()); + let objects = []; + // delete objQueries['users']; + delete objQueries['api_clients']; + for (let k in objQueries) { + let filters = [ + ['uuid', 'in', objQueries[k]] + ]; + prom_1 = prom_1.then(() => makeArvadosRequest(arvHost, arvToken, + '/arvados/v1/' + k + '?filters=' + + encodeURIComponent(JSON.stringify(filters)))); + prom_1 = prom_1.then(xhr => (objects = objects.concat(xhr.response['items']))); + } + prom_1 = prom_1.then(() => objects); + return prom_1; + }); + prom = prom.then(objects => { + let objDict = {}; + objects.map(o => (objDict[o['uuid']] = o)); + let urls = objects.map(o => urlForObject(o)); + this.setState({ 'objectUrls': urls }); + }); + } + + render({ app, uuid }, { objectUrls }) { return (
-
This is the process view for { uuid }
+
+ This is the process view for { uuid } +
+
+ Click here +
+
    + { objectUrls.map(url => ( +
  • { url }
  • + )) } +
); }