This commit is contained in:
@@ -1,25 +1,22 @@
|
|||||||
/* xeslint-disable */
|
/* xeslint-disable */
|
||||||
|
import store from "../store";
|
||||||
import config from "../utils/config";
|
import config from "../utils/config";
|
||||||
import api from "./apiutil";
|
import api from "./apiutil";
|
||||||
import _ from "../utils/libs/core.min.js";
|
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 {
|
export default {
|
||||||
get(key) {
|
get(key) {
|
||||||
if (!_.has(lt, key)) {
|
if (!_.has(store.state.localeText, key)) {
|
||||||
return "?" + key + "?";
|
return "?" + key + "?";
|
||||||
}
|
}
|
||||||
return lt[key];
|
return store.state.localeText[key];
|
||||||
},
|
},
|
||||||
fetch(keys) {
|
fetch(keys) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
//step 1: build an array of keys that we don't have already
|
//step 1: build an array of keys that we don't have already
|
||||||
var NeedIt = [];
|
var NeedIt = [];
|
||||||
for (var i = 0; i < keys.length; i++) {
|
for (var i = 0; i < keys.length; i++) {
|
||||||
if (!_.has(lt, keys[i])) {
|
if (!_.has(store.state.localeText, keys[i])) {
|
||||||
NeedIt.push(keys[i]);
|
NeedIt.push(keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,18 +28,13 @@ export default {
|
|||||||
method: "post",
|
method: "post",
|
||||||
mode: "cors",
|
mode: "cors",
|
||||||
headers: api.AuthorizedHeaders(),
|
headers: api.AuthorizedHeaders(),
|
||||||
// headers: {
|
|
||||||
// Accept: "application/json, text/plain, */*",
|
|
||||||
// "Content-Type": "application/json",
|
|
||||||
// Authorization: "Bearer " + getToken()
|
|
||||||
// },
|
|
||||||
body: JSON.stringify(NeedIt)
|
body: JSON.stringify(NeedIt)
|
||||||
})
|
})
|
||||||
.then(api.status)
|
.then(api.status)
|
||||||
.then(api.json)
|
.then(api.json)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
_.forEach(response.data, function(item) {
|
_.forEach(response.data, function(item) {
|
||||||
lt[item.key] = item.value;
|
store.commit("addLocaleText", item);
|
||||||
});
|
});
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
@@ -50,8 +42,5 @@ export default {
|
|||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
|
||||||
clearCache() {
|
|
||||||
lt = {};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,23 +11,28 @@ export default new Vuex.Store({
|
|||||||
apiUrl: "http://localhost:7575/api/v8.0/",
|
apiUrl: "http://localhost:7575/api/v8.0/",
|
||||||
userId: 0,
|
userId: 0,
|
||||||
roles: 0,
|
roles: 0,
|
||||||
|
localeText: {},
|
||||||
navItems: []
|
navItems: []
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setAuthentication(state, data) {
|
login(state, data) {
|
||||||
// mutate state
|
// mutate state
|
||||||
state.authenticated = data.authenticated;
|
state.authenticated = data.authenticated;
|
||||||
state.userId = data.userId;
|
state.userId = data.userId;
|
||||||
state.roles = data.roles;
|
state.roles = data.roles;
|
||||||
},
|
},
|
||||||
clearAuthentication(state) {
|
logout(state) {
|
||||||
state.authenticated = false;
|
state.authenticated = false;
|
||||||
state.userId = 0;
|
state.userId = 0;
|
||||||
state.roles = 0;
|
state.roles = 0;
|
||||||
state.navItems = [];
|
state.navItems = [];
|
||||||
|
state.localeText = [];
|
||||||
},
|
},
|
||||||
addNavItem(state, data) {
|
addNavItem(state, data) {
|
||||||
state.navItems.push(data);
|
state.navItems.push(data);
|
||||||
|
},
|
||||||
|
addLocaleText(state, data) {
|
||||||
|
state.localeText[data.key] = data.value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {}
|
actions: {}
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ function addNavItem(title, icon, route) {
|
|||||||
// Initialize the app
|
// Initialize the app
|
||||||
// on change of authentication status
|
// on change of authentication status
|
||||||
export default function initialize() {
|
export default function initialize() {
|
||||||
//clear the locale text cache
|
|
||||||
lt.clearCache();
|
|
||||||
if (store.state.authenticated) {
|
if (store.state.authenticated) {
|
||||||
//fetch the required localized text keys into the cache
|
//fetch the required localized text keys into the cache
|
||||||
lt.fetch([
|
lt.fetch([
|
||||||
|
|||||||
Reference in New Issue
Block a user