diff --git a/src/module/alertModal.js b/src/module/alertModal.js index 57f723c..bcddc14 100644 --- a/src/module/alertModal.js +++ b/src/module/alertModal.js @@ -425,3 +425,32 @@ export async function deleteSuccess() { customClass: customClass }) }; +/** + * Really deleted information + * @param {string} files 被刪除的檔案 html + * @param {array} reallyDeldetData 被刪除的檔案 data,未取得 recordId 而傳入 + */ +export async function reallyDeldetInformation(files, reallyDeldetData) { + const filesStore = FilesStore(); + const deleteCustomClass = { ...customClass }; + const htmlText = `

The following file(s) have been deleted by other user(s):

`; + let recordIdData = []; + + deleteCustomClass.confirmButton = '!inline-block !rounded-full !text-sm !font-medium !text-center !align-middle !transition-colors !duration-300 !px-5 !py-2 !w-[100px] !h-[40px] !text-primary !bg-neutral-10 !border !border-primary'; + deleteCustomClass.cancelButton = null; + await Swal.fire({ + title: 'FILE(S) DELETED BY OTHER USER(S)', + html: htmlText, + icon: 'info', + iconColor: '#0099FF', + customClass: deleteCustomClass, + confirmButtonColor: '#ffffff', + didOpen: () => { + const confirmButton = Swal.getConfirmButton(); + + confirmButton.style.border = '1px solid #0099FF'; + } + }); + recordIdData = await Promise.all(reallyDeldetData.map(file => filesStore.deletionRecord(file.id))); + await filesStore.fetchAllFiles(); +} diff --git a/src/stores/files.js b/src/stores/files.js index 1be5c23..3b4fdce 100644 --- a/src/stores/files.js +++ b/src/stores/files.js @@ -259,7 +259,6 @@ export default defineStore('filesStore', { let api; if(id == null || isNaN(id)) { - console.error('Delete File API:', id); return $toast.default('Delete File API Error.', {position: 'bottom'}); }; loading.isLoading = true; @@ -287,6 +286,22 @@ export default defineStore('filesStore', { loading.isLoading = false; } }, + /** + * Remove a Deletion Record,真刪除被 Admin 或被其他帳號刪除的檔案 + */ + async deletionRecord(id) { + let api = ''; + + loading.isLoading = true; + api = `/api/deletion/${id}`; + try { + const response = await axios.delete(api); + } catch(error) { + apiError(error, 'Failed to Remove a Deletion Record.') + } finally { + loading.isLoading = false; + } + }, /** * Download file as CSV * @param { string } type log | filter | log-check | filter-check diff --git a/src/views/Files/index.vue b/src/views/Files/index.vue index 2d60939..19fc4e6 100644 --- a/src/views/Files/index.vue +++ b/src/views/Files/index.vue @@ -223,7 +223,7 @@ import IconVector from '@/components/icons/IconVector.vue'; import IconList from '@/components/icons/IconList.vue'; import IconGrid from '@/components/icons/IconGrid.vue'; - import { renameModal, deleteFileModal } from '@/module/alertModal.js'; + import { renameModal, deleteFileModal, reallyDeldetInformation } from '@/module/alertModal.js'; export default { data() { @@ -318,6 +318,19 @@ isCompareDisabledButton: function() { let result = this.primaryDragData.length === 0 || this.secondaryDragData.length === 0 ? true : false; return result; + }, + /** + * Really deleted information + */ + reallyDeldetData: function() { + let result = []; + + if(this.store.allFiles.length !== 0){ + result = JSON.parse(JSON.stringify(this.store.allFiles)); + result = result.filter(file => file.is_deleted === true); + } + + return result } }, watch: { @@ -331,8 +344,14 @@ }, allFiles: { handler(newValue) { - this.compareData = JSON.parse(JSON.stringify(newValue)); + if(newValue != null) this.compareData = JSON.parse(JSON.stringify(newValue)); } + }, + reallyDeldetData: { + handler(newValue, oldValue) { + if(newValue.length !== 0 && oldValue.length === 0) this.showReallyDeldet(); + }, + immediate: true } }, methods: { @@ -471,6 +490,30 @@ deleteFileModal(srt, this.selectedType, this.selectedId, this.selecteName); srt = ''; }, + /** + * 顯示被 Admin 或被其他帳號刪除的檔案 + */ + showReallyDeldet(){ + let srt = ''; + + if(this.reallyDeldetData.length !== 0) { + this.reallyDeldetData.forEach(file => { + switch (file.type) { + case 'log-check': + file.type = 'rule'; + break; + case 'filter-check': + file.type = 'rule'; + break; + } + + let content = `
  • [${file.type}] ${file.name}
  • `; + srt += content; + }); + } + reallyDeldetInformation(srt, this.reallyDeldetData); + srt = ''; + }, /** * Download file as CSV * @param {string} type