Display settings with hacky solution to retain order

Python utility included to convert config-base.json into a new version
which includes lists that define the order settings should be displayed.
admin.js edited to recognize this.
This commit is contained in:
Harvey Tindall
2020-07-31 16:09:30 +01:00
parent ef4f2503c9
commit 024c0b56aa
9 changed files with 811 additions and 20 deletions
+33
View File
@@ -461,3 +461,36 @@ func (ctx *appContext) SetDefaults(gc *gin.Context) {
}
gc.JSON(200, map[string]bool{"success": true})
}
func (ctx *appContext) GetConfig(gc *gin.Context) {
resp := map[string]interface{}{}
for section, settings := range ctx.configBase {
if section == "order" {
resp[section] = settings.([]interface{})
} else {
resp[section] = make(map[string]interface{})
for key, values := range settings.(map[string]interface{}) {
if key == "order" {
resp[section].(map[string]interface{})[key] = values.([]interface{})
} else {
resp[section].(map[string]interface{})[key] = values.(map[string]interface{})
if key != "meta" {
fmt.Println(resp[section].(map[string]interface{})[key].(map[string]interface{}))
dataType := resp[section].(map[string]interface{})[key].(map[string]interface{})["type"].(string)
configKey := ctx.config.Section(section).Key(key)
if dataType == "number" {
if val, err := configKey.Int(); err == nil {
resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = val
}
} else if dataType == "bool" {
resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = configKey.MustBool(false)
} else {
resp[section].(map[string]interface{})[key].(map[string]interface{})["value"] = configKey.String()
}
}
}
}
}
}
gc.JSON(200, resp)
}