Skip to content

Commit 893d62a

Browse files
committed
Allow to specify a URL in the UDP wizard
1 parent 754752a commit 893d62a

File tree

4 files changed

+101
-29
lines changed

4 files changed

+101
-29
lines changed

src/components/modals/ImportProcessModal.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ export default {
108108
if (!Utils.isObject(data)) {
109109
throw new Error('Process does not contain any data');
110110
}
111-
if (typeof data.id !== 'string' && !Utils.isObject(data.process_graph)) {
112-
throw new Error('Process does not contain `id` or `process graph`');
111+
if (!Utils.hasText(data.id)) {
112+
throw new Error('Process does not contain an id');
113+
}
114+
if (!Utils.isObject(data.process_graph)) {
115+
throw new Error('Process does not contain a process graph');
113116
}
114117
return data;
115118
},

src/components/modals/WizardModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<Modal id="WizardModal" :show="show" :width="width" :title="title" @closed="$emit('closed')">
2+
<Modal id="WizardModal" :show="show" :width="width" :title="title" :submitFunction="nextTab" @closed="$emit('closed')">
33
<template #default>
44
<div v-if="selected" class="wizard">
55
<div class="wizard-navigation">

src/components/wizards/UDP.vue

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="wizard-tab-content">
33
<WizardTab v-if="!noProcessSelection" :pos="tabPos[0]" :parent="parent" title="Process" :beforeChange="checkProcessRequirements">
4-
<ChooseUserDefinedProcess :value="process" :namespace="processNamespace" @input="submitProcess" />
4+
<ChooseUserDefinedProcess :value="process" :namespace="processNamespace" :url="processUrl" @input="submitProcess" />
55
</WizardTab>
66
<WizardTab :pos="tabPos[1]" :parent="parent" title="Parameters" :beforeChange="checkParameterRequirements">
77
<ChooseProcessParameters v-if="processSpec" v-model="args" :process="processSpec" />
@@ -37,6 +37,7 @@ export default {
3737
loading: false,
3838
noProcessSelection: false,
3939
process: null,
40+
processUrl: null,
4041
processSpec: null,
4142
processNamespace: 'user',
4243
args: {},
@@ -58,16 +59,20 @@ export default {
5859
if (!this.process || !this.processSpec) {
5960
return null;
6061
}
61-
let [id, namespace] = Utils.extractUDPParams(this.process);
62+
let node = {
63+
process_id: this.process,
64+
arguments: this.args,
65+
result: true
66+
};
67+
if (Utils.hasText(this.processNamespace)) {
68+
node.namespace = this.processNamespace;
69+
}
70+
if (Utils.hasText(this.processSpec.summary)) {
71+
node.description = this.processSpec.summary;
72+
}
6273
return {
6374
process_graph: {
64-
[id]: {
65-
process_id: id,
66-
namespace,
67-
description: this.processSpec.summary,
68-
arguments: this.args,
69-
result: true
70-
}
75+
[this.process]: node
7176
}
7277
};
7378
}
@@ -88,30 +93,70 @@ export default {
8893
},
8994
methods: {
9095
...Utils.mapActions(['loadProcess']),
91-
submitProcess(item) {
92-
this.process = item.id;
93-
if (item.namespace) {
94-
this.processNamespace = item.namespace;
96+
submitProcess(item, isUrl = false) {
97+
if (isUrl) {
98+
this.processUrl = item;
99+
}
100+
else {
101+
this.process = item.id;
102+
if (item.namespace) {
103+
this.processNamespace = item.namespace;
104+
}
105+
this.parent.nextTab();
95106
}
96-
this.parent.nextTab();
107+
},
108+
async loadFromUrl(url) {
109+
if (!Utils.isUrl(url)) {
110+
throw new Error('Please provide a valid URL!');
111+
}
112+
let data;
113+
try {
114+
const response = await axios(url);
115+
data = response.data;
116+
} catch(error) {
117+
throw new Error('Failed to load process from the given URL');
118+
}
119+
if (typeof data === 'string') {
120+
try {
121+
data = JSON.parse(data);
122+
} catch(error) {
123+
throw new Error('Process is not valid JSON');
124+
}
125+
}
126+
if (!Utils.isObject(data)) {
127+
throw new Error('Process does not contain any data');
128+
}
129+
if (!Utils.hasText(data.id)) {
130+
throw new Error('Process does not contain an id');
131+
}
132+
if (!Utils.isObject(data.process_graph)) {
133+
throw new Error('Process does not contain a process graph');
134+
}
135+
return data;
97136
},
98137
async checkProcessRequirements() {
99138
this.loading = true;
100-
try {
139+
if (this.processUrl) {
140+
const process = await this.loadFromUrl(this.processUrl);
141+
this.processes.add(process, this.processUrl);
142+
this.processNamespace = this.processUrl;
143+
this.process = process.id;
144+
this.processSpec = process;
145+
}
146+
else if (this.process) {
101147
this.processSpec = await this.loadProcess({
102148
id: this.process,
103149
namespace: this.processNamespace
104150
});
105-
this.loading = false;
106-
if (this.processSpec) {
107-
this.jobTitle = this.processSpec.id;
108-
}
109-
return true;
110-
} catch (error) {
111-
this.loading = false;
112-
console.warn(error);
113-
return false;
114151
}
152+
else {
153+
throw new Error('Please select a user-defined process');
154+
}
155+
this.loading = false;
156+
if (this.processSpec) {
157+
this.jobTitle = this.processSpec.id;
158+
}
159+
return true;
115160
},
116161
checkParameterRequirements() {
117162
if (this.graph) {

src/components/wizards/tabs/ChooseUserDefinedProcess.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="step choose-process">
3-
<p>Please select the user-defined process to execute.</p>
3+
<p>Please select the user-defined process to execute:</p>
44
<Processes heading="" :processes="filteredProcesses" :offerDetails="false">
55
<template #summary="{ item }">
66
<div :class="{element: true, selected: item.id == value}">
@@ -12,6 +12,9 @@
1212
</div>
1313
</template>
1414
</Processes>
15+
<hr />
16+
<p>Alternatively, provide a URL to a user-defined process:</p>
17+
<input type="url" name="url" class="url" :value="url" @blur="updateUrl" />
1518
</div>
1619
</template>
1720

@@ -36,6 +39,10 @@ export default {
3639
namespace: {
3740
type: String,
3841
default: 'user'
42+
},
43+
url: {
44+
type: String,
45+
default: null
3946
}
4047
},
4148
computed: {
@@ -46,9 +53,21 @@ export default {
4653
},
4754
methods: {
4855
...Utils.mapActions(['describeUserProcess']),
49-
async update(id) {
56+
update(id) {
5057
this.$emit('input', id);
5158
},
59+
updateUrl(event) {
60+
const url = event.target.value;
61+
if (!url) {
62+
return;
63+
}
64+
else if (Utils.isUrl(url)) {
65+
this.$emit('input', url, true);
66+
}
67+
else {
68+
throw new Error('The provided URL is not valid.');
69+
}
70+
},
5271
showProcess(item) {
5372
this.broadcast('showProcess', item);
5473
}
@@ -58,6 +77,11 @@ export default {
5877

5978
<style lang="scss">
6079
.choose-process {
80+
input.url {
81+
width: 100%;
82+
box-sizing: border-box;
83+
}
84+
6185
.vue-component.searchable-list ul.list > li {
6286
margin-bottom: 0;
6387

0 commit comments

Comments
 (0)