feat: store last gcode commands in moonraker db (#460)
* feat: add console gcode history in moonraker db Signed-off-by: Stefan Dej <meteyou@gmail.com>
This commit is contained in:
1 parent
945a3f8eaf
commit
1298da15f2
13 files changed
+111
-6
No files matched your search
@@ -107,7 +107,6 @@ export default class MiniconsolePanel extends Mixins(BaseMixin) {
|
||||
}
|
||||
|
||||
private gcode = ''
|
||||
private lastCommands: string[] = []
|
||||
private lastCommandNumber: number | null = null
|
||||
private items = [];
|
||||
private cmdListSearch: string | null = null
|
||||
@@ -162,6 +161,10 @@ export default class MiniconsolePanel extends Mixins(BaseMixin) {
|
||||
return this.gcode?.split('\n').length ?? 1
|
||||
}
|
||||
|
||||
get lastCommands(): string[] {
|
||||
return this.$store.state.gui.gcodehistory.history ?? []
|
||||
}
|
||||
|
||||
commandClick(msg: string): void {
|
||||
this.gcode = msg
|
||||
|
||||
@@ -174,7 +177,7 @@ export default class MiniconsolePanel extends Mixins(BaseMixin) {
|
||||
if (!cmd.shiftKey) {
|
||||
if (this.gcode !== '') {
|
||||
this.$store.dispatch('printer/sendGcode', this.gcode)
|
||||
this.lastCommands.push(this.gcode)
|
||||
this.$store.dispatch('gui/gcodehistory/addToHistory', this.gcode)
|
||||
this.gcode = ''
|
||||
this.lastCommandNumber = null
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -50,6 +50,13 @@
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.mainsail_gcodehistory"
|
||||
:label="$t('Settings.GeneralTab.DbGcodehistry')"
|
||||
v-if="moonrakerDbNamespaces.includes('mainsail_gcodehistory')"
|
||||
hide-details
|
||||
class="mt-0"
|
||||
></v-checkbox>
|
||||
<v-checkbox
|
||||
v-model="dbCheckboxes.mainsail_macrogroups"
|
||||
:label="$t('Settings.GeneralTab.DbMacrogroups')"
|
||||
@@ -127,6 +134,7 @@ export default class SettingsGeneralTab extends Mixins(BaseMixin) {
|
||||
private dbCheckboxes = {
|
||||
mainsail: false,
|
||||
mainsail_presets: false,
|
||||
mainsail_gcodehistory: false,
|
||||
mainsail_macrogroups: false,
|
||||
mainsail_remoteprinters: false,
|
||||
timelapse: false,
|
||||
|
||||
@@ -607,6 +607,7 @@
|
||||
"Reset": "reset",
|
||||
"DbGeneral": "General",
|
||||
"DbPresets": "Presets",
|
||||
"DbGcodehistry": "G-Code History",
|
||||
"DbMacrogroups": "Macrogroups",
|
||||
"DbRemoteprinters": "Remoteprinters",
|
||||
"DbHistoryJobs": "History Jobs",
|
||||
|
||||
@@ -95,7 +95,6 @@ import CommandHelpModal from '@/components/CommandHelpModal.vue'
|
||||
})
|
||||
export default class PageConsole extends Mixins(BaseMixin) {
|
||||
private gcode = ''
|
||||
private lastCommands: string[] = []
|
||||
private lastCommandNumber: number | null = null
|
||||
private items = []
|
||||
|
||||
@@ -150,6 +149,10 @@ export default class PageConsole extends Mixins(BaseMixin) {
|
||||
return this.$store.state.gui.console.customFilters
|
||||
}
|
||||
|
||||
get lastCommands(): string[] {
|
||||
return this.$store.state.gui.gcodehistory.history ?? []
|
||||
}
|
||||
|
||||
commandClick(msg: string): void {
|
||||
this.gcode = msg
|
||||
|
||||
@@ -162,7 +165,7 @@ export default class PageConsole extends Mixins(BaseMixin) {
|
||||
if (!cmd.shiftKey) {
|
||||
if (this.gcode !== '') {
|
||||
this.$store.dispatch('printer/sendGcode', this.gcode)
|
||||
this.lastCommands.push(this.gcode)
|
||||
this.$store.dispatch('gui/gcodehistory/addToHistory', this.gcode)
|
||||
this.gcode = ''
|
||||
this.lastCommandNumber = null
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { ActionTree } from 'vuex'
|
||||
import {RootState} from '@/store/types'
|
||||
import Vue from 'vue'
|
||||
import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
|
||||
import {maxGcodeHistory} from '@/store/variables'
|
||||
|
||||
export const actions: ActionTree<GuiGcodehistoryState, RootState> = {
|
||||
reset({ commit }) {
|
||||
commit('reset')
|
||||
},
|
||||
|
||||
init() {
|
||||
window.console.debug('init gui/gcodehistory')
|
||||
Vue.$socket.emit('server.database.get_item', { namespace: 'mainsail_gcodehistory' }, { action: 'gui/gcodehistory/initStore' })
|
||||
},
|
||||
|
||||
initStore({ commit }, payload) {
|
||||
commit('reset')
|
||||
commit('initStore', payload)
|
||||
},
|
||||
|
||||
upload({ state }) {
|
||||
Vue.$socket.emit('server.database.post_item', { namespace: 'mainsail_gcodehistory', key: 'history', value: state.history })
|
||||
},
|
||||
|
||||
async addToHistory({ commit, dispatch, state }, payload) {
|
||||
const newHistory = [...state.history]
|
||||
newHistory.push(payload)
|
||||
|
||||
while (newHistory.length > maxGcodeHistory) newHistory.splice(0, 1)
|
||||
|
||||
await commit('updateHistory', newHistory)
|
||||
await dispatch('upload')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
|
||||
|
||||
// eslint-disable-next-line
|
||||
export const getters: GetterTree<GuiGcodehistoryState, any> = {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Module } from 'vuex'
|
||||
import { actions } from '@/store/gui/gcodehistory/actions'
|
||||
import { mutations } from '@/store/gui/gcodehistory/mutations'
|
||||
import { getters } from '@/store/gui/gcodehistory/getters'
|
||||
import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
|
||||
|
||||
export const getDefaultState = (): GuiGcodehistoryState => {
|
||||
return {
|
||||
history: [],
|
||||
}
|
||||
}
|
||||
|
||||
// initial state
|
||||
const state = getDefaultState()
|
||||
|
||||
// eslint-disable-next-line
|
||||
export const gcodehistory: Module<GuiGcodehistoryState, any> = {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { getDefaultState } from './index'
|
||||
import {MutationTree} from 'vuex'
|
||||
import Vue from 'vue'
|
||||
import {GuiGcodehistoryState} from '@/store/gui/gcodehistory/types'
|
||||
|
||||
export const mutations: MutationTree<GuiGcodehistoryState> = {
|
||||
reset(state) {
|
||||
Object.assign(state, getDefaultState())
|
||||
},
|
||||
|
||||
initStore(state, payload) {
|
||||
Vue.set(state, 'history', payload.value?.history)
|
||||
},
|
||||
|
||||
updateHistory(state, payload) {
|
||||
Vue.set(state, 'history', payload)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface GuiGcodehistoryState {
|
||||
history: string[]
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import {defaultLogoColor, defaultPrimaryColor} from '@/store/variables'
|
||||
|
||||
// load modules
|
||||
import { consolefilters } from '@/store/gui/consolefilters'
|
||||
import { gcodehistory } from '@/store/gui/gcodehistory'
|
||||
import { macrogroups } from '@/store/gui/macrogroups'
|
||||
import { presets } from '@/store/gui/presets'
|
||||
import { remoteprinters } from '@/store/gui/remoteprinters'
|
||||
@@ -224,6 +225,7 @@ export const gui: Module<GuiState, any> = {
|
||||
mutations,
|
||||
modules: {
|
||||
consolefilters,
|
||||
gcodehistory,
|
||||
macrogroups,
|
||||
presets,
|
||||
remoteprinters,
|
||||
|
||||
@@ -27,6 +27,7 @@ export const actions: ActionTree<ServerState, RootState> = {
|
||||
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 })
|
||||
if (payload.namespaces?.includes('mainsail_consolefilters')) dispatch('gui/consolefilters/init', null, { root: true })
|
||||
if (payload.namespaces?.includes('mainsail_gcodehistory')) dispatch('gui/gcodehistory/init', null, { root: true })
|
||||
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 })
|
||||
|
||||
|
||||
@@ -97,10 +97,10 @@ export const mutations: MutationTree<ServerState> = {
|
||||
},
|
||||
|
||||
setThrottledState(state, payload) {
|
||||
if ('bits' in payload)
|
||||
if (payload && 'bits' in payload)
|
||||
Vue.set(state.throttled_state, 'bits', payload.bits)
|
||||
|
||||
if ('flags' in payload)
|
||||
if (payload && 'flags' in payload)
|
||||
Vue.set(state.throttled_state, 'flags', payload.flags)
|
||||
},
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ export const allowedMetadata = [
|
||||
]
|
||||
|
||||
export const maxEventHistory = 500
|
||||
export const maxGcodeHistory = 50
|
||||
|
||||
export const allDashboardPanels = [
|
||||
'control',
|
||||
|
||||
Reference in new issue
Block a user