123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using InABox.DynamicGrid;
- using InABox.WPF;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- namespace InABox.Wpf.Dashboard;
- public class DynamicDashboardGridPresenterEditor : IDynamicDashboardDataPresenterEditor<DynamicDashboardGridPresenter, DynamicDashboardGridPresenterProperties>
- {
- private DynamicDashboardDataComponent _dataComponent = null!;
- public DynamicDashboardDataComponent DataComponent
- {
- get => _dataComponent;
- set
- {
- _dataComponent = value;
- QueryBox.ItemsSource = DataComponent.Queries.Select(x => x.Key);
- if(!DataComponent.TryGetQuery(Properties.Query, out var _query))
- {
- Properties.Query = DataComponent.Queries.FirstOrDefault()?.Key ?? "";
- }
- QueryBox.SelectedValue = Properties.Query;
- }
- }
- public DynamicDashboardGridPresenterProperties Properties { get; set; } = null!;
- private ContentControl Content = new();
- private ComboBox QueryBox = new();
- public FrameworkElement? Setup()
- {
- UpdateData();
- var grid = new Grid();
- grid.AddRow(GridUnitType.Auto);
- grid.AddRow(GridUnitType.Star);
- var dock = new DockPanel
- {
- LastChildFill = false
- };
- var label = new Label
- {
- Content = "Query:",
- VerticalAlignment = VerticalAlignment.Center,
- };
- DockPanel.SetDock(label, Dock.Left);
- QueryBox.Padding = new(5);
- QueryBox.MinWidth = 100;
- QueryBox.SelectionChanged += QueryBox_SelectionChanged;
- DockPanel.SetDock(QueryBox, Dock.Left);
- dock.Children.Add(label);
- dock.Children.Add(QueryBox);
- Content.Margin = new(0, 5, 0, 0);
- grid.AddChild(dock, 0, 0);
- grid.AddChild(Content, 1, 0);
- Content.Height = 100;
- return grid;
- }
- private void QueryBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- Properties.Query = QueryBox.SelectedValue as string ?? "";
- UpdateData();
- }
- private void UpdateData()
- {
- if (!DataComponent.TryGetQuery(Properties.Query, out var query)) return;
- var grid = (Activator.CreateInstance(typeof(DynamicItemsListGrid<>).MakeGenericType(query.Type)) as IDynamicGrid)!;
- grid.Reconfigure(options =>
- {
- options.Clear();
- options.SelectColumns = true;
- });
- grid.OnGenerateColumns += (o, e) =>
- {
- e.Columns.Clear();
- if(Properties.Columns is null)
- {
- e.Columns.AddRange(grid.ExtractColumns(query.Columns));
- }
- else
- {
- e.Columns.AddRange(Properties.Columns);
- }
- };
- grid.OnSaveColumns += (o, e) =>
- {
- Properties.Columns = grid.VisibleColumns;
- };
- grid.Refresh(true, true);
- Content.Content = grid;
- }
- }
|