Skip to content

Commit 866b3a3

Browse files
committed
Add support for actually creating that folder on the daemon
1 parent 0b11532 commit 866b3a3

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {ServerApplicationCredentials} from "@/store/types";
2+
import http from "@/api/http";
3+
import {AxiosError, AxiosRequestConfig} from "axios";
4+
import {ServerData} from "@/models/server";
5+
6+
/**
7+
* Connects to the remote daemon and creates a new folder on the server.
8+
*/
9+
export function createFolder(server: ServerData, credentials: ServerApplicationCredentials, path: string): Promise<void> {
10+
const config: AxiosRequestConfig = {
11+
baseURL: credentials.node,
12+
headers: {
13+
'X-Access-Server': server.uuid,
14+
'X-Access-Token': credentials.key,
15+
},
16+
};
17+
18+
return new Promise((resolve, reject) => {
19+
http.post('/v1/server/file/folder', { path }, config)
20+
.then(() => {
21+
resolve();
22+
})
23+
.catch((error: AxiosError) => {
24+
reject(error);
25+
});
26+
});
27+
}

resources/assets/scripts/components/server/components/filemanager/modals/CreateFolderModal.vue

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<Modal :show="visible" v-on:close="onModalClose" :showCloseIcon="false">
2+
<Modal :show="visible" v-on:close="onModalClose" :showCloseIcon="false" :dismissable="!isLoading">
33
<div class="flex items-end">
44
<div class="flex-1">
55
<label class="input-label">
@@ -16,8 +16,15 @@
1616
/>
1717
</div>
1818
<div class="ml-4">
19-
<button class="btn btn-primary btn-sm" type="submit" v-on:submit.prevent="submit">
20-
Create
19+
<button type="submit"
20+
class="btn btn-primary btn-sm"
21+
v-on:click.prevent="submit"
22+
:disabled="errors.any() || isLoading"
23+
>
24+
<span class="spinner white" v-bind:class="{ hidden: !isLoading }">&nbsp;</span>
25+
<span :class="{ hidden: isLoading }">
26+
Create
27+
</span>
2128
</button>
2229
</div>
2330
</div>
@@ -31,17 +38,19 @@
3138
import Vue from 'vue';
3239
import Modal from '@/components/core/Modal.vue';
3340
import {mapState} from "vuex";
41+
import {createFolder} from "@/api/server/files/createFolder";
3442
3543
export default Vue.extend({
3644
name: 'CreateFolderModal',
3745
components: {Modal},
3846
3947
computed: {
40-
...mapState('server', ['fm']),
48+
...mapState('server', ['server', 'credentials', 'fm']),
4149
},
4250
4351
data: function () {
4452
return {
53+
isLoading: false,
4554
visible: false,
4655
folderName: '',
4756
};
@@ -55,19 +64,35 @@
5564
window.events.$on('server:files:open-directory-modal', () => {
5665
this.visible = true;
5766
this.$nextTick(() => {
58-
(this.$refs.folderNameField as HTMLInputElement).focus();
67+
if (this.$refs.folderNameField) {
68+
(this.$refs.folderNameField as HTMLInputElement).focus();
69+
}
5970
});
6071
});
6172
},
6273
74+
beforeDestroy: function () {
75+
window.events.$off('server:files:open-directory-modal');
76+
},
77+
6378
methods: {
6479
submit: function () {
6580
this.$validator.validate().then((result) => {
6681
if (!result) {
6782
return;
6883
}
6984
70-
this.onModalClose();
85+
this.isLoading = true;
86+
87+
console.log(`${this.fm.currentDirectory}/${this.folderName.replace(/^\//, '')}`);
88+
89+
createFolder(this.server, this.credentials, `${this.fm.currentDirectory}/${this.folderName.replace(/^\//, '')}`)
90+
.then(() => {
91+
this.$emit('close');
92+
this.onModalClose();
93+
})
94+
.catch(console.error.bind(this))
95+
.then(() => this.isLoading = false)
7196
});
7297
},
7398

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<a href="#" class="block btn btn-primary btn-sm">New File</a>
4949
</div>
5050
</div>
51-
<CreateFolderModal/>
51+
<CreateFolderModal v-on:close="listDirectory"/>
5252
</div>
5353
</template>
5454

@@ -112,8 +112,6 @@
112112
* Watch the current directory setting and when it changes update the file listing.
113113
*/
114114
currentDirectory: function () {
115-
this.$store.dispatch('server/updateCurrentDirectory', this.currentDirectory);
116-
117115
this.listDirectory();
118116
},
119117
@@ -152,6 +150,8 @@
152150
this.loading = true;
153151
154152
const directory = encodeURI(this.currentDirectory.replace(/^\/|\/$/, ''));
153+
this.$store.dispatch('server/updateCurrentDirectory', `/${directory}`);
154+
155155
getDirectoryContents(this.$route.params.id, directory)
156156
.then((response) => {
157157
this.files = response.files;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
33
import {ActionContext} from "vuex";
44
import {ServerData} from "@/models/server";
5-
import {FileManagerState, ServerApplicationCredentials, ServerState} from "../types";
5+
import {ServerApplicationCredentials, ServerState} from "../types";
66

77
export default {
88
namespaced: true,

0 commit comments

Comments
 (0)