Files page Pinia Done
This commit is contained in:
85
src/stores/files.js
Normal file
85
src/stores/files.js
Normal file
@@ -0,0 +1,85 @@
|
||||
import { defineStore } from "pinia";
|
||||
import axios from "axios";
|
||||
import moment from 'moment';
|
||||
|
||||
export default defineStore('filesStore', {
|
||||
state: () => ({
|
||||
allFilter: [
|
||||
{
|
||||
log: {},
|
||||
fileType: '',
|
||||
}
|
||||
],
|
||||
allEventLog: [
|
||||
{
|
||||
parentLog: '',
|
||||
fileType: '',
|
||||
}
|
||||
],
|
||||
switchFilesTagData: {
|
||||
ALL: ['Log', 'Filter', 'Rule', 'Design'],
|
||||
DISCOVER: ['Log', 'Filter', 'Rule'],
|
||||
COMPARE: ['Filter'],
|
||||
DESIGN: ['Log', 'Design'],
|
||||
},
|
||||
filesTag: 'ALL',
|
||||
}),
|
||||
getters: {
|
||||
/**
|
||||
* Get allFiles and switch files tag
|
||||
*/
|
||||
allFiles: state => {
|
||||
let result = [
|
||||
...state.allEventLog,
|
||||
...state.allFilter.map(itemFilter => {
|
||||
return { ...itemFilter, parentLog: itemFilter.log.name }
|
||||
})
|
||||
];
|
||||
let data = state.switchFilesTagData;
|
||||
let filesTag = state.filesTag;
|
||||
|
||||
result = result.filter(file => data[filesTag].includes(file.fileType));
|
||||
return result;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* Fetch event logs api
|
||||
*/
|
||||
async fetchEventLog() {
|
||||
const api = 'api/logs';
|
||||
|
||||
try {
|
||||
const response = await axios.get(api);
|
||||
|
||||
this.allEventLog = response.data;
|
||||
this.allEventLog.map(o => {
|
||||
o.parentLog = "-";
|
||||
o.fileType = "Log";
|
||||
o.updated_at = moment(o.updated_at).format('YYYY-MM-DD HH:MM');
|
||||
o.accessed_at = moment(o.accessed_at).format('YYYY-MM-DD HH:MM');
|
||||
return this.allEventLog
|
||||
})
|
||||
} catch(error) {
|
||||
} finally {};
|
||||
},
|
||||
/**
|
||||
* Fetch filters api
|
||||
*/
|
||||
async fetchFilter() {
|
||||
const api = 'api/filters';
|
||||
|
||||
try {
|
||||
const response = await axios.get(api);
|
||||
|
||||
this.allFilter = response.data;
|
||||
this.allFilter.map(o => {
|
||||
o.fileType = "Filter";
|
||||
o.updated_at = moment(o.updated_at).format('YYYY-MM-DD HH:MM');
|
||||
o.accessed_at = moment(o.accessed_at).format('YYYY-MM-DD HH:MM');
|
||||
});
|
||||
} catch(error) {
|
||||
} finally {};
|
||||
},
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user