feature: save countPerPage from gcode files & config files in gui.json

Signed-off-by: meteyou <meteyou@gmail.com>
This commit is contained in:
meteyou 2020-11-20 20:28:21 +01:00
parent 6c01fc04f8
commit ebaab6324d
4 changed files with 80 additions and 31 deletions

View File

@ -30,9 +30,13 @@
<v-card-title> <v-card-title>
Config Files Config Files
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn color=" ml-4" v-if="currentPath !== '' && currentPath !== '/config_examples'" @click="createFile"><v-icon>mdi-file-plus</v-icon></v-btn> <input type="file" ref="fileUpload" style="display: none" @change="uploadFile" />
<v-btn color=" ml-4" v-if="currentPath !== '' && currentPath !== '/config_examples'" @click="createFolder"><v-icon>mdi-folder-plus</v-icon></v-btn> <v-item-group class="v-btn-toggle">
<v-btn color="primary ml-4" @click="refreshFileList"><v-icon>mdi-refresh</v-icon></v-btn> <v-btn color="" v-if="currentPath !== '' && currentPath !== '/config_examples'" @click="uploadFileButton" :loading="loadings.includes['configFileUpload']"><v-icon>mdi-file-upload</v-icon></v-btn>
<v-btn color="" v-if="currentPath !== '' && currentPath !== '/config_examples'" @click="createFile"><v-icon>mdi-file-plus</v-icon></v-btn>
<v-btn color="" v-if="currentPath !== '' && currentPath !== '/config_examples'" @click="createFolder"><v-icon>mdi-folder-plus</v-icon></v-btn>
<v-btn color="primary" @click="refreshFileList"><v-icon>mdi-refresh</v-icon></v-btn>
</v-item-group>
</v-card-title> </v-card-title>
<v-card-subtitle>Current path: {{ this.currentPath === "" ? "/" : this.currentPath }}</v-card-subtitle> <v-card-subtitle>Current path: {{ this.currentPath === "" ? "/" : this.currentPath }}</v-card-subtitle>
<v-data-table <v-data-table
@ -44,14 +48,14 @@
:custom-sort="sortFiles" :custom-sort="sortFiles"
:sort-by.sync="sortBy" :sort-by.sync="sortBy"
:sort-desc.sync="sortDesc" :sort-desc.sync="sortDesc"
:items-per-page="countPerPage" :items-per-page.sync="countPerPage"
item-key="name"> item-key="name">
<template #no-data> <template #no-data>
<div class="text-center">empty</div> <div class="text-center">empty</div>
</template> </template>
<template v-slot:top v-if="(currentPath !== '')"> <template slot="body.prepend" v-if="(currentPath !== '')">
<tr <tr
class="file-list-cursor" class="file-list-cursor"
@click="clickRowGoBack"> @click="clickRowGoBack">
@ -230,10 +234,18 @@
computed: { computed: {
...mapState({ ...mapState({
filetree: state => state.files.filetree, filetree: state => state.files.filetree,
countPerPage: state => state.gui.settings.configfiles.countPerPage,
hostname: state => state.socket.hostname, hostname: state => state.socket.hostname,
port: state => state.socket.port, port: state => state.socket.port,
}) loadings: state => state.socket.loadings,
}),
countPerPage: {
get: function() {
return this.$store.state.gui.settings.configfiles.countPerPage
},
set: function(newVal) {
return this.$store.dispatch("gui/setSettings", { settings: { configfiles: { countPerPage: newVal } } });
}
},
}, },
created() { created() {
this.loadPath(); this.loadPath();
@ -427,6 +439,34 @@
deleteDirectoryAction: function() { deleteDirectoryAction: function() {
this.$socket.sendObj('server.files.delete_directory', { path: this.currentPath+"/"+this.contextMenu.item.filename }, 'files/getDeleteDir'); this.$socket.sendObj('server.files.delete_directory', { path: this.currentPath+"/"+this.contextMenu.item.filename }, 'files/getDeleteDir');
}, },
uploadFileButton: function() {
this.$refs.fileUpload.click()
},
uploadFile: function() {
if (this.$refs.fileUpload.files.length) {
this.doUploadFile(this.$refs.fileUpload.files[0]).finally(() => {
this.$refs.fileUpload.value = ''
})
}
},
doUploadFile: function(file) {
let toast = this.$toast;
let formData = new FormData();
let filename = file.name.replace(" ", "_");
formData.append('root', 'config');
formData.append('file', file, (this.currentPath+"/"+filename).substring(7));
this.$store.commit('socket/addLoading', { name: 'configFileUpload' });
return axios.post('//' + this.hostname + ':' + this.port + '/server/files/upload',
formData, { headers: { 'Content-Type': 'multipart/form-data' } }
).then((result) => {
this.$store.commit('socket/removeLoading', { name: 'configFileUpload' });
toast.success("Upload of "+result.data.result+" successful!");
}).catch(() => {
this.$store.commit('socket/removeLoading', { name: 'configFileUpload' });
toast.error("Cannot upload the file!");
});
},
}, },
watch: { watch: {
config: { config: {
@ -445,7 +485,7 @@
handler() { handler() {
this.loadPath(); this.loadPath();
} }
}, }
} }
} }
</script> </script>

View File

@ -53,24 +53,26 @@
<v-card-title> <v-card-title>
G-Code Files G-Code Files
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-btn @click="createDirectory"><v-icon class="mr-1">mdi-folder-plus</v-icon> new Directory</v-btn>
<v-btn color="primary ml-4" @click="refreshFileList"><v-icon class="mr-1">mdi-refresh</v-icon> Refresh</v-btn>
<input type="file" ref="fileUpload" style="display: none" @change="uploadFile" /> <input type="file" ref="fileUpload" style="display: none" @change="uploadFile" />
<v-btn class="primary ml-4 " :loading="loadings.includes('gcodeUpload')" @click="clickUploadButton"><v-icon>mdi-upload</v-icon>Upload</v-btn> <v-item-group class="v-btn-toggle" name="controllers">
<v-menu :offset-y="true"> <v-btn @click="clickUploadButton" title="Upload new Gcode" class="primary" :loading="loadings.includes('gcodeUpload')"><v-icon>mdi-upload</v-icon></v-btn>
<template v-slot:activator="{ on, attrs }"> <v-btn @click="createDirectory" title="Create new Directory"><v-icon>mdi-folder-plus</v-icon></v-btn>
<v-btn class="ml-4" v-bind="attrs" v-on="on"><v-icon>mdi-cog</v-icon></v-btn> <v-btn @click="refreshFileList" title="Refresh current Directory"><v-icon>mdi-refresh</v-icon></v-btn>
</template> <v-menu :offset-y="true" title="Setup current list">
<v-list> <template v-slot:activator="{ on, attrs }">
<v-list-item class="minHeight36"> <v-btn class="" v-bind="attrs" v-on="on"><v-icon>mdi-cog</v-icon></v-btn>
<v-checkbox class="mt-0" hide-details v-model="showHiddenFiles" label="Hidden files"></v-checkbox> </template>
</v-list-item> <v-list>
<v-divider></v-divider> <v-list-item class="minHeight36">
<v-list-item class="minHeight36" v-for="header of configHeaders" v-bind:key="header.key"> <v-checkbox class="mt-0" hide-details v-model="showHiddenFiles" label="Hidden files"></v-checkbox>
<v-checkbox class="mt-0" hide-details v-model="header.visible" @change="changeMetadataVisible(header.value)" :label="header.text"></v-checkbox> </v-list-item>
</v-list-item> <v-divider></v-divider>
</v-list> <v-list-item class="minHeight36" v-for="header of configHeaders" v-bind:key="header.key">
</v-menu> <v-checkbox class="mt-0" hide-details v-model="header.visible" @change="changeMetadataVisible(header.value)" :label="header.text"></v-checkbox>
</v-list-item>
</v-list>
</v-menu>
</v-item-group>
</v-card-title> </v-card-title>
<v-card-subtitle>Current path: {{ this.currentPath !== 'gcodes' ? "/"+this.currentPath.substring(7) : "/" }}</v-card-subtitle> <v-card-subtitle>Current path: {{ this.currentPath !== 'gcodes' ? "/"+this.currentPath.substring(7) : "/" }}</v-card-subtitle>
<v-card-text> <v-card-text>
@ -90,7 +92,7 @@
:custom-sort="sortFiles" :custom-sort="sortFiles"
:sort-by.sync="sortBy" :sort-by.sync="sortBy"
:sort-desc.sync="sortDesc" :sort-desc.sync="sortDesc"
:items-per-page="countPerPage" :items-per-page.sync="countPerPage"
item-key="name" item-key="name"
:search="search" :search="search"
:custom-filter="advancedSearch" :custom-filter="advancedSearch"
@ -298,7 +300,6 @@
computed: { computed: {
...mapState({ ...mapState({
filetree: state => state.files.filetree, filetree: state => state.files.filetree,
countPerPage: state => state.gui.gcodefiles.countPerPage,
hostname: state => state.socket.hostname, hostname: state => state.socket.hostname,
port: state => state.socket.port, port: state => state.socket.port,
loadings: state => state.socket.loadings, loadings: state => state.socket.loadings,
@ -319,9 +320,17 @@
return this.$store.state.gui.gcodefiles.showHiddenFiles; return this.$store.state.gui.gcodefiles.showHiddenFiles;
}, },
set: function(newVal) { set: function(newVal) {
return this.$store.dispatch("gui/setGcodefilesShowHiddenFiles", newVal); return this.$store.dispatch("gui/setSettings", { gcodefiles: { showHiddenFiles: newVal } });
} }
} },
countPerPage: {
get: function() {
return this.$store.state.gui.gcodefiles.countPerPage
},
set: function(newVal) {
return this.$store.dispatch("gui/setSettings", { gcodefiles: { countPerPage: newVal } });
}
},
}, },
created() { created() {
this.loadPath() this.loadPath()

View File

@ -12,7 +12,8 @@ export default {
getMetadata({ commit, rootState }, payload) { getMetadata({ commit, rootState }, payload) {
if (payload !== undefined && payload.filename !== "") { if (payload !== undefined && payload.filename !== "") {
if (payload.filename === rootState.printer.print_stats.filename) { if (payload.filename === rootState.printer.print_stats.filename) {
this.commit('getMetadataCurrentFile', payload); commit('printer/clearCurrentFile', null, { root: true });
commit('printer/setData', { current_file: payload }, { root: true });
} }
commit('setMetadata', payload); commit('setMetadata', payload);

View File

@ -33,7 +33,6 @@ export default {
Vue.set(state.gcodefiles.showMetadata, data.name, data.value) Vue.set(state.gcodefiles.showMetadata, data.name, data.value)
}, },
setGcodefilesShowHiddenFiles(state, value) { setGcodefilesShowHiddenFiles(state, value) {
Vue.set(state.gcodefiles, "showHiddenFiles", value) Vue.set(state.gcodefiles, "showHiddenFiles", value)
}, },