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

72 lines
1.5 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";
2023-10-17 18:56:37 +03:00
2023-10-04 23:48:12 +03:00
const channel = getContext("channel");
export let title;
2023-10-05 13:03:17 +03:00
$: date = "";
$: logs = "";
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() {
const eventSource = new EventSource(channel.lucentUrl + "/build-report-source");
eventSource.onmessage = function (event) {
inProgress = true;
const data = JSON.parse(event.data);
date = data.date;
logs = data.logs;
}
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;
2023-10-05 13:03:17 +03:00
axios.post(channel.lucentUrl + "/build").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-17 21:10:01 +03:00
<button on:click={buildWebsite} class="button primary mb-3" disabled={inProgress}>Start Build
2023-10-08 13:46:05 +03:00
</button>
<div class="mb-3">
{#if inProgress}
<span class="badge text-bg-warning">
Build in progress
</span>
{/if}
{#if !inProgress && logs}
<span class="badge text-bg-info">
2023-10-16 13:16:22 +03:00
Build 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
<pre>{logs}</pre>
2023-10-04 23:48:12 +03:00
</div>
</div>