From 709d6ac2ad320efa0ab1681ce5eb93a6f2c876e6 Mon Sep 17 00:00:00 2001 From: James Read Date: Fri, 28 Mar 2025 23:48:26 +0000 Subject: [PATCH] feature: Allow rendering output as HTML (#544) --- service/internal/config/sanitize.go | 3 +++ webui.dev/index.html | 1 + webui.dev/js/ExecutionDialog.js | 14 +++++++++++++- webui.dev/js/marshaller.js | 22 +++++++++++++--------- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/service/internal/config/sanitize.go b/service/internal/config/sanitize.go index 644fc17..2a93759 100644 --- a/service/internal/config/sanitize.go +++ b/service/internal/config/sanitize.go @@ -77,10 +77,13 @@ func getActionID(action *Action) string { return action.ID } +//gocyclo:ignore func sanitizePopupOnStart(raw string, cfg *Config) string { switch raw { case "execution-dialog": return raw + case "execution-dialog-output-html": + return raw case "execution-dialog-stdout-only": return raw case "execution-button": diff --git a/webui.dev/index.html b/webui.dev/index.html index bb38eda..485a3ca 100644 --- a/webui.dev/index.html +++ b/webui.dev/index.html @@ -153,6 +153,7 @@
+
diff --git a/webui.dev/js/ExecutionDialog.js b/webui.dev/js/ExecutionDialog.js index 4fef223..2e40af1 100644 --- a/webui.dev/js/ExecutionDialog.js +++ b/webui.dev/js/ExecutionDialog.js @@ -11,6 +11,7 @@ export class ExecutionDialog { this.domIcon = document.getElementById('execution-dialog-icon') this.domTitle = document.getElementById('execution-dialog-title') this.domOutput = document.getElementById('execution-dialog-xterm') + this.domOutputHtml = document.getElementById('execution-dialog-output-html') this.domOutputToggleBig = document.getElementById('execution-dialog-toggle-size') this.domOutputToggleBig.onclick = () => { this.toggleSize() @@ -197,7 +198,17 @@ export class ExecutionDialog { clearInterval(window.executionDialogTicker) - this.domOutput.hidden = false + if ("type" in res && res.type == "execution-dialog-output-html") { + this.domOutputHtml.hidden = false + this.domOutput.hidden = true + this.domOutputHtml.innerHTML = res.logEntry.output + this.domOutputHtml.hidden = false + this.hideDetailsonResult = true + } else { + this.domOutput.hidden = false + this.domOutputHtml.innerHTML = '' + this.domOutputHtml.hidden = true + } if (this.hideDetailsOnResult) { this.domExecutionDetails.hidden = true @@ -218,6 +229,7 @@ export class ExecutionDialog { this.updateDuration(res.logEntry) + window.terminal.reset() window.terminal.write(res.logEntry.output, () => { window.terminal.fit() diff --git a/webui.dev/js/marshaller.js b/webui.dev/js/marshaller.js index 281635d..9ebd112 100644 --- a/webui.dev/js/marshaller.js +++ b/webui.dev/js/marshaller.js @@ -158,28 +158,31 @@ function onExecutionFinished (evt) { return } + let feedbackButton = actionButton; + switch (actionButton.popupOnStart) { case 'execution-button': - if (document.querySelector('execution-button#execution-' + logEntry.executionTrackingId) !== null) { // If the button was created in our instance - document.querySelector('execution-button#execution-' + logEntry.executionTrackingId).onExecutionFinished(logEntry) - } + let executionButton = document.querySelector('execution-button#execution-' + logEntry.executionTrackingId) + + if (executionButton != null) { + feedbackButton = executionButton + } + break + case 'execution-dialog-output-html': case 'execution-dialog-stdout-only': case 'execution-dialog': - actionButton.onExecutionFinished(logEntry) - // We don't need to fetch the logEntry for the dialog because we already // have it, so we open the dialog and it will get updated below. window.executionDialog.show() window.executionDialog.executionTrackingId = logEntry.uuid - break - default: - actionButton.onExecutionFinished(logEntry) break } + feedbackButton.onExecutionFinished(logEntry) + marshalLogsJsonToHtml({ logs: [logEntry] }) @@ -187,7 +190,8 @@ function onExecutionFinished (evt) { // If the current execution dialog is open, update that too if (window.executionDialog.dlg.open && window.executionDialog.executionUuid === logEntry.uuid) { window.executionDialog.renderExecutionResult({ - logEntry: logEntry + logEntry: logEntry, + type: actionButton.popupOnStart, }) } }