This commit is contained in:
@@ -19,23 +19,6 @@ var stringifyPrimitive = function(v) {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
status(response) {
|
status(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
|
|
||||||
);
|
|
||||||
return Promise.reject(new Error(response.statusText));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
status2(response) {
|
|
||||||
//debugger;
|
//debugger;
|
||||||
if (response.status >= 200 && response.status < 300) {
|
if (response.status >= 200 && response.status < 300) {
|
||||||
return Promise.resolve(response);
|
return Promise.resolve(response);
|
||||||
@@ -51,6 +34,7 @@ export default {
|
|||||||
);
|
);
|
||||||
|
|
||||||
//TODO: If no viable data to return then should reject, otherwise should resolve regardless
|
//TODO: If no viable data to return then should reject, otherwise should resolve regardless
|
||||||
|
//Nope because we will never get here if nothing at all was returned so what is this actually doing??
|
||||||
|
|
||||||
return Promise.resolve(response);
|
return Promise.resolve(response);
|
||||||
}
|
}
|
||||||
@@ -58,6 +42,14 @@ export default {
|
|||||||
json(response) {
|
json(response) {
|
||||||
return response.json();
|
return response.json();
|
||||||
},
|
},
|
||||||
|
apiErrorToHumanString(apiError) {
|
||||||
|
//empty error object?
|
||||||
|
if (!apiError) {
|
||||||
|
return "apiErrorToHumanString():: Empty API eror, unknown";
|
||||||
|
}
|
||||||
|
//convert to readable string
|
||||||
|
return JSON.stringify(apiError);
|
||||||
|
},
|
||||||
patchAuthorizedHeaders() {
|
patchAuthorizedHeaders() {
|
||||||
return {
|
return {
|
||||||
//Accept: "application/json, text/plain, */*",
|
//Accept: "application/json, text/plain, */*",
|
||||||
@@ -166,5 +158,30 @@ export default {
|
|||||||
eq +
|
eq +
|
||||||
encodeURIComponent(stringifyPrimitive(obj))
|
encodeURIComponent(stringifyPrimitive(obj))
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
get(route) {
|
||||||
|
var that=this;
|
||||||
|
//debugger;
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
//debugger;
|
||||||
|
fetch(that.APIUrl(route), that.fetchGetOptions())
|
||||||
|
.then(that.status)
|
||||||
|
.then(that.json)
|
||||||
|
.then(response => {
|
||||||
|
//For now, assuming that all returns that make it here have either an error or a data object attached to them
|
||||||
|
//debugger;
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
/* eslint-disable */
|
/* xeslint-disable */
|
||||||
import apiUtil from "./apiutil";
|
import apiUtil from "./apiutil";
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
export default {
|
export default {
|
||||||
get(route) {
|
get(route) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
fetch(apiUtil.APIUrl(route), apiUtil.fetchGetOptions())
|
fetch(apiUtil.APIUrl(route), apiUtil.fetchGetOptions())
|
||||||
.then(apiUtil.status2)
|
.then(apiUtil.status)
|
||||||
.then(apiUtil.json)
|
.then(apiUtil.json)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
//For now, assuming that all returns that make it here have either an error or a data object attached to them
|
||||||
|
//debugger;
|
||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
//fundamental error, can't proceed with this call
|
//fundamental error, can't proceed with this call
|
||||||
// debugger;
|
// debugger;
|
||||||
var errorMessage =
|
var errorMessage =
|
||||||
"API error: GET route =" + route + ", message =" + error.message;
|
"API error: GET route =" + route + ", message =" + error.message;
|
||||||
store.commit("logItem", errorMessage);
|
store.commit("logItem", errorMessage);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/* eslint-disable */
|
/* xeslint-disable */
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import roles from "./roles";
|
import roles from "./roles";
|
||||||
import lt from "../api/locale";
|
import lt from "../api/locale";
|
||||||
import api from "../api/getAPIItem";
|
import api from "../api/apiutil";
|
||||||
|
|
||||||
function addNavItem(title, icon, route) {
|
function addNavItem(title, icon, route) {
|
||||||
store.commit("addNavItem", {
|
store.commit("addNavItem", {
|
||||||
@@ -17,7 +17,6 @@ function addNavItem(title, icon, route) {
|
|||||||
// on change of authentication status
|
// on change of authentication status
|
||||||
export default function initialize() {
|
export default function initialize() {
|
||||||
if (store.state.authenticated) {
|
if (store.state.authenticated) {
|
||||||
|
|
||||||
//GET LOCALIZED TEXT FOR SHELL
|
//GET LOCALIZED TEXT FOR SHELL
|
||||||
lt.fetch([
|
lt.fetch([
|
||||||
"Home",
|
"Home",
|
||||||
@@ -90,31 +89,31 @@ export default function initialize() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//CACHE LOCALE SETTINGS
|
//CACHE LOCALE SETTINGS
|
||||||
debugger;
|
|
||||||
//check the timezone offset is still valid, offer to change it if not
|
//check the timezone offset is still valid, offer to change it if not
|
||||||
//api.get("UserOptions/" + store.state.userId).then(res => {
|
//api.get("UserOptions/" + store.state.userId).then(res => {
|
||||||
api
|
api
|
||||||
.get("UserOptions/bb")
|
.get("UserOptions/bb")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
debugger;
|
if (res.error) {
|
||||||
|
//In a form this would trigger a bunch of validation or error display code but for here and now:
|
||||||
|
//convert error to human readable string for display
|
||||||
|
alert(api.apiErrorToHumanString(res.error));
|
||||||
|
} else {
|
||||||
|
var localOffset = new Date().getTimezoneOffset();
|
||||||
|
if (localOffset != 0) {
|
||||||
|
localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: check if error in return object
|
if (res.data.timeZoneOffset != localOffset) {
|
||||||
//centralize that shit so can easily handle it in client
|
//todo: timezone doesn't match, offer to fix it
|
||||||
|
alert(
|
||||||
var localOffset = new Date().getTimezoneOffset();
|
"Time zone offset for this account is set to " +
|
||||||
if (localOffset != 0) {
|
res.data.timeZoneOffset +
|
||||||
localOffset = (localOffset / 60) * -1; //time is in minutes and reversed from what we want or expect
|
" which doesn't match the local timezone offset of " +
|
||||||
}
|
localOffset +
|
||||||
|
"."
|
||||||
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) {
|
.catch(function(error) {
|
||||||
@@ -124,7 +123,5 @@ export default function initialize() {
|
|||||||
);
|
);
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user