From ed666419abd9eae6ddbc6af9762cfc0ba05f38f3 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 27 Feb 2020 20:40:53 +0000 Subject: [PATCH] --- devdocs/specs/core-log-business.txt | 2 +- server/AyaNova/DataList/AyaDataList.cs | 113 +++++++++++++++---------- 2 files changed, 70 insertions(+), 45 deletions(-) diff --git a/devdocs/specs/core-log-business.txt b/devdocs/specs/core-log-business.txt index 5bc483ae..4d2824ee 100644 --- a/devdocs/specs/core-log-business.txt +++ b/devdocs/specs/core-log-business.txt @@ -25,7 +25,7 @@ A master enum of all event types in RAVEN. Co-used by this log feature, but also used by notification system Also used by localized text feature to fetch text about event for display in log and notification etc May be used for other things in future. -Common event types that apply to any object and then specific event types that apply to particular types of objects but all in teh same master enum +Common event types that apply to any object and then specific event types that apply to particular types of objects but all in the same master enum EventType ALL OBJECTS diff --git a/server/AyaNova/DataList/AyaDataList.cs b/server/AyaNova/DataList/AyaDataList.cs index f85f29ca..15ee103a 100644 --- a/server/AyaNova/DataList/AyaDataList.cs +++ b/server/AyaNova/DataList/AyaDataList.cs @@ -48,6 +48,7 @@ namespace AyaNova.DataList var ListViewFieldKeys = GetFieldListFromListView(listViewArray); + var CustomFieldDefinitions = GetCustomFieldDefinitionsForList(); //Generate JSON fragment to return with column definitions StringBuilder sb = new StringBuilder(); @@ -106,50 +107,15 @@ namespace AyaNova.DataList } - // //make sure the template parses and all the fields specified are really existant - // //this is more for dev errors or api users becuase the client shouldn't generate bad templates - // public bool ValidateTemplate(string template) - // { - // try - // { - // //parse the template - // var jtemplate = JObject.Parse(template); - // var fullFields = ((JArray)jtemplate["full"]).ToObject(); - // var miniFields = ((JArray)jtemplate["mini"]).ToObject(); - - // foreach (string s in fullFields) - // { - // AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s); - // if (o == null) - // { - // return false; - // } - // } - - // foreach (string s in miniFields) - // { - // AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s); - // if (o == null) - // { - // return false; - // } - // } - // } - // catch - // { - // return false; - // } - - // return true; - // } - - //Find and return a dictionary of all custom fields definitions for all types in list //used to build the column array and define specific type defined for custom fields so client datatable //knows how to format it - private Dictionary GetCustomFieldDefinitionsForList() + private Dictionary GetCustomFieldDefinitionsForList() { - Dictionary ret = new Dictionary(); + //all keys and types can go in the same list since they are unique to each type of list + //i.e. both users and widget custom fields can be in the same list + Dictionary ret = new Dictionary(); + List typesProcessed = new List(); //custom fields handling foreach (AyaDataListFieldDefinition d in this.FieldDefinitions) { @@ -158,8 +124,10 @@ namespace AyaNova.DataList //this relies on the convention I'm using of AyaType name as the first part of all custom fields lT keys, e.g. //WidgetCustom1 -> Widget var ayatypename = d.LtKey.Split("Custom")[0]; - if (!ret.ContainsKey(ayatypename)) + if (!typesProcessed.Contains(ayatypename)) { + //make sure we do each type only once + typesProcessed.Add(ayatypename); //fetch it and set it using (var ct = AyaNova.Util.ServiceProviderProvider.DBContext) { @@ -170,18 +138,75 @@ namespace AyaNova.DataList throw new System.ArgumentNullException($"AyaDataList:GetCustomFieldDefinitionsForList, Custom field object type {ayatypename} has no FormCustom defined"); } #endif - if (fc != null) - ret.Add(ayatypename, JArray.Parse(fc.Template)); + //production handling of missing formcustom + if (fc == null) + continue; + + //iterate the fields and add each custom one with a type to the return dictionary + var flds = JArray.Parse(fc.Template); + foreach(JToken t in flds){ + if(t["type"]!=null){ + ret.Add(t["fld"].Value(),t["type"].Value()); + } + } + + } } } } - + /*{[ + { + "fld": "Notes", + "required": true + }, + { + "fld": "WidgetCustom1", + "required": false, + "type": 1 + }, + { + "fld": "WidgetCustom2", + "required": true, + "type": 4 + }, + { + "fld": "WidgetCustom3", + "required": false, + "type": 5 + }, + { + "fld": "WidgetCustom4", + "required": false, + "type": 6 + }, + { + "fld": "WidgetCustom5", + "required": false, + "type": 8 + }, + { + "fld": "WidgetCustom6", + "required": false, + "type": 2 + }, + { + "fld": "WidgetCustom7", + "required": false, + "type": 3 + } + ]}*/ return ret; } + private class NameType + { + string name { get; set; } + UiFieldDataType datatype { get; set; } + } + }//eoc }//eons \ No newline at end of file