This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import logger from "../utils/logit";
|
import logger from "../utils/logit";
|
||||||
|
import { getToken } from "../utils/authUtil";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
status(response) {
|
status(response) {
|
||||||
@@ -11,5 +12,12 @@ export default {
|
|||||||
},
|
},
|
||||||
json(response) {
|
json(response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
|
},
|
||||||
|
AuthorizedHeaders() {
|
||||||
|
return {
|
||||||
|
Accept: "application/json, text/plain, */*",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + getToken()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
/* eslint-disable */
|
/* xeslint-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";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Locale:
|
Locale:
|
||||||
@@ -26,17 +25,13 @@ var lt = {};
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
Get(key) {
|
Get(key) {
|
||||||
console.log("locale::Get -> " + key);
|
|
||||||
if (!_.has(lt, key)) {
|
if (!_.has(lt, key)) {
|
||||||
console.log("locale::Get Key not found");
|
|
||||||
return "?" + key + "?";
|
return "?" + key + "?";
|
||||||
}
|
}
|
||||||
console.log("locale::Get Key was found");
|
|
||||||
return lt[key];
|
return lt[key];
|
||||||
},
|
},
|
||||||
SuperFetch(keys) {
|
Fetch(keys) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
console.log("locale::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++) {
|
||||||
@@ -44,14 +39,19 @@ export default {
|
|||||||
NeedIt.push(keys[i]);
|
NeedIt.push(keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (NeedIt.length == 0) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
fetch(config.apiUrl + "locale/subset", {
|
fetch(config.apiUrl + "locale/subset", {
|
||||||
method: "post",
|
method: "post",
|
||||||
mode: "cors",
|
mode: "cors",
|
||||||
headers: {
|
headers: api.AuthorizedHeaders(),
|
||||||
Accept: "application/json, text/plain, */*",
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// Accept: "application/json, text/plain, */*",
|
||||||
Authorization: "Bearer " + getToken()
|
// "Content-Type": "application/json",
|
||||||
},
|
// Authorization: "Bearer " + getToken()
|
||||||
|
// },
|
||||||
body: JSON.stringify(NeedIt)
|
body: JSON.stringify(NeedIt)
|
||||||
})
|
})
|
||||||
.then(api.status)
|
.then(api.status)
|
||||||
@@ -60,59 +60,13 @@ export default {
|
|||||||
_.forEach(response.data, function(item) {
|
_.forEach(response.data, function(item) {
|
||||||
lt[item.key] = item.value;
|
lt[item.key] = item.value;
|
||||||
});
|
});
|
||||||
console.log(
|
|
||||||
"locale::fetch, done and returning from fetch api call and processing "
|
|
||||||
);
|
|
||||||
resolve();
|
resolve();
|
||||||
}) //succeeded, nothing to return
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
reject(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() {
|
ClearCache() {
|
||||||
lt = {};
|
lt = {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default function initialize() {
|
|||||||
if (store.state.authenticated) {
|
if (store.state.authenticated) {
|
||||||
console.log("initialize about to call fetch");
|
console.log("initialize about to call fetch");
|
||||||
//fetch the required localized text keys into the cache
|
//fetch the required localized text keys into the cache
|
||||||
lt.SuperFetch([
|
lt.Fetch([
|
||||||
"Home",
|
"Home",
|
||||||
"Service",
|
"Service",
|
||||||
"Dispatch",
|
"Dispatch",
|
||||||
|
|||||||
Reference in New Issue
Block a user