This commit is contained in:
2020-06-19 22:47:57 +00:00
parent 7067e26a24
commit 70f035f90e
5 changed files with 63 additions and 213 deletions

View File

@@ -34,7 +34,6 @@ export default {
if (!window.$gz._.isArray(enumKey)) { if (!window.$gz._.isArray(enumKey)) {
enumKey = [enumKey]; enumKey = [enumKey];
} }
for (let i = 0; i < enumKey.length; i++) { for (let i = 0; i < enumKey.length; i++) {
//check if list //check if list
//if not then fetch it and store it //if not then fetch it and store it
@@ -43,27 +42,25 @@ export default {
if (!window.$gz._.has(window.$gz.store.state.enums, k)) { if (!window.$gz._.has(window.$gz.store.state.enums, k)) {
let that = this; let that = this;
// eslint-disable-next-line // eslint-disable-next-line
await that.fetchEnumKey(k).then((dat) => { let dat = await that.fetchEnumKey(k);
//massage the data as necessary //massage the data as necessary
let e = { enumKey: k, items: {} }; let e = { enumKey: k, items: {} };
for (let i = 0; i < dat.length; i++) { for (let i = 0; i < dat.length; i++) {
let o = dat[i]; let o = dat[i];
e.items[o.id] = o.name; e.items[o.id] = o.name;
} }
//stuff the data into the store //stuff the data into the store
window.$gz.store.commit("setEnum", e); window.$gz.store.commit("setEnum", e);
});
} }
} }
}, },
fetchEnumKey(enumKey) { async fetchEnumKey(enumKey) {
// eslint-disable-next-line // eslint-disable-next-line
return window.$gz.api.get("enum-list/list/" + enumKey).then((res) => { let res = await window.$gz.api.get("enum-list/list/" + enumKey);
//We never expect there to be no data here //We never expect there to be no data here
if (!res.data) { if (!res.data) {
throw res; throw res;
} }
return res.data; return res.data;
});
} }
}; };

View File

@@ -17,30 +17,19 @@ function addDataKeyNames(obj) {
export default { export default {
// cache the form customization data if it's not already present // cache the form customization data if it's not already present
//cache invalidation is hard, this needs it...hmmm.... async get(formKey) {
//for now will rely on logout and back in to clear up any customization issues if (!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey)) {
get(formKey) { //fetch and populate the store
return new Promise(function getFormTemplate(resolve) { let res = await window.$gz.api.get("form-custom/" + formKey);
if ( if (res.error) {
!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey) throw res.error;
) {
//fetch and populate the store
window.$gz.api.get("form-custom/" + formKey).then(res => {
if (res.error) {
throw res.error;
}
window.$gz.store.commit("setFormCustomTemplateItem", {
formKey: formKey,
concurrency: res.data.concurrency,
value: addDataKeyNames(JSON.parse(res.data.template))
});
resolve();
});
} else {
resolve();
} }
}); window.$gz.store.commit("setFormCustomTemplateItem", {
formKey: formKey,
concurrency: res.data.concurrency,
value: addDataKeyNames(JSON.parse(res.data.template))
});
}
}, },
set(formKey, token, template) { set(formKey, token, template) {
window.$gz.store.commit("setFormCustomTemplateItem", { window.$gz.store.commit("setFormCustomTemplateItem", {

View File

@@ -423,7 +423,7 @@ export default {
/////////////////////////////////// ///////////////////////////////////
// GET DATA FROM API SERVER // GET DATA FROM API SERVER
// //
async getEx(route) { async get(route) {
try { try {
let that = this; let that = this;
let r = await fetch(that.APIUrl(route), that.fetchGetOptions()); let r = await fetch(that.APIUrl(route), that.fetchGetOptions());
@@ -435,25 +435,7 @@ export default {
handleError("GET", error, route, reject); handleError("GET", error, route, reject);
} }
}, },
///////////////////////////////////
// GET DATA FROM API SERVER
//
get(route) {
let that = this;
return new Promise(function getDataFromServer(resolve, reject) {
fetch(that.APIUrl(route), that.fetchGetOptions())
.then(that.status)
.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
resolve(response);
})
.catch(function handleGetError(error) {
//fundamental error, can't proceed with this call
handleError("GET", error, route, reject);
});
});
},
////////////////////////////////////// //////////////////////////////////////
// Test delay for troubleshooting // Test delay for troubleshooting
// //
@@ -504,7 +486,7 @@ export default {
/////////////////////////////////// ///////////////////////////////////
// DELETE DATA FROM API SERVER // DELETE DATA FROM API SERVER
// //
async removeEx(route) { async remove(route) {
let that = this; let that = this;
try { try {
let r = await fetch(that.APIUrl(route), that.fetchRemoveOptions()); let r = await fetch(that.APIUrl(route), that.fetchRemoveOptions());
@@ -517,67 +499,27 @@ export default {
handleError("DELETE", error, route); handleError("DELETE", error, route);
} }
}, },
///////////////////////////////////
// DELETE DATA FROM API SERVER
//
remove(route) {
let that = this;
return new Promise(function removeDataFromServer(resolve, reject) {
fetch(that.APIUrl(route), that.fetchRemoveOptions())
.then(that.status)
//.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
resolve(response);
})
.catch(function handleRemoveError(error) {
//fundamental error, can't proceed with this call
handleError("DELETE", error, route, reject);
});
});
},
///////////////////////////////////
// POST DUPLICATE TO API SERVER
//
duplicate(route) {
let that = this;
return new Promise(function duplicateRecordOnServer(resolve, reject) {
fetch(that.APIUrl(route), that.fetchPostOptions(null))
.then(that.status)
.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
//Note: response.error indicates there is an error, however this is not an unusual condition
//it could be validation errors or other general error so we need to treat it here like it's normal
//and let the caller deal with it appropriately
resolve(response);
})
.catch(function handleDuplicateError(error) {
handleError("DUPLICATE", error, route, reject);
});
});
},
/////////////////////////////////// ///////////////////////////////////
// POST FILE ATTACHMENTS // POST FILE ATTACHMENTS
// @param {ayaId:objectid, ayaType:objectType, files:[array of files]} // @param {ayaId:objectid, ayaType:objectType, files:[array of files]}
// //
uploadAttachment(at) { async uploadAttachment(at) {
let that = this; let that = this;
try {
var files = at.files;
var data = new FormData();
for (var i = 0; i < files.length; i++) {
data.append(files[i].name, files[i]);
}
var files = at.files; data.append("AttachToObjectType", at.ayaType);
var data = new FormData(); data.append("AttachToObjectId", at.ayaId);
for (var i = 0; i < files.length; i++) { data.append("Notes", at.notes);
data.append(files[i].name, files[i]); data.append("FileData", at.fileData);
}
data.append("AttachToObjectType", at.ayaType); //-----------------
data.append("AttachToObjectId", at.ayaId);
data.append("Notes", at.notes);
data.append("FileData", at.fileData);
//-----------------
return new Promise(function postAttachmentToServer(resolve, reject) {
let fetchOptions = { let fetchOptions = {
method: "post", method: "post",
mode: "cors", mode: "cors",
@@ -587,19 +529,15 @@ export default {
body: data body: data
}; };
fetch(that.APIUrl("attachment"), fetchOptions) let r = await fetch(that.APIUrl("attachment"), fetchOptions);
.then(that.status) that.statusEx(r);
.then(that.extractBody) r = await that.extractBodyEx(r);
// eslint-disable-next-line return r;
.then((response) => { } catch (error) {
resolve(response); handleError("POSTATTACHMENT", error, route, reject);
}) }
.catch(function handlePostAttachment(error) {
handleError("POSTATTACHMENT", error, route, reject);
});
});
//---------------
} }
//---------------
//new functions above here //new functions above here
}; };

View File

@@ -216,7 +216,7 @@ export default {
} }
}; };
}, },
created() { async created() {
let vm = this; let vm = this;
//------------------ //------------------
//Test ui feedback mechanisms here: //Test ui feedback mechanisms here:
@@ -242,16 +242,14 @@ export default {
icon: "", icon: "",
title: "" title: ""
}); });
window.$gz.api try {
.get("notify/hello") let res = await window.$gz.api.get("notify/hello");
.then(res => { if (res.data != null) {
if (res.data != null) { vm.showEvalUsers = res.data;
vm.showEvalUsers = res.data; }
} } catch (error) {
}) //squash it, this isn't critical
.catch(function handleGetTrialModeError(error) { }
//squash it, this isn't critical
});
}, },
methods: { methods: {
@@ -274,9 +272,6 @@ export default {
let vm = this; let vm = this;
if (vm.input.username != "" && vm.input.password != "") { if (vm.input.username != "" && vm.input.password != "") {
vm.errorBadCreds = false; vm.errorBadCreds = false;
//auth directly bypass auth here
//==========================
let loggedInWithKnownPassword = let loggedInWithKnownPassword =
vm.input.username == "superuser" && vm.input.password == "l3tm3in"; vm.input.username == "superuser" && vm.input.password == "l3tm3in";
@@ -347,75 +342,6 @@ export default {
return; return;
} }
} }
//==========================
//############## OLD AUTH ########################
// auth
// .authenticate(vm.input.username, vm.input.password)
// .then(() => {
// /*public enum LicenseStatus
// {
// NONE = 0,//fast track
// ActiveTrial = 1,//slow track
// ExpiredTrial = 2,//fast track
// ActivePurchased = 3,//slow track
// ExpiredPurchased = 4,//fast track
// Revoked = 5//slow track
// } */
// //check if support and updates has expired and is paid for license and show warning if so
// if (
// vm.$store.state.globalSettings.maintenanceExpired &&
// (vm.$store.state.globalSettings.licenseStatus == 3 ||
// vm.$store.state.globalSettings.licenseStatus == 4)
// ) {
// (async function() {
// await window.$gz.dialog.displayLTModalNotificationMessage(
// "MaintenanceExpiredNote",
// "MaintenanceExpired",
// "error",
// "https://www.ayanova.com/subscriptionexpired.htm"
// );
// })();
// }
// if (vm.$store.state.openObject != null) {
// window.$gz.eventBus.$emit("openobject", null);
// } else {
// vm.$router.push(vm.$store.state.homePage);
// }
// })
// .catch(function handleCaughtLoginError(error) {
// //bad creds?
// if (
// error.message &&
// error.message.includes("ErrorUserNotAuthenticated")
// ) {
// vm.errorBadCreds = true;
// return;
// }
// //server closed by server state setting?
// if (error.code == 2000 || error.code == 2001) {
// vm.formState.errorBoxMessage = error.message;
// return;
// }
// //probably here because server unresponsive.
// if (error.message) {
// let msg = error.message;
// if (
// msg.includes("NetworkError") ||
// msg.includes("Failed to fetch")
// ) {
// msg =
// "Could not connect to AyaNova server at " +
// window.$gz.api.APIUrl("") +
// "\r\nError: " +
// error.message;
// }
// vm.formState.errorBoxMessage = msg;
// return;
// }
// });
//#################################################
} }
} }
}, },

View File

@@ -429,7 +429,7 @@ export default {
try { try {
window.$gz.form.deleteAllErrorBoxErrors(vm); window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.getEx(url); let res = await window.$gz.api.get(url);
if (res.error) { if (res.error) {
//Not found? //Not found?
@@ -523,7 +523,7 @@ export default {
let url = API_BASE_URL + vm.$route.params.recordid; let url = API_BASE_URL + vm.$route.params.recordid;
window.$gz.form.deleteAllErrorBoxErrors(vm); window.$gz.form.deleteAllErrorBoxErrors(vm);
let res = await window.$gz.api.removeEx(url); let res = await window.$gz.api.remove(url);
if (res.error) { if (res.error) {
vm.formState.serverError = res.error; vm.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(vm); window.$gz.form.setErrorBoxErrors(vm);