diff --git a/src/components/TheSelectPrinterDialog.vue b/src/components/TheSelectPrinterDialog.vue index 235bf2624..abf1f78d8 100644 --- a/src/components/TheSelectPrinterDialog.vue +++ b/src/components/TheSelectPrinterDialog.vue @@ -82,7 +82,7 @@ - + + + + @@ -138,7 +146,7 @@ - + + + + @@ -257,10 +273,10 @@ import { mdiCancel, mdiCheckboxMarkedCircle, mdiCloseThick, - mdiConnection, - mdiDelete, mdiCog, mdiCogOff, + mdiConnection, + mdiDelete, mdiPencil, mdiSync, } from '@mdi/js' @@ -275,6 +291,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { hostname: '', port: 7125, path: '/', + name: '', } editPrinterValid = false dialogEditPrinter = { @@ -283,6 +300,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { hostname: '', port: 0, path: '/', + name: '', } showOptionalSettings = false @@ -327,6 +345,10 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { return this.$store.state.socket.path } + get name() { + return this.$store.state.printer + } + get formatHostname() { return this.hostname + (this.port !== '' ? ':' + this.port : '') + (this.path !== '' ? this.path : '') } @@ -391,12 +413,14 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { hostname: this.dialogAddPrinter.hostname, port: this.dialogAddPrinter.port, path: this.dialogAddPrinter.path, + name: this.dialogAddPrinter.name, } this.$store.dispatch('gui/remoteprinters/store', { values }) this.dialogAddPrinter.hostname = '' this.dialogAddPrinter.bool = false this.dialogAddPrinter.path = '/' + this.dialogAddPrinter.name = '' } editPrinter(printer: GuiRemoteprintersStatePrinter) { @@ -404,7 +428,10 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { this.dialogEditPrinter.port = printer.port this.dialogEditPrinter.id = printer.id ?? '' this.dialogEditPrinter.path = printer.path ?? '/' + this.dialogEditPrinter.name = printer.name ?? '' this.dialogEditPrinter.bool = true + + this.showOptionalSettings = printer.name ? printer.name.length > 0 : false } updatePrinter() { @@ -413,6 +440,7 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { port: this.dialogEditPrinter.port, path: this.dialogEditPrinter.path, id: this.dialogEditPrinter.id, + name: this.dialogEditPrinter.name, } this.$store.dispatch('gui/remoteprinters/update', { id: this.dialogEditPrinter.id, @@ -464,7 +492,28 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) { } mounted() { - this.$store.dispatch('gui/remoteprinters/initFromLocalstorage') + this.$store.dispatch('gui/remoteprinters/initFromLocalstorage').then(() => { + if (!('printer' in this.$route.query)) return + + 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) { + 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.`) + return + } + + this.connect(matching[0]) + }) } } diff --git a/src/components/settings/SettingsRemotePrintersTab.vue b/src/components/settings/SettingsRemotePrintersTab.vue index c15ec255d..96e448fda 100644 --- a/src/components/settings/SettingsRemotePrintersTab.vue +++ b/src/components/settings/SettingsRemotePrintersTab.vue @@ -75,6 +75,14 @@ outlined dense /> + {{ $t('Settings.Cancel') }} @@ -99,6 +107,7 @@ import { mdiCancel, mdiCheckboxMarkedCircle, mdiDelete, mdiPencil, mdiAlertOutli interface printerForm { bool: boolean hostname: string + name: string port: number path: string | null id: string | null @@ -120,6 +129,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { hostname: '', port: 7125, path: '/', + name: '', id: null, namespace: null, } @@ -144,6 +154,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { this.form.hostname = '' this.form.port = 7125 this.form.path = '/' + this.form.name = '' this.form.id = null this.form.namespace = null this.form.bool = true @@ -153,6 +164,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { const printer = { hostname: this.form.hostname, port: this.form.port, + name: this.form.name, path: this.form.path, } @@ -160,6 +172,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { this.form.hostname = '' this.form.port = 7125 + this.form.name = '' this.form.id = null this.form.bool = false } @@ -169,6 +182,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { this.form.hostname = printer.hostname this.form.port = printer.port this.form.path = printer.path ?? '/' + this.form.name = printer.name ?? '' this.form.bool = true } @@ -176,6 +190,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { const values = { hostname: this.form.hostname, port: this.form.port, + name: this.form.name, path: this.form.path, } @@ -185,6 +200,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) { this.form.hostname = '' this.form.port = 7125 this.form.path = '/' + this.form.name = '' this.form.bool = false } diff --git a/src/locales/en.json b/src/locales/en.json index 03afbabeb..a9999d938 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -832,6 +832,7 @@ "HostnameInvalid": "invalid Hostname/IP", "HostnameIp": "Hostname/IP", "HostnameRequired": "Hostname is required", + "Name": "Name", "Path": "Path", "Port": "Port", "PortRequired": "Port is required", @@ -1066,6 +1067,8 @@ "AddPrinter": "Add Printer", "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", diff --git a/src/store/gui/remoteprinters/actions.ts b/src/store/gui/remoteprinters/actions.ts index b966c6876..e06b57f98 100644 --- a/src/store/gui/remoteprinters/actions.ts +++ b/src/store/gui/remoteprinters/actions.ts @@ -55,6 +55,7 @@ export const actions: ActionTree = { printers.push({ hostname: state.printers[id].hostname, port: state.printers[id].port, + name: state.printers[id].name, path: state.printers[id].path, settings: state.printers[id].settings, }) @@ -88,6 +89,7 @@ export const actions: ActionTree = { hostname: payload.values.hostname ?? '', port: payload.values.port ?? 7125, path: payload.values.path ?? '', + name: payload.values.name, }, { root: true } ) diff --git a/src/store/gui/remoteprinters/types.ts b/src/store/gui/remoteprinters/types.ts index d1f366c5b..2b5a59205 100644 --- a/src/store/gui/remoteprinters/types.ts +++ b/src/store/gui/remoteprinters/types.ts @@ -11,6 +11,7 @@ export interface GuiRemoteprintersStatePrinter { hostname: string port: number path?: string | null + name?: string | null socket?: FarmPrinterStateSocket settings?: { [key: string]: any 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}` },