mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
feat: show loader while opening event source (#3388)
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<InfiniteLoader :onLoadMore="fetchMore" :enabled="!loadingMore && messages.length > 10" />
|
<InfiniteLoader :onLoadMore="fetchMore" :enabled="!loadingMore && messages.length > 10" />
|
||||||
|
<div v-if="!opened" class="m-4 text-center">
|
||||||
|
<span class="loading loading-ring loading-md text-primary"></span>
|
||||||
|
</div>
|
||||||
<slot :messages="messages"></slot>
|
<slot :messages="messages"></slot>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -11,7 +14,7 @@ const { entity, streamSource } = $defineProps<{
|
|||||||
entity: T;
|
entity: T;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const { messages, loadOlderLogs, isLoadingMore } = streamSource($$(entity));
|
const { messages, loadOlderLogs, isLoadingMore, opened } = streamSource($$(entity));
|
||||||
const { loadingMore } = useLoggingContext();
|
const { loadingMore } = useLoggingContext();
|
||||||
|
|
||||||
const enabled = ref(true);
|
const enabled = ref(true);
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<ul
|
<ul class="events group pt-4" :class="{ 'disable-wrap': !softWrap, [size]: true, compact }">
|
||||||
class="events group pt-4"
|
|
||||||
:class="{ 'disable-wrap': !softWrap, [size]: true, compact }"
|
|
||||||
v-if="messages.length > 0"
|
|
||||||
>
|
|
||||||
<li
|
<li
|
||||||
v-for="item in messages"
|
v-for="item in messages"
|
||||||
ref="list"
|
ref="list"
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ exports[`<ContainerEventSource /> > render html correctly > should render messag
|
|||||||
|
|
||||||
exports[`<ContainerEventSource /> > renders loading correctly 1`] = `
|
exports[`<ContainerEventSource /> > renders loading correctly 1`] = `
|
||||||
"<div class="flex min-h-[1px] justify-center"><span class="loading loading-bars loading-md mt-4 text-primary" style="display: none;"></span></div>
|
"<div class="flex min-h-[1px] justify-center"><span class="loading loading-bars loading-md mt-4 text-primary" style="display: none;"></span></div>
|
||||||
<!--v-if-->"
|
<div class="m-4 text-center"><span class="loading loading-ring loading-md text-primary"></span></div>
|
||||||
|
<ul data-v-cf9ff940="" class="events group pt-4 medium"></ul>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`<ContainerEventSource /> > should parse messages 1`] = `
|
exports[`<ContainerEventSource /> > should parse messages 1`] = `
|
||||||
|
|||||||
@@ -20,9 +20,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div ref="scrollableContent">
|
<div ref="scrollableContent">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<div v-if="scrollContext.loading" class="m-4 text-center">
|
|
||||||
<span class="loading loading-ring loading-md text-primary"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="animate-background h-1 w-1/2 bg-gradient-radial from-primary to-transparent to-75%"
|
class="animate-background h-1 w-1/2 bg-gradient-radial from-primary to-transparent to-75%"
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export type LogStreamSource = ReturnType<typeof useLogStream>;
|
|||||||
function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
|
function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
|
||||||
const messages: ShallowRef<LogEntry<string | JSONObject>[]> = shallowRef([]);
|
const messages: ShallowRef<LogEntry<string | JSONObject>[]> = shallowRef([]);
|
||||||
const buffer: ShallowRef<LogEntry<string | JSONObject>[]> = shallowRef([]);
|
const buffer: ShallowRef<LogEntry<string | JSONObject>[]> = shallowRef([]);
|
||||||
|
const opened = ref(false);
|
||||||
const { paused: scrollingPaused } = useScrollContext();
|
const { paused: scrollingPaused } = useScrollContext();
|
||||||
|
|
||||||
function flushNow() {
|
function flushNow() {
|
||||||
@@ -122,6 +123,7 @@ function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
|
|||||||
function connect({ clear } = { clear: true }) {
|
function connect({ clear } = { clear: true }) {
|
||||||
close();
|
close();
|
||||||
if (clear) clearMessages();
|
if (clear) clearMessages();
|
||||||
|
opened.value = false;
|
||||||
es = new EventSource(urlWithParams.value);
|
es = new EventSource(urlWithParams.value);
|
||||||
es.addEventListener("container-event", (e) => {
|
es.addEventListener("container-event", (e) => {
|
||||||
const event = JSON.parse((e as MessageEvent).data) as { actorId: string; name: string };
|
const event = JSON.parse((e as MessageEvent).data) as { actorId: string; name: string };
|
||||||
@@ -150,6 +152,9 @@ function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
es.onerror = () => clearMessages();
|
es.onerror = () => clearMessages();
|
||||||
|
es.onopen = () => {
|
||||||
|
opened.value = true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(urlWithParams, () => connect(), { immediate: true });
|
watch(urlWithParams, () => connect(), { immediate: true });
|
||||||
@@ -205,5 +210,5 @@ function useLogStream(url: Ref<string>, loadMoreUrl?: Ref<string>) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return { messages, loadOlderLogs, isLoadingMore, hasComplexLogs };
|
return { messages, loadOlderLogs, isLoadingMore, hasComplexLogs, opened };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,7 +164,9 @@ Cache-Control: no-cache
|
|||||||
Connection: keep-alive
|
Connection: keep-alive
|
||||||
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
|
Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn.jsdelivr.net https://*.duckdb.org; style-src 'self' 'unsafe-inline'; img-src 'self' data:;
|
||||||
Content-Type: text/event-stream
|
Content-Type: text/event-stream
|
||||||
X-Accel-Buffering: no
|
X-Accel-Buffering: no
|
||||||
|
|
||||||
|
:ping
|
||||||
|
|
||||||
/* snapshot: Test_handler_streamLogs_error_std */
|
/* snapshot: Test_handler_streamLogs_error_std */
|
||||||
HTTP/1.1 400 Bad Request
|
HTTP/1.1 400 Bad Request
|
||||||
@@ -185,6 +187,8 @@ Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn
|
|||||||
Content-Type: text/event-stream
|
Content-Type: text/event-stream
|
||||||
X-Accel-Buffering: no
|
X-Accel-Buffering: no
|
||||||
|
|
||||||
|
:ping
|
||||||
|
|
||||||
data: {"m":"INFO Testing logs...","ts":0,"id":4256192898,"l":"info","s":"stdout","c":"123456"}
|
data: {"m":"INFO Testing logs...","ts":0,"id":4256192898,"l":"info","s":"stdout","c":"123456"}
|
||||||
|
|
||||||
|
|
||||||
@@ -201,6 +205,8 @@ Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn
|
|||||||
Content-Type: text/event-stream
|
Content-Type: text/event-stream
|
||||||
X-Accel-Buffering: no
|
X-Accel-Buffering: no
|
||||||
|
|
||||||
|
:ping
|
||||||
|
|
||||||
event: container-event
|
event: container-event
|
||||||
data: {"name":"container-stopped","host":"localhost","actorId":"123456"}
|
data: {"name":"container-stopped","host":"localhost","actorId":"123456"}
|
||||||
|
|
||||||
@@ -214,6 +220,8 @@ Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval' blob: https://cdn
|
|||||||
Content-Type: text/event-stream
|
Content-Type: text/event-stream
|
||||||
X-Accel-Buffering: no
|
X-Accel-Buffering: no
|
||||||
|
|
||||||
|
:ping
|
||||||
|
|
||||||
data: {"m":"INFO Testing logs...","ts":1589396137772,"id":1469707724,"l":"info","s":"stdout","c":"123456"}
|
data: {"m":"INFO Testing logs...","ts":1589396137772,"id":1469707724,"l":"info","s":"stdout","c":"123456"}
|
||||||
id: 1589396137772
|
id: 1589396137772
|
||||||
|
|
||||||
|
|||||||
@@ -395,6 +395,7 @@ func streamLogsForContainers(w http.ResponseWriter, r *http.Request, multiHostCl
|
|||||||
multiHostClient.SubscribeContainersStarted(r.Context(), newContainers, filter)
|
multiHostClient.SubscribeContainersStarted(r.Context(), newContainers, filter)
|
||||||
|
|
||||||
ticker := time.NewTicker(5 * time.Second)
|
ticker := time.NewTicker(5 * time.Second)
|
||||||
|
sseWriter.Ping()
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|||||||
Reference in New Issue
Block a user