From c00fd568acb991cdc7faba7b14f12a262ba23d4f Mon Sep 17 00:00:00 2001 From: 4cello Date: Thu, 28 Mar 2024 23:50:47 +0100 Subject: [PATCH 1/8] Added UI fields for printer name --- src/components/TheSelectPrinterDialog.vue | 52 ++++++++++++++++++- .../settings/SettingsRemotePrintersTab.vue | 21 ++++++++ src/locales/en.json | 4 ++ src/store/gui/remoteprinters/actions.ts | 2 + src/store/gui/remoteprinters/types.ts | 1 + 5 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index 8e82c03c6..240d3a762 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -83,6 +83,21 @@ dense> + + + + + + + @@ -121,6 +136,21 @@ hide-details="auto"> + + + + + + + @@ -238,6 +268,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { bool: false, hostname: '', port: 7125, + name: '' } private editPrinterValid = false private dialogEditPrinter = { @@ -245,6 +276,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { id: '', hostname: '', port: 0, + name: '' } /** @@ -282,6 +314,10 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { return this.$store.state.socket.port } + get name() { + return this.$store.state.printer + } + get formatHostname() { return parseInt(this.port) !== 80 && this.port !== '' ? this.hostname + ':' + this.port : this.hostname } @@ -345,17 +381,20 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { const values = { hostname: this.dialogAddPrinter.hostname, port: this.dialogAddPrinter.port, + name: this.dialogAddPrinter.name } this.$store.dispatch('gui/remoteprinters/store', { values }) this.dialogAddPrinter.hostname = '' this.dialogAddPrinter.bool = false + this.dialogAddPrinter.name = '' } editPrinter(printer: GuiRemoteprintersStatePrinter) { this.dialogEditPrinter.hostname = printer.hostname this.dialogEditPrinter.port = printer.port this.dialogEditPrinter.id = printer.id ?? '' + this.dialogEditPrinter.name = printer.name ?? '' this.dialogEditPrinter.bool = true } @@ -363,6 +402,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { const values = { hostname: this.dialogEditPrinter.hostname, port: this.dialogEditPrinter.port, + name: this.dialogEditPrinter.name } this.$store.dispatch('gui/remoteprinters/update', { id: this.dialogEditPrinter.id, @@ -404,7 +444,17 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { } mounted() { - this.$store.dispatch('gui/remoteprinters/initFromLocalstorage') + this.$store.dispatch('gui/remoteprinters/initFromLocalstorage').then( + () => { + window.console.log({printers: this.printers, gui: this.guiIsReady}) + if ("printer" in this.$route.query) { + let matching = this.printers.filter((printer) => printer.name === this.$route.query.printer) + if (matching.length > 0) { + this.connect(matching[0]) + } + } + } + ) } } diff --git a/src/components/settings/SettingsRemotePrintersTab.vue b/src/components/settings/SettingsRemotePrintersTab.vue index be8c806e6..59d2aede5 100644 --- a/src/components/settings/SettingsRemotePrintersTab.vue +++ b/src/components/settings/SettingsRemotePrintersTab.vue @@ -66,6 +66,19 @@ dense outlined> + + + + + {{ $t('Settings.Cancel') }} @@ -91,6 +104,7 @@ interface printerForm { bool: boolean hostname: string port: number + name: string id: string | null namespace: string | null } @@ -109,6 +123,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { bool: false, hostname: '', port: 7125, + name: '', id: null, namespace: null, } @@ -132,6 +147,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { createPrinter() { this.form.hostname = '' this.form.port = 7125 + this.form.name = '' this.form.id = null this.form.namespace = null this.form.bool = true @@ -141,12 +157,14 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { const printer = { hostname: this.form.hostname, port: this.form.port, + name: this.form.name } this.$store.dispatch('gui/remoteprinters/store', { values: printer }) this.form.hostname = '' this.form.port = 7125 + this.form.name = '' this.form.id = null this.form.bool = false } @@ -155,6 +173,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { this.form.id = printer.id ?? null this.form.hostname = printer.hostname this.form.port = printer.port + this.form.name = printer.name ?? '' this.form.bool = true } @@ -162,6 +181,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { const values = { hostname: this.form.hostname, port: this.form.port, + name: this.form.name } this.$store.dispatch('gui/remoteprinters/update', { id: this.form.id, values }) @@ -169,6 +189,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { this.form.id = null this.form.hostname = '' this.form.port = 7125 + this.form.name = '' this.form.bool = false } diff --git a/src/locales/en.json b/src/locales/en.json index 4b25e5eb0..0c31360d5 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -820,6 +820,7 @@ "SelectPrinterDialog": { "AddPrinter": "Add Printer", "AddPrintersToJson": "Please add the Printers to the config.json.", + "AdvancedSettings": "Advanced Settings", "CannotConnectTo": "Cannot connect to {host}.", "ChangePrinter": "Change Printer", "Connecting": "Connecting to {host}", @@ -829,6 +830,7 @@ "HostnameInvalid": "invalid Hostname/IP", "HostnameIp": "Hostname/IP", "HostnameRequired": "Hostname is required", + "Name": "Name", "Port": "Port", "PortRequired": "Port is required", "RememberToAdd": "Please remember to add '{cors}' in moonraker.conf within 'cors_domains'.", @@ -1060,8 +1062,10 @@ }, "RemotePrintersTab": { "AddPrinter": "Add Printer", + "AdvancedSettings":"Advanced Settings", "EditPrinter": "Edit Printer", "Hostname": "Hostname", + "Name": "Name", "Port": "Port", "RemotePrinters": "Printers", "UpdatePrinter": "Update Printer", diff --git a/src/store/gui/remoteprinters/actions.ts b/src/store/gui/remoteprinters/actions.ts index a62e70e19..9cc9c184b 100644 --- a/src/store/gui/remoteprinters/actions.ts +++ b/src/store/gui/remoteprinters/actions.ts @@ -54,6 +54,7 @@ export const actions: ActionTree = { printers.push({ hostname: state.printers[id].hostname, port: state.printers[id].port, + name: state.printers[id].name, settings: state.printers[id].settings, }) }) @@ -84,6 +85,7 @@ export const actions: ActionTree = { id, hostname: payload.values.hostname ?? '', port: payload.values.port ?? 7125, + name: payload.values.name }, { root: true } ) diff --git a/src/store/gui/remoteprinters/types.ts b/src/store/gui/remoteprinters/types.ts index c77458f23..2119726e9 100644 --- a/src/store/gui/remoteprinters/types.ts +++ b/src/store/gui/remoteprinters/types.ts @@ -10,6 +10,7 @@ export interface GuiRemoteprintersStatePrinter { id?: string | null hostname: string port: number + name?: string | null socket?: FarmPrinterStateSocket settings?: { [key: string]: any From 5763bb58961b41f07e0370aece4feeb8ec7579d6 Mon Sep 17 00:00:00 2001 From: 4cello Date: Sat, 30 Mar 2024 11:14:04 +0100 Subject: [PATCH 2/8] Formatting --- src/components/TheSelectPrinterDialog.vue | 24 +++++++++---------- .../settings/SettingsRemotePrintersTab.vue | 4 ++-- src/locales/en.json | 2 +- src/store/gui/remoteprinters/actions.ts | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index 240d3a762..7e41977d2 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -268,7 +268,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { bool: false, hostname: '', port: 7125, - name: '' + name: '', } private editPrinterValid = false private dialogEditPrinter = { @@ -276,7 +276,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { id: '', hostname: '', port: 0, - name: '' + name: '', } /** @@ -381,7 +381,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { const values = { hostname: this.dialogAddPrinter.hostname, port: this.dialogAddPrinter.port, - name: this.dialogAddPrinter.name + name: this.dialogAddPrinter.name, } this.$store.dispatch('gui/remoteprinters/store', { values }) @@ -402,7 +402,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { const values = { hostname: this.dialogEditPrinter.hostname, port: this.dialogEditPrinter.port, - name: this.dialogEditPrinter.name + name: this.dialogEditPrinter.name, } this.$store.dispatch('gui/remoteprinters/update', { id: this.dialogEditPrinter.id, @@ -444,17 +444,15 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { } mounted() { - this.$store.dispatch('gui/remoteprinters/initFromLocalstorage').then( - () => { - window.console.log({printers: this.printers, gui: this.guiIsReady}) - if ("printer" in this.$route.query) { - let matching = this.printers.filter((printer) => printer.name === this.$route.query.printer) - if (matching.length > 0) { - this.connect(matching[0]) - } + this.$store.dispatch('gui/remoteprinters/initFromLocalstorage').then(() => { + window.console.log({ printers: this.printers, gui: this.guiIsReady }) + if ('printer' in this.$route.query) { + let matching = this.printers.filter((printer) => printer.name === this.$route.query.printer) + if (matching.length > 0) { + this.connect(matching[0]) } } - ) + }) } } diff --git a/src/components/settings/SettingsRemotePrintersTab.vue b/src/components/settings/SettingsRemotePrintersTab.vue index 59d2aede5..528bb2019 100644 --- a/src/components/settings/SettingsRemotePrintersTab.vue +++ b/src/components/settings/SettingsRemotePrintersTab.vue @@ -157,7 +157,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { const printer = { hostname: this.form.hostname, port: this.form.port, - name: this.form.name + name: this.form.name, } this.$store.dispatch('gui/remoteprinters/store', { values: printer }) @@ -181,7 +181,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { const values = { hostname: this.form.hostname, port: this.form.port, - name: this.form.name + name: this.form.name, } this.$store.dispatch('gui/remoteprinters/update', { id: this.form.id, values }) diff --git a/src/locales/en.json b/src/locales/en.json index 0c31360d5..210a1afd7 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1062,7 +1062,7 @@ }, "RemotePrintersTab": { "AddPrinter": "Add Printer", - "AdvancedSettings":"Advanced Settings", + "AdvancedSettings": "Advanced Settings", "EditPrinter": "Edit Printer", "Hostname": "Hostname", "Name": "Name", diff --git a/src/store/gui/remoteprinters/actions.ts b/src/store/gui/remoteprinters/actions.ts index 9cc9c184b..b0b06842c 100644 --- a/src/store/gui/remoteprinters/actions.ts +++ b/src/store/gui/remoteprinters/actions.ts @@ -85,7 +85,7 @@ export const actions: ActionTree = { id, hostname: payload.values.hostname ?? '', port: payload.values.port ?? 7125, - name: payload.values.name + name: payload.values.name, }, { root: true } ) From 2c14caeece304c1dfd751f5f4b4b7c507b39d570 Mon Sep 17 00:00:00 2001 From: 4cello Date: Mon, 1 Apr 2024 11:02:39 +0200 Subject: [PATCH 3/8] Removed accordions, added console error message if no/multiple printers with given name --- src/components/TheSelectPrinterDialog.vue | 85 ++++++++++++------- .../settings/SettingsRemotePrintersTab.vue | 17 +--- src/locales/en.json | 2 - 3 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index 7e41977d2..fd128931e 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -83,23 +83,25 @@ dense> - - - - - - - + + + + + + {{ $t('SelectPrinterDialog.AddPrinter') }} @@ -136,26 +138,28 @@ hide-details="auto"> - - - - - - - + + + + + {{ mdiDelete }} + {{ $t('SelectPrinterDialog.UpdatePrinter') }} @@ -253,6 +257,8 @@ import { mdiCancel, mdiCheckboxMarkedCircle, mdiCloseThick, + mdiCog, + mdiCogOff, mdiConnection, mdiDelete, mdiPencil, @@ -278,6 +284,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { port: 0, name: '', } + private showOptionalSettings = false /** * Icons @@ -289,6 +296,8 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { mdiPencil = mdiPencil mdiCheckboxMarkedCircle = mdiCheckboxMarkedCircle mdiCancel = mdiCancel + mdiShowOptional = mdiCog + mdiHideOptional = mdiCogOff get printers() { return this.$store.getters['gui/remoteprinters/getRemoteprinters'] ?? [] @@ -396,6 +405,8 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { this.dialogEditPrinter.id = printer.id ?? '' this.dialogEditPrinter.name = printer.name ?? '' this.dialogEditPrinter.bool = true + + this.showOptionalSettings = printer.name ? printer.name.length > 0 : false } updatePrinter() { @@ -445,11 +456,19 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { mounted() { this.$store.dispatch('gui/remoteprinters/initFromLocalstorage').then(() => { - window.console.log({ printers: this.printers, gui: this.guiIsReady }) if ('printer' in this.$route.query) { - let matching = this.printers.filter((printer) => printer.name === this.$route.query.printer) - if (matching.length > 0) { + let name = this.$route.query.printer + let matching = this.printers.filter((printer) => printer.name === name) + if (matching.length == 0) { + window.console.error( + `No printer with given name '${name}' found. Showing selection dialog instead.` + ) + } else if (matching.length == 1) { this.connect(matching[0]) + } else { + window.console.error( + `Multiple printers with name '${name}' found. Showing selection dialog instead.` + ) } } }) diff --git a/src/components/settings/SettingsRemotePrintersTab.vue b/src/components/settings/SettingsRemotePrintersTab.vue index 528bb2019..ec89321a6 100644 --- a/src/components/settings/SettingsRemotePrintersTab.vue +++ b/src/components/settings/SettingsRemotePrintersTab.vue @@ -66,19 +66,10 @@ dense outlined> - - - - - + + + + {{ $t('Settings.Cancel') }} diff --git a/src/locales/en.json b/src/locales/en.json index 210a1afd7..780c5d18d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -820,7 +820,6 @@ "SelectPrinterDialog": { "AddPrinter": "Add Printer", "AddPrintersToJson": "Please add the Printers to the config.json.", - "AdvancedSettings": "Advanced Settings", "CannotConnectTo": "Cannot connect to {host}.", "ChangePrinter": "Change Printer", "Connecting": "Connecting to {host}", @@ -1062,7 +1061,6 @@ }, "RemotePrintersTab": { "AddPrinter": "Add Printer", - "AdvancedSettings": "Advanced Settings", "EditPrinter": "Edit Printer", "Hostname": "Hostname", "Name": "Name", From 57c5b2b8bf80491dcdf908c87bb44dd1e2a6da34 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 27 Apr 2024 16:41:41 +0200 Subject: [PATCH 4/8] fix: fix connecting issue without a path Signed-off-by: Stefan Dej --- src/store/socket/getters.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/store/socket/getters.ts b/src/store/socket/getters.ts index 1ce9907cb..9d133b03d 100644 --- a/src/store/socket/getters.ts +++ b/src/store/socket/getters.ts @@ -5,7 +5,10 @@ import { RootState } from '@/store/types' export const getters: GetterTree = { getUrl: (state) => { const port = state.port !== 80 ? ':' + state.port : '' - const path = '/' + state.path.replace(/^\/|\/$/g, '') + let path = '/' + state.path.replace(/^\/|\/$/g, '') + + // remove last / in path + if (path.endsWith('/')) path = path.slice(0, -1) return `//${state.hostname}${port}${path}` }, From 53360eb844e4f38fb7985c9de450466b437bc499 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 27 Apr 2024 17:26:33 +0200 Subject: [PATCH 5/8] style: run prettier Signed-off-by: Stefan Dej --- src/components/TheSelectPrinterDialog.vue | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index 9e68a045e..4c42f7c07 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -504,17 +504,13 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { // no printers found with this name if (matching.length == 0) { - window.console.error( - `No printer with given name '${name}' found. Showing selection dialog instead.` - ) + window.console.error(`No printer with given name '${name}' found. Showing selection dialog instead.`) return } // multiple printers found with this name if (matching.length > 1) { - window.console.error( - `Multiple printers with name '${name}' found. Showing selection dialog instead.` - ) + window.console.error(`Multiple printers with name '${name}' found. Showing selection dialog instead.`) return } From c9021be309a7c48716d90a33246485bed1387255 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 27 Apr 2024 17:35:46 +0200 Subject: [PATCH 6/8] fix: check the printer name case-insensitive Signed-off-by: Stefan Dej --- src/components/TheSelectPrinterDialog.vue | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index 4c42f7c07..d23f088f6 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -99,7 +99,7 @@ :label="$t('SelectPrinterDialog.Name')" outlined hide-details="auto" - dense> + dense /> @@ -148,7 +148,7 @@ - + { if (!('printer' in this.$route.query)) return - let name = this.$route.query.printer - let matching = this.printers.filter((printer) => printer.name === name) + let name = this.$route.query.printer.toString().toLowerCase() + let matching = this.printers.filter( + (printer: GuiRemoteprintersStatePrinter) => printer.name?.toLowerCase() === name + ) // no printers found with this name if (matching.length == 0) { From 0951bcdd4fa93d1a4218d7bd000392676e4e3eb8 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 27 Apr 2024 17:37:27 +0200 Subject: [PATCH 7/8] fix: fix TheSelectPrinterDialog advanced settings Signed-off-by: Stefan Dej --- src/components/TheSelectPrinterDialog.vue | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index d23f088f6..abf1f78d8 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -82,7 +82,7 @@ - + - - - + - + - - - + Date: Sat, 27 Apr 2024 17:45:08 +0200 Subject: [PATCH 8/8] fix: display name field only with instancesDB browser or json Signed-off-by: Stefan Dej --- .../settings/SettingsRemotePrintersTab.vue | 12 ++++++++---- src/locales/en.json | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/settings/SettingsRemotePrintersTab.vue b/src/components/settings/SettingsRemotePrintersTab.vue index 5ff81a2f9..96e448fda 100644 --- a/src/components/settings/SettingsRemotePrintersTab.vue +++ b/src/components/settings/SettingsRemotePrintersTab.vue @@ -75,10 +75,14 @@ outlined dense /> - - - - + {{ $t('Settings.Cancel') }} diff --git a/src/locales/en.json b/src/locales/en.json index 02f7399d7..a9999d938 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1068,6 +1068,7 @@ "EditPrinter": "Edit Printer", "Hostname": "Hostname", "Name": "Name", + "NameDescription": "This name will not be displayed in the GUI and will only used for redirects.", "Path": "Path", "Port": "Port", "RemotePrinters": "Printers",