mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 13:23:07 +01:00
* feat: moves to tailwindcss and better component library * update styles * creates toggle component * adds drop down component * cleans up components * removes unused components * uses tailwind for scroll view * removes table component * improves animation * cleans up more styles * uses more tailwind * cleans up more styles with flex * more styles * removes bulma * adds colors * updates modules * fixes bugs * stops importing styles.scss * more clean up * cleans up headers * cleans up title * fixes title * fixes mobile-hidden * fixes shadow * fixes colors * add tailwindcss/nesting * adds more colors * fixes more colors * updates colors * fixes colors * colors * fixes menu on left * menu and modal * menu and modal * fuzzy search * fixes menu on left * remove logs * cleans up search * adds host to search * remove outline from inputs * cleans up left search icon * removes unused styles * fixes docker * removes sass! * cleans up styles * Fixe smobile menu * fixes mobile menu * fixes typecheck * fixes seconday color * adds drop down for container * cleans header css * updates css * fixes other layouts * updates some tests * fixes border * fixes home screen font * fixes top header * fixes tests * fixes fieldlist * fixes complex * cleans up more * removes index * fixes tests * fixes tests * resolves conflicts
118 lines
3.7 KiB
TypeScript
118 lines
3.7 KiB
TypeScript
import { acceptHMRUpdate, defineStore } from "pinia";
|
|
import { Ref, UnwrapNestedRefs } from "vue";
|
|
import type { ContainerHealth, ContainerJson, ContainerStat } from "@/types/Container";
|
|
import { Container } from "@/models/Container";
|
|
|
|
export const useContainerStore = defineStore("container", () => {
|
|
const containers: Ref<Container[]> = ref([]);
|
|
const activeContainerIds: Ref<string[]> = ref([]);
|
|
let es: EventSource | null = null;
|
|
const ready = ref(false);
|
|
|
|
const allContainersById = computed(() =>
|
|
containers.value.reduce(
|
|
(acc, container) => {
|
|
acc[container.id] = container;
|
|
return acc;
|
|
},
|
|
{} as Record<string, Container>,
|
|
),
|
|
);
|
|
|
|
const visibleContainers = computed(() => {
|
|
const filter = showAllContainers.value ? () => true : (c: Container) => c.state === "running";
|
|
return containers.value.filter(filter);
|
|
});
|
|
|
|
const activeContainers = computed(() => activeContainerIds.value.map((id) => allContainersById.value[id]));
|
|
|
|
function connect() {
|
|
es?.close();
|
|
ready.value = false;
|
|
es = new EventSource(`${config.base}/api/events/stream`);
|
|
|
|
es.addEventListener("containers-changed", (e: Event) =>
|
|
updateContainers(JSON.parse((e as MessageEvent).data) as ContainerJson[]),
|
|
);
|
|
es.addEventListener("container-stat", (e) => {
|
|
const stat = JSON.parse((e as MessageEvent).data) as ContainerStat;
|
|
const container = allContainersById.value[stat.id] as unknown as UnwrapNestedRefs<Container>;
|
|
if (container) {
|
|
const { id, ...rest } = stat;
|
|
container.updateStat(rest);
|
|
}
|
|
});
|
|
es.addEventListener("container-die", (e) => {
|
|
const event = JSON.parse((e as MessageEvent).data) as { actorId: string };
|
|
const container = allContainersById.value[event.actorId];
|
|
if (container) {
|
|
container.state = "dead";
|
|
}
|
|
});
|
|
|
|
es.addEventListener("container-health", (e) => {
|
|
const event = JSON.parse((e as MessageEvent).data) as { actorId: string; health: ContainerHealth };
|
|
const container = allContainersById.value[event.actorId];
|
|
if (container) {
|
|
container.health = event.health;
|
|
}
|
|
});
|
|
|
|
watchOnce(containers, () => (ready.value = true));
|
|
}
|
|
|
|
connect();
|
|
|
|
const updateContainers = (containersPayload: ContainerJson[]) => {
|
|
const existingContainers = containersPayload.filter((c) => allContainersById.value[c.id]);
|
|
const newContainers = containersPayload.filter((c) => !allContainersById.value[c.id]);
|
|
|
|
existingContainers.forEach((c) => {
|
|
const existing = allContainersById.value[c.id];
|
|
existing.status = c.status;
|
|
existing.state = c.state;
|
|
existing.health = c.health;
|
|
});
|
|
|
|
containers.value = [
|
|
...containers.value,
|
|
...newContainers.map((c) => {
|
|
return new Container(
|
|
c.id,
|
|
new Date(c.created * 1000),
|
|
c.image,
|
|
c.name,
|
|
c.command,
|
|
c.host,
|
|
c.status,
|
|
c.state,
|
|
c.health,
|
|
);
|
|
}),
|
|
];
|
|
};
|
|
|
|
const currentContainer = (id: Ref<string>) => computed(() => allContainersById.value[id.value]);
|
|
const appendActiveContainer = ({ id }: { id: string }) => activeContainerIds.value.push(id);
|
|
const removeActiveContainer = ({ id }: { id: string }) =>
|
|
activeContainerIds.value.splice(activeContainerIds.value.indexOf(id), 1);
|
|
|
|
return {
|
|
containers,
|
|
activeContainerIds,
|
|
allContainersById,
|
|
visibleContainers,
|
|
activeContainers,
|
|
currentContainer,
|
|
appendActiveContainer,
|
|
removeActiveContainer,
|
|
ready,
|
|
};
|
|
});
|
|
|
|
// @ts-ignore
|
|
if (import.meta.hot) {
|
|
// @ts-ignore
|
|
import.meta.hot.accept(acceptHMRUpdate(useContainerStore, import.meta.hot));
|
|
}
|