ChartWindow: Rework varibute selection
This commit is contained in:
@ -35,9 +35,9 @@ namespace Elwig.Windows {
|
||||
private Text TooltipPlot;
|
||||
private LegendItem UngebundenLegend;
|
||||
private LegendItem GebundenLegend;
|
||||
private LegendItem LDWLegend;
|
||||
private LegendItem QUWLegend;
|
||||
private LegendItem KABLegend;
|
||||
private LegendItem LdwLegend;
|
||||
private LegendItem QuwLegend;
|
||||
private LegendItem KabLegend;
|
||||
|
||||
private (Graph? Graph, int Index) LastHighlighted = (null, -1);
|
||||
private (Graph? Graph, int Index) Highlighted = (null, -1);
|
||||
@ -50,6 +50,9 @@ namespace Elwig.Windows {
|
||||
|
||||
private List<GraphEntry> GraphEntries = [];
|
||||
private GraphEntry? SelectedGraphEntry => (GraphEntry)GraphList.SelectedItem;
|
||||
private List<Varibute> Vaributes = [];
|
||||
private bool AllVaributesAssigned => Vaributes.All(v => v.AssignedGraphId != null);
|
||||
private bool AllVaributesAssignedAbgew => Vaributes.All(v => v.AssignedAbgewGraphId != null);
|
||||
|
||||
public ChartWindow(int year, int avnr) {
|
||||
InitializeComponent();
|
||||
@ -88,12 +91,22 @@ namespace Elwig.Windows {
|
||||
var paymentEntries = data.GetPaymentGraphEntries(Context, Season);
|
||||
GraphEntries = [
|
||||
..paymentEntries,
|
||||
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Max(e => e.Id))
|
||||
..data.GetQualityGraphEntries(Context, Season, paymentEntries.Any() ? paymentEntries.Max(e => e.Id) : 0)
|
||||
];
|
||||
Vaributes = Utils.GetVaributeList(Context, Year);
|
||||
GraphEntries.ForEach(e => {
|
||||
e.Vaributes.ForEach(v => {
|
||||
var found = Vaributes.Find(a => a.Attribute?.AttrId == v.Attribute?.AttrId && a.Variety?.SortId == v.Variety?.SortId);
|
||||
if (e.Abgewertet) {
|
||||
found!.AssignedAbgewGraphId = e.Id;
|
||||
} else {
|
||||
found!.AssignedGraphId = e.Id;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var vaributes = Utils.GetVaributesForYear(Context, Year);
|
||||
FillingInputs = true;
|
||||
ControlUtils.RenewItemsSource(VaributeInput, vaributes, g => (g as Varibute)?.Listing);
|
||||
ControlUtils.RenewItemsSource(VaributeInput, Vaributes, v => (v as Varibute)?.Listing);
|
||||
FillingInputs = false;
|
||||
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.VaributeStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||
|
||||
@ -174,21 +187,21 @@ namespace Elwig.Windows {
|
||||
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorGebunden)
|
||||
};
|
||||
|
||||
LDWLegend = new LegendItem() {
|
||||
LdwLegend = new LegendItem() {
|
||||
Label = "68 °Oe (LDW)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Red,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
QUWLegend = new LegendItem() {
|
||||
QuwLegend = new LegendItem() {
|
||||
Label = "73 °Oe (QUW)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Orange,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
KABLegend = new LegendItem() {
|
||||
KabLegend = new LegendItem() {
|
||||
Label = "84 °Oe (KAB)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Green,
|
||||
@ -372,9 +385,9 @@ namespace Elwig.Windows {
|
||||
OechslePricePlot.Plot.Legend.Location = Alignment.UpperLeft;
|
||||
OechslePricePlot.Plot.Legend.IsVisible = true;
|
||||
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(LDWLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(QUWLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(KABLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(LdwLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(QuwLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(KabLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(UngebundenLegend);
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) OechslePricePlot.Plot.Legend.ManualItems.Add(GebundenLegend);
|
||||
}
|
||||
@ -635,7 +648,8 @@ namespace Elwig.Windows {
|
||||
|
||||
private async void SaveButton_Click(object sender, RoutedEventArgs e) {
|
||||
var origData = BillingData.FromJson(PaymentVar.Data);
|
||||
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetVaributes(Context, Year, withSlash: true));
|
||||
var data = BillingData.FromGraphEntries(GraphEntries, origData, Utils.GetVaributes(Context, Year, withSlash: true),
|
||||
AllVaributesAssigned, AllVaributesAssignedAbgew);
|
||||
|
||||
EntityEntry<PaymentVar>? tr = null;
|
||||
try {
|
||||
@ -716,20 +730,33 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void VaributeInput_Changed(object sender, ItemSelectionChangedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
if (e.IsSelected == true) {
|
||||
bool success = RemoveVaributeFromOtherGraphEntries(e.Item.ToString());
|
||||
if (!success) {
|
||||
if (FillingInputs || e.Item is not Varibute v) return;
|
||||
var isOpen = VaributeInput.IsDropDownOpen;
|
||||
if (e.IsSelected) {
|
||||
if (RemoveVaributeFromOthers(e.Item.ToString())) {
|
||||
if (AbgewertetInput.IsChecked == true) {
|
||||
v.AssignedAbgewGraphId = SelectedGraphEntry?.Id;
|
||||
} else {
|
||||
v.AssignedGraphId = SelectedGraphEntry?.Id;
|
||||
}
|
||||
} else {
|
||||
VaributeInput.SelectedItems.Remove(e.Item);
|
||||
}
|
||||
} else {
|
||||
if (AbgewertetInput.IsChecked == true) {
|
||||
v.AssignedAbgewGraphId = null;
|
||||
} else {
|
||||
v.AssignedGraphId = null;
|
||||
}
|
||||
}
|
||||
var r = VaributeInput.SelectedItems.Cast<Varibute>();
|
||||
SelectedGraphEntry!.Vaributes = r.ToList();
|
||||
SelectedGraphEntry!.Vaributes = VaributeInput.SelectedItems.Cast<Varibute>().ToList();
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
VaributeInput.Items.Refresh();
|
||||
VaributeInput.IsDropDownOpen = isOpen;
|
||||
}
|
||||
|
||||
private bool RemoveVaributeFromOtherGraphEntries(string? varibute) {
|
||||
private bool RemoveVaributeFromOthers(string? varibute) {
|
||||
if (varibute == null) return true;
|
||||
foreach (var ge in GraphEntries) {
|
||||
if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) {
|
||||
|
Reference in New Issue
Block a user