Skip to content

Commit

Permalink
Feature/supprt settings page (#877)
Browse files Browse the repository at this point in the history
* settings page frontend create

* support setting page

* version

* add restore

* add restore

* add not display and not inited

* delete unused code

* update example

* add report

* fix bug

* update example

---------

Co-authored-by: noO0ob <[email protected]>
  • Loading branch information
noO0oOo0ob and noO0ob authored Nov 11, 2024
1 parent 86f949a commit 7664463
Show file tree
Hide file tree
Showing 17 changed files with 1,243 additions and 6 deletions.
29 changes: 29 additions & 0 deletions frontend/src/api/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,32 @@ export const updateConfigByKey = (data) => {
method: 'PATCH'
})
}

export const getSettingModelList = () => {
return axios({
url: '/api/settings/list',
method: 'GET'
})
}

export const getSettingsForm = (name) => {
return axios({
url: '/api/settings/detail?name='+name,
method: 'GET'
})
}

export const setSettingsForm = (name, data) => {
return axios({
url: '/api/settings?name='+name,
data: { data },
method: 'POST'
})
}

export const restoreSettingsForm = (name) => {
return axios({
url: '/api/settings?name='+name,
method: 'DELETE'
})
}
12 changes: 12 additions & 0 deletions frontend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DataManager from './views/datamanager/DataManager.vue'
import Checker from './views/checker/Checker.vue'
import EventInspector from '@/views/event/EventInspector.vue'
import PluginView from './views/PluginView.vue'
import Settings from './views/settings/Settings.vue'

//vue router error handler
const originalPush = Router.prototype.push
Expand Down Expand Up @@ -77,6 +78,17 @@ export default new Router({
},
],
},
{
path: '/settings',
component: Main,
children: [
{
path: '',
name: 'settings',
component: Settings,
},
],
},
{
path: '/plugin',
name: 'plugin',
Expand Down
59 changes: 55 additions & 4 deletions frontend/src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export default {
state: {
config: {},
initialized: false,
preLoadFuncSet: new Set()
preLoadFuncSet: new Set(),
focusSettingPanel: '',
settingsList: [],
settingsCurrentDetail: {},
},
mutations: {
setConfig (state, config) {
Expand All @@ -42,7 +45,16 @@ export default {
},
deletePreLoadFuncSet (state, preLoadFunc) {
state.preLoadFuncSet.delete(preLoadFunc)
}
},
setSettingsList(state, data) {
state.settingsList = data
},
setSettingsCurrentDetail(state, data) {
state.settingsCurrentDetail = data
},
setFocusSettingPanel(state, data) {
state.focusSettingPanel = data
},
},
actions: {
loadConfig({ state, commit, dispatch }) {
Expand Down Expand Up @@ -98,6 +110,45 @@ export default {
.catch(error => {
bus.$emit('msg.error', `Update config failed ${error.data.message}`)
})
}
}
},
loadSettingsList({ state, commit, dispatch }) {
api.getSettingModelList()
.then(response => {
console.log(response.data.data)
commit('setSettingsList', response.data.data)
})
.catch(error => {
bus.$emit('msg.error', 'Load config failed ' + error.data.message)
})
},
loadSettingsForm({ state, commit, dispatch }, payload) {
api.getSettingsForm(payload)
.then(response => {
commit('setSettingsCurrentDetail', response.data.data)
})
.catch(error => {
bus.$emit('msg.error', 'Load config failed ' + error.data.message)
})
},
saveSettingsForm({ state, commit, dispatch }, { formName, formData }) {
api.setSettingsForm(formName, formData)
.then(response => {
dispatch('loadSettingsForm', formName)
bus.$emit('msg.success', 'Data ' + formName + ' update!')
})
.catch(error => {
bus.$emit('msg.error', 'Data ' + formName + ' update error: ' + error.data.message)
})
},
restoreSettingsForm({ state, commit, dispatch }, payload) {
api.restoreSettingsForm(payload)
.then(response => {
dispatch('loadSettingsForm', payload)
bus.$emit('msg.success', 'Data ' + payload + ' update!')
})
.catch(error => {
bus.$emit('msg.error', 'Data ' + payload + ' update error: ' + error.data.message)
})
},
},
}
Loading

0 comments on commit 7664463

Please sign in to comment.