This commit is contained in:
@@ -74,7 +74,7 @@ namespace AyaNova.PickList
|
||||
sb.Append("{");
|
||||
//Build required part of column definition
|
||||
if (!o.IsCustomField)
|
||||
sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.UiFieldDataType}");
|
||||
sb.Append($"\"cm\":\"{o.LtKey}\",\"dt\":{(int)o.ColumnDataType}");
|
||||
else
|
||||
{
|
||||
//insert specific type for this custom field
|
||||
|
||||
@@ -27,23 +27,23 @@ namespace AyaNova.PickList
|
||||
//CLIENT / SERVER - client display server validation purposes
|
||||
public bool IsSortable { get; set; }
|
||||
|
||||
//CLIENT Use only for display
|
||||
public int UiFieldDataType { get; set; }
|
||||
//PL Used for casting query
|
||||
public UiFieldDataType ColumnDataType { get; set; }
|
||||
|
||||
//CLIENT Use only for display
|
||||
public string EnumType { get; set; }
|
||||
|
||||
//SERVER / CLIENT - used to identify the column that represents the entire row ID and object
|
||||
//MUST be present in all datalists and displayed at the client
|
||||
//PL Used
|
||||
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
|
||||
//don't return these properties when api user fetches field list definitions in DataListController
|
||||
public AyaType AyaObjectType { get; set; }
|
||||
|
||||
|
||||
//PL Used
|
||||
[JsonIgnore]
|
||||
public string SqlIdColumnName { get; set; }
|
||||
[JsonIgnore]
|
||||
@@ -61,7 +61,7 @@ namespace AyaNova.PickList
|
||||
IsFilterable = true;
|
||||
IsSortable = true;
|
||||
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
|
||||
AyaObjectType = (int)AyaType.NoType;
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Biz;
|
||||
|
||||
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)
|
||||
//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
|
||||
//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
|
||||
bool HasAutoCompleteQuery = !string.IsNullOrWhiteSpace(autoCompleteQuery);
|
||||
|
||||
//lists to collect the clauses so to avoid comma fuckery
|
||||
List<string> lSelect = new List<string>();
|
||||
string ActiveWhereFragment = string.Empty;
|
||||
List<string> lWhere = new List<string>();
|
||||
List<string> lOrderBy = new List<string>();
|
||||
|
||||
@@ -53,7 +57,7 @@ namespace AyaNova.PickList
|
||||
if (activeColumn != null)
|
||||
{
|
||||
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
|
||||
|
||||
var valueColumnName = o.GetSqlValueColumnName();
|
||||
|
||||
lSelect.Add(valueColumnName);
|
||||
lOrderBy.Add(valueColumnName);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -100,9 +125,14 @@ namespace AyaNova.PickList
|
||||
sb.Append(pickList.SQLFrom);
|
||||
|
||||
|
||||
//WHERE
|
||||
sb.Append(" ");
|
||||
sb.Append("where ");
|
||||
//WHERE
|
||||
sb.Append(" where ");
|
||||
if (!IncludeInactive)
|
||||
{
|
||||
sb.Append(ActiveWhereFragment);
|
||||
sb.Append(" and (");
|
||||
}
|
||||
|
||||
foreach (string s in lWhere)
|
||||
{
|
||||
sb.Append(s);
|
||||
@@ -110,9 +140,14 @@ namespace AyaNova.PickList
|
||||
}
|
||||
//clear trailing or
|
||||
sb.Length -= 4;
|
||||
//enclosing parenthesis
|
||||
if (!IncludeInactive)
|
||||
{
|
||||
sb.Append(")");
|
||||
}
|
||||
|
||||
//ORDER BY
|
||||
sb.Append("ORDER BY ");
|
||||
sb.Append(" order by ");
|
||||
foreach (string s in lOrderBy)
|
||||
{
|
||||
sb.Append(s);
|
||||
@@ -121,9 +156,8 @@ namespace AyaNova.PickList
|
||||
//clear trailing comma
|
||||
sb.Length--;
|
||||
|
||||
//LIMIT
|
||||
sb.Append(" ");
|
||||
sb.Append($"LIMIT {MAXIMUM_RESULT_COUNT}");
|
||||
//LIMIT
|
||||
sb.Append($" limit {MAXIMUM_RESULT_COUNT}");
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace AyaNova.PickList
|
||||
{
|
||||
LtKey = "Active",
|
||||
FieldKey = "widgetactive",
|
||||
UiFieldDataType = (int)UiFieldDataType.Bool,
|
||||
ColumnDataType = UiFieldDataType.Bool,
|
||||
SqlValueColumnName = "awidget.active",
|
||||
IsActiveColumn = true
|
||||
});
|
||||
@@ -46,8 +46,8 @@ namespace AyaNova.PickList
|
||||
{
|
||||
LtKey = "WidgetName",
|
||||
FieldKey = "widgetname",
|
||||
AyaObjectType = (int)AyaType.Widget,
|
||||
UiFieldDataType = (int)UiFieldDataType.Text,
|
||||
AyaObjectType = AyaType.Widget,
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
SqlIdColumnName = "awidget.id",
|
||||
SqlValueColumnName = "awidget.name",
|
||||
IsRowId = true
|
||||
@@ -57,7 +57,7 @@ namespace AyaNova.PickList
|
||||
{
|
||||
LtKey = "WidgetSerial",
|
||||
FieldKey = "widgetserial",
|
||||
UiFieldDataType = (int)UiFieldDataType.Integer,
|
||||
ColumnDataType = UiFieldDataType.Integer,
|
||||
SqlValueColumnName = "awidget.serial"
|
||||
});
|
||||
|
||||
@@ -65,8 +65,8 @@ namespace AyaNova.PickList
|
||||
{
|
||||
FieldKey = "username",
|
||||
LtKey = "User",
|
||||
UiFieldDataType = (int)UiFieldDataType.Text,
|
||||
AyaObjectType = (int)AyaType.User,
|
||||
ColumnDataType = UiFieldDataType.Text,
|
||||
AyaObjectType = AyaType.User,
|
||||
SqlIdColumnName = "auser.id",
|
||||
SqlValueColumnName = "auser.name"
|
||||
});
|
||||
@@ -75,7 +75,7 @@ namespace AyaNova.PickList
|
||||
{
|
||||
LtKey = "Tags",
|
||||
FieldKey = "widgettags",
|
||||
UiFieldDataType = (int)UiFieldDataType.Tags,
|
||||
ColumnDataType = UiFieldDataType.Tags,
|
||||
SqlValueColumnName = "awidget.tags"
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user