diff --git a/app/ayanova/src/api/apiutil.js b/app/ayanova/src/api/apiutil.js index 41ec356e..1b30dde1 100644 --- a/app/ayanova/src/api/apiutil.js +++ b/app/ayanova/src/api/apiutil.js @@ -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() + }; } }; diff --git a/app/ayanova/src/api/locale.js b/app/ayanova/src/api/locale.js index a08f286c..59d8ece9 100644 --- a/app/ayanova/src/api/locale.js +++ b/app/ayanova/src/api/locale.js @@ -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 = {}; } diff --git a/app/ayanova/src/utils/initialize.js b/app/ayanova/src/utils/initialize.js index 32d5b948..63bd0f79 100644 --- a/app/ayanova/src/utils/initialize.js +++ b/app/ayanova/src/utils/initialize.js @@ -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",