Skip to content

Commit 7ae0a37

Browse files
committed
beautify last seen and ip address fields
1 parent 1ce2408 commit 7ae0a37

3 files changed

Lines changed: 106 additions & 66 deletions

File tree

cmd/dashboard/ui/templates/get_all_emissary_clients.templ

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@ templ GetAllEmissaryClients(clients []*emissary.EmissaryClient, latestClientEven
1313
if client.Revoked == 1 {
1414
<span>{ client.Name } (Revoked)</span>
1515
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="36" height="36" fill="currentColor"><path d="M13 18V20H17V22H7V20H11V18H2.9918C2.44405 18 2 17.5511 2 16.9925V4.00748C2 3.45107 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44892 22 4.00748V16.9925C22 17.5489 21.5447 18 21.0082 18H13Z"></path></svg>
16+
if latestClientEvents[client.ID].Timestamp == "" {
17+
<span>Last Seen: Never</span>
18+
<span>IP Address: N/A</span>
19+
} else {
1620
<span>Last Seen: { latestClientEvents[client.ID].Timestamp }</span>
1721
<span>IP Address: { latestClientEvents[client.ID].ConnectionIP }</span>
22+
}
1823
<button value="Restore Access" hx-post={ fmt.Sprintf("emissary/post/client/%s/unrevoke_certificate", client.ID) } hx-target={ fmt.Sprintf("#fleet-device-%s",client.ID) } hx-swap="outerHTML" class="emissary-restore-btn">Restore Access</button>
1924
} else {
2025
<span>{ client.Name }</span>
2126
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="36" height="36" fill="currentColor"><path d="M13 18V20H17V22H7V20H11V18H2.9918C2.44405 18 2 17.5511 2 16.9925V4.00748C2 3.45107 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44892 22 4.00748V16.9925C22 17.5489 21.5447 18 21.0082 18H13Z"></path></svg>
27+
if latestClientEvents[client.ID].Timestamp == "" {
28+
<span>Last Seen: Never</span>
29+
<span>IP Address: N/A</span>
30+
} else {
2231
<span>Last Seen: { latestClientEvents[client.ID].Timestamp }</span>
2332
<span>IP Address: { latestClientEvents[client.ID].ConnectionIP }</span>
33+
}
2434
<button value="Revoke Access" hx-post={ fmt.Sprintf("emissary/post/client/%s/revoke_certificate", client.ID) } hx-target={ fmt.Sprintf("#fleet-device-%s",client.ID) } hx-swap="outerHTML" class="emissary-revoke-btn">Revoke Access</button>
2535
}
2636
</li>

cmd/dashboard/ui/templates/get_all_emissary_clients_templ.go

Lines changed: 89 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/utils/utils.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,22 @@ func BeautifulTimeSince(timestamp string) string {
378378

379379
switch {
380380
case duration < minuteThreshold:
381-
return "less than a minute ago"
381+
return "Less than a minute ago"
382382
case duration < 2*minuteThreshold:
383-
return "around a minute ago"
383+
return "Around a minute ago"
384384
case duration < hourThreshold:
385385
minutes := int(duration.Minutes())
386-
return fmt.Sprintf("%d minutes ago", minutes)
386+
return fmt.Sprintf("Around %d minutes ago", minutes)
387387
case duration < 2*hourThreshold:
388-
return "around 1 hour ago"
388+
return "Around 1 hour ago"
389389
case duration < dayThreshold:
390390
hours := int(duration.Hours())
391-
return fmt.Sprintf("around %d hours ago", hours)
391+
return fmt.Sprintf("Around %d hours ago", hours)
392392
default:
393393
days := int(duration.Hours() / 24)
394394
if days == 1 {
395-
return "1 day ago"
395+
return "Around 1 day ago"
396396
}
397-
return fmt.Sprintf("%d days ago", days)
397+
return fmt.Sprintf("Around %d days ago", days)
398398
}
399399
}

0 commit comments

Comments
 (0)