refactor: move macrogroups to own moonraker db namespace and create a sub module of gui store
Signed-off-by: Stefan Dej <meteyou@gmail.com>
This commit is contained in:
1 parent
8ded071403
commit
6597c9cdc2
15 files changed
+265
-187
No files matched your search
@@ -68,7 +68,7 @@
|
||||
import Component from 'vue-class-component'
|
||||
import {Mixins, Prop, Watch} from 'vue-property-decorator'
|
||||
import BaseMixin from '@/components/mixins/base'
|
||||
import {GuiStateMacrogroupMacros} from '@/store/gui/types'
|
||||
import {GuiMacrogroupsStateMacrogroupMacro} from '@/store/gui/macrogroups/types'
|
||||
|
||||
interface param {
|
||||
type: 'int' | 'double' | 'string' | null,
|
||||
@@ -85,7 +85,7 @@ export default class MacroButton extends Mixins(BaseMixin) {
|
||||
private paramArray: string[] = []
|
||||
private params: params = {}
|
||||
|
||||
@Prop({ required: true }) readonly macro!: GuiStateMacrogroupMacros
|
||||
@Prop({ required: true }) readonly macro!: GuiMacrogroupsStateMacrogroupMacro
|
||||
@Prop({ default: 'primary' }) readonly color!: string
|
||||
|
||||
get klipperMacro() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import Component from 'vue-class-component'
|
||||
import BaseMixin from '@/components/mixins/base'
|
||||
import {allDashboardPanels} from '@/store/variables'
|
||||
import {GuiStateMacrogroup} from '@/store/gui/types'
|
||||
import {capitalize} from '@/plugins/helpers'
|
||||
import {GuiMacrogroupsStateMacrogroup} from '@/store/gui/macrogroups/types'
|
||||
|
||||
@Component
|
||||
export default class DashboardMixin extends BaseMixin {
|
||||
@@ -12,7 +12,7 @@ export default class DashboardMixin extends BaseMixin {
|
||||
}
|
||||
|
||||
get macrogroups() {
|
||||
return this.$store.state.gui.dashboard.macrogroups ?? []
|
||||
return this.$store.getters['gui/macrogroups/getAllMacrogroups'] ?? []
|
||||
}
|
||||
|
||||
get missingPanelsMobile() {
|
||||
@@ -56,7 +56,7 @@ export default class DashboardMixin extends BaseMixin {
|
||||
const missingPanels: any[] = []
|
||||
|
||||
if (this.macroMode === 'expert') {
|
||||
this.macrogroups.forEach((group: GuiStateMacrogroup) => {
|
||||
this.macrogroups.forEach((group: GuiMacrogroupsStateMacrogroup) => {
|
||||
allPanels.push('macrogroup_'+group.id)
|
||||
})
|
||||
|
||||
@@ -77,7 +77,7 @@ export default class DashboardMixin extends BaseMixin {
|
||||
getPanelName(name: string) {
|
||||
if (name.startsWith('macrogroup_')) {
|
||||
const groupId = name.split('_')[1] ?? ''
|
||||
const group = this.macrogroups.find((group: GuiStateMacrogroup) => group.id === groupId)
|
||||
const group = this.macrogroups.find((group: GuiMacrogroupsStateMacrogroup) => group.id === groupId)
|
||||
|
||||
return (group) ? group.name : 'Macrogroup'
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
import {Component, Mixins, Prop} from 'vue-property-decorator'
|
||||
import BaseMixin from '../mixins/base'
|
||||
import Panel from '@/components/ui/Panel.vue'
|
||||
import {GuiStateMacrogroupMacros} from '@/store/gui/types'
|
||||
import MacroButton from '@/components/inputs/MacroButton.vue'
|
||||
import {PrinterStateMacro} from '@/store/printer/types'
|
||||
import {GuiMacrogroupsStateMacrogroupMacro} from '@/store/gui/macrogroups/types'
|
||||
@Component({
|
||||
components: {MacroButton, Panel}
|
||||
})
|
||||
@@ -40,7 +40,7 @@ export default class MacrogroupPanel extends Mixins(BaseMixin) {
|
||||
@Prop({ required: true }) panelId!: string
|
||||
|
||||
get macrogroup() {
|
||||
return this.$store.getters['gui/getMacroGroup'](this.panelId)
|
||||
return this.$store.getters['gui/macrogroups/getMacrogroup'](this.panelId)
|
||||
}
|
||||
|
||||
get allMacros() {
|
||||
@@ -50,7 +50,7 @@ export default class MacrogroupPanel extends Mixins(BaseMixin) {
|
||||
get macros() {
|
||||
let macros = this.macrogroup?.macros ?? []
|
||||
|
||||
macros = macros.filter((macro: GuiStateMacrogroupMacros) => {
|
||||
macros = macros.filter((macro: GuiMacrogroupsStateMacrogroupMacro) => {
|
||||
if (!this.allMacros.find((existMacro: PrinterStateMacro) => existMacro.name.toLowerCase() === macro.name.toLowerCase())) return false
|
||||
|
||||
return (
|
||||
@@ -60,7 +60,7 @@ export default class MacrogroupPanel extends Mixins(BaseMixin) {
|
||||
)
|
||||
})
|
||||
|
||||
return macros.sort((a: GuiStateMacrogroupMacros, b: GuiStateMacrogroupMacros) => a.pos - b.pos)
|
||||
return macros.sort((a: GuiMacrogroupsStateMacrogroupMacro, b: GuiMacrogroupsStateMacrogroupMacro) => a.pos - b.pos)
|
||||
}
|
||||
|
||||
get macrogroupStatus() {
|
||||
@@ -71,7 +71,7 @@ export default class MacrogroupPanel extends Mixins(BaseMixin) {
|
||||
)
|
||||
}
|
||||
|
||||
getColor(macro: GuiStateMacrogroupMacros) {
|
||||
getColor(macro: GuiMacrogroupsStateMacrogroupMacro) {
|
||||
if (macro.color === 'group') {
|
||||
if (this.macrogroup.color === 'custom') return this.macrogroup.colorCustom
|
||||
else return this.macrogroup.color
|
||||
|
||||
@@ -190,9 +190,9 @@ import {Component, Mixins, Watch} from 'vue-property-decorator'
|
||||
import BaseMixin from '../mixins/base'
|
||||
import draggable from 'vuedraggable'
|
||||
import SettingsRow from '@/components/settings/SettingsRow.vue'
|
||||
import {GuiStateMacrogroup, GuiStateMacrogroupMacros} from '@/store/gui/types'
|
||||
import {Debounce} from 'vue-debounce-decorator'
|
||||
import {PrinterStateMacro} from '@/store/printer/types'
|
||||
import {GuiMacrogroupsStateMacrogroup, GuiMacrogroupsStateMacrogroupMacro} from '@/store/gui/macrogroups/types'
|
||||
|
||||
@Component({
|
||||
components: {SettingsRow, draggable}
|
||||
@@ -253,24 +253,24 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin) {
|
||||
}
|
||||
|
||||
get availableMacros() {
|
||||
return this.allMacros.filter((m: GuiStateMacrogroupMacros) => !this.editGroupUsedMacros.includes(m.name))
|
||||
return this.allMacros.filter((m: GuiMacrogroupsStateMacrogroupMacro) => !this.editGroupUsedMacros.includes(m.name))
|
||||
}
|
||||
|
||||
get groups() {
|
||||
return this.$store.getters['gui/getAllMacroGroups'] ?? []
|
||||
return this.$store.getters['gui/macrogroups/getAllMacrogroups'] ?? []
|
||||
}
|
||||
|
||||
get editGroupUsedMacros() {
|
||||
return this.editGroup?.macros?.map((m: GuiStateMacrogroupMacros) => m.name) ?? []
|
||||
return this.editGroup?.macros?.map((m: GuiMacrogroupsStateMacrogroupMacro) => m.name) ?? []
|
||||
}
|
||||
|
||||
get editGroup(): GuiStateMacrogroup | null {
|
||||
return this.$store.getters['gui/getMacroGroup'](this.editGroupId)
|
||||
get editGroup(): GuiMacrogroupsStateMacrogroup | null {
|
||||
return this.$store.getters['gui/macrogroups/getMacrogroup'](this.editGroupId)
|
||||
}
|
||||
|
||||
get editGroupMacros() {
|
||||
const macros = this.editGroup?.macros ?? []
|
||||
macros.sort((a, b) => a.pos - b.pos)
|
||||
macros.sort((a: GuiMacrogroupsStateMacrogroupMacro, b: GuiMacrogroupsStateMacrogroupMacro) => a.pos - b.pos)
|
||||
|
||||
return macros
|
||||
}
|
||||
@@ -280,7 +280,7 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin) {
|
||||
}
|
||||
|
||||
existsGroupName(name: string) {
|
||||
return (this.groups.findIndex((group: GuiStateMacrogroup) => group.name === name && group.id != this.editGroupId) >= 0)
|
||||
return (this.groups.findIndex((group: GuiMacrogroupsStateMacrogroup) => group.name === name && group.id != this.editGroupId) >= 0)
|
||||
}
|
||||
|
||||
clearColorObject(color: any): string {
|
||||
@@ -296,37 +296,38 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin) {
|
||||
}
|
||||
|
||||
async addGroup() {
|
||||
this.editGroupId = await this.$store.dispatch('gui/storeMarcogroup', {
|
||||
const values = {
|
||||
name: '',
|
||||
color: 'primary',
|
||||
colorCustom: '#fff',
|
||||
showInStandby: true,
|
||||
showInPause: true,
|
||||
showInPrinting: true,
|
||||
})
|
||||
}
|
||||
this.editGroupId = await this.$store.dispatch('gui/macrogroups/store', { values })
|
||||
|
||||
this.boolFormEdit = true
|
||||
}
|
||||
|
||||
editMacrogroup(group: GuiStateMacrogroup) {
|
||||
editMacrogroup(group: GuiMacrogroupsStateMacrogroup) {
|
||||
this.boolFormEdit = true
|
||||
this.editGroupId = group.id
|
||||
}
|
||||
|
||||
deleteMacrogroup(id: string) {
|
||||
this.$store.dispatch('gui/destroyMacrogroup', id)
|
||||
this.$store.dispatch('gui/macrogroups/delete', id)
|
||||
}
|
||||
|
||||
addMacroToGroup(macro: PrinterStateMacro) {
|
||||
this.$store.dispatch('gui/addMacroToMacrogroup', {
|
||||
group: this.editGroupId,
|
||||
this.$store.dispatch('gui/macrogroups/addMacroToMacrogroup', {
|
||||
id: this.editGroupId,
|
||||
macro: macro.name
|
||||
})
|
||||
}
|
||||
|
||||
updateMacroFromGroup(macro: GuiStateMacrogroupMacros, option: string, value: boolean | string | number) {
|
||||
this.$store.dispatch('gui/updateMacroFromMacrogroup', {
|
||||
group: this.editGroupId,
|
||||
updateMacroFromGroup(macro: GuiMacrogroupsStateMacrogroupMacro, option: string, value: boolean | string | number) {
|
||||
this.$store.dispatch('gui/macrogroups/updateMacroFromMacrogroup', {
|
||||
id: this.editGroupId,
|
||||
macro: macro.name,
|
||||
option: option,
|
||||
value: value
|
||||
@@ -343,7 +344,7 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin) {
|
||||
this.updateMacroFromGroup(this.editGroupMacros[newIndex], 'pos', oldPos)
|
||||
}
|
||||
|
||||
changeColorMacroFromGroup(macro: GuiStateMacrogroupMacros) {
|
||||
changeColorMacroFromGroup(macro: GuiMacrogroupsStateMacrogroupMacro) {
|
||||
let index = this.macroColors.findIndex((color) => color.value === macro.color) + 1
|
||||
const maxIndex = this.macroColors.length - 1
|
||||
|
||||
@@ -353,9 +354,9 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin) {
|
||||
this.updateMacroFromGroup(macro, 'color', newColor)
|
||||
}
|
||||
|
||||
removeMacroFromGroup(macro: GuiStateMacrogroupMacros) {
|
||||
this.$store.dispatch('gui/removeMacroFromMacrogroup', {
|
||||
group: this.editGroupId,
|
||||
removeMacroFromGroup(macro: GuiMacrogroupsStateMacrogroupMacro) {
|
||||
this.$store.dispatch('gui/macrogroups/removeMacroFromMacrogroup', {
|
||||
id: this.editGroupId,
|
||||
macro: macro.name
|
||||
})
|
||||
}
|
||||
@@ -372,10 +373,12 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin) {
|
||||
}
|
||||
|
||||
updateMacrogroupOption(option: string, newVal: boolean | string) {
|
||||
this.$store.dispatch('gui/updateMacrogroup', {
|
||||
group: this.editGroupId,
|
||||
option: option,
|
||||
value: newVal
|
||||
const values:any = {}
|
||||
values[option] = newVal
|
||||
|
||||
this.$store.dispatch('gui/macrogroups/update', {
|
||||
id: this.editGroupId,
|
||||
values
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,19 @@ export const actions: ActionTree<GuiState, RootState> = {
|
||||
delete payload.value.remote_printers
|
||||
}
|
||||
|
||||
//added in V2.1.0
|
||||
if (payload.value.dashboard?.macrogroups) {
|
||||
window.console.debug('convert old macrogroups')
|
||||
|
||||
payload.value.dashboard?.macrogroups.forEach((macrogroup: any) => {
|
||||
dispatch('macrogroups/store', { values: macrogroup })
|
||||
})
|
||||
|
||||
Vue.$socket.emit('server.database.delete_item', { namespace: 'mainsail', key: 'dashboard.macrogroups' })
|
||||
|
||||
delete payload.value.dashboard.macrogroups
|
||||
}
|
||||
|
||||
commit('setData', payload.value)
|
||||
},
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {caseInsensitiveSort} from '@/plugins/helpers'
|
||||
import {GetterTree} from 'vuex'
|
||||
import {GuiState, GuiStateMacrogroup} from '@/store/gui/types'
|
||||
import {GuiState} from '@/store/gui/types'
|
||||
import {GuiMacrogroupsStateMacrogroup} from '@/store/gui/macrogroups/types'
|
||||
|
||||
// eslint-disable-next-line
|
||||
export const getters: GetterTree<GuiState, any> = {
|
||||
@@ -28,27 +29,19 @@ export const getters: GetterTree<GuiState, any> = {
|
||||
return !state.dashboard.nonExpandPanels?.includes(name) ?? true
|
||||
},
|
||||
|
||||
getAllMacroGroups: (state) => {
|
||||
return caseInsensitiveSort(state.dashboard.macrogroups ?? [], 'name')
|
||||
},
|
||||
|
||||
getMacroGroup: (state) => (id: string) => {
|
||||
return state.dashboard.macrogroups.find((group: GuiStateMacrogroup) => group.id === id)
|
||||
},
|
||||
|
||||
getPanels: (state, getters) => (viewport: string) => {
|
||||
let panels = state.dashboard[viewport]?.filter((element: any) => element !== null) ?? []
|
||||
|
||||
if (state.dashboard.macroManagement === 'simple') panels = panels.filter((element: any) => !element.name.startsWith('macrogroup_'))
|
||||
else {
|
||||
panels = panels.filter((element: any) => element.name !== 'macros')
|
||||
const macrogroups = getters['getAllMacroGroups']
|
||||
const macrogroups = getters['macrogroups/getAllMacrogroups']
|
||||
if (macrogroups.length) {
|
||||
panels = panels.filter((element: any) => {
|
||||
if (!element.name.startsWith('macrogroup_')) return true
|
||||
|
||||
const macrogroupId = element.name.substr(11)
|
||||
return (macrogroups.findIndex((macrogroup: GuiStateMacrogroup) => macrogroup.id === macrogroupId) !== -1)
|
||||
return (macrogroups.findIndex((macrogroup: GuiMacrogroupsStateMacrogroup) => macrogroup.id === macrogroupId) !== -1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {defaultLogoColor, defaultPrimaryColor} from '@/store/variables'
|
||||
|
||||
// load modules
|
||||
import { consolefilters } from '@/store/gui/consolefilters'
|
||||
import { macrogroups } from '@/store/gui/macrogroups'
|
||||
import { presets } from '@/store/gui/presets'
|
||||
import { remoteprinters } from '@/store/gui/remoteprinters'
|
||||
import { webcams } from '@/store/gui/webcams'
|
||||
@@ -32,7 +33,6 @@ export const getDefaultState = (): GuiState => {
|
||||
boolBigThumbnail: true,
|
||||
macroManagement: 'simple',
|
||||
hiddenMacros: [],
|
||||
macrogroups: [],
|
||||
hiddenTempChart: [],
|
||||
control: {
|
||||
style: 'bars',
|
||||
@@ -206,6 +206,7 @@ export const gui: Module<GuiState, any> = {
|
||||
mutations,
|
||||
modules: {
|
||||
consolefilters,
|
||||
macrogroups,
|
||||
presets,
|
||||
remoteprinters,
|
||||
webcams,
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { ActionTree } from 'vuex'
|
||||
import {RootState} from '@/store/types'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import Vue from 'vue'
|
||||
import {GuiMacrogroupsState} from '@/store/gui/macrogroups/types'
|
||||
|
||||
export const actions: ActionTree<GuiMacrogroupsState, RootState> = {
|
||||
reset({ commit }) {
|
||||
commit('reset')
|
||||
},
|
||||
|
||||
init() {
|
||||
window.console.debug('init gui/macrogroups')
|
||||
Vue.$socket.emit('server.database.get_item', { namespace: 'mainsail_macrogroups' }, { action: 'gui/macrogroups/initStore' })
|
||||
},
|
||||
|
||||
initStore({ commit }, payload) {
|
||||
commit('reset')
|
||||
commit('initStore', payload)
|
||||
},
|
||||
|
||||
upload({ state }, id) {
|
||||
Vue.$socket.emit('server.database.post_item', { namespace: 'mainsail_macrogroups', key: id, value: state.macrogroups[id] })
|
||||
},
|
||||
|
||||
async store({ commit, dispatch, state }, payload) {
|
||||
const id = uuidv4()
|
||||
|
||||
await commit('store', { id, values: payload.values })
|
||||
await dispatch('upload', id)
|
||||
|
||||
return id
|
||||
},
|
||||
|
||||
update({ commit, dispatch, state }, payload) {
|
||||
commit('update', payload)
|
||||
dispatch('upload', payload.id)
|
||||
},
|
||||
|
||||
addMacroToMacrogroup({ commit, dispatch }, payload) {
|
||||
commit('addMacroToMacrogroup', payload)
|
||||
dispatch('upload', payload.id)
|
||||
},
|
||||
|
||||
updateMacroFromMacrogroup({ commit, dispatch }, payload) {
|
||||
commit('updateMacroFromMacrogroup', payload)
|
||||
dispatch('upload', payload.id)
|
||||
},
|
||||
|
||||
removeMacroFromMacrogroup({ commit, dispatch }, payload) {
|
||||
commit('removeMacroFromMacrogroup', payload)
|
||||
dispatch('upload', payload.id)
|
||||
},
|
||||
|
||||
delete({ commit }, id) {
|
||||
commit('delete', id)
|
||||
Vue.$socket.emit('server.database.delete_item', { namespace: 'mainsail_macrogroups', key: id })
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { GetterTree } from 'vuex'
|
||||
import {GuiMacrogroupsState, GuiMacrogroupsStateMacrogroup} from '@/store/gui/macrogroups/types'
|
||||
import {caseInsensitiveSort} from '@/plugins/helpers'
|
||||
|
||||
// eslint-disable-next-line
|
||||
export const getters: GetterTree<GuiMacrogroupsState, any> = {
|
||||
|
||||
getAllMacrogroups: (state) => {
|
||||
const macrogroups: GuiMacrogroupsStateMacrogroup[] = []
|
||||
|
||||
Object.keys(state.macrogroups).forEach((id: string) => {
|
||||
macrogroups.push({...state.macrogroups[id], id})
|
||||
})
|
||||
|
||||
return caseInsensitiveSort(macrogroups, 'name')
|
||||
},
|
||||
|
||||
getMacrogroup: (state) => (id: string) => {
|
||||
return state.macrogroups[id]
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Module } from 'vuex'
|
||||
import { actions } from '@/store/gui/macrogroups/actions'
|
||||
import { mutations } from '@/store/gui/macrogroups/mutations'
|
||||
import { getters } from '@/store/gui/macrogroups/getters'
|
||||
import {GuiMacrogroupsState} from '@/store/gui/macrogroups/types'
|
||||
|
||||
export const getDefaultState = (): GuiMacrogroupsState => {
|
||||
return {
|
||||
macrogroups: {},
|
||||
}
|
||||
}
|
||||
|
||||
// initial state
|
||||
const state = getDefaultState()
|
||||
|
||||
// eslint-disable-next-line
|
||||
export const macrogroups: Module<GuiMacrogroupsState, any> = {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { getDefaultState } from './index'
|
||||
import {MutationTree} from 'vuex'
|
||||
import Vue from 'vue'
|
||||
import {GuiMacrogroupsState, GuiMacrogroupsStateMacrogroupMacro} from '@/store/gui/macrogroups/types'
|
||||
|
||||
export const mutations: MutationTree<GuiMacrogroupsState> = {
|
||||
reset(state) {
|
||||
Object.assign(state, getDefaultState())
|
||||
},
|
||||
|
||||
initStore(state, payload) {
|
||||
Vue.set(state, 'macrogroups', payload.value)
|
||||
},
|
||||
|
||||
store(state, payload) {
|
||||
Vue.set(state.macrogroups, payload.id, payload.values)
|
||||
},
|
||||
|
||||
update(state, payload) {
|
||||
if (payload.id in state.macrogroups) {
|
||||
const preset = {...state.macrogroups[payload.id]}
|
||||
Object.assign(preset, payload.values)
|
||||
|
||||
Vue.set(state.macrogroups, payload.id, preset)
|
||||
}
|
||||
},
|
||||
|
||||
addMacroToMacrogroup(state, payload) {
|
||||
const macros = [...state.macrogroups[payload.id]?.macros ?? []]
|
||||
|
||||
const newMacro: GuiMacrogroupsStateMacrogroupMacro = {
|
||||
pos: 1,
|
||||
name: payload.macro,
|
||||
color: 'group',
|
||||
showInStandby: true,
|
||||
showInPrinting: true,
|
||||
showInPause: true
|
||||
}
|
||||
|
||||
if (macros.length) newMacro.pos = Math.max(...macros.map((m: GuiMacrogroupsStateMacrogroupMacro) => m.pos)) + 1
|
||||
macros.push(newMacro)
|
||||
|
||||
Vue.set(state.macrogroups[payload.id], 'macros', macros)
|
||||
},
|
||||
|
||||
updateMacroFromMacrogroup(state, payload) {
|
||||
const macros = [...state.macrogroups[payload.id]?.macros ?? []]
|
||||
const updateMacroIndex = macros.findIndex((m: GuiMacrogroupsStateMacrogroupMacro) => m.name === payload.macro)
|
||||
if (updateMacroIndex !== -1) {
|
||||
const macro = macros[updateMacroIndex]
|
||||
// @ts-ignore
|
||||
macro[payload.option] = payload.value
|
||||
Vue.set(state.macrogroups[payload.id], 'macros', macros)
|
||||
}
|
||||
},
|
||||
|
||||
removeMacroFromMacrogroup(state, payload) {
|
||||
const macros = [...state.macrogroups[payload.id]?.macros ?? []]
|
||||
const deletedMacroIndex = macros.findIndex((m: GuiMacrogroupsStateMacrogroupMacro) => m.name === payload.macro)
|
||||
if (deletedMacroIndex !== -1) {
|
||||
const oldPos = macros[deletedMacroIndex].pos
|
||||
macros.splice(deletedMacroIndex, 1)
|
||||
|
||||
macros.filter((macro: GuiMacrogroupsStateMacrogroupMacro) => macro.pos > oldPos).forEach((macro: GuiMacrogroupsStateMacrogroupMacro) => {
|
||||
macro.pos = macro.pos - 1
|
||||
})
|
||||
}
|
||||
|
||||
Vue.set(state.macrogroups[payload.id], 'macros', macros)
|
||||
},
|
||||
|
||||
delete(state, payload) {
|
||||
if (payload in state.macrogroups) {
|
||||
Vue.delete(state.macrogroups, payload)
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
export interface GuiMacrogroupsState {
|
||||
macrogroups: {
|
||||
[key: string]: GuiMacrogroupsStateMacrogroup
|
||||
}
|
||||
}
|
||||
|
||||
export interface GuiMacrogroupsStateMacrogroup {
|
||||
id: string | null
|
||||
name: string
|
||||
color: 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'custom'
|
||||
colorCustom?: string
|
||||
showInStandby: boolean
|
||||
showInPrinting: boolean
|
||||
showInPause: boolean
|
||||
macros?: GuiMacrogroupsStateMacrogroupMacro[]
|
||||
}
|
||||
|
||||
export interface GuiMacrogroupsStateMacrogroupMacro {
|
||||
pos: number
|
||||
name: string
|
||||
color: 'group' | 'primary' | 'secondary' | 'success' | 'warning' | 'error'
|
||||
showInStandby: boolean
|
||||
showInPrinting: boolean
|
||||
showInPause: boolean
|
||||
}
|
||||
+1
-119
@@ -1,8 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import { getDefaultState } from './index'
|
||||
import {MutationTree} from 'vuex'
|
||||
import {GuiState, GuiStateMacrogroup, GuiStateMacrogroupMacros} from '@/store/gui/types'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
import {GuiState} from '@/store/gui/types'
|
||||
|
||||
export const mutations: MutationTree<GuiState> = {
|
||||
reset(state) {
|
||||
@@ -66,50 +65,6 @@ export const mutations: MutationTree<GuiState> = {
|
||||
Vue.set(state.webcamSettings.currentCam, payload.viewport, payload.value)
|
||||
},
|
||||
|
||||
addPreset(state, payload) {
|
||||
state.presets.push({
|
||||
name: payload.name,
|
||||
gcode: payload.gcode,
|
||||
values: payload.values
|
||||
})
|
||||
},
|
||||
|
||||
updatePreset(state, payload) {
|
||||
if (state.presets[payload.index]) {
|
||||
Vue.set(state.presets[payload.index], 'name', payload.name)
|
||||
Vue.set(state.presets[payload.index], 'gcode', payload.gcode)
|
||||
Vue.set(state.presets[payload.index], 'values', payload.values)
|
||||
}
|
||||
},
|
||||
|
||||
deletePreset(state, payload) {
|
||||
if (state.presets[payload.index]) {
|
||||
state.presets.splice(payload.index, 1)
|
||||
}
|
||||
},
|
||||
|
||||
addConsoleFilter(state, payload) {
|
||||
state.console.customFilters.push({
|
||||
name: payload.name,
|
||||
regex: payload.regex,
|
||||
bool: payload.bool
|
||||
})
|
||||
},
|
||||
|
||||
updateConsoleFilter(state, payload) {
|
||||
if (state.console.customFilters[payload.index]) {
|
||||
Vue.set(state.console.customFilters[payload.index], 'name', payload.name)
|
||||
Vue.set(state.console.customFilters[payload.index], 'regex', payload.regex)
|
||||
Vue.set(state.console.customFilters[payload.index], 'bool', payload.bool)
|
||||
}
|
||||
},
|
||||
|
||||
deleteConsoleFilter(state, payload) {
|
||||
if (state.console.customFilters[payload.index]) {
|
||||
state.console.customFilters.splice(payload.index, 1)
|
||||
}
|
||||
},
|
||||
|
||||
setHistoryColumns(state, data) {
|
||||
if (data.value && state.history.hideColums.includes(data.name)) {
|
||||
state.history.hideColums.splice(state.history.hideColums.indexOf(data.name), 1)
|
||||
@@ -141,77 +96,4 @@ export const mutations: MutationTree<GuiState> = {
|
||||
Vue.set(state.dashboard, 'nonExpandPanels', nonExpandPanels)
|
||||
}
|
||||
},
|
||||
|
||||
storeMacrogroup(state, payload) {
|
||||
state.dashboard.macrogroups.push(payload)
|
||||
},
|
||||
|
||||
destroyMacrogroup(state, payload) {
|
||||
const index = state.dashboard.macrogroups.findIndex((group: GuiStateMacrogroup) => group.id === payload)
|
||||
if (index !== -1) state.dashboard.macrogroups.splice(index, 1)
|
||||
},
|
||||
|
||||
addMacroToMacrogroup(state, payload) {
|
||||
const index = state.dashboard.macrogroups.findIndex((group: GuiStateMacrogroup) => group.id === payload.group)
|
||||
if (index !== -1) {
|
||||
const macros = [...state.dashboard.macrogroups[index]?.macros ?? []]
|
||||
|
||||
const newMacro: GuiStateMacrogroupMacros = {
|
||||
pos: 1,
|
||||
name: payload.macro,
|
||||
color: 'group',
|
||||
showInStandby: true,
|
||||
showInPrinting: true,
|
||||
showInPause: true
|
||||
}
|
||||
|
||||
if (macros.length) newMacro.pos = Math.max(...macros.map((m: GuiStateMacrogroupMacros) => m.pos)) + 1
|
||||
macros.push(newMacro)
|
||||
|
||||
Vue.set(state.dashboard.macrogroups[index], 'macros', macros)
|
||||
}
|
||||
},
|
||||
|
||||
updateMacroFromMacrogroup(state, payload) {
|
||||
const index = state.dashboard.macrogroups.findIndex((group: GuiStateMacrogroup) => group.id === payload.group)
|
||||
if (index !== -1) {
|
||||
const macros = [...state.dashboard.macrogroups[index]?.macros ?? []]
|
||||
const updateMacroIndex = macros.findIndex((m: GuiStateMacrogroupMacros) => m.name === payload.macro)
|
||||
if (updateMacroIndex !== -1) {
|
||||
macros[updateMacroIndex][payload.option] = payload.value
|
||||
Vue.set(state.dashboard.macrogroups[index], 'macros', macros)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
removeMacroFromMacrogroup(state, payload) {
|
||||
const index = state.dashboard.macrogroups.findIndex((group: GuiStateMacrogroup) => group.id === payload.group)
|
||||
if (index !== -1) {
|
||||
const macros = [...state.dashboard.macrogroups[index]?.macros ?? []]
|
||||
const deletedMacroIndex = macros.findIndex((m: GuiStateMacrogroupMacros) => m.name === payload.macro)
|
||||
if (deletedMacroIndex !== -1) {
|
||||
const oldPos = macros[deletedMacroIndex].pos
|
||||
macros.splice(deletedMacroIndex, 1)
|
||||
|
||||
macros.filter((macro: GuiStateMacrogroupMacros) => macro.pos > oldPos).forEach((macro: GuiStateMacrogroupMacros) => {
|
||||
macro.pos = macro.pos - 1
|
||||
})
|
||||
}
|
||||
|
||||
Vue.set(state.dashboard.macrogroups[index], 'macros', macros)
|
||||
}
|
||||
},
|
||||
|
||||
updateMacrogroup(state, payload) {
|
||||
const index = state.dashboard.macrogroups.findIndex((group: GuiStateMacrogroup) => group.id === payload.group)
|
||||
if (index !== -1 && payload.option in state.dashboard.macrogroups[index]) {
|
||||
Vue.set(state.dashboard.macrogroups[index], payload.option, payload.value)
|
||||
}
|
||||
},
|
||||
|
||||
deleteFromDashboardLayout(state, payload) {
|
||||
const layoutArray = [...state.dashboard[payload.layoutname]]
|
||||
layoutArray.splice(payload.index, 1)
|
||||
Vue.set(state.dashboard, payload.layoutname, layoutArray)
|
||||
}
|
||||
}
|
||||
@@ -7,24 +7,4 @@ export interface GuiState {
|
||||
boolNavi: boolean
|
||||
}
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export interface GuiStateMacrogroup {
|
||||
id: string | null
|
||||
name: string
|
||||
color: 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'custom'
|
||||
colorCustom?: string
|
||||
showInStandby: boolean
|
||||
showInPrinting: boolean
|
||||
showInPause: boolean
|
||||
macros?: GuiStateMacrogroupMacros[]
|
||||
}
|
||||
|
||||
export interface GuiStateMacrogroupMacros {
|
||||
pos: number
|
||||
name: string
|
||||
color: 'group' | 'primary' | 'secondary' | 'success' | 'warning' | 'error'
|
||||
showInStandby: boolean
|
||||
showInPrinting: boolean
|
||||
showInPause: boolean
|
||||
}
|
||||
@@ -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_macrogroups')) dispatch('gui/macrogroups/init', null, { root: true })
|
||||
if (!rootState.socket?.remoteMode && payload.namespaces?.includes('mainsail_remoteprinters')) dispatch('gui/remoteprinters/init', null, { root: true })
|
||||
|
||||
dispatch('printer/init', null, { root: true })
|
||||
|
||||
Reference in new issue
Block a user