publish

package
v0.0.0-...-2ef9421 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2015 License: MIT Imports: 13 Imported by: 0

README

Introduction

Publish allow user update a resource but do not show the change in website until it is get "published"

Usage

Use "Product" and gorm for example.

First set publish.Status as field in the resource you want to use Publish

type Product struct {
  Name        string
  Description string
  publish.Status
}

DB, err = gorm.Open("sqlite3", "demo_db")
DB.AutoMigrate(&Product{})

Then initialize Publish and set which resource(table) needs Publish support.

publish := publish.New(&DB)
publish.AutoMigrate(&Product{})

Now, you have two tables for product. "products" and "products_draft", all changes made on product will be saved in "products_draft"

draft_db = publish.DraftDB() // Draft resources are saved here
production_db = publish.ProductionDB() // Published resources saved here

To process draft products

publish.Publish(products)
publish.Discard(products)

Use with QOR admin

Initialize QOR admin by set DB as Publish.DraftDB(), then add Publish to Admin resource.

Admin := admin.New(&qor.Config{DB: Publish.DraftDB()})
Admin.AddResource(Publish)

Now you can see a "Publish" link appears in QOR admin website, updated product will appears in this page and not available at front end. You can view difference, publish or discard changes made on product.

Documentation

Index

Constants

View Source
const (
	PUBLISHED = false
	DIRTY     = true
)

Variables

This section is empty.

Functions

func DraftTableName

func DraftTableName(table string) string

func IsDraftMode

func IsDraftMode(db *gorm.DB) bool

func IsPublishEvent

func IsPublishEvent(model interface{}) (ok bool)

func IsPublishableModel

func IsPublishableModel(model interface{}) (ok bool)

func OriginalTableName

func OriginalTableName(table string) string

func RegisterEvent

func RegisterEvent(name string, event EventInterface)

Types

type EventInterface

type EventInterface interface {
	Publish(db *gorm.DB, event PublishEventInterface) error
	Discard(db *gorm.DB, event PublishEventInterface) error
}

type Publish

type Publish struct {
	DB *gorm.DB
}

func New

func New(db *gorm.DB) *Publish

func (*Publish) AutoMigrate

func (db *Publish) AutoMigrate(values ...interface{})

func (*Publish) ConfigureQorResource

func (publish *Publish) ConfigureQorResource(res *admin.Resource)

func (Publish) Discard

func (db Publish) Discard(records ...interface{})

func (Publish) DraftDB

func (db Publish) DraftDB() *gorm.DB

func (Publish) ProductionDB

func (db Publish) ProductionDB() *gorm.DB

func (Publish) Publish

func (db Publish) Publish(records ...interface{})

type PublishEvent

type PublishEvent struct {
	gorm.Model
	Name          string
	Description   string
	Argument      string `sql:"size:65532"`
	PublishStatus bool
	PublishedBy   string
}

func (*PublishEvent) Discard

func (publishEvent *PublishEvent) Discard(db *gorm.DB) error

func (*PublishEvent) Publish

func (publishEvent *PublishEvent) Publish(db *gorm.DB) error

func (PublishEvent) VisiblePublishResource

func (PublishEvent) VisiblePublishResource() bool

type PublishEventInterface

type PublishEventInterface interface {
	Publish(*gorm.DB) error
	Discard(*gorm.DB) error
}

type Status

type Status struct {
	PublishStatus bool
}

func (Status) ConfigureQorResource

func (s Status) ConfigureQorResource(res *admin.Resource)

func (Status) GetPublishStatus

func (s Status) GetPublishStatus() bool

func (*Status) SetPublishStatus

func (s *Status) SetPublishStatus(status bool)

Jump to

Keyboard shortcuts

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