本文整理匯總了Golang中github.com/qor/admin.Context.Execute方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Execute方法的具體用法?Golang Context.Execute怎麽用?Golang Context.Execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/qor/admin.Context
的用法示例。
在下文中一共展示了Context.Execute方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Update
func (wc workerController) Update(context *admin.Context) {
if job, err := wc.GetJob(context.ResourceID); err == nil {
if job.GetStatus() == JobStatusScheduled || job.GetStatus() == JobStatusNew {
if job.GetJob().HasPermission(roles.Update, context.Context) {
if context.AddError(wc.Worker.JobResource.Decode(context.Context, job)); !context.HasError() {
context.AddError(wc.Worker.JobResource.CallSave(job, context.Context))
context.AddError(wc.Worker.AddJob(job))
}
if !context.HasError() {
context.Flash(string(context.Admin.T(context.Context, "qor_worker.form.successfully_updated", "{{.Name}} was successfully updated", wc.Worker.JobResource)), "success")
}
context.Execute("edit", job)
return
}
}
context.AddError(errors.New("not allowed to update this job"))
} else {
context.AddError(err)
}
http.Redirect(context.Writer, context.Request, context.Request.URL.Path, http.StatusFound)
}
示例2: AddJob
func (wc workerController) AddJob(context *admin.Context) {
jobResource := wc.Worker.JobResource
result := jobResource.NewStruct().(QorJobInterface)
job := wc.Worker.GetRegisteredJob(context.Request.Form.Get("job_name"))
result.SetJob(job)
if !job.HasPermission(roles.Create, context.Context) {
context.AddError(errors.New("don't have permission to run job"))
}
if context.AddError(jobResource.Decode(context.Context, result)); !context.HasError() {
// ensure job name is correct
result.SetJob(job)
context.AddError(jobResource.CallSave(result, context.Context))
context.AddError(wc.Worker.AddJob(result))
}
if context.HasError() {
responder.With("html", func() {
context.Writer.WriteHeader(422)
context.Execute("edit", result)
}).With("json", func() {
context.Writer.WriteHeader(422)
context.JSON("index", map[string]interface{}{"errors": context.GetErrors()})
}).Respond(context.Request)
return
}
context.Flash(string(context.Admin.T(context.Context, "qor_worker.form.successfully_created", "{{.Name}} was successfully created", jobResource)), "success")
http.Redirect(context.Writer, context.Request, context.Request.URL.Path, http.StatusFound)
}
示例3: Preview
func (pc *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(context.Context) {
continue
}
} else if res.Config.Invisible {
continue
}
if res.HasPermission(PublishPermission, context.Context) {
results := res.NewSlice()
if IsPublishableModel(res.Value) || IsPublishEvent(res.Value) {
if pc.SearchHandler(draftDB.Where("publish_status = ?", DIRTY), context.Context).Find(results).RowsAffected > 0 {
drafts = append(drafts, resource{
Resource: res,
Value: results,
})
}
}
}
}
context.Execute("publish_drafts", drafts)
}
示例4: Index
func (wc workerController) Index(context *admin.Context) {
context = context.NewResourceContext(wc.JobResource)
result, err := context.FindMany()
context.AddError(err)
if context.HasError() {
http.NotFound(context.Writer, context.Request)
} else {
responder.With("html", func() {
context.Execute("index", result)
}).With("json", func() {
context.JSON("index", result)
}).Respond(context.Request)
}
}
示例5: New
func (wc workerController) New(context *admin.Context) {
context.Execute("new", wc.Worker)
}
示例6: Show
func (wc workerController) Show(context *admin.Context) {
job, err := wc.GetJob(context.ResourceID)
context.AddError(err)
context.Execute("show", job)
}
示例7: Index
func (controller *i18nController) Index(context *admin.Context) {
context.Execute("index", controller.I18n)
}