From 3bac8c686ebd937109b41f47327b52b03957a1aa Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 16 Jan 2020 00:37:02 +0000 Subject: [PATCH] --- devdocs/specs/core-main-grids.txt | 4 ++-- server/AyaNova/biz/ObjectFields.cs | 7 +++++- server/AyaNova/biz/SqlSelectBuilder.cs | 32 ++++++++++++++++++++------ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/devdocs/specs/core-main-grids.txt b/devdocs/specs/core-main-grids.txt index 55e76ca5..2249fe69 100644 --- a/devdocs/specs/core-main-grids.txt +++ b/devdocs/specs/core-main-grids.txt @@ -28,7 +28,7 @@ Client - Each row contains a bunch of row objects - Each column from the db is converted to an object and is formatted like this: - {v:[field value],id:42[optional id value if openable]}, {v:[field value],id:42[optional id value if openable]}...etc - - First row object is ALWAYS the Default object and is not intended for display + - _df_ First row object is ALWAYS the Default "_df_" object and is not intended for display - First column contains the same format as a normal column but doesn't display and is intended for the client to know what type and ID of object to open - This is necessary in cases where they have made selections that preclude knowing what link to open, so if there is no links in the row this is the default for the entire row - This also saves bandwidth as a list that has no other types can not bother setting the type or id for any other columns @@ -61,7 +61,7 @@ Server - To save bandwidth abbreviations are used in the column definitions: - ColumnsJSON=@"""columns"":[ {""cm"":""Widget"",""dt"":""text"",""ay"":"+ AyaType.Widget.ToString()+ "}]"; - cm=column name locale key, dt=AyDataType, ay=AyaType to open on click of that column field (optional, not present if not openable) - - First column is the DEFAULT column that corresponds to the + - First column in each row is *ALWAYS* the DEFAULT column that corresponds to the _df_ column specified in objectfields with it's sql attributes - For example (wide list): data:{ columns:{[ {cm:"lt_client_name",dt:text,ay:2},{cm:"lt_client_notes",dt:text},{cm:"lt_last_workorder",dt:number,ay:workorder}]} diff --git a/server/AyaNova/biz/ObjectFields.cs b/server/AyaNova/biz/ObjectFields.cs index 60749351..7bb7cdd3 100644 --- a/server/AyaNova/biz/ObjectFields.cs +++ b/server/AyaNova/biz/ObjectFields.cs @@ -20,7 +20,7 @@ namespace AyaNova.Biz //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 + //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"; @@ -153,6 +153,10 @@ namespace AyaNova.Biz */ 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 ObjectField { Key = "_df_", AyObjectType=(int)AyaType.Widget }); l.Add(new ObjectField { Key = "WidgetName", PropertyName = "Name", DataType = (int)AyaDataType.Text, Hideable = false }); l.Add(new ObjectField { Key = "WidgetSerial", PropertyName = "Serial", DataType = (int)AyaDataType.Integer }); l.Add(new ObjectField { Key = "WidgetDollarAmount", PropertyName = "DollarAmount", DataType = (int)AyaDataType.Currency }); @@ -184,6 +188,7 @@ namespace AyaNova.Biz #endregion case USER_KEY: #region USER_KEY + l.Add(new ObjectField { Key = "_df_", AyObjectType=(int)AyaType.User }); l.Add(new ObjectField { Key = "Name", PropertyName = "Name", SharedLTKey = true, DataType = (int)AyaDataType.Text, Hideable = false }); l.Add(new ObjectField { Key = "UserEmployeeNumber", PropertyName = "EmployeeNumber", DataType = (int)AyaDataType.Text }); l.Add(new ObjectField { Key = "AuthorizationRoles", PropertyName = "Roles", Hideable = false, DataType = (int)AyaDataType.Enum, EnumType = typeof(AuthorizationRoles).ToString() }); diff --git a/server/AyaNova/biz/SqlSelectBuilder.cs b/server/AyaNova/biz/SqlSelectBuilder.cs index 728a195b..6fc76e13 100644 --- a/server/AyaNova/biz/SqlSelectBuilder.cs +++ b/server/AyaNova/biz/SqlSelectBuilder.cs @@ -20,7 +20,7 @@ namespace AyaNova.Biz var jtemplate = JObject.Parse(template); //get the fields list - var FieldsList = ObjectFields.ObjectFieldsList(objectKey); + var objectFieldsList = ObjectFields.ObjectFieldsList(objectKey); //convert to strings array (https://stackoverflow.com/a/33836599/8939) string[] templateFieldList; @@ -32,21 +32,39 @@ namespace AyaNova.Biz { templateFieldList = ((JArray)jtemplate["full"]).ToObject(); } - StringBuilder sb = new StringBuilder(); - sb.Append("SELECT "); + //Default ID column + ObjectField def = objectFieldsList.FirstOrDefault(x => x.Key == "_df_"); + sb.Append(def.SqlIdColumn); + sb.Append(" AS _df_ "); + foreach (string ColumnName in templateFieldList) { - //NOPE, NOPE, NOPE....rather than this, it needs to get the names by consulting the ObjectFields list which may contain overrides for the sql name etc - sb.Append(ColumnName); + ObjectField o = objectFieldsList.FirstOrDefault(x => x.Key == s); + if (o != null) + {//Here is where we can vet the field name, if it doesn't exist though, for now we'll just ignore those ones + + sb.Append(","); + sb.Append("{"); + //Build required part of column definition + sb.Append($"\"cm\":\"{o.Key}\",\"dt\":{(int)o.DataType}"); + + //Has a AyObjectType? (linkable / openable) + if (o.AyObjectType != 0) + sb.Append($",\"ay\":{(int)o.AyObjectType}"); + + sb.Append("}"); + + } } - - return sb.ToString(); + + + return sb.ToString(); }