This commit is contained in:
2020-03-13 21:18:59 +00:00
parent 6c2370b053
commit 73ccf1c359
4 changed files with 66 additions and 32 deletions

View File

@@ -74,7 +74,7 @@ namespace AyaNova.PickList
sb.Append("{"); sb.Append("{");
//Build required part of column definition //Build required part of column definition
if (!o.IsCustomField) if (!o.IsCustomField)
sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.UiFieldDataType}"); sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.ColumnDataType}");
else else
{ {
//insert specific type for this custom field //insert specific type for this custom field

View File

@@ -27,23 +27,23 @@ namespace AyaNova.PickList
//CLIENT / SERVER - client display server validation purposes //CLIENT / SERVER - client display server validation purposes
public bool IsSortable { get; set; } public bool IsSortable { get; set; }
//CLIENT Use only for display //PL Used for casting query
public int UiFieldDataType { get; set; } public UiFieldDataType ColumnDataType { get; set; }
//CLIENT Use only for display //CLIENT Use only for display
public string EnumType { get; set; } public string EnumType { get; set; }
//SERVER / CLIENT - used to identify the column that represents the entire row ID and object //PL Used
//MUST be present in all datalists and displayed at the client
public bool IsRowId { get; set; } public bool IsRowId { get; set; }
public bool IsActiveColumn { get; set; } //PL Used
public bool IsActiveColumn { get; set; }
//CLIENT / SERVER - client display and to indicate what object to open , Server for formatting return object
public int AyaObjectType { get; set; }
//SERVER - for building sql queries public AyaType AyaObjectType { get; set; }
//don't return these properties when api user fetches field list definitions in DataListController
//PL Used
[JsonIgnore] [JsonIgnore]
public string SqlIdColumnName { get; set; } public string SqlIdColumnName { get; set; }
[JsonIgnore] [JsonIgnore]
@@ -61,7 +61,7 @@ namespace AyaNova.PickList
IsFilterable = true; IsFilterable = true;
IsSortable = true; IsSortable = true;
IsRowId = false; IsRowId = false;
IsActiveColumn=false; IsActiveColumn = false;
//Set openable object type to no type which is the default and means it's not a link to another object //Set openable object type to no type which is the default and means it's not a link to another object
AyaObjectType = (int)AyaType.NoType; AyaObjectType = (int)AyaType.NoType;

View File

@@ -1,11 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System;
using System.Globalization;
using System.Text; using System.Text;
using Newtonsoft.Json.Linq;
using System.Linq; using System.Linq;
using Microsoft.EntityFrameworkCore; using AyaNova.Biz;
using Microsoft.Extensions.Logging;
namespace AyaNova.PickList namespace AyaNova.PickList
{ {
@@ -28,12 +24,20 @@ namespace AyaNova.PickList
//TODO: build a sql List<AyaPickListFieldDefinition> columnDefinitionsselect and order by and a where clause that searches appropriately in each field (tags) //TODO: build a sql List<AyaPickListFieldDefinition> columnDefinitionsselect and order by and a where clause that searches appropriately in each field (tags)
//it should return results based on the query where there is a single name (display) column and an id column for rowid //it should return results based on the query where there is a single name (display) column and an id column for rowid
//and the fields should be combined in a standard way separated by spaces "Widget widgetserial username" for compactness //and the fields should be combined in a standard way separated by spaces "Widget widgetserial username" for compactness
//WORKING QUERY
//select awidget.id AS rowid,awidget.active,awidget.name,awidget.serial,auser.name from awidget left outer join auser on (awidget.userid=auser.id)
//where awidget.active = true and ((awidget.name like '%some%') or (cast (awidget.serial as text) like '%some%') or (auser.name like '%some%') ) order by awidget.name,awidget.serial,auser.name limit 100
//TODO: TAGS
//TODO: Clean out unnneeded stuff in AyaPickListFieldDefinition (stuff from datalist copied over)
//determine this in advance as it will be used in a loop later //determine this in advance as it will be used in a loop later
bool HasAutoCompleteQuery = !string.IsNullOrWhiteSpace(autoCompleteQuery); bool HasAutoCompleteQuery = !string.IsNullOrWhiteSpace(autoCompleteQuery);
//lists to collect the clauses so to avoid comma fuckery //lists to collect the clauses so to avoid comma fuckery
List<string> lSelect = new List<string>(); List<string> lSelect = new List<string>();
string ActiveWhereFragment = string.Empty;
List<string> lWhere = new List<string>(); List<string> lWhere = new List<string>();
List<string> lOrderBy = new List<string>(); List<string> lOrderBy = new List<string>();
@@ -53,7 +57,7 @@ namespace AyaNova.PickList
if (activeColumn != null) if (activeColumn != null)
{ {
lSelect.Add(activeColumn.SqlValueColumnName); lSelect.Add(activeColumn.SqlValueColumnName);
lWhere.Add(activeColumn.SqlValueColumnName + " = true"); ActiveWhereFragment = activeColumn.SqlValueColumnName + " = true";
} }
} }
@@ -71,12 +75,33 @@ namespace AyaNova.PickList
{//Ignore missing fields in production {//Ignore missing fields in production
var valueColumnName = o.GetSqlValueColumnName(); var valueColumnName = o.GetSqlValueColumnName();
lSelect.Add(valueColumnName); lSelect.Add(valueColumnName);
lOrderBy.Add(valueColumnName); lOrderBy.Add(valueColumnName);
if (HasAutoCompleteQuery) if (HasAutoCompleteQuery)
{ {
string sWhere = $"({valueColumnName} LIKE '%{autoCompleteQuery}%')"; string sWhere = string.Empty;
//Tag?
if (o.ColumnDataType == UiFieldDataType.Tags)
{
}
else if (o.ColumnDataType == UiFieldDataType.Text || o.ColumnDataType == UiFieldDataType.EmailAddress || o.ColumnDataType == UiFieldDataType.HTTP)
{
//regular text field
sWhere = $"({valueColumnName} LIKE '%{autoCompleteQuery}%')";
}
else
{
//needs to be cast to text
//(cast (awidget.serial as text) like '%some%')
sWhere = $"(cast ({valueColumnName} as text) LIKE '%{autoCompleteQuery}%')";
}
lWhere.Add(sWhere); lWhere.Add(sWhere);
} }
@@ -101,8 +126,13 @@ namespace AyaNova.PickList
//WHERE //WHERE
sb.Append(" "); sb.Append(" where ");
sb.Append("where "); if (!IncludeInactive)
{
sb.Append(ActiveWhereFragment);
sb.Append(" and (");
}
foreach (string s in lWhere) foreach (string s in lWhere)
{ {
sb.Append(s); sb.Append(s);
@@ -110,9 +140,14 @@ namespace AyaNova.PickList
} }
//clear trailing or //clear trailing or
sb.Length -= 4; sb.Length -= 4;
//enclosing parenthesis
if (!IncludeInactive)
{
sb.Append(")");
}
//ORDER BY //ORDER BY
sb.Append("ORDER BY "); sb.Append(" order by ");
foreach (string s in lOrderBy) foreach (string s in lOrderBy)
{ {
sb.Append(s); sb.Append(s);
@@ -122,8 +157,7 @@ namespace AyaNova.PickList
sb.Length--; sb.Length--;
//LIMIT //LIMIT
sb.Append(" "); sb.Append($" limit {MAXIMUM_RESULT_COUNT}");
sb.Append($"LIMIT {MAXIMUM_RESULT_COUNT}");
return sb.ToString(); return sb.ToString();

View File

@@ -37,7 +37,7 @@ namespace AyaNova.PickList
{ {
LtKey = "Active", LtKey = "Active",
FieldKey = "widgetactive", FieldKey = "widgetactive",
UiFieldDataType = (int)UiFieldDataType.Bool, ColumnDataType = UiFieldDataType.Bool,
SqlValueColumnName = "awidget.active", SqlValueColumnName = "awidget.active",
IsActiveColumn = true IsActiveColumn = true
}); });
@@ -46,8 +46,8 @@ namespace AyaNova.PickList
{ {
LtKey = "WidgetName", LtKey = "WidgetName",
FieldKey = "widgetname", FieldKey = "widgetname",
AyaObjectType = (int)AyaType.Widget, AyaObjectType = AyaType.Widget,
UiFieldDataType = (int)UiFieldDataType.Text, ColumnDataType = UiFieldDataType.Text,
SqlIdColumnName = "awidget.id", SqlIdColumnName = "awidget.id",
SqlValueColumnName = "awidget.name", SqlValueColumnName = "awidget.name",
IsRowId = true IsRowId = true
@@ -57,7 +57,7 @@ namespace AyaNova.PickList
{ {
LtKey = "WidgetSerial", LtKey = "WidgetSerial",
FieldKey = "widgetserial", FieldKey = "widgetserial",
UiFieldDataType = (int)UiFieldDataType.Integer, ColumnDataType = UiFieldDataType.Integer,
SqlValueColumnName = "awidget.serial" SqlValueColumnName = "awidget.serial"
}); });
@@ -65,8 +65,8 @@ namespace AyaNova.PickList
{ {
FieldKey = "username", FieldKey = "username",
LtKey = "User", LtKey = "User",
UiFieldDataType = (int)UiFieldDataType.Text, ColumnDataType = UiFieldDataType.Text,
AyaObjectType = (int)AyaType.User, AyaObjectType = AyaType.User,
SqlIdColumnName = "auser.id", SqlIdColumnName = "auser.id",
SqlValueColumnName = "auser.name" SqlValueColumnName = "auser.name"
}); });
@@ -75,7 +75,7 @@ namespace AyaNova.PickList
{ {
LtKey = "Tags", LtKey = "Tags",
FieldKey = "widgettags", FieldKey = "widgettags",
UiFieldDataType = (int)UiFieldDataType.Tags, ColumnDataType = UiFieldDataType.Tags,
SqlValueColumnName = "awidget.tags" SqlValueColumnName = "awidget.tags"
}); });