Skip to content

Commit 79f8d5e

Browse files
committed
feat: display log at readWorkflow, redirect to service description
1 parent 1154627 commit 79f8d5e

File tree

5 files changed

+77
-16
lines changed

5 files changed

+77
-16
lines changed

src/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export const {
77
INPUTS_DATA_XML_FILEPATH = "api/inputData.xml",
88
USERNAME = "",
99
PASSWORD = "",
10-
SERVICES_API = ""
10+
SERVICES_API = "",
11+
BASE_URL = "http://diufvm17.unifr.ch:8080/exist/projects/diae/"
1112
} = process.env;

src/js/elements/addElement.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { layoutSettingsApp } from "../layoutSettings";
3939

4040
const createBox = (
4141
e,
42-
{ position, size, boxId, defaultParams = {}, ports: { items } }
42+
{ position, size, boxId, defaultParams = {}, ports: { items }, serviceId }
4343
) => {
4444
const { graph } = app;
4545
const { category, label, description, params = {} } = e;
@@ -73,6 +73,7 @@ const createBox = (
7373
rect: { ...THEME.rect, ...size }
7474
},
7575
boxId,
76+
serviceId,
7677
category: CATEGORY_SERVICE,
7778
position,
7879
size,
@@ -194,7 +195,7 @@ const createPortsFromInputOutput = (inputs, outputs) => {
194195
export const buildElementFromName = name => {
195196
// find webservice given name
196197
const webservice = getWebserviceByName(name);
197-
const { outputs = [], inputs = [] } = webservice;
198+
const { outputs = [], inputs = [], id } = webservice;
198199

199200
const el = transformWebserviceForGraph(webservice);
200201

@@ -214,6 +215,7 @@ export const buildElementFromName = name => {
214215
const position = position ? position : findEmptyPosition(size);
215216

216217
return {
218+
serviceId: id,
217219
category: CATEGORY_SERVICE,
218220
boxId,
219221
defaultParams,

src/js/layout/components/Log.js

+30-7
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,48 @@ import { centerBoxInPaperByBoxId } from "../utils";
44
const Log = Vue.component("Log", {
55
data() {
66
return {
7-
messages: []
7+
messages: [],
8+
activated: false // hacky variable to activate readworkflow initial push
89
};
910
},
10-
computed: {
11-
logMessages() {
12-
return this.messages;
13-
}
14-
},
1511
methods: {
12+
findMessage(message) {
13+
return this.messages.findIndex(
14+
m => m.boxId == message.boxId && m.paramName == message.paramName
15+
);
16+
},
1617
setLogMessages(messages) {
1718
this.messages = messages;
1819
},
20+
addMessage(message) {
21+
const mId = this.findMessage(message);
22+
// if the input is not already false
23+
if (mId < 0) {
24+
this.messages.push(message);
25+
this.hacky(message);
26+
}
27+
// replace the message
28+
else {
29+
this.$set(this.messages[mId], "value", message.value);
30+
}
31+
},
32+
hacky(message) {
33+
// BUG HACK: add twice the message for first pushed message:
34+
if (!this.activated) {
35+
this.messages.push(message);
36+
this.activated = true;
37+
}
38+
},
39+
removeMessage(message) {
40+
this.messages.splice(this.findMessage(message), 1);
41+
},
1942
goToBox(name) {
2043
centerBoxInPaperByBoxId(name);
2144
}
2245
},
2346
template: `
2447
<div id="log">
25-
<div v-for="{value, paramName, paramType, name, boxId} in logMessages">Invalid value <span class="value">{{value}}</span> in <span class="name">{{paramName}}</span> of <span class="boxName" @click="goToBox(boxId)">{{name}}</span></div>
48+
<div v-for="{value, paramName, paramType, name, boxId} in messages">Invalid value <span class="value">{{value}}</span> in <span class="name">{{paramName}}</span> of <span class="boxName" @click="goToBox(boxId)">{{name}}</span></div>
2649
</div>
2750
`
2851
});

src/js/layout/inputs.js

+40-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const $ = jQuery;
44
global.$ = global.jQuery = $;
55

66
import "select2js";
7+
import { BASE_URL } from "../../config";
78
import {
89
TOOLTIP_BREAK_LINE,
910
Inputs,
@@ -45,14 +46,16 @@ export const setSelectValueInElement = (boxId, parameters) => {
4546
}
4647
};
4748

48-
export const setInputValueInElement = (boxId, parameters) => {
49+
export const setInputValueInElement = (box, parameters) => {
50+
console.log("TCL: setInputValueInElement -> box", box);
51+
const { boxId, type: boxName } = box;
4952
for (const [key, { value }] of Object.entries(parameters)) {
5053
// we need to precise paper root because of the minimap duplicate elements
5154
const el = $(
5255
`${INTERFACE_ROOT} foreignObject[boxId="${boxId}"] ${Inputs.NUMBER.tag}[name="${key}"]`
5356
);
5457
el.val(value);
55-
checkInputValue(el);
58+
checkInputValue(el, { boxId, boxName });
5659
}
5760
};
5861

@@ -241,14 +244,17 @@ export const createInput = (
241244
}
242245
});
243246

247+
const { boxId, type: boxName } = element.attributes;
248+
const boxParams = { boxId, boxName };
249+
244250
// update param
245251
inputEl.on({
246252
blur: function() {
247253
const input = $(this);
248254
const value = input.val();
249255
const attr = input.attr("name");
250256
app.setInputValueInElement({ element, attr, value });
251-
checkInputValue(input);
257+
checkInputValue(input, boxParams);
252258
},
253259
click: function() {
254260
$(this).select();
@@ -259,7 +265,7 @@ export const createInput = (
259265
});
260266

261267
// evaluate default parameters
262-
checkInputValue(inputEl);
268+
checkInputValue(inputEl, boxParams);
263269

264270
// reset
265271
const resetButtonNumber = resetButton.clone(true).attr({
@@ -281,7 +287,7 @@ export const createInput = (
281287
return newInput;
282288
};
283289

284-
export const checkInputValue = input => {
290+
export const checkInputValue = (input, { boxName, boxId }) => {
285291
const currentVal = input.val();
286292
const { min, max, step } = input.data();
287293

@@ -291,13 +297,34 @@ export const checkInputValue = input => {
291297
step
292298
});
293299

300+
if (!isValid) {
301+
app.$refs.log.addMessage({
302+
value: currentVal,
303+
paramName: input.attr("name"),
304+
paramType: Inputs.NUMBER.type,
305+
name: boxName,
306+
boxId
307+
});
308+
} else {
309+
app.$refs.log.removeMessage({
310+
paramName: input.attr("name"),
311+
name: boxName,
312+
boxId
313+
});
314+
}
315+
294316
input.toggleClass("is-invalid", !isValid);
295317
};
296318

297319
// cannot merge defaultParams in element, because element needs to be "pure"
298320
// in order to modify it with jointjs functions
299321
export const setParametersInForeignObject = (element, defaultParams = {}) => {
300-
const { description, type: label, originalParams } = element.attributes;
322+
const {
323+
description,
324+
type: label,
325+
originalParams,
326+
serviceId
327+
} = element.attributes;
301328

302329
const selectsArr = [];
303330
const inputsArr = [];
@@ -396,6 +423,13 @@ export const setParametersInForeignObject = (element, defaultParams = {}) => {
396423
"data-toggle": "tooltip",
397424
"data-placement": "right"
398425
})
426+
.on("click", function() {
427+
const win = window.open(
428+
`${BASE_URL}services/service?id=${serviceId}`,
429+
"_blank"
430+
);
431+
win.focus();
432+
})
399433
.appendTo(foreignObject.find(`.${TITLE_ROW_CLASS}`));
400434
}
401435

src/styles/mainContent.scss

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ input[type="file"]:hover {
9696
display: block;
9797
width: 40px;
9898
margin: auto 10px auto auto;
99+
cursor: pointer;
99100

100101
svg {
101102
display: block;

0 commit comments

Comments
 (0)