• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang admin.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/qor/admin.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Context类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: PublishOrDiscard

func (pc *publishController) PublishOrDiscard(context *admin.Context) {
	var request = context.Request
	var ids = request.Form["checked_ids[]"]

	if scheduler := pc.Publish.WorkerScheduler; scheduler != nil {
		jobResource := scheduler.JobResource
		result := jobResource.NewStruct().(worker.QorJobInterface)
		if request.Form.Get("publish_type") == "discard" {
			result.SetJob(scheduler.GetRegisteredJob("Discard"))
		} else {
			result.SetJob(scheduler.GetRegisteredJob("Publish"))
		}

		workerArgument := &QorWorkerArgument{IDs: ids}
		if t, err := utils.ParseTime(request.Form.Get("scheduled_time"), context.Context); err == nil {
			workerArgument.ScheduleTime = &t
		}
		result.SetSerializableArgumentValue(workerArgument)

		jobResource.CallSave(result, context.Context)
		scheduler.AddJob(result)

		http.Redirect(context.Writer, context.Request, context.URLFor(jobResource), http.StatusFound)
	} else {
		records := pc.searchWithPublishIDs(context.GetDB().Set(publishDraftMode, true), context.Admin, ids)

		if request.Form.Get("publish_type") == "publish" {
			pc.Publish.Publish(records...)
		} else if request.Form.Get("publish_type") == "discard" {
			pc.Publish.Discard(records...)
		}

		http.Redirect(context.Writer, context.Request, context.Request.RequestURI, http.StatusFound)
	}
}
开发者ID:qor,项目名称:publish,代码行数:35,代码来源:controller.go


示例2: 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)
}
开发者ID:qor,项目名称:publish,代码行数:32,代码来源:controller.go


示例3: getPrimaryKey

func getPrimaryKey(context *admin.Context, record interface{}) string {
	db := context.GetDB()

	var primaryValues []string
	for _, field := range db.NewScope(record).PrimaryFields() {
		primaryValues = append(primaryValues, fmt.Sprint(field.Field.Interface()))
	}
	return strings.Join(primaryValues, "::")
}
开发者ID:qor,项目名称:activity,代码行数:9,代码来源:resource.go


示例4: RunJob

func (wc workerController) RunJob(context *admin.Context) {
	if newJob := wc.Worker.saveAnotherJob(context.ResourceID); newJob != nil {
		wc.Worker.AddJob(newJob)
	} else {
		context.AddError(errors.New("failed to clone job " + context.ResourceID))
	}

	http.Redirect(context.Writer, context.Request, context.URLFor(wc.Worker.JobResource), http.StatusFound)
}
开发者ID:qor,项目名称:worker,代码行数:9,代码来源:controller.go


示例5: renderLatestOrder

func renderLatestOrder(context *admin.Context) template.HTML {
	var orderContext = context.NewResourceContext("Order")
	orderContext.Searcher.Pagination.PerPage = 5
	// orderContext.SetDB(orderContext.GetDB().Where("state in (?)", []string{"paid"}))

	if orders, err := orderContext.FindMany(); err == nil {
		return orderContext.Render("index/table", orders)
	}
	return template.HTML("")
}
开发者ID:qor,项目名称:qor-example,代码行数:10,代码来源:funcmap.go


示例6: KillJob

func (wc workerController) KillJob(context *admin.Context) {
	if qorJob, err := wc.Worker.GetJob(context.ResourceID); err == nil {
		if context.AddError(wc.Worker.KillJob(qorJob.GetJobID())); !context.HasError() {
			context.Flash(string(context.Admin.T(context.Context, "qor_worker.form.successfully_killed", "{{.Name}} was successfully killed", wc.JobResource)), "success")
		} else {
			context.Flash(string(context.Admin.T(context.Context, "qor_worker.form.failed_to_kill", "Failed to kill job {{.Name}}", wc.JobResource)), "error")
		}
	}

	http.Redirect(context.Writer, context.Request, context.Request.URL.Path, http.StatusFound)
}
开发者ID:qor,项目名称:worker,代码行数:11,代码来源:controller.go


示例7: GetActivity

func (ctrl controller) GetActivity(context *admin.Context) {
	activities, _ := GetActivities(context, "-tag")
	activityResource := ctrl.ActivityResource

	if context.HasError() {
		responder.With("json", func() {
			context.JSON("edit", map[string]interface{}{"errors": context.GetErrors()})
		}).Respond(context.Request)
	} else {
		responder.With("json", func() {
			context.Resource = activityResource
			context.JSON("index", activities)
		}).Respond(context.Request)
	}
}
开发者ID:qor,项目名称:activity,代码行数:15,代码来源:controller.go


示例8: prepareGetActivitiesDB

func prepareGetActivitiesDB(context *admin.Context, types ...string) *gorm.DB {
	db := context.GetDB().Order("id asc").Where("resource_id = ? AND resource_type = ?", context.Resource.GetPrimaryValue(context.Request), context.Resource.ToParam())

	var inTypes, notInTypes []string
	for _, t := range types {
		if strings.HasPrefix(t, "-") {
			notInTypes = append(notInTypes, strings.TrimPrefix(t, "-"))
		} else {
			inTypes = append(inTypes, t)
		}
	}

	if len(inTypes) > 0 {
		db = db.Where("type IN (?)", inTypes)
	}

	if len(notInTypes) > 0 {
		db = db.Where("type NOT IN (?)", notInTypes)
	}

	return db
}
开发者ID:qor,项目名称:activity,代码行数:22,代码来源:resource.go


示例9: Diff

func (pc *publishController) Diff(context *admin.Context) {
	var (
		resourceID = context.Request.URL.Query().Get(":publish_unique_key")
		params     = strings.Split(resourceID, "__") // name__primary_keys
		res        = context.Admin.GetResource(params[0])
	)

	draft := res.NewStruct()
	pc.search(context.GetDB().Set(publishDraftMode, true), res, [][]string{params[1:]}).First(draft)

	production := res.NewStruct()
	pc.search(context.GetDB().Set(publishDraftMode, false), res, [][]string{params[1:]}).First(production)

	results := map[string]interface{}{"Production": production, "Draft": draft, "Resource": res}
	fmt.Fprintf(context.Writer, string(context.Render("publish_diff", results)))
}
开发者ID:qor,项目名称:publish,代码行数:16,代码来源:controller.go


示例10: 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)
}
开发者ID:qor,项目名称:worker,代码行数:31,代码来源:controller.go


示例11: 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)
}
开发者ID:qor,项目名称:worker,代码行数:25,代码来源:controller.go


示例12: New

func (wc workerController) New(context *admin.Context) {
	context.Execute("new", wc.Worker)
}
开发者ID:qor,项目名称:worker,代码行数:3,代码来源:controller.go


示例13: Show

func (wc workerController) Show(context *admin.Context) {
	job, err := wc.GetJob(context.ResourceID)
	context.AddError(err)
	context.Execute("show", job)
}
开发者ID:qor,项目名称:worker,代码行数:5,代码来源:controller.go


示例14: 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)
	}
}
开发者ID:qor,项目名称:worker,代码行数:15,代码来源:controller.go


示例15: Index

func (controller *i18nController) Index(context *admin.Context) {
	context.Execute("index", controller.I18n)
}
开发者ID:qor,项目名称:i18n,代码行数:3,代码来源:controller.go


示例16: UpdateActivity

func (ctrl controller) UpdateActivity(context *admin.Context) {
	c := context.Admin.NewContext(context.Writer, context.Request)
	c.ResourceID = ctrl.ActivityResource.GetPrimaryValue(context.Request)
	c.Resource = ctrl.ActivityResource
	c.Searcher = &admin.Searcher{Context: c}
	result, err := c.FindOne()

	context.AddError(err)
	if !context.HasError() {
		if context.AddError(c.Resource.Decode(c.Context, result)); !context.HasError() {
			context.AddError(context.Resource.CallSave(result, c.Context))
		}
	}

	redirectTo := context.Request.Referer()
	if context.HasError() {
		context.Writer.WriteHeader(admin.HTTPUnprocessableEntity)
		responder.With("html", func() {
			http.Redirect(context.Writer, context.Request, redirectTo, http.StatusFound)
		}).With("json", func() {
			context.JSON("edit", map[string]interface{}{"errors": context.GetErrors()})
		}).Respond(context.Request)
	} else {
		responder.With("html", func() {
			context.Flash(string(context.Admin.T(context.Context, "activity.successfully_updated", "Activity was successfully updated")), "success")
			http.Redirect(context.Writer, context.Request, redirectTo, http.StatusFound)
		}).With("json", func() {
			c.JSON("show", result)
		}).Respond(context.Request)
	}
}
开发者ID:qor,项目名称:activity,代码行数:31,代码来源:controller.go


示例17: CreateActivity

func (ctrl controller) CreateActivity(context *admin.Context) {
	result, err := context.FindOne()
	activityResource := ctrl.ActivityResource
	newActivity := &QorActivity{}
	if err == nil {
		if context.AddError(activityResource.Decode(context.Context, newActivity)); !context.HasError() {
			context.AddError(CreateActivity(context, newActivity, result))
		}
	}
	context.AddError(err)

	redirectTo := context.Request.Referer()
	if context.HasError() {
		responder.With("html", func() {
			context.Flash(context.Error(), "error")
			http.Redirect(context.Writer, context.Request, redirectTo, http.StatusFound)
		}).With("json", func() {
			context.JSON("edit", map[string]interface{}{"errors": context.GetErrors()})
		}).Respond(context.Request)
	} else {
		responder.With("html", func() {
			context.Flash(string(context.Admin.T(context.Context, "activity.successfully_created", "Activity was successfully created")), "success")
			http.Redirect(context.Writer, context.Request, redirectTo, http.StatusFound)
		}).With("json", func() {
			context.Resource = activityResource
			context.JSON("show", newActivity)
		}).Respond(context.Request)
	}
}
开发者ID:qor,项目名称:activity,代码行数:29,代码来源:controller.go



注:本文中的github.com/qor/admin.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang inflection.Plural函数代码示例发布时间:2022-05-28
下一篇:
Golang utils.PageCheck函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap