import Vue from "vue"; import Vuex from "vuex"; import createPersistedState from "vuex-persistedstate"; /* Xeslint-disable */ const MaxLogLength = 100; Vue.use(Vuex); export default new Vuex.Store({ plugins: [createPersistedState()], state: { authenticated: false, apiUrl: "", helpUrl: "", apiToken: "-", userId: 0, userName: "NOT AUTHENTICATED", roles: 0, localeText: {}, locale: { decimalSeparator: ".", currencySymbol: "$", shortDate: "YYYY-MM-DD", shortTime: "hh:mm:ss A", shortDateAndTime: "YYYY-MM-DD hh:mm:ss A", timeZoneOffset: -7 //timeZoneOffset is in decimal hours }, navItems: [], logArray: [], formSettings: {}, //this is the settings on forms that survive a refresh like grid number of items to show etc formCustomTemplate: {} //this is the custom fields settings for forms }, mutations: { login(state, data) { // mutate state state.authenticated = data.authenticated; state.userId = data.userId; state.roles = data.roles; state.apiToken = data.apiToken; state.userName = data.userName; }, logout(state) { //Things that are reset on logout state.apiToken = "-"; state.authenticated = false; state.userId = 0; state.userName = "NOT AUTHENTICATED"; state.roles = 0; state.navItems = []; state.localeText = {}; state.formCustomTemplate = {}; state.apiUrl = ""; state.locale.decimalSeparator = "."; state.locale.currencySymbol = "$"; state.locale.shortDate = "YYYY-MM-DD"; state.locale.shortTime = "hh:mm:ss A"; state.locale.shortDateAndTime = "YYYY-MM-DD hh:mm:ss A"; state.locale.timeZoneOffset = -7; }, addNavItem(state, data) { state.navItems.push(data); }, addLocaleText(state, data) { state.localeText[data.key] = data.value; }, addFormCustomTemplateItem(state, data) { state.formCustomTemplate[data.formKey] = data.value; }, setLocale(state, data) { // mutate state state.locale.decimalSeparator = data.decimalSeparator; state.locale.currencySymbol = data.currencySymbol; state.locale.shortDate = data.shortDate; state.locale.shortTime = data.shortTime; state.locale.shortDateAndTime = data.shortDateAndTime; state.locale.timeZoneOffset = data.timeZoneOffset; }, setAPIURL(state, data) { state.apiUrl = data; }, setHelpURL(state, data) { state.helpUrl = data; }, logItem(state, msg) { msg = Date.now() + "|" + msg; state.logArray.push(msg); if (state.logArray.length > MaxLogLength) { state.logArray = window.$gz._.drop( state.logArray, state.logArray.length - MaxLogLength ); } }, clearAllFormSettings(state) { state.formSettings = {}; }, setFormSettings(state, data) { state.formSettings[data.formKey] = data.formSettings; }, clearFormSettings(state, formKey) { delete state.formSettings[formKey]; } }, actions: {} });