func (ctl *ConfigurationController) postEditConfigurationAction(c *gin.Context) {

	appId := c.Param("app_id")
	configId := c.Param("config_id")

	application := ctl.getApplication(c, appId)
	if application == nil {
		return
	}

	config := ctl.getConfig(c, application, configId)
	if config == nil {
		return
	}

	var form models.ConfigUpdateForm
	if err := c.Bind(&form); err != nil {
		c.AbortWithStatus(http.StatusBadRequest)
		return
	}

	// Workaround for bool field, because http form only send string
	// The value is "on" for true, and "" for false
	form.Enabled = c.PostForm("enabled") == "on"

	if err := form.Validate(); err != nil {
		c.HTML(http.StatusOK, "configuration_edit.html", map[string]interface{}{
			"errors":      err.Errors,
			"application": application,
			"form":        form,
		})
		return
	}

	config.Update(&form)

	if err := models.ConfigMapper.Update(config); err != nil {
		panic(err)
	}

	c.Redirect(http.StatusFound, "/application/show/"+application.Name)
}
示例#2
0
func (cc *ConfigController) putConfig(c *gin.Context) {

	app, err := cc.getApp(c)
	if err != nil {
		c.JSON(http.StatusNotFound, err)
		return
	}

	configId := c.Param("config_id")

	config, err := models.ConfigMapper.FetchOne(app, configId)
	if err != nil {
		panic(err)
	}

	if config == nil {
		c.JSON(http.StatusNotFound, config)
		return
	}

	var form models.ConfigUpdateForm
	if err := c.Bind(&form); err != nil {
		c.AbortWithStatus(http.StatusBadRequest)
		return
	}

	if err := form.Validate(); err != nil {
		c.JSON(http.StatusBadRequest, err)
		return
	}

	config.Update(&form)

	if err := models.ConfigMapper.Update(config); err != nil {
		panic(err)
	}

	c.JSON(http.StatusOK, config)
}
func (ctl *ConfigurationController) getEditConfigurationAction(c *gin.Context) {

	appId := c.Param("app_id")
	configId := c.Param("config_id")

	application := ctl.getApplication(c, appId)
	if application == nil {
		return
	}

	config := ctl.getConfig(c, application, configId)
	if config == nil {
		return
	}

	// Hydrate the form
	var form models.ConfigUpdateForm
	form.Hydrate(config)

	c.HTML(http.StatusOK, "configuration_edit.html", map[string]interface{}{
		"application": application,
		"form":        form,
	})
}