|
@@ -33,16 +33,31 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private bool _onlyVisible;
|
|
|
|
+ public bool OnlyVisible
|
|
|
|
+ {
|
|
|
|
+ get => _onlyVisible;
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ _onlyVisible = value;
|
|
|
|
+ Refresh(false, true);
|
|
|
|
+ DoPropertyChanged();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private List<DynamicGridColumnNameSelectorItem> _items;
|
|
private List<DynamicGridColumnNameSelectorItem> _items;
|
|
|
|
|
|
public string SearchText { get; set; }
|
|
public string SearchText { get; set; }
|
|
|
|
|
|
public DynamicGridColumnNameSelectorGrid(Type type, IEnumerable<string> columnNames)
|
|
public DynamicGridColumnNameSelectorGrid(Type type, IEnumerable<string> columnNames)
|
|
{
|
|
{
|
|
|
|
+ var itemMap = new Dictionary<string, DynamicGridColumnNameSelectorItem>();
|
|
var items = new List<DynamicGridColumnNameSelectorItem>();
|
|
var items = new List<DynamicGridColumnNameSelectorItem>();
|
|
- var parentCols = new HashSet<string>();
|
|
|
|
|
|
+ var parentCols = new Dictionary<string, List<DynamicGridColumnNameSelectorItem>>();
|
|
foreach (var column in columnNames)
|
|
foreach (var column in columnNames)
|
|
{
|
|
{
|
|
|
|
+ var item = new DynamicGridColumnNameSelectorItem();
|
|
|
|
+
|
|
var props = column.Split('.');
|
|
var props = column.Split('.');
|
|
string? parent = null;
|
|
string? parent = null;
|
|
for (int i = 0; i < props.Length - 1; ++i)
|
|
for (int i = 0; i < props.Length - 1; ++i)
|
|
@@ -55,28 +70,30 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
|
|
{
|
|
{
|
|
parent = $"{parent}.{props[i]}";
|
|
parent = $"{parent}.{props[i]}";
|
|
}
|
|
}
|
|
- parentCols.Add(parent);
|
|
|
|
|
|
+ parentCols.GetValueOrAdd(parent).Add(item);
|
|
}
|
|
}
|
|
|
|
|
|
- var item = new DynamicGridColumnNameSelectorItem
|
|
|
|
- {
|
|
|
|
- ColumnName = column,
|
|
|
|
- ParentColumn = parent,
|
|
|
|
- Display = props[^1],
|
|
|
|
- IsParent = false,
|
|
|
|
- Comment = DatabaseSchema.Property(type, column)?.Comment ?? ""
|
|
|
|
- };
|
|
|
|
|
|
+ var prop = DatabaseSchema.Property(type, column);
|
|
|
|
+ item.ColumnName = column;
|
|
|
|
+ item.ParentColumn = parent;
|
|
|
|
+ item.Display = props[^1];
|
|
|
|
+ item.IsParent = false;
|
|
|
|
+ item.Comment = prop?.Comment ?? "";
|
|
|
|
+ item.IsVisible = (prop?.Editor.Visible ?? Visible.Optional) != Visible.Hidden;
|
|
items.Add(item);
|
|
items.Add(item);
|
|
}
|
|
}
|
|
|
|
|
|
- foreach (var col in parentCols)
|
|
|
|
|
|
+ foreach (var (col, children) in parentCols)
|
|
{
|
|
{
|
|
|
|
+ var prop = DatabaseSchema.Property(type, col);
|
|
|
|
+
|
|
var lastColIdx = col.LastIndexOf('.');
|
|
var lastColIdx = col.LastIndexOf('.');
|
|
var item = new DynamicGridColumnNameSelectorItem
|
|
var item = new DynamicGridColumnNameSelectorItem
|
|
{
|
|
{
|
|
ColumnName = col,
|
|
ColumnName = col,
|
|
IsParent = true,
|
|
IsParent = true,
|
|
- Comment = DatabaseSchema.Property(type, col)?.Comment ?? ""
|
|
|
|
|
|
+ Comment = prop?.Comment ?? "",
|
|
|
|
+ IsVisible = children.Any(x => x.IsVisible)
|
|
};
|
|
};
|
|
if (lastColIdx == -1)
|
|
if (lastColIdx == -1)
|
|
{
|
|
{
|
|
@@ -198,7 +215,7 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
|
|
{
|
|
{
|
|
if (SearchText.IsNullOrWhiteSpace())
|
|
if (SearchText.IsNullOrWhiteSpace())
|
|
{
|
|
{
|
|
- Items = _items;
|
|
|
|
|
|
+ Items = _items.ToList();
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -219,14 +236,19 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (OnlyVisible)
|
|
|
|
+ {
|
|
|
|
+ Items.RemoveAll(x => !x.IsVisible);
|
|
|
|
+ }
|
|
|
|
|
|
base.Reload(criteria, columns, ref sort, token, action);
|
|
base.Reload(criteria, columns, ref sort, token, action);
|
|
}
|
|
}
|
|
|
|
|
|
- public static bool SelectColumnName(Type type, IEnumerable<string> columnNames, out string value)
|
|
|
|
|
|
+ public static bool SelectColumnName(Type type, IEnumerable<string> columnNames, out string value, bool showVisibilityButton = false)
|
|
{
|
|
{
|
|
var grid = new DynamicGridColumnNameSelectorGrid(type, columnNames)
|
|
var grid = new DynamicGridColumnNameSelectorGrid(type, columnNames)
|
|
{
|
|
{
|
|
|
|
+ OnlyVisible = showVisibilityButton
|
|
};
|
|
};
|
|
grid.Refresh(true, true);
|
|
grid.Refresh(true, true);
|
|
|
|
|
|
@@ -249,16 +271,33 @@ public class DynamicGridColumnNameSelectorGrid : DynamicItemsListGrid<DynamicGri
|
|
grid.Refresh(false, true);
|
|
grid.Refresh(false, true);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ var onlyVisible = new CheckBox()
|
|
|
|
+ {
|
|
|
|
+ Content = "Only Visible?",
|
|
|
|
+ VerticalAlignment = VerticalAlignment.Center,
|
|
|
|
+ Margin = new(5, 0, 0, 5)
|
|
|
|
+ };
|
|
|
|
+ onlyVisible.Bind(CheckBox.IsCheckedProperty, grid, x => x.OnlyVisible);
|
|
|
|
+
|
|
var control = new Grid();
|
|
var control = new Grid();
|
|
control.AddColumn(GridUnitType.Auto);
|
|
control.AddColumn(GridUnitType.Auto);
|
|
control.AddColumn(GridUnitType.Star);
|
|
control.AddColumn(GridUnitType.Star);
|
|
|
|
+ if (showVisibilityButton)
|
|
|
|
+ {
|
|
|
|
+ control.AddColumn(GridUnitType.Auto);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ control.AddColumn(0);
|
|
|
|
+ }
|
|
|
|
|
|
control.AddRow(GridUnitType.Auto);
|
|
control.AddRow(GridUnitType.Auto);
|
|
control.AddRow(GridUnitType.Star);
|
|
control.AddRow(GridUnitType.Star);
|
|
|
|
|
|
control.AddChild(lbl, 0, 0);
|
|
control.AddChild(lbl, 0, 0);
|
|
control.AddChild(search, 0, 1);
|
|
control.AddChild(search, 0, 1);
|
|
- control.AddChild(grid, 1, 0, colSpan: 2);
|
|
|
|
|
|
+ control.AddChild(onlyVisible, 0, 2);
|
|
|
|
+ control.AddChild(grid, 1, 0, colSpan: 3);
|
|
|
|
|
|
var window = new DynamicContentDialog(control)
|
|
var window = new DynamicContentDialog(control)
|
|
{
|
|
{
|
|
@@ -304,5 +343,7 @@ public class DynamicGridColumnNameSelectorItem : BaseObject
|
|
|
|
|
|
public string Comment { get; set; } = "";
|
|
public string Comment { get; set; } = "";
|
|
|
|
|
|
|
|
+ public bool IsVisible { get; set; }
|
|
|
|
+
|
|
public bool IsParent { get; set; }
|
|
public bool IsParent { get; set; }
|
|
}
|
|
}
|