diff --git a/src/components/TheEditor.vue b/src/components/TheEditor.vue index c1ef7e06..ab5dbe6c 100644 --- a/src/components/TheEditor.vue +++ b/src/components/TheEditor.vue @@ -13,12 +13,7 @@ + :title="title"> + + diff --git a/src/components/panels/GcodefilesPanel.vue b/src/components/panels/GcodefilesPanel.vue index 8110f87a..21e87c4d 100644 --- a/src/components/panels/GcodefilesPanel.vue +++ b/src/components/panels/GcodefilesPanel.vue @@ -1,4 +1,5 @@ + + + + diff --git a/src/components/panels/Status/Jobqueue.vue b/src/components/panels/Status/Jobqueue.vue new file mode 100644 index 00000000..30a0156a --- /dev/null +++ b/src/components/panels/Status/Jobqueue.vue @@ -0,0 +1,213 @@ + + + + + diff --git a/src/components/panels/Status/Printstatus.vue b/src/components/panels/Status/Printstatus.vue new file mode 100644 index 00000000..e84693cb --- /dev/null +++ b/src/components/panels/Status/Printstatus.vue @@ -0,0 +1,28 @@ + + + + + diff --git a/src/components/panels/Status/PrintstatusComplete.vue b/src/components/panels/Status/PrintstatusComplete.vue new file mode 100644 index 00000000..0de1a40b --- /dev/null +++ b/src/components/panels/Status/PrintstatusComplete.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/src/components/panels/Status/PrintstatusPrinting.vue b/src/components/panels/Status/PrintstatusPrinting.vue new file mode 100644 index 00000000..a23eda5b --- /dev/null +++ b/src/components/panels/Status/PrintstatusPrinting.vue @@ -0,0 +1,286 @@ + + + + + diff --git a/src/components/panels/Status/PrintstatusThumbnail.vue b/src/components/panels/Status/PrintstatusThumbnail.vue new file mode 100644 index 00000000..b5dbbf56 --- /dev/null +++ b/src/components/panels/Status/PrintstatusThumbnail.vue @@ -0,0 +1,214 @@ + + + + + diff --git a/src/components/panels/StatusPanel.vue b/src/components/panels/StatusPanel.vue index 5024e4a0..c3783792 100644 --- a/src/components/panels/StatusPanel.vue +++ b/src/components/panels/StatusPanel.vue @@ -1,15 +1,11 @@ - + - - - - - - - - + + + + + {{ $t('Panels.StatusPanel.Status') }} + {{ $t('Panels.StatusPanel.Files') }} + {{ $t('Panels.StatusPanel.Jobqueue', { count: jobsCount }) }} + + + + + + + + + + + + + @@ -324,16 +83,17 @@ diff --git a/src/locales/en.json b/src/locales/en.json index 64106e5f..5415c973 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -121,6 +121,15 @@ "SendCode": "Send code...", "SetupConsole": "Setup Console" }, + "Dialogs": { + "StartPrint": { + "Cancel": "Cancel", + "DoYouWantToStartFilename": "Do you want to start {filename}?", + "Headline": "Start Job", + "Print": "print", + "Timelapse": "Timelapse" + } + }, "Editor": { "Cancel": "Cancel", "ConfigReference": "Config Reference", @@ -156,7 +165,7 @@ "DeleteSelectedQuestion": "Do you really want to delete {count} selected files?", "Download": "Download", "Downloading": "Downloading", - "DoYouWantToStartFilename": "Do you want to start {filename}?", + "DropFilesToAddGcode": "Drag & Drop files to add G-Code.", "EditFile": "Edit File", "Empty": "Empty", "Filament": "Filament", @@ -170,8 +179,12 @@ "FreeDisk": "Free disk", "GCodeFiles": "G-Code Files", "HiddenFiles": "Hidden files", + "LastEndTime": "Last End Time", + "LastFilamentUsed": "Last Filament Used", "LastModified": "Last modified", "LastPrintDuration": "Last Print Duration", + "LastStartTime": "Last Start Time", + "LastTotalDuration": "Last Total Duration", "LayerHeight": "Layer Height", "Name": "Name", "NewDirectory": "New Directory", @@ -551,6 +564,12 @@ }, "Filament": "Filament", "File": "File", + "Files": "Files", + "EmptyGcodes": "No G-Code available.", + "EmptyJobqueue": "There is currently no file in the job queue.", + "Jobqueue": "Jobqueue ({count})", + "JobqueueMoreFiles": "no more jobs | one more job | {count} more jobs", + "PrintTime": "Print Time", "Flow": "Flow", "Headline": "Status", "Layer": "Layer", @@ -563,6 +582,7 @@ "ResumePrint": "Resume print", "Slicer": "Slicer", "Speed": "Speed", + "Status": "Status", "Total": "Total", "Unknown": "Unknown" }, diff --git a/src/store/actions.ts b/src/store/actions.ts index 78549e7c..7fa3caa0 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -5,7 +5,7 @@ import { v4 as uuidv4 } from 'uuid' export const actions: ActionTree = { switchToDashboard() { - router.push('/') + if (router.currentRoute.fullPath !== '/') router.push('/') }, changePrinter({ dispatch, getters, state }, payload) { diff --git a/src/store/editor/actions.ts b/src/store/editor/actions.ts index 07f3da99..7cf655a4 100644 --- a/src/store/editor/actions.ts +++ b/src/store/editor/actions.ts @@ -13,7 +13,15 @@ export const actions: ActionTree = { }, openFile({ state, dispatch, commit, rootGetters, rootState }, payload) { - const fullFilepath = payload.root + payload.path + '/' + payload.filename + const fullFilepathArray = [] + fullFilepathArray.push(payload.root) + let path = payload.path + if (path.slice(0, 1) === '/') path = path.slice(1) + if (path.slice(-1) === '/') path = path.slice(0, -1) + if (path !== '') fullFilepathArray.push(path) + fullFilepathArray.push(payload.filename) + + const fullFilepath = fullFilepathArray.join('/') const url = rootGetters['socket/getUrl'] + '/server/files/' + encodeURI(fullFilepath) + `?${Date.now()}` if (state.cancelToken) dispatch('cancelLoad') @@ -66,7 +74,7 @@ export const actions: ActionTree = { commit('openFile', { filename: payload.filename, fileroot: payload.root, - filepath: payload.path, + filepath: path, file, }) }) diff --git a/src/store/files/getters.ts b/src/store/files/getters.ts index d2aa88f5..27037dd3 100644 --- a/src/store/files/getters.ts +++ b/src/store/files/getters.ts @@ -8,6 +8,7 @@ import { import { GetterTree } from 'vuex' import { FileState, FileStateFile, FileStateGcodefile } from '@/store/files/types' import { ServerHistoryStateJob } from '@/store/server/history/types' +import { ServerJobQueueStateJob } from '@/store/server/jobQueue/types' // eslint-disable-next-line export const getters: GetterTree = { @@ -42,10 +43,31 @@ export const getters: GetterTree = { getGcodeFiles: (state, getters, rootState, rootGetters) => - (path: string, boolShowHiddenFiles: boolean, boolShowPrintedFiles: boolean) => { - const directory = getters['getDirectory']('gcodes' + path) - const baseURL = `${rootGetters['socket/getUrl']}/server/files/gcodes${encodeURI(path)}` - let files = directory?.childrens ?? [] + (path: string | null, boolShowHiddenFiles: boolean, boolShowPrintedFiles: boolean) => { + let baseURL = `${rootGetters['socket/getUrl']}/server/files/gcodes` + let files: FileStateFile[] = [] + + if (path !== null) { + baseURL += encodeURI(path) + const directory = getters['getDirectory']('gcodes' + path) + files = directory?.childrens ?? [] + } else { + const rootGcodes = getters['getDirectory']('gcodes') + + const searchGcodes = (directory: FileStateFile, currentPath: string) => { + if (directory.isDirectory && directory.childrens?.length) { + directory.childrens?.forEach((file) => { + if (!file.isDirectory) { + const tmp = { ...file } + tmp.filename = currentPath + file.filename + files.push(tmp) + } else searchGcodes(file, currentPath + file.filename + '/') + }) + } + } + + searchGcodes(rootGcodes, '') + } files = files.filter((file: FileStateFile) => { // filter hidden files @@ -74,12 +96,18 @@ export const getters: GetterTree = { last_start_time: null, last_end_time: null, last_filament_used: null, - last_status: '', + last_status: null, last_print_duration: null, last_total_duration: null, } if (file.thumbnails?.length) { + let subdirectory = '' + if (path === null) { + const pos = file.filename.lastIndexOf('/') + if (pos > 0) subdirectory = '/' + file.filename.slice(0, pos) + } + const small_thumbnail = file.thumbnails.find( (thumb) => thumb.width >= thumbnailSmallMin && @@ -89,7 +117,7 @@ export const getters: GetterTree = { ) if (small_thumbnail && 'relative_path' in small_thumbnail) { - tmp.small_thumbnail = `${baseURL}/${encodeURI( + tmp.small_thumbnail = `${baseURL + subdirectory}/${encodeURI( small_thumbnail.relative_path )}?timestamp=${fileTimestamp}` } @@ -97,7 +125,7 @@ export const getters: GetterTree = { const big_thumbnail = file.thumbnails.find((thumb) => thumb.width >= thumbnailBigMin) if (big_thumbnail && 'relative_path' in big_thumbnail) { - tmp.big_thumbnail = `${baseURL}/${encodeURI( + tmp.big_thumbnail = `${baseURL + subdirectory}/${encodeURI( big_thumbnail.relative_path )}?timestamp=${fileTimestamp}` @@ -105,35 +133,50 @@ export const getters: GetterTree = { } } - const fullFilename = path.length ? path + '/' + file.filename : file.filename - const histories = rootGetters['server/history/getPrintJobsForGcodes']( + const fullFilename = path && path.length ? path + '/' + file.filename : file.filename + let histories = rootGetters['server/history/getPrintJobsForGcodes']( fullFilename, fileTimestamp, file.size, file.uuid ?? null, file.job_id ) - if (histories && histories.length) { - const history = histories[0] - tmp.last_end_time = new Date(history.end_time * 1000) - tmp.last_filament_used = history.filament_used - tmp.last_print_duration = history.print_duration - tmp.last_start_time = new Date(history.start_time * 1000) - tmp.last_status = history.status - tmp.last_total_duration = history.total_duration - tmp.count_printed = histories.filter( - (job: ServerHistoryStateJob) => job.status === 'completed' - ).length + if (histories && histories.length) { + histories = histories.sort( + (a: ServerHistoryStateJob, b: ServerHistoryStateJob) => b.start_time - a.start_time + ) + + const histories_completed = histories.filter( + (history: ServerHistoryStateJob) => history.status === 'completed' + ) + + const last_history = [...histories].shift() + tmp.last_status = last_history.status + tmp.count_printed = histories_completed.length + tmp.last_start_time = new Date(last_history.start_time * 1000) + + if (tmp.count_printed > 0) { + const history_completed = histories_completed[0] + tmp.last_start_time = new Date(history_completed.start_time * 1000) + tmp.last_end_time = new Date(history_completed.end_time * 1000) + tmp.last_filament_used = history_completed.filament_used + tmp.last_print_duration = history_completed.print_duration + tmp.last_total_duration = history_completed.total_duration + } } if (boolShowPrintedFiles) output.push(tmp) - else if (tmp.last_status !== 'completed') output.push(tmp) + else if (tmp.count_printed === 0) output.push(tmp) }) return output }, + getAllGcodes: (state, getters) => { + return getters['getGcodeFiles'](null, false, true) + }, + getThemeFileUrl: (state, getters, rootState, rootGetters) => (acceptName: string, acceptExtensions: string[]) => { const directory = getters['getDirectory']('config/' + themeDir) @@ -208,4 +251,38 @@ export const getters: GetterTree = { ) !== -1 ) }, + + getSmallThumbnail: (state, getters, rootState, rootGetters) => (item: FileStateFile, currentPath: string) => { + if ('thumbnails' in item && item.thumbnails?.length) { + const thumbnail = item.thumbnails.find( + (thumb) => + thumb.width >= thumbnailSmallMin && + thumb.width <= thumbnailSmallMax && + thumb.height >= thumbnailSmallMin && + thumb.height <= thumbnailSmallMax + ) + + if (thumbnail && 'relative_path' in thumbnail) { + return `${rootGetters['socket/getUrl']}/server/files/${currentPath}/${encodeURI( + thumbnail.relative_path + )}?timestamp=${item.modified.getTime()}` + } + } + + return '' + }, + + getBigThumbnail: (state, getters, rootState, rootGetters) => (item: FileStateFile, currentPath: string) => { + if ('thumbnails' in item && item.thumbnails?.length) { + const thumbnail = item.thumbnails.find((thumb) => thumb.width >= thumbnailBigMin) + + if (thumbnail && 'relative_path' in thumbnail) { + return `${rootGetters['socket/getUrl']}/server/files/${encodeURI(currentPath)}/${encodeURI( + thumbnail.relative_path + )}?timestamp=${item.modified.getTime()}` + } + } + + return '' + }, } diff --git a/src/store/server/history/mutations.ts b/src/store/server/history/mutations.ts index cc7e48f0..188c2fab 100644 --- a/src/store/server/history/mutations.ts +++ b/src/store/server/history/mutations.ts @@ -22,14 +22,15 @@ export const mutations: MutationTree = { }, addJob(state, payload) { - state.jobs.push(payload) + const jobs = [...state.jobs] + jobs.push(payload) + + Vue.set(state, 'jobs', jobs) }, updateJob(state, payload) { const index = state.jobs.findIndex((job) => job.job_id === payload.job_id) - if (index !== -1) { - Vue.set(state.jobs, index, payload) - } + if (index !== -1) Vue.set(state.jobs, index, payload) }, destroyJob(state, payload) { diff --git a/src/store/server/jobQueue/actions.ts b/src/store/server/jobQueue/actions.ts index a571849b..753e015c 100644 --- a/src/store/server/jobQueue/actions.ts +++ b/src/store/server/jobQueue/actions.ts @@ -13,7 +13,7 @@ export const actions: ActionTree = { }, getEvent({ commit }, payload) { - if ('updated_queue' in payload) commit('setQueuedJobs', payload.updated_queue) + if ('updated_queue' in payload && payload.updated_queue !== null) commit('setQueuedJobs', payload.updated_queue) if ('queue_state' in payload) commit('setQueueState', payload.queue_state) }, diff --git a/src/store/server/jobQueue/getters.ts b/src/store/server/jobQueue/getters.ts index a54fe91c..62265776 100644 --- a/src/store/server/jobQueue/getters.ts +++ b/src/store/server/jobQueue/getters.ts @@ -1,6 +1,7 @@ import { GetterTree } from 'vuex' import { ServerJobQueueState, ServerJobQueueStateJob } from '@/store/server/jobQueue/types' import Vue from 'vue' +import { thumbnailBigMin, thumbnailSmallMax, thumbnailSmallMin } from '@/store/variables' // eslint-disable-next-line export const getters: GetterTree = { @@ -19,4 +20,56 @@ export const getters: GetterTree = { return jobs }, + + getSmallThumbnail: (state, getters, rootState, rootGetters) => (item: ServerJobQueueStateJob) => { + if (item?.metadata?.thumbnails?.length) { + const thumbnail = item?.metadata?.thumbnails.find( + (thumb: any) => + thumb.width >= thumbnailSmallMin && + thumb.width <= thumbnailSmallMax && + thumb.height >= thumbnailSmallMin && + thumb.height <= thumbnailSmallMax + ) + const path = + item.filename.lastIndexOf('/') !== -1 + ? 'gcodes/' + item.filename.slice(0, item.filename.lastIndexOf('/')) + : 'gcodes' + + if (thumbnail && 'relative_path' in thumbnail) + return ( + rootGetters['socket/getUrl'] + + '/server/files/' + + path + + '/' + + encodeURI(thumbnail.relative_path) + + '?timestamp=' + + item.metadata?.modified.getTime() + ) + } + + return '' + }, + + getBigThumbnail: (state, getters, rootState, rootGetters) => (item: ServerJobQueueStateJob) => { + if (item?.metadata?.thumbnails?.length) { + const thumbnail = item?.metadata?.thumbnails.find((thumb: any) => thumb.width >= thumbnailBigMin) + const path = + item.filename.lastIndexOf('/') !== -1 + ? 'gcodes/' + item.filename.slice(0, item.filename.lastIndexOf('/')) + : 'gcodes' + + if (thumbnail && 'relative_path' in thumbnail) + return ( + rootGetters['socket/getUrl'] + + '/server/files/' + + path + + '/' + + encodeURI(thumbnail.relative_path) + + '?timestamp=' + + item.metadata?.modified.getTime() + ) + } + + return '' + }, } diff --git a/src/store/server/jobQueue/types.ts b/src/store/server/jobQueue/types.ts index f838c9ae..1b007256 100644 --- a/src/store/server/jobQueue/types.ts +++ b/src/store/server/jobQueue/types.ts @@ -9,4 +9,5 @@ export interface ServerJobQueueStateJob { time_added: number time_in_queue: number metadata?: any + isFirst?: boolean }