Files
lucent-laravel/front/js/svelte/build/Report.svelte
T

83 lines
1.9 KiB
Svelte
Raw Normal View History

2023-10-04 23:48:12 +03:00
<script>
2023-10-08 13:46:05 +03:00
import {getContext, onMount} from "svelte";
2024-08-24 18:51:36 +03:00
import axios from "axios";
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() {
2024-08-24 18:51:36 +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;
2024-08-27 17:59:12 +03:00
anchorEl.scrollIntoView()
2023-10-08 13:46:05 +03:00
}
eventSource.onerror = (e) => {
console.log(e)
eventSource.close();
inProgress = false;
}
}
2023-10-05 13:03:17 +03:00
function buildWebsite(e) {
e.preventDefault();
2023-10-08 13:46:05 +03:00
inProgress = true;
2024-08-24 18:51:36 +03:00
axios.post(channel.lucentUrl + "/command/" + command.signature).then(response => {
2023-10-08 13:46:05 +03:00
connect()
2023-10-05 13:03:17 +03:00
})
2023-10-04 23:48:12 +03:00
}
2023-10-08 13:46:05 +03:00
onMount(() => {
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">
2023-10-05 13:03:17 +03:00
2023-10-04 23:48:12 +03:00
<h3 class="header-small mb-5">{title}</h3>
2024-08-24 18:51:36 +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}
<span class="badge text-bg-warning">
2024-08-24 18:51:36 +03:00
Action in progress
2023-10-08 13:46:05 +03:00
</span>
{/if}
{#if !inProgress && logs}
<span class="badge text-bg-info">
2024-08-24 18:51:36 +03:00
Action completed
2023-10-08 13:46:05 +03:00
</span>
{/if}
2023-10-05 13:03:17 +03:00
2023-10-08 13:46:05 +03:00
</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>
2024-08-27 17:59:12 +03:00
<style>
.logs{
max-height: 70vh;
overflow: scroll;
background: var(--p90);
color: var(--p10);
padding: 10px;
}
</style>