Add support for actually creating that folder on the daemon

This commit is contained in:
Dane Everitt 2019-02-17 13:29:11 -08:00
parent 0b11532a48
commit 866b3a3aac
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 62 additions and 10 deletions

View file

@ -0,0 +1,27 @@
import {ServerApplicationCredentials} from "@/store/types";
import http from "@/api/http";
import {AxiosError, AxiosRequestConfig} from "axios";
import {ServerData} from "@/models/server";
/**
* Connects to the remote daemon and creates a new folder on the server.
*/
export function createFolder(server: ServerData, credentials: ServerApplicationCredentials, path: string): Promise<void> {
const config: AxiosRequestConfig = {
baseURL: credentials.node,
headers: {
'X-Access-Server': server.uuid,
'X-Access-Token': credentials.key,
},
};
return new Promise((resolve, reject) => {
http.post('/v1/server/file/folder', { path }, config)
.then(() => {
resolve();
})
.catch((error: AxiosError) => {
reject(error);
});
});
}

View file

@ -1,5 +1,5 @@
<template> <template>
<Modal :show="visible" v-on:close="onModalClose" :showCloseIcon="false"> <Modal :show="visible" v-on:close="onModalClose" :showCloseIcon="false" :dismissable="!isLoading">
<div class="flex items-end"> <div class="flex items-end">
<div class="flex-1"> <div class="flex-1">
<label class="input-label"> <label class="input-label">
@ -16,8 +16,15 @@
/> />
</div> </div>
<div class="ml-4"> <div class="ml-4">
<button class="btn btn-primary btn-sm" type="submit" v-on:submit.prevent="submit"> <button type="submit"
class="btn btn-primary btn-sm"
v-on:click.prevent="submit"
:disabled="errors.any() || isLoading"
>
<span class="spinner white" v-bind:class="{ hidden: !isLoading }">&nbsp;</span>
<span :class="{ hidden: isLoading }">
Create Create
</span>
</button> </button>
</div> </div>
</div> </div>
@ -31,17 +38,19 @@
import Vue from 'vue'; import Vue from 'vue';
import Modal from '@/components/core/Modal.vue'; import Modal from '@/components/core/Modal.vue';
import {mapState} from "vuex"; import {mapState} from "vuex";
import {createFolder} from "@/api/server/files/createFolder";
export default Vue.extend({ export default Vue.extend({
name: 'CreateFolderModal', name: 'CreateFolderModal',
components: {Modal}, components: {Modal},
computed: { computed: {
...mapState('server', ['fm']), ...mapState('server', ['server', 'credentials', 'fm']),
}, },
data: function () { data: function () {
return { return {
isLoading: false,
visible: false, visible: false,
folderName: '', folderName: '',
}; };
@ -55,11 +64,17 @@
window.events.$on('server:files:open-directory-modal', () => { window.events.$on('server:files:open-directory-modal', () => {
this.visible = true; this.visible = true;
this.$nextTick(() => { this.$nextTick(() => {
if (this.$refs.folderNameField) {
(this.$refs.folderNameField as HTMLInputElement).focus(); (this.$refs.folderNameField as HTMLInputElement).focus();
}
}); });
}); });
}, },
beforeDestroy: function () {
window.events.$off('server:files:open-directory-modal');
},
methods: { methods: {
submit: function () { submit: function () {
this.$validator.validate().then((result) => { this.$validator.validate().then((result) => {
@ -67,7 +82,17 @@
return; return;
} }
this.isLoading = true;
console.log(`${this.fm.currentDirectory}/${this.folderName.replace(/^\//, '')}`);
createFolder(this.server, this.credentials, `${this.fm.currentDirectory}/${this.folderName.replace(/^\//, '')}`)
.then(() => {
this.$emit('close');
this.onModalClose(); this.onModalClose();
})
.catch(console.error.bind(this))
.then(() => this.isLoading = false)
}); });
}, },

View file

@ -48,7 +48,7 @@
<a href="#" class="block btn btn-primary btn-sm">New File</a> <a href="#" class="block btn btn-primary btn-sm">New File</a>
</div> </div>
</div> </div>
<CreateFolderModal/> <CreateFolderModal v-on:close="listDirectory"/>
</div> </div>
</template> </template>
@ -112,8 +112,6 @@
* Watch the current directory setting and when it changes update the file listing. * Watch the current directory setting and when it changes update the file listing.
*/ */
currentDirectory: function () { currentDirectory: function () {
this.$store.dispatch('server/updateCurrentDirectory', this.currentDirectory);
this.listDirectory(); this.listDirectory();
}, },
@ -152,6 +150,8 @@
this.loading = true; this.loading = true;
const directory = encodeURI(this.currentDirectory.replace(/^\/|\/$/, '')); const directory = encodeURI(this.currentDirectory.replace(/^\/|\/$/, ''));
this.$store.dispatch('server/updateCurrentDirectory', `/${directory}`);
getDirectoryContents(this.$route.params.id, directory) getDirectoryContents(this.$route.params.id, directory)
.then((response) => { .then((response) => {
this.files = response.files; this.files = response.files;

View file

@ -2,7 +2,7 @@
import route from '../../../../../vendor/tightenco/ziggy/src/js/route'; import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
import {ActionContext} from "vuex"; import {ActionContext} from "vuex";
import {ServerData} from "@/models/server"; import {ServerData} from "@/models/server";
import {FileManagerState, ServerApplicationCredentials, ServerState} from "../types"; import {ServerApplicationCredentials, ServerState} from "../types";
export default { export default {
namespaced: true, namespaced: true,