Skip to content

Commit be7f7d8

Browse files
committed
Add initial support for tracking current FM directory for creating a folder (and other stuff eventually)
1 parent 767e466 commit be7f7d8

File tree

6 files changed

+80
-6
lines changed

6 files changed

+80
-6
lines changed

resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</div>
3434
<div class="action">New File</div>
3535
</div>
36-
<div class="context-row">
36+
<div class="context-row" v-on:click="openFolderModal">
3737
<div class="icon">
3838
<Icon name="folder-plus" class="h-4"/>
3939
</div>
@@ -58,5 +58,12 @@
5858
export default Vue.extend({
5959
name: 'FileContextMenu',
6060
components: {Icon},
61+
62+
methods: {
63+
openFolderModal: function () {
64+
window.events.$emit('server:files:open-directory-modal');
65+
this.$emit('close');
66+
}
67+
}
6168
});
6269
</script>

resources/assets/scripts/components/server/components/filemanager/FileRow.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
<div class="flex-1 text-right text-neutral-600">{{formatDate(file.modified)}}</div>
1111
<div class="flex-none w-1/6"></div>
1212
</div>
13-
<FileContextMenu class="context-menu" v-show="contextMenuVisible" ref="contextMenu"/>
13+
<FileContextMenu
14+
class="context-menu"
15+
v-show="contextMenuVisible"
16+
v-on:close="contextMenuVisible = false"
17+
ref="contextMenu"
18+
/>
1419
</div>
1520
</template>
1621

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<Modal :show="visible" v-on:close="visible = false">
3+
<div>
4+
<h2 class="font-medium text-neutral-900 mb-6">{{ fm.currentDirectory }}</h2>
5+
</div>
6+
</Modal>
7+
</template>
8+
9+
<script lang="ts">
10+
import Vue from 'vue';
11+
import Modal from '@/components/core/Modal.vue';
12+
import {mapState} from "vuex";
13+
14+
export default Vue.extend({
15+
name: 'CreateFolderModal',
16+
components: {Modal},
17+
18+
computed: {
19+
...mapState('server', ['fm']),
20+
},
21+
22+
data: function () {
23+
return {
24+
visible: false,
25+
};
26+
},
27+
28+
mounted: function () {
29+
window.events.$on('server:files:open-directory-modal', () => {
30+
this.visible = true;
31+
});
32+
},
33+
});
34+
</script>

resources/assets/scripts/components/server/subpages/FileManager.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
<div class="flex mt-6" v-if="!loading && !errorMessage">
4343
<div class="flex-1"></div>
4444
<div class="mr-4">
45-
<a href="#" class="block btn btn-secondary btn-sm">New Folder</a>
45+
<a href="#" class="block btn btn-secondary btn-sm" v-on:click.prevent="openNewFolderModal">New Folder</a>
4646
</div>
4747
<div>
4848
<a href="#" class="block btn btn-primary btn-sm">New File</a>
4949
</div>
5050
</div>
51+
<CreateFolderModal/>
5152
</div>
5253
</template>
5354

@@ -58,6 +59,7 @@
5859
import getDirectoryContents from "@/api/server/getDirectoryContents";
5960
import FileRow from "@/components/server/components/filemanager/FileRow.vue";
6061
import FolderRow from "@/components/server/components/filemanager/FolderRow.vue";
62+
import CreateFolderModal from '../components/filemanager/modals/CreateFolderModal.vue';
6163
6264
type DataStructure = {
6365
loading: boolean,
@@ -70,7 +72,7 @@
7072
7173
export default Vue.extend({
7274
name: 'FileManager',
73-
components: {FileRow, FolderRow},
75+
components: {CreateFolderModal, FileRow, FolderRow},
7476
computed: {
7577
...mapState('server', ['server', 'credentials']),
7678
...mapState('socket', ['connected']),
@@ -110,6 +112,8 @@
110112
* Watch the current directory setting and when it changes update the file listing.
111113
*/
112114
currentDirectory: function () {
115+
this.$store.dispatch('server/updateCurrentDirectory', this.currentDirectory);
116+
113117
this.listDirectory();
114118
},
115119
@@ -167,6 +171,10 @@
167171
this.loading = false;
168172
});
169173
},
174+
175+
openNewFolderModal: function () {
176+
window.events.$emit('server:files:open-directory-modal');
177+
}
170178
},
171179
});
172180
</script>

resources/assets/scripts/store/modules/server.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
// @ts-ignore
22
import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
33
import {ActionContext} from "vuex";
4-
import {ServerData} from "../../models/server";
5-
import {ServerApplicationCredentials, ServerState} from "../types";
4+
import {ServerData} from "@/models/server";
5+
import {FileManagerState, ServerApplicationCredentials, ServerState} from "../types";
66

77
export default {
88
namespaced: true,
99
state: {
1010
server: {},
1111
credentials: {node: '', key: ''},
1212
console: [],
13+
fm: {
14+
currentDirectory: '/',
15+
},
1316
},
1417
getters: {},
1518
actions: {
@@ -63,8 +66,20 @@ export default {
6366
.catch(reject);
6467
});
6568
},
69+
70+
/**
71+
* Update the last viewed directory for the server the user is currently viewing. This allows
72+
* us to quickly navigate back to that directory, as well as ensure that actions taken are
73+
* performed aganist the correct directory without having to pass that mess everywhere.
74+
*/
75+
updateCurrentDirectory: ({commit}: ActionContext<ServerState, any>, directory: string) => {
76+
commit('SET_CURRENT_DIRECTORY', directory);
77+
},
6678
},
6779
mutations: {
80+
SET_CURRENT_DIRECTORY: function (state: ServerState, directory: string) {
81+
state.fm.currentDirectory = directory;
82+
},
6883
SERVER_DATA: function (state: ServerState, data: ServerData) {
6984
state.server = data;
7085
},

resources/assets/scripts/store/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ export type ServerApplicationCredentials = {
1919
key: string,
2020
};
2121

22+
export type FileManagerState = {
23+
currentDirectory: string,
24+
}
25+
2226
export type ServerState = {
2327
server: ServerData,
2428
credentials: ServerApplicationCredentials,
2529
console: Array<string>,
30+
fm: FileManagerState,
2631
};
2732

2833
export type DashboardState = {

0 commit comments

Comments
 (0)