diff --git a/config.inc.php b/config.inc.php index 32ca9aa..bbe0ae6 100644 --- a/config.inc.php +++ b/config.inc.php @@ -1,3 +1,9 @@ ["rich" => true] +]); diff --git a/controller/status.php b/controller/status.php new file mode 100644 index 0000000..6723f89 --- /dev/null +++ b/controller/status.php @@ -0,0 +1,54 @@ +data = array_merge($page, $status); + } + + public function display() { + + $filter = new \Twig\TwigFilter('timeago', function ($ago, $now) { + + $time = strtotime($now) - strtotime($ago); + + $units = array ( + 31536000 => 'year', + 2592000 => 'month', + 604800 => 'week', + 86400 => 'day', + 3600 => 'hour', + 60 => 'minute', + 1 => 'second' + ); + + foreach ($units as $unit => $val) { + if ($time < $unit) continue; + $numberOfUnits = floor($time / $unit); + return ($val == 'second')? 'a few seconds ago' : + (($numberOfUnits>1) ? $numberOfUnits : 'a') + .' '.$val.(($numberOfUnits>1) ? 's' : '').' ago'; + } + + }); + + $twig_config = []; + if(ENABLE_TWIG_CACHE) $twig_config["cache"] = "../cache/twig/"; + + $loader = new \Twig\Loader\FilesystemLoader("../view/"); + $twig = new \Twig\Environment($loader, $twig_config); + $twig->addFilter($filter); + + $monitoring = MONITORINGS ?? []; + + echo $twig->render('index.twig', array_merge(["monitoring" => $monitoring], $this->data)); + + } + +} \ No newline at end of file diff --git a/public/index.php b/public/index.php index 72fa0b2..4415fd4 100644 --- a/public/index.php +++ b/public/index.php @@ -1,16 +1,10 @@ '../cache/twig/', -]); +require("../config.inc.php"); +require("../controller/status.php"); -$page = json_decode(file_get_contents(UPTIME_KUMA_URL . "/api/status-page/public"), true); -$monitors = json_decode(file_get_contents(UPTIME_KUMA_URL . "/api/status-page/heartbeat/public"), true); +$status = new UptimeStatus; -$data = array_merge($page, $monitors); - -echo $twig->render('index.twig', $data); \ No newline at end of file +$status->load_data(); +$status->display(); diff --git a/public/style.css b/public/style.css index bb578b8..0b83a73 100644 --- a/public/style.css +++ b/public/style.css @@ -29,7 +29,6 @@ h3, h4 { .group .item { overflow: hidden; - margin: 5px 0; border-radius: var(--border-radius); } @@ -37,6 +36,13 @@ h3, h4 { background-color: #fff1; } +:is(.group, .item) > .inner { + margin: 10px; +} + + +/* MONITOR */ + .monitor { --color: #fff2; } @@ -54,27 +60,57 @@ h3, h4 { grid-template-columns: 22px 1fr max-content; } -.monitor .heartbeats { +.monitor .icon { + color: var(--color); + display: flex; +} + +.monitor .uptime { + font-size: .9rem; + color: var(--color); +} + + +/* HEARTBEATS */ + +.heartbeats { + display: flex; + gap: 5px; + flex-direction: column; +} + +.heartbeats .items { display: flex; gap: 2px; border-radius: var(--border-radius); overflow: hidden; height: 5px; - transition: all .3s; + transition: all .3s .5s; opacity: .4; } -.monitor:hover .heartbeats { - height: 25px; - opacity: 1; -} - -.monitor .heartbeats > * { +.heartbeats .items > * { flex: 1; background-color: var(--color); border-radius: var(--border-radius); } +.heartbeats .time { + display: flex; + justify-content: space-between; + font-size: .9rem; + opacity: .5; + line-height: 1; +} + +.monitor:hover .heartbeats .items { + height: 25px; + opacity: 1; +} + + +/* STATUS COLORS */ + .monitor.status-1, .monitor .heartbeats .status-1 { --color: var(--green-color); } @@ -85,18 +121,4 @@ h3, h4 { .monitor.status-2, .monitor .heartbeats .status-2 { --color: var(--red-color); -} - -:is(.group, .item) > .inner { - margin: 10px; -} - -.monitor .icon { - color: var(--color); - display: flex; -} - -.monitor .uptime { - font-size: .9rem; - color: var(--color); } \ No newline at end of file diff --git a/view/heartbeats.twig b/view/heartbeats.twig new file mode 100644 index 0000000..14b4276 --- /dev/null +++ b/view/heartbeats.twig @@ -0,0 +1,11 @@ +
+
+ {% for heartbeat in heartbeats %} +
+ {% endfor %} +
+
+
{{ (heartbeats | first).time | timeago((heartbeats | last).time) }}
+
now
+
+
\ No newline at end of file diff --git a/view/monitor.twig b/view/monitor.twig index b0aff4f..127c5b9 100644 --- a/view/monitor.twig +++ b/view/monitor.twig @@ -19,10 +19,8 @@ {{ (attribute(uptimeList, "#{monitor.id}_24") * 100) | number_format(1, '.') }}% uptime -
- {% for heartbeat in heartbeats %} -
- {% endfor %} -
+ {% if monitoring[monitor.id].rich %} + {{ include('./heartbeats.twig') }} + {% endif %} \ No newline at end of file