From f5c4aa6e2ae6b816bfdb7384b5d5af2a7ce8f956 Mon Sep 17 00:00:00 2001 From: CF3B5 Date: Mon, 15 Jul 2024 22:42:41 +0800 Subject: [PATCH 1/6] Object alias name & macro alias name --- src/components/TheSettingsMenu.vue | 8 + src/components/charts/TempChart.vue | 2 +- src/components/inputs/FilamentSensor.vue | 2 +- src/components/inputs/MiscellaneousLight.vue | 2 +- src/components/inputs/MiscellaneousSlider.vue | 2 +- src/components/mixins/base.ts | 7 + src/components/panels/MacrogroupPanel.vue | 5 + .../Temperature/TemperaturePanelListItem.vue | 2 +- src/components/settings/SettingsAliasTab.vue | 137 ++++++++++++++++++ .../settings/SettingsMacrosTabExpert.vue | 56 ++++++- src/locales/en.json | 4 + src/locales/zh.json | 4 + src/store/gui/index.ts | 2 + src/store/gui/types.ts | 6 + 14 files changed, 233 insertions(+), 6 deletions(-) create mode 100644 src/components/settings/SettingsAliasTab.vue diff --git a/src/components/TheSettingsMenu.vue b/src/components/TheSettingsMenu.vue index f989aae96..3c807d1f2 100644 --- a/src/components/TheSettingsMenu.vue +++ b/src/components/TheSettingsMenu.vue @@ -81,6 +81,7 @@ import SettingsGCodeViewerTab from '@/components/settings/SettingsGCodeViewerTab import SettingsEditorTab from '@/components/settings/SettingsEditorTab.vue' import SettingsTimelapseTab from '@/components/settings/SettingsTimelapseTab.vue' import SettingsNavigationTab from '@/components/settings/SettingsNavigationTab.vue' +import SettingsAliasTab from "@/components/settings/SettingsAliasTab.vue" import Panel from '@/components/ui/Panel.vue' import { @@ -101,6 +102,7 @@ import { mdiDipSwitch, mdiMenu, mdiGrid, + mdiRenameOutline, } from '@mdi/js' import SettingsMiscellaneousTab from '@/components/settings/SettingsMiscellaneousTab.vue' import SettingsHeightmapTab from '@/components/settings/SettingsHeightmapTab.vue' @@ -123,6 +125,7 @@ import SettingsHeightmapTab from '@/components/settings/SettingsHeightmapTab.vue SettingsMiscellaneousTab, SettingsNavigationTab, SettingsHeightmapTab, + SettingsAliasTab, }, }) export default class TheSettingsMenu extends Mixins(BaseMixin) { @@ -211,6 +214,11 @@ export default class TheSettingsMenu extends Mixins(BaseMixin) { name: 'heightmap', title: this.$t('Settings.HeightmapTab.Heightmap'), }, + { + icon: mdiRenameOutline, + name: 'alias', + title: this.$t('Settings.AliasTab.AliasName'), + }, ] if (this.moonrakerComponents.includes('timelapse')) { diff --git a/src/components/charts/TempChart.vue b/src/components/charts/TempChart.vue index 2fe69636a..956505218 100644 --- a/src/components/charts/TempChart.vue +++ b/src/components/charts/TempChart.vue @@ -302,7 +302,7 @@ export default class TempChart extends Mixins(BaseMixin, ThemeMixin) { mainDatasets.forEach((dataset: any) => { const baseSeriesName = dataset.seriesName.substring(0, dataset.seriesName.lastIndexOf('-')) - let displayName = baseSeriesName + let displayName = this.aliasName(baseSeriesName) if (displayName.indexOf(' ') !== -1) { displayName = displayName.substring(displayName.indexOf(' ') + 1) } diff --git a/src/components/inputs/FilamentSensor.vue b/src/components/inputs/FilamentSensor.vue index 82b53085a..70c1df2b6 100644 --- a/src/components/inputs/FilamentSensor.vue +++ b/src/components/inputs/FilamentSensor.vue @@ -4,7 +4,7 @@ {{ mdiPrinter3dNozzleAlert }} - {{ convertName(name) }} + {{ aliasName(name) }} {{ statusText }} diff --git a/src/components/inputs/MiscellaneousLight.vue b/src/components/inputs/MiscellaneousLight.vue index 57eee47b1..2ea784716 100644 --- a/src/components/inputs/MiscellaneousLight.vue +++ b/src/components/inputs/MiscellaneousLight.vue @@ -175,7 +175,7 @@ export default class MiscellaneousLight extends Mixins(BaseMixin) { get name() { if (this.group) return convertName(this.group.name) - return convertName(this.object.name) + return this.aliasName(this.object.name) } get colorPickerOptions() { diff --git a/src/components/inputs/MiscellaneousSlider.vue b/src/components/inputs/MiscellaneousSlider.vue index fd70a0a5d..b9a4308c9 100644 --- a/src/components/inputs/MiscellaneousSlider.vue +++ b/src/components/inputs/MiscellaneousSlider.vue @@ -15,7 +15,7 @@ {{ mdiLightbulbOutline }} {{ mdiFan }} - {{ convertName(name) }} + {{ aliasName(name) }} {{ Math.round(rpm ?? 0) }} RPM diff --git a/src/components/mixins/base.ts b/src/components/mixins/base.ts index 4aabadbc8..d583876c9 100644 --- a/src/components/mixins/base.ts +++ b/src/components/mixins/base.ts @@ -2,6 +2,7 @@ import Vue from 'vue' import Component from 'vue-class-component' import { DateTimeFormatOptions } from 'vue-i18n' import { ServerPowerStateDevice } from '@/store/server/power/types' +import { convertName } from '@/plugins/helpers' @Component export default class BaseMixin extends Vue { @@ -224,4 +225,10 @@ export default class BaseMixin extends Vue { return `${date} ${time}` } + + alisaName(name: string): string { + const aliasNames = this.$store.state.gui.aliasNames + if(aliasNames[name] !== undefined) return aliasNames[name] + return convertName(name) + } } diff --git a/src/components/panels/MacrogroupPanel.vue b/src/components/panels/MacrogroupPanel.vue index a7e7471f6..185c9157a 100644 --- a/src/components/panels/MacrogroupPanel.vue +++ b/src/components/panels/MacrogroupPanel.vue @@ -14,6 +14,7 @@ v-for="(macro, index) in macros" :key="'macroparam_' + index" :macro="macro" + :alias="macroAliasNames[macro.name]" :color="getColor(macro)" class="mx-1 my-1" /> @@ -38,6 +39,10 @@ export default class MacrogroupPanel extends Mixins(BaseMixin) { @Prop({ required: true }) declare panelId: string + get macroAliasNames() { + return this.$store.state.gui.macroAliasNames + } + get macrogroup() { return this.$store.getters['gui/macros/getMacrogroup'](this.panelId) } diff --git a/src/components/panels/Temperature/TemperaturePanelListItem.vue b/src/components/panels/Temperature/TemperaturePanelListItem.vue index 311e7b140..f8850d087 100644 --- a/src/components/panels/Temperature/TemperaturePanelListItem.vue +++ b/src/components/panels/Temperature/TemperaturePanelListItem.vue @@ -107,7 +107,7 @@ export default class TemperaturePanelListItem extends Mixins(BaseMixin) { } get formatName() { - return convertName(this.name) + return this.aliasName(this.objectName) } get icon() { diff --git a/src/components/settings/SettingsAliasTab.vue b/src/components/settings/SettingsAliasTab.vue new file mode 100644 index 000000000..476b98394 --- /dev/null +++ b/src/components/settings/SettingsAliasTab.vue @@ -0,0 +1,137 @@ + + + diff --git a/src/components/settings/SettingsMacrosTabExpert.vue b/src/components/settings/SettingsMacrosTabExpert.vue index eb4b5313d..b5bf6920e 100644 --- a/src/components/settings/SettingsMacrosTabExpert.vue +++ b/src/components/settings/SettingsMacrosTabExpert.vue @@ -152,7 +152,7 @@ {{ $t('Settings.MacrosTab.ChangeMacroColor') }} + + + {{ $t('Settings.MacrosTab.macroAlisaName') }} + @@ -308,6 +337,7 @@ import { mdiDragVertical, mdiPalette, mdiPencil, + mdiRename, } from '@mdi/js' @Component({ @@ -325,6 +355,7 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixi mdiPlus = mdiPlus mdiDragVertical = mdiDragVertical mdiPalette = mdiPalette + mdiRename = mdiRename private rules = { required: (value: string) => value !== '' || 'required', @@ -333,6 +364,18 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixi private boolFormEdit = false private editGroupId: string | null = '' + private macroAliasNameDialog = false + private editMacro: GuiMacrosStateMacrogroupMacro | null = null + + get macroAliasNames() { + return this.$store.state.gui.macroAliasNames + } + + @Watch('macroAliasNames', { deep: true }) + onMacroAliasNames(val: string[]) { + val.filter(i=>i && i.trim()) + this.$store.dispatch('gui/saveSetting', { name: 'macroAliasNames', value: val }) + } get groupColors() { return [ @@ -495,6 +538,12 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixi ) } + getMacroName(macroname:string){ + const aliasMacroName = this.macroAliasNames[macroname] + if (aliasMacroName) return aliasMacroName + " (" + macroname + ")" + return macroname + } + getMacroDescription(macroname: string) { const macro = this.allMacros.find((m: PrinterStateMacro) => m.name.toLowerCase() === macroname.toLowerCase()) if (!macro) return this.$t('Settings.MacrosTab.DeletedMacro') @@ -547,5 +596,10 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixi this.boolFormEdit = false this.$emit('scrollToTop') } + + editMacroAlisaName(macro: GuiMacrosStateMacrogroupMacro) { + this.editMacro = macro + this.macroAliasNameDialog = true + } } diff --git a/src/locales/en.json b/src/locales/en.json index 5c403574b..a9d4aea57 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -878,6 +878,9 @@ "YouCanFindMore": "You can find more details at" }, "Settings": { + "AliasTab": { + "AliasName": "Alias Name" + }, "Cancel": "Cancel", "Close": "Close", "ConsoleTab": { @@ -1023,6 +1026,7 @@ "Add": "add", "AddGroup": "add Group", "AvailableMacros": "Available Macros", + "MacroAlisaName": "Macro Alisa Name", "ChangeMacroColor": "Change the color of the button.", "Color": "Color", "CountMacros": "no Macros added | {count} Macro | {count} Macros", diff --git a/src/locales/zh.json b/src/locales/zh.json index 9ff1fadbf..077990ca8 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -874,6 +874,9 @@ "YouCanFindMore": "你可以从这里查看更多信息:" }, "Settings": { + "AliasTab": { + "AliasName": "别名" + }, "Cancel": "取消", "Close": "关闭", "ConsoleTab": { @@ -1019,6 +1022,7 @@ "Add": "添加", "AddGroup": "添加分组", "AvailableMacros": "可用宏", + "MacroAlisaName": "宏别名", "ChangeMacroColor": "修改按钮颜色。", "Color": "颜色", "CountMacros": "没有添加宏 | {count}个宏 | {count}个宏", diff --git a/src/store/gui/index.ts b/src/store/gui/index.ts index 6f94a5344..18f28d33f 100644 --- a/src/store/gui/index.ts +++ b/src/store/gui/index.ts @@ -289,6 +289,8 @@ export const getDefaultState = (): GuiState => { }, }, }, + aliasNames: {}, + macroAliasNames: {}, } } diff --git a/src/store/gui/types.ts b/src/store/gui/types.ts index a1bef68e2..3a4ef0317 100644 --- a/src/store/gui/types.ts +++ b/src/store/gui/types.ts @@ -207,6 +207,12 @@ export interface GuiState { } } } + aliasNames: { + [index: string]: string + } + macroAliasNames: { + [index: string]: string + } } export interface GuiStateLayoutoption { From e794ff7f3a75523462bb10dc719f22c9a269b373 Mon Sep 17 00:00:00 2001 From: CF3B5 Date: Tue, 16 Jul 2024 01:13:46 +0800 Subject: [PATCH 2/6] Object alias name & macro alias name --- src/components/mixins/base.ts | 2 +- src/components/settings/SettingsAliasTab.vue | 13 ++++++++----- .../settings/SettingsMacrosTabExpert.vue | 16 ++++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/components/mixins/base.ts b/src/components/mixins/base.ts index d583876c9..b38662d5a 100644 --- a/src/components/mixins/base.ts +++ b/src/components/mixins/base.ts @@ -226,7 +226,7 @@ export default class BaseMixin extends Vue { return `${date} ${time}` } - alisaName(name: string): string { + aliasName(name: string): string { const aliasNames = this.$store.state.gui.aliasNames if(aliasNames[name] !== undefined) return aliasNames[name] return convertName(name) diff --git a/src/components/settings/SettingsAliasTab.vue b/src/components/settings/SettingsAliasTab.vue index 476b98394..3edc15f78 100644 --- a/src/components/settings/SettingsAliasTab.vue +++ b/src/components/settings/SettingsAliasTab.vue @@ -43,22 +43,25 @@ import Component from 'vue-class-component' import { Mixins, Watch } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import { convertName } from '@/plugins/helpers' +import _ from 'lodash' @Component({ methods: { convertName }, components: {}, }) export default class SettingsAliasTab extends Mixins(BaseMixin) { - get aliasNames() { - return this.$store.state.gui.aliasNames - } + private aliasNames = {} @Watch('aliasNames', { deep: true }) - onAliasNames(val: string[]) { - val.filter(i=>i && i.trim()) + onAliasNames(val: any) { + val = _.omitBy(val, (value)=>value == null || false || _.isEmpty(value)) this.$store.dispatch('gui/saveSetting', { name: 'aliasNames', value: val }) } + mounted(){ + this.aliasNames = this.$store.state.gui.aliasNames + } + get available_heaters() { return this.$store.state.printer?.heaters?.available_heaters ?? [] } diff --git a/src/components/settings/SettingsMacrosTabExpert.vue b/src/components/settings/SettingsMacrosTabExpert.vue index b5bf6920e..380709e36 100644 --- a/src/components/settings/SettingsMacrosTabExpert.vue +++ b/src/components/settings/SettingsMacrosTabExpert.vue @@ -328,6 +328,7 @@ import SettingsRow from '@/components/settings/SettingsRow.vue' import { Debounce } from 'vue-debounce-decorator' import { PrinterStateMacro } from '@/store/printer/types' import { GuiMacrosStateMacrogroup, GuiMacrosStateMacrogroupMacro } from '@/store/gui/macros/types' +import _ from 'lodash' import { mdiDelete, mdiSleep, @@ -344,6 +345,8 @@ import { components: { SettingsRow, draggable }, }) export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixin) { + private macroAliasNames = {} + /** * Icons */ @@ -367,16 +370,17 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixi private macroAliasNameDialog = false private editMacro: GuiMacrosStateMacrogroupMacro | null = null - get macroAliasNames() { - return this.$store.state.gui.macroAliasNames - } - @Watch('macroAliasNames', { deep: true }) - onMacroAliasNames(val: string[]) { - val.filter(i=>i && i.trim()) + onMacroAliasNames(val: any) { + val = _.omitBy(val, (value)=>value == null || false || _.isEmpty(value)) this.$store.dispatch('gui/saveSetting', { name: 'macroAliasNames', value: val }) } + + mounted(): void { + this.macroAliasNames = this.$store.state.gui.macroAliasNames + } + get groupColors() { return [ { From 2a9a928f41730ff8c64c92f826ce429d41f91399 Mon Sep 17 00:00:00 2001 From: CF3B5 Date: Tue, 16 Jul 2024 01:23:42 +0800 Subject: [PATCH 3/6] prettier code --- src/components/TheSettingsMenu.vue | 2 +- src/components/mixins/base.ts | 2 +- src/components/settings/SettingsAliasTab.vue | 4 ++-- .../settings/SettingsMacrosTabExpert.vue | 18 +++++++++--------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/components/TheSettingsMenu.vue b/src/components/TheSettingsMenu.vue index 3c807d1f2..e285244a3 100644 --- a/src/components/TheSettingsMenu.vue +++ b/src/components/TheSettingsMenu.vue @@ -81,7 +81,7 @@ import SettingsGCodeViewerTab from '@/components/settings/SettingsGCodeViewerTab import SettingsEditorTab from '@/components/settings/SettingsEditorTab.vue' import SettingsTimelapseTab from '@/components/settings/SettingsTimelapseTab.vue' import SettingsNavigationTab from '@/components/settings/SettingsNavigationTab.vue' -import SettingsAliasTab from "@/components/settings/SettingsAliasTab.vue" +import SettingsAliasTab from '@/components/settings/SettingsAliasTab.vue' import Panel from '@/components/ui/Panel.vue' import { diff --git a/src/components/mixins/base.ts b/src/components/mixins/base.ts index b38662d5a..7c45dabec 100644 --- a/src/components/mixins/base.ts +++ b/src/components/mixins/base.ts @@ -228,7 +228,7 @@ export default class BaseMixin extends Vue { aliasName(name: string): string { const aliasNames = this.$store.state.gui.aliasNames - if(aliasNames[name] !== undefined) return aliasNames[name] + if (aliasNames[name] !== undefined) return aliasNames[name] return convertName(name) } } diff --git a/src/components/settings/SettingsAliasTab.vue b/src/components/settings/SettingsAliasTab.vue index 3edc15f78..6ccb5f14f 100644 --- a/src/components/settings/SettingsAliasTab.vue +++ b/src/components/settings/SettingsAliasTab.vue @@ -54,11 +54,11 @@ export default class SettingsAliasTab extends Mixins(BaseMixin) { @Watch('aliasNames', { deep: true }) onAliasNames(val: any) { - val = _.omitBy(val, (value)=>value == null || false || _.isEmpty(value)) + val = _.omitBy(val, (value) => value == null || false || _.isEmpty(value)) this.$store.dispatch('gui/saveSetting', { name: 'aliasNames', value: val }) } - mounted(){ + mounted() { this.aliasNames = this.$store.state.gui.aliasNames } diff --git a/src/components/settings/SettingsMacrosTabExpert.vue b/src/components/settings/SettingsMacrosTabExpert.vue index 380709e36..2215bb6c1 100644 --- a/src/components/settings/SettingsMacrosTabExpert.vue +++ b/src/components/settings/SettingsMacrosTabExpert.vue @@ -300,17 +300,18 @@ {{ $t('Settings.Close') }} - + {{ $t('Settings.MacrosTab.MacroAlisaName') }} - + @@ -372,11 +373,10 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixi @Watch('macroAliasNames', { deep: true }) onMacroAliasNames(val: any) { - val = _.omitBy(val, (value)=>value == null || false || _.isEmpty(value)) + val = _.omitBy(val, (value) => value == null || false || _.isEmpty(value)) this.$store.dispatch('gui/saveSetting', { name: 'macroAliasNames', value: val }) } - mounted(): void { this.macroAliasNames = this.$store.state.gui.macroAliasNames } @@ -542,9 +542,9 @@ export default class SettingsMacrosTabExpert extends Mixins(BaseMixin, ThemeMixi ) } - getMacroName(macroname:string){ + getMacroName(macroname: string) { const aliasMacroName = this.macroAliasNames[macroname] - if (aliasMacroName) return aliasMacroName + " (" + macroname + ")" + if (aliasMacroName) return aliasMacroName + ' (' + macroname + ')' return macroname } From d93d580e8d726f1d5847d060ac9c712a77b1ade3 Mon Sep 17 00:00:00 2001 From: CF3B5 Date: Tue, 16 Jul 2024 01:28:31 +0800 Subject: [PATCH 4/6] fix spelling mistake --- src/components/settings/SettingsMacrosTabExpert.vue | 8 ++++---- src/locales/en.json | 2 +- src/locales/zh.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/settings/SettingsMacrosTabExpert.vue b/src/components/settings/SettingsMacrosTabExpert.vue index 2215bb6c1..1d2062984 100644 --- a/src/components/settings/SettingsMacrosTabExpert.vue +++ b/src/components/settings/SettingsMacrosTabExpert.vue @@ -180,11 +180,11 @@ v-bind="attrs" class="ml-3 minwidth-0 px-2" v-on="on" - @click="editMacroAlisaName(macro)"> + @click="editMacroAliasName(macro)"> {{ mdiRename }} - {{ $t('Settings.MacrosTab.macroAlisaName') }} + {{ $t('Settings.MacrosTab.macroAliasName') }} - {{ $t('Settings.MacrosTab.macroAliasName') }} + {{ $t('Settings.MacrosTab.MacroAliasName') }}