diff --git a/handlers/draw_handler.go b/handlers/draw_handler.go index 99c3221..28c9ffc 100644 --- a/handlers/draw_handler.go +++ b/handlers/draw_handler.go @@ -12,6 +12,7 @@ import ( "github.com/gorilla/csrf" ) +// ToDo this should not be in draw for home! func Home(db *sql.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { rows, err := db.Query(` @@ -50,8 +51,9 @@ func Home(db *sql.DB) http.HandlerFunc { context := helpers.TemplateContext(w, r) context["Data"] = results - tmpl := template.Must(template.ParseFiles( + tmpl := template.Must(template.New("").Funcs(helpers.TemplateFuncs()).ParseFiles( "templates/layout.html", + "templates/topbar.html", "templates/index.html", )) @@ -69,6 +71,7 @@ func NewDraw(w http.ResponseWriter, r *http.Request) { tmpl := template.Must(template.ParseFiles( "templates/layout.html", + "templates/topbar.html", "templates/new_draw.html", )) diff --git a/models/user.go b/models/user.go index 33c940d..842c2d2 100644 --- a/models/user.go +++ b/models/user.go @@ -13,6 +13,22 @@ type User struct { IsAdmin bool } +type Notification struct { + ID int + Title string + Message string + IsRead bool + CreatedAt time.Time +} + +type Message struct { + ID int + Sender string + Subject string + IsRead bool + CreatedAt time.Time +} + var db *sql.DB func SetDB(database *sql.DB) { diff --git a/static/css/site.css b/static/css/site.css index 8975d60..98e6bb8 100644 --- a/static/css/site.css +++ b/static/css/site.css @@ -1,3 +1,5 @@ +@import "topbar.css"; + body { font-family: Arial, sans-serif; margin: 0px; } table { border-collapse: collapse; width: 100%; margin-top: 20px; } th, td { padding: 8px 12px; border: 1px solid #ddd; text-align: center; } @@ -15,23 +17,6 @@ th { background-color: #f5f5f5; } } .flash { padding: 10px; color: green; background: #e9ffe9; border: 1px solid #c3e6c3; margin-bottom: 15px; } -.dropdown-admin-box { - min-width: 350px; -} - -.dropdown-notification-box { - min-width: 350px; -} - -.dropdown-message-box { - min-width: 350px; -} - -.btn-xs { - padding: 2px 6px; - font-size: 0.75rem; - line-height: 1; -} /* Ball Stuff */ .ball { diff --git a/static/css/topbar.css b/static/css/topbar.css new file mode 100644 index 0000000..85b43ce --- /dev/null +++ b/static/css/topbar.css @@ -0,0 +1,50 @@ +.dropdown-admin-box { + min-width: 350px; + } + + .dropdown-notification-box { + min-width: 350px; + } + + .dropdown-message-box { + min-width: 350px; + } + + .dropdown-with-arrow::before { + content: ""; + position: absolute; + top: -8px; + right: 3.5px; + width: 0; + height: 0; + border-left: 9px solid transparent; + border-right: 9px solid transparent; + border-bottom: 9px solid white; + z-index: 1; + } + + .dropdown-with-arrow::after { + content: ""; + position: absolute; + top: -9px; + right: 3.5px; + width: 0; + height: 0; + border-left: 9px solid transparent; + border-right: 9px solid transparent; + border-bottom: 9px solid rgba(0, 0, 0, 0.15); + z-index: 0; + } + +.btn-xs { + padding: 2px 6px; + font-size: 0.75rem; + line-height: 1; +} + +.badge-small { + font-size: 0.9rem; + padding: 2px 5px; + line-height: 1; + transform: translate(-50%, -50%); +} diff --git a/storage/badgecounts.go b/storage/badgecounts.go new file mode 100644 index 0000000..8ae8604 --- /dev/null +++ b/storage/badgecounts.go @@ -0,0 +1,11 @@ +package storage + +// "database/sql" + +// // Get all for count +// var count int +// db.Get(&count, `SELECT COUNT(*) FROM user_notifications WHERE user_id = ? AND is_read = FALSE`, userID) + +// // Then get the top 15 for display +// var notifications []Notification +// db.Select(¬ifications, `SELECT * FROM user_notifications WHERE user_id = ? AND is_read = FALSE ORDER BY created_at DESC LIMIT 15`, userID) diff --git a/storage/db.go b/storage/db.go index b1c2f60..a7cda70 100644 --- a/storage/db.go +++ b/storage/db.go @@ -135,16 +135,46 @@ func InitDB(filepath string) *sql.DB { createUsersTable := ` CREATE TABLE IF NOT EXISTS users ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - username TEXT NOT NULL UNIQUE, - password_hash TEXT NOT NULL, - is_admin BOOLEAN + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT NOT NULL UNIQUE, + password_hash TEXT NOT NULL, + is_admin BOOLEAN );` if _, err := db.Exec(createUsersTable); err != nil { log.Fatal("❌ Failed to create Users table:", err) } + createUsersMessageTable := ` + CREATE TABLE IF NOT EXISTS users_messages ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL REFERENCES users(id), + title TEXT NOT NULL, + message TEXT, + is_read BOOLEAN DEFAULT FALSE, + type VARCHAR(50), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + );` + + if _, err := db.Exec(createUsersMessageTable); err != nil { + log.Fatal("❌ Failed to create Users messages table:", err) + } + + createUsersNotificationTable := ` + CREATE TABLE IF NOT EXISTS users_notification ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL REFERENCES users(id), + sender_name VARCHAR(100), + subject TEXT, + body TEXT, + is_read BOOLEAN DEFAULT FALSE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + );` + + if _, err := db.Exec(createUsersNotificationTable); err != nil { + log.Fatal("❌ Failed to create Users notification table:", err) + } + createAuditLogTable := ` CREATE TABLE IF NOT EXISTS auditlog ( id INTEGER PRIMARY KEY AUTOINCREMENT, diff --git a/templates/layout.html b/templates/layout.html index e08d539..a0cecd8 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -10,111 +10,8 @@
- - - + {{ template "topbar" . }}