Files

82 lines
2.0 KiB
Svelte
Raw Permalink Normal View History

2023-10-04 23:48:12 +03:00
<script>
2026-05-07 22:50:02 +03:00
import { getContext, onMount } from "svelte";
import { apiPost } from "../../helpers";
2023-10-04 23:48:12 +03:00
const channel = getContext("channel");
export let title;
2024-08-24 18:51:36 +03:00
export let command;
2023-10-05 13:03:17 +03:00
$: date = "";
$: logs = "";
2024-08-24 18:51:36 +03:00
2024-08-27 17:59:12 +03:00
let anchorEl;
2023-10-08 13:46:05 +03:00
let inProgress = false;
2023-10-05 13:03:17 +03:00
2023-10-08 13:46:05 +03:00
function connect() {
2026-05-07 22:50:02 +03:00
const eventSource = new EventSource(
channel.lucentUrl + "/command-report-source/" + command.signature,
);
2023-10-08 13:46:05 +03:00
eventSource.onmessage = function (event) {
inProgress = true;
const data = JSON.parse(event.data);
date = data.date;
logs = data.logs;
2026-05-07 22:50:02 +03:00
anchorEl.scrollIntoView();
};
2023-10-08 13:46:05 +03:00
eventSource.onerror = (e) => {
2026-05-07 22:50:02 +03:00
console.log(e);
2023-10-08 13:46:05 +03:00
eventSource.close();
inProgress = false;
2026-05-07 22:50:02 +03:00
};
2023-10-08 13:46:05 +03:00
}
2023-10-05 13:03:17 +03:00
function buildWebsite(e) {
e.preventDefault();
2023-10-08 13:46:05 +03:00
inProgress = true;
2026-05-07 22:50:02 +03:00
apiPost(channel.lucentUrl + "/command/" + command.signature).then(
(response) => {
connect();
},
);
2023-10-04 23:48:12 +03:00
}
2023-10-08 13:46:05 +03:00
onMount(() => {
2026-05-07 22:50:02 +03:00
connect();
});
2023-10-04 23:48:12 +03:00
</script>
2024-08-17 21:10:01 +03:00
<div class="common-wrapper">
2023-10-04 23:48:12 +03:00
<div class="lx-card mt-5">
<h3 class="header-small mb-5">{title}</h3>
2026-05-07 22:50:02 +03:00
<button
on:click={buildWebsite}
class="button primary mb-3"
disabled={inProgress}
>Start
2023-10-08 13:46:05 +03:00
</button>
<div class="mb-3">
{#if inProgress}
2026-05-07 22:50:02 +03:00
<span class="badge text-bg-warning"> Action in progress </span>
2023-10-08 13:46:05 +03:00
{/if}
{#if !inProgress && logs}
2026-05-07 22:50:02 +03:00
<span class="badge text-bg-info"> Action completed </span>
2023-10-08 13:46:05 +03:00
{/if}
</div>
2023-10-05 13:03:17 +03:00
2024-08-27 17:59:12 +03:00
<pre class="logs">{logs}
<div bind:this={anchorEl}>&nbsp;</div>
</pre>
2023-10-04 23:48:12 +03:00
</div>
</div>
2026-05-07 22:50:02 +03:00
2024-08-27 17:59:12 +03:00
<style>
2026-05-07 22:50:02 +03:00
.logs {
2024-08-27 17:59:12 +03:00
max-height: 70vh;
overflow: scroll;
background: var(--p90);
color: var(--p10);
padding: 10px;
}
2026-05-07 22:50:02 +03:00
</style>