m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-13 15:43:49 -05:00

Add multiple server support to Liquid UI, CSS fixes

This commit is contained in:
Sergio
2025-02-07 17:25:06 +02:00
parent f1c8a45122
commit 0314ef2f05
6 changed files with 312 additions and 214 deletions

View File

@@ -2,6 +2,7 @@ use std::sync::Arc;
use chrono::Local; use chrono::Local;
use liquid::{object, Object, ValueView}; use liquid::{object, Object, ValueView};
use rustc_hash::FxHashMap;
use serde_json::Value; use serde_json::Value;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tokio_cron_scheduler::{Job, JobScheduler}; use tokio_cron_scheduler::{Job, JobScheduler};
@@ -184,11 +185,6 @@ impl ServerData {
.unwrap() .unwrap()
.parse(HTML) .parse(HTML)
.unwrap(); .unwrap();
let images = self
.raw_updates
.iter()
.map(|image| object!({"name": image.reference, "status": image.get_status().to_string()}),)
.collect::<Vec<Object>>();
self.simple_json = to_simple_json(&self.raw_updates); self.simple_json = to_simple_json(&self.raw_updates);
self.full_json = to_full_json(&self.raw_updates); self.full_json = to_full_json(&self.raw_updates);
let last_updated = Local::now(); let last_updated = Local::now();
@@ -219,9 +215,22 @@ impl ServerData {
.unwrap(), .unwrap(),
) )
}); });
let mut servers: FxHashMap<&str, Vec<Object>> = FxHashMap::default();
self.raw_updates.iter().for_each(|update| {
let key = update.server.as_deref().unwrap_or("");
match servers.get_mut(&key) {
Some(server) => server.push(
object!({"name": update.reference, "status": update.get_status().to_string()}),
),
None => {
let _ = servers.insert(key, vec![object!({"name": update.reference, "status": update.get_status().to_string()})]);
}
}
});
let globals = object!({ let globals = object!({
"metrics": metrics, "metrics": metrics,
"images": images, "servers": servers,
"server_ids": servers.into_keys().collect::<Vec<&str>>(),
"last_updated": last_updated.format("%Y-%m-%d %H:%M:%S").to_string(), "last_updated": last_updated.format("%Y-%m-%d %H:%M:%S").to_string(),
"theme": &self.theme "theme": &self.theme
}); });

Binary file not shown.

View File

@@ -1,34 +1,34 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf8" /> <meta charset="utf8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
{% if theme == 'neutral' %} {% if theme == 'neutral' %}
<meta <meta
name="theme-color" name="theme-color"
media="(prefers-color-scheme: light)" media="(prefers-color-scheme: light)"
content="#fafafa" content="#fafafa"
/> >
<meta <meta
name="theme-color" name="theme-color"
media="(prefers-color-scheme: dark)" media="(prefers-color-scheme: dark)"
content="#0a0a0a" content="#0a0a0a"
/> >
{% else %} {% else %}
<meta <meta
name="theme-color" name="theme-color"
media="(prefers-color-scheme: light)" media="(prefers-color-scheme: light)"
content="#f9fafb" content="#f9fafb"
/> >
<meta <meta
name="theme-color" name="theme-color"
media="(prefers-color-scheme: dark)" media="(prefers-color-scheme: dark)"
content="#030712" content="#030712"
/> >
{% endif %} {% endif %}
<link rel="icon" type="image/svg+xml" href="favicon.svg" /> <link rel="icon" type="image/svg+xml" href="favicon.svg">
<link rel="icon" type="image/x-icon" href="favicon.ico" /> <link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="apple-touch-icon" href="apple-touch-icon.png" /> <link rel="apple-touch-icon" href="apple-touch-icon.png">
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Cup</title> <title>Cup</title>
</head> </head>
<body> <body>
@@ -39,9 +39,7 @@
<div class="mx-auto h-full w-full max-w-[80rem] px-4 sm:px-6 lg:px-8"> <div class="mx-auto h-full w-full max-w-[80rem] px-4 sm:px-6 lg:px-8">
<div class="mx-auto my-8 h-full max-w-[48rem] flex-col"> <div class="mx-auto my-8 h-full max-w-[48rem] flex-col">
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
<h1 class="text-5xl font-bold lg:text-6xl dark:text-white"> <h1 class="text-5xl font-bold lg:text-6xl dark:text-white">Cup</h1>
Cup
</h1>
<svg <svg
version="1.1" version="1.1"
id="Layer_2" id="Layer_2"
@@ -110,10 +108,9 @@
<dl <dl
class="grid grid-cols-2 gap-1 overflow-hidden *:relative lg:grid-cols-4" class="grid grid-cols-2 gap-1 overflow-hidden *:relative lg:grid-cols-4"
> >
{% assign metrics_to_show = {% assign metrics_to_show = 'monitored_images,up_to_date,updates_available,unknown' | split: ',' %}
'monitored_images,up_to_date,updates_available,unknown' | split: {% for metric in metrics %}
',' %} {% for metric in metrics %} {% if metrics_to_show {% if metrics_to_show contains metric.name %}
contains metric.name %}
<div <div
class="before:bg-{{ theme }}-200 before:dark:bg-{{ theme }}-800 after:bg-{{ theme }}-200 after:dark:bg-{{ theme }}-800 gi" class="before:bg-{{ theme }}-200 before:dark:bg-{{ theme }}-800 after:bg-{{ theme }}-200 after:dark:bg-{{ theme }}-800 gi"
> >
@@ -131,7 +128,8 @@
> >
{{ metric.value }} {{ metric.value }}
</dd> </dd>
{% case metric.name %} {% when 'monitored_images' %} {% case metric.name %}
{% when 'monitored_images' %}
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
@@ -159,16 +157,25 @@
d="M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-1.293 5.953a1 1 0 0 0 -1.32 -.083l-.094 .083l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.403 1.403l.083 .094l2 2l.094 .083a1 1 0 0 0 1.226 0l.094 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z" d="M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-1.293 5.953a1 1 0 0 0 -1.32 -.083l-.094 .083l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.403 1.403l.083 .094l2 2l.094 .083a1 1 0 0 0 1.226 0l.094 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z"
/> />
</svg> </svg>
{% when 'updates_available' %} {% assign max_metric = '' {% when 'updates_available' %}
%} {% assign max_value = 0 %} {% for m in metrics %} {% {% assign max_metric = '' %}
unless metrics_to_show contains m.name %} {% if m.value > {% assign max_value = 0 %}
max_value %} {% assign max_metric = m.name %} {% assign {% for m in metrics %}
max_value = m.value %} {% endif %} {% endunless %} {% {% unless metrics_to_show contains m.name %}
endfor %} {% case max_metric %} {% when 'major_updates' %} {% if m.value > max_value %}
{% assign color = 'text-red-500' %} {% when {% assign max_metric = m.name %}
'minor_updates' %} {% assign color = 'text-yellow-500' %} {% assign max_value = m.value %}
{% else %} {% assign color = 'text-blue-500' %} {% endcase {% endif %}
%} {% endunless %}
{% endfor %}
{% case max_metric %}
{% when 'major_updates' %}
{% assign color = 'text-red-500' %}
{% when 'minor_updates' %}
{% assign color = 'text-yellow-500' %}
{% else %}
{% assign color = 'text-blue-500' %}
{% endcase %}
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
@@ -200,7 +207,8 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %} {% endfor %} {% endif %}
{% endfor %}
</dl> </dl>
</div> </div>
<div <div
@@ -210,30 +218,14 @@
class="flex justify-between items-center px-6 py-4 text-{{ theme }}-500" class="flex justify-between items-center px-6 py-4 text-{{ theme }}-500"
> >
<h3>Last checked: {{ last_updated }}</h3> <h3>Last checked: {{ last_updated }}</h3>
<button class="group" onclick="refresh(event)">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="group-disabled:animate-spin"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M4,11A8.1,8.1 0 0 1 19.5,9M20,5v4h-4" />
<path d="M20,13A8.1,8.1 0 0 1 4.5,15M4,19v-4h4" />
</svg>
</button>
</div> </div>
<ul <ul>
class="*:py-4 *:px-6 *:flex *:items-center *:gap-3 dark:divide-{{ theme }}-800 divide-y dark:text-white" {% for server in server_ids %}
> {% if server == '' %}
{% for image in images %} <li class="mb-8 last:mb-0">
<li> <ul class="dark:divide-{{theme}}-800 divide-y dark:text-white">
{% for image in servers[server] %}
<li class="flex items-center gap-4 break-all px-6 py-4 text-start">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
@@ -244,6 +236,7 @@
stroke-width="2" stroke-width="2"
stroke-linecap="round" stroke-linecap="round"
stroke-linejoin="round" stroke-linejoin="round"
class="size-6 shrink-0"
> >
<path stroke="none" d="M0 0h24v24H0z" fill="none" /> <path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path <path
@@ -253,8 +246,9 @@
<path d="M12 12l8.73 -5.04" /> <path d="M12 12l8.73 -5.04" />
<path d="M3.27 6.96l8.73 5.04" /> <path d="M3.27 6.96l8.73 5.04" />
</svg> </svg>
{{ image.name }} {% case image.status %} {% when 'Up to date' {{ image.name }}
%} {% case image.status %}
{% when 'Up to date' %}
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
@@ -282,10 +276,15 @@
d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm0 13a1 1 0 0 0 -.993 .883l-.007 .117l.007 .127a1 1 0 0 0 1.986 0l.007 -.117l-.007 -.127a1 1 0 0 0 -.993 -.883zm1.368 -6.673a2.98 2.98 0 0 0 -3.631 .728a1 1 0 0 0 1.44 1.383l.171 -.18a.98 .98 0 0 1 1.11 -.15a1 1 0 0 1 -.34 1.886l-.232 .012a1 1 0 0 0 .111 1.994a3 3 0 0 0 1.371 -5.673z" d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm0 13a1 1 0 0 0 -.993 .883l-.007 .117l.007 .127a1 1 0 0 0 1.986 0l.007 -.117l-.007 -.127a1 1 0 0 0 -.993 -.883zm1.368 -6.673a2.98 2.98 0 0 0 -3.631 .728a1 1 0 0 0 1.44 1.383l.171 -.18a.98 .98 0 0 1 1.11 -.15a1 1 0 0 1 -.34 1.886l-.232 .012a1 1 0 0 0 .111 1.994a3 3 0 0 0 1.371 -5.673z"
/> />
</svg> </svg>
{% else %} {% case image.status %} {% when 'Major update' %} {% else %}
{% assign color = 'text-red-500' %} {% when 'Minor update' %} {% case image.status %}
{% assign color = 'text-yellow-500' %} {% else %} {% assign {% when 'Major update' %}
color = 'text-blue-500' %} {% endcase %} {% assign color = 'text-red-500' %}
{% when 'Minor update' %}
{% assign color = 'text-yellow-500' %}
{% else %}
{% assign color = 'text-blue-500' %}
{% endcase %}
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
@@ -303,6 +302,95 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</li>
{% else %}
<li class="mb-4 last:mb-0">
<p class="my-4 text-lg font-semibold text-{{ theme }}-600 dark:text-{{ theme }}-400 px-6">
{{ server }}
</p>
<ul class="dark:divide-{{ theme }}-800 divide-y dark:text-white">
{% for image in servers[server] %}
<li class="flex items-center gap-4 break-all px-6 py-4 text-start">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="size-6 shrink-0"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M21 16.008v-8.018a1.98 1.98 0 0 0 -1 -1.717l-7 -4.008a2.016 2.016 0 0 0 -2 0l-7 4.008c-.619 .355 -1 1.01 -1 1.718v8.018c0 .709 .381 1.363 1 1.717l7 4.008a2.016 2.016 0 0 0 2 0l7 -4.008c.619 -.355 1 -1.01 1 -1.718z"
/>
<path d="M12 22v-10" />
<path d="M12 12l8.73 -5.04" />
<path d="M3.27 6.96l8.73 5.04" />
</svg>
{{ image.name }}
{% case image.status %}
{% when 'Up to date' %}
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="currentColor"
class="ml-auto text-green-500"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-1.293 5.953a1 1 0 0 0 -1.32 -.083l-.094 .083l-3.293 3.292l-1.293 -1.292l-.094 -.083a1 1 0 0 0 -1.403 1.403l.083 .094l2 2l.094 .083a1 1 0 0 0 1.226 0l.094 -.083l4 -4l.083 -.094a1 1 0 0 0 -.083 -1.32z"
/>
</svg>
{% when 'Unknown' %}
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="currentColor"
class="text-{{ theme }}-500 ml-auto"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm0 13a1 1 0 0 0 -.993 .883l-.007 .117l.007 .127a1 1 0 0 0 1.986 0l.007 -.117l-.007 -.127a1 1 0 0 0 -.993 -.883zm1.368 -6.673a2.98 2.98 0 0 0 -3.631 .728a1 1 0 0 0 1.44 1.383l.171 -.18a.98 .98 0 0 1 1.11 -.15a1 1 0 0 1 -.34 1.886l-.232 .012a1 1 0 0 0 .111 1.994a3 3 0 0 0 1.371 -5.673z"
/>
</svg>
{% else %}
{% case image.status %}
{% when 'Major update' %}
{% assign color = 'text-red-500' %}
{% when 'Minor update' %}
{% assign color = 'text-yellow-500' %}
{% else %}
{% assign color = 'text-blue-500' %}
{% endcase %}
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="currentColor"
class="ml-auto {{ color }}"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M17 3.34a10 10 0 1 1 -14.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 14.995 -8.336zm-4.98 3.66l-.163 .01l-.086 .016l-.142 .045l-.113 .054l-.07 .043l-.095 .071l-.058 .054l-4 4l-.083 .094a1 1 0 0 0 1.497 1.32l2.293 -2.293v5.586l.007 .117a1 1 0 0 0 1.993 -.117v-5.585l2.293 2.292l.094 .083a1 1 0 0 0 1.32 -1.497l-4 -4l-.082 -.073l-.089 -.064l-.113 -.062l-.081 -.034l-.113 -.034l-.112 -.02l-.098 -.006z"
/>
</svg>
{% endcase %}
</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -14,6 +14,7 @@
"@headlessui/react": "^2.1.10", "@headlessui/react": "^2.1.10",
"@radix-ui/react-tooltip": "^1.1.2", "@radix-ui/react-tooltip": "^1.1.2",
"@tabler/icons-react": "^3.14.0", "@tabler/icons-react": "^3.14.0",
"caniuse-lite": "^1.0.30001698",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"react": "^18.3.1", "react": "^18.3.1",

View File

@@ -30,7 +30,7 @@ export function Server({
{name} {name}
</span> </span>
<IconChevronDown <IconChevronDown
className={`duration:300 size-5 text-${theme}-600 transition-transform group-data-[open]:rotate-180 dark:text-${theme}-400 group-data-[hover]:text-${theme}-800 group-data-[hover]:dark:text-${theme}-200 transition-colors duration-300`} className={`duration-300 size-5 text-${theme}-600 transition-transform group-data-[open]:rotate-180 dark:text-${theme}-400 group-data-[hover]:text-${theme}-800 group-data-[hover]:dark:text-${theme}-200 transition-colors`}
/> />
</DisclosureButton> </DisclosureButton>
<DisclosurePanel <DisclosurePanel

View File

@@ -1,6 +1,6 @@
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
export default { export default {
content: ["./src/App.tsx", "./src/components/*.tsx"], content: ["./src/App.tsx", "./src/components/*.tsx", "./index.liquid"],
theme: { theme: {
extend: {}, extend: {},
}, },