本文整理汇总了Golang中github.com/qor/qor/admin.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Preview
func (db *publishController) Preview(context *admin.Context) {
type resource struct {
*admin.Resource
Value interface{}
}
var drafts = []resource{}
draftDB := context.GetDB().Set(publishDraftMode, true).Unscoped()
for _, res := range context.Admin.GetResources() {
if visibleInterface, ok := res.Value.(visiblePublishResourceInterface); ok {
if !visibleInterface.VisiblePublishResource() {
continue
}
} else if res.Config.Invisible {
continue
}
results := res.NewSlice()
if IsPublishableModel(res.Value) || IsPublishEvent(res.Value) {
if draftDB.Unscoped().Where("publish_status = ?", DIRTY).Find(results).RowsAffected > 0 {
drafts = append(drafts, resource{
Resource: res,
Value: results,
})
}
}
}
context.Execute("publish_drafts", drafts)
}
示例2: PublishOrDiscard
func (db *publishController) PublishOrDiscard(context *admin.Context) {
var request = context.Request
var ids = request.Form["checked_ids[]"]
var records = []interface{}{}
var values = map[string][]string{}
for _, id := range ids {
if keys := strings.Split(id, "__"); len(keys) == 2 {
name, id := keys[0], keys[1]
values[name] = append(values[name], id)
}
}
draftDB := context.GetDB().Set("publish:draft_mode", true).Unscoped()
for name, value := range values {
res := context.Admin.GetResource(name)
results := res.NewSlice()
if draftDB.Find(results, fmt.Sprintf("%v IN (?)", res.PrimaryDBName()), value).Error == nil {
resultValues := reflect.Indirect(reflect.ValueOf(results))
for i := 0; i < resultValues.Len(); i++ {
records = append(records, resultValues.Index(i).Interface())
}
}
}
if request.Form.Get("publish_type") == "publish" {
Publish{DB: draftDB}.Publish(records...)
} else if request.Form.Get("publish_type") == "discard" {
Publish{DB: draftDB}.Discard(records...)
}
http.Redirect(context.Writer, context.Request, context.Request.RequestURI, http.StatusFound)
}
示例3: Preview
func (db *publishController) Preview(context *admin.Context) {
drafts := make(map[*admin.Resource]interface{})
draftDB := context.GetDB().Set("publish:draft_mode", true).Unscoped()
for _, res := range context.Admin.GetResources() {
results := res.NewSlice()
if isPublishableModel(res.Value) {
if draftDB.Where("publish_status = ?", DIRTY).Find(results).RowsAffected > 0 {
drafts[res] = results
}
}
}
context.Execute("publish/drafts", drafts)
}
示例4: updatePosition
func updatePosition(context *admin.Context) {
if result, err := context.FindOne(); err == nil {
if position, ok := result.(sortingInterface); ok {
if pos, err := strconv.Atoi(context.Request.Form.Get("to")); err == nil {
var count int
if _, ok := result.(sortingDescInterface); ok {
context.GetDB().New().Model(modelValue(result)).Count(&count)
pos = count - pos + 1
}
if MoveTo(context.GetDB(), position, pos) == nil {
var pos = position.GetPosition()
if _, ok := result.(sortingDescInterface); ok {
pos = count - pos + 1
}
context.Writer.Write([]byte(fmt.Sprintf("%d", pos)))
return
}
}
}
}
context.Writer.Write([]byte("Error"))
context.Writer.WriteHeader(422)
}
示例5: updatePosition
func updatePosition(context *admin.Context) {
if result, err := context.FindOne(); err == nil {
if position, ok := result.(sortingInterface); ok {
if pos, err := strconv.Atoi(context.Request.Form.Get("to")); err == nil {
var count int
if _, ok := result.(sortingDescInterface); ok {
var result = context.Resource.NewStruct()
context.GetDB().Set("l10n:mode", "locale").Order("position DESC", true).First(result)
count = result.(sortingInterface).GetPosition()
pos = count - pos + 1
}
if MoveTo(context.GetDB(), position, pos) == nil {
var pos = position.GetPosition()
if _, ok := result.(sortingDescInterface); ok {
pos = count - pos + 1
}
context.Writer.Write([]byte(fmt.Sprintf("%d", pos)))
return
}
}
}
}
context.Writer.WriteHeader(admin.HTTPUnprocessableEntity)
context.Writer.Write([]byte("Error"))
}
示例6: Diff
func (db *publishController) Diff(context *admin.Context) {
resourceID := strings.Split(context.Request.URL.Path, "/")[4]
params := strings.Split(resourceID, "__")
name, id := params[0], params[1]
res := context.Admin.GetResource(name)
draft := res.NewStruct()
context.GetDB().Set("publish:draft_mode", true).Unscoped().First(draft, id)
production := res.NewStruct()
context.GetDB().Set("publish:draft_mode", false).Unscoped().First(production, id)
results := map[string]interface{}{"Production": production, "Draft": draft, "Resource": res}
fmt.Fprintf(context.Writer, string(context.Render("publish/diff", results)))
}
示例7: Index
func (controller *i18nController) Index(context *admin.Context) {
context.Execute("index", controller.I18n)
}