From 77f6f49d6fc019281cdb216df864e44b06625033 Mon Sep 17 00:00:00 2001 From: dcore94 Date: Fri, 21 Apr 2023 15:05:56 +0200 Subject: [PATCH] added triggers for saving and retrieving executions to/from workspace --- ccp/js/executionhistorycontroller.js | 76 ++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/ccp/js/executionhistorycontroller.js b/ccp/js/executionhistorycontroller.js index f0547e2..1cecae9 100644 --- a/ccp/js/executionhistorycontroller.js +++ b/ccp/js/executionhistorycontroller.js @@ -4,11 +4,14 @@ class CCPExecutionHistory extends HTMLElement { #rootdoc = null; #serviceurl = null; #broadcasturl = null; + #archive = null; #data = []; #filtered = []; #socket = null; #interval = null; #searchfield = null; + #fileupload = null; + #archiveupload = null; constructor(){ super() @@ -20,6 +23,7 @@ class CCPExecutionHistory extends HTMLElement { this.#broadcasturl = this.#serviceurl.replace(/^http/, "ws") } this.#broadcasturl = this.#broadcasturl + "/ws/notification" + this.#archive = this.getAttribute("archive") this.connectNewExecution() this.connectBroadcast() } @@ -73,15 +77,18 @@ class CCPExecutionHistory extends HTMLElement { + ${ this.#archive ? ` + ` + : `` + } - + + +
+ + +
- +
    @@ -155,6 +173,23 @@ class CCPExecutionHistory extends HTMLElement { this.#searchfield.addEventListener("input", ev=>{ this.updateList() }) + + this.#fileupload = this.#rootdoc.querySelector("label[name=fileupload] > input[type=file]") + this.#fileupload.addEventListener("change", ev=>{ + const filelist = ev.target.files; + if (filelist.length > 0) { + const files = Array.prototype.slice.call(filelist) + this.importExecutions(files) + } + }) + + this.#archiveupload = this.#rootdoc.querySelector("button[name=archive]") + this.#archiveupload.addEventListener("click", ev=>{ + const link = ev.target.parentElement.querySelector("input").value + if(link){ + this.fromArchive(link) + } + }) } updateList(){ @@ -332,6 +367,29 @@ class CCPExecutionHistory extends HTMLElement { }).catch(err=>{ alert(err)}) } + toArchive(id){ + this.#boot.secureFetch(`${this.#serviceurl}/executions/${id}/archive`, { method: "POST" }) + .then(reply =>{ + if (reply.status !== 200) { + throw "Unable to archive" + } + }).catch(err=>{ alert(err)}) + } + + fromArchive(url){ + if(url){ + this.#boot.secureFetch(`${this.#serviceurl}/executions/archive?url=${url}`) + .then(reply =>{ + if (reply.status !== 200) { + throw "Unable to fetch from archive" + } + return reply.text() + }).then(data=>{ + this.refreshExecutions() + }).catch(err=>{ alert(err)}) + } + } + #execution_list_bss = { template : "#EXECUTIOM_LIST_TEMPLATE", target : "ul[name=ccp_execution_list]", @@ -427,9 +485,9 @@ class CCPExecutionHistory extends HTMLElement { const id = ev.currentTarget.getAttribute("data-index") this.reexecute(id, 1) } - if(ev.target.getAttribute("name") === "reexecute2"){ + if(ev.target.getAttribute("name") === "archive"){ const id = ev.currentTarget.getAttribute("data-index") - this.reexecute(id, 2) + this.toArchive(id) } }, recurse : [