/* * 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 , 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: {} });