Add simple notifications system to header
This just allows me to indicate that I need to tell the user something.
This commit is contained in:
parent
89c4072a35
commit
96c25b256b
2 changed files with 99 additions and 51 deletions
25
html.go
25
html.go
|
|
@ -84,9 +84,10 @@ type ServiceRequestSummary struct {
|
|||
Status string
|
||||
}
|
||||
type User struct {
|
||||
DisplayName string
|
||||
Initials string
|
||||
Username string
|
||||
DisplayName string
|
||||
Initials string
|
||||
Notifications []Notification
|
||||
Username string
|
||||
}
|
||||
|
||||
func (bt *BuiltTemplate) ExecuteTemplate(w io.Writer, data any) error {
|
||||
|
|
@ -162,6 +163,11 @@ func htmlDashboard(ctx context.Context, w http.ResponseWriter, user *models.User
|
|||
Status: "Completed",
|
||||
})
|
||||
}
|
||||
notifications, err := notificationsForUser(user)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get notifications", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
data := ContentDashboard{
|
||||
CountInspections: int(inspectionCount),
|
||||
CountMosquitoSources: int(sourceCount),
|
||||
|
|
@ -170,9 +176,10 @@ func htmlDashboard(ctx context.Context, w http.ResponseWriter, user *models.User
|
|||
Org: org.Name.MustGet(),
|
||||
RecentRequests: requests,
|
||||
User: User{
|
||||
DisplayName: user.DisplayName,
|
||||
Initials: extractInitials(user.DisplayName),
|
||||
Username: user.Username,
|
||||
DisplayName: user.DisplayName,
|
||||
Initials: extractInitials(user.DisplayName),
|
||||
Notifications: notifications,
|
||||
Username: user.Username,
|
||||
},
|
||||
}
|
||||
renderOrError(w, dashboard, data)
|
||||
|
|
@ -394,16 +401,18 @@ func timeSince(t time.Time) string {
|
|||
}
|
||||
|
||||
type Notification struct {
|
||||
Created time.Time
|
||||
Link string
|
||||
Message string
|
||||
Time time.Time
|
||||
Type string
|
||||
}
|
||||
|
||||
func notificationsForUser(u *models.User) ([]Notification, error) {
|
||||
return []Notification{Notification{
|
||||
Created: time.Now(),
|
||||
Link: "/foo/bar",
|
||||
Message: "hey, your oauth is broken.",
|
||||
Time: time.Now(),
|
||||
Type: "alert",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,50 +1,89 @@
|
|||
{{define "header"}}
|
||||
<header class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<!-- Logo -->
|
||||
<a class="navbar-brand" href="dashboard.html">
|
||||
<div class="logo-placeholder" style="width: 100px; height: 40px; background-color: #e9ecef; display: flex; align-items: center; justify-content: center; border-radius: 4px;">
|
||||
<span class="text-muted small">Your Logo</span>
|
||||
</div>
|
||||
</a>
|
||||
<div class="container">
|
||||
<!-- Logo -->
|
||||
<a class="navbar-brand" href="dashboard.html">
|
||||
<div class="logo-placeholder" style="width: 100px; height: 40px; background-color: #e9ecef; display: flex; align-items: center; justify-content: center; border-radius: 4px;">
|
||||
<span class="text-muted small">Your Logo</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<!-- Toggle Button for Mobile -->
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<!-- Toggle Button for Mobile -->
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<!-- Nav Items -->
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="dashboard.html">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="projects.html">Projects</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="maps.html">Maps</a>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- Nav Items -->
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="dashboard.html">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="projects.html">Projects</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="maps.html">Maps</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- User Info & Logout -->
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="dropdown">
|
||||
<a class="text-decoration-none dropdown-toggle d-flex align-items-center" href="#" role="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<div class="avatar me-2 bg-primary rounded-circle d-flex align-items-center justify-content-center" style="width: 36px; height: 36px;">
|
||||
<span class="text-white">{{ .Initials }}</span>
|
||||
</div>
|
||||
<span class="me-2">{{ .DisplayName }}</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
||||
<li><a class="dropdown-item" href="profile.html">Profile</a></li>
|
||||
<li><a class="dropdown-item" href="settings.html">Settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-danger" href="login.html">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- User Info, Notifications & Logout -->
|
||||
<div class="d-flex align-items-center">
|
||||
<!-- Notification Bell with Badge -->
|
||||
<div class="dropdown me-3">
|
||||
<a class="position-relative text-decoration-none" href="#" role="button" id="notificationsDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-bell-fill fs-5"></i>
|
||||
{{if gt (len .Notifications) 0}}
|
||||
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
|
||||
{{if gt (len .Notifications) 99}}99+{{else}}{{len .Notifications}}{{end}}
|
||||
<span class="visually-hidden">unread notifications</span>
|
||||
</span>
|
||||
{{end}}
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="notificationsDropdown" style="width: 300px; max-height: 400px; overflow-y: auto;">
|
||||
<li><h6 class="dropdown-header">Notifications</h6></li>
|
||||
{{if gt (len .Notifications) 0}}
|
||||
{{range .Notifications}}
|
||||
<li>
|
||||
<a class="dropdown-item py-2" href="{{.Link}}">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<div class="{{if eq .Type "alert"}}bg-danger{{else}}bg-primary{{end}} rounded-circle p-1">
|
||||
<i class="bi bi-{{if eq .Type "alert"}}exclamation{{else}}info{{end}}-circle text-white small"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-grow-1 ms-2">
|
||||
<p class="mb-0 small">{{.Message}}</p>
|
||||
<span class="text-muted x-small">{{.Time | timeSince}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
{{end}}
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-center small" href="notifications.html">View all</a></li>
|
||||
{{else}}
|
||||
<li><p class="dropdown-item text-center py-3 text-muted">No new notifications</p></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="dropdown">
|
||||
<a class="text-decoration-none dropdown-toggle d-flex align-items-center" href="#" role="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<div class="avatar me-2 bg-primary rounded-circle d-flex align-items-center justify-content-center" style="width: 36px; height: 36px;">
|
||||
<span class="text-white">{{ .Initials }}</span>
|
||||
</div>
|
||||
<span class="me-2">{{ .DisplayName }}</span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
||||
<li><a class="dropdown-item" href="profile.html">Profile</a></li>
|
||||
<li><a class="dropdown-item" href="settings.html">Settings</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-danger" href="login.html">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
{{end}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue