HUGE REFACTOR / CLEANUP

if there is a issue it's probably something in here that was changed
This commit is contained in:
2021-09-28 20:19:44 +00:00
parent 51eddfede9
commit d0afdd9855
238 changed files with 3127 additions and 8614 deletions

View File

@@ -1,4 +1,3 @@
/* Xeslint-disable */
import router from "../router";
function stringifyPrimitive(v) {
@@ -22,7 +21,7 @@ function stringifyPrimitive(v) {
// return true if handled or false if not
//
function handleError(action, error, route) {
let errorMessage =
const errorMessage =
"API error: " + action + " route =" + route + ", message =" + error.message;
window.$gz.store.commit("logItem", errorMessage);
@@ -80,7 +79,6 @@ function handleError(action, error, route) {
//Ideally this should never get called because any issue should be addressed above
window.$gz.errorHandler.handleFormError(error);
// devShowUnknownError(error);
}
export default {
@@ -166,7 +164,7 @@ export default {
//no content, nothing to process
return response;
}
let contentType = response.headers.get("content-type");
const contentType = response.headers.get("content-type");
if (!contentType) {
return response;
@@ -188,7 +186,7 @@ export default {
//no content, nothing to process
return response;
}
let contentType = response.headers.get("content-type");
const contentType = response.headers.get("content-type");
if (!contentType) {
return response;
}
@@ -210,7 +208,6 @@ export default {
},
patchAuthorizedHeaders() {
return {
//Accept: "application/json, text/plain, */*",
Accept: "application/json",
"Content-Type": "application/json-patch+json",
Authorization: "Bearer " + window.$gz.store.state.apiToken
@@ -308,10 +305,7 @@ export default {
//
genericDownloadUrl(route) {
//http://localhost:7575/api/v8/backup/download/100?t=sssss
let url = route + "?t=" + window.$gz.store.state.downloadToken;
return this.APIUrl(url);
return this.APIUrl(route + "?t=" + window.$gz.store.state.downloadToken);
},
/////////////////////////////
// report file download URL
@@ -319,13 +313,12 @@ export default {
reportDownloadUrl(fileName) {
//http://localhost:7575/api/v8/report/download/filename.pdf?t=sssss
let url =
return this.APIUrl(
"report/download/" +
fileName +
"?t=" +
window.$gz.store.state.downloadToken;
return this.APIUrl(url);
fileName +
"?t=" +
window.$gz.store.state.downloadToken
);
},
/////////////////////////////
// backup file download URL
@@ -333,13 +326,12 @@ export default {
backupDownloadUrl(fileName) {
//http://localhost:7575/api/v8/backup/download/100?t=sssss
let url =
return this.APIUrl(
"backup/download/" +
fileName +
"?t=" +
window.$gz.store.state.downloadToken;
return this.APIUrl(url);
fileName +
"?t=" +
window.$gz.store.state.downloadToken
);
},
/////////////////////////////
// attachment download URL
@@ -366,9 +358,7 @@ export default {
// (size= 'small', 'medium', 'large')
logoUrl(size) {
//http://localhost:7575/api/v8/logo/small
let url = "logo/" + size;
return this.APIUrl(url);
return this.APIUrl("logo/" + size);
},
/////////////////////////////
// REPLACE END OF URL
@@ -389,7 +379,7 @@ export default {
if (typeof obj === "object") {
return Object.keys(obj)
.map(function(k) {
let ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
const ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
if (Array.isArray(obj[k])) {
return obj[k]
.map(function(v) {
@@ -416,7 +406,7 @@ export default {
//
async get(route) {
try {
let that = this;
const that = this;
let r = await fetch(that.APIUrl(route), that.fetchGetOptions());
that.statusEx(r);
r = await that.extractBodyEx(r);
@@ -441,7 +431,7 @@ export default {
//
async upsert(route, data, isLogin = false) {
try {
let that = this;
const that = this;
//determine if this is a new or existing record
let fetchOptions = undefined;
//put?
@@ -451,7 +441,6 @@ export default {
//post
//ensure the route doesn't end in /0 which will happen if it's a new record
//since the edit forms just send the url here with the ID regardless
//note: de-lodash was using lodash here endswith method
if (route.endsWith("/0")) {
route = route.slice(0, -2);
}
@@ -471,7 +460,6 @@ export default {
handleError("UPSERT", error, route);
} else {
//specifically this is for the login page
// throw new Error(error);
throw new Error(window.$gz.errorHandler.errorToString(error));
}
}
@@ -480,13 +468,12 @@ export default {
// DELETE DATA FROM API SERVER
//
async remove(route) {
let that = this;
const that = this;
try {
let r = await fetch(that.APIUrl(route), that.fetchRemoveOptions());
that.statusEx(r);
//delete will return a body if there is an error of some kind with the request
r = await that.extractBodyEx(r);
return r;
} catch (error) {
//fundamental error, can't proceed with this call
@@ -498,7 +485,7 @@ export default {
// (used for puts that can't have a concurrency token like above)
async put(route, data) {
try {
let that = this;
const that = this;
let r = await fetch(that.APIUrl(route), that.fetchPutOptions(data));
that.statusEx(r);
r = await that.extractBodyEx(r);
@@ -512,7 +499,7 @@ export default {
// (used for post only routes not needing upserts)
async post(route, data) {
try {
let that = this;
const that = this;
let r = await fetch(that.APIUrl(route), that.fetchPostOptions(data));
that.statusEx(r);
r = await that.extractBodyEx(r);
@@ -526,7 +513,7 @@ export default {
// @param {ayaId:objectid, ayaType:aType, files:[array of files]}
//
async uploadAttachment(at) {
let that = this;
const that = this;
try {
var files = at.files;
var data = new FormData();
@@ -541,7 +528,7 @@ export default {
//-----------------
let fetchOptions = {
const fetchOptions = {
method: "post",
mode: "cors",
headers: {
@@ -565,7 +552,7 @@ export default {
//
//
async upload(route, at) {
let that = this;
const that = this;
try {
var files = at.files;
var data = new FormData();
@@ -585,7 +572,7 @@ export default {
//-----------------
let fetchOptions = {
const fetchOptions = {
method: "post",
mode: "cors",
headers: {
@@ -608,14 +595,14 @@ export default {
//
//
async uploadLogo(fileData, size) {
let that = this;
const that = this;
try {
let data = new FormData();
const data = new FormData();
data.append(fileData.name, fileData);
//-----------------
let fetchOptions = {
const fetchOptions = {
method: "post",
mode: "cors",
headers: {
@@ -654,13 +641,13 @@ export default {
//
//
async renderReport(objectid, reportid, redirectNotPopup) {
let reportDataOptions = {
const reportDataOptions = {
ReportId: reportid,
SelectedRowIds: [objectid],
ClientMeta: this.reportClientMetaData()
};
let res = await window.$gz.api.upsert("report/render", reportDataOptions);
const res = await window.$gz.api.upsert("report/render", reportDataOptions);
if (res.error) {
if (redirectNotPopup) {
return res;
@@ -668,7 +655,7 @@ export default {
throw new Error(window.$gz.errorHandler.errorToString(res));
}
} else {
let reportUrl = window.$gz.api.reportDownloadUrl(res.data);
const reportUrl = window.$gz.api.reportDownloadUrl(res.data);
if (redirectNotPopup) {
//used for direct report open from direct report view url
window.location.replace(reportUrl);
@@ -686,10 +673,7 @@ export default {
//
//
async fetchBizObjectName(ayaType, objectId) {
//todo: this is a good candidate for a light weight cache
//maybe one hour or something to invalidate and volatile on refresh
let res = await this.get(`name/${ayaType}/${objectId}`);
const res = await this.get(`name/${ayaType}/${objectId}`);
//We never expect there to be no data here
if (!res.hasOwnProperty("data")) {
return Promise.reject(res);