diff --git a/src/components/dialogs/JobqueueEntryChangeCountDialog.vue b/src/components/dialogs/JobqueueEntryChangeCountDialog.vue new file mode 100644 index 000000000..0cd1d88c6 --- /dev/null +++ b/src/components/dialogs/JobqueueEntryChangeCountDialog.vue @@ -0,0 +1,88 @@ + + diff --git a/src/components/panels/JobqueuePanel.vue b/src/components/panels/JobqueuePanel.vue index b7391e121..8ab308c38 100644 --- a/src/components/panels/JobqueuePanel.vue +++ b/src/components/panels/JobqueuePanel.vue @@ -1,63 +1,53 @@ - diff --git a/src/components/panels/Status/Jobqueue.vue b/src/components/panels/Status/Jobqueue.vue index 7de8ca37b..d1c80bbaa 100644 --- a/src/components/panels/Status/Jobqueue.vue +++ b/src/components/panels/Status/Jobqueue.vue @@ -1,40 +1,19 @@ @@ -42,122 +21,37 @@ import Component from 'vue-class-component' import { Mixins } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' -import { ServerJobQueueStateJob } from '@/store/server/jobQueue/types' -import { mdiFileMultiple } from '@mdi/js' import JobqueueEntry from '@/components/panels/Status/JobqueueEntry.vue' @Component({ components: { JobqueueEntry }, }) export default class StatusPanelJobqueue extends Mixins(BaseMixin) { - mdiFileMultiple = mdiFileMultiple - - private contentTdWidth = 100 - - declare $refs: { - filesJobqueue: any - } - get jobs() { return this.$store.getters['server/jobQueue/getJobs'] ?? [] } - get jobsTable() { - return this.jobs.slice(0, 5) - } - - get jobsRest() { - return this.jobs.slice(5) - } - - get restJobsLength() { - let count = 0 - - this.jobsRest.forEach((item: ServerJobQueueStateJob) => { - count += (item.combinedIds?.length ?? 0) + 1 - }) + get maxLength() { + if (this.jobs.length > 5) return 4 - return count + return 5 } - get descriptionRestJobs() { - let filamentLength = 0 - let filamentWeight = 0 - let printTime = 0 - - this.jobsRest.forEach((item: ServerJobQueueStateJob) => { - const count = (item.combinedIds?.length ?? 0) + 1 - - if (item.metadata?.filament_total) filamentLength += item.metadata?.filament_total * count - if (item.metadata?.filament_weight_total) filamentWeight += item.metadata?.filament_weight_total * count - if (item.metadata?.estimated_time) printTime += item.metadata.estimated_time * count - }) - - let output = '' - - output += this.$t('Files.Filament') + ': ' - if (filamentLength || filamentWeight) { - if (filamentLength) output += filamentLength.toFixed() + ' mm' - if (filamentLength && filamentWeight) output += ' / ' - if (filamentWeight) output += filamentWeight.toFixed(2) + ' g' - } else output += '--' - - output += ', ' + this.$t('Files.PrintTime') + ': ' - if (printTime) output += this.formatPrintTime(printTime) - else output += '--' - - return output + get jobsTable() { + return this.jobs.slice(0, this.maxLength) } - formatPrintTime(totalSeconds: number) { - if (totalSeconds) { - let output = '' - - const days = Math.floor(totalSeconds / (3600 * 24)) - if (days) { - totalSeconds %= 3600 * 24 - output += days + 'd' - } - - const hours = Math.floor(totalSeconds / 3600) - totalSeconds %= 3600 - if (hours) output += ' ' + hours + 'h' - - const minutes = Math.floor(totalSeconds / 60) - if (minutes) output += ' ' + minutes + 'm' - - const seconds = totalSeconds % 60 - if (seconds) output += ' ' + seconds.toFixed(0) + 's' - - return output - } - - return '--' + get jobsRest() { + return this.jobs.slice(this.maxLength) } startJobqueue() { this.$store.dispatch('server/jobQueue/start') } - - mounted() { - setTimeout(() => { - this.calcContentTdWidth() - }, 200) - } - - calcContentTdWidth() { - this.contentTdWidth = this.$refs.filesJobqueue?.$el?.clientWidth - 48 - 48 - 32 - } - - handleResize() { - this.$nextTick(() => { - this.calcContentTdWidth() - }) - } } diff --git a/src/components/panels/Status/JobqueueEntry.vue b/src/components/panels/Status/JobqueueEntry.vue index 6a1a6ea72..0f0fdc90d 100644 --- a/src/components/panels/Status/JobqueueEntry.vue +++ b/src/components/panels/Status/JobqueueEntry.vue @@ -1,116 +1,75 @@ - - diff --git a/src/components/panels/Status/JobqueueEntryRest.vue b/src/components/panels/Status/JobqueueEntryRest.vue new file mode 100644 index 000000000..02d413d8f --- /dev/null +++ b/src/components/panels/Status/JobqueueEntryRest.vue @@ -0,0 +1,120 @@ + + + diff --git a/src/components/panels/StatusPanel.vue b/src/components/panels/StatusPanel.vue index 2c1efcab1..1c68082ea 100644 --- a/src/components/panels/StatusPanel.vue +++ b/src/components/panels/StatusPanel.vue @@ -160,22 +160,22 @@ export default class StatusPanel extends Mixins(BaseMixin) { mdiDotsVertical = mdiDotsVertical mdiAlertOutline = mdiAlertOutline - private boolShowObjects = false - private boolShowPauseAtLayer = false - declare $refs: { bigThumbnail: any } - private activeTab = 'files' - private lastFilename = '' + boolShowObjects = false + boolShowPauseAtLayer = false + + activeTab = 'files' + lastFilename = '' get jobs() { return this.$store.getters['server/jobQueue/getJobs'] } get jobsCount() { - return this.jobs.length ?? 0 + return this.$store.getters['server/jobQueue/getJobsCount'] } get jobQueueBadgeColor() { diff --git a/src/locales/en.json b/src/locales/en.json index 37a803a5b..58639460a 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -198,7 +198,6 @@ "EditFile": "Edit File", "Empty": "Empty", "ExtruderTemp": "Extruder Temp.", - "Filament": "Filament", "FilamentName": "Filament Name", "FilamentType": "Filament Type", "FilamentUsage": "Filament Usage", @@ -390,7 +389,6 @@ "TotalTime": "Total Time" }, "JobQueue": { - "AllJobs": "All Jobs", "Cancel": "Cancel", "ChangeCount": "Change count", "Count": "Count", @@ -398,10 +396,10 @@ "InvalidCountEmpty": "Input must not be empty!", "InvalidCountGreaterZero": "Input must be greater than 0!", "JobQueue": "Job Queue", - "Jobs": "Jobs", "Pause": "Pause", "RemoveFromQueue": "Remove from Queue", - "Start": "Start" + "Start": "Start", + "StartPrint": "Start Job" }, "Machine": { "ConfigFilesPanel": { diff --git a/src/locales/pl.json b/src/locales/pl.json index da91fd503..7887bada8 100644 --- a/src/locales/pl.json +++ b/src/locales/pl.json @@ -388,7 +388,6 @@ "TotalTime": "Całkowity czas druku" }, "JobQueue": { - "AllJobs": "Wszystkie wydruki", "Cancel": "Anuluj", "ChangeCount": "Zmień ilość", "Count": "Ilość", @@ -396,7 +395,6 @@ "InvalidCountEmpty": "Pole wejściowe nie może być puste!", "InvalidCountGreaterZero": "Wprowadzona wartość musi być większa niż 0!", "JobQueue": "Kolejka wydruków", - "Jobs": "Wydruki", "Pause": "Pauza", "RemoveFromQueue": "Usuń z kolejki", "Start": "Start" diff --git a/src/store/server/jobQueue/actions.ts b/src/store/server/jobQueue/actions.ts index 705eb09c8..f8afb3afd 100644 --- a/src/store/server/jobQueue/actions.ts +++ b/src/store/server/jobQueue/actions.ts @@ -18,8 +18,8 @@ export const actions: ActionTree = { }, async getStatus({ commit, dispatch }, payload) { - if ('queued_jobs' in payload) await commit('setQueuedJobs', payload.queued_jobs) - if ('queue_state' in payload) await commit('setQueueState', payload.queue_state) + if ('queued_jobs' in payload) commit('setQueuedJobs', payload.queued_jobs) + if ('queue_state' in payload) commit('setQueueState', payload.queue_state) await dispatch('socket/removeInitModule', 'server/jobQueue/init', { root: true }) }, @@ -28,29 +28,61 @@ export const actions: ActionTree = { Vue.$socket.emit('server.job_queue.post_job', { filenames: filenames }) }, - changeCount({ getters }, payload: { job_id: string; count: number }) { - const filenames: string[] = [] - const jobs = getters['getJobs'] - - jobs.forEach((job: ServerJobQueueStateJob) => { - if (job.job_id === payload.job_id) { - for (let i = 0; i < payload.count; i++) { - filenames.push(job.filename) - } - - return - } - - const count = (job.combinedIds?.length ?? 0) + 1 - for (let i = 0; i < count; i++) { - filenames.push(job.filename) - } - }) - - Vue.$socket.emit('server.job_queue.post_job', { - filenames, - reset: true, - }) + changeCount({ dispatch, getters }, payload: { job_id: string; count: number }) { + const jobs: ServerJobQueueStateJob[] = getters['getJobs'] + + const index = jobs.findIndex((job) => job.job_id === payload.job_id) + if (index === -1) return + + jobs[index].combinedIds = Array(payload.count - 1).fill(payload.job_id) + + dispatch('sendNewQueueList', { jobs }) + }, + + changePosition({ dispatch, getters }, payload: { oldIndex: number; newIndex: number }) { + const jobs: ServerJobQueueStateJob[] = getters['getJobs'] + + const job = jobs.splice(payload.oldIndex, 1)[0] + jobs.splice(payload.newIndex, 0, job) + + dispatch('sendNewQueueList', { jobs }) + }, + + startByJobId({ dispatch, getters }, job_id: string) { + const jobs: ServerJobQueueStateJob[] = getters['getJobs'] + + const index = jobs.findIndex((job) => job.job_id === job_id) + if (index === -1) return + + const job = jobs.splice(index, 1)[0] + jobs.splice(0, 0, job) + + dispatch('sendNewQueueList', { jobs, printStart: true }) + }, + + sendNewQueueList(_, payload: { jobs: ServerJobQueueStateJob[]; printStart?: boolean }) { + const filenames = payload.jobs + .map((job) => { + const numJobs = (job.combinedIds?.length ?? 0) + 1 + // return job.filename if the job will be only printed one time + if (numJobs === 1) return job.filename + + // return an array of job.filename if the job will be printed multiple times + return Array(numJobs).fill(job.filename) + }) + .flat() + + const emitOptions: { action?: string } = {} + if (payload.printStart) emitOptions.action = 'server/jobQueue/start' + + Vue.$socket.emit( + 'server.job_queue.post_job', + { + filenames, + reset: true, + }, + emitOptions + ) }, deleteFromQueue(_, job_ids: string[]) {