This commit is contained in:
2018-11-12 23:22:26 +00:00
parent 251cd6dbb6
commit f1fe285fd5
3 changed files with 22 additions and 60 deletions

View File

@@ -1,4 +1,5 @@
import logger from "../utils/logit";
import { getToken } from "../utils/authUtil";
export default {
status(response) {
@@ -11,5 +12,12 @@ export default {
},
json(response) {
return response.json();
},
AuthorizedHeaders() {
return {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
Authorization: "Bearer " + getToken()
};
}
};

View File

@@ -1,8 +1,7 @@
/* eslint-disable */
/* xeslint-disable */
import config from "../utils/config";
import api from "./apiutil";
import _ from "../utils/libs/core.min.js";
import { getToken } from "../utils/authUtil";
/*
Locale:
@@ -26,17 +25,13 @@ var lt = {};
export default {
Get(key) {
console.log("locale::Get -> " + key);
if (!_.has(lt, key)) {
console.log("locale::Get Key not found");
return "?" + key + "?";
}
console.log("locale::Get Key was found");
return lt[key];
},
SuperFetch(keys) {
Fetch(keys) {
return new Promise(function(resolve, reject) {
console.log("locale::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++) {
@@ -44,14 +39,19 @@ export default {
NeedIt.push(keys[i]);
}
}
if (NeedIt.length == 0) {
resolve();
return;
}
fetch(config.apiUrl + "locale/subset", {
method: "post",
mode: "cors",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
Authorization: "Bearer " + getToken()
},
headers: api.AuthorizedHeaders(),
// headers: {
// Accept: "application/json, text/plain, */*",
// "Content-Type": "application/json",
// Authorization: "Bearer " + getToken()
// },
body: JSON.stringify(NeedIt)
})
.then(api.status)
@@ -60,59 +60,13 @@ export default {
_.forEach(response.data, function(item) {
lt[item.key] = item.value;
});
console.log(
"locale::fetch, done and returning from fetch api call and processing "
);
resolve();
}) //succeeded, nothing to return
})
.catch(function(error) {
reject(error);
});
// var z = keys.length;
// if (isMomHappy) {
// resolve(true); // fulfilled
// } else {
// var reason = new Error("mom is not happy");
// reject(reason); // reject
// }
});
},
Fetch(keys) {
console.log("locale::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++) {
if (!_.has(lt, keys[i])) {
NeedIt.push(keys[i]);
}
}
fetch(config.apiUrl + "locale/subset", {
method: "post",
mode: "cors",
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;
});
console.log(
"locale::fetch, done and returning from fetch api call and processing "
);
return null;
}) //succeeded, nothing to return
.catch(function(error) {
return error;
});
},
ClearCache() {
lt = {};
}

View File

@@ -23,7 +23,7 @@ export default function initialize() {
if (store.state.authenticated) {
console.log("initialize about to call fetch");
//fetch the required localized text keys into the cache
lt.SuperFetch([
lt.Fetch([
"Home",
"Service",
"Dispatch",