fix save settings
This commit is contained in:
+7
-1
@@ -144,7 +144,7 @@ func (a *APIHandler) getHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
jsonObj(c, *users, nil)
|
jsonObj(c, *users, nil)
|
||||||
case "setting":
|
case "settings":
|
||||||
data, err := a.SettingService.GetAllSetting()
|
data, err := a.SettingService.GetAllSetting()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonMsg(c, "", err)
|
jsonMsg(c, "", err)
|
||||||
@@ -298,6 +298,12 @@ func (a *APIHandler) loadPartialData(c *gin.Context, objs []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
data[obj] = json.RawMessage(config)
|
data[obj] = json.RawMessage(config)
|
||||||
|
case "settings":
|
||||||
|
settings, err := a.SettingService.GetAllSetting()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = settings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, login
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = s.restartCoreWithConfig(data)
|
err = s.restartCoreWithConfig(data)
|
||||||
|
case "settings":
|
||||||
|
err = s.SettingService.Save(tx, data)
|
||||||
default:
|
default:
|
||||||
return nil, common.NewError("unknown object: ", obj)
|
return nil, common.NewError("unknown object: ", obj)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,13 +351,14 @@ func (s *SettingService) SaveConfig(tx *gorm.DB, config json.RawMessage) error {
|
|||||||
return tx.Model(model.Setting{}).Where("key = ?", "config").Update("value", string(configs)).Error
|
return tx.Model(model.Setting{}).Where("key = ?", "config").Update("value", string(configs)).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SettingService) Save(tx *gorm.DB, changes []model.Changes) error {
|
func (s *SettingService) Save(tx *gorm.DB, data json.RawMessage) error {
|
||||||
var err error
|
var err error
|
||||||
for _, change := range changes {
|
var settings map[string]string
|
||||||
key := change.Key
|
err = json.Unmarshal(data, &settings)
|
||||||
var obj string
|
if err != nil {
|
||||||
json.Unmarshal(change.Obj, &obj)
|
return err
|
||||||
|
}
|
||||||
|
for key, obj := range settings {
|
||||||
// Secure file existance check
|
// Secure file existance check
|
||||||
if obj != "" && (key == "webCertFile" ||
|
if obj != "" && (key == "webCertFile" ||
|
||||||
key == "webKeyFile" ||
|
key == "webKeyFile" ||
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<v-card-text>
|
<v-card-text>
|
||||||
<v-row align="center" justify="center" style="margin-bottom: 10px;">
|
<v-row align="center" justify="center" style="margin-bottom: 10px;">
|
||||||
<v-col cols="auto">
|
<v-col cols="auto">
|
||||||
<v-btn color="primary" @click="saveChanges" :loading="loading" :disabled="!stateChange">
|
<v-btn color="primary" @click="save" :loading="loading" :disabled="!stateChange">
|
||||||
{{ $t('actions.save') }}
|
{{ $t('actions.save') }}
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -152,11 +152,12 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useLocale } from 'vuetify'
|
import { useLocale } from 'vuetify'
|
||||||
import { languages } from '@/locales'
|
import { i18n, languages } from '@/locales'
|
||||||
import { Ref, computed, inject, onMounted, ref } from 'vue'
|
import { Ref, computed, inject, onMounted, ref } from 'vue'
|
||||||
import HttpUtils from '@/plugins/httputil'
|
import HttpUtils from '@/plugins/httputil'
|
||||||
import { FindDiff } from '@/plugins/utils'
|
import { FindDiff } from '@/plugins/utils'
|
||||||
import SubJsonExtVue from '@/components/SubJsonExt.vue'
|
import SubJsonExtVue from '@/components/SubJsonExt.vue'
|
||||||
|
import { push } from 'notivue'
|
||||||
const locale = useLocale()
|
const locale = useLocale()
|
||||||
const tab = ref("t1")
|
const tab = ref("t1")
|
||||||
const loading:Ref = inject('loading')?? ref(false)
|
const loading:Ref = inject('loading')?? ref(false)
|
||||||
@@ -195,22 +196,28 @@ const changeLocale = (l: any) => {
|
|||||||
|
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const msg = await HttpUtils.get('api/setting')
|
const msg = await HttpUtils.get('api/settings')
|
||||||
loading.value = false
|
loading.value = false
|
||||||
if (msg.success) {
|
if (msg.success) {
|
||||||
settings.value = msg.obj
|
setData(msg.obj)
|
||||||
oldSettings.value = { ...msg.obj }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveChanges = async () => {
|
const setData = (data: any) => {
|
||||||
loading.value = true
|
settings.value = data
|
||||||
const diff = {
|
oldSettings.value = { ...data }
|
||||||
settings: JSON.stringify(FindDiff.Settings(settings.value,oldSettings.value)),
|
|
||||||
}
|
}
|
||||||
const msg = await HttpUtils.post('api/save', diff)
|
|
||||||
|
const save = async () => {
|
||||||
|
loading.value = true
|
||||||
|
const msg = await HttpUtils.post('api/save', { object: 'settings', action: 'set', data: JSON.stringify(settings.value) })
|
||||||
if (msg.success) {
|
if (msg.success) {
|
||||||
loadData()
|
push.success({
|
||||||
|
title: i18n.global.t('success'),
|
||||||
|
duration: 5000,
|
||||||
|
message: i18n.global.t('actions.set') + " " + i18n.global.t('pages.settings')
|
||||||
|
})
|
||||||
|
setData(msg.obj.settings)
|
||||||
}
|
}
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user