Skip to content

Commit

Permalink
demo2 + dropdown + revert (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp authored Sep 8, 2024
1 parent a904ef1 commit 8cbae96
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 28 deletions.
10 changes: 7 additions & 3 deletions abap.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ for (const dirent of fs.readdirSync("open-abap-core/src", {recursive: true, with

/////////////////////////////////////////

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

{
Expand Down
17 changes: 12 additions & 5 deletions examples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ await initializeABAP();

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

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

const writer = new abap.Classes["ZCL_EXCEL_WRITER_2007"]();
await writer.constructor_();
const excel = await abap.Classes[className].zif_excel_demo_output$run();

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

fs.writeFileSync("public/zcl_excel_demo1.xlsx", Buffer.from(xstring.get(), "hex"));
const xstring = await writer.zif_excel_writer$write_file({io_excel: excel});

fs.writeFileSync("public/zcl_excel_demo" + i + ".xlsx", Buffer.from(xstring.get(), "hex"));
}
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"license": "MIT",
"devDependencies": {
"@abaplint/monaco": "^2.113.6",
"@abaplint/runtime": "^2.10.16",
"@abaplint/transpiler": "^2.10.16",
"@abaplint/transpiler-cli": "^2.10.16",
"@abaplint/runtime": "^2.10.17",
"@abaplint/transpiler": "^2.10.17",
"@abaplint/transpiler-cli": "^2.10.17",
"buffer": "^6.0.3",
"copy-webpack-plugin": "^12.0.2",
"crypto-browserify": "^3.12.0",
Expand Down
10 changes: 9 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
</head>
<body>
<div id="horizon" class="table">
<div id="container1" class="container">Todo: Dropdown, Revert</div>
<div id="container1" class="container">
<table><tr><td>
<select id="demoDropdown" name="demo">
</select>
</td><td>
<input type="button" id="revertButton" value="Revert"></input>
</td></tr>
</table>
</div>

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

Expand Down
Binary file modified public/zcl_excel_demo1.xlsx
Binary file not shown.
Binary file added public/zcl_excel_demo2.xlsx
Binary file not shown.
26 changes: 22 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ import * as abapMonaco from "@abaplint/monaco";
import Split from "split-grid";
import { abapfiles } from "./abap";

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

const filename = "file:///" + top;
let top = "zcl_excel_demo1.clas.abap";
const filename = "file:///zcl_demo.clas.abap";

const model1 = monaco.editor.createModel(
abapfiles[top],
"abap",
Expand Down Expand Up @@ -85,6 +87,21 @@ observer.observe(document.getElementById("horizon"), {

window.addEventListener("resize", updateEditorLayouts);

document.getElementById("revertButton").addEventListener("click", () => {
reg.updateFile(new abaplint.MemoryFile(filename, abapfiles[top]));
model1.setValue(abapfiles[top]);
abapChanged();
});

document.getElementById("demoDropdown").addEventListener("change", (e) => {
// @ts-ignore
top = document.getElementById("demoDropdown").value;

reg.updateFile(new abaplint.MemoryFile(filename, abapfiles[top]));
model1.setValue(abapfiles[top]);
abapChanged();
});

// see https://github.com/SimulatedGREG/electron-vue/issues/777
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncFunction
const AsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor`)();
Expand All @@ -98,7 +115,8 @@ async function abapChanged() {
abapMonaco.updateMarkers(reg, model1);

if (contents === abapfiles[top]) {
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>`;
const name = top.split(".")[0];
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>`;

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

0 comments on commit 8cbae96

Please sign in to comment.