From 84e413181fd591ae77d85c268b2f2446e0b8d693 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 13 Nov 2019 10:17:01 +0100 Subject: [PATCH] log: show log fetching status * show a spinner while log is being fetched: while calling the api and while streaming the log * show when log doesn't exists * show error when fetching the log fails (with retry button) * show when there're no lines. --- src/components/log.vue | 69 +++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/src/components/log.vue b/src/components/log.vue index 87efb3e..00c2ad7 100644 --- a/src/components/log.vue +++ b/src/components/log.vue @@ -1,11 +1,44 @@ @@ -36,7 +69,11 @@ export default { lines: [], formatter: formatter, es: null, - fetching: false + fetching: false, + streaming: false, + done: false, + logExists: null, + error: null }; }, methods: { @@ -54,6 +91,9 @@ export default { }, async getLogs(follow) { this.items = []; + this.logExists = null; + this.error = null; + let path = "/logs?runID=" + this.runid + "&taskID=" + this.taskid; if (this.setup) { path += "&setup"; @@ -68,6 +108,7 @@ export default { this.fetching = true; let res = await fetch(apiurl(path), { signal: this.fetchAbort.signal }); if (res.status == 200) { + this.streaming = true; const reader = res.body.getReader(); let lastline = ""; @@ -76,6 +117,8 @@ export default { let { done, value } = await reader.read(); if (done) { this.fetching = false; + this.streaming = false; + this.done = true; return; } @@ -113,11 +156,18 @@ export default { j += part.length; this.lastitem = this.formatter.ansi_to_html(lastline); } + } else if (res.status == 404) { + this.logExists = false; + } else if (res.status == 500) { + this.error = true; } } catch (e) { + this.error = true; // TODO(sgotti) show that log fetching has failed } this.fetching = false; + this.streaming = false; + this.done = false; }, abortFetch() { if (this.fetchAbort) { @@ -170,6 +220,3 @@ export default { } }; - - \ No newline at end of file