Skip to content

Commit

Permalink
Added UI fields for printer name
Browse files Browse the repository at this point in the history
  • Loading branch information
4cello committed Mar 28, 2024
1 parent c859440 commit c00fd56
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/components/TheSelectPrinterDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@
dense></v-text-field>
</v-col>
</v-row>
<sub-panel
:title="$t('SelectPrinterDialog.AdvancedSettings')"
sub-panel-class="add-printer-advanced"
expand="false">
<v-row>
<v-col class="col-6">
<v-text-field
v-model="dialogAddPrinter.name"
:label="$t('SelectPrinterDialog.Name')"
outlined
hide-details="auto"
dense></v-text-field>
</v-col>
</v-row>
</sub-panel>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
Expand Down Expand Up @@ -121,6 +136,21 @@
hide-details="auto"></v-text-field>
</v-col>
</v-row>
<sub-panel
:title="$t('SelectPrinterDialog.AdvancedSettings')"
sub-panel-class="edit-printer-advanced"
expand="false">
<v-row>
<v-col class="col-6">
<v-text-field
v-model="dialogEditPrinter.name"
:label="$t('SelectPrinterDialog.Name')"
outlined
hide-details="auto"
dense></v-text-field>
</v-col>
</v-row>
</sub-panel>
</v-card-text>
<v-card-actions>
<v-btn color="red" icon tile class="minwidth-0 rounded" @click="delPrinter">
Expand Down Expand Up @@ -238,13 +268,15 @@ export default class TheSelectPrinterDialog extends Mixins(BaseMixin) {
bool: false,
hostname: '',
port: 7125,
name: ''
}
private editPrinterValid = false
private dialogEditPrinter = {
bool: false,
id: '',
hostname: '',
port: 0,
name: ''
}
/**
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -345,24 +381,28 @@ 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
}
updatePrinter() {
const values = {
hostname: this.dialogEditPrinter.hostname,
port: this.dialogEditPrinter.port,
name: this.dialogEditPrinter.name
}
this.$store.dispatch('gui/remoteprinters/update', {
id: this.dialogEditPrinter.id,
Expand Down Expand Up @@ -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])
}
}
}
)
}
}
</script>
21 changes: 21 additions & 0 deletions src/components/settings/SettingsRemotePrintersTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@
dense
outlined></v-text-field>
</settings-row>
<sub-panel
:title="$t('Settings.RemotePrintersTab.AdvancedSettings')"
sub-panel-class="remote-printer-advanced"
expand="false">
<settings-row :title="$t('Settings.RemotePrintersTab.Name')">
<v-text-field
v-model="form.name"
:label="$t('Settings.RemotePrintersTab.Name')"
outlined
hide-details="auto"
dense></v-text-field>
</settings-row>
</sub-panel>
</v-card-text>
<v-card-actions class="d-flex justify-end">
<v-btn text @click="form.bool = false">{{ $t('Settings.Cancel') }}</v-btn>
Expand All @@ -91,6 +104,7 @@ interface printerForm {
bool: boolean
hostname: string
port: number
name: string
id: string | null
namespace: string | null
}
Expand All @@ -109,6 +123,7 @@ export default class SettingsRemotePrintersTab extends Mixins(BaseMixin) {
bool: false,
hostname: '',
port: 7125,
name: '',
id: null,
namespace: null,
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -155,20 +173,23 @@ 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
}
updatePrinter() {
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 })
this.form.id = null
this.form.hostname = ''
this.form.port = 7125
this.form.name = ''
this.form.bool = false
}
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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'.",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/store/gui/remoteprinters/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const actions: ActionTree<GuiRemoteprintersState, RootState> = {
printers.push({
hostname: state.printers[id].hostname,
port: state.printers[id].port,
name: state.printers[id].name,
settings: state.printers[id].settings,
})
})
Expand Down Expand Up @@ -84,6 +85,7 @@ export const actions: ActionTree<GuiRemoteprintersState, RootState> = {
id,
hostname: payload.values.hostname ?? '',
port: payload.values.port ?? 7125,
name: payload.values.name
},
{ root: true }
)
Expand Down
1 change: 1 addition & 0 deletions src/store/gui/remoteprinters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface GuiRemoteprintersStatePrinter {
id?: string | null
hostname: string
port: number
name?: string | null
socket?: FarmPrinterStateSocket
settings?: {
[key: string]: any
Expand Down

0 comments on commit c00fd56

Please sign in to comment.