From 5caae16a8322ceab62c4bbeb439a9004c6a2fa62 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 18 Apr 2019 20:06:53 +0000 Subject: [PATCH] refactoring, renaming capitalized functions to proper case, etc --- ayanova/devdocs/todo.txt | 2 +- ayanova/src/api/errorhandler.js | 2 +- ayanova/src/api/gzutil.js | 2 +- ayanova/src/api/gzvalidate.js | 57 +++++++++++---------- ayanova/src/api/initialize.js | 26 +++++----- ayanova/src/api/roles.js | 2 +- ayanova/src/views/inventory-widget-edit.vue | 56 ++++++++++---------- 7 files changed, 75 insertions(+), 72 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index 79e1a2b1..ff8f24e1 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -255,7 +255,7 @@ Make all fields work according to specs below - Use browser Numeric format - Override browser with these numeric format settings instead (see below) - Digit grouping symbol i.e. the , in 1,000,000 - - Decimal symbol i.e. the . in 1.00 + - decimalValid symbol i.e. the . in 1.00 - Currency symbol string (may be more than one character in some locales i.e. "Eur") - negative display format one of these: -1.1, (1.1), 1.1- - Use browser Datetime format diff --git a/ayanova/src/api/errorhandler.js b/ayanova/src/api/errorhandler.js index 1595e3b0..1a496172 100644 --- a/ayanova/src/api/errorhandler.js +++ b/ayanova/src/api/errorhandler.js @@ -30,7 +30,7 @@ function dealWithError(msg, form) { } } form.appError = msg; - form.$gzv.SetErrorBoxErrors(form); + form.$gzv.setErrorBoxErrors(form); } } export default { diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js index 942744c0..f4db50ff 100644 --- a/ayanova/src/api/gzutil.js +++ b/ayanova/src/api/gzutil.js @@ -9,7 +9,7 @@ export default { // Clear all properties from object without resorting to assigning a new object (o={}) // which can be problematic in some cases (IE bugs, watched data items in forms etc) - RemoveAllPropertiesFromObject(o) { + removeAllPropertiesFromObject(o) { for (var variableKey in o) { if (o.hasOwnProperty(variableKey)) { delete o[variableKey]; diff --git a/ayanova/src/api/gzvalidate.js b/ayanova/src/api/gzvalidate.js index d3d0e1b3..ee97c004 100644 --- a/ayanova/src/api/gzvalidate.js +++ b/ayanova/src/api/gzvalidate.js @@ -95,7 +95,7 @@ function getErrorsForField(v, ref) { // ERROR BOX ERRORS // gathers any messages for error box on form which is the generic catch all for non field specific errors from server // and application itself locally -function GetErrorBoxErrors(v, errs) { +function getErrorBoxErrors(v, errs) { var hasErrors = false; var ret = ""; if (errs.length > 0) { @@ -123,7 +123,7 @@ export default { /////////////////////////////// // REQUIRED // - Required(v, ref) { + required(v, ref) { var ctrl = getControl(v, ref); if (typeof ctrl == "undefined") { return false; @@ -145,7 +145,7 @@ export default { /////////////////////////////// // MAXLENGTH // - MaxLength(v, ref, max) { + maxLength(v, ref, max) { var ctrl = getControl(v, ref); if (typeof ctrl == "undefined") { return false; @@ -171,12 +171,14 @@ export default { /////////////////////////////// // MAX 255 // - Max255(v, ref) { - return this.MaxLength(v, ref, 255); + max255(v, ref) { + return this.maxLength(v, ref, 255); }, /////////////////////////////// - // AFTER - After(v, refStart, refEnd) { + // DatePrecedence + // (start date must precede end date) + // + datePrecedence(v, refStart, refEnd) { var ctrlStart = getControl(v, refStart); if (typeof ctrlStart == "undefined") { return false; @@ -214,16 +216,16 @@ export default { } }, /////////////////////////////// - // INTEGER + // INTEGER IS VALID // - Integer(v, ref) { + integerValid(v, ref) { var ctrl = getControl(v, ref); if (typeof ctrl == "undefined") { return false; } //DEBUG - //logControl("Integer", ctrl, ref); + //logControl("integerValid", ctrl, ref); var value = getControlValue(ctrl); if (isEmpty(value)) { @@ -242,7 +244,8 @@ export default { /////////////////////////////// // DECIMAL // Basically anything that can be a number is valid - Decimal(v, ref) { + // + decimalValid(v, ref) { //TODO: Handle commas and spaces in numbers //as per v.$gzlocale rules for numbers @@ -252,7 +255,7 @@ export default { } //DEBUG - //logControl("Decimal", ctrl, ref); + //logControl("decimalValid", ctrl, ref); var value = getControlValue(ctrl); if (isEmpty(value)) { @@ -272,29 +275,29 @@ export default { // SERVER ERRORS // Process and return server errors if any for form and field specified // - ServerErrors(v, ref) { + serverErrors(v, ref) { //CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC if (v.$gzdevmode()) { //make sure serverErrors is defined on data if (!v.$_.has(v, "serverError")) { - throw "DEV ERROR gzvalidate::ServerErrors -> serverError seems to be missing from form's vue data object"; + throw "DEV ERROR gzvalidate::serverErrors -> serverError seems to be missing from form's vue data object"; } //make sure appError is defined on data if (!v.$_.has(v, "appError")) { - throw "DEV ERROR gzvalidate::ServerErrors -> appError seems to be missing from form's vue data object"; + throw "DEV ERROR gzvalidate::serverErrors -> appError seems to be missing from form's vue data object"; } //make sure errorBoxMessage is defined on data if (!v.$_.has(v, "errorBoxMessage")) { - throw "DEV ERROR gzvalidate::ServerErrors -> errorBoxMessage seems to be missing from form's vue data object"; + throw "DEV ERROR gzvalidate::serverErrors -> errorBoxMessage seems to be missing from form's vue data object"; } //ensure the error returned is in an expected format to catch coding errors at the server end if (!v.$_.isEmpty(v.serverError)) { //Make sure there is an error code if there is an error collection if (!v.serverError.code) { - throw "DEV ERROR gzvalidate::ServerErrors -> server returned error without code"; + throw "DEV ERROR gzvalidate::serverErrors -> server returned error without code"; } } } @@ -317,7 +320,7 @@ export default { ret.push(err); } //DETAIL ERRORS - //{"error":{"code":"2200","details":[{"message":"Exception: Error converting value \"\" to type 'AyaNova.Biz.AuthorizationRoles'. Path 'roles', line 1, position 141.","target":"roles","error":"2203"}],"message":"Object did not pass validation"}} + //{"error":{"code":"2200","details":[{"message":"Exception: Error converting value \"\" to type 'AyaNova.Biz.AUTHORIZATION_ROLES'. Path 'roles', line 1, position 141.","target":"roles","error":"2203"}],"message":"Object did not pass validation"}} //Specific field validation errors are in an array in "details" key if (!v.$_.isEmpty(v.serverError.details)) { //See if this key is in the details array @@ -352,28 +355,28 @@ export default { // ClearServerErrors // Clear all server errors and app errors and ensure error box doesn't show // - DeleteAllErrorBoxErrors(v) { + deleteAllErrorBoxErrors(v) { //clear all keys from server error - v.$gzutil.RemoveAllPropertiesFromObject(v.serverError); + v.$gzutil.removeAllPropertiesFromObject(v.serverError); //clear app errors v.appError = null; //clear out actual message box display v.errorBoxMessage = null; }, /////////////////////////////// - // SetErrorBoxErrors + // setErrorBoxErrors // Gather server errors and set the appropriate keys // - SetErrorBoxErrors(v) { - var errs = this.ServerErrors(v, "errorbox"); - var ret = GetErrorBoxErrors(v, errs); + setErrorBoxErrors(v) { + var errs = this.serverErrors(v, "errorbox"); + var ret = getErrorBoxErrors(v, errs); v.errorBoxMessage = ret; }, /////////////////////////////// - // On Change handler + // On onChange handler // This is required so that server errors can be cleared when input is changed // - Change(v, ref) { + onChange(v, ref) { if (triggeringChange) { return; } @@ -389,7 +392,7 @@ export default { if (v.serverError.details && v.serverError.details.length < 1) { if (v.serverError.code == "2200") { //clear all keys from server error - v.$gzutil.RemoveAllPropertiesFromObject(v.serverError); + v.$gzutil.removeAllPropertiesFromObject(v.serverError); } } diff --git a/ayanova/src/api/initialize.js b/ayanova/src/api/initialize.js index a6ac5cbe..e69001e7 100644 --- a/ayanova/src/api/initialize.js +++ b/ayanova/src/api/initialize.js @@ -26,29 +26,29 @@ export default function initialize() { addNavItem(locale.get("Home"), "home", "/"); if ( - roles.hasRole(roles.AuthorizationRoles.TechLimited) || - roles.hasRole(roles.AuthorizationRoles.TechFull) || - roles.hasRole(roles.AuthorizationRoles.SubContractorLimited) || - roles.hasRole(roles.AuthorizationRoles.SubContractorFull) + roles.hasRole(roles.AUTHORIZATION_ROLES.TechLimited) || + roles.hasRole(roles.AUTHORIZATION_ROLES.TechFull) || + roles.hasRole(roles.AUTHORIZATION_ROLES.SubContractorLimited) || + roles.hasRole(roles.AUTHORIZATION_ROLES.SubContractorFull) ) { addNavItem(locale.get("Service"), "toolbox", "/service"); } if ( - roles.hasRole(roles.AuthorizationRoles.DispatchLimited) || - roles.hasRole(roles.AuthorizationRoles.DispatchFull) + roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchLimited) || + roles.hasRole(roles.AUTHORIZATION_ROLES.DispatchFull) ) { addNavItem(locale.get("Dispatch"), "shipping-fast", "/dispatch"); } if ( - roles.hasRole(roles.AuthorizationRoles.InventoryLimited) || - roles.hasRole(roles.AuthorizationRoles.InventoryFull) + roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryLimited) || + roles.hasRole(roles.AUTHORIZATION_ROLES.InventoryFull) ) { addNavItem(locale.get("Inventory"), "dolly", "/inventory"); } - if (roles.hasRole(roles.AuthorizationRoles.AccountingFull)) { + if (roles.hasRole(roles.AUTHORIZATION_ROLES.AccountingFull)) { addNavItem( locale.get("Accounting"), "file-invoice-dollar", @@ -57,15 +57,15 @@ export default function initialize() { } if ( - roles.hasRole(roles.AuthorizationRoles.BizAdminLimited) || - roles.hasRole(roles.AuthorizationRoles.BizAdminFull) + roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminLimited) || + roles.hasRole(roles.AUTHORIZATION_ROLES.BizAdminFull) ) { addNavItem(locale.get("Administration"), "user-tie", "/admin"); } if ( - roles.hasRole(roles.AuthorizationRoles.OpsAdminFull) || - roles.hasRole(roles.AuthorizationRoles.OpsAdminLimited) + roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminFull) || + roles.hasRole(roles.AUTHORIZATION_ROLES.OpsAdminLimited) ) { addNavItem(locale.get("Operations"), "cogs", "ops"); } diff --git a/ayanova/src/api/roles.js b/ayanova/src/api/roles.js index 6aae7f22..0ac2696c 100644 --- a/ayanova/src/api/roles.js +++ b/ayanova/src/api/roles.js @@ -1,6 +1,6 @@ import store from "../store"; export default { - AuthorizationRoles: { + AUTHORIZATION_ROLES: { ///No role set NoRole: 0, ///BizAdminLimited diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index 9e2887b3..1c48c965 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -21,10 +21,10 @@ clearable :counter="255" :label="this.$gzlocale.get('WidgetName')" - :rules="[this.$gzv.Max255(this,'name'),this.$gzv.Required(this,'name')]" - :error-messages="this.$gzv.ServerErrors(this,'name')" + :rules="[this.$gzv.max255(this,'name'),this.$gzv.required(this,'name')]" + :error-messages="this.$gzv.serverErrors(this,'name')" ref="name" - @change="Change('name')" + @change="onChange('name')" > @@ -33,10 +33,10 @@ clearable :counter="10" :label="this.$gzlocale.get('WidgetSerial')" - :rules="[this.$gzv.MaxLength(this,'serial',10)]" - :error-messages="this.$gzv.ServerErrors(this,'serial')" + :rules="[this.$gzv.maxLength(this,'serial',10)]" + :error-messages="this.$gzv.serverErrors(this,'serial')" ref="serial" - @change="Change('serial')" + @change="onChange('serial')" > @@ -46,10 +46,10 @@ :counter="10" :label="this.$gzlocale.get('WidgetCount')" ref="count" - :rules="[this.$gzv.Integer(this,'count'),this.$gzv.Required(this,'count')]" - :error-messages="this.$gzv.ServerErrors(this,'count')" + :rules="[this.$gzv.integerValid(this,'count'),this.$gzv.required(this,'count')]" + :error-messages="this.$gzv.serverErrors(this,'count')" required - @change="Change('count')" + @change="onChange('count')" type="number" > @@ -61,9 +61,9 @@ :label="this.$gzlocale.get('WidgetDollarAmount')" ref="dollarAmount" required - :rules="[this.$gzv.Decimal(this,'dollarAmount'),this.$gzv.Required(this,'dollarAmount')]" - :error-messages="this.$gzv.ServerErrors(this,'dollarAmount')" - @change="Change('dollarAmount')" + :rules="[this.$gzv.decimalValid(this,'dollarAmount'),this.$gzv.required(this,'dollarAmount')]" + :error-messages="this.$gzv.serverErrors(this,'dollarAmount')" + @change="onChange('dollarAmount')" type="number" > @@ -73,19 +73,19 @@ :label="this.$gzlocale.get('WidgetStartDate')" v-model="obj.startDate" ref="startDate" - :error-messages="this.$gzv.ServerErrors(this,'startDate')" - @change="Change('startDate')" + :error-messages="this.$gzv.serverErrors(this,'startDate')" + @change="onChange('startDate')" > @@ -93,9 +93,9 @@ v-model="obj.active" :label="this.$gzlocale.get('Active')" ref="active" - :error-messages="this.$gzv.ServerErrors(this,'active')" + :error-messages="this.$gzv.serverErrors(this,'active')" required - @change="Change('active')" + @change="onChange('active')" > @@ -103,10 +103,10 @@ v-model="obj.roles" :label="this.$gzlocale.get('WidgetRoles')" ref="roles" - :rules="[this.$gzv.Integer(this,'roles'),this.$gzv.Required(this,'roles')]" - :error-messages="this.$gzv.ServerErrors(this,'roles')" + :rules="[this.$gzv.integerValid(this,'roles'),this.$gzv.required(this,'roles')]" + :error-messages="this.$gzv.serverErrors(this,'roles')" required - @change="Change('roles')" + @change="onChange('roles')" type="number" > @@ -218,19 +218,19 @@ export default { }; }, methods: { - Change(ref) { - this.$gzv.Change(this, ref); + onChange(ref) { + this.$gzv.onChange(this, ref); }, getDataFromApi() { var url = "Widget/" + this.$route.params.id; var that = this; - this.$gzv.DeleteAllErrorBoxErrors(this); + this.$gzv.deleteAllErrorBoxErrors(this); this.$gzapi .get(url) .then(res => { if (res.error) { that.serverError = res.error; - that.$gzv.SetErrorBoxErrors(that); + that.$gzv.setErrorBoxErrors(that); } else { that.obj = res.data; } @@ -246,14 +246,14 @@ export default { var url = "Widget/" + this.$route.params.id; //clear any errors that might be around from previous submit - this.$gzv.DeleteAllErrorBoxErrors(this); + this.$gzv.deleteAllErrorBoxErrors(this); this.$gzapi .upsert(url, this.obj) .then(res => { if (res.error) { that.serverError = res.error; - that.$gzv.SetErrorBoxErrors(that); + that.$gzv.setErrorBoxErrors(that); } else { //Logic for detecting if a post or put: if id then it was a post, if no id then it was a put if (res.id) {