This commit is contained in:
2020-01-22 16:24:39 +00:00
parent 8267365370
commit 070688265b
18 changed files with 92 additions and 54 deletions

View File

@@ -77,6 +77,44 @@ namespace AyaNova.DataList
return 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[]>();
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;
}
}//eoc
}//eons

View File

@@ -32,19 +32,19 @@ namespace AyaNova.DataList
}
//FETCH DATALISTTEMPLATE HERE OR USE DEFAULT IF FAULTY OR NOT FOUND
//start with default
string JSONDataListTemplate=DataList.DefaultDataListDisplayTemplate;
string JSONDataListTemplate = DataList.DefaultDataListDisplayTemplate;
var CustomDataListTemplate = await ct.DataListTemplate.FirstOrDefaultAsync(x => x.DataListKey == listOptions.DataListKey);
//Null is expected unless user has created a new one
if(CustomDataListTemplate!=null){
//todo: validate the template first here need a new method to do that
//Assuming it's valid then use it
JSONDataListTemplate = CustomDataListTemplate.Template;
//Null is expected unless user has created a custom one
if (CustomDataListTemplate != null)
{
//Make sure it's valid, if not then don't use it
if (DataList.ValidateTemplate(CustomDataListTemplate.Template))
JSONDataListTemplate = CustomDataListTemplate.Template;
}
//PARSE THE TEMPLATE INTO A STRING ARRAY
//SO WE KNOW WHICH FIELDS TO RETURN FROM QUERY

View File

@@ -25,6 +25,8 @@ namespace AyaNova.DataList
string GenerateMINIListColumnsJSON();
string GenerateListColumnsJSONFromTemplate(string template);
bool ValidateTemplate(string template);
}