This commit is contained in:
2019-01-04 20:04:48 +00:00
parent 17d44a4cef
commit 8fe9cca33a
3 changed files with 82 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
/* Xeslint-disable */
/* eslint-disable */
import store from "../store";
var stringifyPrimitive = function(v) {
@@ -19,13 +19,42 @@ var stringifyPrimitive = function(v) {
export default {
status(response) {
//debugger;
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
store.commit("logItem", "API error: " + response.statusText);
} else {
store.commit(
"logItem",
"API error: status=" +
response.status +
", statusText=" +
response.statusText +
", url=" +
response.url
);
return Promise.reject(new Error(response.statusText));
}
},
status2(response) {
//debugger;
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
store.commit(
"logItem",
"API error: status=" +
response.status +
", statusText=" +
response.statusText +
", url=" +
response.url
);
//TODO: If no viable data to return then should reject, otherwise should resolve regardless
return Promise.resolve(response);
}
},
json(response) {
return response.json();
},

View File

@@ -1,15 +1,23 @@
/* xeslint-disable */
/* eslint-disable */
import apiUtil from "./apiutil";
import store from "../store";
export default {
get(route) {
return new Promise(function(resolve, reject) {
fetch(apiUtil.APIUrl(route), apiUtil.fetchGetOptions())
.then(apiUtil.status)
.then(apiUtil.status2)
.then(apiUtil.json)
.then(response => {
resolve(response);
})
.catch(function(error) {
//fundamental error, can't proceed with this call
// debugger;
var errorMessage =
"API error: GET route =" + route + ", message =" + error.message;
store.commit("logItem", errorMessage);
alert("Error: " + errorMessage);
reject(error);
});
});

View File

@@ -17,30 +17,8 @@ function addNavItem(title, icon, route) {
// on change of authentication status
export default function initialize() {
if (store.state.authenticated) {
//Fetch the users options for local caching
//check the timezone offset is still valid, offer to change it if not
api.get("UserOptions/" + store.state.userId).then(res => {
//debugger;
var localOffset = new Date().getTimezoneOffset();
if (localOffset != 0) {
localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect
}
if (res.data.timeZoneOffset != localOffset) {
//todo: timezone doesn't match, offer to fix it
alert(
"Time zone offset for this account is set to " +
res.data.timeZoneOffset +
" which doesn't match the local timezone offset of " +
localOffset +
"."
);
}
});
//fetch the required localized text keys into the cache
//GET LOCALIZED TEXT FOR SHELL
lt.fetch([
"Home",
"Service",
@@ -107,8 +85,46 @@ export default function initialize() {
addNavItem(lt.get("Logout"), "sign-out-alt", "/login");
})
.catch(function(error) {
store.commit("logItem", "Initialize::() -> error" + error);
store.commit("logItem", "Initialize::() ltfetch -> error" + error);
throw error;
});
//CACHE LOCALE SETTINGS
debugger;
//check the timezone offset is still valid, offer to change it if not
//api.get("UserOptions/" + store.state.userId).then(res => {
api
.get("UserOptions/bb")
.then(res => {
debugger;
//TODO: check if error in return object
//centralize that shit so can easily handle it in client
var localOffset = new Date().getTimezoneOffset();
if (localOffset != 0) {
localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect
}
if (res.data.timeZoneOffset != localOffset) {
//todo: timezone doesn't match, offer to fix it
alert(
"Time zone offset for this account is set to " +
res.data.timeZoneOffset +
" which doesn't match the local timezone offset of " +
localOffset +
"."
);
}
})
.catch(function(error) {
store.commit(
"logItem",
"Initialize::() fetch useroptions -> error" + error
);
throw error;
});
}
}