publish

package
v0.0.0-...-ea25219 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2015 License: MIT Imports: 10 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 Delete

func Delete(scope *gorm.Scope)

func DraftTableName

func DraftTableName(table string) string

func GetModeAndNewScope

func GetModeAndNewScope(scope *gorm.Scope) (isProduction bool, clone *gorm.Scope)

func IncludeValue

func IncludeValue(value string, values []string) bool

func IsPublishableModel

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

func OriginalTableName

func OriginalTableName(table string) string

func SetTableAndPublishStatus

func SetTableAndPublishStatus(ensureDraftMode bool) func(*gorm.Scope)

func SyncToProductionAfterCreate

func SyncToProductionAfterCreate(scope *gorm.Scope)

func SyncToProductionAfterDelete

func SyncToProductionAfterDelete(scope *gorm.Scope)

func SyncToProductionAfterUpdate

func SyncToProductionAfterUpdate(scope *gorm.Scope)

Types

type Dependency

type Dependency struct {
	Type        reflect.Type
	PrimaryKeys []string
}

type Interface

type Interface interface {
	GetPublishStatus() bool
	SetPublishStatus(bool)
}

type Publish

type Publish struct {
	DB              *gorm.DB
	SupportedModels []interface{}
}

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

func (db *Publish) NewResolver(records ...interface{}) *Resolver

func (*Publish) ProductionDB

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

func (*Publish) Publish

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

type PublishController

type PublishController struct {
	*Publish
}

func (*PublishController) Diff

func (db *PublishController) Diff(context *admin.Context)

func (*PublishController) Preview

func (db *PublishController) Preview(context *admin.Context)

func (*PublishController) PublishOrDiscard

func (db *PublishController) PublishOrDiscard(context *admin.Context)

type PublishJoinTableHandler

type PublishJoinTableHandler struct {
	gorm.JoinTableHandler
}

func (PublishJoinTableHandler) Add

func (handler PublishJoinTableHandler) Add(h gorm.JoinTableHandlerInterface, db *gorm.DB, source1 interface{}, source2 interface{}) error

func (PublishJoinTableHandler) Delete

func (handler PublishJoinTableHandler) Delete(h gorm.JoinTableHandlerInterface, db *gorm.DB, sources ...interface{}) error

func (PublishJoinTableHandler) Table

func (handler PublishJoinTableHandler) Table(db *gorm.DB) string

type Resolver

type Resolver struct {
	Records      []interface{}
	Dependencies map[string]*Dependency
	DB           *Publish
}

func (*Resolver) AddDependency

func (resolver *Resolver) AddDependency(dependency *Dependency)

func (*Resolver) Discard

func (resolver *Resolver) Discard() error

func (*Resolver) GenerateDependencies

func (resolver *Resolver) GenerateDependencies()

func (*Resolver) GetDependencies

func (resolver *Resolver) GetDependencies(dependency *Dependency, primaryKeys []string)

func (*Resolver) Publish

func (resolver *Resolver) Publish() error

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