publish

package
v0.0.0-...-24faacb Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2015 License: MIT Imports: 12 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

This section is empty.

Types

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) Discard

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

func (Publish) DraftDB

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

func (*Publish) InjectQorAdmin

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

func (Publish) ProductionDB

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

func (Publish) Publish

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

type Status

type Status struct {
	PublishStatus bool
}

func (Status) GetPublishStatus

func (s Status) GetPublishStatus() bool

func (Status) InjectQorAdmin

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

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