diff --git a/server/AyaNova/DataList/AyaDataList.cs b/server/AyaNova/DataList/AyaDataList.cs index edb836d0..fa6fdf33 100644 --- a/server/AyaNova/DataList/AyaDataList.cs +++ b/server/AyaNova/DataList/AyaDataList.cs @@ -1,9 +1,8 @@ using System.Collections.Generic; -using System.Collections.Immutable; -using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using AyaNova.Biz; +using Newtonsoft.Json.Linq; namespace AyaNova.DataList { @@ -19,39 +18,63 @@ namespace AyaNova.DataList } - // private string _listKey = string.Empty; - // public string ListKey - // { - // get - // { - // return _listKey; - // } - // set - // { - // _listKey = value; - // } - // } - - //private readonly string _sqlFrom = string.Empty; public string SQLFrom { get; set; } - - // private readonly List _fieldDefinitions = new List(); public List FieldDefinitions { get; set; } - public AuthorizationRoles AllowedRoles { get; set; } - public AyaType DefaultListObjectType { get; set; } - public string ListKey { get; set; } public string GenerateMINIListColumnsJSON() { - throw new System.NotImplementedException(); + return $"[ {{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)DefaultListObjectType}}},{{\"cm\":\"Widget\",\"dt\":{(int)AyaUiFieldDataType.Text},\"ay\":{(int)DefaultListObjectType}}}]"; } public string GenerateListColumnsJSONFromTemplate(string template) { - throw new System.NotImplementedException(); + //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)DefaultListObjectType}}}"); + + foreach (string s in fullFields) + { + AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s); +#if (DEBUG) + //Developers little helper + if (o == null) + { + throw new System.ArgumentNullException($"DEV ERROR in AyaDataList::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