Skip to content

Commit 8cbae96

Browse files
authored
demo2 + dropdown + revert (#10)
1 parent a904ef1 commit 8cbae96

File tree

8 files changed

+65
-28
lines changed

8 files changed

+65
-28
lines changed

abap.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ for (const dirent of fs.readdirSync("open-abap-core/src", {recursive: true, with
3030

3131
/////////////////////////////////////////
3232

33-
{
34-
const contents = fs.readFileSync("abap2xlsx-demos/src/demo001/zcl_excel_demo1.clas.abap", "utf-8").toString("utf-8");
35-
add("zcl_excel_demo1.clas.abap", contents);
33+
for (let i = 1; i < 10; i++) {
34+
try {
35+
const contents = fs.readFileSync("abap2xlsx-demos/src/demo00" + i + "/zcl_excel_demo" + i + ".clas.abap", "utf-8").toString("utf-8");
36+
add("zcl_excel_demo" + i + ".clas.abap", contents);
37+
} catch {
38+
break;
39+
}
3640
}
3741

3842
{

examples.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ await initializeABAP();
44

55
console.log("Running examples.mjs");
66

7-
const excel = await abap.Classes["ZCL_EXCEL_DEMO1"].zif_excel_demo_output$run();
7+
for (let i = 1; i < 10; i++) {
8+
const className = "ZCL_EXCEL_DEMO" + i;
9+
if (abap.Classes[className] === undefined) {
10+
break;
11+
}
812

9-
const writer = new abap.Classes["ZCL_EXCEL_WRITER_2007"]();
10-
await writer.constructor_();
13+
const excel = await abap.Classes[className].zif_excel_demo_output$run();
1114

12-
const xstring = await writer.zif_excel_writer$write_file({io_excel: excel});
15+
const writer = new abap.Classes["ZCL_EXCEL_WRITER_2007"]();
16+
await writer.constructor_();
1317

14-
fs.writeFileSync("public/zcl_excel_demo1.xlsx", Buffer.from(xstring.get(), "hex"));
18+
const xstring = await writer.zif_excel_writer$write_file({io_excel: excel});
19+
20+
fs.writeFileSync("public/zcl_excel_demo" + i + ".xlsx", Buffer.from(xstring.get(), "hex"));
21+
}

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"license": "MIT",
1818
"devDependencies": {
1919
"@abaplint/monaco": "^2.113.6",
20-
"@abaplint/runtime": "^2.10.16",
21-
"@abaplint/transpiler": "^2.10.16",
22-
"@abaplint/transpiler-cli": "^2.10.16",
20+
"@abaplint/runtime": "^2.10.17",
21+
"@abaplint/transpiler": "^2.10.17",
22+
"@abaplint/transpiler-cli": "^2.10.17",
2323
"buffer": "^6.0.3",
2424
"copy-webpack-plugin": "^12.0.2",
2525
"crypto-browserify": "^3.12.0",

public/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
</head>
99
<body>
1010
<div id="horizon" class="table">
11-
<div id="container1" class="container">Todo: Dropdown, Revert</div>
11+
<div id="container1" class="container">
12+
<table><tr><td>
13+
<select id="demoDropdown" name="demo">
14+
</select>
15+
</td><td>
16+
<input type="button" id="revertButton" value="Revert"></input>
17+
</td></tr>
18+
</table>
19+
</div>
1220

1321
<div id="gutter1" class="gutter"></div>
1422

public/zcl_excel_demo1.xlsx

0 Bytes
Binary file not shown.

public/zcl_excel_demo2.xlsx

6.66 KB
Binary file not shown.

src/index.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ import * as abapMonaco from "@abaplint/monaco";
2525
import Split from "split-grid";
2626
import { abapfiles } from "./abap";
2727

28-
const top = "zcl_excel_demo1.clas.abap";
2928
const reg = new abaplint.Registry(new abaplint.Config(JSON.stringify(config)));
3029
for (const filename in abapfiles) {
31-
if (filename === top) {
30+
if (filename.indexOf("zcl_excel_demo") === 0) {
31+
document.getElementById("demoDropdown").innerHTML += `<option value="${filename}">${filename}</option>\n`;
3232
continue;
3333
}
3434
reg.addFile(new abaplint.MemoryFile(filename, abapfiles[filename]));
3535
}
3636
abapMonaco.registerABAP(reg);
3737

38-
const filename = "file:///" + top;
38+
let top = "zcl_excel_demo1.clas.abap";
39+
const filename = "file:///zcl_demo.clas.abap";
40+
3941
const model1 = monaco.editor.createModel(
4042
abapfiles[top],
4143
"abap",
@@ -85,6 +87,21 @@ observer.observe(document.getElementById("horizon"), {
8587

8688
window.addEventListener("resize", updateEditorLayouts);
8789

90+
document.getElementById("revertButton").addEventListener("click", () => {
91+
reg.updateFile(new abaplint.MemoryFile(filename, abapfiles[top]));
92+
model1.setValue(abapfiles[top]);
93+
abapChanged();
94+
});
95+
96+
document.getElementById("demoDropdown").addEventListener("change", (e) => {
97+
// @ts-ignore
98+
top = document.getElementById("demoDropdown").value;
99+
100+
reg.updateFile(new abaplint.MemoryFile(filename, abapfiles[top]));
101+
model1.setValue(abapfiles[top]);
102+
abapChanged();
103+
});
104+
88105
// see https://github.com/SimulatedGREG/electron-vue/issues/777
89106
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
90107
const AsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor`)();
@@ -98,7 +115,8 @@ async function abapChanged() {
98115
abapMonaco.updateMarkers(reg, model1);
99116

100117
if (contents === abapfiles[top]) {
101-
document.getElementById("container2").innerHTML = `<iframe src="https://view.officeapps.live.com/op/view.aspx?src=https://abap2xlsx.github.io/abap2xlsx-web/zcl_excel_demo1.xlsx" title="Excel"></iframe>`;
118+
const name = top.split(".")[0];
119+
document.getElementById("container2").innerHTML = `<iframe src="https://view.officeapps.live.com/op/view.aspx?src=https://abap2xlsx.github.io/abap2xlsx-web/${name}.xlsx" title="Excel"></iframe>`;
102120

103121
setTimeout(() => monaco.editor.getEditors()[0].focus(), 1000);
104122
} else {

0 commit comments

Comments
 (0)