From d85a072a394581102b66cd8d5a55db78ea9ed0ce Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 28 May 2022 15:47:48 +0200 Subject: [PATCH] fix: hide toolhead, extruder & temperature panel if they have no content (#852) * refactor: fix deprecated substr function Signed-off-by: Stefan Dej * refactor: remove unused import Signed-off-by: Stefan Dej * fix: hide toolhead, extruder and temperature panel if it is not available Signed-off-by: Stefan Dej --- src/components/mixins/dashboard.ts | 31 ++++++++++++++++++++++++++++++ src/pages/Dashboard.vue | 17 +++++++++++++++- src/store/gui/getters.ts | 3 +-- src/store/printer/getters.ts | 10 ++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/components/mixins/dashboard.ts b/src/components/mixins/dashboard.ts index 47600c28..a34e64e9 100644 --- a/src/components/mixins/dashboard.ts +++ b/src/components/mixins/dashboard.ts @@ -8,6 +8,22 @@ import Vue from 'vue' @Component export default class DashboardMixin extends BaseMixin { + get printerKinematics() { + return this.$store.getters['printer/getKinematics'] + } + + get printerExtruderCount() { + return this.$store.getters['printer/getExtruders'].length + } + + get printerAvailableHeatersCount() { + return this.$store.getters['printer/getAvailableHeaters'].length + } + + get printerAvailableSensorsCount() { + return this.$store.getters['printer/getAvailableSensors'].length + } + get macroMode() { return this.$store.state.gui.macros.mode ?? 'simple' } @@ -66,6 +82,21 @@ export default class DashboardMixin extends BaseMixin { allPanels = allPanels.filter((name) => name !== 'macros') } + // remove toolhead panel, if kinematics === none + if (this.printerKinematics === 'none') { + allPanels = allPanels.filter((name) => name !== 'toolhead-control') + } + + // remove extruder panel, if printerExtruderCount < 1 + if (this.printerExtruderCount < 1) { + allPanels = allPanels.filter((name) => name !== 'extruder-control') + } + + // remove temperature panel, if heaters & sensors < 1 + if (this.printerAvailableHeatersCount + this.printerAvailableSensorsCount < 1) { + allPanels = allPanels.filter((name) => name !== 'temperature') + } + // remove webcam panel, if no webcam exists if (this.webcams.length === 0) { allPanels = allPanels.filter((name) => name !== 'webcam') diff --git a/src/pages/Dashboard.vue b/src/pages/Dashboard.vue index 7361a73c..1db410be 100644 --- a/src/pages/Dashboard.vue +++ b/src/pages/Dashboard.vue @@ -115,13 +115,28 @@ import kebabCase from 'lodash.kebabcase' }) export default class PageDashboard extends Mixins(DashboardMixin) { get allComponents() { - const output: string[] = [] + let output: string[] = [] const components = Object.keys(this.$options.components ?? {}) components?.forEach((component) => { if (component.endsWith('Panel')) output.push(kebabCase(component)) }) + // remove toolhead panel, if kinematics === none + if (this.printerKinematics === 'none') { + output = output.filter((name) => name !== 'toolhead-control-panel') + } + + // remove extruder panel, if printerExtruderCount < 1 + if (this.printerExtruderCount < 1) { + output = output.filter((name) => name !== 'extruder-control-panel') + } + + // remove temperature panel, if heaters & sensors < 1 + if (this.printerAvailableHeatersCount + this.printerAvailableSensorsCount < 1) { + output = output.filter((name) => name !== 'temperature-panel') + } + return output } diff --git a/src/store/gui/getters.ts b/src/store/gui/getters.ts index 9022c6c9..9afd53a7 100644 --- a/src/store/gui/getters.ts +++ b/src/store/gui/getters.ts @@ -1,7 +1,6 @@ import { GetterTree } from 'vuex' import { GuiState } from '@/store/gui/types' import { GuiMacrosStateMacrogroup } from '@/store/gui/macros/types' -import Vue from 'vue' // eslint-disable-next-line export const getters: GetterTree = { @@ -47,7 +46,7 @@ export const getters: GetterTree = { panels = panels.filter((element: any) => { if (!element.name.startsWith('macrogroup_')) return true - const macrogroupId = element.name.substr(11) + const macrogroupId = element.name.slice(11) return ( macrogroups.findIndex( (macrogroup: GuiMacrosStateMacrogroup) => macrogroup.id === macrogroupId diff --git a/src/store/printer/getters.ts b/src/store/printer/getters.ts index ea4ac3fc..99b070bc 100644 --- a/src/store/printer/getters.ts +++ b/src/store/printer/getters.ts @@ -452,6 +452,10 @@ export const getters: GetterTree = { return additionValues }, + getAvailableHeaters: (state) => { + return state.heaters?.available_heaters ?? [] + }, + getAvailableSensors: (state) => { return state.heaters?.available_sensors ?? [] }, @@ -870,6 +874,12 @@ export const getters: GetterTree = { return tools }, + getKinematics: (state) => { + if (!state.configfile?.settings?.printer) return false + + return state.configfile?.settings?.printer.kinematics ?? 'none' + }, + existsQGL: (state) => { if (!state.configfile?.settings) return false