This commit is contained in:
2018-11-12 21:32:51 +00:00
parent c9de558a06
commit c276d395fb
2 changed files with 19 additions and 14 deletions

View File

@@ -1,8 +1,9 @@
/* eslint-disable */
import config from "../utils/config";
import api from "./apiutil";
import _ from "../utils/libs/core.min.js";
import { getToken } from "../utils/authUtil";
/* eslint-disable */
/*
Locale:
Methods
@@ -10,7 +11,7 @@ Methods
- 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
- 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
- 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
@@ -24,11 +25,14 @@ Methods
const lt = {};
export default {
async Get(keys) {
this.PreFetch(keys);
//TODO: return they keys / lt array
Get(key) {
debugger;
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
var NeedIt = [];
for (var i = 0; i < keys.length; i++) {
@@ -48,8 +52,11 @@ export default {
})
.then(api.status)
.then(api.json)
.then(() => {
.then(response => {
_.forEach(response.data, function(item) {
lt[item.key] = item.value;
});
debugger;
return Promise.resolve(true);
}) //succeeded, nothing to return
.catch(function(error) {

View File

@@ -1,7 +1,8 @@
/* eslint-disable */
import store from "../store";
import roles from "./roles";
import lt from "../api/locale";
/* eslint-disable */
function addNavItem(title, icon, route) {
store.state.navItems.push({
title,
@@ -19,9 +20,8 @@ export default function initialize() {
//clear the locale text cache
lt.ClearCache();
if (store.state.authenticated) {
//prefetch the always required localized text keys into the cache
lt.PreFetch([
//fetch the required localized text keys into the cache
lt.Fetch([
"Service",
"Dispatch",
"Inventory",
@@ -33,7 +33,6 @@ export default function initialize() {
])
.then(() => {
debugger;
//do success
//put nav items into store
//Everyone has a home
addNavItem(lt.Get("Home"), "home", "/");
@@ -88,7 +87,6 @@ export default function initialize() {
addNavItem(lt.Get("Logout"), "sign-out-alt", "/login");
})
.catch(function(error) {
debugger;
alert("initialize::LT->Prefetch failed: " + error);
});
}