From 594d14a62dbd85f6ffbed231af7fd986d4ece1af Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 22 Jan 2020 00:07:31 +0000 Subject: [PATCH] --- devdocs/todo.txt | 6 +- .../Controllers/FormCustomController.cs | 2 +- .../Controllers/ObjectFieldsController.cs | 4 +- server/AyaNova/biz/AyaFormFieldDefinitions.cs | 194 +++++++++ .../AyaNova/biz/AyaObjectFieldDefinitions.cs | 408 ------------------ server/AyaNova/biz/CustomFieldsValidator.cs | 4 +- server/AyaNova/biz/DataFilterBiz.cs | 6 +- server/AyaNova/biz/FormCustomBiz.cs | 8 +- server/AyaNova/biz/PickListFetcher.cs | 2 +- server/AyaNova/biz/RequiredFieldsValidator.cs | 4 +- server/AyaNova/biz/UserBiz.cs | 2 +- server/AyaNova/biz/WidgetBiz.cs | 2 +- server/AyaNova/util/Seeder.cs | 2 +- 13 files changed, 214 insertions(+), 430 deletions(-) create mode 100644 server/AyaNova/biz/AyaFormFieldDefinitions.cs delete mode 100644 server/AyaNova/biz/AyaObjectFieldDefinitions.cs diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 8672ba1a..dee395b6 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -6,9 +6,6 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTcxODU5OTU0IiwiZXhwIjoiMTU3MjQ ## IMMEDIATE ITEMS -Make DATALIST route for fetching all datalist key names -Make datalist route for fetching the field list of a specific datalist by key name -Make dataList route for fetching the actual data Clean up AyaObjectField definition for FORM FIELD STUFF: @@ -30,7 +27,8 @@ UnMock MOCK_WIDGET_DISPLAY_TEMPLATE_JSON into db with objects and with seeded da - Can it just make a default template if none is found? (no they are all required) - Once both lists are working: - +AyaFormFieldDefinitions still has UI field datatype in it, but I don't think I'll need it so ponder this by looking at tests and client and make a decision + - Consider if there is some possible future use for this or YAGNI //READ THESE NOTES, IS IT ALL DONE NOW? - abstract away the commonalities into other classes diff --git a/server/AyaNova/Controllers/FormCustomController.cs b/server/AyaNova/Controllers/FormCustomController.cs index a08130e0..eafafaea 100644 --- a/server/AyaNova/Controllers/FormCustomController.cs +++ b/server/AyaNova/Controllers/FormCustomController.cs @@ -145,7 +145,7 @@ namespace AyaNova.Api.Controllers if (!ModelState.IsValid) return BadRequest(new ApiErrorResponse(ModelState)); - return Ok(ApiOkResponse.Response(AyaObjectFieldDefinitions.AyaObjectFieldDefinitionKeys, true)); + return Ok(ApiOkResponse.Response(AyaFormFieldDefinitions.AyaFormFieldDefinitionKeys, true)); } diff --git a/server/AyaNova/Controllers/ObjectFieldsController.cs b/server/AyaNova/Controllers/ObjectFieldsController.cs index ab9f7500..c07ee4ab 100644 --- a/server/AyaNova/Controllers/ObjectFieldsController.cs +++ b/server/AyaNova/Controllers/ObjectFieldsController.cs @@ -59,9 +59,9 @@ namespace AyaNova.Api.Controllers if (!ModelState.IsValid) return BadRequest(new ApiErrorResponse(ModelState)); - if (AyaObjectFieldDefinitions.IsValidObjectKey(objectKey)) + if (AyaFormFieldDefinitions.IsValidFormFieldDefinitionKey(objectKey)) { - return Ok(ApiOkResponse.Response(AyaObjectFieldDefinitions.AyaObjectFields(objectKey), true)); + return Ok(ApiOkResponse.Response(AyaFormFieldDefinitions.AyaObjectFields(objectKey), true)); } else { diff --git a/server/AyaNova/biz/AyaFormFieldDefinitions.cs b/server/AyaNova/biz/AyaFormFieldDefinitions.cs new file mode 100644 index 00000000..34f685a4 --- /dev/null +++ b/server/AyaNova/biz/AyaFormFieldDefinitions.cs @@ -0,0 +1,194 @@ +using System.Linq; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; +using System.Text; + +namespace AyaNova.Biz +{ + //************************************************ + // This contains all the fields that are customizable on forms + // it is used for both validation and driving the UI etc + //See the DataList folder / namespace for LIST related similar class + + public static class AyaFormFieldDefinitions + { + + //DEFINE VALID KEYS HERE + + public const string WIDGET_KEY = "widget"; + public const string USER_KEY = "user"; + + + public static List AyaFormFieldDefinitionKeys + { + get + { + List l = new List{ + WIDGET_KEY, USER_KEY + }; + return l; + } + } + + public static bool IsValidFormFieldDefinitionKey(string key) + { + return AyaFormFieldDefinitionKeys.Contains(key); + } + + public static List AyaObjectFields(string key) + { + /* + ***************************** WARNING: Be careful here, if a standard field is hideable and also it's DB SCHEMA is set to NON NULLABLE then the CLIENT end needs to set a default + ***************************** Otherwise the hidden field can't be set and the object can't be saved EVER + */ + List l = new List(); + switch (key) + { + case WIDGET_KEY: + #region WIDGET_KEY + + //first column is the non visible Default Id column so that the client knows what to open when there is no field with ID selected that matches underlying record type + //in this case the default of id is sufficient for this list + l.Add(new AyaFormFieldDefinition { LtKey = "df", AyaObjectType = (int)AyaType.Widget }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetName", FieldKey = "Name", UiFieldDataType = (int)AyaUiFieldDataType.Text, Hideable = false }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetSerial", FieldKey = "Serial", UiFieldDataType = (int)AyaUiFieldDataType.Integer }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetDollarAmount", FieldKey = "DollarAmount", UiFieldDataType = (int)AyaUiFieldDataType.Currency }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCount", FieldKey = "Count", UiFieldDataType = (int)AyaUiFieldDataType.Integer }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetRoles", FieldKey = "Roles", UiFieldDataType = (int)AyaUiFieldDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetStartDate", FieldKey = "StartDate", UiFieldDataType = (int)AyaUiFieldDataType.DateTime }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetEndDate", FieldKey = "EndDate", UiFieldDataType = (int)AyaUiFieldDataType.DateTime }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetNotes", FieldKey = "Notes", UiFieldDataType = (int)AyaUiFieldDataType.Text }); + //More to do on this, maybe the datatype should be a LINK or something for UI purposes + //circle back on this when there is enough infrastructure to test + l.Add(new AyaFormFieldDefinition { LtKey = "User", FieldKey = "userid", UiFieldDataType = (int)AyaUiFieldDataType.Text, AyaObjectType = (int)AyaType.User }); + l.Add(new AyaFormFieldDefinition { LtKey = "Active", FieldKey = "Active", UiFieldDataType = (int)AyaUiFieldDataType.Bool, Hideable = false }); + l.Add(new AyaFormFieldDefinition { LtKey = "Tags", FieldKey = "Tags", UiFieldDataType = (int)AyaUiFieldDataType.Tags }); + + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom1", FieldKey = "WidgetCustom1", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom2", FieldKey = "WidgetCustom2", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom3", FieldKey = "WidgetCustom3", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom4", FieldKey = "WidgetCustom4", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom5", FieldKey = "WidgetCustom5", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom6", FieldKey = "WidgetCustom6", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom7", FieldKey = "WidgetCustom7", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom8", FieldKey = "WidgetCustom8", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom9", FieldKey = "WidgetCustom9", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom10", FieldKey = "WidgetCustom10", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom11", FieldKey = "WidgetCustom11", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom12", FieldKey = "WidgetCustom12", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom13", FieldKey = "WidgetCustom13", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom14", FieldKey = "WidgetCustom14", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom15", FieldKey = "WidgetCustom15", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom16", FieldKey = "WidgetCustom16", IsCustomField = true }); + break; + #endregion + case USER_KEY: + #region USER_KEY + l.Add(new AyaFormFieldDefinition { LtKey = "df", AyaObjectType = (int)AyaType.User }); + l.Add(new AyaFormFieldDefinition { LtKey = "Name", FieldKey = "Name", UiFieldDataType = (int)AyaUiFieldDataType.Text, Hideable = false }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserEmployeeNumber", FieldKey = "EmployeeNumber", UiFieldDataType = (int)AyaUiFieldDataType.Text }); + l.Add(new AyaFormFieldDefinition { LtKey = "AuthorizationRoles", FieldKey = "Roles", Hideable = false, UiFieldDataType = (int)AyaUiFieldDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserNotes", FieldKey = "Notes", UiFieldDataType = (int)AyaUiFieldDataType.Text }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserUserType", FieldKey = "UserType", Hideable = false, UiFieldDataType = (int)AyaUiFieldDataType.Enum, EnumType = typeof(UserType).ToString() }); + l.Add(new AyaFormFieldDefinition { LtKey = "Active", FieldKey = "Active", UiFieldDataType = (int)AyaUiFieldDataType.Bool, Hideable = false }); + l.Add(new AyaFormFieldDefinition { LtKey = "Tags", FieldKey = "Tags", UiFieldDataType = (int)AyaUiFieldDataType.Tags }); + + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom1", FieldKey = "UserCustom1", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom2", FieldKey = "UserCustom2", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom3", FieldKey = "UserCustom3", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom4", FieldKey = "UserCustom4", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom5", FieldKey = "UserCustom5", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom6", FieldKey = "UserCustom6", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom7", FieldKey = "UserCustom7", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom8", FieldKey = "UserCustom8", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom9", FieldKey = "UserCustom9", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom10", FieldKey = "UserCustom10", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom11", FieldKey = "UserCustom11", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom12", FieldKey = "UserCustom12", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom13", FieldKey = "UserCustom13", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom14", FieldKey = "UserCustom14", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom15", FieldKey = "UserCustom15", IsCustomField = true }); + l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom16", FieldKey = "UserCustom16", IsCustomField = true }); + break; + #endregion + + + + default: + throw new System.ArgumentOutOfRangeException($"AyaFormFieldDefinitions: {key} is not valid"); + } + return l; + } + + + // public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName) + // { + // var i = System.Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace( + // lTCustomFieldName, // Our input + // "[^0-9]", // Select everything that is not in the range of 0-9 + // "" // Replace that with an empty string. + // )); + + // return $"c{i}"; + // } + + + + + + + + }//eoc ObjectFields + + public class AyaFormFieldDefinition + { + //CLIENT / SERVER Unique identifier used at BOTH client and server + //also the sql displaycolumnname if identical + public string FieldKey { get; set; } + + //CLIENT Use only for display + public string LtKey { get; set; } + + //CLIENT form customization + public bool Hideable { get; set; } + + //CLIENT / SERVER - client display server validation purposes + public bool IsCustomField { get; set; } + + // //CLIENT / SERVER - client display server validation purposes + // public bool IsFilterable { get; set; } + + // //CLIENT / SERVER - client display server validation purposes + // public bool IsSortable { get; set; } + + //CLIENT Use only for display + public int UiFieldDataType { get; set; } + + //CLIENT Use only for display + public string EnumType { get; set; } + + //CLIENT / SERVER - client display and to indicate what object to open , Server for formatting return object + public int AyaObjectType { get; set; } + + + + + public AyaFormFieldDefinition() + { + //most common defaults + Hideable = true; + IsCustomField = false; + // IsFilterable = true; + // IsSortable = true; + //Set openable object type to no type which is the default and means it's not a link to another object + AyaObjectType = (int)AyaType.NoType; + + } + + + + + } + + +}//ens diff --git a/server/AyaNova/biz/AyaObjectFieldDefinitions.cs b/server/AyaNova/biz/AyaObjectFieldDefinitions.cs deleted file mode 100644 index 0262c0a7..00000000 --- a/server/AyaNova/biz/AyaObjectFieldDefinitions.cs +++ /dev/null @@ -1,408 +0,0 @@ -using System.Linq; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using System.Text; - -namespace AyaNova.Biz -{ - //************************************************ - // This contains all the fields that are: - // - Customizable on forms - // - In grid list templates - //In addition it serves as a source for valid object keys in AvailableObjectKeys - //SQL code uses this: - // - a source of database column names and ID column names - // - Essentially this replaces all the attribute decoration in v7 and the individual classes with objects - - - public static class AyaObjectFieldDefinitions - { - - //DEFINE VALID KEYS HERE - //For objects that are both list and edit form it's just the name of the object - //For objects that are compound list objects or reporting objects it's whatever uniquely but clearly identifies that and ends in _LIST - public const string WIDGET_KEY = "widget"; - public const string USER_KEY = "user"; - public const string TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY = "TEST_WIDGET_USER_EMAIL_ADDRESS_LIST";//for development testing, not a real thing going forward - - - public static List AyaObjectFieldDefinitionKeys - { - get - { - List l = new List{ - WIDGET_KEY, USER_KEY - }; - return l; - } - } - - public static bool IsValidObjectKey(string key) - { - return AyaObjectFieldDefinitionKeys.Contains(key); - } - - public static List AyaObjectFields(string key) - { - /* - ***************************** WARNING: Be careful here, if a standard field is hideable and also it's DB SCHEMA is set to NON NULLABLE then the CLIENT end needs to set a default - ***************************** Otherwise the hidden field can't be set and the object can't be saved EVER - Defaults of paramterless constructor: - SharedLTKey = false; - Hideable = true; - Custom = false; - Filterable = true; - Sortable = true; - MiniAvailable = true; - */ - List l = new List(); - switch (key) - { - /* - TODO: going to need some SQL hints added here - - SqlIDColumn indicating what the ID column is to fetch the underlying value from - - SqlColumn indicating an alternative column name as known to the sql server if it varies from the propertyname (in lowercase) - - Also: going to need a definition of the table name and the default identity column - Maybe decorate with an INTERNAL ONLY bool so that we see it at the server but not at the client or when fetched as possible fields - - hypothetical to help develop this: - Client and head office list: - {key=ClientName, propertyname=Name, idcolumn=id,} - - In v7 this is what the attribute decorations looked like: - [SqlColumnNameAttribute("aClient.aName", "aClient.aID")] - public GridNameValueCellItem LT_O_Client - { - get - { - return mClient; - } - } - - [SqlColumnNameAttribute("aHeadOffice.aName","aHeadOffice.aID")] - public GridNameValueCellItem LT_O_HeadOffice - { - get - { - return mHeadOffice; - } - } - - And the query (from clientlistdetailed) - string q = - "SELECT ~MAXRECS~ ACLIENT.aID, ACLIENT.aName, ACLIENT.aModified, " + - " ACLIENT.AACTIVE, ACLIENT.aUsesBanking, " + - " ACLIENT.aBillHeadOffice, ACLIENT.aWebAddress, " + - " ACLIENT.aDispatchZoneID, ACLIENT.aClientGroupID, " + - " ACLIENT.aLastWorkorderID, " + - " ACLIENT.aLastServiceDate, (SELECT TOP 1 aSBANK.aHoursBalance " + - "FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " + - "= ACLIENT.aID ORDER " + - "BY aSBANK.aCreated DESC) AS HOURSBAL, (SELECT TOP " + - "1 aSBANK.aIncidentsBalance FROM aServiceBank aSBANK " + - "WHERE aSBANK.AAPPLIESTOROOTOBJECTID = ACLIENT.aID " + - "ORDER BY aSBANK.aCreated DESC) AS INCIDENTSBAL, " + - " (SELECT TOP 1 aSBANK.aCurrencyBalance FROM " + - "aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " + - "= ACLIENT.aID ORDER BY aSBANK.aCreated DESC) " + - "AS CURRENCYBAL, " + - " ACLIENT.AACCOUNTNUMBER, aHeadOffice.aName " + - "AS aHeadOfficeName, aHeadOffice.aID " + - "AS aHeadOfficeID, aDispatchZone.aName AS aDispatchZoneName, " + - " ACLIENT.aRegionID, aRegion.aName " + - "AS aRegionName, aClientGroup.aName AS " + - "aClientGroupName, aPHYSICAL.aDeliveryAddress, " + - "aPHYSICAL.aCity, aPHYSICAL.aStateProv, aPHYSICAL.aCountry, " + - " aPHYSICAL.aPostal, aPHYSICAL.AADDRESSTYPE, " + - " aPHYSICAL.aLongitude, aPHYSICAL.aLatitude, " + - " aWorkorderService.aServiceNumber, " + - " ACLIENT.aContractID, aContract.aName AS " + - "aContractName, ACLIENT.aContractExpires, aPHYSICAL.aCountryCode, " + - " aPOSTAL.AADDRESSTYPE AS aPAddressType, " + - " aPOSTAL.aDeliveryAddress AS aPDeliveryAddress, " + - " aPOSTAL.aCity AS aPCity, aPOSTAL.aStateProv " + - "AS aPStateProv, aPOSTAL.aCountryCode AS aPCountryCode, " + - " aPOSTAL.aCountry AS aPCountry, aPOSTAL.aPostal " + - "AS aPPostal, ACLIENT.aCustom1, ACLIENT.aCustom2, " + - " ACLIENT.aCustom3, ACLIENT.aCustom4, " + - " ACLIENT.aCustom5, ACLIENT.aCustom6, " + - " ACLIENT.aCustom7, ACLIENT.aCustom8, ACLIENT.aCustom9, " + - " ACLIENT.aCustom0, ACLIENT.aTechNotes, " + - " ACLIENT.aNotes, ACLIENT.aPopUpNotes, " + - " ACLIENT.ACONTACT, ACLIENT.AEMAIL, ACLIENT.APHONE1, ACLIENT.APHONE2, ACLIENT.APHONE3, ACLIENT.APHONE4, ACLIENT.APHONE5, ACLIENT.ACONTACTNOTES " + - - - - "FROM " + - " ACLIENT ACLIENT " + - " LEFT OUTER JOIN ADISPATCHZONE ON (ACLIENT.ADISPATCHZONEID=ADISPATCHZONE.AID) " + - " LEFT OUTER JOIN ACLIENTGROUP ON (ACLIENT.ACLIENTGROUPID=ACLIENTGROUP.AID) " + - " LEFT OUTER JOIN AADDRESS aPHYSICAL ON (ACLIENT.AID=aPHYSICAL.AROOTOBJECTID) " + - " LEFT OUTER JOIN AADDRESS aPOSTAL ON (ACLIENT.AID=aPOSTAL.AROOTOBJECTID) " + - " LEFT OUTER JOIN ACONTRACT ON (ACLIENT.ACONTRACTID=ACONTRACT.AID) " + - " LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID=AHEADOFFICE.AID) " + - " LEFT OUTER JOIN AWORKORDERSERVICE ON (ACLIENT.ALASTWORKORDERID=AWORKORDERSERVICE.AWORKORDERID) " + - " LEFT OUTER JOIN AREGION ON (ACLIENT.AREGIONID=AREGION.AID) " + - - "WHERE (aPHYSICAL.AADDRESSTYPE " + - "IS NULL OR aPHYSICAL.AADDRESSTYPE " + - "= 2) AND (aPOSTAL.AADDRESSTYPE IS NULL OR aPOSTAL.AADDRESSTYPE " + - "= 1) \r\n "; - - - */ - case WIDGET_KEY: - #region WIDGET_KEY - - //first column is the non visible Default Id column so that the client knows what to open when there is no field with ID selected that matches underlying record type - //in this case the default of id is sufficient for this list - l.Add(new AyaObjectFieldDefinition { LtKey = "df", AyaObjectType = (int)AyaType.Widget }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetName", FieldKey = "Name", UiFieldDataType = (int)AyaUiFieldDataType.Text, Hideable = false }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetSerial", FieldKey = "Serial", UiFieldDataType = (int)AyaUiFieldDataType.Integer }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetDollarAmount", FieldKey = "DollarAmount", UiFieldDataType = (int)AyaUiFieldDataType.Currency }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCount", FieldKey = "Count", UiFieldDataType = (int)AyaUiFieldDataType.Integer }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetRoles", FieldKey = "Roles", UiFieldDataType = (int)AyaUiFieldDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetStartDate", FieldKey = "StartDate", UiFieldDataType = (int)AyaUiFieldDataType.DateTime }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetEndDate", FieldKey = "EndDate", UiFieldDataType = (int)AyaUiFieldDataType.DateTime }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetNotes", FieldKey = "Notes", UiFieldDataType = (int)AyaUiFieldDataType.Text }); - //More to do on this, maybe the datatype should be a LINK or something for UI purposes - //circle back on this when there is enough infrastructure to test - l.Add(new AyaObjectFieldDefinition { LtKey = "User", FieldKey = "userid", UiFieldDataType = (int)AyaUiFieldDataType.Text, AyaObjectType = (int)AyaType.User }); - l.Add(new AyaObjectFieldDefinition { LtKey = "Active", FieldKey = "Active", UiFieldDataType = (int)AyaUiFieldDataType.Bool, Hideable = false }); - l.Add(new AyaObjectFieldDefinition { LtKey = "Tags", FieldKey = "Tags", UiFieldDataType = (int)AyaUiFieldDataType.Tags }); - - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom1", FieldKey = "WidgetCustom1", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom2", FieldKey = "WidgetCustom2", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom3", FieldKey = "WidgetCustom3", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom4", FieldKey = "WidgetCustom4", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom5", FieldKey = "WidgetCustom5", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom6", FieldKey = "WidgetCustom6", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom7", FieldKey = "WidgetCustom7", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom8", FieldKey = "WidgetCustom8", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom9", FieldKey = "WidgetCustom9", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom10", FieldKey = "WidgetCustom10", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom11", FieldKey = "WidgetCustom11", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom12", FieldKey = "WidgetCustom12", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom13", FieldKey = "WidgetCustom13", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom14", FieldKey = "WidgetCustom14", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom15", FieldKey = "WidgetCustom15", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "WidgetCustom16", FieldKey = "WidgetCustom16", IsCustomField = true }); - break; - #endregion - case USER_KEY: - #region USER_KEY - l.Add(new AyaObjectFieldDefinition { LtKey = "df", AyaObjectType = (int)AyaType.User }); - l.Add(new AyaObjectFieldDefinition { LtKey = "Name", FieldKey = "Name", UiFieldDataType = (int)AyaUiFieldDataType.Text, Hideable = false }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserEmployeeNumber", FieldKey = "EmployeeNumber", UiFieldDataType = (int)AyaUiFieldDataType.Text }); - l.Add(new AyaObjectFieldDefinition { LtKey = "AuthorizationRoles", FieldKey = "Roles", Hideable = false, UiFieldDataType = (int)AyaUiFieldDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserNotes", FieldKey = "Notes", UiFieldDataType = (int)AyaUiFieldDataType.Text }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserUserType", FieldKey = "UserType", Hideable = false, UiFieldDataType = (int)AyaUiFieldDataType.Enum, EnumType = typeof(UserType).ToString() }); - l.Add(new AyaObjectFieldDefinition { LtKey = "Active", FieldKey = "Active", UiFieldDataType = (int)AyaUiFieldDataType.Bool, Hideable = false }); - l.Add(new AyaObjectFieldDefinition { LtKey = "Tags", FieldKey = "Tags", UiFieldDataType = (int)AyaUiFieldDataType.Tags }); - - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom1", FieldKey = "UserCustom1", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom2", FieldKey = "UserCustom2", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom3", FieldKey = "UserCustom3", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom4", FieldKey = "UserCustom4", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom5", FieldKey = "UserCustom5", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom6", FieldKey = "UserCustom6", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom7", FieldKey = "UserCustom7", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom8", FieldKey = "UserCustom8", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom9", FieldKey = "UserCustom9", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom10", FieldKey = "UserCustom10", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom11", FieldKey = "UserCustom11", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom12", FieldKey = "UserCustom12", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom13", FieldKey = "UserCustom13", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom14", FieldKey = "UserCustom14", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom15", FieldKey = "UserCustom15", IsCustomField = true }); - l.Add(new AyaObjectFieldDefinition { LtKey = "UserCustom16", FieldKey = "UserCustom16", IsCustomField = true }); - break; - #endregion - case TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY: - #region TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY - - l.Add(new AyaObjectFieldDefinition { FieldKey = "df", AyaObjectType = (int)AyaType.Widget, SqlIdColumnName = "awidget.id" }); - l.Add(new AyaObjectFieldDefinition - { - FieldKey = "widgetname", - LtKey = "WidgetName", - UiFieldDataType = (int)AyaUiFieldDataType.Text, - AyaObjectType = (int)AyaType.Widget, - SqlIdColumnName = "awidget.id", - SqlValueColumnName = "awidget.name" - }); - l.Add(new AyaObjectFieldDefinition - { - FieldKey = "username", - LtKey = "User", - UiFieldDataType = (int)AyaUiFieldDataType.Text, - AyaObjectType = (int)AyaType.User, - SqlIdColumnName = "auser.id", - SqlValueColumnName = "auser.name" - }); - l.Add(new AyaObjectFieldDefinition - { - LtKey = "UserEmailAddress", - FieldKey = "emailaddress", - SqlValueColumnName = "auseroptions.emailaddress", - UiFieldDataType = (int)AyaUiFieldDataType.EmailAddress - }); - l.Add(new AyaObjectFieldDefinition - { - LtKey = "Active", - FieldKey = "widgetactive", - SqlValueColumnName = "awidget.active", - UiFieldDataType = (int)AyaUiFieldDataType.Bool - }); - break; - #endregion - - - default: - throw new System.ArgumentOutOfRangeException($"ObjectFields: {key} is not a valid object key"); - } - return l; - } - - - public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName) - { - var i = System.Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace( - lTCustomFieldName, // Our input - "[^0-9]", // Select everything that is not in the range of 0-9 - "" // Replace that with an empty string. - )); - - return $"c{i}"; - } - - - - //Standard mini COLUMN definition - public static string GenerateMINIListColumnsJSON(AyaType defaultLinkType) - { - return $"[ {{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)defaultLinkType}}},{{\"cm\":\"Widget\",\"dt\":{(int)AyaUiFieldDataType.Text},\"ay\":{(int)defaultLinkType}}}]"; - } - - - //Accept a json template - //return a column list suitable for api list return - public static string GenerateListColumnsJSONFromTemplate(AyaType defaultLinkType, List objectFields, string template) - { - //parse the template - var jtemplate = JObject.Parse(template); - - - //convert to strings (https://stackoverflow.com/a/33836599/8939) - var fullFields = ((JArray)jtemplate["full"]).ToObject(); - - //Generate JSON fragment to return with column definitions - StringBuilder sb = new StringBuilder(); - - sb.Append("["); - //df First column is always the df column - sb.Append($"{{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)defaultLinkType}}}"); - - foreach (string s in fullFields) - { - AyaObjectFieldDefinition o = objectFields.FirstOrDefault(x => x.FieldKey == s); -#if (DEBUG) - //Developers little helper - if (o == null) - { - throw new System.ArgumentNullException($"DEV ERROR in objectFields::GenerateListColumnsJSONFromTemplate - field {s} specified in template was NOT found in ObjectFields list"); - } -#endif - - if (o != null) - {//Here is where we can vet the field name, if it doesn't exist. For production we'll just ignore those ones - - sb.Append(","); - sb.Append("{"); - //Build required part of column definition - sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.UiFieldDataType}"); - - //Has a AyObjectType? (linkable / openable) - if (o.AyaObjectType != 0) - sb.Append($",\"ay\":{(int)o.AyaObjectType}"); - - sb.Append("}"); - - } - } - sb.Append("]"); - - return sb.ToString(); - } - - - - }//eoc ObjectFields - - public class AyaObjectFieldDefinition - { - //CLIENT / SERVER Unique identifier used at BOTH client and server - //also the sql displaycolumnname if identical - public string FieldKey { get; set; } - - //CLIENT Use only for display - public string LtKey { get; set; } - - //CLIENT form customization - public bool Hideable { get; set; } - - //CLIENT / SERVER - client display server validation purposes - public bool IsCustomField { get; set; } - - //CLIENT / SERVER - client display server validation purposes - public bool IsFilterable { get; set; } - - //CLIENT / SERVER - client display server validation purposes - public bool IsSortable { get; set; } - - //CLIENT Use only for display - public int UiFieldDataType { get; set; } - - //CLIENT Use only for display - public string EnumType { get; set; } - - //CLIENT / SERVER - client display and to indicate what object to open , Server for formatting return object - public int AyaObjectType { get; set; } - - //SERVER - for building sql queries - public string SqlIdColumnName { get; set; } - public string SqlValueColumnName { get; set; } - - - public AyaObjectFieldDefinition() - { - //most common defaults - Hideable = true; - IsCustomField = false; - IsFilterable = true; - IsSortable = true; - //Set openable object type to no type which is the default and means it's not a link to another object - AyaObjectType = (int)AyaType.NoType; - - } - - //Get column to query for display name or use FieldName if there is no difference - public string GetSqlValueColumnName() - { - if (string.IsNullOrEmpty(SqlValueColumnName)) - { - return FieldKey.ToLowerInvariant(); - } - else - { - return SqlValueColumnName; - } - } - - - - } - - -}//ens diff --git a/server/AyaNova/biz/CustomFieldsValidator.cs b/server/AyaNova/biz/CustomFieldsValidator.cs index a01e9bb5..866e7b0d 100644 --- a/server/AyaNova/biz/CustomFieldsValidator.cs +++ b/server/AyaNova/biz/CustomFieldsValidator.cs @@ -16,7 +16,7 @@ namespace AyaNova.Biz return; var FormTemplate = JArray.Parse(formCustom.Template); - var ThisFormCustomFieldsList = AyaObjectFieldDefinitions.AyaObjectFields(formCustom.FormKey).Where(x => x.IsCustomField == true).Select(x => x.LtKey).ToList(); + var ThisFormCustomFieldsList = AyaFormFieldDefinitions.AyaObjectFields(formCustom.FormKey).Where(x => x.IsCustomField == true).Select(x => x.LtKey).ToList(); //If the customFields string is empty then only validation is if any of the fields are required to be filled in if (!hasCustomData) @@ -52,7 +52,7 @@ namespace AyaNova.Biz { //Translate the LT field key to the actual customFieldData field key - var InternalCustomFieldName = AyaObjectFieldDefinitions.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey); + var InternalCustomFieldName = AyaFormFieldDefinitions.TranslateLTCustomFieldToInternalCustomFieldName(iFldKey); //Check if it's set to required var isRequired = CustomFieldIsSetToRequired(FormTemplate, iFldKey); diff --git a/server/AyaNova/biz/DataFilterBiz.cs b/server/AyaNova/biz/DataFilterBiz.cs index f085ff9a..7153690a 100644 --- a/server/AyaNova/biz/DataFilterBiz.cs +++ b/server/AyaNova/biz/DataFilterBiz.cs @@ -247,14 +247,14 @@ namespace AyaNova.Biz AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListKey"); - List FieldList = null; - if (!AyaObjectFieldDefinitions.IsValidObjectKey(inObj.ListKey)) + List FieldList = null; + if (!AyaFormFieldDefinitions.IsValidFormFieldDefinitionKey(inObj.ListKey)) { AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListKey", $"ListKey \"{inObj.ListKey}\" is empty or in-valid"); } else { - FieldList = AyaObjectFieldDefinitions.AyaObjectFields(inObj.ListKey); + FieldList = AyaFormFieldDefinitions.AyaObjectFields(inObj.ListKey); } diff --git a/server/AyaNova/biz/FormCustomBiz.cs b/server/AyaNova/biz/FormCustomBiz.cs index 42f98379..f009e4ce 100644 --- a/server/AyaNova/biz/FormCustomBiz.cs +++ b/server/AyaNova/biz/FormCustomBiz.cs @@ -96,7 +96,7 @@ namespace AyaNova.Biz } //If it doesn't exist, vet the form key name is ok by checking with this list - if (!AyaObjectFieldDefinitions.AyaObjectFieldDefinitionKeys.Contains(formKey)) + if (!AyaFormFieldDefinitions.AyaFormFieldDefinitionKeys.Contains(formKey)) { //Nope, whatever it is, it's not valid return null; @@ -165,7 +165,7 @@ namespace AyaNova.Biz AddError(ApiErrorCode.VALIDATION_REQUIRED, "FormKey"); else { - if (!AyaObjectFieldDefinitions.IsValidObjectKey(inObj.FormKey)) + if (!AyaFormFieldDefinitions.IsValidFormFieldDefinitionKey(inObj.FormKey)) { AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "FormKey"); } @@ -192,7 +192,7 @@ namespace AyaNova.Biz if ((!PropertyHasErrors("FormKey") && !string.IsNullOrWhiteSpace(inObj.Template))) { var ValidCustomFieldTypes = CustomFieldType.ValidCustomFieldTypes; - var ValidFormFields = AyaObjectFieldDefinitions.AyaObjectFields(inObj.FormKey); + var ValidFormFields = AyaFormFieldDefinitions.AyaObjectFields(inObj.FormKey); try { //Parse the json, expecting something like this: @@ -206,7 +206,7 @@ namespace AyaNova.Biz for (int i = 0; i < v.Count; i++) { - AyaObjectFieldDefinition MasterFormField = null; + AyaFormFieldDefinition MasterFormField = null; var formFieldItem = v[i]; if (formFieldItem["fld"] == null) diff --git a/server/AyaNova/biz/PickListFetcher.cs b/server/AyaNova/biz/PickListFetcher.cs index cdab5461..0e4ce95c 100644 --- a/server/AyaNova/biz/PickListFetcher.cs +++ b/server/AyaNova/biz/PickListFetcher.cs @@ -10,7 +10,7 @@ namespace AyaNova.Biz internal static class PickListFetcher { - internal static PickListResult GetPickList(AyContext ct, long userId, ListOptions pagingOptions, List objectFields, string tableName) + internal static PickListResult GetPickList(AyContext ct, long userId, ListOptions pagingOptions, List objectFields, string tableName) { List listItems = new List(); diff --git a/server/AyaNova/biz/RequiredFieldsValidator.cs b/server/AyaNova/biz/RequiredFieldsValidator.cs index caa9738f..25d91cc0 100644 --- a/server/AyaNova/biz/RequiredFieldsValidator.cs +++ b/server/AyaNova/biz/RequiredFieldsValidator.cs @@ -18,7 +18,7 @@ namespace AyaNova.Biz //var OuterJson=JObject.Parse(formCustom.Template); var FormTemplate = JArray.Parse(formCustom.Template); // var FormTemplate=(JArray)OuterJson["template"]; - var FormFields = AyaObjectFieldDefinitions.AyaObjectFields(formCustom.FormKey); + var FormFields = AyaFormFieldDefinitions.AyaObjectFields(formCustom.FormKey); // var ThisFormNormalFieldsList = FormFields.Where(x => x.Custom == false).Select(x => x.Key).ToList(); foreach (JObject jo in FormTemplate) @@ -30,7 +30,7 @@ namespace AyaNova.Biz // - e.g.: {template:[{fld:"ltkeyfieldname",hide:"true/false",required:"true/false", type:"bool"},{fld:"ltkeyfieldname",hide:"true/false",required:"true/false", type:"text"]} //get the FormField object - AyaObjectFieldDefinition FF = FormFields.Where(x => x.LtKey == FldLtKey).Single(); + AyaFormFieldDefinition FF = FormFields.Where(x => x.LtKey == FldLtKey).Single(); //don't validate custom fields, just skip them // if (!string.IsNullOrWhiteSpace(FF.PropertyName))//this used to work because there would be no property name but now there is so it doesn't diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 536394b0..9c89f050 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -531,7 +531,7 @@ namespace AyaNova.Biz AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "EmployeeNumber", "255 max"); //Any form customizations to validate? - var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == AyaObjectFieldDefinitions.USER_KEY); + var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == AyaFormFieldDefinitions.USER_KEY); if (FormCustomization != null) { //Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index f29062de..ab62a401 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -375,7 +375,7 @@ namespace AyaNova.Biz } //Any form customizations to validate? - var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == AyaObjectFieldDefinitions.WIDGET_KEY); + var FormCustomization = ct.FormCustom.SingleOrDefault(x => x.FormKey == AyaFormFieldDefinitions.WIDGET_KEY); if (FormCustomization != null) { //Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index 54b61899..09d1c8a4 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -82,7 +82,7 @@ namespace AyaNova.Util var fc = new FormCustom() { - FormKey = AyaObjectFieldDefinitions.WIDGET_KEY, + FormKey = AyaFormFieldDefinitions.WIDGET_KEY, Template = @"[ { ""fld"": ""WidgetNotes"",