This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
|
/* eslint-disable */
|
||||||
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";
|
||||||
import { getToken } from "../utils/authUtil";
|
import { getToken } from "../utils/authUtil";
|
||||||
/* eslint-disable */
|
|
||||||
/*
|
/*
|
||||||
Locale:
|
Locale:
|
||||||
Methods
|
Methods
|
||||||
@@ -10,7 +11,7 @@ Methods
|
|||||||
- It stores a local in memory cache of the keys and returns them from cache whenever possible
|
- It stores a local in memory cache of the keys and returns them from cache whenever possible
|
||||||
- Method: Get keys one at a time or in an array
|
- Method: Get keys one at a time or in an array
|
||||||
- a method that accepts lt keys and returns their text
|
- a method that accepts lt keys and returns their text
|
||||||
- If a key is not in the cache here then it fetches it from the server
|
- If a key is not in the cache here then it returns an obvious error string
|
||||||
- Method: pre-fetch / Cache keys
|
- Method: pre-fetch / Cache keys
|
||||||
- Used to pre-fetch a bunch of keys at once if necessary
|
- Used to pre-fetch a bunch of keys at once if necessary
|
||||||
- A caller will call this with the list of keys it will need in advance, the ones that are not present in the cache will be fetched from the server and the cache populated
|
- A caller will call this with the list of keys it will need in advance, the ones that are not present in the cache will be fetched from the server and the cache populated
|
||||||
@@ -24,11 +25,14 @@ Methods
|
|||||||
const lt = {};
|
const lt = {};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async Get(keys) {
|
Get(key) {
|
||||||
this.PreFetch(keys);
|
debugger;
|
||||||
//TODO: return they keys / lt array
|
if (!_.has(lt, key)) {
|
||||||
|
return "?" + key + "?";
|
||||||
|
}
|
||||||
|
return lt[key];
|
||||||
},
|
},
|
||||||
async PreFetch(keys) {
|
async Fetch(keys) {
|
||||||
//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++) {
|
||||||
@@ -48,8 +52,11 @@ export default {
|
|||||||
})
|
})
|
||||||
.then(api.status)
|
.then(api.status)
|
||||||
.then(api.json)
|
.then(api.json)
|
||||||
|
.then(response => {
|
||||||
.then(() => {
|
_.forEach(response.data, function(item) {
|
||||||
|
lt[item.key] = item.value;
|
||||||
|
});
|
||||||
|
debugger;
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}) //succeeded, nothing to return
|
}) //succeeded, nothing to return
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
/* eslint-disable */
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import roles from "./roles";
|
import roles from "./roles";
|
||||||
import lt from "../api/locale";
|
import lt from "../api/locale";
|
||||||
/* eslint-disable */
|
|
||||||
function addNavItem(title, icon, route) {
|
function addNavItem(title, icon, route) {
|
||||||
store.state.navItems.push({
|
store.state.navItems.push({
|
||||||
title,
|
title,
|
||||||
@@ -19,9 +20,8 @@ export default function initialize() {
|
|||||||
//clear the locale text cache
|
//clear the locale text cache
|
||||||
lt.ClearCache();
|
lt.ClearCache();
|
||||||
if (store.state.authenticated) {
|
if (store.state.authenticated) {
|
||||||
//prefetch the always required localized text keys into the cache
|
//fetch the required localized text keys into the cache
|
||||||
|
lt.Fetch([
|
||||||
lt.PreFetch([
|
|
||||||
"Service",
|
"Service",
|
||||||
"Dispatch",
|
"Dispatch",
|
||||||
"Inventory",
|
"Inventory",
|
||||||
@@ -33,7 +33,6 @@ export default function initialize() {
|
|||||||
])
|
])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
debugger;
|
debugger;
|
||||||
//do success
|
|
||||||
//put nav items into store
|
//put nav items into store
|
||||||
//Everyone has a home
|
//Everyone has a home
|
||||||
addNavItem(lt.Get("Home"), "home", "/");
|
addNavItem(lt.Get("Home"), "home", "/");
|
||||||
@@ -88,7 +87,6 @@ export default function initialize() {
|
|||||||
addNavItem(lt.Get("Logout"), "sign-out-alt", "/login");
|
addNavItem(lt.Get("Logout"), "sign-out-alt", "/login");
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
debugger;
|
|
||||||
alert("initialize::LT->Prefetch failed: " + error);
|
alert("initialize::LT->Prefetch failed: " + error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user