Skip to content

Commit f4280d9

Browse files
committed
feat: order elements function, save workflow in order
1 parent 4938ba9 commit f4280d9

File tree

3 files changed

+81
-49
lines changed

3 files changed

+81
-49
lines changed

src/js/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ export let app;
183183
currentDataElements: {
184184
deep: true,
185185
handler(newValue, oldValue) {
186-
// const difference = findDifferenceBy(newValue, oldValue, "boxId");
186+
const difference = findDifferenceBy(newValue, oldValue, "boxId");
187+
console.log("TCL: handler -> difference", difference);
187188
// for (const { boxId, defaultParams } of difference) {
188189
// setSelectValueInElement(boxId, defaultParams[Types.SELECT.type]);
189190
// setInputValueInElement(boxId, defaultParams[Types.NUMBER.type]);

src/js/elements/orderElement.js

+33
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,36 @@ export const orderGraph = graph => {
3838

3939
app.$fitContent(app.paper);
4040
};
41+
42+
export const getOrderedElements = () => {
43+
const order = [];
44+
const { graph } = app;
45+
const sources = graph.getSources();
46+
47+
const addedBoxId = [];
48+
49+
for (const source of sources) {
50+
order.push(source);
51+
addedBoxId.push(source.attributes.boxId);
52+
53+
let children = graph.getNeighbors(source, { outbound: true });
54+
do {
55+
let allChildren = [];
56+
const noDuplicates = children.filter(
57+
({ attributes: { boxId } }) => !addedBoxId.includes(boxId)
58+
);
59+
//.sort((a,b) => graph.getNeighbors(b).length - graph.getNeighbors(a).length)
60+
61+
for (const child of noDuplicates) {
62+
order.push(child);
63+
addedBoxId.push(child.attributes.boxId);
64+
allChildren = allChildren.concat(
65+
graph.getNeighbors(child, { outbound: true })
66+
);
67+
}
68+
69+
children = allChildren;
70+
} while (children.length);
71+
}
72+
return order;
73+
};

src/js/workflows/saveWorkflow.js

+46-48
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,67 @@
55
import xml2js from "xml2js";
66
import { getWebserviceByName } from "../constants/globals";
77
import { app } from "../app";
8-
import { CATEGORY_DATATEST } from "../constants/constants";
8+
import { CATEGORY_DATATEST, CATEGORY_SERVICE } from "../constants/constants";
99
import { Validation } from "divaservices-utils";
1010
import { sendWorkflowSteps } from "../api/requests";
11+
import { getOrderedElements } from "../elements/orderElement";
1112

1213
// we use the actual graph nodes to get the workflow
1314
// because it contains vital ids (especially ports)
1415
// we make a connection with our store elements
1516
// to retrieve the actual parameters
1617
export const saveWorkflow = jsonGraph => {
18+
const orderedElements = getOrderedElements().filter(
19+
({ attributes: { category } }) => category == CATEGORY_SERVICE
20+
);
21+
1722
const log = [];
1823
const Steps = { Step: [] };
1924
// NODE
20-
app.currentElements
21-
.filter(({ category }) => category != CATEGORY_DATATEST)
22-
.forEach((box, i) => {
23-
const { type, boxId } = box;
24-
const Name = type.replace(/\s/g, "");
25-
const No = i;
26-
const Inputs = { Parameter: [], Data: [] };
27-
28-
// get actual defaultParams in store
29-
const defaultParams = app.elements.find(el => el.boxId == boxId)
30-
.defaultParams;
31-
32-
for (const [paramType, values] of Object.entries(defaultParams)) {
33-
for (const [paramName, options] of Object.entries(values)) {
34-
const { value: Value, defaultValue, values } = options;
35-
if (Value != defaultValue.toString()) {
36-
Inputs.Parameter.push({
37-
Name: paramName,
38-
Value
39-
});
40-
}
41-
const validity = Validation.checkValue(Value, paramType, values);
42-
if (!validity) {
43-
log.push({
44-
value: Value,
45-
Name: paramName,
46-
paramType,
47-
name: type,
48-
boxId
49-
});
50-
}
25+
26+
for (const [i, { attributes: box }] of orderedElements.entries()) {
27+
// app.currentElements
28+
// .filter(({ category }) => category != CATEGORY_DATATEST)
29+
// .forEach((box, i) => {
30+
const { type, boxId } = box;
31+
const Name = type.replace(/\s/g, "");
32+
const No = i;
33+
const Inputs = { Parameter: [], Data: [] };
34+
35+
// get actual defaultParams in store
36+
const defaultParams = app.elements.find(el => el.boxId == boxId)
37+
.defaultParams;
38+
39+
for (const [paramType, values] of Object.entries(defaultParams)) {
40+
for (const [paramName, options] of Object.entries(values)) {
41+
const { value: Value, defaultValue, values } = options;
42+
if (Value != defaultValue.toString()) {
43+
Inputs.Parameter.push({
44+
Name: paramName,
45+
Value
46+
});
47+
}
48+
const validity = Validation.checkValue(Value, paramType, values);
49+
if (!validity) {
50+
log.push({
51+
value: Value,
52+
Name: paramName,
53+
paramType,
54+
name: type,
55+
boxId
56+
});
5157
}
5258
}
59+
}
5360

54-
// ports.items.forEach(port => {
55-
// console.log(port);
56-
// allPorts[port.id] = {
57-
// boxId,
58-
// boxNo: i,
59-
// name: port.name
60-
// };
61-
// });
62-
63-
// key in webservices list
64-
const Key = getWebserviceByName(type).id;
65-
const Service = { Key };
61+
// key in webservices list
62+
const Key = getWebserviceByName(type).id;
63+
const Service = { Key };
6664

67-
const step = { Id: boxId, No, Name, Service, Inputs };
68-
Steps.Step.push(step);
69-
});
65+
const step = { Id: boxId, No, Name, Service, Inputs };
66+
Steps.Step.push(step);
67+
// });
68+
}
7069

7170
// save data elements
7271
const dataPorts = {};
@@ -131,7 +130,6 @@ export const saveWorkflow = jsonGraph => {
131130

132131
// remove Id to match relax validation schema
133132
for (const step of Steps.Step) {
134-
console.log("TCL: step", step);
135133
delete step.Id;
136134
}
137135

0 commit comments

Comments
 (0)