This commit is contained in:
2020-01-17 00:42:22 +00:00
parent 05427f2f98
commit d1afda396f
2 changed files with 149 additions and 99 deletions

View File

@@ -226,42 +226,27 @@ namespace AyaNova.Biz
from awidget from awidget
left outer join auser on (awidget.userid=auser.id) left outer join auser on (awidget.userid=auser.id)
left outer join auseroptions on (auser.id=auseroptions.userid) left outer join auseroptions on (auser.id=auseroptions.userid)
public string Key { get; set; }
public string PropertyName { get; set; }
public bool Hideable { get; set; }
public bool SharedLTKey { get; set; }
public bool Custom { get; set; }
public bool Filterable { get; set; }
public bool Sortable { get; set; }
public bool MiniAvailable { get; set; }
public int UiFieldDataType { get; set; }
//If it's an enum DataType then this is the specific enum type which sb the name of the class that holds the enum in the server project
public string EnumType { get; set; }
//if field is a reference to another object (i.e. a client in a workorders list)
//then the type to open is set here
public int AyObjectType { get; set; }
//For query building
//This is the equivalent of the v7 SqlColumnNameAttribute
public string SqlIdColumn { get; set; }
public string SqlColumn { get; set; }
*/ */
//THIS is strictly a list object, not for forms so it doesn't need hideable set to any as that's a customization thing
l.Add(new ObjectField { Key = "df", AyObjectType = (int)AyaType.Widget }); l.Add(new ObjectField { Key = "df", AyObjectType = (int)AyaType.Widget });
l.Add(new ObjectField l.Add(new ObjectField
{ {
Key = "WidgetName", Key = "WidgetName",
PropertyName = "widgetname", PropertyName = "widgetname",//same as sql display column so no need to specify both
UiFieldDataType = (int)AyaUiFieldDataType.Text, UiFieldDataType = (int)AyaUiFieldDataType.Text,
Hideable = false,
AyObjectType = (int)AyaType.Widget, AyObjectType = (int)AyaType.Widget,
SqlIdColumn = "widgetid", SqlIdColumn = "widgetid"
SqlDisplayColumn = "widgetname" });
});//not hideable for strictly list must mean it has to be in template? l.Add(new ObjectField
{
l.Add(new ObjectField { Key = "User", PropertyName = "userid", UiFieldDataType = (int)AyaUiFieldDataType.Text, AyObjectType = (int)AyaType.User }); Key = "User",
l.Add(new ObjectField { Key = "Name", PropertyName = "Name", SharedLTKey = true, UiFieldDataType = (int)AyaUiFieldDataType.Text, Hideable = false }); PropertyName = "username",//same as sql display column so no need to specify both
l.Add(new ObjectField { Key = "UserEmailAddress", PropertyName = "Emailaddress", UiFieldDataType = (int)AyaUiFieldDataType.EmailAddress, SqlDisplayColumn = "emailaddress" }); UiFieldDataType = (int)AyaUiFieldDataType.Text,
AyObjectType = (int)AyaType.User,
SqlIdColumn = "userid"
});
l.Add(new ObjectField { Key = "UserEmailAddress", PropertyName = "emailaddress", UiFieldDataType = (int)AyaUiFieldDataType.EmailAddress});
break; break;
#endregion #endregion
@@ -358,8 +343,8 @@ namespace AyaNova.Biz
public bool Custom { get; set; } public bool Custom { get; set; }
public bool Filterable { get; set; } public bool Filterable { get; set; }
public bool Sortable { get; set; } public bool Sortable { get; set; }
//had this but don't know why //had this but don't know why
//if a user wants to shove a bunch of notes into a single column with other shit that's their lookout surely //if a user wants to shove a bunch of notes into a single column with other shit that's their lookout surely
//public bool MiniAvailable { get; set; } //public bool MiniAvailable { get; set; }
public int UiFieldDataType { get; set; } public int UiFieldDataType { get; set; }
//If it's an enum DataType then this is the specific enum type which sb the name of the class that holds the enum in the server project //If it's an enum DataType then this is the specific enum type which sb the name of the class that holds the enum in the server project
@@ -380,13 +365,14 @@ namespace AyaNova.Biz
SharedLTKey = false; SharedLTKey = false;
Hideable = true; Hideable = true;
Custom = false; Custom = false;
Filterable = true; Filterable = true;
Sortable = true; Sortable = true;
//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
AyObjectType = (int)AyaType.NoType; AyObjectType = (int)AyaType.NoType;
} }
//Get column to query for display name or use PropertyName if there is no difference
public string GetSqlDisplayColumnName() public string GetSqlDisplayColumnName()
{ {
if (string.IsNullOrEmpty(SqlDisplayColumn)) if (string.IsNullOrEmpty(SqlDisplayColumn))

View File

@@ -270,7 +270,8 @@ namespace AyaNova.Biz
//get many (paged) //Generic list of widgets
#region GetList
internal async Task<ApiPagedResponse> GetList(IUrlHelper Url, string routeName, ListOptions listOptions) internal async Task<ApiPagedResponse> GetList(IUrlHelper Url, string routeName, ListOptions listOptions)
{ {
@@ -338,7 +339,7 @@ namespace AyaNova.Biz
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom}"; qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom}";
} }
//RETURN OBJECTS //RETURN OBJECTS
List<object[]> items = new List<object[]>(); List<object[]> items = new List<object[]>();
long totalRecordCount = 0; long totalRecordCount = 0;
@@ -365,15 +366,15 @@ namespace AyaNova.Biz
if (dr.Read()) if (dr.Read())
{ {
totalRecordCount = dr.GetInt64(0); totalRecordCount = dr.GetInt64(0);
} }
} }
} }
//TODO: Build the return object in a clean format //TODO: Build the return object in a clean format
//rows:{[ {},{v:"Green mechanics",id:32},{v:"...notes..."},{v:"42",id:42}, ...thousands more etc.... ]} //rows:{[ {},{v:"Green mechanics",id:32},{v:"...notes..."},{v:"42",id:42}, ...thousands more etc.... ]}
//BUILD THE PAGING LINKS PORTION //BUILD THE PAGING LINKS PORTION
var pageLinks = new PaginationLinkBuilder(Url, routeName, null, listOptions, totalRecordCount).PagingLinksObject(); var pageLinks = new PaginationLinkBuilder(Url, routeName, null, listOptions, totalRecordCount).PagingLinksObject();
@@ -401,77 +402,140 @@ namespace AyaNova.Biz
return pr; return pr;
} }
#endregion
// //get many (paged) //TEST WIDGET->USER->EMAILADDRESS multi table list
// internal async Task<ApiPagedResponse<Widget>> GetManyAsync(IUrlHelper Url, string routeName, ListOptions pagingOptions) #region TestGetWidgetUserEmailList
// { internal async Task<ApiPagedResponse> TestGetWidgetUserEmailList(IUrlHelper Url, string routeName, ListOptions listOptions)
// pagingOptions.Offset = pagingOptions.Offset ?? ListOptions.DefaultOffset; {
// pagingOptions.Limit = pagingOptions.Limit ?? ListOptions.DefaultLimit;
// //BUILD THE QUERY
// //base query
// var q = "SELECT *, xmin FROM AWIDGET ";
// //GET THE FILTER / SORT
// if (pagingOptions.DataFilterId > 0)
// {
// var TheFilter = await ct.DataFilter.FirstOrDefaultAsync(x => x.Id == pagingOptions.DataFilterId);
// //BUILD WHERE AND APPEND IT
// q = q + FilterSqlCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, WidgetBiz.FilterOptions(), UserId);
// //BUILD ORDER BY AND APPEND IT
// q = q + FilterSqlOrderByBuilder.DataFilterToSQLOrderBy(TheFilter);
// }
// else
// {
// //GET DEFAULT ORDER BY
// q = q + FilterSqlOrderByBuilder.DefaultGetManyOrderBy();
// }
// #pragma warning disable EF1000
// var items = await ct.Widget //TODO: Get template (MOCKED FOR NOW UNTIL PROOF OF CONCEPT)
// .FromSqlRaw(q) var MOCK_WIDGET_DISPLAY_TEMPLATE_JSON = @"
// .AsNoTracking() {
// .Skip(pagingOptions.Offset.Value) ""full"":[""WidgetName"",""WidgetSerial"",""WidgetDollarAmount"",""WidgetRoles"",""WidgetStartDate"",""Active""],
// .Take(pagingOptions.Limit.Value) ""mini"":[""WidgetName"",""WidgetSerial""]
// .ToArrayAsync(); }
";
// var totalRecordCount = await ct.Widget //BUILD THE QUERY
// .FromSqlRaw(q)
// .AsNoTracking()
// .CountAsync();
// #pragma warning restore EF1000
// var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, totalRecordCount).PagingLinksObject(); //SELECT FRAGMENT COLUMNS FROM TEMPLATE
//"select clm,clm,clm"
var qSelectColumns = SqlSelectBuilder.Build(ObjectFields.WIDGET_KEY, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON, listOptions.Mini);
// ApiPagedResponse<Widget> pr = new ApiPagedResponse<Widget>(items, pageLinks); var qFrom = "FROM AWIDGET";
// return pr;
// } //FILTERED?
DataFilter TheFilter = null;
if (listOptions.DataFilterId > 0)
{
TheFilter = await ct.DataFilter.FirstOrDefaultAsync(x => x.Id == listOptions.DataFilterId);
}
//WHERE CLAUSE - FILTER
var qWhere = string.Empty;
if (listOptions.DataFilterId > 0)
{
qWhere = SqlFilterCriteriaBuilder.DataFilterToSQLCriteria(TheFilter, ObjectFields.ObjectFieldsList(ObjectFields.WIDGET_KEY), UserId);
}
//ORDER BY CLAUSE - SORT
var qOrderBy = string.Empty;
if (listOptions.DataFilterId > 0)
{
//BUILD ORDER BY AND APPEND IT
qOrderBy = SqlFilterOrderByBuilder.DataFilterToSQLOrderBy(TheFilter);
}
else
{
//GET DEFAULT ORDER BY
qOrderBy = SqlFilterOrderByBuilder.DefaultGetManyOrderBy();
}
//LIMIT AND OFFSET CLAUSE - PAGING
listOptions.Offset = listOptions.Offset ?? ListOptions.DefaultOffset;
listOptions.Limit = listOptions.Limit ?? ListOptions.DefaultLimit;
var qLimitOffset = $"LIMIT {listOptions.Limit} OFFSET {listOptions.Offset}";
//PUT IT ALL TOGETHER
string qDataQuery = string.Empty;
string qTotalRecordsQuery = string.Empty;
if (TheFilter != null)
{
qDataQuery = $"{qSelectColumns} {qFrom} {qWhere} {qOrderBy} {qLimitOffset}";
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom} {qWhere}";
}
else
{
qDataQuery = $"{qSelectColumns} {qFrom} {qLimitOffset}";
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom}";
}
// /// <summary> //RETURN OBJECTS
// /// Get PickList List<object[]> items = new List<object[]>();
// /// </summary> long totalRecordCount = 0;
// /// <param name="Url"></param>
// /// <param name="routeName"></param> //RUN THE QUERY
// /// <param name="pagingOptions"></param> using (var command = ct.Database.GetDbConnection().CreateCommand())
// /// <returns></returns> {
// internal ApiPagedResponse<NameIdItem> GetPickList(IUrlHelper Url, string routeName, ListOptions pagingOptions)
// { ct.Database.OpenConnection();
// pagingOptions.Offset = pagingOptions.Offset ?? ListOptions.DefaultOffset; command.CommandText = qDataQuery;
// pagingOptions.Limit = pagingOptions.Limit ?? ListOptions.DefaultLimit; using (var dr = command.ExecuteReader())
// var ret = PickListFetcher.GetPickList(ct, UserId, pagingOptions, FilterOptions(), "awidget"); {
// var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, ret.TotalRecordCount).PagingLinksObject(); while (dr.Read())
// ApiPagedResponse<NameIdItem> pr = new ApiPagedResponse<NameIdItem>(ret.Items, pageLinks); {
// return pr; object[] row = new object[dr.FieldCount];
// } dr.GetValues(row);
items.Add(row);
}
}
command.CommandText = qTotalRecordsQuery;
using (var dr = command.ExecuteReader())
{
if (dr.Read())
{
totalRecordCount = dr.GetInt64(0);
}
}
}
//TODO: Build the return object in a clean format
//rows:{[ {},{v:"Green mechanics",id:32},{v:"...notes..."},{v:"42",id:42}, ...thousands more etc.... ]}
//BUILD THE PAGING LINKS PORTION
var pageLinks = new PaginationLinkBuilder(Url, routeName, null, listOptions, totalRecordCount).PagingLinksObject();
//BUILD THE COLUMNS RETURN PROPERTY JSON FRAGMENT
string ColumnsJSON = string.Empty;
if (listOptions.Mini)
{
ColumnsJSON = ObjectFields.GenerateMINIListColumnsJSON(AyaType.Widget);
}
else
{
ColumnsJSON = ObjectFields.GenerateListColumnsJSONFromTemplate(AyaType.Widget, ObjectFields.WIDGET_KEY, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON);
}
//TODO: BUILD THE RETURN LIST OF DATA ITEMS
//If mini format all desired columns in order into the single mini return display (and set the only other return field which is ID)
//If wide then format the fields in oder chosen (grid sort and filter template has already done that part above)
//TODO: Genericize the above block of building return when it's working as this code needs to be central and optimized as much as possible
ApiPagedResponse pr = new ApiPagedResponse(items, pageLinks, ColumnsJSON);
return pr;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION //VALIDATION