From 66320972be6cbde2acbbaf10ca1517913b6466f8 Mon Sep 17 00:00:00 2001
From: Dane Everitt
Date: Sun, 10 Mar 2019 14:14:47 -0700
Subject: [PATCH] Improve file deletion logic to not require a refresh
---
.../filemanager/FileContextMenu.vue | 3 +-
.../server/components/filemanager/FileRow.vue | 13 ++++-
.../filemanager/modals/DeleteFileModal.vue | 51 +++++++------------
.../server/subpages/FileManager.vue | 11 ++--
4 files changed, 37 insertions(+), 41 deletions(-)
diff --git a/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue b/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue
index f88aca70c..d224f6fae 100644
--- a/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue
+++ b/resources/assets/scripts/components/server/components/filemanager/FileContextMenu.vue
@@ -79,8 +79,7 @@
},
openDeleteModal: function () {
- window.events.$emit('server:files:delete', this.object);
- this.$emit('close');
+ this.$emit('action:delete', this.object);
}
}
});
diff --git a/resources/assets/scripts/components/server/components/filemanager/FileRow.vue b/resources/assets/scripts/components/server/components/filemanager/FileRow.vue
index 2bdc2d6cc..9f9237fb6 100644
--- a/resources/assets/scripts/components/server/components/filemanager/FileRow.vue
+++ b/resources/assets/scripts/components/server/components/filemanager/FileRow.vue
@@ -12,11 +12,13 @@
+
@@ -27,10 +29,11 @@
import {formatDate, readableSize} from '../../../../helpers'
import FileContextMenu from "./FileContextMenu.vue";
import {DirectoryContentObject} from "@/api/server/types";
+ import DeleteFileModal from "@/components/server/components/filemanager/modals/DeleteFileModal.vue";
export default Vue.extend({
name: 'FileRow',
- components: {Icon, FileContextMenu},
+ components: {DeleteFileModal, Icon, FileContextMenu},
props: {
file: {
@@ -46,6 +49,7 @@
data: function () {
return {
contextMenuVisible: false,
+ deleteModalVisible: false,
};
},
@@ -67,6 +71,11 @@
},
methods: {
+ showDeleteFileModal: function () {
+ this.contextMenuVisible = false;
+ this.deleteModalVisible = true;
+ },
+
/**
* Handle a right-click action on a file manager row.
*/
diff --git a/resources/assets/scripts/components/server/components/filemanager/modals/DeleteFileModal.vue b/resources/assets/scripts/components/server/components/filemanager/modals/DeleteFileModal.vue
index 9825a92a6..a6a467924 100644
--- a/resources/assets/scripts/components/server/components/filemanager/modals/DeleteFileModal.vue
+++ b/resources/assets/scripts/components/server/components/filemanager/modals/DeleteFileModal.vue
@@ -13,7 +13,10 @@
-
+
@@ -30,8 +33,6 @@
type DataStructure = {
isLoading: boolean,
- object: null | DirectoryContentObject,
- visible: boolean,
error: string | null,
};
@@ -39,11 +40,20 @@
name: 'DeleteFileModal',
components: {Modal},
+ props: {
+ visible: { type: Boolean, default: false },
+ object: { type: Object as () => DirectoryContentObject, required: true }
+ },
+
+ watch: {
+ visible: function (value: boolean) {
+ this.$emit('update:visible', value);
+ },
+ },
+
data: function (): DataStructure {
return {
isLoading: false,
- visible: false,
- object: null,
error: null,
};
},
@@ -52,45 +62,20 @@
...mapState('server', ['fm', 'server', 'credentials']),
},
- mounted: function () {
- window.events.$on('server:files:delete', (object: DirectoryContentObject) => {
- this.visible = true;
- this.object = object;
- });
- },
-
- beforeDestroy: function () {
- window.events.$off('server:files:delete');
- },
-
methods: {
deleteItem: function () {
- if (!this.object) {
- return;
- }
-
this.isLoading = true;
deleteElement(this.server.uuid, this.credentials, [
join(this.fm.currentDirectory, this.object.name)
])
- .then(() => {
- this.$emit('close');
- this.closeModal();
- })
+ .then(() => this.$emit('deleted'))
.catch((error: AxiosError) => {
- this.error = `There was an error deleting the requested ${(this.object && this.object.directory) ? 'folder' : 'file'}. Response was: ${error.message}`;
- console.error('Error at Server::Files::Delete', { error });
+ this.error = `There was an error deleting the requested ${(this.object.directory) ? 'folder' : 'file'}. Response was: ${error.message}`;
+ console.error('Error at Server::Files::Delete', {error});
})
.then(() => this.isLoading = false);
},
-
- closeModal: function () {
- this.object = null;
- this.isLoading = false;
- this.visible = false;
- this.error = null;
- },
},
});
diff --git a/resources/assets/scripts/components/server/subpages/FileManager.vue b/resources/assets/scripts/components/server/subpages/FileManager.vue
index 437082bf0..99c2b18df 100644
--- a/resources/assets/scripts/components/server/subpages/FileManager.vue
+++ b/resources/assets/scripts/components/server/subpages/FileManager.vue
@@ -32,10 +32,10 @@
Actions
-
+
-
+
@@ -50,7 +50,6 @@
-
@@ -179,7 +178,11 @@
openNewFolderModal: function () {
window.events.$emit('server:files:open-directory-modal');
- }
+ },
+
+ fileRowDeleted: function (file: DirectoryContentObject) {
+ this.files = this.files.filter(data => data !== file);
+ },
},
});