notification-center.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package e21_presents
  2. // @snippet_begin(NotificationCenterSample)
  3. import (
  4. "github.com/qor5/admin/presets"
  5. "github.com/qor5/admin/presets/gorm2op"
  6. "github.com/qor5/docs/docsrc/examples/utils"
  7. v "github.com/qor5/ui/vuetify"
  8. "github.com/qor5/web"
  9. h "github.com/theplant/htmlgo"
  10. )
  11. func PresetsNotificationCenterSample(b *presets.Builder) {
  12. db := utils.InitDB()
  13. b.URIPrefix(NotificationCenterSamplePath).
  14. DataOperator(gorm2op.DataOperator(db))
  15. db.AutoMigrate(&utils.Page{})
  16. b.Model(&utils.Page{})
  17. b.NotificationFunc(NotifierComponent(), NotifierCount())
  18. return
  19. }
  20. func NotifierComponent() func(ctx *web.EventContext) h.HTMLComponent {
  21. return func(ctx *web.EventContext) h.HTMLComponent {
  22. return v.VList(
  23. v.VListItem(
  24. v.VListItemContent(h.A(h.Label("New Notice:"),
  25. h.Text("unread notes: 3")),
  26. ),
  27. ),
  28. )
  29. }
  30. }
  31. func NotifierCount() func(ctx *web.EventContext) int {
  32. return func(ctx *web.EventContext) int {
  33. // Use your own count calculation logic here
  34. return 3
  35. }
  36. }
  37. // @snippet_end
  38. const NotificationCenterSamplePath = "/samples/notification_center"