feat: Files Delete File done.
This commit is contained in:
@@ -253,7 +253,6 @@ export async function uploadSuccess() {
|
|||||||
*/
|
*/
|
||||||
export async function uploadConfirm(fetchData) {
|
export async function uploadConfirm(fetchData) {
|
||||||
const filesStore = FilesStore();
|
const filesStore = FilesStore();
|
||||||
|
|
||||||
const result = await Swal.fire({
|
const result = await Swal.fire({
|
||||||
title: 'ARE YOU SURE?',
|
title: 'ARE YOU SURE?',
|
||||||
html: 'After uploading, you won’t be able to modify labels.',
|
html: 'After uploading, you won’t be able to modify labels.',
|
||||||
@@ -266,13 +265,10 @@ export async function uploadConfirm(fetchData) {
|
|||||||
cancelButtonText: 'No',
|
cancelButtonText: 'No',
|
||||||
cancelButtonColor: '#94a3b8',
|
cancelButtonColor: '#94a3b8',
|
||||||
customClass: customClass,
|
customClass: customClass,
|
||||||
})
|
});
|
||||||
|
|
||||||
if(result.isConfirmed) {
|
if(result.isConfirmed) {
|
||||||
filesStore.uploadLog(fetchData);
|
filesStore.uploadLog(fetchData);
|
||||||
} else if(result.dismiss === 'cancel') {
|
|
||||||
// 什麼都不做
|
|
||||||
} else if(result.dismiss === 'backdrop') {
|
|
||||||
// 什麼都不做
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -326,10 +322,10 @@ export async function renameModal(rename, type, id) {
|
|||||||
*/
|
*/
|
||||||
export async function deleteFileModal(files, type, id) {
|
export async function deleteFileModal(files, type, id) {
|
||||||
const filesStore = FilesStore();
|
const filesStore = FilesStore();
|
||||||
|
let htmlText = files.length === 0 ? '' : `<div class=" w-[227px] text-left mx-auto space-y-1"><p>All related files will be deleted.</p><p>List of file(s) to delete: </p><ul class="list-disc ml-6">${files}</ul></div>`;
|
||||||
const result = await Swal.fire({
|
const result = await Swal.fire({
|
||||||
title: 'ARE YOU SURE?',
|
title: 'ARE YOU SURE?',
|
||||||
html: '<div class=" w-[227px] text-left mx-auto space-y-1"><p>All related files will be deleted.</p><p>List of file(s) to delete: </p><ul class="list-disc ml-6"><li>[log] Taipower 001</li><li>[filter] Filter0401 - Taipower 001 Filter0401 - Taipower 001 Filter0401 - Taipower 001</li><li>[rule] 1224 - Taipower 001</li></ul></div>',
|
html: htmlText,
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
iconColor: '#FF3366',
|
iconColor: '#FF3366',
|
||||||
reverseButtons:true,
|
reverseButtons:true,
|
||||||
@@ -339,12 +335,9 @@ export async function deleteFileModal(files, type, id) {
|
|||||||
cancelButtonText: 'No',
|
cancelButtonText: 'No',
|
||||||
cancelButtonColor: '#94a3b8',
|
cancelButtonColor: '#94a3b8',
|
||||||
customClass: customClass,
|
customClass: customClass,
|
||||||
})
|
});
|
||||||
|
|
||||||
if(result.isConfirmed) {
|
if(result.isConfirmed) {
|
||||||
// filesStore.deleteFile(type, id);
|
filesStore.deleteFile(type, id);
|
||||||
} else if(result.dismiss === 'cancel') {
|
|
||||||
// 什麼都不做
|
|
||||||
} else if(result.dismiss === 'backdrop') {
|
|
||||||
// 什麼都不做
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import router from "@/router/index.js";
|
import router from "@/router/index.js";
|
||||||
import loadingStore from '@/stores/loading.js';
|
import loadingStore from '@/stores/loading.js';
|
||||||
import pinia from '@/stores/main.js'
|
import pinia from '@/stores/main.js';
|
||||||
import {useToast} from 'vue-toast-notification';
|
import {useToast} from 'vue-toast-notification';
|
||||||
import 'vue-toast-notification/dist/theme-sugar.css';
|
import 'vue-toast-notification/dist/theme-sugar.css';
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import axios from "axios";
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import apiError from '@/module/apiError.js';
|
import apiError from '@/module/apiError.js';
|
||||||
import Swal from 'sweetalert2';
|
import Swal from 'sweetalert2';
|
||||||
import { uploadFailedFirst, uploadFailedSecond, uploadloader, uploadSuccess } from '@/module/alertModal.js'
|
import { uploadFailedFirst, uploadFailedSecond, uploadloader, uploadSuccess } from '@/module/alertModal.js';
|
||||||
|
import pinia from '@/stores/main.js';
|
||||||
|
import loadingStore from '@/stores/loading.js';
|
||||||
|
|
||||||
|
const loading = loadingStore(pinia);
|
||||||
|
|
||||||
export default defineStore('filesStore', {
|
export default defineStore('filesStore', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -26,26 +30,33 @@ export default defineStore('filesStore', {
|
|||||||
allUploadDetail: null,
|
allUploadDetail: null,
|
||||||
uploadLogId: null,
|
uploadLogId: null,
|
||||||
uploadFileName: null,
|
uploadFileName: null,
|
||||||
|
allDependentsData: null,
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
/**
|
/**
|
||||||
* Get allFiles and switch files tag
|
* Get allFiles and switch files tag
|
||||||
*/
|
*/
|
||||||
allFiles: state => {
|
allFiles: state => {
|
||||||
let result = state.allEventFiles;
|
let result = state.allEventFiles;
|
||||||
let data = state.switchFilesTagData;
|
let data = state.switchFilesTagData;
|
||||||
let filesTag = state.filesTag;
|
let filesTag = state.filesTag;
|
||||||
|
|
||||||
result = result.filter(file => data[filesTag].includes(file.fileType));
|
result = result.filter(file => data[filesTag].includes(file.fileType));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Get upload preview
|
* Get upload preview
|
||||||
*/
|
*/
|
||||||
uploadDetail: state => {
|
uploadDetail: state => {
|
||||||
return state.allUploadDetail;
|
return state.allUploadDetail;
|
||||||
}
|
},
|
||||||
|
/**
|
||||||
|
* Get dependents of files data
|
||||||
|
*/
|
||||||
|
dependentsData: state => {
|
||||||
|
return state.allDependentsData;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
/**
|
/**
|
||||||
@@ -205,6 +216,35 @@ export default defineStore('filesStore', {
|
|||||||
apiError(error, 'Failed to rename.');
|
apiError(error, 'Failed to rename.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Get the Dependents of the files
|
||||||
|
* @param { string } type log | filter | log-check | filter-check
|
||||||
|
* @param { number } id
|
||||||
|
*/
|
||||||
|
async getDependents(type, id) {
|
||||||
|
let api;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'log':
|
||||||
|
api = `/api/logs/${id}/dependents`;
|
||||||
|
break;
|
||||||
|
case 'filter':
|
||||||
|
api = `/api/filters/${id}/dependents`;
|
||||||
|
break;
|
||||||
|
case 'log-check':
|
||||||
|
api = `/api/log-checks/${id}/dependents`;
|
||||||
|
break;
|
||||||
|
case 'filter-check':
|
||||||
|
api = `/api/filter-checks/${id}/dependents`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await axios.get(api);
|
||||||
|
this.allDependentsData = response.data;
|
||||||
|
} catch(error) {
|
||||||
|
apiError(error, 'Failed to get Dependents of the files.');
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Delete file
|
* Delete file
|
||||||
* @param { string } type log | filter | log-check | filter-check
|
* @param { string } type log | filter | log-check | filter-check
|
||||||
@@ -213,6 +253,7 @@ export default defineStore('filesStore', {
|
|||||||
async deleteFile(type, id) {
|
async deleteFile(type, id) {
|
||||||
let api;
|
let api;
|
||||||
|
|
||||||
|
loading.isLoading = true;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'log':
|
case 'log':
|
||||||
api = `/api/logs/${id}`;
|
api = `/api/logs/${id}`;
|
||||||
@@ -229,8 +270,11 @@ export default defineStore('filesStore', {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const response = await axios.delete(api);
|
const response = await axios.delete(api);
|
||||||
|
await this.fetchAllFiles();
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
apiError(error, 'Failed to delete.');
|
apiError(error, 'Failed to delete.');
|
||||||
|
} finally {
|
||||||
|
loading.isLoading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -249,12 +293,14 @@ export default defineStore('filesStore', {
|
|||||||
case 'filter':
|
case 'filter':
|
||||||
api = `/api/filters/${id}/csv`;
|
api = `/api/filters/${id}/csv`;
|
||||||
break;
|
break;
|
||||||
case 'log-check':
|
// case 'log-check':
|
||||||
api = `/api/log-checks/${id}/csv`;
|
// api = `/api/log-checks/${id}/csv`;
|
||||||
break;
|
// break;
|
||||||
case 'filter-check':
|
// case 'filter-check':
|
||||||
api = `/api/filter-checks/${id}/csv`;
|
// api = `/api/filter-checks/${id}/csv`;
|
||||||
break;
|
// break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(api);
|
const response = await axios.get(api);
|
||||||
|
|||||||
@@ -146,10 +146,11 @@
|
|||||||
const store = filesStore();
|
const store = filesStore();
|
||||||
const allMapDataStore = AllMapDataStore();
|
const allMapDataStore = AllMapDataStore();
|
||||||
const loadingStore = LoadingStore();
|
const loadingStore = LoadingStore();
|
||||||
|
const { dependentsData } = storeToRefs(store);
|
||||||
const { createFilterId, baseLogId } = storeToRefs(allMapDataStore);
|
const { createFilterId, baseLogId } = storeToRefs(allMapDataStore);
|
||||||
const { isLoading } = storeToRefs(loadingStore);
|
const { isLoading } = storeToRefs(loadingStore);
|
||||||
|
|
||||||
return { store, allMapDataStore, createFilterId, baseLogId, isLoading }
|
return { store, dependentsData, allMapDataStore, createFilterId, baseLogId, isLoading }
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
IconDataFormat,
|
IconDataFormat,
|
||||||
@@ -287,21 +288,34 @@
|
|||||||
* @param {number} id
|
* @param {number} id
|
||||||
* @param {string} source hover icon
|
* @param {string} source hover icon
|
||||||
*/
|
*/
|
||||||
deleteFile(type, id, source) {
|
async deleteFile(type, id, source) {
|
||||||
// 先取得 id 打 Delete Daile API
|
let srt = '';
|
||||||
|
let data = [];
|
||||||
|
|
||||||
|
// 判斷是否來自 hover icon 選單
|
||||||
if(type && id && source === 'list-hover') {
|
if(type && id && source === 'list-hover') {
|
||||||
this.selectedType = type;
|
this.selectedType = type;
|
||||||
this.selectedId = id;
|
this.selectedId = id;
|
||||||
}
|
}
|
||||||
console.log(this.selectedId);
|
// 取得相依性檔案
|
||||||
// let srt = '';
|
await this.store.getDependents(this.selectedType, this.selectedId);
|
||||||
// data.forEach(i => {
|
if(this.dependentsData.length !== 0) {
|
||||||
// let content = `<li>[${type}] ${fileName}<li>`;
|
data = [...this.dependentsData];
|
||||||
// srt += content;
|
data.forEach(i => {
|
||||||
// });
|
switch (i.type) {
|
||||||
// console.log('srt:', srt);
|
case 'log-check':
|
||||||
// deleteFileModal(id, srt);
|
i.type = 'rule';
|
||||||
deleteFileModal();
|
break;
|
||||||
|
case 'filter-check':
|
||||||
|
i.type = 'rule';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let content = `<li>[${i.type}] ${i.name}</li>`;
|
||||||
|
srt += content;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
deleteFileModal(srt, this.selectedType, this.selectedId);
|
||||||
|
srt = '';
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Download file as CSV
|
* Download file as CSV
|
||||||
|
|||||||
Reference in New Issue
Block a user