-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize.js
33 lines (29 loc) · 1.33 KB
/
initialize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
sap.ui.getCore().attachInit(function (data, navObj) {
// when the HTMLObject is rendered create the monaco editor in the div element
HTMLObject.addEventDelegate({
onAfterRendering: function () {
const monacoEditor = monaco.editor.create(document.getElementById("jsonEditor"), {
automaticLayout: true,
language: 'json',
theme: "vs-dark",
formatOnPaste: true,
});
// when the editor content is changed update the graph model
monacoEditor.onDidChangeModelContent(function (e) {
try {
const jsonString = monacoEditor.getValue().replaceAll("\n", "");
if (!jsonString) throw "Empty JSON.";
const jsonObj = JSON.parse(jsonString);
if (!Object.keys(jsonObj)) throw "Invalid JSON.";
modelGraph.setData(buildGraphData(jsonObj));
modelGraph.refresh(true);
} catch (err) {
sap.m.MessageToast.show(err);
modelGraph.setData([]);
modelGraph.refresh(true);
}
});
}
});
modelGraph.setSizeLimit(10000); // change the size limit if needed for larger json
});