This commit is contained in:
2018-11-13 22:44:16 +00:00
parent 15daaebab9
commit a31093d50d
4 changed files with 12 additions and 20 deletions

View File

@@ -1,25 +1,22 @@
/* xeslint-disable */
import store from "../store";
import config from "../utils/config";
import api from "./apiutil";
import _ from "../utils/libs/core.min.js";
//Keep the localized text keys here temporarily
//TODO: rehydrate on page refresh / put in sessionstorage
var lt = {};
export default {
get(key) {
if (!_.has(lt, key)) {
if (!_.has(store.state.localeText, key)) {
return "?" + key + "?";
}
return lt[key];
return store.state.localeText[key];
},
fetch(keys) {
return new Promise(function(resolve, reject) {
//step 1: build an array of keys that we don't have already
var NeedIt = [];
for (var i = 0; i < keys.length; i++) {
if (!_.has(lt, keys[i])) {
if (!_.has(store.state.localeText, keys[i])) {
NeedIt.push(keys[i]);
}
}
@@ -31,18 +28,13 @@ export default {
method: "post",
mode: "cors",
headers: api.AuthorizedHeaders(),
// headers: {
// Accept: "application/json, text/plain, */*",
// "Content-Type": "application/json",
// Authorization: "Bearer " + getToken()
// },
body: JSON.stringify(NeedIt)
})
.then(api.status)
.then(api.json)
.then(response => {
_.forEach(response.data, function(item) {
lt[item.key] = item.value;
store.commit("addLocaleText", item);
});
resolve();
})
@@ -50,8 +42,5 @@ export default {
reject(error);
});
});
},
clearCache() {
lt = {};
}
};

View File

@@ -11,23 +11,28 @@ export default new Vuex.Store({
apiUrl: "http://localhost:7575/api/v8.0/",
userId: 0,
roles: 0,
localeText: {},
navItems: []
},
mutations: {
setAuthentication(state, data) {
login(state, data) {
// mutate state
state.authenticated = data.authenticated;
state.userId = data.userId;
state.roles = data.roles;
},
clearAuthentication(state) {
logout(state) {
state.authenticated = false;
state.userId = 0;
state.roles = 0;
state.navItems = [];
state.localeText = [];
},
addNavItem(state, data) {
state.navItems.push(data);
},
addLocaleText(state, data) {
state.localeText[data.key] = data.value;
}
},
actions: {}

View File

@@ -16,8 +16,6 @@ function addNavItem(title, icon, route) {
// Initialize the app
// on change of authentication status
export default function initialize() {
//clear the locale text cache
lt.clearCache();
if (store.state.authenticated) {
//fetch the required localized text keys into the cache
lt.fetch([