From b988f39a7057a7db499be8ce2c14a230b334194a Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 14 Jan 2020 00:43:25 +0000 Subject: [PATCH] --- .../Controllers/FormCustomController.cs | 2 +- server/AyaNova/biz/AyDataType.cs | 4 ++ server/AyaNova/biz/CustomFieldsValidator.cs | 2 +- .../AyaNova/biz/FilterSqlCriteriaBuilder.cs | 3 ++ server/AyaNova/biz/FormCustomBiz.cs | 2 +- server/AyaNova/biz/ObjectFields.cs | 40 +++++++++++++++---- server/AyaNova/biz/RequiredFieldsValidator.cs | 2 +- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/server/AyaNova/Controllers/FormCustomController.cs b/server/AyaNova/Controllers/FormCustomController.cs index a351c050..5ba7fc2e 100644 --- a/server/AyaNova/Controllers/FormCustomController.cs +++ b/server/AyaNova/Controllers/FormCustomController.cs @@ -119,7 +119,7 @@ namespace AyaNova.Api.Controllers if (ObjectFields.IsValidObjectKey(formkey)) { - return Ok(ApiOkResponse.Response(ObjectFields.FormFields(formkey), true)); + return Ok(ApiOkResponse.Response(ObjectFields.ObjectFields(formkey), true)); } else { diff --git a/server/AyaNova/biz/AyDataType.cs b/server/AyaNova/biz/AyDataType.cs index d3db6c64..d2991a99 100644 --- a/server/AyaNova/biz/AyDataType.cs +++ b/server/AyaNova/biz/AyDataType.cs @@ -4,11 +4,15 @@ namespace AyaNova.Biz { public static class AyDataType { + //Date and time types, all stored internally as a date and time timestamp, but may display as date only or time only + public const string DateTime = "datetime"; public const string Date = "date"; + public const string Time = "time"; public const string Text = "text"; public const string Integer = "int"; public const string Bool = "bool"; public const string Decimal = "decimal"; + public const string Currency = "currency"; public const string Tags = "tags"; public const string Enum = "enum";//enums are just integers in the db so the sql code handles it like an int, but the client needs to know it's an enum diff --git a/server/AyaNova/biz/CustomFieldsValidator.cs b/server/AyaNova/biz/CustomFieldsValidator.cs index e1ddcc3b..ece7f8a4 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 = ObjectFields.FormFields(formCustom.FormKey).Where(x => x.Custom == true).Select(x => x.Key).ToList(); + var ThisFormCustomFieldsList = ObjectFields.ObjectFields(formCustom.FormKey).Where(x => x.Custom == true).Select(x => x.Key).ToList(); //If the customFields string is empty then only validation is if any of the fields are required to be filled in if (!hasCustomData) diff --git a/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs b/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs index 2213c9af..69947c0c 100644 --- a/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs +++ b/server/AyaNova/biz/FilterSqlCriteriaBuilder.cs @@ -270,7 +270,10 @@ namespace AyaNova.Biz } break; + //Note there are three types here for display purposes but all are stored in the db as a timestamp the same with date and time components case AyDataType.Date: + case AyDataType.DateTime: + case AyDataType.Time: { //Note: it is assumed all dates come into here from the CLIENT in UTC iso8601 format //suitable for the database to handle as all database dates are in UTC diff --git a/server/AyaNova/biz/FormCustomBiz.cs b/server/AyaNova/biz/FormCustomBiz.cs index a2ed3e20..ab6f5172 100644 --- a/server/AyaNova/biz/FormCustomBiz.cs +++ b/server/AyaNova/biz/FormCustomBiz.cs @@ -192,7 +192,7 @@ namespace AyaNova.Biz if ((!PropertyHasErrors("FormKey") && !string.IsNullOrWhiteSpace(inObj.Template))) { var ValidCustomFieldTypes = CustomFieldType.ValidCustomFieldTypes; - var ValidFormFields = ObjectFields.FormFields(inObj.FormKey); + var ValidFormFields = ObjectFields.ObjectFields(inObj.FormKey); try { //Parse the json, expecting something like this: diff --git a/server/AyaNova/biz/ObjectFields.cs b/server/AyaNova/biz/ObjectFields.cs index 81f8ed31..33200f2e 100644 --- a/server/AyaNova/biz/ObjectFields.cs +++ b/server/AyaNova/biz/ObjectFields.cs @@ -6,11 +6,14 @@ 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 form keys in AvailableFormKeys + //In addition it serves as a source for valid object keys in AvailableObjectKeys // public static class ObjectFields { + //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 public const string WIDGET_KEY = "widget"; public const string USER_KEY = "user"; @@ -31,21 +34,31 @@ namespace AyaNova.Biz return AvailableObjectKeys.Contains(key); } - public static List FormFields(string key) + public static List ObjectFieldsList(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) { case WIDGET_KEY: - l.Add(new ObjectField("WidgetName", "Name", false, false));//is not shared localized text key and not hideable as it is in the validation rules for widget - l.Add(new ObjectField("WidgetSerial", "Serial"));//not in validation rules BUT, is HIDEABLE and is set to NOT NULLABLE in the schema so this field MUST MUST have a default value in client - l.Add(new ObjectField("WidgetDollarAmount", "DollarAmount")); - l.Add(new ObjectField("WidgetCount", "Count")); - l.Add(new ObjectField("WidgetRoles", "Roles"));//not required but must be a valid default + l.Add(new ObjectField { Key = "WidgetName", PropertyName = "Name", DataType = AyDataType.Text, Hideable = false }); + l.Add(new ObjectField { Key = "WidgetSerial", PropertyName = "Serial", DataType = AyDataType.Integer }); + l.Add(new ObjectField { Key = "WidgetDollarAmount", PropertyName = "DollarAmount", DataType = AyDataType.Currency }); + l.Add(new ObjectField { Key = "WidgetCount", PropertyName = "Count", DataType = AyDataType.Integer }); + l.Add(new ObjectField { Key = "WidgetRoles", PropertyName = "Roles", DataType = AyDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); +l.Add(new ObjectField { Key = "WidgetStartDate", PropertyName = "StartDate", DataType = AyDataType.Date }); + + l.Add(new ObjectField("WidgetStartDate", "StartDate"));//have rule for date precedence but can both be empty so allowing to hide is ok l.Add(new ObjectField("WidgetEndDate", "EndDate")); l.Add(new ObjectField("WidgetNotes", "Notes")); @@ -131,9 +144,20 @@ namespace AyaNova.Biz public bool Sortable { get; set; } public bool MiniAvailable { get; set; } public string DataType { get; set; } + //If it's an enum DataType then this is the specific enum type which sb the name of the class that holds the enum in the server project + public string EnumType { get; set; } - public ObjectField() { } + public ObjectField() + { + //most common defaults + SharedLTKey = false; + Hideable = true; + Custom = false; + Filterable = true; + Sortable = true; + MiniAvailable = true; + } public ObjectField(string key, string propertyName, bool sharedLTKey = false, bool hideable = true, bool custom = false) { diff --git a/server/AyaNova/biz/RequiredFieldsValidator.cs b/server/AyaNova/biz/RequiredFieldsValidator.cs index e81e9b65..2950c8b6 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 = ObjectFields.FormFields(formCustom.FormKey); + var FormFields = ObjectFields.ObjectFields(formCustom.FormKey); // var ThisFormNormalFieldsList = FormFields.Where(x => x.Custom == false).Select(x => x.Key).ToList(); foreach (JObject jo in FormTemplate)