feat: new navbar design

This commit is contained in:
Tine 2024-05-28 22:22:29 +02:00
parent dc314a4828
commit 4afb709b87
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
7 changed files with 132 additions and 118 deletions

View file

@ -193,26 +193,26 @@ func (h *BaseHandler) Index(c echo.Context) error {
}
timeRangeQuery := c.QueryParam("time-range")
if timeRangeQuery != "48hours" && timeRangeQuery != "90days" && timeRangeQuery != "90minutes" {
timeRangeQuery = "90days"
if timeRangeQuery != "48hours" && timeRangeQuery != "60days" && timeRangeQuery != "60minutes" {
timeRangeQuery = "60days"
}
var timeBuckets int
var timeInterval time.Duration
var timeRange services.TargetHistoryDateRange
switch timeRangeQuery {
case "90days":
timeRange = services.TargetHistoryDateRange90Days
case "60days":
timeRange = services.TargetHistoryDateRange60Days
timeInterval = time.Hour * 24
timeBuckets = 90
timeBuckets = 60
case "48hours":
timeRange = services.TargetHistoryDateRange48Hours
timeInterval = time.Hour
timeBuckets = 48
case "90minutes":
timeRange = services.TargetHistoryDateRange90Minutes
case "60minutes":
timeRange = services.TargetHistoryDateRange60Minutes
timeInterval = time.Minute
timeBuckets = 90
timeBuckets = 60
}
overallOutcome := HistoryOutcomeUnknown

View file

@ -83,7 +83,7 @@ func (h *BaseHandler) SettingsTargetsDescribeGET(c echo.Context) error {
return err
}
history, err := services.GetTargetHistoryForTarget(context.Background(), h.db, slug, services.TargetHistoryDateRange90Minutes)
history, err := services.GetTargetHistoryForTarget(context.Background(), h.db, slug, services.TargetHistoryDateRange60Minutes)
if err != nil {
return err
}

View file

@ -18,20 +18,20 @@ type TargetHistory struct {
type TargetHistoryDateRange string
const (
TargetHistoryDateRange90Days TargetHistoryDateRange = "90_DAYS"
TargetHistoryDateRange60Days TargetHistoryDateRange = "60_DAYS"
TargetHistoryDateRange48Hours TargetHistoryDateRange = "48_HOURS"
TargetHistoryDateRange90Minutes TargetHistoryDateRange = "90_MINUTES"
TargetHistoryDateRange60Minutes TargetHistoryDateRange = "60_MINUTES"
)
func GetTargetHistoryForTarget(ctx context.Context, db *sqlx.DB, targetId string, dateRange TargetHistoryDateRange) ([]*TargetHistory, error) {
dateRangeFilter := ""
switch dateRange {
case TargetHistoryDateRange90Days:
dateRangeFilter = "AND strftime('%Y-%m-%dT%H:%M:%fZ', th.created_at) >= datetime('now', 'localtime', '-90 days')"
case TargetHistoryDateRange60Days:
dateRangeFilter = "AND strftime('%Y-%m-%dT%H:%M:%fZ', th.created_at) >= datetime('now', 'localtime', '-60 days')"
case TargetHistoryDateRange48Hours:
dateRangeFilter = "AND strftime('%Y-%m-%dT%H:%M:%fZ', th.created_at) >= datetime('now', 'localtime', '-48 hours')"
case TargetHistoryDateRange90Minutes:
dateRangeFilter = "AND strftime('%Y-%m-%dT%H:%M:%fZ', th.created_at) >= datetime('now', 'localtime', '-90 minutes')"
case TargetHistoryDateRange60Minutes:
dateRangeFilter = "AND strftime('%Y-%m-%dT%H:%M:%fZ', th.created_at) >= datetime('now', 'localtime', '-60 minutes')"
}
var targetHistory []*TargetHistory

View file

@ -32,23 +32,12 @@ code {
@apply font-mono text-sm bg-gray-100 rounded-lg p-1;
}
.navbar {
@apply justify-center flex flex-wrap space-x-2 gap-2 mt-10;
}
.navbar a {
@apply font-bold py-2 px-4 rounded-lg;
}
.navbar a:hover {
@apply bg-gray-200 shadow-inner;
}
.navbar a:focus {
@apply outline-none ring-2 ring-blue-700 text-blue-700;
@apply font-medium px-5 py-2 rounded-lg;
@apply text-center text-black bg-gray-100 hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-gray-400;
}
.navbar a.active {
@apply bg-gray-300 text-black shadow;
}
.navbar a.active:hover {
@apply shadow;
@apply bg-white hover:bg-gray-300 shadow;
}
#page-index .targets .time-range > a {
@ -75,36 +64,36 @@ code {
background: repeating-linear-gradient(
45deg,
var(--color-red-300),
var(--color-red-300) 20%,
var(--color-red-400) 20%,
var(--color-red-400) 40%
var(--color-red-300) 10%,
var(--color-red-400) 10%,
var(--color-red-400) 20%
);
}
#page-index .history.down:hover > .bar {
background: repeating-linear-gradient(
45deg,
var(--color-red-400),
var(--color-red-400) 20%,
var(--color-red-500) 20%,
var(--color-red-500) 40%
var(--color-red-400) 10%,
var(--color-red-500) 10%,
var(--color-red-500) 20%
);
}
#page-index .history.degraded > .bar {
background: repeating-linear-gradient(
0deg,
var(--color-orange-300),
var(--color-orange-300) 20%,
var(--color-orange-400) 20%,
var(--color-orange-400) 40%
var(--color-orange-300) 10%,
var(--color-orange-400) 10%,
var(--color-orange-400) 20%
);
}
#page-index .history.degraded:hover > .bar {
background: repeating-linear-gradient(
0deg,
var(--color-orange-400),
var(--color-orange-400) 20%,
var(--color-orange-500) 20%,
var(--color-orange-500) 40%
var(--color-orange-400) 10%,
var(--color-orange-500) 10%,
var(--color-orange-500) 20%
);
}

View file

@ -1020,6 +1020,10 @@ video {
height: min-content;
}
.w-12 {
width: 3rem;
}
.w-20 {
width: 5rem;
}
@ -1133,6 +1137,12 @@ video {
gap: 1px;
}
.space-x-2 > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 0;
margin-right: calc(0.5rem * var(--tw-space-x-reverse));
margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
}
.self-center {
align-self: center;
}
@ -1225,6 +1235,11 @@ video {
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
}
.bg-gray-300 {
--tw-bg-opacity: 1;
background-color: rgb(209 213 219 / var(--tw-bg-opacity));
}
.bg-gray-50 {
--tw-bg-opacity: 1;
background-color: rgb(249 250 251 / var(--tw-bg-opacity));
@ -1371,6 +1386,11 @@ video {
line-height: 1.5rem;
}
.text-lg {
font-size: 1.125rem;
line-height: 1.75rem;
}
.text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
@ -1587,63 +1607,46 @@ code {
line-height: 1.25rem;
}
.navbar {
margin-top: 2.5rem;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.5rem;
}
.navbar > :not([hidden]) ~ :not([hidden]) {
--tw-space-x-reverse: 0;
margin-right: calc(0.5rem * var(--tw-space-x-reverse));
margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
}
.navbar a {
border-radius: 0.5rem;
padding-left: 1.25rem;
padding-right: 1.25rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
padding-left: 1rem;
padding-right: 1rem;
font-weight: 700;
font-weight: 500;
--tw-bg-opacity: 1;
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
text-align: center;
--tw-text-opacity: 1;
color: rgb(0 0 0 / var(--tw-text-opacity));
}
.navbar a:hover {
--tw-bg-opacity: 1;
background-color: rgb(229 231 235 / var(--tw-bg-opacity));
--tw-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
--tw-shadow-colored: inset 0 2px 4px 0 var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
background-color: rgb(209 213 219 / var(--tw-bg-opacity));
}
.navbar a:focus {
--tw-text-opacity: 1;
color: rgb(29 78 216 / var(--tw-text-opacity));
outline: 2px solid transparent;
outline-offset: 2px;
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
--tw-ring-opacity: 1;
--tw-ring-color: rgb(29 78 216 / var(--tw-ring-opacity));
--tw-ring-color: rgb(156 163 175 / var(--tw-ring-opacity));
}
.navbar a.active {
--tw-bg-opacity: 1;
background-color: rgb(209 213 219 / var(--tw-bg-opacity));
--tw-text-opacity: 1;
color: rgb(0 0 0 / var(--tw-text-opacity));
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.navbar a.active:hover {
--tw-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
--tw-bg-opacity: 1;
background-color: rgb(209 213 219 / var(--tw-bg-opacity));
}
#page-index .targets .time-range > a {
@ -1720,9 +1723,9 @@ code {
background: repeating-linear-gradient(
45deg,
var(--color-red-300),
var(--color-red-300) 20%,
var(--color-red-400) 20%,
var(--color-red-400) 40%
var(--color-red-300) 10%,
var(--color-red-400) 10%,
var(--color-red-400) 20%
);
}
@ -1730,9 +1733,9 @@ code {
background: repeating-linear-gradient(
45deg,
var(--color-red-400),
var(--color-red-400) 20%,
var(--color-red-500) 20%,
var(--color-red-500) 40%
var(--color-red-400) 10%,
var(--color-red-500) 10%,
var(--color-red-500) 20%
);
}
@ -1740,9 +1743,9 @@ code {
background: repeating-linear-gradient(
0deg,
var(--color-orange-300),
var(--color-orange-300) 20%,
var(--color-orange-400) 20%,
var(--color-orange-400) 40%
var(--color-orange-300) 10%,
var(--color-orange-400) 10%,
var(--color-orange-400) 20%
);
}
@ -1750,9 +1753,9 @@ code {
background: repeating-linear-gradient(
0deg,
var(--color-orange-400),
var(--color-orange-400) 20%,
var(--color-orange-500) 20%,
var(--color-orange-500) 40%
var(--color-orange-400) 10%,
var(--color-orange-500) 10%,
var(--color-orange-500) 20%
);
}
@ -2130,6 +2133,10 @@ code {
justify-content: center;
}
.sm\:justify-evenly {
justify-content: space-evenly;
}
.sm\:px-8 {
padding-left: 2rem;
padding-right: 2rem;

View file

@ -17,21 +17,29 @@
<link rel="stylesheet" href="/static/css/tailwind.css" />
</head>
<body class="bg-gray-100 flex flex-col">
<nav class="navbar">
{{ range .Navbar }}
<a
{{ $active := eq .Path $path }}
{{ if $active }}aria-current="true"{{ end }}
href="{{ .Path }}"
class="{{ if $active }}active{{ end }}"
>
{{ .Title }}
</a>
{{ end }}
</nav>
<header class="flex flex-col sm:flex-row items-center sm:justify-evenly p-4 gap-2">
<a href="/" class="text-2xl font-bold">zdravko.mnts.dev</a>
<nav class="navbar flex sm:flex-row flex-col flex-wrap space-x-2 gap-1">
{{ range .Navbar }}
<a
{{ $active := eq .Path $path }}
{{ if $active }}aria-current="true"{{ end }}
href="{{ .Path }}"
class="{{ if $active }}active{{ end }}"
>
{{ .Title }}
</a>
{{ end }}
</nav>
<img
src="https://avatars.githubusercontent.com/u/1910649?v=4"
alt="Profile Image"
class="rounded-full w-12 h-12"
></img>
</header>
{{ template "main" . }}
<div class="container mx-auto">
<footer class="text-center text-gray-500 text-xs mt-8 mb-4">
<footer class="text-center text-gray-600 text-xs mt-8 mb-4">
&copy; {{ Now.UTC.Year }} Zdravko -
<a
class="hover:underline"

View file

@ -32,14 +32,29 @@
</div>
</section>
{{ else }}
{{ if or (eq .Outcome "UNKNOWN") (eq .Outcome "HEALTHY") }}
{{ if eq .Outcome "HEALTHY" }}
<div class="flex flex-col items-center">
<svg
class="feather h-20 w-20 rounded-full bg-green-300 p-4 overflow-visible"
>
<use href="/static/icons/feather-sprite.svg#check" />
</svg>
<h1 class="text-gray-700 mt-4">All services are online</h1>
<h1 class="text-gray-700 mt-4 text-lg">All services are online</h1>
<p class="text-gray-700 text-sm">
Last updated on
{{ Now.UTC.Format "Jan 02 at 15:04 MST" }}
</p>
</div>
{{ else if eq .Outcome "UNKNOWN" }}
<div class="flex flex-col items-center">
<svg
class="feather h-20 w-20 rounded-full bg-gray-300 p-4 overflow-visible"
>
<use href="/static/icons/feather-sprite.svg#help-circle" />
</svg>
<h1 class="text-gray-700 mt-4 text-lg">
We are unable to determine current status
</h1>
<p class="text-gray-700 text-sm">
Last updated on
{{ Now.UTC.Format "Jan 02 at 15:04 MST" }}
@ -50,9 +65,9 @@
<svg
class="feather h-20 w-20 rounded-full bg-red-300 p-4 overflow-visible"
>
<use href="/static/icons/feather-sprite.svg#alert-triangle" />
<use href="/static/icons/feather-sprite.svg#alert-circle" />
</svg>
<h1 class="text-gray-700 mt-4">Some services are down</h1>
<h1 class="text-gray-700 mt-4 text-lg">Some services are down</h1>
<p class="text-gray-700 text-sm">
Last updated on
{{ Now.UTC.Format "Jan 02 at 15:04 MST" }}
@ -65,7 +80,7 @@
>
<use href="/static/icons/feather-sprite.svg#alert-triangle" />
</svg>
<h1 class="text-gray-700 mt-4">Degraded services</h1>
<h1 class="text-gray-700 mt-4 text-lg">Degraded services</h1>
<p class="text-gray-700 text-sm">
Last updated on
{{ Now.UTC.Format "Jan 02 at 15:04 MST" }}
@ -78,10 +93,10 @@
role="group"
>
<a
href="/?time-range=90days"
class="{{ if eq .TimeRange "90days" }}active{{ end }}"
href="/?time-range=60days"
class="{{ if eq .TimeRange "60days" }}active{{ end }}"
type="button"
>90 Days</a
>60 Days</a
>
<a
href="/?time-range=48hours"
@ -90,10 +105,10 @@
>48 Hours</a
>
<a
href="/?time-range=90minutes"
class="{{ if eq .TimeRange "90minutes" }}active{{ end }}"
href="/?time-range=60minutes"
class="{{ if eq .TimeRange "60minutes" }}active{{ end }}"
type="button"
>90 Minutes</a
>60 Minutes</a
>
</div>
{{ range $group, $targetsAndStatus := .Targets }}
@ -147,11 +162,6 @@
<h4>
{{ .Name }}
{{ if eq .Visibility "PUBLIC" }}
<span
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800"
>
Public
</span>
{{ else if eq .Visibility "PRIVATE" }}
<span
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-fuchsia-100 text-fuchsia-800"
@ -192,11 +202,11 @@
class="tooltip flex flex-col gap-2 bg-white border border-gray-200 rounded p-2 shadow-lg hidden z-50 absolute mt-10 -ml-4 flex-row text-xs"
>
<div class="flex flex-row gap-2 justify-between">
{{ if eq $.TimeRange "90days" }}
{{ if eq $.TimeRange "60days" }}
{{ .Date.Format "Jan 02" }}
{{ else if eq $.TimeRange "48hours" }}
{{ .Date.Format "Jan 02, 15:00 MST" }}
{{ else if eq $.TimeRange "90minutes" }}
{{ else if eq $.TimeRange "60minutes" }}
{{ .Date.Format "Jan 02, 15:04 MST" }}
{{ end }}
<span
@ -221,12 +231,12 @@
<div
class="text-slate-500 justify-self-start text-xs tracking-wider"
>
{{ if eq $.TimeRange "90days" }}
90 days ago
{{ if eq $.TimeRange "60days" }}
60 days ago
{{ else if eq $.TimeRange "48hours" }}
48 hours ago
{{ else if eq $.TimeRange "90minutes" }}
90 minutes ago
{{ else if eq $.TimeRange "60minutes" }}
60 minutes ago
{{ end }}
</div>
<div