|
@@ -29,29 +29,13 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
public class DynamicDataGrid<TEntity> : DynamicGrid<TEntity>, IDynamicDataGrid where TEntity : Entity, IRemotable, IPersistent, new()
|
|
|
{
|
|
|
- public delegate bool FilterSelectedHandler(CoreFilterDefinition filter);
|
|
|
-
|
|
|
- public event FilterSelectedHandler OnFilterSelected;
|
|
|
|
|
|
public delegate void OnReloadEventHandler(object sender, Filters<TEntity> criteria, Columns<TEntity> columns, ref SortOrder<TEntity>? sortby);
|
|
|
|
|
|
private readonly int ChunkSize = 500;
|
|
|
- private Button MergeBtn;
|
|
|
- private Button FilterBtn;
|
|
|
-
|
|
|
- private bool _showFilterList;
|
|
|
- public bool ShowFilterList
|
|
|
- {
|
|
|
- get => _showFilterList;
|
|
|
- set
|
|
|
- {
|
|
|
- _showFilterList = value;
|
|
|
- if (FilterBtn != null) // FilterBtn can be null when ShowFilterList is set in DynamicGrid constructor
|
|
|
- FilterBtn.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
|
|
|
- }
|
|
|
- }
|
|
|
+ private Button MergeBtn = null!; //Late-initialised
|
|
|
|
|
|
- protected Tuple<string, Filter<TEntity>>? SelectedFilter;
|
|
|
+ protected DynamicGridFilterButtonComponent<TEntity> FilterComponent;
|
|
|
|
|
|
private Column<TEntity>[] FilterColumns;
|
|
|
|
|
@@ -90,16 +74,13 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
protected override void Init()
|
|
|
{
|
|
|
- FilterBtn = AddButton("", Wpf.Resources.filter.AsBitmapImage(), DoFilter);
|
|
|
- FilterBtn.Margin = new Thickness(0, 2, 7, 0);
|
|
|
- FilterBtn.Padding = new Thickness(0);
|
|
|
+ FilterComponent = new(this, new GlobalConfiguration<CoreFilterDefinitions>(GetTag()));
|
|
|
+ FilterComponent.OnFilterRefresh += () => Refresh(false, true);
|
|
|
|
|
|
MergeBtn = AddButton("Merge", Wpf.Resources.merge.AsBitmapImage(Color.White), DoMerge);
|
|
|
}
|
|
|
protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
|
{
|
|
|
- FilterBtn.Visibility = ShowFilterList ? Visibility.Visible : Visibility.Collapsed;
|
|
|
-
|
|
|
options.BeginUpdate();
|
|
|
if (Security.CanEdit<TEntity>())
|
|
|
options.Add(DynamicGridOption.AddRows).Add(DynamicGridOption.EditRows);
|
|
@@ -153,7 +134,8 @@ namespace InABox.DynamicGrid
|
|
|
base.OptionsChanged();
|
|
|
if (MergeBtn != null)
|
|
|
MergeBtn.Visibility = Visibility.Collapsed;
|
|
|
- ShowFilterList = HasOption(DynamicGridOption.FilterRows);
|
|
|
+
|
|
|
+ FilterComponent.ShowFilterList = HasOption(DynamicGridOption.FilterRows);
|
|
|
}
|
|
|
|
|
|
protected override void SelectItems(CoreRow[]? rows)
|
|
@@ -163,64 +145,13 @@ namespace InABox.DynamicGrid
|
|
|
? Visibility.Visible
|
|
|
: Visibility.Collapsed;
|
|
|
}
|
|
|
-
|
|
|
- /*private Filter<T>? CreateFilter<T>(Dictionary<string, object> criteria) where T : Entity
|
|
|
- {
|
|
|
- Filter<T>? filter = null;
|
|
|
- foreach (var key in criteria.Keys)
|
|
|
- {
|
|
|
- var exp = CoreUtils.GetPropertyExpression<T>(key);
|
|
|
- var flt = new Filter<T>(exp).IsEqualTo(criteria[key]);
|
|
|
- if (filter != null)
|
|
|
- filter.Ands.Add(flt);
|
|
|
- else
|
|
|
- filter = flt;
|
|
|
- }
|
|
|
-
|
|
|
- return filter;
|
|
|
- }
|
|
|
-
|
|
|
- private Columns<T> CreateColumns<T>(List<string> columnnames) where T : Entity
|
|
|
- {
|
|
|
- var expressions = new List<Expression<Func<T, object?>>>();
|
|
|
- foreach (var columnname in columnnames)
|
|
|
- try
|
|
|
- {
|
|
|
- var expression = CoreUtils.GetPropertyExpression<T>(columnname);
|
|
|
- expressions.Add(expression);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
|
|
|
- }
|
|
|
-
|
|
|
- if (!columnnames.Contains("ID"))
|
|
|
- expressions.Add(CoreUtils.GetPropertyExpression<T>("ID"));
|
|
|
-
|
|
|
- //if (!columnnames.Contains("Attributes"))
|
|
|
- // expressions.Add(CoreUtils.GetPropertyExpression<T>("Attributes"));
|
|
|
-
|
|
|
- return new Columns<T>(expressions.ToArray());
|
|
|
- }
|
|
|
-
|
|
|
- private SortOrder<T>? CreateSortOrder<T>(string columnname) where T : Entity
|
|
|
- {
|
|
|
- if (string.IsNullOrWhiteSpace(columnname))
|
|
|
- return null;
|
|
|
-
|
|
|
- var expression = CoreUtils.GetPropertyExpression<T>(columnname);
|
|
|
- return new SortOrder<T>(expression);
|
|
|
- }*/
|
|
|
-
|
|
|
+
|
|
|
public event OnReloadEventHandler? OnReload;
|
|
|
|
|
|
protected override void Reload(Filters<TEntity> criteria, Columns<TEntity> columns, ref SortOrder<TEntity>? sort,
|
|
|
Action<CoreTable?, Exception?> action)
|
|
|
{
|
|
|
- //if (sort == null)
|
|
|
- // sort = new SortOrder<TEntity>(x => x.Sort);
|
|
|
- if (SelectedFilter != null)
|
|
|
- criteria.Add(SelectedFilter.Item2);
|
|
|
+ criteria.Add(FilterComponent.GetFilter());
|
|
|
|
|
|
OnReload?.Invoke(this, criteria, columns, ref sort);
|
|
|
new Client<TEntity>().Query(criteria.Combine(), columns, sort, action);
|
|
@@ -695,94 +626,6 @@ namespace InABox.DynamicGrid
|
|
|
return grid.EditItems(new[] { item }, t => children.ContainsKey(t) ? children[t] : null, true);
|
|
|
}
|
|
|
|
|
|
- private bool DoFilter(Button button, CoreRow[] rows)
|
|
|
- {
|
|
|
- var menu = new ContextMenu();
|
|
|
- var none = new MenuItem { Header = "Clear Filters", Tag = null };
|
|
|
- none.Click += Filter_Click;
|
|
|
- menu.Items.Add(none);
|
|
|
-
|
|
|
- var tag = GetTag();
|
|
|
- var filters = new GlobalConfiguration<CoreFilterDefinitions>(tag).Load();
|
|
|
- foreach (var filter in filters)
|
|
|
- {
|
|
|
- var item = new MenuItem { Header = filter.Name, Tag = filter };
|
|
|
- if (SelectedFilter?.Item1 == filter.Name)
|
|
|
- {
|
|
|
- item.IsChecked = true;
|
|
|
- }
|
|
|
- item.Click += Filter_Click;
|
|
|
- menu.Items.Add(item);
|
|
|
- }
|
|
|
-
|
|
|
- if (Security.IsAllowed<CanCustomiseFilters>())
|
|
|
- {
|
|
|
- menu.Items.Add(new Separator());
|
|
|
- var manage = new MenuItem { Header = "Manage Filters" };
|
|
|
- manage.Click += (s, e) =>
|
|
|
- {
|
|
|
- var window = new DynamicGridFilterEditor(filters, typeof(TEntity));
|
|
|
- if (window.ShowDialog() == true)
|
|
|
- {
|
|
|
- new GlobalConfiguration<CoreFilterDefinitions>(tag).Save(filters);
|
|
|
- }
|
|
|
- };
|
|
|
- menu.Items.Add(manage);
|
|
|
- }
|
|
|
-
|
|
|
- menu.IsOpen = true;
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- protected virtual void FilterSelected(CoreFilterDefinition filter)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void DoFilterSelected(CoreFilterDefinition filter)
|
|
|
- {
|
|
|
- FilterSelected(filter);
|
|
|
- OnFilterSelected?.Invoke(filter);
|
|
|
- }
|
|
|
-
|
|
|
- public void SelectFilter(CoreFilterDefinition? filter, bool refresh)
|
|
|
- {
|
|
|
- SelectedFilter = filter != null
|
|
|
- ? new(filter.Name, Serialization.Deserialize<Filter<TEntity>>(filter.Filter))
|
|
|
- : null;
|
|
|
- Bitmap image = SelectedFilter != null
|
|
|
- ? Wpf.Resources.filter_set
|
|
|
- : Wpf.Resources.filter;
|
|
|
- String text = SelectedFilter?.Item1 ?? "";
|
|
|
- UpdateButton(FilterBtn, image.AsBitmapImage(), text);
|
|
|
- if (refresh)
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
-
|
|
|
- private void Filter_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- var tag = (sender as MenuItem)?.Tag;
|
|
|
- string text = "";
|
|
|
- Bitmap image;
|
|
|
- if (tag is CoreFilterDefinition filter)
|
|
|
- {
|
|
|
- SelectedFilter = new(filter.Name, Serialization.Deserialize<Filter<TEntity>>(filter.Filter));
|
|
|
- image = Wpf.Resources.filter_set;
|
|
|
- text = filter.Name;
|
|
|
- DoFilterSelected(filter);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- SelectedFilter = null;
|
|
|
- image = Wpf.Resources.filter;
|
|
|
- text = "";
|
|
|
- DoFilterSelected(null);
|
|
|
- }
|
|
|
- UpdateButton(FilterBtn, image.AsBitmapImage(), text);
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
-
|
|
|
private bool DoMerge(Button arg1, CoreRow[] arg2)
|
|
|
{
|
|
|
if (arg2 == null || arg2.Length <= 1)
|
|
@@ -973,20 +816,6 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
return new Client<TEntity>().Query(null, new Columns<TEntity>(fields));
|
|
|
}
|
|
|
-
|
|
|
- public void UpdateFilterButton(Bitmap image, string text = "")
|
|
|
- {
|
|
|
- UpdateButton(FilterBtn, image.AsBitmapImage(), text);
|
|
|
- }
|
|
|
-
|
|
|
- public void UpdateFilterButton(string text)
|
|
|
- {
|
|
|
- UpdateFilterButton(String.IsNullOrWhiteSpace(text)
|
|
|
- ? Wpf.Resources.filter_set
|
|
|
- : Wpf.Resources.filter,
|
|
|
- text
|
|
|
- );
|
|
|
- }
|
|
|
|
|
|
}
|
|
|
}
|