diff --git a/build.sh b/build.sh index 8c3b9e1..11e288a 100755 --- a/build.sh +++ b/build.sh @@ -17,6 +17,9 @@ bun run build # Copy UI to src folder cp -r dist/ ../src/static +# Go back +cd ../ + # Run command from argv $@ \ No newline at end of file diff --git a/src/server.rs b/src/server.rs index 8dcfd8c..8d3f591 100644 --- a/src/server.rs +++ b/src/server.rs @@ -32,6 +32,17 @@ const FAVICON_ICO: &[u8] = include_bytes!("static/favicon.ico"); const FAVICON_SVG: &[u8] = include_bytes!("static/favicon.svg"); const APPLE_TOUCH_ICON: &[u8] = include_bytes!("static/apple-touch-icon.png"); +const SORT_ORDER: [&'static str; 8] = [ + "monitored_images", + "updates_available", + "major_updates", + "minor_updates", + "patch_updates", + "other_updates", + "up_to_date", + "unknown", +]; // For Liquid rendering + pub async fn serve(port: &u16, config: &Config) -> std::io::Result<()> { info!("Starting server, please wait..."); let data = ServerData::new(config).await; @@ -153,7 +164,7 @@ impl ServerData { let images = self .raw_updates .iter() - .map(|image| object!({"name": image.reference, "has_update": image.has_update().to_option_bool().to_value()}),) + .map(|image| object!({"name": image.reference, "status": image.has_update().to_string()}),) .collect::>(); self.simple_json = to_simple_json(&self.raw_updates); self.full_json = to_full_json(&self.raw_updates); @@ -170,8 +181,10 @@ impl ServerData { Theme::Default => "neutral", Theme::Blue => "gray", }; + let mut metrics = self.simple_json["metrics"].entries().map(|(key, value)| liquid::object!({ "name": key, "value": value.as_u16().unwrap()})).collect::>(); + metrics.sort_unstable_by(|a, b| {dbg!(a, b); SORT_ORDER.iter().position(|i| i == &a["name"].to_kstr().as_str()).unwrap().cmp(&SORT_ORDER.iter().position(|i| i == &b["name"].to_kstr().as_str()).unwrap())}); let globals = object!({ - "metrics": [{"name": "Monitored images", "value": self.simple_json["metrics"]["monitored_images"].as_usize()}, {"name": "Up to date", "value": self.simple_json["metrics"]["up_to_date"].as_usize()}, {"name": "Updates available", "value": self.simple_json["metrics"]["update_available"].as_usize()}, {"name": "Unknown", "value": self.simple_json["metrics"]["unknown"].as_usize()}], + "metrics": metrics, "images": images, "last_updated": last_updated.format("%Y-%m-%d %H:%M:%S").to_string(), "theme": &self.theme diff --git a/web/index.html b/web/index.html index cff7945..d902ba9 100644 --- a/web/index.html +++ b/web/index.html @@ -1,31 +1,45 @@ - - {% if theme == "neutral" %} - - + + {% if theme == 'neutral' %} + + {% else %} - - + + {% endif %} - - - - + + + + Cup
-
+
-

- Cup -

+

Cup

+ {% assign metrics_to_show = 'monitored_images,up_to_date,updates_available,unknown' | split: ',' %} {% for metric in metrics %} -
-
-
- {{ metric.name }} -
-
-
- {{ metric.value }} -
- {% if metric.name == 'Monitored images' %} - - - - - {% elsif metric.name == 'Up to date' %} - - - - - {% elsif metric.name == 'Updates available' %} - - - - - {% elsif metric.name == 'Unknown' %} - - - - - {% endif %} +
+ {{ metric.name | replace: '_', ' ' | capitalize }} +
+
+
+ {{ metric.value }} +
+ {% case metric.name %} + {% when 'monitored_images' %} + + + + + {% when 'up_to_date' %} + + + + + {% when 'updates_available' %} + {% assign max_metric = '' %} + {% assign max_value = 0 %} + + {% for m in metrics %} + {% unless metrics_to_show contains m.name %} + {% if m.value > max_value %} + {% assign max_metric = m.name %} + {% assign max_value = m.value %} + {% 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 %} + + + + + {% when 'unknown' %} + + + + + {% endcase %} +
+
-
-
+ {% endif %} {% endfor %}
@@ -205,70 +243,80 @@ class="*:py-4 *:px-6 *:flex *:items-center *:gap-3 dark:divide-{{ theme }}-800 divide-y dark:text-white" > {% for image in images %} -
  • - - - - - - - - {{ image.name }} {% if image.has_update == 'false' %} - - - - - {% elsif image.has_update == 'true' %} - - - - - {% elsif image.has_update == 'null' %} - - - - - {% endif %} -
  • +
  • + + + + + + + + {{ image.name }} + {% case image.status %} + {% when 'Up to date' %} + + + + + {% when 'Unknown' %} + + + + + {% 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 %} + + + + + {% endcase %} +
  • {% endfor %}
    diff --git a/web/index.liquid b/web/index.liquid new file mode 120000 index 0000000..64233a9 --- /dev/null +++ b/web/index.liquid @@ -0,0 +1 @@ +index.html \ No newline at end of file diff --git a/web/src/App.tsx b/web/src/App.tsx index 3b1527e..4b56851 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -30,7 +30,11 @@ function App() { >
    {Object.entries(data.metrics).map(([name]) => ( - + ))}
    diff --git a/web/src/components/CodeBlock.tsx b/web/src/components/CodeBlock.tsx index c1c7fa2..4de3fe1 100644 --- a/web/src/components/CodeBlock.tsx +++ b/web/src/components/CodeBlock.tsx @@ -29,10 +29,12 @@ export function CodeBlock({ {enableCopy && navigator.clipboard && (copySuccess ? ( - + ) : (