diff --git a/package-lock.json b/package-lock.json index 0a9a7c8..05c8dbe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "autoprefixer": "^10.4.13", "axios": "^1.2.2", + "mitt": "^3.0.0", "moment": "^2.29.4", "pinia": "^2.0.28", "postcss": "^8.4.20", @@ -4138,6 +4139,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/mitt": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz", + "integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==" + }, "node_modules/moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", @@ -9243,6 +9249,11 @@ "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", "dev": true }, + "mitt": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz", + "integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==" + }, "moment": { "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", diff --git a/package.json b/package.json index 24254ec..8d109f1 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "dependencies": { "autoprefixer": "^10.4.13", "axios": "^1.2.2", + "mitt": "^3.0.0", "moment": "^2.29.4", "pinia": "^2.0.28", "postcss": "^8.4.20", diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index f5c8a9a..c654912 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -5,10 +5,10 @@

FILES

@@ -35,6 +35,7 @@ diff --git a/src/main.js b/src/main.js index dc2dd62..886a6e3 100644 --- a/src/main.js +++ b/src/main.js @@ -6,9 +6,11 @@ import router from "./router"; import axios from 'axios'; import VueAxios from 'vue-axios'; import moment from 'moment'; +import mitt from 'mitt'; import "./assets/main.css"; +const emitter = mitt(); const pinia = createPinia(); const app = createApp(App); @@ -18,6 +20,7 @@ pinia.use(({ store }) => { // can use `this.$moment` in Vue.js app.config.globalProperties.$moment = moment; +app.config.globalProperties.emitter = emitter; app.use(pinia); app.use(router); app.use(VueAxios, axios); diff --git a/src/stores/files.js b/src/stores/files.js new file mode 100644 index 0000000..c70f8e6 --- /dev/null +++ b/src/stores/files.js @@ -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 {}; + }, + } +}) diff --git a/src/views/Files/index.vue b/src/views/Files/index.vue index b259dee..0d4f9d6 100644 --- a/src/views/Files/index.vue +++ b/src/views/Files/index.vue @@ -28,7 +28,7 @@
-

All Files

+

All Files

  • @@ -114,6 +114,8 @@