From 5aa40800c894e2225b623d85679263b0640f0c44 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 10 Mar 2019 18:42:53 -0700 Subject: [PATCH] Add support for copying a file or folder --- .../scripts/api/server/files/copyElement.ts | 19 ++++++ .../scripts/api/server/files/deleteElement.ts | 4 +- .../scripts/components/core/SpinnerModal.vue | 24 ++++++++ .../filemanager/FileContextMenu.vue | 14 ++--- .../server/components/filemanager/FileRow.vue | 9 ++- .../filemanager/modals/CopyFileModal.vue | 58 +++++++++++++++++++ .../server/subpages/FileManager.vue | 3 +- resources/assets/styles/components/modal.css | 4 ++ 8 files changed, 119 insertions(+), 16 deletions(-) create mode 100644 resources/assets/scripts/api/server/files/copyElement.ts create mode 100644 resources/assets/scripts/components/core/SpinnerModal.vue create mode 100644 resources/assets/scripts/components/server/components/filemanager/modals/CopyFileModal.vue diff --git a/resources/assets/scripts/api/server/files/copyElement.ts b/resources/assets/scripts/api/server/files/copyElement.ts new file mode 100644 index 000000000..7b594974d --- /dev/null +++ b/resources/assets/scripts/api/server/files/copyElement.ts @@ -0,0 +1,19 @@ +import {withCredentials} from "@/api/http"; +import {ServerApplicationCredentials} from "@/store/types"; + +/** + * Creates a copy of the given file or directory on the Daemon. Expects a fully resolved path + * to be passed through for both data arguments. + */ +export function copyElement(server: string, credentials: ServerApplicationCredentials, data: { + currentPath: string, newPath: string +}): Promise { + return new Promise((resolve, reject) => { + withCredentials(server, credentials).post('/v1/server/file/copy', { + from: data.currentPath, + to: data.newPath, + }) + .then(() => resolve()) + .catch(reject); + }); +} diff --git a/resources/assets/scripts/api/server/files/deleteElement.ts b/resources/assets/scripts/api/server/files/deleteElement.ts index 2f1da48b2..6cb851396 100644 --- a/resources/assets/scripts/api/server/files/deleteElement.ts +++ b/resources/assets/scripts/api/server/files/deleteElement.ts @@ -5,10 +5,10 @@ import {ServerApplicationCredentials} from "@/store/types"; * Deletes files and/or folders from the server. You should pass through an array of * file or folder paths to be deleted. */ -export function deleteElement(server: string, credentials: ServerApplicationCredentials, items: Array): Promise { +export function deleteElement(server: string, credentials: ServerApplicationCredentials, items: Array): Promise { return new Promise((resolve, reject) => { withCredentials(server, credentials).post('/v1/server/file/delete', { items }) - .then(resolve) + .then(() => resolve()) .catch(reject); }) } diff --git a/resources/assets/scripts/components/core/SpinnerModal.vue b/resources/assets/scripts/components/core/SpinnerModal.vue new file mode 100644 index 000000000..d5ebd8bdd --- /dev/null +++ b/resources/assets/scripts/components/core/SpinnerModal.vue @@ -0,0 +1,24 @@ + + + diff --git a/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue b/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue index b0c16be8b..b8588a633 100644 --- a/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue +++ b/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue @@ -1,7 +1,7 @@ @@ -49,6 +51,7 @@ import {DirectoryContentObject} from "@/api/server/types"; import DeleteFileModal from "@/components/server/components/filemanager/modals/DeleteFileModal.vue"; import RenameModal from "@/components/server/components/filemanager/modals/RenameModal.vue"; + import CopyFileModal from "@/components/server/components/filemanager/modals/CopyFileModal.vue"; type DataStructure = { currentDirectory: string, @@ -58,7 +61,7 @@ export default Vue.extend({ name: 'FileRow', - components: {DeleteFileModal, Icon, FileContextMenu, RenameModal}, + components: {CopyFileModal, DeleteFileModal, Icon, FileContextMenu, RenameModal}, props: { file: { @@ -79,6 +82,7 @@ modals: { rename: false, delete: false, + copy: false, }, }; }, @@ -102,7 +106,6 @@ methods: { showModal: function (name: string) { - console.warn('showModal', name); this.contextMenuVisible = false; Object.keys(this.modals).forEach(k => { diff --git a/resources/assets/scripts/components/server/components/filemanager/modals/CopyFileModal.vue b/resources/assets/scripts/components/server/components/filemanager/modals/CopyFileModal.vue new file mode 100644 index 000000000..b8465656b --- /dev/null +++ b/resources/assets/scripts/components/server/components/filemanager/modals/CopyFileModal.vue @@ -0,0 +1,58 @@ + + + diff --git a/resources/assets/scripts/components/server/subpages/FileManager.vue b/resources/assets/scripts/components/server/subpages/FileManager.vue index b596069f2..f4258a149 100644 --- a/resources/assets/scripts/components/server/subpages/FileManager.vue +++ b/resources/assets/scripts/components/server/subpages/FileManager.vue @@ -37,7 +37,7 @@ :file="file" :editable="editableFiles" v-on:deleted="fileRowDeleted(file, file.directory)" - v-on:renamed="listDirectory" + v-on:list="listDirectory" /> @@ -57,7 +57,6 @@