Skip to content

Commit 444c5f9

Browse files
committed
refactor: use webservices to compute data inputs, fixes
1 parent f4280d9 commit 444c5f9

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

src/js/constants/dataTestDecorator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const dataTestDecorator = async xmlData => {
2121
Name: [name],
2222
Output: [output]
2323
} of xml.DataTests.Data) {
24-
const data = { name, outputType: output.Type[0], type: DATATEST_TYPE };
24+
const data = { name, outputType: output.Type[0], category: DATATEST_TYPE };
2525
const mimeType = output.MimeType;
2626
if (output.MimeType) {
2727
data.mimeType = mimeType[0];

src/js/constants/globals.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,50 @@ import { Decorators } from "divaservices-utils";
22
import { getServicesAPI } from "../api/requests";
33
import { INPUTS_DATA_XML_FILEPATH } from "../../config";
44
import { dataTestDecorator } from "./dataTestDecorator";
5+
import { DATATEST_TYPE } from "./constants";
56

67
export let webservices;
78
export let dataInputs;
89

910
const _initWebservices = async () => {
1011
const xml = await getServicesAPI();
11-
console.log("wefd");
1212
webservices = await Decorators.webservicesDecorator(xml);
13-
console.log("wefd");
1413
};
1514

16-
const _initDataInputs = async () => {
15+
const _initDataInputsOld = async () => {
1716
const inputDataFilePath = INPUTS_DATA_XML_FILEPATH;
1817
const inputDataXml = (await import(`!!raw-loader!../../${inputDataFilePath}`))
1918
.default;
2019
dataInputs = await dataTestDecorator(inputDataXml);
2120
};
2221

22+
const _initDataInputs = async () => {
23+
dataInputs = [
24+
...new Set( // remove duplicates
25+
webservices
26+
.map(service =>
27+
service.inputs.map(inp =>
28+
inp.mimeTypes ? inp.mimeTypes.allowed : null
29+
)
30+
)
31+
.flat(2)
32+
.filter(Boolean) // flat and filter null values
33+
)
34+
].map(mimetype => ({
35+
name: mimetype,
36+
category: DATATEST_TYPE,
37+
outputType: mimetype.split("/")[0],
38+
mimeType: mimetype
39+
}));
40+
};
41+
2342
// init webservices from xml file
2443
export const initWebservices = async () => {
2544
await _initWebservices();
45+
await _initDataInputsOld();
46+
console.log(dataInputs);
2647
await _initDataInputs();
48+
console.log(dataInputs);
2749
};
2850

2951
export const getWebserviceByName = name => {

src/js/elements/addDataElement.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ const createFolderInput = boxId => {
8585
return input;
8686
};
8787

88-
const createFileInput = ({ boxId }) => {
89-
const input = document.createElement("input");
90-
input.setAttribute("type", "file");
91-
input.classList.add("btn");
92-
// input.setAttribute("accept", mimeType);
93-
input.addEventListener("change", function() {
94-
const data = [...this.files];
95-
app.updateDataInDataElement({ boxId, data });
96-
});
97-
return input;
98-
};
88+
// const createFileInput = ({ boxId }) => {
89+
// const input = document.createElement("input");
90+
// input.setAttribute("type", "file");
91+
// input.classList.add("btn");
92+
// // input.setAttribute("accept", mimeType);
93+
// input.addEventListener("change", function() {
94+
// const data = [...this.files];
95+
// app.updateDataInDataElement({ boxId, data });
96+
// });
97+
// return input;
98+
// };
9999

100100
const createFileInputNew = ({ boxId }) => {
101101
const btn = document.createElement("button");
@@ -170,7 +170,7 @@ const addContent = ({ mimeType, outputType, boxId }) => {
170170
}
171171
default: {
172172
console.log("default for type : " + outputType);
173-
const input = createFileInput({ mimeType, boxId });
173+
const input = createFileInputNew({ mimeType, boxId });
174174
content.appendChild(input);
175175
}
176176
}

src/js/layout/inputs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export const setParametersInForeignObject = (element, defaultParams = {}) => {
425425
})
426426
.on("click", function() {
427427
const win = window.open(
428-
`${BASE_URL}services/service?id=${serviceId}`,
428+
`${BASE_URL}services/${serviceId}/view`,
429429
"_blank"
430430
);
431431
win.focus();

src/js/layout/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const buildPortAttrs = (name, type, typeAllowed) => {
189189
const showPortDetails = layoutSettingsApp.isShowPortsDetailsChecked();
190190
const showPorts = layoutSettingsApp.isShowPortsChecked();
191191
const typeAllowedShort = shortenString(typeAllowed.join(", "), 25);
192-
192+
console.log(type);
193193
return {
194194
[PORT_SELECTOR]: {
195195
fill: MimeTypes[type].color,

0 commit comments

Comments
 (0)