Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't allow to add/update printers with empty hostname #693

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 77 additions & 71 deletions src/components/TheSelectPrinterDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,79 +55,83 @@
</v-card-text>
</template>
<template v-else-if="!isConnecting && dialogAddPrinter.bool">
<v-card-text>
<v-row>
<v-col class="col-8">
<v-text-field
v-model="dialogAddPrinter.hostname"
:rules="[
(v) => !!v || $t('SelectPrinterDialog.HostnameRequired'),
(v) => !v.startsWith('http:') || $t('SelectPrinterDialog.HostnameInvalid'),
(v) => !v.startsWith('https:') || $t('SelectPrinterDialog.HostnameInvalid'),
]"
label="Hostname/IP"
required
outlined
hide-details="auto"
dense></v-text-field>
</v-col>
<v-col class="col-4">
<v-text-field
v-model="dialogAddPrinter.port"
:rules="[(v) => !!v || $t('SelectPrinterDialog.PortRequired')]"
label="Port"
hide-details="auto"
required
outlined
dense></v-text-field>
</v-col>
</v-row>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="primary" text class="middle" @click="addPrinter">
{{ $t('SelectPrinterDialog.AddPrinter') }}
</v-btn>
</v-card-actions>
<v-form v-model="addPrinterValid" @submit.prevent="addPrinter">
<v-card-text>
<v-row>
<v-col class="col-8">
<v-text-field
v-model="dialogAddPrinter.hostname"
:rules="[
(v) => !!v || $t('SelectPrinterDialog.HostnameRequired'),
(v) => !v.startsWith('http:') || $t('SelectPrinterDialog.HostnameInvalid'),
(v) => !v.startsWith('https:') || $t('SelectPrinterDialog.HostnameInvalid'),
]"
:label="$t('SelectPrinterDialog.HostnameIp')"
required
outlined
hide-details="auto"
dense></v-text-field>
</v-col>
<v-col class="col-4">
<v-text-field
v-model="dialogAddPrinter.port"
:rules="[(v) => !!v || $t('SelectPrinterDialog.PortRequired')]"
:label="$t('SelectPrinterDialog.Port')"
hide-details="auto"
required
outlined
dense></v-text-field>
</v-col>
</v-row>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="primary" text class="middle" type="submit" :disabled="!addPrinterValid">
{{ $t('SelectPrinterDialog.AddPrinter') }}
</v-btn>
</v-card-actions>
</v-form>
</template>
<template v-else-if="!isConnecting && dialogEditPrinter.bool">
<v-card-text>
<v-row>
<v-col class="col-8">
<v-text-field
v-model="dialogEditPrinter.hostname"
:rules="[
(v) => !!v || $t('SelectPrinterDialog.HostnameRequired'),
(v) => !v.startsWith('http:') || $t('SelectPrinterDialog.HostnameInvalid'),
(v) => !v.startsWith('https:') || $t('SelectPrinterDialog.HostnameInvalid'),
]"
label="Hostname/IP"
required
outlined
dense
hide-details="auto"></v-text-field>
</v-col>
<v-col class="col-4">
<v-text-field
v-model="dialogEditPrinter.port"
:rules="[(v) => !!v || $t('SelectPrinterDialog.PortRequired')]"
label="Port"
required
outlined
dense
hide-details="auto"></v-text-field>
</v-col>
</v-row>
</v-card-text>
<v-card-actions>
<v-btn color="red" icon tile class="minwidth-0 rounded" @click="delPrinter">
<v-icon small>{{ mdiDelete }}</v-icon>
</v-btn>
<v-spacer></v-spacer>
<v-btn color="primary" text @click="updatePrinter">
{{ $t('SelectPrinterDialog.UpdatePrinter') }}
</v-btn>
</v-card-actions>
<v-form v-model="editPrinterValid" @submit.prevent="updatePrinter">
<v-card-text>
<v-row>
<v-col class="col-8">
<v-text-field
v-model="dialogEditPrinter.hostname"
:rules="[
(v) => !!v || $t('SelectPrinterDialog.HostnameRequired'),
(v) => !v.startsWith('http:') || $t('SelectPrinterDialog.HostnameInvalid'),
(v) => !v.startsWith('https:') || $t('SelectPrinterDialog.HostnameInvalid'),
]"
:label="$t('SelectPrinterDialog.HostnameIp')"
required
outlined
dense
hide-details="auto"></v-text-field>
</v-col>
<v-col class="col-4">
<v-text-field
v-model="dialogEditPrinter.port"
:rules="[(v) => !!v || $t('SelectPrinterDialog.PortRequired')]"
:label="$t('SelectPrinterDialog.Port')"
required
outlined
dense
hide-details="auto"></v-text-field>
</v-col>
</v-row>
</v-card-text>
<v-card-actions>
<v-btn color="red" icon tile class="minwidth-0 rounded" @click="delPrinter">
<v-icon small>{{ mdiDelete }}</v-icon>
</v-btn>
<v-spacer></v-spacer>
<v-btn color="primary" text type="submit" :disabled="!editPrinterValid">
{{ $t('SelectPrinterDialog.UpdatePrinter') }}
</v-btn>
</v-card-actions>
</v-form>
</template>
<template v-else>
<v-card-text class="mt-3">
Expand Down Expand Up @@ -219,11 +223,13 @@ import {
components: { Panel },
})
export default class TheSelectPrinterDialog extends Mixins(BaseMixin) {
private addPrinterValid = false
private dialogAddPrinter = {
bool: false,
hostname: '',
port: 7125,
}
private editPrinterValid = false
private dialogEditPrinter = {
bool: false,
id: '',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
"EditPrinter": "Edit Printer",
"UpdatePrinter": "Update Printer",
"ChangePrinter": "Change Printer",
"HostnameIp": "Hostname/IP",
"Port": "Port",
"HostnameRequired": "Hostname is required",
"HostnameInvalid": "invalid Hostname/IP",
"PortRequired": "Port is required",
Expand Down