This commit is contained in:
2021-01-30 16:08:13 +00:00
parent 6be01deba6
commit 0e8b90a778
3 changed files with 83 additions and 66 deletions

View File

@@ -1,5 +1,9 @@
using System.Threading.Tasks;
using AyaNova.Biz;
using System.Collections.Generic;
using AyaNova.DataList;
using Newtonsoft.Json;
using EnumsNET;
namespace AyaNova.Models
{
//Used to drive processes that rely on selections made at client from a datalist
@@ -7,50 +11,24 @@ namespace AyaNova.Models
//be used to rehydrate a list of id's
public class DataListSelectedProcessingOptions : DataListProcessingBase
{
public AyaType ObjectType { get; set; }
public long[] SelectedRowIds { get; set; }
//public AyaType ObjectType { get; set; }
// public long[] SelectedRowIds { get; set; }
// public string DataListKey { get; set; }
// public string ListView { get; set; }//optional, if null or empty will use default list view built into DataList
// public string MetaView { get; set; }//optional meta list view to integrate into the standard list view. Used by client to add "meta" filter conditions above the user's choices e.g. customer notes customer id
public bool IsEmpty
internal DataListSelectedProcessingOptions(
DataListSelectedRequest request,
IDataListProcessing dataList,
DataListSavedColumnView savedView,
DataListSavedFilter savedFilter,
long userId,
AuthorizationRoles userRoles)
{
get
{
return SelectedRowIds.LongLength == 0 && string.IsNullOrWhiteSpace(DataListKey);
}
}
///TODO: recode this to fulfil requirements of datalistfetcher in the same way as
//DataListTableProcessingOptions constructor
//clean out datalistfetcher comments and similar afterwards
public async Task RehydrateIdList(AyContext ct, AuthorizationRoles userRoles, Microsoft.Extensions.Logging.ILogger log, long userId)
{
if (SelectedRowIds.Length == 0)
SelectedRowIds = await AyaNova.DataList.DataListFetcher.GetIdListResponseAsync(ct, this, userRoles, log, userId);
}
}
}
/*
internal DataListTableProcessingOptions(
DataListTableRequest request,
IDataListProcessing dataList,
DataListSavedColumnView savedView,
DataListSavedFilter savedFilter,
long userId,
AuthorizationRoles userRoles)
{
//set some values from request
Limit = request.Limit;
Offset = request.Offset;
//set some values from request
base.ClientCriteria = request.ClientCriteria;
base.DataListKey = request.DataListKey;
//SET COLUMNS
Columns = JsonConvert.DeserializeObject<List<string>>(savedView.Columns);
//SET SORTBY
base.SortBy = JsonConvert.DeserializeObject<Dictionary<string, string>>(savedView.Sort);
@@ -69,4 +47,41 @@ namespace AyaNova.Models
base.Filter.Add(dfo);
}
*/
public static async Task<long[]> RehydrateIdList(DataListSelectedRequest selectedRequest, AyContext ct, AuthorizationRoles userRoles, Microsoft.Extensions.Logging.ILogger log, long userId, long userTranslationId)
{
DataListSavedColumnViewBiz viewbiz = new DataListSavedColumnViewBiz(ct, userId, userTranslationId, userRoles);
var SavedView = await viewbiz.GetAsync(userId, selectedRequest.DataListKey, true);
DataListSavedFilter SavedFilter = null;
if (selectedRequest.FilterId != 0)
{
DataListSavedFilterBiz filterbiz = new DataListSavedFilterBiz(ct, userId, userTranslationId, userRoles);
SavedFilter = await filterbiz.GetAsync(selectedRequest.FilterId, false);
}
var DataList = DataListFactory.GetAyaDataList(selectedRequest.DataListKey);
if (DataList == null)
throw new System.ArgumentOutOfRangeException($"DataList \"{selectedRequest.DataListKey}\" specified does not exist");
//check rights
if (!userRoles.HasAnyFlags(DataList.AllowedRoles))
throw new System.UnauthorizedAccessException($"DataList \"{selectedRequest.DataListKey}\" required Roles not found for this user");
DataListSelectedProcessingOptions d = new DataListSelectedProcessingOptions(selectedRequest, DataList, SavedView, SavedFilter, userId, userRoles);
//hydrate the saved view and filter
// DataListSelectedProcessingOptions dataListSelectedOptions = new DataListSelectedProcessingOptions(selectedRequest, DataList, SavedView, SavedFilter, UserId, UserRoles);
// //------------------------
// if (SelectedRowIds.Length == 0)
// SelectedRowIds = await AyaNova.DataList.DataListFetcher.GetIdListResponseAsync(ct, this, userRoles, log, userId);
return await AyaNova.DataList.DataListFetcher.GetIdListResponseAsync(ct, d, DataList, userRoles, log, userId);
}
}
}