AppReports/src/store/index.js
Timo Hocker cf5c17bf59
All checks were successful
continuous-integration/drone/push Build is passing
styling, restructure
2020-08-30 15:28:27 +02:00

61 lines
1.5 KiB
JavaScript

/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of appreports which is released under GPL-3.0-or-later.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, July 2020
*/
import Vue from 'vue';
import Vuex from 'vuex';
import version from '../../version';
Vue.use (Vuex);
export default new Vuex.Store ({
state: { log: {}, version, theme: '' },
mutations: {
set_log (state, log) {
state.log = log;
}
},
getters: {
log (state) {
return (source) => {
if (typeof state.log[source] === 'undefined')
return [];
return state.log[source];
};
}
},
actions: {
async get_log ({ commit }, { app_id, sources }) {
const logs = {};
for (const source of sources) {
// eslint-disable-next-line no-await-in-loop
const log = await fetch ('/log', {
headers: {
app_id,
offset: source.offset,
limit: source.limit
}
})
.then ((res) => res.json ())
.then ((json) => json.map ((entry) => {
entry.data = JSON.parse (entry.data);
const time = new Date (entry.timestamp);
time.setMinutes (time.getMinutes () - time.getTimezoneOffset ());
entry.timestamp = time.toISOString ()
.replace ('T', ' ')
.substr (0, 19);
return entry;
}));
logs[source.name] = log;
}
commit ('set_log', logs);
}
},
modules: {}
});