From f064719515b10e516b60368bd72919a9d58633fd Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Tue, 24 Jan 2023 23:48:09 -0300 Subject: [PATCH] add some logging for #133 Signed-off-by: Victor Seiji Hariki --- index.html | 2 +- js/lib/commands.d.js | 1 + js/ui/floating/history.js | 16 ++++++++++++++++ js/ui/tool/select.js | 3 ++- js/ui/tool/stamp.js | 31 ++++++++++++++++++------------- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 94ed8c7..a47c565 100644 --- a/index.html +++ b/index.html @@ -247,7 +247,7 @@
History
-
diff --git a/js/lib/commands.d.js b/js/lib/commands.d.js index 9845c91..b69ea8c 100644 --- a/js/lib/commands.d.js +++ b/js/lib/commands.d.js @@ -8,6 +8,7 @@ * @property {() => void | Promise} redo A method to redo whatever undo did * @property {() => any | Promise} export A method to export the command * @property {{[key: string]: any}} state The state of the current command instance + * @property {{[key: string]: any}} extra Extra information saved with the command */ /** diff --git a/js/ui/floating/history.js b/js/ui/floating/history.js index 4712086..87a4d9d 100644 --- a/js/ui/floating/history.js +++ b/js/ui/floating/history.js @@ -1,4 +1,20 @@ (() => { + const historyLogBtn = document.getElementById("history-logs-btn"); + historyLogBtn.addEventListener("click", () => { + let logs = ""; + commands._history.forEach((entry) => { + if (entry.extra.log) logs += ` => ${entry.extra.log}\n`; + }); + + const blob = new Blob([logs], {type: "text/plain"}); + const url = URL.createObjectURL(blob); + + var link = document.createElement("a"); // Or maybe get it from the current document + link.href = url; + link.download = `${new Date().toISOString()}_openOutpaint_log.txt`; + link.click(); + }); + const historyView = document.getElementById("history"); const makeHistoryEntry = (index, id, title) => { diff --git a/js/ui/tool/select.js b/js/ui/tool/select.js index b66425d..0f07427 100644 --- a/js/ui/tool/select.js +++ b/js/ui/tool/select.js @@ -298,7 +298,8 @@ const selectTransformTool = () => ` - rotation : ${ Math.round(1000 * ((180 * state.selected.rotation) / Math.PI)) / 1000 - } degrees` + } degrees`, + false ); // Draw Image diff --git a/js/ui/tool/stamp.js b/js/ui/tool/stamp.js index e3fb597..33c61df 100644 --- a/js/ui/tool/stamp.js +++ b/js/ui/tool/stamp.js @@ -418,21 +418,26 @@ const stampTool = () => const resource = state.selected; - let commandLog = `Stamped image '${resource.name}' to x: ${resource.x} and y: ${resource.y}`; - - const addline = (v, newline = true) => { - commandLog += v; - if (newline) commandLog += "\n"; - }; - addline(` - scaling : ${state.scale}`); - addline( - ` - rotation: ${ - Math.round(1000 * ((180 * rotation) / Math.PI)) / 1000 - } degrees` - ); - if (resource) { const {canvas, bb} = cropCanvas(ovCanvas, {border: 10}); + + let commandLog = ""; + + const addline = (v, newline = true) => { + commandLog += v; + if (newline) commandLog += "\n"; + }; + addline( + `Stamped image '${resource.name}' to x: ${bb.x} and y: ${bb.y}` + ); + addline(` - scaling : ${state.scale}`); + addline( + ` - rotation: ${ + Math.round(1000 * ((180 * rotation) / Math.PI)) / 1000 + } degrees`, + false + ); + commands.runCommand( "drawImage", "Image Stamp",