From 2a2bcc5f7f6d6e484fb1e8b756484847d7360308 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 7 Oct 2020 17:33:37 +0000 Subject: [PATCH] --- ayanova/src/api/enums.js | 20 ++++++------- ayanova/src/api/errorhandler.js | 2 +- ayanova/src/api/form-custom-template.js | 12 ++++---- ayanova/src/api/gzform.js | 30 +++++++++++-------- ayanova/src/api/gzutil.js | 24 +++++++++++++++ ayanova/src/api/translation.js | 15 ++++++---- .../src/components/custom-fields-control.vue | 16 ++++++---- 7 files changed, 80 insertions(+), 39 deletions(-) diff --git a/ayanova/src/api/enums.js b/ayanova/src/api/enums.js index 1623e10c..a51dc27e 100644 --- a/ayanova/src/api/enums.js +++ b/ayanova/src/api/enums.js @@ -44,21 +44,18 @@ export default { //de-lodash // //turn it into an array suitable for selection lists - // window.$gz._.forOwn(e, function(value, key) { + // window.$gz. _.forOwn(e, function(value, key) { // ret.push({ id: Number(key), name: value }); // }); + //return window.$gz. _.sortBy(ret, "name"); //turn it into an array suitable for selection lists for (const [key, value] of Object.entries(e)) { ret.push({ id: Number(key), name: value }); } - - //e is an object with keys of id values i.e. {1:"display1",2:"display 2"} - //what needs to be returned is an array of objects like: [{id:1,name:"display1"},{id:2,name:"display2"}] - - console.log("enum::getSelectionList, e is: ", e); - console.log("ret is", ret); - return window.$gz._.sortBy(ret, "name"); + //sort by name + ret.sort(window.$gz.util.sortByKey("name")); + return ret; }, /////////////////////////////////// // @@ -67,7 +64,7 @@ export default { // ACCEPTS an ARRAY or a single STRING KEY // async fetchEnumList(enumKey) { - if (!window.$gz._.isArray(enumKey)) { + if (!Array.isArray(enumKey)) { enumKey = [enumKey]; } for (let i = 0; i < enumKey.length; i++) { @@ -75,7 +72,10 @@ export default { //if not then fetch it and store it let k = enumKey[i].toLowerCase(); - if (!window.$gz._.has(window.$gz.store.state.enums, k)) { + //de-lodash + // if (!window.$gz. _.has(window.$gz.store.state.enums, k)) { + //enums is an object this is checking if that object has a key with the name in k + if (!window.$gz.util.has(window.$gz.store.state.enums, k)) { let that = this; // eslint-disable-next-line let dat = await that.fetchEnumKey(k); diff --git a/ayanova/src/api/errorhandler.js b/ayanova/src/api/errorhandler.js index 716b829b..22df189c 100644 --- a/ayanova/src/api/errorhandler.js +++ b/ayanova/src/api/errorhandler.js @@ -48,7 +48,7 @@ function dealWithError(msg, vm) { //should be able to display in form... if (vm.$ay.dev) { //make sure formState.appError is defined on data - if (!window.$gz._.has(vm, "formState.appError")) { + if (!window.$gz.util.has(vm, "formState.appError")) { throw new Error( "DEV ERROR errorHandler::dealWithError -> formState.appError seems to be missing from form's vue data object" ); diff --git a/ayanova/src/api/form-custom-template.js b/ayanova/src/api/form-custom-template.js index d3db4f15..6eaa7ce1 100644 --- a/ayanova/src/api/form-custom-template.js +++ b/ayanova/src/api/form-custom-template.js @@ -18,7 +18,9 @@ function addDataKeyNames(obj) { export default { // cache the form customization data if it's not already present async get(formKey) { - if (!window.$gz._.has(window.$gz.store.state.formCustomTemplate, formKey)) { + if ( + !window.$gz.util.has(window.$gz.store.state.formCustomTemplate, formKey) + ) { //fetch and populate the store let res = await window.$gz.api.get("form-custom/" + formKey); if (res.error) { @@ -56,11 +58,11 @@ export default { ); } - //_https://lodash.com/docs#find //Note that not every field being requested will exist so it's valid to return undefined - let templateItem = window.$gz._.find(template, ["fld", fieldKey]); - - return templateItem; + //template is an array of objects that contain a key called "fld" + //de-lodash + //let templateItem = window.$gz. _.find(template, ["fld", fieldKey]); + return template.find(z => z.fld == fieldKey); }, getTemplateConcurrencyToken(formKey) { let tok = diff --git a/ayanova/src/api/gzform.js b/ayanova/src/api/gzform.js index d6d64fd1..578b8710 100644 --- a/ayanova/src/api/gzform.js +++ b/ayanova/src/api/gzform.js @@ -506,11 +506,13 @@ export default { //See if control formCustomTemplateFieldName is in server required fields collection //this is a collection of both custom field definitions and standard form fields that are required //since all names are unique can just filter out the one we need by name which will inherently ignore custom fields by default - //_https://lodash.com/docs#find - let templateItem = window.$gz._.find(template, [ - "fld", - formCustomTemplateFieldName - ]); + //de-lodash + // let templateItem = window.$gz. _.find(template, [ + // "fld", + // formCustomTemplateFieldName + // ]); + + let templateItem = template.find(z => z.fld == formCustomTemplateFieldName); //templateItem.required if (templateItem === undefined || templateItem.required !== true) { @@ -590,21 +592,21 @@ export default { //CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC if (vm.$ay.dev) { //make sure formState.serverErrors is defined on data - if (!window.$gz._.has(vm, "formState.serverError")) { + if (!window.$gz.util.has(vm, "formState.serverError")) { throw new Error( "DEV ERROR gzform::formState.serverErrors -> formState.serverError seems to be missing from form's vue data object" ); } //make sure formState.appError is defined on data - if (!window.$gz._.has(vm, "formState.appError")) { + if (!window.$gz.util.has(vm, "formState.appError")) { throw new Error( "DEV ERROR gzform::formState.serverErrors -> formState.appError seems to be missing from form's vue data object" ); } //make sure formState.errorBoxMessage is defined on data - if (!window.$gz._.has(vm, "formState.errorBoxMessage")) { + if (!window.$gz.util.has(vm, "formState.errorBoxMessage")) { throw new Error( "DEV ERROR gzform::formState.serverErrors -> formState.errorBoxMessage seems to be missing from form's vue data object" ); @@ -726,11 +728,13 @@ export default { //See if control templateFieldName is in server required fields collection //this is a collection of both custom field definitions and standard form fields that are required //since all names are unique can just filter out the one we need by name which will inherently ignore custom fields by default - //_https://lodash.com/docs#find - let templateItem = window.$gz._.find(template, [ - "fld", - formCustomTemplateFieldName - ]); + //de-lodash + // let templateItem = window.$gz. _.find(template, [ + // "fld", + // formCustomTemplateFieldName + // ]); + + let templateItem = template.find(z => z.fld == formCustomTemplateFieldName); if (templateItem === undefined || templateItem.hide !== true) { return true; diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js index 7f966bc1..bd3da394 100644 --- a/ayanova/src/api/gzutil.js +++ b/ayanova/src/api/gzutil.js @@ -383,6 +383,30 @@ export default { sleepAsync: function(milliseconds) { // eslint-disable-next-line return new Promise((resolve) => setTimeout(resolve, milliseconds)); + }, + /////////////////////////////////////////////// + // sortByKey lodash "sortBy" replacement + // https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_sortby-and-_orderby + //usage: + // The native sort modifies the array in place. `_.orderBy` and `_.sortBy` do not, so we use `.concat()` to + // copy the array, then sort. + // fruits.concat().sort(sortBy("name")); + // => [{name:"apple", amount: 4}, {name:"banana", amount: 2}, {name:"mango", amount: 1}, {name:"pineapple", amount: 2}] + sortByKey: key => { + return (a, b) => (a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0); + }, + /////////////////////////////////////////////// + // "has" lodash replacement + // https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_has + // + has: function(obj, key) { + var keyParts = key.split("."); + return ( + !!obj && + (keyParts.length > 1 + ? has(obj[key.split(".")[0]], keyParts.slice(1).join(".")) + : hasOwnProperty.call(obj, key)) + ); } /** diff --git a/ayanova/src/api/translation.js b/ayanova/src/api/translation.js index ccd1815b..545469fd 100644 --- a/ayanova/src/api/translation.js +++ b/ayanova/src/api/translation.js @@ -17,9 +17,14 @@ export default { cachekey ) { //find match - let display = window.$gz._.find(editedTranslation.translationItems, { - key: cachekey - }).display; + //de-lodash + // let display = window.$gz. _.find(editedTranslation.translationItems, { + // key: cachekey + // }).display; + let display = editedTranslation.translationItems.find( + z => z.key == cachekey + ).display; + window.$gz.store.commit("setTranslationText", { key: cachekey, value: display @@ -48,7 +53,7 @@ export default { if (key == "Wiki") { return "Wiki"; } - if (!window.$gz._.has(window.$gz.store.state.translationText, key)) { + if (!window.$gz.util.has(window.$gz.store.state.translationText, key)) { return "??" + key; } return window.$gz.store.state.translationText[key]; @@ -62,7 +67,7 @@ export default { let needIt = []; for (let i = 0; i < keys.length; i++) { if ( - !window.$gz._.has(window.$gz.store.state.translationText, keys[i]) + !window.$gz.util.has(window.$gz.store.state.translationText, keys[i]) ) { needIt.push(keys[i]); } diff --git a/ayanova/src/components/custom-fields-control.vue b/ayanova/src/components/custom-fields-control.vue index 88a1e1dc..e927472a 100644 --- a/ayanova/src/components/custom-fields-control.vue +++ b/ayanova/src/components/custom-fields-control.vue @@ -233,7 +233,9 @@ export default { return false; } //iterate template and see if it has any custom fields set to display - return window.$gz._.find(template, "type") != undefined; + //de-lodash + //return window.$gz. _.find(template, "type") != undefined; + return template.find(z => z.type != undefined); }, GetValueForField: function(dataKey) { if (!this.value) { @@ -252,9 +254,13 @@ export default { //Get the field data type //https://lodash.com/docs#find - let ctrlType = window.$gz._.find( - this.$store.state.formCustomTemplate[this.formKey], - ["dataKey", dataKey] + // let ctrlType = window.$gz._.find( + // this.$store.state.formCustomTemplate[this.formKey], + // ["dataKey", dataKey] + // ).type; + + let ctrlType = this.$store.state.formCustomTemplate[this.formKey].find( + z => z.dataKey == dataKey ).type; //First get current value for the data that came from the server @@ -327,7 +333,7 @@ export default { //Get the current data out of the json string value // let cData = JSON.parse(this.value); - if (!window.$gz._.has(cData, dataKey)) { + if (!window.$gz.util.has(cData, dataKey)) { cData[dataKey] = null; }