161 lines
4.7 KiB
JavaScript
161 lines
4.7 KiB
JavaScript
import Vue from "vue";
|
|
import Vuex from "vuex";
|
|
import createPersistedState from "vuex-persistedstate";
|
|
|
|
/* Xeslint-disable */
|
|
const MaxLogLength = 100;
|
|
|
|
Vue.use(Vuex);
|
|
|
|
//reset all local settings via url in case of fucked up situation
|
|
if (window.location.search) {
|
|
var searchParams = new URLSearchParams(window.location.search);
|
|
if (searchParams.has("reset")) {
|
|
localStorage.removeItem("AyaNova");
|
|
console.log("RESET LOCAL SETTINGS");
|
|
}
|
|
}
|
|
|
|
export default new Vuex.Store({
|
|
plugins: [createPersistedState({ key: "AyaNova" })],
|
|
state: {
|
|
openObject: null,
|
|
lastClientVersion: "",
|
|
authenticated: false,
|
|
apiUrl: "",
|
|
helpUrl: "",
|
|
apiToken: "-",
|
|
downloadToken: "-",
|
|
userId: 0,
|
|
userName: "NOT AUTHENTICATED",
|
|
roles: 0,
|
|
userType: 0,
|
|
homePage: undefined,
|
|
translationText: {},
|
|
enums: {}, //all enum values with translated text to match stored as key e.g. enums:={AuthorizationRoles:{0:"no role",1:"Limited role"},UserTypes:{0:"Technician",1:"Client user"}}
|
|
locale: {
|
|
languageOverride: "en-US",
|
|
timeZoneOverride: "America/New_York",
|
|
currencyName: "USD",
|
|
hour12: true
|
|
},
|
|
globalSettings: {},
|
|
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,
|
|
darkMode: false,
|
|
knownPassword: false,
|
|
newNotificationCount: 0
|
|
},
|
|
mutations: {
|
|
setLastClientVersion(state, data) {
|
|
state.lastClientVersion = data;
|
|
},
|
|
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;
|
|
state.userType = data.userType;
|
|
state.downloadToken = data.dlt;
|
|
},
|
|
logout(state) {
|
|
//Things that are reset on logout
|
|
state.apiToken = "-";
|
|
state.downloadToken = "-";
|
|
state.authenticated = false;
|
|
state.userId = 0;
|
|
state.userName = "NOT AUTHENTICATED";
|
|
state.roles = 0;
|
|
state.userType = 0;
|
|
state.homePage = undefined;
|
|
state.navItems = [];
|
|
state.translationText = {};
|
|
state.enums = {};
|
|
state.formCustomTemplate = {};
|
|
state.apiUrl = "";
|
|
state.locale.languageOverride = "en-US";
|
|
state.locale.timeZoneOverride = "America/New_York";
|
|
state.locale.currencyName = "USD";
|
|
state.locale.hour12 = true;
|
|
state.globalSettings = {};
|
|
state.knownPassword = false;
|
|
state.newNotificationCount = 0;
|
|
},
|
|
addNavItem(state, data) {
|
|
state.navItems.push(data);
|
|
},
|
|
setTranslationText(state, data) {
|
|
state.translationText[data.key] = data.value;
|
|
},
|
|
setFormCustomTemplateItem(state, data) {
|
|
state.formCustomTemplate[data.formKey + "_concurrencyToken"] =
|
|
data.concurrency;
|
|
state.formCustomTemplate[data.formKey] = data.value;
|
|
},
|
|
setLocale(state, data) {
|
|
// mutate state
|
|
state.locale.languageOverride = data.languageOverride;
|
|
state.locale.currencyName = data.currencyName;
|
|
state.locale.hour12 = data.hour12;
|
|
state.locale.timeZoneOverride = data.timeZoneOverride;
|
|
},
|
|
setGlobalSettings(state, data) {
|
|
// mutate state
|
|
state.globalSettings = data;
|
|
},
|
|
setEnum(state, data) {
|
|
state.enums[data.enumKey] = data.items; //{enumKey:"AuthorizationRoles",items:[{0:"no role"},{1:"Limited role"}]}
|
|
},
|
|
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];
|
|
},
|
|
setHomePage(state, data) {
|
|
state.homePage = data;
|
|
},
|
|
setOpenObject(state, data) {
|
|
//data should be format for open-object-handler
|
|
// { type: [AYATYPE], id: [RECORDID] }
|
|
state.openObject = data;
|
|
},
|
|
clearOpenObject(state) {
|
|
state.openObject = null;
|
|
},
|
|
setDarkMode(state, data) {
|
|
state.darkMode = data;
|
|
},
|
|
setKnownPassword(state, data) {
|
|
state.knownPassword = data;
|
|
},
|
|
setNewNotificationCount(state, data) {
|
|
state.newNotificationCount = data;
|
|
}
|
|
},
|
|
actions: {}
|
|
});
|