Improve file deletion logic to not require a refresh
This commit is contained in:
parent
6b4bf3eaa7
commit
66320972be
4 changed files with 37 additions and 41 deletions
|
@ -79,8 +79,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
openDeleteModal: function () {
|
openDeleteModal: function () {
|
||||||
window.events.$emit('server:files:delete', this.object);
|
this.$emit('action:delete', this.object);
|
||||||
this.$emit('close');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,11 +12,13 @@
|
||||||
</div>
|
</div>
|
||||||
<FileContextMenu
|
<FileContextMenu
|
||||||
class="context-menu"
|
class="context-menu"
|
||||||
v-bind:object="file"
|
:object="file"
|
||||||
v-show="contextMenuVisible"
|
v-show="contextMenuVisible"
|
||||||
v-on:close="contextMenuVisible = false"
|
v-on:close="contextMenuVisible = false"
|
||||||
|
v-on:action:delete="showDeleteFileModal"
|
||||||
ref="contextMenu"
|
ref="contextMenu"
|
||||||
/>
|
/>
|
||||||
|
<DeleteFileModal :visible.sync="deleteModalVisible" :object="file" v-on:deleted="$emit('deleted')" v-on:close="deleteModalVisible = false"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -27,10 +29,11 @@
|
||||||
import {formatDate, readableSize} from '../../../../helpers'
|
import {formatDate, readableSize} from '../../../../helpers'
|
||||||
import FileContextMenu from "./FileContextMenu.vue";
|
import FileContextMenu from "./FileContextMenu.vue";
|
||||||
import {DirectoryContentObject} from "@/api/server/types";
|
import {DirectoryContentObject} from "@/api/server/types";
|
||||||
|
import DeleteFileModal from "@/components/server/components/filemanager/modals/DeleteFileModal.vue";
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
name: 'FileRow',
|
name: 'FileRow',
|
||||||
components: {Icon, FileContextMenu},
|
components: {DeleteFileModal, Icon, FileContextMenu},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
file: {
|
file: {
|
||||||
|
@ -46,6 +49,7 @@
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
contextMenuVisible: false,
|
contextMenuVisible: false,
|
||||||
|
deleteModalVisible: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -67,6 +71,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
showDeleteFileModal: function () {
|
||||||
|
this.contextMenuVisible = false;
|
||||||
|
this.deleteModalVisible = true;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a right-click action on a file manager row.
|
* Handle a right-click action on a file manager row.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,7 +13,10 @@
|
||||||
</p>
|
</p>
|
||||||
<div class="mt-8 text-right">
|
<div class="mt-8 text-right">
|
||||||
<button class="btn btn-secondary btn-sm" v-on:click.prevent="visible = false">Cancel</button>
|
<button class="btn btn-secondary btn-sm" v-on:click.prevent="visible = false">Cancel</button>
|
||||||
<button class="btn btn-red btn-sm ml-2" v-on:click="deleteItem">Yes, Delete</button>
|
<button class="btn btn-red btn-sm ml-2" v-on:click="deleteItem" :disabled="isLoading">
|
||||||
|
<span v-if="isLoading" class="spinner white"> </span>
|
||||||
|
<span v-else>Yes, Delete</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -30,8 +33,6 @@
|
||||||
|
|
||||||
type DataStructure = {
|
type DataStructure = {
|
||||||
isLoading: boolean,
|
isLoading: boolean,
|
||||||
object: null | DirectoryContentObject,
|
|
||||||
visible: boolean,
|
|
||||||
error: string | null,
|
error: string | null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,11 +40,20 @@
|
||||||
name: 'DeleteFileModal',
|
name: 'DeleteFileModal',
|
||||||
components: {Modal},
|
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 {
|
data: function (): DataStructure {
|
||||||
return {
|
return {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
visible: false,
|
|
||||||
object: null,
|
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -52,45 +62,20 @@
|
||||||
...mapState('server', ['fm', 'server', 'credentials']),
|
...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: {
|
methods: {
|
||||||
deleteItem: function () {
|
deleteItem: function () {
|
||||||
if (!this.object) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
|
||||||
deleteElement(this.server.uuid, this.credentials, [
|
deleteElement(this.server.uuid, this.credentials, [
|
||||||
join(this.fm.currentDirectory, this.object.name)
|
join(this.fm.currentDirectory, this.object.name)
|
||||||
])
|
])
|
||||||
.then(() => {
|
.then(() => this.$emit('deleted'))
|
||||||
this.$emit('close');
|
|
||||||
this.closeModal();
|
|
||||||
})
|
|
||||||
.catch((error: AxiosError) => {
|
.catch((error: AxiosError) => {
|
||||||
this.error = `There was an error deleting the requested ${(this.object && this.object.directory) ? 'folder' : 'file'}. Response was: ${error.message}`;
|
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 });
|
console.error('Error at Server::Files::Delete', {error});
|
||||||
})
|
})
|
||||||
.then(() => this.isLoading = false);
|
.then(() => this.isLoading = false);
|
||||||
},
|
},
|
||||||
|
|
||||||
closeModal: function () {
|
|
||||||
this.object = null;
|
|
||||||
this.isLoading = false;
|
|
||||||
this.visible = false;
|
|
||||||
this.error = null;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -32,10 +32,10 @@
|
||||||
<div class="flex-none w-1/6">Actions</div>
|
<div class="flex-none w-1/6">Actions</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="directory in directories">
|
<div v-for="directory in directories">
|
||||||
<FolderRow :directory="directory"/>
|
<FolderRow :directory="directory" :key="directory.name"/>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="file in files">
|
<div v-for="file in files">
|
||||||
<FileRow :file="file" :editable="editableFiles"/>
|
<FileRow :file="file" :editable="editableFiles" v-on:deleted="fileRowDeleted(file)" :key="file.name"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,7 +50,6 @@
|
||||||
</div>
|
</div>
|
||||||
<CreateFolderModal v-on:close="listDirectory"/>
|
<CreateFolderModal v-on:close="listDirectory"/>
|
||||||
<RenameModal/>
|
<RenameModal/>
|
||||||
<DeleteFileModal v-on:close="listDirectory"/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -179,7 +178,11 @@
|
||||||
|
|
||||||
openNewFolderModal: function () {
|
openNewFolderModal: function () {
|
||||||
window.events.$emit('server:files:open-directory-modal');
|
window.events.$emit('server:files:open-directory-modal');
|
||||||
}
|
},
|
||||||
|
|
||||||
|
fileRowDeleted: function (file: DirectoryContentObject) {
|
||||||
|
this.files = this.files.filter(data => data !== file);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue