From be7f7d8da81a334b431bdc7d73bb2ba65917c417 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 16 Feb 2019 17:54:15 -0800 Subject: [PATCH] Add initial support for tracking current FM directory for creating a folder (and other stuff eventually) --- .../filemanager/FileContextMenu.vue | 9 ++++- .../server/components/filemanager/FileRow.vue | 7 +++- .../filemanager/modals/CreateFolderModal.vue | 34 +++++++++++++++++++ .../server/subpages/FileManager.vue | 12 +++++-- .../assets/scripts/store/modules/server.ts | 19 +++++++++-- resources/assets/scripts/store/types.ts | 5 +++ 6 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 resources/assets/scripts/components/server/components/filemanager/modals/CreateFolderModal.vue diff --git a/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue b/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue index 468de6e04..0264c2cc4 100644 --- a/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue +++ b/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue @@ -33,7 +33,7 @@
New File
-
+
@@ -58,5 +58,12 @@ export default Vue.extend({ name: 'FileContextMenu', components: {Icon}, + + methods: { + openFolderModal: function () { + window.events.$emit('server:files:open-directory-modal'); + this.$emit('close'); + } + } }); diff --git a/resources/assets/scripts/components/server/components/filemanager/FileRow.vue b/resources/assets/scripts/components/server/components/filemanager/FileRow.vue index aad283f69..9e9dc2e83 100644 --- a/resources/assets/scripts/components/server/components/filemanager/FileRow.vue +++ b/resources/assets/scripts/components/server/components/filemanager/FileRow.vue @@ -10,7 +10,12 @@
{{formatDate(file.modified)}}
- +
diff --git a/resources/assets/scripts/components/server/components/filemanager/modals/CreateFolderModal.vue b/resources/assets/scripts/components/server/components/filemanager/modals/CreateFolderModal.vue new file mode 100644 index 000000000..34f774f6f --- /dev/null +++ b/resources/assets/scripts/components/server/components/filemanager/modals/CreateFolderModal.vue @@ -0,0 +1,34 @@ + + + diff --git a/resources/assets/scripts/components/server/subpages/FileManager.vue b/resources/assets/scripts/components/server/subpages/FileManager.vue index 2f03d3650..3b9387ab6 100644 --- a/resources/assets/scripts/components/server/subpages/FileManager.vue +++ b/resources/assets/scripts/components/server/subpages/FileManager.vue @@ -42,12 +42,13 @@
New File
+ @@ -58,6 +59,7 @@ import getDirectoryContents from "@/api/server/getDirectoryContents"; import FileRow from "@/components/server/components/filemanager/FileRow.vue"; import FolderRow from "@/components/server/components/filemanager/FolderRow.vue"; + import CreateFolderModal from '../components/filemanager/modals/CreateFolderModal.vue'; type DataStructure = { loading: boolean, @@ -70,7 +72,7 @@ export default Vue.extend({ name: 'FileManager', - components: {FileRow, FolderRow}, + components: {CreateFolderModal, FileRow, FolderRow}, computed: { ...mapState('server', ['server', 'credentials']), ...mapState('socket', ['connected']), @@ -110,6 +112,8 @@ * Watch the current directory setting and when it changes update the file listing. */ currentDirectory: function () { + this.$store.dispatch('server/updateCurrentDirectory', this.currentDirectory); + this.listDirectory(); }, @@ -167,6 +171,10 @@ this.loading = false; }); }, + + openNewFolderModal: function () { + window.events.$emit('server:files:open-directory-modal'); + } }, }); diff --git a/resources/assets/scripts/store/modules/server.ts b/resources/assets/scripts/store/modules/server.ts index c98102885..8864aa045 100644 --- a/resources/assets/scripts/store/modules/server.ts +++ b/resources/assets/scripts/store/modules/server.ts @@ -1,8 +1,8 @@ // @ts-ignore import route from '../../../../../vendor/tightenco/ziggy/src/js/route'; import {ActionContext} from "vuex"; -import {ServerData} from "../../models/server"; -import {ServerApplicationCredentials, ServerState} from "../types"; +import {ServerData} from "@/models/server"; +import {FileManagerState, ServerApplicationCredentials, ServerState} from "../types"; export default { namespaced: true, @@ -10,6 +10,9 @@ export default { server: {}, credentials: {node: '', key: ''}, console: [], + fm: { + currentDirectory: '/', + }, }, getters: {}, actions: { @@ -63,8 +66,20 @@ export default { .catch(reject); }); }, + + /** + * Update the last viewed directory for the server the user is currently viewing. This allows + * us to quickly navigate back to that directory, as well as ensure that actions taken are + * performed aganist the correct directory without having to pass that mess everywhere. + */ + updateCurrentDirectory: ({commit}: ActionContext, directory: string) => { + commit('SET_CURRENT_DIRECTORY', directory); + }, }, mutations: { + SET_CURRENT_DIRECTORY: function (state: ServerState, directory: string) { + state.fm.currentDirectory = directory; + }, SERVER_DATA: function (state: ServerState, data: ServerData) { state.server = data; }, diff --git a/resources/assets/scripts/store/types.ts b/resources/assets/scripts/store/types.ts index 77b1e78a6..01049f60d 100644 --- a/resources/assets/scripts/store/types.ts +++ b/resources/assets/scripts/store/types.ts @@ -19,10 +19,15 @@ export type ServerApplicationCredentials = { key: string, }; +export type FileManagerState = { + currentDirectory: string, +} + export type ServerState = { server: ServerData, credentials: ServerApplicationCredentials, console: Array, + fm: FileManagerState, }; export type DashboardState = {