feat: reset database namespaces and/or history jobs/totals
Signed-off-by: Stefan Dej <meteyou@gmail.com>
This commit is contained in:
1 parent
de673810c3
commit
08b60c0072
8 files changed
+153
-48
No files matched your search
@@ -23,39 +23,83 @@
|
||||
</settings-row>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
<v-dialog v-model="dialogResetMainsail" persistent :width="300">
|
||||
<v-card dark>
|
||||
<v-toolbar flat dense color="primary">
|
||||
<v-toolbar-title>
|
||||
<span class="subheading">
|
||||
<v-icon class="mdi mdi-help-circle" left></v-icon> {{ $t('Settings.GeneralTab.FactoryReset') }}
|
||||
</span>
|
||||
</v-toolbar-title>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn small class="minwidth-0" @click="dialogResetMainsail = false"><v-icon small>mdi-close-thick</v-icon></v-btn>
|
||||
</v-toolbar>
|
||||
<v-card-text class="pt-3">
|
||||
<v-container class="pb-0">
|
||||
|
||||
<v-row>
|
||||
<v-col>
|
||||
<p class="text-center mb-0">{{ $t('Settings.GeneralTab.FactoryInfo') }}</p>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<v-row>
|
||||
<v-col class="text-center">
|
||||
<v-btn
|
||||
color="red"
|
||||
@click="resetMainsail"
|
||||
>
|
||||
{{ $t('Settings.GeneralTab.ResetMainsail') }}
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
<v-dialog v-model="dialogResetMainsail" persistent :width="360">
|
||||
<panel :title="$t('Settings.GeneralTab.FactoryReset')" card-class="ractory-reset-dialog" :margin-bottom="false" icon="mdi-help-circle">
|
||||
<template v-slot:buttons>
|
||||
<v-btn icon tile @click="dialogResetMainsail = false"><v-icon>mdi-close-thick</v-icon></v-btn>
|
||||
</template>
|
||||
<v-card-text>
|
||||
<v-row>
|
||||
<v-col>
|
||||
<p class="mb-0">{{ $t('Settings.GeneralTab.FactoryDialog') }}</p>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row>
|
||||
<v-col class="pl-6">
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.mainsail"
|
||||
:label="$t('Settings.GeneralTab.DbGeneral')"
|
||||
v-if="moonrakerDbNamespaces.includes('mainsail')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.mainsail_presets"
|
||||
:label="$t('Settings.GeneralTab.DbPresets')"
|
||||
v-if="moonrakerDbNamespaces.includes('mainsail_presets')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.mainsail_macrogroups"
|
||||
:label="$t('Settings.GeneralTab.DbMacrogroups')"
|
||||
v-if="moonrakerDbNamespaces.includes('mainsail_macrogroups')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.mainsail_remoteprinters"
|
||||
:label="$t('Settings.GeneralTab.DbRemoteprinters')"
|
||||
v-if="moonrakerDbNamespaces.includes('mainsail_remoteprinters')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.webcams"
|
||||
:label="$t('Settings.GeneralTab.DbWebcams')"
|
||||
v-if="moonrakerDbNamespaces.includes('webcams')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.history_jobs"
|
||||
:label="$t('Settings.GeneralTab.DbHistoryJobs')"
|
||||
v-if="moonrakerComponents.includes('history')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.history_totals"
|
||||
:label="$t('Settings.GeneralTab.DbHistoryTotals')"
|
||||
v-if="moonrakerComponents.includes('history')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row>
|
||||
<v-col class="text-center">
|
||||
<v-btn
|
||||
color="red"
|
||||
@click="resetMainsail"
|
||||
:loading="dialogResetMainsailLoading"
|
||||
>
|
||||
{{ $t('Settings.GeneralTab.Reset') }}
|
||||
</v-btn>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</panel>
|
||||
</v-dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -66,11 +110,21 @@ import Component from 'vue-class-component'
|
||||
import { Mixins } from 'vue-property-decorator'
|
||||
import BaseMixin from '@/components/mixins/base'
|
||||
import SettingsRow from '@/components/settings/SettingsRow.vue'
|
||||
import Panel from '@/components/ui/Panel.vue'
|
||||
@Component({
|
||||
components: {SettingsRow}
|
||||
components: {Panel, SettingsRow}
|
||||
})
|
||||
export default class SettingsGeneralTab extends Mixins(BaseMixin) {
|
||||
private dialogResetMainsail = false
|
||||
private dialogResetMainsailLoading = false
|
||||
private dbCheckboxes = {
|
||||
mainsail: false,
|
||||
mainsail_presets: false,
|
||||
mainsail_macrogroups: false,
|
||||
mainsail_remoteprinters: false,
|
||||
history_jobs: false,
|
||||
history_totals: false,
|
||||
}
|
||||
|
||||
get printerName() {
|
||||
return this.$store.state.gui.general.printername
|
||||
@@ -136,9 +190,17 @@ export default class SettingsGeneralTab extends Mixins(BaseMixin) {
|
||||
this.$store.dispatch('gui/saveSetting', {name: 'general.calcEtaTime', value: newVal })
|
||||
}
|
||||
|
||||
get moonrakerDbNamespaces() {
|
||||
return this.$store.state.server.dbNamespaces ?? []
|
||||
}
|
||||
|
||||
get moonrakerComponents() {
|
||||
return this.$store.state.server.components ?? []
|
||||
}
|
||||
|
||||
resetMainsail() {
|
||||
this.$store.dispatch('gui/resetMoonrakerDB')
|
||||
this.dialogResetMainsail = false
|
||||
this.$store.dispatch('gui/resetMoonrakerDB', this.dbCheckboxes)
|
||||
this.dialogResetMainsailLoading = true
|
||||
}
|
||||
}
|
||||
</script>
|
||||
+9
-2
@@ -521,8 +521,15 @@
|
||||
"CalcEtaTime": "ETA calculation",
|
||||
"CalcEtaTimeDescription": "If multiple are selected, an average will be calculated",
|
||||
"FactoryReset": "Factory reset",
|
||||
"FactoryInfo": "Do you really want to reset mainsail to factory settings?",
|
||||
"ResetMainsail": "reset mainsail"
|
||||
"FactoryDialog": "Please select all the sections you want to reset:",
|
||||
"Reset": "reset",
|
||||
"DbGeneral": "General",
|
||||
"DbPresets": "Presets",
|
||||
"DbMacrogroups": "Macrogroups",
|
||||
"DbRemoteprinters": "Remoteprinters",
|
||||
"DbHistoryJobs": "History Jobs",
|
||||
"DbHistoryTotals": "History Totals",
|
||||
"DbWebcams": "Webcams"
|
||||
},
|
||||
"WebcamsTab": {
|
||||
"Webcams": "Webcams",
|
||||
|
||||
+21
-10
@@ -168,24 +168,35 @@ export const actions: ActionTree<GuiState, RootState> = {
|
||||
})
|
||||
},
|
||||
|
||||
resetMoonrakerDB() {
|
||||
Vue.$socket.emit('server.database.list', { }, { action: 'gui/resetMoonrakerDB2' })
|
||||
async resetMoonrakerDB({ commit, dispatch }, payload) {
|
||||
await commit('setResetDatabases', payload)
|
||||
dispatch('resetMoonrakerDbLoop')
|
||||
},
|
||||
|
||||
resetMoonrakerDB2(_, payload) {
|
||||
if ('namespaces' in payload && payload.namespaces.includes('mainsail')) {
|
||||
Vue.$socket.emit('server.database.get_item', { namespace: 'mainsail' }, { action: 'gui/resetMoonrakerDB3' })
|
||||
}
|
||||
async resetMoonrakerDbLoop({ state, commit }) {
|
||||
if (state.resetDatabases.length) {
|
||||
const namespace = state.resetDatabases[0]
|
||||
|
||||
if (namespace.startsWith('mainsail') || namespace === 'webcams') {
|
||||
Vue.$socket.emit('server.database.get_item', { namespace: namespace }, { action: 'gui/resetMoonrakerDbLoopItems' })
|
||||
} else if (namespace === 'history_jobs') {
|
||||
Vue.$socket.emit('server.history.delete_job', { all: true }, { action: 'gui/resetMoonrakerDbLoopItems' })
|
||||
} else if (namespace === 'history_totals') {
|
||||
Vue.$socket.emit('server.history.reset_totals', { }, { action: 'gui/resetMoonrakerDbLoopItems' })
|
||||
}
|
||||
|
||||
await commit('removeResetDatabase', namespace)
|
||||
} else window.location.reload()
|
||||
},
|
||||
|
||||
resetMoonrakerDB3(_, payload) {
|
||||
resetMoonrakerDbLoopItems({ dispatch }, payload) {
|
||||
if ('value' in payload && Object.keys(payload.value).length) {
|
||||
Object.keys(payload.value).forEach(key => {
|
||||
Vue.$socket.emit('server.database.delete_item', { namespace: 'mainsail', key: key })
|
||||
Vue.$socket.emit('server.database.delete_item', { namespace: payload.namespace, key: key })
|
||||
})
|
||||
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
dispatch('resetMoonrakerDbLoop')
|
||||
},
|
||||
|
||||
setHistoryColumns({ commit, dispatch, state }, data) {
|
||||
|
||||
@@ -105,5 +105,22 @@ export const mutations: MutationTree<GuiState> = {
|
||||
|
||||
toggleHideUploadAndPrintBtn(state, payload) {
|
||||
Vue.set(state.dashboard, 'boolHideUploadAndPrintButton', payload)
|
||||
},
|
||||
|
||||
setResetDatabases(state, payload) {
|
||||
const array: string[] = []
|
||||
Object.keys(payload).forEach((element) => {
|
||||
if (payload[element] === true) array.push(element)
|
||||
})
|
||||
|
||||
Vue.set(state, 'resetDatabases', array)
|
||||
},
|
||||
|
||||
removeResetDatabase(state, payload) {
|
||||
const array = [...state.resetDatabases]
|
||||
const index = array.findIndex((element) => element === payload)
|
||||
if (index !== -1) array.splice(index, 1)
|
||||
|
||||
Vue.set(state, 'resetDatabases', array)
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export const actions: ActionTree<ServerState, RootState> = {
|
||||
Vue.$socket.emit('server.database.list', { root: 'config' }, { action: 'server/checkDatabases'})
|
||||
},
|
||||
|
||||
checkDatabases({ dispatch, rootState }, payload) {
|
||||
checkDatabases({ dispatch, commit, rootState }, payload) {
|
||||
if (payload.namespaces?.includes('mainsail')) dispatch('gui/init', null, { root: true })
|
||||
if (payload.namespaces?.includes('webcams')) dispatch('gui/webcams/init', null, { root: true })
|
||||
if (payload.namespaces?.includes('mainsail_presets')) dispatch('gui/presets/init', null, { root: true })
|
||||
@@ -30,6 +30,8 @@ export const actions: ActionTree<ServerState, RootState> = {
|
||||
if (payload.namespaces?.includes('mainsail_macrogroups')) dispatch('gui/macrogroups/init', null, { root: true })
|
||||
if (!rootState.socket?.remoteMode && payload.namespaces?.includes('mainsail_remoteprinters')) dispatch('gui/remoteprinters/init', null, { root: true })
|
||||
|
||||
commit('saveDbNamespaces', payload.namespaces)
|
||||
|
||||
dispatch('printer/init', null, { root: true })
|
||||
},
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ export const getDefaultState = (): ServerState => {
|
||||
bits: 0,
|
||||
flags: [],
|
||||
},
|
||||
dbNamespaces: [],
|
||||
websocket_count: 0,
|
||||
moonraker_version: ''
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ export const mutations: MutationTree<ServerState> = {
|
||||
})
|
||||
},
|
||||
|
||||
saveDbNamespaces(state, payload) {
|
||||
Vue.set(state, 'dbNamespaces', payload)
|
||||
},
|
||||
|
||||
setConfig(state, payload) {
|
||||
Object.entries(payload.config).forEach(([key, value]) => {
|
||||
Vue.set(state.config, key, value)
|
||||
|
||||
@@ -33,6 +33,7 @@ export interface ServerState {
|
||||
bits: number
|
||||
flags: string[]
|
||||
},
|
||||
dbNamespaces: string[]
|
||||
websocket_count: number
|
||||
moonraker_version: string
|
||||
|
||||
|
||||
Reference in new issue
Block a user