Skip to content

Commit

Permalink
feat: add ability to add history items to job queue (#1778)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefan Dej <[email protected]>
  • Loading branch information
mdziekon and meteyou authored Feb 15, 2024
1 parent 3b78c3b commit 8e7db0d
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 170 deletions.
120 changes: 120 additions & 0 deletions src/components/dialogs/AddBatchToQueueDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<v-dialog :value="isVisible" :max-width="400" @click:outside="closeDialog" @keydown.esc="closeDialog">
<panel
:title="$t('Files.AddToQueue')"
card-class="gcode-files-add-to-queue-dialog"
:icon="mdiPlaylistPlus"
:margin-bottom="false">
<template #buttons>
<v-btn icon tile @click="closeDialog">
<v-icon>{{ mdiCloseThick }}</v-icon>
</v-btn>
</template>

<v-form v-model="isValid" @submit.prevent="addBatchToQueueAction">
<v-card-text>
<v-text-field
ref="inputFieldAddToQueueCount"
v-model="input"
:label="$t('Files.Count')"
required
hide-spin-buttons
type="number"
:rules="rules.count">
<template #append-outer>
<div class="_spin_button_group">
<v-btn class="mt-n3" icon plain small @click="input++">
<v-icon>{{ mdiChevronUp }}</v-icon>
</v-btn>
<v-btn :disabled="input <= 1" class="mb-n3" icon plain small @click="input--">
<v-icon>{{ mdiChevronDown }}</v-icon>
</v-btn>
</div>
</template>
</v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn text @click="closeDialog">{{ $t('Files.Cancel') }}</v-btn>
<v-btn color="primary" text type="submit" :disabled="!isValid">
{{ $t('Files.AddToQueue') }}
</v-btn>
</v-card-actions>
</v-form>
</panel>
</v-dialog>
</template>

<script lang="ts">
import Component from 'vue-class-component'
import { Mixins, Prop, Watch } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { mdiChevronDown, mdiChevronUp, mdiPlaylistPlus, mdiCloseThick } from '@mdi/js'
@Component
export default class AddBatchToQueueDialog extends Mixins(BaseMixin) {
mdiChevronDown = mdiChevronDown
mdiChevronUp = mdiChevronUp
mdiPlaylistPlus = mdiPlaylistPlus
mdiCloseThick = mdiCloseThick
/**
* Is the dialog currently visible?
*/
@Prop({ type: Boolean, default: false }) declare readonly isVisible: boolean
/**
* Should there be a toast message after the file was added to the queue?
*/
@Prop({ type: Boolean, default: false }) declare readonly showToast: boolean
/**
* Filename of the model to be added to the Queue.
*/
@Prop({ type: String, required: true }) declare readonly filename: string
isValid = false
// because of the text field, the input is always a string
input: string = '1'
rules = {
count: [
(value: string) => !!value || this.$t('JobQueue.InvalidCountEmpty'),
(value: string) => parseInt(value, 10) > 0 || this.$t('JobQueue.InvalidCountGreaterZero'),
],
}
async addBatchToQueueAction() {
const array = Array(parseInt(this.input)).fill(this.filename)
await this.$store.dispatch('server/jobQueue/addToQueue', array)
if (this.showToast)
this.$toast.info(this.$t('History.AddToQueueSuccessful', { filename: this.filename }).toString())
this.closeDialog()
}
closeDialog() {
this.$emit('close')
}
resetFormState() {
this.input = '1'
}
@Watch('isVisible')
isVisibleChanged(newIsVisible: boolean) {
if (newIsVisible) this.resetFormState()
}
}
</script>

<style scoped>
._spin_button_group {
width: 24px;
margin-top: -6px;
margin-left: -6px;
margin-bottom: -6px;
}
</style>
100 changes: 15 additions & 85 deletions src/components/panels/GcodefilesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -568,53 +568,10 @@
</v-card-actions>
</panel>
</v-dialog>
<v-dialog v-model="dialogAddBatchToQueue.show" max-width="400">
<panel
:title="$t('Files.AddToQueue')"
card-class="gcode-files-add-to-queue-dialog"
:icon="mdiPlaylistPlus"
:margin-bottom="false">
<template #buttons>
<v-btn icon tile @click="dialogAddBatchToQueue.show = false">
<v-icon>{{ mdiCloseThick }}</v-icon>
</v-btn>
</template>

<v-card-text>
<v-text-field
ref="inputFieldAddToQueueCount"
v-model="dialogAddBatchToQueue.count"
:label="$t('Files.Count')"
required
hide-spin-buttons
type="number"
:rules="countInputRules"
@keyup.enter="addBatchToQueueAction">
<template #append-outer>
<div class="_spin_button_group">
<v-btn class="mt-n3" icon plain small @click="dialogAddBatchToQueue.count++">
<v-icon>{{ mdiChevronUp }}</v-icon>
</v-btn>
<v-btn
:disabled="dialogAddBatchToQueue.count <= 1"
class="mb-n3"
icon
plain
small
@click="dialogAddBatchToQueue.count--">
<v-icon>{{ mdiChevronDown }}</v-icon>
</v-btn>
</div>
</template>
</v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="" text @click="dialogAddBatchToQueue.show = false">{{ $t('Files.Cancel') }}</v-btn>
<v-btn color="primary" text @click="addBatchToQueueAction">{{ $t('Files.AddToQueue') }}</v-btn>
</v-card-actions>
</panel>
</v-dialog>
<add-batch-to-queue-dialog
:is-visible="dialogAddBatchToQueue.isVisible"
:filename="dialogAddBatchToQueue.filename"
@close="closeAddBatchToQueueDialog" />
</div>
</template>

Expand All @@ -628,8 +585,6 @@ import Panel from '@/components/ui/Panel.vue'
import SettingsRow from '@/components/settings/SettingsRow.vue'
import draggable from 'vuedraggable'
import {
mdiChevronDown,
mdiChevronUp,
mdiDragVertical,
mdiCheckboxBlankOutline,
mdiCheckboxMarked,
Expand All @@ -654,6 +609,7 @@ import {
mdiContentCopy,
} from '@mdi/js'
import StartPrintDialog from '@/components/dialogs/StartPrintDialog.vue'
import AddBatchToQueueDialog from '@/components/dialogs/AddBatchToQueueDialog.vue'
import ControlMixin from '@/components/mixins/control'
import PathNavigation from '@/components/ui/PathNavigation.vue'
Expand All @@ -675,12 +631,6 @@ interface dialogPrintFile {
item: FileStateGcodefile
}
interface dialogAddBatchToQueue {
show: boolean
count: number
item: FileStateGcodefile
}
interface dialogRenameObject {
show: boolean
newName: string
Expand All @@ -698,11 +648,9 @@ interface tableColumnSetting {
}
@Component({
components: { StartPrintDialog, Panel, SettingsRow, PathNavigation, draggable },
components: { StartPrintDialog, AddBatchToQueueDialog, Panel, SettingsRow, PathNavigation, draggable },
})
export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
mdiChevronDown = mdiChevronDown
mdiChevronUp = mdiChevronUp
mdiContentCopy = mdiContentCopy
mdiFile = mdiFile
mdiFileDocumentMultipleOutline = mdiFileDocumentMultipleOutline
Expand Down Expand Up @@ -779,10 +727,9 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
item: { ...this.contextMenu.item },
}
private dialogAddBatchToQueue: dialogAddBatchToQueue = {
show: false,
count: 1,
item: { ...this.contextMenu.item },
dialogAddBatchToQueue: { isVisible: boolean; filename: string } = {
isVisible: false,
filename: '',
}
private dialogRenameFile: dialogRenameObject = {
Expand Down Expand Up @@ -1272,23 +1219,15 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
}
openAddBatchToQueueDialog(item: FileStateGcodefile) {
this.dialogAddBatchToQueue.show = true
this.dialogAddBatchToQueue.count = 1
this.dialogAddBatchToQueue.item = item
}
async addBatchToQueueAction() {
let filename = [this.currentPath, this.dialogAddBatchToQueue.item.filename].join('/')
let filename = [this.currentPath, item.filename].join('/')
if (filename.startsWith('/')) filename = filename.slice(1)
const array: string[] = []
for (let i = 0; i < this.dialogAddBatchToQueue.count; i++) {
array.push(filename)
}
await this.$store.dispatch('server/jobQueue/addToQueue', array)
this.dialogAddBatchToQueue.isVisible = true
this.dialogAddBatchToQueue.filename = filename
}
this.dialogAddBatchToQueue.show = false
closeAddBatchToQueueDialog() {
this.dialogAddBatchToQueue.isVisible = false
}
changeMetadataVisible(name: string, value: boolean) {
Expand Down Expand Up @@ -1549,15 +1488,6 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
}
</script>

<style scoped>
._spin_button_group {
width: 24px;
margin-top: -6px;
margin-left: -6px;
margin-bottom: -6px;
}
</style>

<style>
/*noinspection CssUnusedSymbol*/
.files-table .v-data-table-header__icon {
Expand Down
47 changes: 46 additions & 1 deletion src/components/panels/HistoryListPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@
<v-icon class="mr-1">{{ mdiPrinter }}</v-icon>
{{ $t('History.Reprint') }}
</v-list-item>
<v-list-item
v-if="contextMenu.item.exists && isJobQueueAvailable"
@click="addToQueue(contextMenu.item)">
<v-icon class="mr-1">{{ mdiPlaylistPlus }}</v-icon>
{{ $t('Files.AddToQueue') }}
</v-list-item>
<v-list-item
v-if="contextMenu.item.exists && isJobQueueAvailable"
@click="openAddBatchToQueueDialog(contextMenu.item)">
<v-icon class="mr-1">{{ mdiPlaylistPlus }}</v-icon>
{{ $t('Files.AddBatchToQueue') }}
</v-list-item>
<v-list-item class="red--text" @click="deleteDialog = true">
<v-icon class="mr-1" color="error">{{ mdiDelete }}</v-icon>
{{ $t('History.Delete') }}
Expand Down Expand Up @@ -493,6 +505,11 @@
</v-card-actions>
</panel>
</v-dialog>
<add-batch-to-queue-dialog
:is-visible="dialogAddBatchToQueue.isVisible"
:show-toast="true"
:filename="dialogAddBatchToQueue.filename"
@close="closeAddBatchToQueueDialog" />
</div>
</template>

Expand All @@ -509,6 +526,7 @@ import {
mdiDatabaseArrowDownOutline,
mdiCog,
mdiPrinter,
mdiPlaylistPlus,
mdiTextBoxSearch,
mdiFile,
mdiFileDocumentMultipleOutline,
Expand All @@ -520,15 +538,18 @@ import {
mdiNotebook,
mdiFileCancel,
} from '@mdi/js'
import AddBatchToQueueDialog from '@/components/dialogs/AddBatchToQueueDialog.vue'
@Component({
components: { Panel },
components: { Panel, AddBatchToQueueDialog },
})
export default class HistoryListPanel extends Mixins(BaseMixin) {
mdiDatabaseExportOutline = mdiDatabaseExportOutline
mdiDelete = mdiDelete
mdiDatabaseArrowDownOutline = mdiDatabaseArrowDownOutline
mdiCog = mdiCog
mdiPrinter = mdiPrinter
mdiPlaylistPlus = mdiPlaylistPlus
mdiFileDocumentMultipleOutline = mdiFileDocumentMultipleOutline
mdiTextBoxSearch = mdiTextBoxSearch
mdiFile = mdiFile
Expand Down Expand Up @@ -559,6 +580,11 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
boolShow: false,
}
dialogAddBatchToQueue: { isVisible: boolean; filename: string } = {
isVisible: false,
filename: '',
}
private noteDialog: {
item: ServerHistoryStateJob | null
note: string
Expand Down Expand Up @@ -785,6 +811,10 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
return this.$store.state.gui.general?.language ?? 'en'
}
get isJobQueueAvailable() {
return this.moonrakerComponents.includes('job_queue')
}
refreshHistory() {
this.$store.dispatch('socket/addLoading', { name: 'historyLoadAll' })
Expand Down Expand Up @@ -941,6 +971,21 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
this.$socket.emit('printer.print.start', { filename: item.filename }, { action: 'switchToDashboard' })
}
async addToQueue(item: ServerHistoryStateJob) {
await this.$store.dispatch('server/jobQueue/addToQueue', [item.filename])
this.$toast.info(this.$t('History.AddToQueueSuccessful', { filename: item.filename }).toString())
}
openAddBatchToQueueDialog(item: ServerHistoryStateJob) {
this.dialogAddBatchToQueue.isVisible = true
this.dialogAddBatchToQueue.filename = item.filename
}
closeAddBatchToQueueDialog() {
this.dialogAddBatchToQueue.isVisible = false
}
deleteJob() {
this.$socket.emit(
'server.history.delete_job',
Expand Down
Loading

0 comments on commit 8e7db0d

Please sign in to comment.