Example #1
0
func parseApplicationByID(ctx *context.Context) *models.Application {
	app, err := models.GetApplicationByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if errors.IsApplicationNotFound(err) {
			ctx.Handle(404, "EditApplication", nil)
		} else {
			ctx.Handle(500, "GetApplicationByID", err)
		}
		return nil
	}
	ctx.Data["Application"] = app
	return app
}
Example #2
0
func Applications(ctx *context.Context) {
	ctx.Data["Title"] = "Applications"
	ctx.Data["PageIsApplication"] = true

	apps, err := models.ListApplications()
	if err != nil {
		ctx.Handle(500, "ListApplications", err)
		return
	}
	ctx.Data["Applications"] = apps

	ctx.HTML(200, "application/list")
}
Example #3
0
func parseCollectorByID(ctx *context.Context) *models.Collector {
	collector, err := models.GetCollectorByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if errors.IsCollectorNotFound(err) {
			ctx.Handle(404, "EditApplication", nil)
		} else {
			ctx.Handle(500, "GetCollectorByID", err)
		}
		return nil
	}
	ctx.Data["Collector"] = collector
	return collector
}
Example #4
0
func ViewWebhook(ctx *context.Context) {
	ctx.Data["Title"] = "View Webhook"
	ctx.Data["PageIsWebhook"] = true
	ctx.Data["RequireHighlightJS"] = true

	webhook, err := models.GetWebhookByID(ctx.ParamsInt64(":id"))
	if err != nil {
		if errors.IsWebhookNotFound(err) {
			ctx.Handle(404, "GetWebhookByID", nil)
		} else {
			ctx.Handle(500, "GetWebhookByID", err)
		}
		return
	}
	ctx.Data["Webhook"] = webhook

	// Prettify JSON in case it is not.
	buf := new(bytes.Buffer)
	if err = json.Indent(buf, []byte(webhook.Payload), "", "  "); err != nil {
		ctx.Handle(500, "json.Indent", err)
		return
	}
	webhook.Payload = buf.String()

	ctx.HTML(200, "webhook/view")
}
Example #5
0
func NewApplicationPost(ctx *context.Context, form NewApplicationForm) {
	ctx.Data["Title"] = "New Application"
	ctx.Data["PageIsApplication"] = true

	if ctx.HasError() {
		ctx.HTML(200, "application/new")
		return
	}

	app, err := models.NewApplication(form.Name)
	if err != nil {
		if errors.IsApplicationExists(err) {
			ctx.Data["Err_Name"] = true
			ctx.RenderWithErr("Application name has been used.", "application/new", form)
		} else {
			ctx.Handle(500, "NewApplication", err)
		}
		return
	}

	ctx.Redirect(fmt.Sprintf("/applications/%d", app.ID))
}
Example #6
0
func NewCollectorPost(ctx *context.Context, form NewCollectorForm) {
	ctx.Data["Title"] = "New Collector"
	ctx.Data["PageIsCollector"] = true

	if ctx.HasError() {
		ctx.HTML(200, "collector/new")
		return
	}

	collector, err := models.NewCollector(form.Name, models.COLLECT_TYPE_GITHUB)
	if err != nil {
		if errors.IsCollectorExists(err) {
			ctx.Data["Err_Name"] = true
			ctx.RenderWithErr("Collector name has been used.", "collector/new", form)
		} else {
			ctx.Handle(500, "NewCollector", err)
		}
		return
	}

	ctx.Redirect(fmt.Sprintf("/collectors/%d", collector.ID))
}