import { h, Component, createRef } from 'preact'; import WBNavbarCommon from 'wb-navbar-common'; import WBArvadosCrumbs from 'wb-arvados-crumbs'; import WBToolboxDialog from 'wb-toolbox-dialog'; import makeArvadosRequest from 'make-arvados-request'; import linkState from 'linkstate'; function createInputsTemplate(workflow) { const g = JSON.parse(workflow.definition)['$graph']; const main = g.find(it => (it.id === '#main')); let res = ''; main.inputs.map(it => { let id = it.id.split('/'); id = id[id.length - 1]; if (it.label) res += ' // ' + it.label + '\n'; if (it.doc) res += ' // ' + it.doc + '\n'; res += ' // Type: ' + ((typeof(it.type) === 'string') ? it.type : JSON.stringify(it.type)) + '\n\n'; res += ' \'' + id + '\': \'\',\n\n'; //res += ' // ' + ' '.repeat(id.length) + '^^^^\n\n'; }); /* let res = main.inputs.map(it => { it.value = null; return it; }); res = JSON.stringify(res, null, 2); res = res.split('\n'); res = res.map((ln, i) => (i == 0 ? ln : ' ' + ln)); res = res.join('\n'); */ return res; } function uuidsToCwlObjects(spec) { if (typeof(spec) === 'string') { if (/^[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/.exec(spec)) { return { 'class': 'Directory', 'location': 'keep:' + spec }; } else if (/^[a-f0-9]{32}\+[0-9]+/.exec(spec)) { return { 'class': 'Directory', 'location': 'keep:' + spec }; } else { return spec; } } else if (typeof(spec) === 'object') { const res = (spec instanceof Array) ? [] : {}; Object.keys(spec).map(k => (res[k] = uuidsToCwlObjects(spec[k]))); return res; } else { return spec; } } class WBLaunchWorkflowPage extends Component { constructor(...args) { super(...args); this.state.browseDialogId = uuid.v4(); this.state.insertDialogId = uuid.v4(); this.state.insertManyDialogId = uuid.v4(); this.inputsTextArea = createRef(); } componentDidMount() { let { app, workflowUuid } = this.props; let { arvHost, arvToken } = app.state; let prom = makeArvadosRequest(arvHost, arvToken, '/arvados/v1/workflows/' + workflowUuid); prom = prom.then(xhr => this.setState({ 'workflow': xhr.response, 'defaultProcessName': xhr.response.name + ' ' + (new Date().toISOString()), 'defaultProcessDescription': xhr.response.description, 'inputsFunctionText': '(() => {\n return {\n' + createInputsTemplate(xhr.response) + ' };\n})()' })); } render({ app, workflowUuid }, { workflow, projectUuid, processName, processDescription, defaultProcessName, defaultProcessDescription, inputsFunctionText, browseDialogId, insertDialogId, insertManyDialogId, inputsPreview }) { return (