notification

package module
v0.0.0-...-3208abc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 13 Imported by: 0

README

QOR Notification

QOR Notification provides a way to send notifications to QOR Admin administrators. Notifications can be anything your system needs, like order update, delivery notices, whatever.

Usage

Notification := notification.New(&notification.Config{})

// Add to Admin
Admin.NewResource(Notification)

// Register Database Channel
Notification.RegisterChannel(database.New(&database.Config{DB: db.DB}))

// Send Notification
Notification.Send(message *Message, context *qor.Context)

// Get Notification
Notification.GetNotification(user interface{}, messageID string, context *qor.Context)

// Get Notifications
Notification.GetNotifications(user interface{}, context *qor.Context)

// Get Unresolved Notifications Count
Notification.GetUnresolvedNotificationsCount(user interface{}, context *qor.Context)

The Notifications List in QOR Admin looks a bit like this when populated:

notification

Register Actions for Notification

This example shows how to add a "Dismiss" button to notification. The button will appears in the notification which ResolvedAt is nil. Please read the Action documentation for more details.

Notification.Action(&notification.Action{
  Name:         "Dismiss",
  MessageTypes: []string{"info", "order_processed", "order_returned"},
  Visible: func(data *notification.QorNotification, context *admin.Context) bool {
    return data.ResolvedAt == nil
  },
  Handle: func(argument *notification.ActionArgument) error {
    return argument.Context.GetDB().Model(argument.Message).Update("resolved_at", time.Now()).Error
  },
})

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name         string
	Label        string
	Method       string
	MessageTypes []string
	Resource     *admin.Resource
	Visible      func(data *QorNotification, context *admin.Context) bool
	URL          func(data *QorNotification, context *admin.Context) string
	Handler      func(actionArgument *ActionArgument) error
	Undo         func(actionArgument *ActionArgument) error
	FlashMessage func(actionArgument *ActionArgument, succeed bool, isUndo bool) string
}

func (Action) HasMessageType

func (action Action) HasMessageType(t string) bool

func (Action) ToParam

func (action Action) ToParam() string

ToParam used to register routes for actions

type ActionArgument

type ActionArgument struct {
	Message  *QorNotification
	Context  *admin.Context
	Argument interface{}
}

type ChannelInterface

type ChannelInterface interface {
	Send(message *Message, context *qor.Context) error
	GetNotifications(user interface{}, results *NotificationsResult, notification *Notification, context *qor.Context) error
	GetUnresolvedNotificationsCount(user interface{}, notification *Notification, context *qor.Context) uint
	GetNotification(user interface{}, notificationID string, notification *Notification, context *qor.Context) (*QorNotification, error)
}

type Config

type Config struct {
}

type Message

type Message struct {
	From        interface{}
	To          interface{}
	Title       string
	Body        string
	MessageType string
	ResolvedAt  *time.Time
}

type Notification

type Notification struct {
	Config   *Config
	Channels []ChannelInterface
	Actions  []*Action
}

func New

func New(config *Config) *Notification

func (*Notification) Action

func (notification *Notification) Action(action *Action) error

func (*Notification) ConfigureQorResource

func (notification *Notification) ConfigureQorResource(res resource.Resourcer)

func (*Notification) GetAction

func (notification *Notification) GetAction(name string) *Action

func (*Notification) GetNotification

func (notification *Notification) GetNotification(user interface{}, messageID string, context *qor.Context) *QorNotification

func (*Notification) GetNotifications

func (notification *Notification) GetNotifications(user interface{}, context *qor.Context) *NotificationsResult

func (*Notification) GetUnresolvedNotificationsCount

func (notification *Notification) GetUnresolvedNotificationsCount(user interface{}, context *qor.Context) uint

func (*Notification) RegisterChannel

func (notification *Notification) RegisterChannel(channel ChannelInterface)

func (*Notification) Send

func (notification *Notification) Send(message *Message, context *qor.Context) error

type NotificationsResult

type NotificationsResult struct {
	Notification  *Notification
	Notifications []*QorNotification
	Resolved      []*QorNotification
}

type QorNotification

type QorNotification struct {
	gorm.Model
	From        string
	To          string
	Title       string
	Body        string `sql:"size:65532"`
	MessageType string
	ResolvedAt  *time.Time
}

func (*QorNotification) Actions

func (qorNotification *QorNotification) Actions(context *admin.Context) (actions []*Action)

func (QorNotification) IsResolved

func (qorNotification QorNotification) IsResolved() bool

Directories

Path Synopsis
channels

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL