|
1 | 1 | <template> |
2 | 2 | <Modal :show="visible" v-on:close="visible = false"> |
| 3 | + <MessageBox |
| 4 | + class="alert error mb-8" |
| 5 | + title="Error" |
| 6 | + :message="error" |
| 7 | + v-if="error" |
| 8 | + /> |
3 | 9 | <div v-if="object"> |
4 | 10 | <h3 class="font-medium mb-6">Really delete {{ object.name }}?</h3> |
5 | 11 | <p class="text-sm text-neutral-700"> |
6 | | - Deletion is a permanent operation: <strong>{{ object.name }}</strong><span v-if="object.folder">, as well as its contents,</span> will be removed immediately. |
| 12 | + Deletion is a permanent operation: <strong>{{ object.name }}</strong><span v-if="object.directory">, as well as its contents,</span> will be removed immediately. |
7 | 13 | </p> |
8 | 14 | <div class="mt-8 text-right"> |
9 | 15 | <button class="btn btn-secondary btn-sm" v-on:click.prevent="visible = false">Cancel</button> |
10 | | - <button class="btn btn-red btn-sm ml-2">Yes, Delete</button> |
| 16 | + <button class="btn btn-red btn-sm ml-2" v-on:click="deleteItem">Yes, Delete</button> |
11 | 17 | </div> |
12 | 18 | </div> |
13 | 19 | </Modal> |
|
17 | 23 | import Vue from 'vue'; |
18 | 24 | import Modal from '@/components/core/Modal.vue'; |
19 | 25 | import {DirectoryContentObject} from "@/api/server/types"; |
| 26 | + import {deleteElement} from '@/api/server/files/deleteElement'; |
| 27 | + import {mapState} from "vuex"; |
| 28 | + import {AxiosError} from "axios"; |
| 29 | + import { join } from 'path'; |
20 | 30 |
|
21 | 31 | type DataStructure = { |
| 32 | + isLoading: boolean, |
22 | 33 | object: null | DirectoryContentObject, |
23 | 34 | visible: boolean, |
| 35 | + error: string | null, |
24 | 36 | }; |
25 | 37 |
|
26 | 38 | export default Vue.extend({ |
|
29 | 41 |
|
30 | 42 | data: function (): DataStructure { |
31 | 43 | return { |
| 44 | + isLoading: false, |
32 | 45 | visible: false, |
33 | 46 | object: null, |
| 47 | + error: null, |
34 | 48 | }; |
35 | 49 | }, |
36 | 50 |
|
| 51 | + computed: { |
| 52 | + ...mapState('server', ['fm', 'server', 'credentials']), |
| 53 | + }, |
| 54 | +
|
37 | 55 | mounted: function () { |
38 | 56 | window.events.$on('server:files:delete', (object: DirectoryContentObject) => { |
39 | 57 | this.visible = true; |
|
44 | 62 | beforeDestroy: function () { |
45 | 63 | window.events.$off('server:files:delete'); |
46 | 64 | }, |
| 65 | +
|
| 66 | + methods: { |
| 67 | + deleteItem: function () { |
| 68 | + if (!this.object) { |
| 69 | + return; |
| 70 | + } |
| 71 | +
|
| 72 | + this.isLoading = true; |
| 73 | +
|
| 74 | + deleteElement(this.server.uuid, this.credentials, [ |
| 75 | + join(this.fm.currentDirectory, this.object.name) |
| 76 | + ]) |
| 77 | + .then(() => { |
| 78 | + this.$emit('close'); |
| 79 | + this.closeModal(); |
| 80 | + }) |
| 81 | + .catch((error: AxiosError) => { |
| 82 | + this.error = `There was an error deleting the requested ${(this.object && this.object.directory) ? 'folder' : 'file'}. Response was: ${error.message}`; |
| 83 | + console.error('Error at Server::Files::Delete', { error }); |
| 84 | + }) |
| 85 | + .then(() => this.isLoading = false); |
| 86 | + }, |
| 87 | +
|
| 88 | + closeModal: function () { |
| 89 | + this.object = null; |
| 90 | + this.isLoading = false; |
| 91 | + this.visible = false; |
| 92 | + this.error = null; |
| 93 | + }, |
| 94 | + }, |
47 | 95 | }); |
48 | 96 | </script> |
0 commit comments