diff --git a/src/App.vue b/src/App.vue index 352c6207..73256f32 100644 --- a/src/App.vue +++ b/src/App.vue @@ -16,7 +16,9 @@ background-repeat: no-repeat; } +/*noinspection CssUnusedSymbol*/ .v-btn:not(.v-btn--outlined).primary { + /*noinspection CssUnresolvedCustomProperty*/ color: var(--v-btn-text-primary); } @@ -42,6 +44,8 @@ + + @@ -57,6 +61,8 @@ import TheSelectPrinterDialog from '@/components/TheSelectPrinterDialog.vue' import TheEditor from '@/components/TheEditor.vue' import { panelToolbarHeight, topbarHeight, navigationItemHeight } from '@/store/variables' import TheTimelapseRenderingSnackbar from '@/components/TheTimelapseRenderingSnackbar.vue' +import TheFullscreenUpload from '@/components/TheFullscreenUpload.vue' +import TheUploadSnackbar from '@/components/TheUploadSnackbar.vue' @Component({ components: { @@ -67,6 +73,8 @@ import TheTimelapseRenderingSnackbar from '@/components/TheTimelapseRenderingSna TheUpdateDialog, TheTopbar, TheSidebar, + TheFullscreenUpload, + TheUploadSnackbar, }, metaInfo() { const title = this.$store.getters['getTitle'] @@ -76,10 +84,6 @@ import TheTimelapseRenderingSnackbar from '@/components/TheTimelapseRenderingSna }, }) export default class App extends Mixins(BaseMixin) { - panelToolbarHeight = panelToolbarHeight - topbarHeight = topbarHeight - navigationItemHeight = navigationItemHeight - get title(): string { return this.$store.getters['getTitle'] } @@ -242,21 +246,15 @@ export default class App extends Mixins(BaseMixin) { } else { const favicon = 'data:image/svg+xml;base64,' + - btoa( - '' + - '' + - '' + - '' + - '' + - '' + - '' - ) + window.btoa(` + + + + + + + + `) favicon16.href = favicon favicon32.href = favicon diff --git a/src/assets/styles/toastr.css b/src/assets/styles/toastr.css index fd688082..ea6ce328 100644 --- a/src/assets/styles/toastr.css +++ b/src/assets/styles/toastr.css @@ -13,3 +13,7 @@ .v-toast__text { font-family: 'Roboto', sans-serif; } + +.fullscreenUpload--active .v-toast--bottom { + bottom: 88px; +} diff --git a/src/assets/styles/utils.scss b/src/assets/styles/utils.scss index 187cc036..e190fd76 100644 --- a/src/assets/styles/utils.scss +++ b/src/assets/styles/utils.scss @@ -52,6 +52,10 @@ animation-timing-function: linear; } +.v-toast { + padding: 8px !important; +} + @keyframes spin { from { transform: rotate(0deg); diff --git a/src/components/TheFullscreenUpload.vue b/src/components/TheFullscreenUpload.vue new file mode 100644 index 00000000..84a2f162 --- /dev/null +++ b/src/components/TheFullscreenUpload.vue @@ -0,0 +1,153 @@ + + + + + diff --git a/src/components/TheUploadSnackbar.vue b/src/components/TheUploadSnackbar.vue new file mode 100644 index 00000000..f1821265 --- /dev/null +++ b/src/components/TheUploadSnackbar.vue @@ -0,0 +1,74 @@ + + + diff --git a/src/components/panels/GcodefilesPanel.vue b/src/components/panels/GcodefilesPanel.vue index ebb118fc..8110f87a 100644 --- a/src/components/panels/GcodefilesPanel.vue +++ b/src/components/panels/GcodefilesPanel.vue @@ -7,10 +7,6 @@ cursor: pointer; } -.fileupload-card { - position: relative; -} - .file-list--select-td { width: 20px; } @@ -19,36 +15,6 @@ padding-right: 0 !important; } -.file-list__dragzone { - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - height: 100%; - z-index: 9999999999; - background-color: rgba(0, 0, 0, 0.5); - transition: visibility 175ms, opacity 175ms; - font: bold 42px Oswald, DejaVu Sans, Tahoma, sans-serif; -} - -.file-list__dragzone:before { - display: block; - content: ' '; - position: absolute; - top: 15px; - right: 15px; - bottom: 15px; - left: 15px; - border: 3px dashed white; - border-radius: 15px; -} - -.file-list__dragzone .textnode { - text-align: center; - transition: font-size 175ms; -} - .v-chip.minimum-chip { padding: 0; min-width: 24px; @@ -65,7 +31,7 @@ -
-
{{ $t('Files.DropFilesToAddGcode') }}
-
- - - ({{ uploadSnackbar.number }}/{{ uploadSnackbar.max }}) - - {{ $t('Files.Uploading') + ' ' + uploadSnackbar.filename }} -
- {{ Math.round(uploadSnackbar.percent) }} % @ {{ formatFilesize(Math.round(uploadSnackbar.speed)) }}/s -
- - -
import { Component, Mixins, Watch } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' -import axios from 'axios' import { validGcodeExtensions } from '@/store/variables' import { formatFilesize, formatDate, sortFiles, formatPrintTime } from '@/plugins/helpers' import { FileStateFile, FileStateGcodefile } from '@/store/files/types' @@ -641,7 +586,6 @@ import { } from '@mdi/js' interface draggingFile { - status: boolean item: FileStateGcodefile } @@ -740,7 +684,6 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) { opacity: 0, } private draggingFile: draggingFile = { - status: false, item: { isDirectory: false, filename: '', @@ -1130,171 +1073,61 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) { return this.$store.getters['server/history/getPrintStatusIconColor'](status) } - dragOverUpload(e: Event) { - if (!this.draggingFile.status) { - e.preventDefault() - e.stopPropagation() - - this.dropzone.visibility = 'visible' - this.dropzone.opacity = 1 - } - } - - dragLeaveUpload(e: Event) { - if (!this.draggingFile.status) { - e.preventDefault() - e.stopPropagation() - - this.dropzone.visibility = 'hidden' - this.dropzone.opacity = 0 - } - } - - async dragDropUpload(e: any) { - if (!this.draggingFile.status) { - e.preventDefault() - - this.dropzone.visibility = 'hidden' - this.dropzone.opacity = 0 - - if (e.dataTransfer.files.length) { - const files = [...e.dataTransfer.files].filter((file: File) => { - const format = file.name.slice(file.name.lastIndexOf('.')) - - if (!validGcodeExtensions.includes(format)) { - this.$toast.error(this.$t('Files.WrongFileUploaded', { filename: file.name }).toString()) - - return false - } - - return true - }) - - this.$store.dispatch('socket/addLoading', { name: 'gcodeUpload' }) - let successFiles = [] - this.uploadSnackbar.number = 0 - this.uploadSnackbar.max = files.length - for (const file of files) { - this.uploadSnackbar.number++ - const result = await this.doUploadFile(file) - successFiles.push(result) - } - - this.$store.dispatch('socket/removeLoading', { name: 'gcodeUpload' }) - for (const file of successFiles) { - this.$toast.success(this.$t('Files.SuccessfullyUploaded', { filename: file }).toString()) - } - } - } - } - - doUploadFile(file: File) { - let formData = new FormData() - let filename = file.name - - this.uploadSnackbar.filename = filename - this.uploadSnackbar.status = true - this.uploadSnackbar.percent = 0 - this.uploadSnackbar.speed = 0 - this.uploadSnackbar.lastProgress.loaded = 0 - this.uploadSnackbar.lastProgress.time = 0 - - formData.append('file', file, this.currentPath + '/' + filename) - - return new Promise((resolve) => { - this.uploadSnackbar.cancelTokenSource = axios.CancelToken.source() - axios - .post(this.apiUrl + '/server/files/upload', formData, { - cancelToken: this.uploadSnackbar.cancelTokenSource.token, - headers: { 'Content-Type': 'multipart/form-data' }, - onUploadProgress: (progressEvent: any) => { - this.uploadSnackbar.percent = (progressEvent.loaded * 100) / progressEvent.total - if (this.uploadSnackbar.lastProgress.time) { - const time = progressEvent.timeStamp - this.uploadSnackbar.lastProgress.time - const data = progressEvent.loaded - this.uploadSnackbar.lastProgress.loaded - - if (time) this.uploadSnackbar.speed = data / (time / 1000) - } - - this.uploadSnackbar.lastProgress.time = progressEvent.timeStamp - this.uploadSnackbar.lastProgress.loaded = progressEvent.loaded - this.uploadSnackbar.total = progressEvent.total - }, - }) - .then((result: any) => { - const filename = result.data.item.path.slice(result.data.item.path.indexOf('/') + 1) - this.uploadSnackbar.status = false - resolve(filename) - }) - .catch(() => { - this.uploadSnackbar.status = false - this.$store.dispatch('socket/removeLoading', { name: 'gcodeUpload' }) - this.$toast.error('Cannot upload the file!') - }) - }) - } - dragOverFilelist(e: any, row: any) { - if (this.draggingFile.status) { - e.preventDefault() - //e.stopPropagation() + e.preventDefault() - if (row.isDirectory) { - e.target.parentElement.style.backgroundColor = '#43A04720' - } - } + if (row.isDirectory) e.target.parentElement.style.backgroundColor = '#43A04720' } dragLeaveFilelist(e: any) { - if (this.draggingFile.status) { - e.preventDefault() - e.stopPropagation() + e.preventDefault() + e.stopPropagation() - e.target.parentElement.style.backgroundColor = 'transparent' - } + e.target.parentElement.style.backgroundColor = 'transparent' } async dragDropFilelist(e: any, row: any) { - if (this.draggingFile.status) { - e.preventDefault() - e.target.parentElement.style.backgroundColor = 'transparent' + e.preventDefault() + e.target.parentElement.style.backgroundColor = 'transparent' - let dest = '' - if (row.filename === '..') { - dest = - this.currentPath.substring(0, this.currentPath.lastIndexOf('/') + 1) + - this.draggingFile.item.filename - } else dest = this.currentPath + '/' + row.filename + '/' + this.draggingFile.item.filename + let dest = '' + if (row.filename === '..') { + dest = + this.currentPath.substring(0, this.currentPath.lastIndexOf('/') + 1) + this.draggingFile.item.filename + } else dest = this.currentPath + '/' + row.filename + '/' + this.draggingFile.item.filename - this.$socket.emit( - 'server.files.move', - { - source: 'gcodes' + this.currentPath + '/' + this.draggingFile.item.filename, - dest: 'gcodes' + dest, - }, - { action: 'files/getMove' } - ) - } + this.$socket.emit( + 'server.files.move', + { + source: 'gcodes' + this.currentPath + '/' + this.draggingFile.item.filename, + dest: 'gcodes' + dest, + }, + { action: 'files/getMove' } + ) } async uploadFile() { if (this.$refs.fileUpload.files?.length) { - this.$store.dispatch('socket/addLoading', { name: 'gcodeUpload' }) - let successFiles = [] - this.uploadSnackbar.number = 0 - this.uploadSnackbar.max = this.$refs.fileUpload.files.length - for (const file of this.$refs.fileUpload.files) { - this.uploadSnackbar.number++ - const result = await this.doUploadFile(file) - successFiles.push(result) - } - - this.$store.dispatch('socket/removeLoading', { name: 'gcodeUpload' }) - for (const file of successFiles) { - this.$toast.success(this.$t('Files.SuccessfullyUploaded', { filename: file }).toString()) - } - + const files = [...this.$refs.fileUpload.files] this.$refs.fileUpload.value = '' + + await this.$store.dispatch('socket/addLoading', { name: 'gcodeUpload' }) + await this.$store.dispatch('files/uploadSetCurrentNumber', 0) + await this.$store.dispatch('files/uploadSetMaxNumber', this.$refs.fileUpload.files.length) + for (const file of files) { + await this.$store.dispatch('files/uploadIncrementCurrentNumber') + const path = this.currentPath.slice(0, 1) === '/' ? this.currentPath.slice(1) : this.currentPath + const result = await this.$store.dispatch('files/uploadFile', { + file, + path, + root: 'gcodes', + }) + + if (result !== false) + this.$toast.success(this.$t('Files.SuccessfullyUploaded', { filename: result }).toString()) + } + + await this.$store.dispatch('socket/removeLoading', { name: 'gcodeUpload' }) } } @@ -1385,12 +1218,6 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) { this.$store.dispatch('gui/setGcodefilesMetadata', { name: name, value: value }) } - cancelUpload() { - this.uploadSnackbar.cancelTokenSource.cancel() - this.uploadSnackbar.status = false - this.$refs.fileUpload.value = '' - } - showContextMenu(e: any, item: FileStateFile) { if (!this.contextMenu.shown) { e?.preventDefault() @@ -1521,13 +1348,11 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) { dragFile(e: Event, item: FileStateGcodefile) { e.preventDefault() - this.draggingFile.status = true this.draggingFile.item = item } dragendFile(e: Event) { e.preventDefault() - this.draggingFile.status = false this.draggingFile.item = { isDirectory: false, filename: '', diff --git a/src/components/panels/Machine/ConfigFilesPanel.vue b/src/components/panels/Machine/ConfigFilesPanel.vue index 00f99b3a..892df3ae 100644 --- a/src/components/panels/Machine/ConfigFilesPanel.vue +++ b/src/components/panels/Machine/ConfigFilesPanel.vue @@ -11,12 +11,13 @@ @@ -34,10 +35,10 @@ {{ button.text }} - + @@ -93,7 +94,6 @@ :items="files" class="files-table" :headers="headers" - :options="options" :page.sync="currentPage" :custom-sort="sortFiles" :sort-by.sync="sortBy" @@ -464,7 +464,6 @@ interface uploadSnackbar { } interface draggingFile { - status: boolean item: FileStateFile } @@ -496,8 +495,6 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { inputDialogRenameDirectoryName: HTMLInputElement } - private selected = [] - private options = {} private currentPage = 1 private contextMenu: contextMenu = { shown: false, @@ -572,7 +569,6 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { }, } private draggingFile: draggingFile = { - status: false, item: { isDirectory: false, filename: '', @@ -581,6 +577,14 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { }, } + get blockFileUpload() { + return this.$store.state.gui.view.blockFileUpload ?? false + } + + set blockFileUpload(newVal) { + this.$store.dispatch('gui/saveSettingWithoutUpload', { name: 'view.blockFileUpload', value: newVal }) + } + get toolbarButtons() { return [ { @@ -934,74 +938,30 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { async uploadFile() { if (this.$refs.fileUpload.files?.length) { - this.$store.dispatch('socket/addLoading', { name: 'configFileUpload' }) - let successFiles = [] - this.uploadSnackbar.number = 0 - this.uploadSnackbar.max = this.$refs.fileUpload.files.length - for (const file of this.$refs.fileUpload.files) { - this.uploadSnackbar.number++ - const result = await this.doUploadFile(file) - successFiles.push(result) - } - - this.$store.dispatch('socket/removeLoading', { name: 'configFileUpload' }) - for (const file of successFiles) { - this.$toast.success('Upload of ' + file + ' successful!') - } - + const files = [...this.$refs.fileUpload.files] this.$refs.fileUpload.value = '' + + await this.$store.dispatch('socket/addLoading', { name: 'configFileUpload' }) + await this.$store.dispatch('files/uploadSetCurrentNumber', 0) + await this.$store.dispatch('files/uploadSetMaxNumber', this.$refs.fileUpload.files.length) + + for (const file of files) { + await this.$store.dispatch('files/uploadIncrementCurrentNumber') + const path = this.currentPath.slice(0, 1) === '/' ? this.currentPath.slice(1) : this.currentPath + const result = await this.$store.dispatch('files/uploadFile', { + file, + path, + root: 'config', + }) + + if (result !== false) + this.$toast.success(this.$t('Files.SuccessfullyUploaded', { filename: result }).toString()) + } + + await this.$store.dispatch('socket/removeLoading', { name: 'configFileUpload' }) } } - doUploadFile(file: File) { - let toast = this.$toast - let formData = new FormData() - let filename = file.name.replace(' ', '_') - - this.uploadSnackbar.filename = filename - this.uploadSnackbar.status = true - this.uploadSnackbar.percent = 0 - this.uploadSnackbar.speed = 0 - this.uploadSnackbar.lastProgress.loaded = 0 - this.uploadSnackbar.lastProgress.time = 0 - - formData.append('root', this.root) - formData.append('file', file, this.currentPath + '/' + filename) - this.$store.dispatch('socket/addLoading', { name: 'configFileUpload' }) - - return new Promise((resolve) => { - this.uploadSnackbar.cancelTokenSource = axios.CancelToken.source() - axios - .post(this.apiUrl + '/server/files/upload', formData, { - headers: { 'Content-Type': 'multipart/form-data' }, - cancelToken: this.uploadSnackbar.cancelTokenSource.token, - onUploadProgress: (progressEvent) => { - this.uploadSnackbar.percent = (progressEvent.loaded * 100) / progressEvent.total - if (this.uploadSnackbar.lastProgress.time) { - const time = progressEvent.timeStamp - this.uploadSnackbar.lastProgress.time - const data = progressEvent.loaded - this.uploadSnackbar.lastProgress.loaded - - if (time) this.uploadSnackbar.speed = data / (time / 1000) - } - - this.uploadSnackbar.lastProgress.time = progressEvent.timeStamp - this.uploadSnackbar.lastProgress.loaded = progressEvent.loaded - this.uploadSnackbar.total = progressEvent.total - }, - }) - .then((result) => { - const filename = result.data.item.path.substr(result.data.item.path.indexOf('/') + 1) - this.uploadSnackbar.status = false - resolve(filename) - }) - .catch(() => { - this.uploadSnackbar.status = false - this.$store.dispatch('socket/removeLoading', { name: 'configFileUpload' }) - toast.error('Cannot upload the file!') - }) - }) - } - cancelUpload() { this.uploadSnackbar.cancelTokenSource.cancel() this.uploadSnackbar.status = false @@ -1009,13 +969,13 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { dragFile(e: Event, item: FileStateFile) { e.preventDefault() - this.draggingFile.status = true + this.blockFileUpload = true this.draggingFile.item = item } dragendFile(e: Event) { e.preventDefault() - this.draggingFile.status = false + this.blockFileUpload = false this.draggingFile.item = { isDirectory: false, filename: '', @@ -1025,7 +985,7 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { } dragOverFilelist(e: any, row: any) { - if (this.draggingFile.status) { + if (this.blockFileUpload) { e.preventDefault() //e.stopPropagation() @@ -1034,7 +994,7 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { } dragLeaveFilelist(e: any) { - if (this.draggingFile.status) { + if (this.blockFileUpload) { e.preventDefault() e.stopPropagation() @@ -1043,11 +1003,11 @@ export default class ConfigFilesPanel extends Mixins(BaseMixin) { } async dragDropFilelist(e: any, row: any) { - if (this.draggingFile.status) { + if (this.blockFileUpload) { e.preventDefault() e.target.parentElement.style.backgroundColor = 'transparent' - let dest = '' + let dest: string if (row.filename === '..') { dest = this.absolutePath.slice(1, this.absolutePath.lastIndexOf('/') + 1) + this.draggingFile.item.filename diff --git a/src/locales/de.json b/src/locales/de.json index 40d9eab1..7b6dbcc1 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -205,6 +205,10 @@ "View3D": "3D Betrachtung", "WrongFileUploaded": "Hochladen von {filename} verweigert. Falsches Dateiformat!" }, + "FullscreenUpload": { + "CannotUploadFile": "Datei konnte nicht hochgeladen werden!", + "DropFilesToUploadFiles": "Datei ablegen zum Hochladen" + }, "GCodeViewer": { "ClearLoadedFile": "Löschen", "ColorMode": "Farbmodus", diff --git a/src/locales/en.json b/src/locales/en.json index c1c43045..40dcb7d4 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -157,7 +157,6 @@ "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", @@ -203,6 +202,10 @@ "View3D": "View 3D", "WrongFileUploaded": "Upload was denied for {filename}. Wrong file format!" }, + "FullscreenUpload": { + "CannotUploadFile": "Cannot upload file!", + "DropFilesToUploadFiles": "Drop files to upload" + }, "GCodeViewer": { "ClearLoadedFile": "Clear", "ColorMode": "Color Mode", diff --git a/src/store/files/actions.ts b/src/store/files/actions.ts index 1e1ce919..8326299c 100644 --- a/src/store/files/actions.ts +++ b/src/store/files/actions.ts @@ -10,6 +10,7 @@ import { import { RootState } from '@/store/types' import i18n from '@/plugins/i18n' import { validGcodeExtensions } from '@/store/variables' +import axios from 'axios' export const actions: ActionTree = { reset({ commit }) { @@ -258,4 +259,80 @@ export const actions: ActionTree = { Vue.$toast.success(i18n.t('Files.SuccessfullyDeleted', { filename: delPath })) } }, + + async uploadFile( + { dispatch, commit, rootGetters }, + payload: { file: File; path: string; root: 'gcodes' | 'config' } + ) { + const apiUrl = rootGetters['socket/getUrl'] + const formData = new FormData() + formData.append('file', payload.file, payload.file.name) + formData.append('root', payload.root) + formData.append('path', payload.path) + const cancelTokenSource = axios.CancelToken.source() + + await commit('uploadClearState') + await commit('uploadSetCancelTokenSource', cancelTokenSource) + await commit('uploadSetFilename', payload.file.name) + await commit('uploadSetShow', true) + + let lastTime = 0 + let lastLoaded = 0 + + return new Promise((resolve) => { + axios + .post(apiUrl + '/server/files/upload', formData, { + cancelToken: cancelTokenSource.token, + headers: { 'Content-Type': 'multipart/form-data' }, + onUploadProgress: (progressEvent: any) => { + const percent = (progressEvent.loaded * 100) / progressEvent.total + commit('uploadSetPercent', percent) + + if (lastTime === 0) { + lastTime = progressEvent.timeStamp + lastLoaded = progressEvent.loaded + + return + } + + const time = progressEvent.timeStamp - lastTime + if (time < 1000) return + + const data = progressEvent.loaded - lastLoaded + const speed = data / (time / 1000) + commit('uploadSetSpeed', speed) + + lastTime = progressEvent.timeStamp + lastLoaded = progressEvent.loaded + }, + }) + .then((result: any) => { + commit('uploadSetShow', false) + const lastPos = result.data.item.path.lastIndexOf('/') + const filename = result.data.item.path.slice(lastPos + 1) + resolve(filename) + }) + .catch(() => { + commit('uploadSetShow', false) + Vue.$toast.error(i18n.t('FullscreenUpload.CannotUploadFile').toString()) + resolve(false) + }) + }) + }, + + uploadSetShow({ commit }, payload) { + commit('uploadSetShow', payload) + }, + + uploadSetCurrentNumber({ commit }, payload) { + commit('uploadSetCurrentNumber', payload) + }, + + uploadIncrementCurrentNumber({ state, commit }) { + commit('uploadSetCurrentNumber', state.upload.currentNumber + 1) + }, + + uploadSetMaxNumber({ commit }, payload) { + commit('uploadSetMaxNumber', payload) + }, } diff --git a/src/store/files/index.ts b/src/store/files/index.ts index baee37c0..ec9c8d77 100644 --- a/src/store/files/index.ts +++ b/src/store/files/index.ts @@ -7,6 +7,15 @@ import { getters } from '@/store/files/getters' export const getDefaultState = (): FileState => { return { filetree: [], + upload: { + show: false, + filename: '', + currentNumber: 0, + maxNumber: 0, + cancelTokenSource: null, + percent: 0, + speed: 0, + }, } } diff --git a/src/store/files/mutations.ts b/src/store/files/mutations.ts index 00027fb4..b4f98bab 100644 --- a/src/store/files/mutations.ts +++ b/src/store/files/mutations.ts @@ -255,4 +255,43 @@ export const mutations: MutationTree = { const rootState = state.filetree.find((dir: FileStateFile) => dir.filename === payload.name) if (rootState) Vue.set(rootState, 'permissions', payload.permissions) }, + + uploadClearState(state) { + const upload = { ...state.upload } + upload.show = false + upload.filename = '' + upload.cancelTokenSource = null + upload.speed = 0 + upload.percent = 0 + + Vue.set(state, 'upload', upload) + }, + + uploadSetShow(state, payload) { + Vue.set(state.upload, 'show', payload) + }, + + uploadSetFilename(state, payload) { + Vue.set(state.upload, 'filename', payload) + }, + + uploadSetCancelTokenSource(state, payload) { + Vue.set(state.upload, 'cancelTokenSource', payload) + }, + + uploadSetCurrentNumber(state, payload) { + Vue.set(state.upload, 'currentNumber', payload) + }, + + uploadSetMaxNumber(state, payload) { + Vue.set(state.upload, 'maxNumber', payload) + }, + + uploadSetPercent(state, payload) { + if (state.upload.percent !== payload) Vue.set(state.upload, 'percent', payload) + }, + + uploadSetSpeed(state, payload) { + if (state.upload.speed !== payload) Vue.set(state.upload, 'speed', payload) + }, } diff --git a/src/store/files/types.ts b/src/store/files/types.ts index 2f64aaec..e8d85aa7 100644 --- a/src/store/files/types.ts +++ b/src/store/files/types.ts @@ -1,5 +1,16 @@ +import { CancelTokenSource } from 'axios' + export interface FileState { filetree: FileStateFile[] + upload: { + show: boolean + filename: string + currentNumber: number + maxNumber: number + cancelTokenSource: CancelTokenSource | null + percent: number + speed: number + } } export interface FileStateFile { diff --git a/src/store/gui/index.ts b/src/store/gui/index.ts index 0ecb5d57..381ae77c 100644 --- a/src/store/gui/index.ts +++ b/src/store/gui/index.ts @@ -150,6 +150,7 @@ export const getDefaultState = (): GuiState => { navigationStyle: 'iconsAndText', }, view: { + blockFileUpload: false, configfiles: { countPerPage: 10, sortBy: 'filename', @@ -180,7 +181,7 @@ export const getDefaultState = (): GuiState => { 'last_print_duration', 'slicer', ], - currentPath: 'gcodes', + currentPath: '', selectedFiles: [], }, heightmap: { diff --git a/src/store/gui/types.ts b/src/store/gui/types.ts index 8622b03c..0e66ce53 100644 --- a/src/store/gui/types.ts +++ b/src/store/gui/types.ts @@ -103,6 +103,7 @@ export interface GuiState { navigationStyle: 'iconsAndText' | 'iconsOnly' } view: { + blockFileUpload: boolean configfiles: { countPerPage: number sortBy: string