|
@@ -19,7 +19,7 @@ public class DynamicDashboardGridPresenterProperties : BaseObject
|
|
|
/// <summary>
|
|
|
/// The key of the query that will provide the data for this presenter.
|
|
|
/// </summary>
|
|
|
- public string Query { get; set; } = "";
|
|
|
+ public string Table { get; set; } = "";
|
|
|
|
|
|
public DynamicGridColumns? Columns { get; set; }
|
|
|
}
|
|
@@ -44,7 +44,7 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
|
|
|
public bool IsPreview { get; set; }
|
|
|
|
|
|
- private IDynamicDashboardGridPresenterGrid? Grid;
|
|
|
+ private CoreTableGrid? Grid;
|
|
|
private readonly ContentControl Content = new();
|
|
|
|
|
|
private DynamicDashboardData? _data;
|
|
@@ -57,12 +57,12 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
|
|
|
private void UpdateData()
|
|
|
{
|
|
|
- if (Properties.Query.IsNullOrWhiteSpace() || !DataComponent.TryGetQuery(Properties.Query, out var query))
|
|
|
+ if (Properties.Table.IsNullOrWhiteSpace() || !DataComponent.TryGetTable(Properties.Table, out var table))
|
|
|
{
|
|
|
- Properties.Query = DataComponent.Queries.FirstOrDefault()?.Key ?? "";
|
|
|
+ Properties.Table = DataComponent.Tables.FirstOrDefault()?.Key ?? "";
|
|
|
}
|
|
|
|
|
|
- if (!DataComponent.TryGetQuery(Properties.Query, out query))
|
|
|
+ if (!DataComponent.TryGetTable(Properties.Table, out table))
|
|
|
{
|
|
|
var border = new Border
|
|
|
{
|
|
@@ -73,12 +73,10 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- Grid = (Activator.CreateInstance(typeof(DynamicDashboardGridPresenterGrid<>).MakeGenericType(query.Type)) as IDynamicDashboardGridPresenterGrid)!;
|
|
|
- Grid.OnGenerateColumns += Grid_OnGenerateColumns;
|
|
|
- Grid.OnSaveColumns += Grid_OnSaveColumns;
|
|
|
- Grid.GetAvailableColumns += Grid_GetAvailableColumns;
|
|
|
- Grid.OnLoadColumnsMenu += Grid_OnLoadColumnsMenu;
|
|
|
-
|
|
|
+ Grid = new DataGrid(this)
|
|
|
+ {
|
|
|
+ ColumnSchema = new DataGridColumnSchema(this)
|
|
|
+ };
|
|
|
Grid.Refresh(true, false);
|
|
|
|
|
|
Content.Content = Grid as FrameworkElement;
|
|
@@ -88,13 +86,14 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
{
|
|
|
if (!IsPreview) return;
|
|
|
|
|
|
- if(DataComponent.Queries.Count > 1)
|
|
|
+ var tableItem = menu.AddItem("Select Table", null, null);
|
|
|
+ foreach(var table in DataComponent.Tables)
|
|
|
{
|
|
|
- var queryItem = menu.AddItem("Select Query", null, null);
|
|
|
- foreach(var query in DataComponent.Queries)
|
|
|
- {
|
|
|
- queryItem.AddCheckMenuItem(query.Key, query.Key, SelectQuery_Click, isChecked: Properties.Query == query.Key);
|
|
|
- }
|
|
|
+ tableItem.AddCheckMenuItem(table.Key, table.Key, SelectTable_Click, isChecked: Properties.Table == table.Key);
|
|
|
+ }
|
|
|
+ if(tableItem.Items.Count <= 1)
|
|
|
+ {
|
|
|
+ menu.Items.Remove(tableItem);
|
|
|
}
|
|
|
menu.AddItem("Select Data", null, SelectData_Click);
|
|
|
}
|
|
@@ -118,11 +117,11 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void SelectQuery_Click(string key, bool isChecked)
|
|
|
+ private void SelectTable_Click(string key, bool isChecked)
|
|
|
{
|
|
|
if (!isChecked) return;
|
|
|
|
|
|
- Properties.Query = key;
|
|
|
+ Properties.Table = key;
|
|
|
Properties.Columns = null;
|
|
|
|
|
|
UpdateData();
|
|
@@ -132,22 +131,6 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void Grid_OnLoadColumnsMenu(ContextMenu menu)
|
|
|
- {
|
|
|
- menu.AddSeparatorIfNeeded();
|
|
|
- CustomiseMenu(menu);
|
|
|
- menu.RemoveUnnecessarySeparators();
|
|
|
- }
|
|
|
-
|
|
|
- private void Grid_GetAvailableColumns(GetAvailableColumnsEventArgs args)
|
|
|
- {
|
|
|
- if (!DataComponent.TryGetQuery(Properties.Query, out var query))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- args.Columns = args.Columns.Where(x => query.Columns.Contains(x.ColumnName));
|
|
|
- }
|
|
|
-
|
|
|
private void Border_ContextMenuOpening(object sender, ContextMenuEventArgs e)
|
|
|
{
|
|
|
var menu = new ContextMenu();
|
|
@@ -159,48 +142,22 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
e.Handled = true;
|
|
|
}
|
|
|
|
|
|
- private void Grid_OnSaveColumns(object sender, SaveColumnsEventArgs args)
|
|
|
- {
|
|
|
- Properties.Columns = args.Columns.Count > 0 ? args.Columns : null;
|
|
|
- }
|
|
|
-
|
|
|
- private void Grid_OnGenerateColumns(object sender, GenerateColumnsEventArgs args)
|
|
|
- {
|
|
|
- if(Properties.Columns is not null)
|
|
|
- {
|
|
|
- args.Columns.Clear();
|
|
|
- foreach(var column in Properties.Columns)
|
|
|
- {
|
|
|
- args.Columns.Add(column.Copy());
|
|
|
- }
|
|
|
- }
|
|
|
- else if (DataComponent.TryGetQuery(Properties.Query, out var query) && Grid is not null)
|
|
|
- {
|
|
|
- args.Columns.Clear();
|
|
|
- args.Columns.AddRange(Grid.ExtractColumns(query.Columns));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public void Refresh(DynamicDashboardData data)
|
|
|
{
|
|
|
_data = data;
|
|
|
|
|
|
- if (!DataComponent.TryGetQuery(Properties.Query, out var query) || Grid is null)
|
|
|
+ if (!DataComponent.TryGetTable(Properties.Table, out var _table) || Grid is null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(data.TryGetData(Properties.Query, out var table))
|
|
|
+ if(data.TryGetData(Properties.Table, out var table))
|
|
|
{
|
|
|
- Grid.Items.Clear();
|
|
|
- foreach(var obj in table.ToObjects(query.Type))
|
|
|
- {
|
|
|
- Grid.Items.Add(obj);
|
|
|
- }
|
|
|
+ Grid.Table = table;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Grid.Items.Clear();
|
|
|
+ Grid.Table.Rows.Clear();
|
|
|
}
|
|
|
Grid.Refresh(false, true);
|
|
|
}
|
|
@@ -208,28 +165,81 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
|
|
|
public void Shutdown(CancelEventArgs? cancel)
|
|
|
{
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-internal interface IDynamicDashboardGridPresenterGrid : IDynamicItemsListGrid
|
|
|
-{
|
|
|
- public event Action<ContextMenu>? OnLoadColumnsMenu;
|
|
|
-}
|
|
|
-internal class DynamicDashboardGridPresenterGrid<T> : DynamicItemsListGrid<T>, IDynamicDashboardGridPresenterGrid
|
|
|
- where T : BaseObject, new()
|
|
|
-{
|
|
|
- public event Action<ContextMenu>? OnLoadColumnsMenu;
|
|
|
|
|
|
- protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
+ private class DataGridColumnSchema(DynamicDashboardGridPresenter presenter) : IDynamicGridColumnSchema
|
|
|
{
|
|
|
- base.DoReconfigure(options);
|
|
|
+ public IEnumerable<string> ColumnNames
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ if (presenter.DataComponent.TryGetTable(presenter.Properties.Table, out var table))
|
|
|
+ {
|
|
|
+ return table.CoreColumns.Where(x => EditorUtils.GetEditor(x.DataType) is not null).Select(x => x.ColumnName);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- options.Clear();
|
|
|
- options.SelectColumns = true;
|
|
|
+ public DynamicGridColumn GetColumn(string column)
|
|
|
+ {
|
|
|
+ var table = presenter.DataComponent.GetTable(presenter.Properties.Table);
|
|
|
+ var coreCol = table.CoreColumns.First(x => x.ColumnName == column);
|
|
|
+ return DynamicGridColumn.FromCoreColumn(coreCol)!;
|
|
|
+ }
|
|
|
+
|
|
|
+ public string? GetComment(string column)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsVisible(string column)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- protected override void LoadColumnsMenu(ContextMenu menu)
|
|
|
+ private class DataGrid(DynamicDashboardGridPresenter presenter) : CoreTableGrid
|
|
|
{
|
|
|
- base.LoadColumnsMenu(menu);
|
|
|
- OnLoadColumnsMenu?.Invoke(menu);
|
|
|
+ protected override void DoReconfigure(DynamicGridOptions options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
+ options.SelectColumns = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public override DynamicGridColumns GenerateColumns()
|
|
|
+ {
|
|
|
+ if(presenter.Properties.Columns is not null)
|
|
|
+ {
|
|
|
+ var columns = new DynamicGridColumns();
|
|
|
+ columns.AddRange(presenter.Properties.Columns.Select(x => x.Copy()));
|
|
|
+ return columns;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return base.GenerateColumns();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void LoadColumnsMenu(ContextMenu menu)
|
|
|
+ {
|
|
|
+ base.LoadColumnsMenu(menu);
|
|
|
+ menu.AddSeparatorIfNeeded();
|
|
|
+ presenter.CustomiseMenu(menu);
|
|
|
+ menu.RemoveUnnecessarySeparators();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void SaveColumns(DynamicGridColumns columns)
|
|
|
+ {
|
|
|
+ base.SaveColumns(columns);
|
|
|
+ presenter.Properties.Columns = columns.Count > 0 ? columns : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override DynamicGridColumns LoadColumns()
|
|
|
+ {
|
|
|
+ return presenter.Properties.Columns ?? base.LoadColumns();
|
|
|
+ }
|
|
|
}
|
|
|
}
|