From 26ff51169fd5144c79921d56caa20167bc2a41fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Wed, 22 Oct 2025 10:42:39 +0200 Subject: [PATCH] Nu fungerar RoundRunningView med minimal codeBehind --- .../Specifics/HeaderColorConverter.cs | 12 ++ .../Specifics/LoadedBehavior.cs | 35 ++++++ .../HelperEntities/ScoreCell.cs | 7 ++ .../HelperEntities/ScoreColumn.cs | 9 ++ .../ViewModelClasses/RoundRunningViewModel.cs | 57 ++++++++-- .../RoundStartingViewModel.cs | 1 + GreadyPoang/GreadyPoang.csproj | 8 ++ GreadyPoang/MauiProgram.cs | 6 +- GreadyPoang/Resources/Styles/AppStyles.xaml | 5 +- GreadyPoang/Views/RoundRunningView.xaml | 47 ++++++-- GreadyPoang/Views/RoundRunningView.xaml.cs | 97 +--------------- GreadyPoang/Views/RoundRunningViewOld.xaml | 101 +++++++++++++++++ GreadyPoang/Views/RoundRunningViewOld.xaml.cs | 105 ++++++++++++++++++ 13 files changed, 374 insertions(+), 116 deletions(-) create mode 100644 GreadyPoang.Common/Specifics/HeaderColorConverter.cs create mode 100644 GreadyPoang.Common/Specifics/LoadedBehavior.cs create mode 100644 GreadyPoang.EntityLayer/HelperEntities/ScoreCell.cs create mode 100644 GreadyPoang.EntityLayer/HelperEntities/ScoreColumn.cs create mode 100644 GreadyPoang/Views/RoundRunningViewOld.xaml create mode 100644 GreadyPoang/Views/RoundRunningViewOld.xaml.cs diff --git a/GreadyPoang.Common/Specifics/HeaderColorConverter.cs b/GreadyPoang.Common/Specifics/HeaderColorConverter.cs new file mode 100644 index 0000000..e5edd6e --- /dev/null +++ b/GreadyPoang.Common/Specifics/HeaderColorConverter.cs @@ -0,0 +1,12 @@ +using System.Globalization; + +namespace GreadyPoang.Common; + +public class HeaderColorConverter : IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => + (bool)value ? Colors.DarkGray : Colors.Yellow; + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => + throw new NotImplementedException(); +} diff --git a/GreadyPoang.Common/Specifics/LoadedBehavior.cs b/GreadyPoang.Common/Specifics/LoadedBehavior.cs new file mode 100644 index 0000000..2407673 --- /dev/null +++ b/GreadyPoang.Common/Specifics/LoadedBehavior.cs @@ -0,0 +1,35 @@ +using System.Windows.Input; + +namespace GreadyPoang.Common; + +public class LoadedBehavior +{ + public static readonly BindableProperty CommandProperty = + BindableProperty.CreateAttached( + "Command", + typeof(ICommand), + typeof(LoadedBehavior), + null, + propertyChanged: OnCommandChanged); + + public static ICommand GetCommand(BindableObject view) => + (ICommand)view.GetValue(CommandProperty); + + public static void SetCommand(BindableObject view, ICommand value) => + view.SetValue(CommandProperty, value); + + private static void OnCommandChanged(BindableObject bindable, object oldValue, object newValue) + { + if (bindable is VisualElement element && newValue is ICommand command) + { + element.Loaded += (s, e) => + { + if (command.CanExecute(null)) + { + command.Execute(null); + } + }; + } + } + +} diff --git a/GreadyPoang.EntityLayer/HelperEntities/ScoreCell.cs b/GreadyPoang.EntityLayer/HelperEntities/ScoreCell.cs new file mode 100644 index 0000000..e57e1a6 --- /dev/null +++ b/GreadyPoang.EntityLayer/HelperEntities/ScoreCell.cs @@ -0,0 +1,7 @@ +namespace GreadyPoang.EntityLayer; + +public class ScoreCell +{ + public string Text { get; set; } + public bool IsHeader { get; set; } +} diff --git a/GreadyPoang.EntityLayer/HelperEntities/ScoreColumn.cs b/GreadyPoang.EntityLayer/HelperEntities/ScoreColumn.cs new file mode 100644 index 0000000..0ff85df --- /dev/null +++ b/GreadyPoang.EntityLayer/HelperEntities/ScoreColumn.cs @@ -0,0 +1,9 @@ +using System.Collections.ObjectModel; + +namespace GreadyPoang.EntityLayer; + +public class ScoreColumn +{ + public string PlayerName { get; set; } + public ObservableCollection Cells { get; set; } = new(); +} diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs index c091cfd..74b0773 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundRunningViewModel.cs @@ -7,6 +7,7 @@ using GreadyPoang.EntityLayer; using GreadyPoang.Services; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Windows.Input; namespace GreadyPoang.ViewModelLayer; @@ -14,6 +15,7 @@ public partial class RoundRunningViewModel : ObservableObject { public event EventHandler RebuildRequested; + public ICommand OnLoadedCommand { get; } public RoundRunningViewModel() : base() { @@ -41,6 +43,8 @@ public partial class RoundRunningViewModel : ObservableObject BuilderObject = new(); _popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested; PopupVisad = false; + OnLoadedCommand = new AsyncRelayCommand(OnLoadedAsync, () => true); + } private readonly IRepository? _roundsRepo; @@ -57,19 +61,20 @@ public partial class RoundRunningViewModel : ObservableObject private Collection playerColumns; [ObservableProperty] private RoundBuilderElement builderObject; + public ObservableCollection ScoreColumns { get; } = new ObservableCollection(); + + + private string _activePopupId; public bool PopupVisad { get; set; } - - public void TriggerRebuild() + private async Task OnLoadedAsync() { - // Trigga eventet - RebuildRequested?.Invoke(this, EventArgs.Empty); + await Get(); } - - public void Get() + public async Task Get() { if (_objectMessage.CurrentGroup != null) @@ -102,10 +107,13 @@ public partial class RoundRunningViewModel : ObservableObject { RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints; } - TriggerRebuild(); + //TriggerRebuild(); + BuildScore(playerColumns); + } } + [RelayCommand] private void StoreAndHandlePointsAsync() { @@ -154,7 +162,8 @@ public partial class RoundRunningViewModel : ObservableObject { RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints; } - TriggerRebuild(); + // TriggerRebuild(); + BuildScore(playerColumns); Shell.Current.GoToAsync("..").GetAwaiter().GetResult(); } @@ -290,6 +299,38 @@ public partial class RoundRunningViewModel : ObservableObject } } + + public void BuildScore(IEnumerable columns) + { + ScoreColumns.Clear(); + + + foreach (var column in columns) + { + var scoreColumn = new ScoreColumn + { + PlayerName = column.PlayerName + }; + + scoreColumn.Cells.Add(new ScoreCell + { + Text = column.PlayerName, + IsHeader = true + }); + + foreach (var value in System.Linq.Enumerable.Reverse(column.Values)) + { + scoreColumn.Cells.Add(new ScoreCell + { + Text = value, + IsHeader = false + }); + } + + ScoreColumns.Add(scoreColumn); + } + } + } diff --git a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs index f4cf789..7083e35 100644 --- a/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs +++ b/GreadyPoang.ViewModelLayer/ViewModelClasses/RoundStartingViewModel.cs @@ -210,6 +210,7 @@ public partial class RoundStartingViewModel : ObservableObject if (rbGroup != null) { _objectMessage.CurrentGroup = rbGroup; + //await Shell.Current.GoToAsync("//RoundRunningView"); await Shell.Current.GoToAsync("//RoundRunningView"); } } diff --git a/GreadyPoang/GreadyPoang.csproj b/GreadyPoang/GreadyPoang.csproj index 1360b86..c8f9b59 100644 --- a/GreadyPoang/GreadyPoang.csproj +++ b/GreadyPoang/GreadyPoang.csproj @@ -59,6 +59,14 @@ + + + + + + + + diff --git a/GreadyPoang/MauiProgram.cs b/GreadyPoang/MauiProgram.cs index 43f38c2..d30b2be 100644 --- a/GreadyPoang/MauiProgram.cs +++ b/GreadyPoang/MauiProgram.cs @@ -42,20 +42,24 @@ public static class MauiProgram }); builder.Services.AddScoped, ParticipantRepository>(); + builder.Services.AddScoped, MethodSharingService>(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped, GameRoundRepository>(); + builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped, GamePointRepository>(); + builder.Services.AddScoped(); builder.Services.AddScoped(); - builder.Services.AddScoped, MethodSharingService>(); builder.Services.AddScoped(); builder.Services.AddSingleton(); + builder.Services.AddTransientPopup(); builder.Services.AddSingleton(); diff --git a/GreadyPoang/Resources/Styles/AppStyles.xaml b/GreadyPoang/Resources/Styles/AppStyles.xaml index 809eca1..11a9618 100644 --- a/GreadyPoang/Resources/Styles/AppStyles.xaml +++ b/GreadyPoang/Resources/Styles/AppStyles.xaml @@ -2,8 +2,11 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:local="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common" > + +