Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithCreator(ctx context.Context, name string) context.Context
- func ContextWithDB(ctx context.Context, db *gorm.DB) context.Context
- func DiffComponent(diffstr string, req *http.Request) h.HTMLComponent
- type ActivityBuilder
- func (ab *ActivityBuilder) AddCreateRecord(creator interface{}, v interface{}, db *gorm.DB) error
- func (ab *ActivityBuilder) AddCustomizedRecord(action string, diff bool, ctx context.Context, obj interface{}) error
- func (ab *ActivityBuilder) AddDeleteRecord(creator interface{}, v interface{}, db *gorm.DB) error
- func (ab *ActivityBuilder) AddEditRecord(creator interface{}, now interface{}, db *gorm.DB) error
- func (ab *ActivityBuilder) AddEditRecordWithOld(creator interface{}, old, now interface{}, db *gorm.DB) error
- func (ab *ActivityBuilder) AddEditRecordWithOldAndContext(ctx context.Context, old, now interface{}) error
- func (ab *ActivityBuilder) AddRecords(action string, ctx context.Context, vs ...interface{}) error
- func (ab *ActivityBuilder) AddSaveRecord(creator interface{}, now interface{}, db *gorm.DB) error
- func (ab *ActivityBuilder) AddViewRecord(creator interface{}, v interface{}, db *gorm.DB) error
- func (ab ActivityBuilder) GetActivityLogs(m interface{}, db *gorm.DB) []*ActivityLog
- func (ab ActivityBuilder) GetCustomizeActivityLogs(m interface{}, db *gorm.DB) interface{}
- func (ab ActivityBuilder) GetModelBuilder(v interface{}) (*ModelBuilder, bool)
- func (ab ActivityBuilder) GetModelBuilders() []*ModelBuilder
- func (ab ActivityBuilder) GetPresetModelBuilder() *presets.ModelBuilder
- func (ab ActivityBuilder) MustGetModelBuilder(v interface{}) *ModelBuilder
- func (ab ActivityBuilder) NewLogModelData() interface{}
- func (ab ActivityBuilder) NewLogModelSlice() interface{}
- func (ab *ActivityBuilder) RegisterModel(m interface{}) (mb *ModelBuilder)
- func (ab *ActivityBuilder) RegisterModels(models ...interface{}) *ActivityBuilder
- func (ab *ActivityBuilder) SetCreatorContextKey(key interface{}) *ActivityBuilder
- func (ab *ActivityBuilder) SetDBContextKey(key interface{}) *ActivityBuilder
- func (ab *ActivityBuilder) SetTabHeading(f func(log ActivityLogInterface) string) *ActivityBuilder
- type ActivityLog
- func (al *ActivityLog) GetAction() string
- func (al ActivityLog) GetCreatedAt() time.Time
- func (al *ActivityLog) GetCreator() string
- func (al *ActivityLog) GetModelDiffs() string
- func (al *ActivityLog) GetModelKeys() string
- func (al *ActivityLog) GetModelLabel() string
- func (al *ActivityLog) GetModelLink() string
- func (al *ActivityLog) GetModelName() string
- func (al ActivityLog) GetUserID() uint
- func (al *ActivityLog) SetAction(s string)
- func (al *ActivityLog) SetCreatedAt(t time.Time)
- func (al *ActivityLog) SetCreator(s string)
- func (al *ActivityLog) SetModelDiffs(s string)
- func (al *ActivityLog) SetModelKeys(s string)
- func (al *ActivityLog) SetModelLabel(s string)
- func (al *ActivityLog) SetModelLink(s string)
- func (al *ActivityLog) SetModelName(s string)
- func (al *ActivityLog) SetUserID(id uint)
- type ActivityLogInterface
- type CreatorInterface
- type Diff
- type DiffBuilder
- type Messages
- type ModelBuilder
- func (mb *ModelBuilder) AddCreateRecord(creator interface{}, v interface{}, db *gorm.DB) error
- func (mb *ModelBuilder) AddCustomizedRecord(action string, diff bool, ctx context.Context, obj interface{}) error
- func (mb *ModelBuilder) AddDeleteRecord(creator interface{}, v interface{}, db *gorm.DB) error
- func (mb *ModelBuilder) AddEditRecord(creator interface{}, now interface{}, db *gorm.DB) error
- func (mb *ModelBuilder) AddEditRecordWithOld(creator interface{}, old, now interface{}, db *gorm.DB) error
- func (mb *ModelBuilder) AddIgnoredFields(fields ...string) *ModelBuilder
- func (mb *ModelBuilder) AddKeys(keys ...string) *ModelBuilder
- func (mb *ModelBuilder) AddRecords(action string, ctx context.Context, vs ...interface{}) error
- func (mb *ModelBuilder) AddSaveRecord(creator interface{}, now interface{}, db *gorm.DB) error
- func (mb *ModelBuilder) AddTypeHanders(v interface{}, f TypeHandler) *ModelBuilder
- func (mb *ModelBuilder) AddViewRecord(creator interface{}, v interface{}, db *gorm.DB) error
- func (mb *ModelBuilder) Diff(old, now interface{}) ([]Diff, error)
- func (mb *ModelBuilder) GetType() reflect.Type
- func (mb *ModelBuilder) KeysValue(v interface{}) string
- func (mb *ModelBuilder) SetIgnoredFields(fields ...string) *ModelBuilder
- func (mb *ModelBuilder) SetKeys(keys ...string) *ModelBuilder
- func (mb *ModelBuilder) SetLink(f func(interface{}) string) *ModelBuilder
- func (mb *ModelBuilder) SkipCreate() *ModelBuilder
- func (mb *ModelBuilder) SkipDelete() *ModelBuilder
- func (mb *ModelBuilder) SkipUpdate() *ModelBuilder
- func (mb *ModelBuilder) UseDefaultTab() *ModelBuilder
- type TypeHandler
Constants ¶
const ( Create = 1 << iota Delete Update )
const ( CreatorContextKey contextKey = iota DBContextKey )
const ( ActivityView = "View" ActivityEdit = "Edit" ActivityCreate = "Create" ActivityDelete = "Delete" )
const (
I18nActivityKey i18n.ModuleKey = "I18nActivityKey"
)
Variables ¶
var ( // @snippet_begin(ActivityDefaultIgnoredFields) DefaultIgnoredFields = []string{"ID", "UpdatedAt", "DeletedAt", "CreatedAt"} // @snippet_begin(ActivityDefaultTypeHandles) DefaultTypeHandles = map[reflect.Type]TypeHandler{ reflect.TypeOf(time.Time{}): func(old, now interface{}, prefixField string) []Diff { oldString := old.(time.Time).Format(time.RFC3339) nowString := now.(time.Time).Format(time.RFC3339) if oldString != nowString { return []Diff{ {Field: prefixField, Old: oldString, Now: nowString}, } } return []Diff{} }, reflect.TypeOf(media_library.MediaBox{}): func(old, now interface{}, prefixField string) (diffs []Diff) { oldMediaBox := old.(media_library.MediaBox) nowMediaBox := now.(media_library.MediaBox) if oldMediaBox.Url != nowMediaBox.Url { diffs = append(diffs, Diff{Field: formatFieldByDot(prefixField, "Url"), Old: oldMediaBox.Url, Now: nowMediaBox.Url}) } if oldMediaBox.Description != nowMediaBox.Description { diffs = append(diffs, Diff{Field: formatFieldByDot(prefixField, "Description"), Old: oldMediaBox.Description, Now: nowMediaBox.Description}) } if oldMediaBox.VideoLink != nowMediaBox.VideoLink { diffs = append(diffs, Diff{Field: formatFieldByDot(prefixField, "VideoLink"), Old: oldMediaBox.VideoLink, Now: nowMediaBox.VideoLink}) } return diffs }, } )
var Messages_en_US = &Messages{
Activities: "Activities",
ActionAll: "All",
ActionView: "View",
ActionEdit: "Edit",
ActionCreate: "Create",
ActionDelete: "Delete",
ModelUserID: "Creator ID",
ModelCreatedAt: "Date Time",
ModelAction: "Action",
ModelCreator: "Creator",
ModelKeys: "Keys",
ModelName: "Table Name",
ModelLabel: "Menu Name",
ModelLink: "Link",
ModelDiffs: "Diffs",
FilterAction: "Action",
FilterCreatedAt: "Create Time",
FilterCreator: "Creator",
FilterModel: "Model Name",
DiffDetail: "Detail",
DiffNew: "New",
DiffDelete: "Delete",
DiffChanges: "Changes",
DiffField: "Filed",
DiffOld: "Old",
DiffNow: "Now",
DiffValue: "Value",
}
var Messages_zh_CN = &Messages{
Activities: "活动",
ActionAll: "全部",
ActionView: "查看",
ActionEdit: "编辑",
ActionCreate: "创建",
ActionDelete: "删除",
ModelUserID: "操作者ID",
ModelCreatedAt: "日期时间",
ModelAction: "操作",
ModelCreator: "操作者",
ModelKeys: "表的主键值",
ModelName: "表名",
ModelLabel: "菜单名",
ModelLink: "链接",
ModelDiffs: "差异",
FilterAction: "操作类型",
FilterCreatedAt: "操作时间",
FilterCreator: "操作人",
FilterModel: "操作对象",
DiffDetail: "详情",
DiffNew: "新加",
DiffDelete: "删除",
DiffChanges: "修改",
DiffField: "字段",
DiffOld: "之前的值",
DiffNow: "当前的值",
DiffValue: "值",
}
Functions ¶
func DiffComponent ¶
func DiffComponent(diffstr string, req *http.Request) h.HTMLComponent
Types ¶
type ActivityBuilder ¶
type ActivityBuilder struct {
// contains filtered or unexported fields
}
@snippet_begin(ActivityBuilder)
func New ¶
func New(b *presets.Builder, db *gorm.DB, logModel ...ActivityLogInterface) *ActivityBuilder
func (*ActivityBuilder) AddCreateRecord ¶
func (ab *ActivityBuilder) AddCreateRecord(creator interface{}, v interface{}, db *gorm.DB) error
AddCreateRecord add create record
func (*ActivityBuilder) AddCustomizedRecord ¶
func (ab *ActivityBuilder) AddCustomizedRecord(action string, diff bool, ctx context.Context, obj interface{}) error
AddCustomizedRecord add customized record
func (*ActivityBuilder) AddDeleteRecord ¶
func (ab *ActivityBuilder) AddDeleteRecord(creator interface{}, v interface{}, db *gorm.DB) error
AddDeleteRecord add delete record
func (*ActivityBuilder) AddEditRecord ¶
func (ab *ActivityBuilder) AddEditRecord(creator interface{}, now interface{}, db *gorm.DB) error
AddEditRecord add edit record
func (*ActivityBuilder) AddEditRecordWithOld ¶
func (ab *ActivityBuilder) AddEditRecordWithOld(creator interface{}, old, now interface{}, db *gorm.DB) error
AddEditRecord add edit record
func (*ActivityBuilder) AddEditRecordWithOldAndContext ¶
func (ab *ActivityBuilder) AddEditRecordWithOldAndContext(ctx context.Context, old, now interface{}) error
AddEditRecordWithOldAndContext add edit record
func (*ActivityBuilder) AddRecords ¶
func (ab *ActivityBuilder) AddRecords(action string, ctx context.Context, vs ...interface{}) error
AddRecords add records log
func (*ActivityBuilder) AddSaveRecord ¶
func (ab *ActivityBuilder) AddSaveRecord(creator interface{}, now interface{}, db *gorm.DB) error
AddSaverRecord will save a create log or a edit log
func (*ActivityBuilder) AddViewRecord ¶
func (ab *ActivityBuilder) AddViewRecord(creator interface{}, v interface{}, db *gorm.DB) error
AddViewRecord add view record
func (ActivityBuilder) GetActivityLogs ¶
func (ab ActivityBuilder) GetActivityLogs(m interface{}, db *gorm.DB) []*ActivityLog
GetActivityLogs get activity logs
func (ActivityBuilder) GetCustomizeActivityLogs ¶
func (ab ActivityBuilder) GetCustomizeActivityLogs(m interface{}, db *gorm.DB) interface{}
GetCustomizeActivityLogs get customize activity logs
func (ActivityBuilder) GetModelBuilder ¶
func (ab ActivityBuilder) GetModelBuilder(v interface{}) (*ModelBuilder, bool)
GetModelBuilder get model builder
func (ActivityBuilder) GetModelBuilders ¶
func (ab ActivityBuilder) GetModelBuilders() []*ModelBuilder
GetModelBuilders get all model builders
func (ActivityBuilder) GetPresetModelBuilder ¶
func (ab ActivityBuilder) GetPresetModelBuilder() *presets.ModelBuilder
GetPresetModelBuilder return the preset model builder
func (ActivityBuilder) MustGetModelBuilder ¶
func (ab ActivityBuilder) MustGetModelBuilder(v interface{}) *ModelBuilder
GetModelBuilder get model builder
func (ActivityBuilder) NewLogModelData ¶
func (ab ActivityBuilder) NewLogModelData() interface{}
NewLogModelData new a log model data
func (ActivityBuilder) NewLogModelSlice ¶
func (ab ActivityBuilder) NewLogModelSlice() interface{}
NewLogModelSlice new a log model slice
func (*ActivityBuilder) RegisterModel ¶
func (ab *ActivityBuilder) RegisterModel(m interface{}) (mb *ModelBuilder)
Model register a model and return model builder
func (*ActivityBuilder) RegisterModels ¶
func (ab *ActivityBuilder) RegisterModels(models ...interface{}) *ActivityBuilder
RegisterModels register mutiple models
func (*ActivityBuilder) SetCreatorContextKey ¶
func (ab *ActivityBuilder) SetCreatorContextKey(key interface{}) *ActivityBuilder
SetCreatorContextKey change the default creator context key
func (*ActivityBuilder) SetDBContextKey ¶
func (ab *ActivityBuilder) SetDBContextKey(key interface{}) *ActivityBuilder
SetDBContextKey change the default db context key
func (*ActivityBuilder) SetTabHeading ¶
func (ab *ActivityBuilder) SetTabHeading(f func(log ActivityLogInterface) string) *ActivityBuilder
type ActivityLog ¶
type ActivityLog struct { ID uint `gorm:"primary_key"` UserID uint CreatedAt time.Time Creator string Action string ModelKeys string `gorm:"index"` ModelName string `gorm:"index"` ModelLabel string ModelLink string ModelDiffs string `sql:"type:text;"` }
func (*ActivityLog) GetAction ¶
func (al *ActivityLog) GetAction() string
func (ActivityLog) GetCreatedAt ¶
func (al ActivityLog) GetCreatedAt() time.Time
func (*ActivityLog) GetCreator ¶
func (al *ActivityLog) GetCreator() string
func (*ActivityLog) GetModelDiffs ¶
func (al *ActivityLog) GetModelDiffs() string
func (*ActivityLog) GetModelKeys ¶
func (al *ActivityLog) GetModelKeys() string
func (*ActivityLog) GetModelLabel ¶
func (al *ActivityLog) GetModelLabel() string
func (*ActivityLog) GetModelLink ¶
func (al *ActivityLog) GetModelLink() string
func (*ActivityLog) GetModelName ¶
func (al *ActivityLog) GetModelName() string
func (ActivityLog) GetUserID ¶
func (al ActivityLog) GetUserID() uint
func (*ActivityLog) SetAction ¶
func (al *ActivityLog) SetAction(s string)
func (*ActivityLog) SetCreatedAt ¶
func (al *ActivityLog) SetCreatedAt(t time.Time)
func (*ActivityLog) SetCreator ¶
func (al *ActivityLog) SetCreator(s string)
func (*ActivityLog) SetModelDiffs ¶
func (al *ActivityLog) SetModelDiffs(s string)
func (*ActivityLog) SetModelKeys ¶
func (al *ActivityLog) SetModelKeys(s string)
func (*ActivityLog) SetModelLabel ¶
func (al *ActivityLog) SetModelLabel(s string)
func (*ActivityLog) SetModelLink ¶
func (al *ActivityLog) SetModelLink(s string)
func (*ActivityLog) SetModelName ¶
func (al *ActivityLog) SetModelName(s string)
func (*ActivityLog) SetUserID ¶
func (al *ActivityLog) SetUserID(id uint)
type ActivityLogInterface ¶
type ActivityLogInterface interface { SetCreatedAt(time.Time) GetCreatedAt() time.Time SetUserID(uint) GetUserID() uint SetCreator(string) GetCreator() string SetAction(string) GetAction() string SetModelKeys(string) GetModelKeys() string SetModelName(string) GetModelName() string SetModelLabel(string) GetModelLabel() string SetModelLink(string) GetModelLink() string SetModelDiffs(string) GetModelDiffs() string }
type CreatorInterface ¶
type DiffBuilder ¶
type DiffBuilder struct {
// contains filtered or unexported fields
}
func NewDiffBuilder ¶
func NewDiffBuilder(mb *ModelBuilder) *DiffBuilder
func (*DiffBuilder) Diff ¶
func (db *DiffBuilder) Diff(old, now interface{}) ([]Diff, error)
type Messages ¶
type Messages struct { Activities string ActionAll string ActionView string ActionEdit string ActionCreate string ActionDelete string ModelUserID string ModelCreatedAt string ModelAction string ModelCreator string ModelKeys string ModelName string ModelLabel string ModelLink string ModelDiffs string FilterAction string FilterCreatedAt string FilterCreator string FilterModel string DiffDetail string DiffNew string DiffDelete string DiffChanges string DiffField string DiffOld string DiffNow string DiffValue string }
type ModelBuilder ¶
type ModelBuilder struct {
// contains filtered or unexported fields
}
@snippet_begin(ActivityModelBuilder) a unique model builder is consist of typ and presetModel
func (*ModelBuilder) AddCreateRecord ¶
func (mb *ModelBuilder) AddCreateRecord(creator interface{}, v interface{}, db *gorm.DB) error
AddCreateRecord add create record
func (*ModelBuilder) AddCustomizedRecord ¶
func (mb *ModelBuilder) AddCustomizedRecord(action string, diff bool, ctx context.Context, obj interface{}) error
AddCustomizedRecord add customized record
func (*ModelBuilder) AddDeleteRecord ¶
func (mb *ModelBuilder) AddDeleteRecord(creator interface{}, v interface{}, db *gorm.DB) error
AddDeleteRecord add delete record
func (*ModelBuilder) AddEditRecord ¶
func (mb *ModelBuilder) AddEditRecord(creator interface{}, now interface{}, db *gorm.DB) error
AddEditRecord add edit record
func (*ModelBuilder) AddEditRecordWithOld ¶
func (mb *ModelBuilder) AddEditRecordWithOld(creator interface{}, old, now interface{}, db *gorm.DB) error
AddEditRecord add edit record
func (*ModelBuilder) AddIgnoredFields ¶
func (mb *ModelBuilder) AddIgnoredFields(fields ...string) *ModelBuilder
AddIgnoredFields add ignored fields to the model builder
func (*ModelBuilder) AddKeys ¶
func (mb *ModelBuilder) AddKeys(keys ...string) *ModelBuilder
AddKeys add keys to the model builder
func (*ModelBuilder) AddRecords ¶
func (mb *ModelBuilder) AddRecords(action string, ctx context.Context, vs ...interface{}) error
AddRecords add records log
func (*ModelBuilder) AddSaveRecord ¶
func (mb *ModelBuilder) AddSaveRecord(creator interface{}, now interface{}, db *gorm.DB) error
AddSaverRecord will save a create log or a edit log
func (*ModelBuilder) AddTypeHanders ¶
func (mb *ModelBuilder) AddTypeHanders(v interface{}, f TypeHandler) *ModelBuilder
AddTypeHanders add type handers for the model builder
func (*ModelBuilder) AddViewRecord ¶
func (mb *ModelBuilder) AddViewRecord(creator interface{}, v interface{}, db *gorm.DB) error
AddViewRecord add view record
func (*ModelBuilder) Diff ¶
func (mb *ModelBuilder) Diff(old, now interface{}) ([]Diff, error)
Diff get diffs between old and now value
func (*ModelBuilder) GetType ¶
func (mb *ModelBuilder) GetType() reflect.Type
GetType get ModelBuilder type
func (*ModelBuilder) KeysValue ¶
func (mb *ModelBuilder) KeysValue(v interface{}) string
KeysValue get model keys value
func (*ModelBuilder) SetIgnoredFields ¶
func (mb *ModelBuilder) SetIgnoredFields(fields ...string) *ModelBuilder
SetIgnoredFields set ignored fields for the model builder
func (*ModelBuilder) SetKeys ¶
func (mb *ModelBuilder) SetKeys(keys ...string) *ModelBuilder
SetKeys set keys for the model builder
func (*ModelBuilder) SetLink ¶
func (mb *ModelBuilder) SetLink(f func(interface{}) string) *ModelBuilder
SetLink set the model link
func (*ModelBuilder) SkipCreate ¶
func (mb *ModelBuilder) SkipCreate() *ModelBuilder
SkipCreate skip the create action for preset.ModelBuilder
func (*ModelBuilder) SkipDelete ¶
func (mb *ModelBuilder) SkipDelete() *ModelBuilder
SkipDelete skip the delete action for preset.ModelBuilder
func (*ModelBuilder) SkipUpdate ¶
func (mb *ModelBuilder) SkipUpdate() *ModelBuilder
SkipUpdate skip the update action for preset.ModelBuilder
func (*ModelBuilder) UseDefaultTab ¶
func (mb *ModelBuilder) UseDefaultTab() *ModelBuilder
UseDefaultTab use activity tab on the admin model edit page
type TypeHandler ¶
@snippet_begin(ActivityTypeHandle)