This commit is contained in:
2020-02-13 20:50:53 +00:00
parent 5aacb87a93
commit 684f7be73d
7 changed files with 141 additions and 131 deletions

View File

@@ -20,107 +20,103 @@ namespace AyaNova.DataList
public string SQLFrom { get; set; }
public List<AyaDataListFieldDefinition> FieldDefinitions { get; set; }//NOTE: First field after df is used as the title above the narrow grid view so it should be the name of the item to be shown that is most identifiable
public AuthorizationRoles FullListAllowedRoles { get; set; }
public AuthorizationRoles MiniListAllowedRoles { get; set; }
public AuthorizationRoles AllowedRoles { get; set; }
public AyaType DefaultListObjectType { get; set; }
public string ListKey { get; set; }
public string DefaultDataListDisplayTemplate { get; set; }
public Newtonsoft.Json.Linq.JArray GenerateMINIListColumnsJSON()
public string DefaultListView { get; set; }
public Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromListView(string listView)
{
//return $"[ {{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)DefaultListObjectType}}},{{\"cm\":\"Widget\",\"dt\":{(int)AyaUiFieldDataType.Text},\"ay\":{(int)DefaultListObjectType}}}]";
return JArray.Parse($"[ {{\"cm\":\"df\",\"dt\":0,\"ay\":{(int)DefaultListObjectType}}},{{\"cm\":\"Widget\",\"dt\":{(int)UiFieldDataType.Text},\"ay\":{(int)DefaultListObjectType}}}]");
}
public Newtonsoft.Json.Linq.JArray GenerateListColumnsJSONFromTemplate(string template)
{
//parse the template
var jtemplate = JObject.Parse(template);
throw new System.NotImplementedException("AyaDataList:GenerateListColumnsJSONFromListView not coded yet ");
// //parse the template
// var jtemplate = JObject.Parse(listView);
//convert to strings (https://stackoverflow.com/a/33836599/8939)
var fullFields = ((JArray)jtemplate["full"]).ToObject<string[]>();
// //convert to strings (https://stackoverflow.com/a/33836599/8939)
// var fullFields = ((JArray)jtemplate["full"]).ToObject<string[]>();
//Generate JSON fragment to return with column definitions
StringBuilder sb = new StringBuilder();
// //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}}}");
// 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
// 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
// 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}");
// 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}");
// //Has a AyObjectType? (linkable / openable)
// if (o.AyaObjectType != 0)
// sb.Append($",\"ay\":{(int)o.AyaObjectType}");
//Has a Enumtype?
if (!string.IsNullOrEmpty(o.EnumType))
sb.Append($",\"et\":\"{AyaNova.Util.StringUtil.TrimTypeName(o.EnumType)}\"");
// //Has a Enumtype?
// if (!string.IsNullOrEmpty(o.EnumType))
// sb.Append($",\"et\":\"{AyaNova.Util.StringUtil.TrimTypeName(o.EnumType)}\"");
sb.Append("}");
// sb.Append("}");
}
}
sb.Append("]");
// }
// }
// sb.Append("]");
return JArray.Parse(sb.ToString());
// return JArray.Parse(sb.ToString());
}
//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<string[]>();
var miniFields = ((JArray)jtemplate["mini"]).ToObject<string[]>();
// //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<string[]>();
// var miniFields = ((JArray)jtemplate["mini"]).ToObject<string[]>();
foreach (string s in fullFields)
{
AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s);
if (o == null)
{
return false;
}
}
// 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;
}
// foreach (string s in miniFields)
// {
// AyaDataListFieldDefinition o = FieldDefinitions.FirstOrDefault(x => x.FieldKey == s);
// if (o == null)
// {
// return false;
// }
// }
// }
// catch
// {
// return false;
// }
return true;
}
// return true;
// }
}//eoc