refactor: Issues #177 change files API done.

This commit is contained in:
chiayin
2023-12-14 15:36:50 +08:00
parent 9c7fd4a202
commit 911abc2139
3 changed files with 72 additions and 32 deletions

View File

@@ -1,12 +1,8 @@
import { defineStore } from "pinia";
import loadingStore from './loading.js';
import pinia from '@/stores/main.js'
import axios from "axios";
import moment from 'moment';
import apiError from '@/module/apiError.js';
const loading = loadingStore(pinia);
export default defineStore('filesStore', {
state: () => ({
allFilter: [
@@ -37,6 +33,13 @@ export default defineStore('filesStore', {
ownerName: '',
}
],
allEventFiles: [
{
parentLog: '',
fileType: '',
ownerName: '',
}
],
switchFilesTagData: {
ALL: ['Log', 'Filter', 'Rule', 'Design'],
DISCOVER: ['Log', 'Filter', 'Rule'],
@@ -51,12 +54,7 @@ export default defineStore('filesStore', {
* Get allFiles and switch files tag
*/
allFiles: state => {
let result = [
...state.allEventLog,
...state.allFilter,
...state.allConformanceLog,
...state.allConformanceFilter,
];
let result = state.allEventFiles;
let data = state.switchFilesTagData;
let filesTag = state.filesTag;
@@ -163,6 +161,51 @@ export default defineStore('filesStore', {
apiError(error, 'Failed to load the filters.');
};
},
/**
* Fetch All Files api
*/
async fetchAllFiles() {
const api = '/api/files';
let icon = '';
let fileType = '';
let parentLog = '';
try {
const response = await axios.get(api);
this.allEventFiles = response.data;
this.allEventFiles.map(o => {
switch (o.type) {
case 'log':
icon = 'work_history';
fileType = 'Log';
parentLog = o.name;
break;
case 'filter':
icon = 'tornado';
fileType = 'Filter';
parentLog = o.parent.name;
break;
case 'log-check':
case 'filter-check':
icon = 'local_police';
fileType = 'Rule';
parentLog = o.parent.name;
break;
}
o.icon = icon;
o.parentLog = parentLog;
o.fileType = fileType;
o.ownerName = o.owner.name;
o.updated_base = o.updated_at;
o.accessed_base = o.accessed_at;
o.updated_at = moment(o.updated_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm');
o.accessed_at = o.accessed_at ? moment(o.accessed_at).utcOffset('+08:00').format('YYYY-MM-DD HH:mm') : null;
});
} catch(error) {
apiError(error, 'Failed to load the files.');
};
},
// fetchRule(){o.icon = local_police}
// fetchDesign(){o.icon = shape_line}
},