88 lines
4.5 KiB
C#
88 lines
4.5 KiB
C#
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
|
|
//either a preselected list of id's or a datalist key and listview filter object that can
|
|
//be used to rehydrate a list of id's
|
|
public class DataListSelectedProcessingOptions : DataListProcessingBase
|
|
{
|
|
//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
|
|
|
|
internal DataListSelectedProcessingOptions(
|
|
DataListSelectedRequest request,
|
|
IDataListProcessing dataList,
|
|
DataListColumnView savedView,
|
|
DataListSavedFilter savedFilter,
|
|
long userId,
|
|
AuthorizationRoles userRoles)
|
|
{
|
|
//set some values from request
|
|
base.ClientCriteria = request.ClientCriteria;
|
|
base.DataListKey = request.DataListKey;
|
|
|
|
//SET SORTBY
|
|
base.SortBy = JsonConvert.DeserializeObject<Dictionary<string, string>>(savedView.Sort);
|
|
|
|
//SET FILTER
|
|
if (request.FilterId != 0 && savedFilter != null)
|
|
base.Filter = JsonConvert.DeserializeObject<List<DataListFilterOption>>(savedFilter.Filter);
|
|
|
|
//ADD STATIC SERVER FILTERS
|
|
List<DataListFilterOption> StaticServerFilterOptions = new List<DataListFilterOption>();
|
|
if (dataList is IDataListInternalCriteria)
|
|
StaticServerFilterOptions = ((IDataListInternalCriteria)dataList).DataListInternalCriteria(userId, userRoles, request.ClientCriteria);
|
|
|
|
//Add the internal filters into the listoptions existing filters
|
|
//NOTE: There is currently no overlap between internal filtered columns and filters coming from the client
|
|
foreach (DataListFilterOption dfo in StaticServerFilterOptions)
|
|
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)
|
|
{
|
|
DataListColumnViewBiz viewbiz = new DataListColumnViewBiz(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);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|