Compare commits

...

16 Commits

Author SHA1 Message Date
6df80917ee Merge branch 'UtanSplash' of https://gitweb.tfoman.me/tfoman/GreadyPoang into UtanSplash 2025-10-28 08:01:42 +01:00
f48869205e begränsa utbredning neråt 2025-10-28 08:01:33 +01:00
d586c96ddf Små ändringar i roundrunning 2025-10-28 07:16:55 +01:00
5ff42f5bca Checkar in innan funktionen är klar 2025-10-25 08:46:52 +02:00
26ff51169f Nu fungerar RoundRunningView med minimal codeBehind 2025-10-22 10:42:39 +02:00
ecd3e90dbf RoundRunningView med nytt event "Loaded" triggas endast en gg när sidan är renderad 2025-10-20 16:46:38 +02:00
2797162a93 Nu är det ordning på popuperna 2025-10-19 23:18:51 +02:00
735788969a Med Popups och nytt system för släckning, men utan hantering av rätt popup 2025-10-19 16:33:19 +02:00
a8ca07a1bf Ordning på spelarnas poängsummor + popup i participant och i RoundRunning när någon är på väg att vinna 2025-10-18 09:52:49 +02:00
bb8f4bd5ed Nu fungerar Popupen och den går att stänga 2025-10-17 11:52:01 +02:00
21eb0d5498 Observable properties och RelayCommands införda 2025-10-14 21:57:37 +02:00
b4d6c6d530 Infört Observable Property överallt, där tillämpligt 2025-10-13 12:13:12 +02:00
b2dbb9993f Infört Observable Property och observable object från Community Toolkit 2025-10-13 08:59:26 +02:00
f5cc28f202 Före start av införande av Community Toolkit MVVM 2025-10-12 18:03:08 +02:00
469b0b3377 Nu fungerar det 2025-10-12 14:34:54 +02:00
ae05adc823 Poängräkningen fungerar 2025-10-12 09:41:14 +02:00
48 changed files with 1064 additions and 999 deletions

View File

@ -1,29 +0,0 @@
using System.ComponentModel;
namespace Common.Library;
public abstract class CommonBase : INotifyPropertyChanged
{
#region Constructor
protected CommonBase()
{
Init();
}
#endregion
#region Init Method
public virtual void Init()
{
}
#endregion
#region RaisePropertyChanged Method
public event PropertyChangedEventHandler? PropertyChanged;
public virtual void RaisePropertyChanged(string propertyName)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}

View File

@ -1,5 +0,0 @@
namespace Common.Library;
public class EntityBase : CommonBase
{
}

View File

@ -1,14 +0,0 @@
//using GreadyPoang.DataLayer;
namespace Common.Library;
public class ViewModelBase : CommonBase
{
//private readonly LocalDbService _dbService;
//public ViewModelBase(LocalDbService dbService)
//{
// _dbService = dbService;
//}
}

View File

@ -6,5 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="12.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,39 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.Core;
public partial class BaseViewModel : ObservableObject
{
[ObservableProperty]
private bool isBusy;
protected async Task RunAsyncCommand(Func<Task> action, string loadingMessage = null, string errorMessage = "Ett fel inträffade")
{
if (IsBusy) return;
try
{
IsBusy = true;
if (!string.IsNullOrWhiteSpace(loadingMessage))
await Snackbar.Make(
message: loadingMessage,
duration: TimeSpan.FromSeconds(2),
action: null).Show();
await action.Invoke();
}
catch (Exception ex)
{
await Snackbar.Make(
message: $"{errorMessage}: {ex.Message}",
duration: TimeSpan.FromSeconds(3),
action: () => Console.WriteLine("Åtgärd vald")).Show();
}
finally
{
IsBusy = false;
}
}
}

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.100" />
</ItemGroup>

View File

@ -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();
}

View File

@ -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);
}
};
}
}
}

View File

@ -52,14 +52,14 @@ public class CombinedRepository : ICombinedRepository
gp.GamePointId,
gp.GameRoundId,
gp.GameRoundRegNr,
gp.GameRegPoints,
latest.totPoints as GameRegPoints,
gr.GameRoundStartDate,
gr.GameStatus AS Status,
p.ParticipantId,
(p.LastName || ' ' || p.FirstName) AS ParticipantName
FROM GamePoints gp
INNER JOIN (
SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId
SELECT ParticipantId, GameRoundId, MAX(GamePointId) AS MaxGamePointId, sum(GameRegPoints) AS totPoints
FROM GamePoints
GROUP BY ParticipantId, GameRoundId
) latest ON gp.GamePointId = latest.MaxGamePointId

View File

@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -1,97 +1,42 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
using SQLite;
namespace GreadyPoang.EntityLayer;
[Table("GamePoint")]
public class GamePoint : EntityBase
public partial class GamePoint : ObservableObject
{
public GamePoint()
{
_gamePointId = 0;
_participantId = 0;
_gameRoundId = 0;
_gameDate = DateTime.Now;
_gameRoundRegNr = 0;
_gameRegPoints = 0;
GamePointId = 0;
ParticipantId = 0;
GameRoundId = 0;
GameDate = DateTime.Now;
GameRoundRegNr = 0;
GameRegPoints = 0;
}
private int _gamePointId;
private int _participantId;
private int _gameRoundId;
private DateTime _gameDate;
private int _gameRoundRegNr;
private int _gameRegPoints;
[ObservableProperty]
[property: PrimaryKey, AutoIncrement, Column("GamePointId")]
private int gamePointId;
[PrimaryKey]
[AutoIncrement]
[Column("GamePointId")]
public int GamePointId
{
get { return _gamePointId; }
set
{
_gamePointId = value;
RaisePropertyChanged(nameof(GamePointId));
}
}
[ObservableProperty]
[property: Column("ParticipantId")]
private int participantId;
[Column("ParticipantId")]
public int ParticipantId
{
get { return _participantId; }
set
{
_participantId = value;
RaisePropertyChanged(nameof(ParticipantId));
}
}
[Column("GameRoundId")]
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
RaisePropertyChanged(nameof(GameRoundId));
}
}
[ObservableProperty]
[property: Column("GameRoundId")]
private int gameRoundId;
[Column("GameDate")]
public DateTime GameDate
{
get { return _gameDate; }
set
{
_gameDate = value;
RaisePropertyChanged(nameof(GameDate));
}
}
// GameRoundRegNr räknas upp när en spelare får en ny gamepoint inlagd
// Alltså hans/hennes senaste i samma runda uppräknad med 1
[Column("GameRoundRegNr")]
public int GameRoundRegNr
{
get { return _gameRoundRegNr; }
set
{
_gameRoundRegNr = value;
RaisePropertyChanged(nameof(GameRoundRegNr));
}
}
[Column("GameRegPoints")]
public int GameRegPoints
{
get { return _gameRegPoints; }
set
{
_gameRegPoints = value;
RaisePropertyChanged(nameof(GameRegPoints));
}
}
[ObservableProperty]
[property: Column("GameDate")]
private DateTime gameDate;
[ObservableProperty]
[property: Column("GameRoundRegNr")]
private int gameRoundRegNr;
[ObservableProperty]
[property: Column("GameRegPoints")]
private int gameRegPoints;
}

View File

@ -1,4 +1,4 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
using SQLite;
namespace GreadyPoang.EntityLayer;
@ -6,72 +6,34 @@ namespace GreadyPoang.EntityLayer;
[Table("GameRound")]
public class GameRound : EntityBase
public partial class GameRound : ObservableObject
{
public GameRound()
{
_gameRoundId = 0;
_gameRoundStartDate = DateTime.Now;
_gameStatus = GamePointStatus.New;
_gameRoundFinished = null;
GameRoundId = 0;
GameRoundStartDate = DateTime.Now;
GameStatus = GamePointStatus.New;
GameRoundFinished = null;
}
private int _gameRoundId;
private DateTime _gameRoundStartDate;
private GamePointStatus _gameStatus;
private DateTime? _gameRoundFinished;
[ObservableProperty]
[property: PrimaryKey, AutoIncrement, Column("GameRoundId")]
private int gameRoundId;
[Column("GameRoundFinished")]
public DateTime? GameRoundFinished
{
get { return _gameRoundFinished; }
set
{
_gameRoundFinished = value;
RaisePropertyChanged(nameof(GameRoundFinished));
}
}
[ObservableProperty]
[property: Column("GameRoundStartDate")]
private DateTime gameRoundStartDate;
[Column("GameRoundStartDate")]
public DateTime GameRoundStartDate
{
get { return _gameRoundStartDate; }
set
{
_gameRoundStartDate = value;
RaisePropertyChanged(nameof(GameRoundStartDate));
}
}
[ObservableProperty]
[property: Column("GameStatus")]
private GamePointStatus gameStatus;
[Column("GameStatus")]
public GamePointStatus GameStatus
{
get { return _gameStatus; }
set
{
_gameStatus = value;
RaisePropertyChanged(nameof(GameStatus));
}
}
[PrimaryKey]
[AutoIncrement]
[Column("GameRoundId")]
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
RaisePropertyChanged(nameof(GameRoundId));
}
}
[ObservableProperty]
[property: Column("GameRoundFinished")]
private DateTime? gameRoundFinished;
public string GameRoundStartDateString
{
get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); }
get { return GameRoundStartDate.ToString("yyyy-MM-dd"); }
}
}

View File

@ -1,67 +1,32 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
using SQLite;
namespace GreadyPoang.EntityLayer;
[Table("Participants")]
public class Participant : EntityBase
public partial class Participant : ObservableObject
{
public Participant()
{
_firstName = string.Empty;
_lastName = string.Empty;
_email = string.Empty;
FirstName = string.Empty;
LastName = string.Empty;
Email = string.Empty;
}
private int _participantId;
private string _firstName;
private string _lastName;
private string _email;
[ObservableProperty]
[property: PrimaryKey, AutoIncrement, Column("ParticipantId")]
private int participantId;
[PrimaryKey]
[AutoIncrement]
[Column("ParticipantId")]
public int ParticipantId
{
get { return _participantId; }
set
{
_participantId = value;
RaisePropertyChanged(nameof(ParticipantId));
}
}
[ObservableProperty]
[property: Column("FirstName")]
private string firstName;
[Column("FirstName")]
public string FirstName
{
get { return _firstName; }
set
{
_firstName = value;
RaisePropertyChanged(nameof(FirstName));
}
}
[ObservableProperty]
[property: Column("LastName")]
private string lastName;
[Column("LastName")]
public string LastName
{
get { return _lastName; }
set
{
_lastName = value;
RaisePropertyChanged(nameof(LastName));
}
}
[Column("Email")]
public string Email
{
get { return _email; }
set
{
_email = value;
RaisePropertyChanged(nameof(Email));
}
}
[ObservableProperty]
[property: Column("Email")]
private string email;
public string FullName
{

View File

@ -5,5 +5,7 @@ public enum GamePointStatus
New = 0,
InProgress = 1,
Completed = 2,
Cancelled = 3
Cancelled = 3,
Winning = 4,
Winner = 5
}

View File

@ -11,6 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.11" />
</ItemGroup>

View File

@ -1,55 +1,27 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.EntityLayer;
public class PlayerColumn : EntityBase
public partial class PlayerColumn : ObservableObject
{
public PlayerColumn()
{
_playerName = string.Empty;
_values = new List<string>();
PlayerName = string.Empty;
Values = new List<string>();
}
private int _playerId;
private string _playerName;
private List<string> _values;
public string PlayerName
{
get { return _playerName; }
set
{
_playerName = value;
RaisePropertyChanged(nameof(PlayerName));
}
}
public List<string> Values
{
get { return _values; }
set
{
_values = value;
RaisePropertyChanged(nameof(Values));
}
}
[ObservableProperty]
private int playerId;
public int PlayerId
{
get { return _playerId; }
set
{
_playerId = value;
RaisePropertyChanged(nameof(PlayerId));
}
}
[ObservableProperty]
private string playerName;
private int _playerPoints;
[ObservableProperty]
private List<string> values;
public int PlayerPoints
{
get { return _playerPoints; }
set { _playerPoints = value; }
}
[ObservableProperty]
private int playerPoints;
}

View File

@ -1,128 +1,56 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.EntityLayer;
public class RoundBuilderElement : EntityBase
public partial class RoundBuilderElement : ObservableObject
{
public RoundBuilderElement()
{
_participantId = 0;
_participantName = string.Empty;
_gameRoundRegNr = 0;
_gameRegPoints = 0;
_status = GamePointStatus.New;
_gameRoundStartDate = DateTime.MinValue;
_gameRoundId = 0;
_gamePointId = 0;
ParticipantId = 0;
ParticipantName = string.Empty;
GameRoundRegNr = 0;
GameRegPoints = 0;
Status = GamePointStatus.New;
GameRoundStartDate = DateTime.MinValue;
GameRoundId = 0;
GamePointId = 0;
}
private int _participantId;
private string _participantName;
private int _gameRoundRegNr;
private int _gameRegPoints;
private GamePointStatus _status;
private DateTime _gameRoundStartDate;
private int _gameRoundId;
private int _gamePointId;
[ObservableProperty]
private int participantId;
public int ParticipantId
{
get { return _participantId; }
set
{
_participantId = value;
RaisePropertyChanged(nameof(ParticipantId));
}
}
[ObservableProperty]
private string participantName;
[ObservableProperty]
private int gameRoundRegNr;
public string ParticipantName
{
get { return _participantName; }
set
{
_participantName = value;
RaisePropertyChanged(nameof(ParticipantName));
}
}
[ObservableProperty]
private int gameRegPoints;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusString))]
private GamePointStatus status;
public int GameRoundRegNr
{
get { return _gameRoundRegNr; }
set
{
_gameRoundRegNr = value;
RaisePropertyChanged(nameof(GameRoundRegNr));
}
}
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(GameRoundStartDateString))]
private DateTime gameRoundStartDate;
[ObservableProperty]
private int gameRoundId;
public int GameRegPoints
{
get { return _gameRegPoints; }
set
{
_gameRegPoints = value;
RaisePropertyChanged(nameof(GameRegPoints));
}
}
public GamePointStatus Status
{
get { return _status; }
set
{
_status = value;
RaisePropertyChanged(nameof(Status));
RaisePropertyChanged(nameof(StatusString));
}
}
[ObservableProperty]
private int gamePointId;
public string StatusString
{
get { return _status.ToString(); }
}
public DateTime GameRoundStartDate
{
get { return _gameRoundStartDate; }
set
{
_gameRoundStartDate = value;
RaisePropertyChanged(nameof(GameRoundStartDate));
RaisePropertyChanged(nameof(GameRoundStartDateString));
}
get { return status.ToString(); }
}
public string GameRoundStartDateString
{
get { return _gameRoundStartDate.ToString("yyyy-MM-dd"); }
}
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
RaisePropertyChanged(nameof(GameRoundId));
}
get { return gameRoundStartDate.ToString("yyyy-MM-dd"); }
}
public int GamePointId
{
get { return _gamePointId; }
set
{
_gamePointId = value;
RaisePropertyChanged(nameof(GamePointId));
}
}
}

View File

@ -1,56 +1,26 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.EntityLayer;
public class RoundBuilderGroup : EntityBase
public partial class RoundBuilderGroup : ObservableObject
{
public RoundBuilderGroup()
{
_gameRoundId = 0;
_gameRoundStartDate = DateTime.MinValue;
_status = GamePointStatus.New;
_elements = new List<RoundBuilderElement>();
}
private int _gameRoundId;
private DateTime _gameRoundStartDate;
private GamePointStatus _status;
private List<RoundBuilderElement> _elements;
public int GameRoundId
{
get { return _gameRoundId; }
set
{
_gameRoundId = value;
// No need to raise property changed for this example
}
}
public DateTime GameRoundStartDate
{
get { return _gameRoundStartDate; }
set
{
_gameRoundStartDate = value;
// No need to raise property changed for this example
}
}
public GamePointStatus Status
{
get { return _status; }
set
{
_status = value;
// No need to raise property changed for this example
}
GameRoundId = 0;
GameRoundStartDate = DateTime.MinValue;
Status = GamePointStatus.New;
Elements = new List<RoundBuilderElement>();
}
public List<RoundBuilderElement> Elements
{
get { return _elements; }
set
{
_elements = value;
RaisePropertyChanged(nameof(Elements));
// No need to raise property changed for this example
}
}
[ObservableProperty]
private int gameRoundId;
[ObservableProperty]
private DateTime gameRoundStartDate;
[ObservableProperty]
private GamePointStatus _status;
[ObservableProperty]
private List<RoundBuilderElement> elements;
}

View File

@ -0,0 +1,7 @@
namespace GreadyPoang.EntityLayer;
public class ScoreCell
{
public string Text { get; set; }
public bool IsHeader { get; set; }
}

View File

@ -0,0 +1,9 @@
using System.Collections.ObjectModel;
namespace GreadyPoang.EntityLayer;
public class ScoreColumn
{
public string PlayerName { get; set; }
public ObservableCollection<ScoreCell> Cells { get; set; } = new();
}

View File

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GreadyPoang.EntityLayer\GreadyPoang.EntityLayer.csproj" />
</ItemGroup>

View File

@ -0,0 +1,6 @@
namespace GreadyPoang.Services;
public static class LatestPopup
{
public static string valueGuid = "";
}

View File

@ -0,0 +1,12 @@
namespace GreadyPoang.Services;
public class PopupEventHub : IPopupEventHub
{
public event EventHandler<PopupCloseEventArgs>? InfoPopupCloseRequested;
public void RaiseInfoPopupClose(string popupId)
{
InfoPopupCloseRequested?.Invoke(this, new PopupCloseEventArgs(popupId));
}
}

View File

@ -0,0 +1,9 @@
namespace GreadyPoang.Services;
public interface IPopupEventHub
{
event EventHandler<PopupCloseEventArgs>? InfoPopupCloseRequested;
void RaiseInfoPopupClose(string popupId);
}

View File

@ -0,0 +1,11 @@
namespace GreadyPoang.Services;
public class PopupCloseEventArgs : EventArgs
{
public string PopupId { get; }
public PopupCloseEventArgs(string popupId)
{
PopupId = popupId;
}
}

View File

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common.Library\Common.Library.csproj" />
<ProjectReference Include="..\GreadyPoang.DataLayer\GreadyPoang.DataLayer.csproj" />

View File

@ -0,0 +1,50 @@
using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.Services;
namespace GreadyPoang.ViewModelLayer;
public partial class InfoPopupViewModel : ObservableObject, IQueryAttributable
{
private readonly IPopupService _popupService;
private readonly IPopupEventHub _popupEvent;
public string PopupId { get; } = Guid.NewGuid().ToString();
public event EventHandler ClosePopupRequested;
[ObservableProperty]
private string title;
[ObservableProperty]
private string message;
[ObservableProperty]
private string name;
public InfoPopupViewModel(IPopupService popupService, IPopupEventHub popupEvent)
{
_popupService = popupService;
_popupEvent = popupEvent;
LatestPopup.valueGuid = PopupId;
}
[RelayCommand]
private async Task Cancel()
{
_popupEvent.RaiseInfoPopupClose(PopupId);
}
[RelayCommand(CanExecute = nameof(CanSave))]
void OnSave()
{
}
bool CanSave() => string.IsNullOrWhiteSpace(Name) is false;
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
Title = (string)query[nameof(InfoPopupViewModel.Title)];
Message = (string)query[nameof(InfoPopupViewModel.Message)];
Name = (string)query[nameof(InfoPopupViewModel.Name)];
}
}

View File

@ -1,10 +1,11 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
using GreadyPoang.EntityLayer;
using System.Collections.ObjectModel;
namespace GreadyPoang.ViewModelLayer;
public class MethodSharingService : ViewModelBase, IMethodSharingService<Participant>
public class MethodSharingService : ObservableObject, IMethodSharingService<Participant>
{
private readonly IRepository<Participant> _repository;

View File

@ -1,11 +1,16 @@
using Common.Library;
using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.Core;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using System.Collections.ObjectModel;
namespace GreadyPoang.ViewModelLayer;
public class ParticipantViewModel : ViewModelBase
public partial class ParticipantViewModel : BaseViewModel
{
#region Constructors
public ParticipantViewModel() : base()
@ -13,49 +18,68 @@ public class ParticipantViewModel : ViewModelBase
}
public ParticipantViewModel(IRepository<Participant> repo, IMethodSharingService<Participant> sharingService) : base()
public ParticipantViewModel(
IRepository<Participant> repo,
IMethodSharingService<Participant> sharingService,
IPopupService popupService,
IPopupEventHub popupEvent
) : base()
{
_Repository = repo;
_sharingService = sharingService;
_popupService = popupService;
_popupEvent = popupEvent;
ParticipantObject = new Participant();
ParticipantList = new ObservableCollection<Participant>();
IsSaveCommandEnabled = true;
PopupVisad = false;
_popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested;
}
#endregion
#region Private Variables
private Participant? _ParticipantObject = new();
private ObservableCollection<Participant> _ParticipantList = new();
[ObservableProperty]
private Participant? participantObject;
[ObservableProperty]
private ObservableCollection<Participant> participantList;
private readonly IRepository<Participant>? _Repository;
private readonly IMethodSharingService<Participant> _sharingService;
#endregion
#region public Properties
public Participant? ParticipantObject
{
get { return _ParticipantObject; }
set
{
_ParticipantObject = value;
RaisePropertyChanged(nameof(ParticipantObject));
}
}
public ObservableCollection<Participant> ParticipantList
{
get { return _ParticipantList; }
set
{
_ParticipantList = value;
RaisePropertyChanged(nameof(ParticipantList));
}
}
private readonly IPopupService _popupService;
private readonly IPopupEventHub _popupEvent;
private readonly InfoPopupViewModel _infoPopupViewModel;
private string _activePopupId;
#endregion
public bool PopupVisad { get; set; }
[ObservableProperty]
private bool isSaveCommandEnabled;
#region Get Method
public ObservableCollection<Participant> Get()
{
ParticipantList = _sharingService.Get();
if (!PopupVisad)
{
var queryAttributes = new Dictionary<string, object>
{
[nameof(InfoPopupViewModel.Title)] = "Deltagar bildens infopopup",
[nameof(InfoPopupViewModel.Message)] = "Deltagare laddade",
[nameof(InfoPopupViewModel.Name)] = " ",
};
_popupService.ShowPopup<InfoPopupViewModel>(
Shell.Current,
options: PopupOptions.Empty,
shellParameters: queryAttributes);
_activePopupId = LatestPopup.valueGuid;
}
return ParticipantList;
}
@ -77,20 +101,62 @@ public class ParticipantViewModel : ViewModelBase
return ParticipantObject;
}
public virtual bool Save()
#endregion
[RelayCommand(CanExecute = nameof(IsSaveCommandEnabled))]
private async Task Save()
{
await RunAsyncCommand(async () =>
{
if (_Repository == null || ParticipantObject == null)
{
return false;
return;
}
await Task.Delay(3600); // Simulerar en fördröjning för att visa laddningsindikatorn
var tmpTask = _Repository.Save(ParticipantObject);
int tmp = tmpTask.GetAwaiter().GetResult();
int tmp = await tmpTask;
if (tmp != -1)
{
ParticipantObject = new Participant();
this.Get();
await Shell.Current.GoToAsync("..");
}
return tmp != -1;
}, loadingMessage: "Sparar deltagare...", errorMessage: "Fel vid sparande av deltagare");
}
#endregion
[RelayCommand]
private void DeleteAsync(Participant pp)
{
Console.WriteLine($"Valt från ViewModel: {pp.FullName}");
if (_Repository == null || pp == null || pp.ParticipantId <= 0)
{
return;
}
var tmpTask = _Repository.Delete(pp);
this.Get();
Shell.Current.GoToAsync("..");
}
[RelayCommand]
private async Task LoadDataAsync()
{
await RunAsyncCommand(async () =>
{
await Task.Delay(1500); // Simulerar laddning
Console.WriteLine("Data laddad!");
}, loadingMessage: "Laddar data...");
}
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
{
if (e.PopupId != _activePopupId)
{
return;
}
PopupVisad = true;
await _popupService.ClosePopupAsync(Shell.Current);
}
}

View File

@ -1,16 +1,21 @@
using Common.Library;
using CommunityToolkit.Maui;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows.Input;
namespace GreadyPoang.ViewModelLayer;
public class RoundRunningViewModel : ViewModelBase
public partial class RoundRunningViewModel : ObservableObject
{
public event EventHandler RebuildRequested;
public ICommand OnLoadedCommand { get; }
public RoundRunningViewModel() : base()
{
@ -22,7 +27,9 @@ public class RoundRunningViewModel : ViewModelBase
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined,
IObjectMessageService objectMessage
IObjectMessageService objectMessage,
IPopupService popupService,
IPopupEventHub popupEvent
) : base()
{
_roundsRepo = roundsRepo;
@ -30,8 +37,14 @@ public class RoundRunningViewModel : ViewModelBase
_sharingService = sharingService;
_combined = combined;
_objectMessage = objectMessage;
_roundElements = new ObservableCollection<RoundBuilderElement>();
_builderObject = new();
_popupService = popupService;
_popupEvent = popupEvent;
RoundElements = new ObservableCollection<RoundBuilderElement>();
BuilderObject = new();
_popupEvent.InfoPopupCloseRequested += infoPopupViewModel_ClosePopupRequested;
//PopupVisad = false;
OnLoadedCommand = new AsyncRelayCommand(OnLoadedAsync, () => true);
}
private readonly IRepository<GameRound>? _roundsRepo;
@ -39,53 +52,30 @@ public class RoundRunningViewModel : ViewModelBase
private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage;
private readonly IPopupService _popupService;
private readonly IPopupEventHub _popupEvent;
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
private ObservableCollection<RoundBuilderElement> _roundElements;
private Collection<PlayerColumn> _playerColumns;
private RoundBuilderElement _builderObject;
[ObservableProperty]
private ObservableCollection<RoundBuilderElement> roundElements;
[ObservableProperty]
private Collection<PlayerColumn> playerColumns;
[ObservableProperty]
private RoundBuilderElement builderObject;
public ObservableCollection<ScoreColumn> ScoreColumns { get; } = new ObservableCollection<ScoreColumn>();
public void TriggerRebuild()
private string _activePopupId;
//public bool PopupVisad { get; set; }
private async Task OnLoadedAsync()
{
// Trigga eventet
RebuildRequested?.Invoke(this, EventArgs.Empty);
await Get();
}
public ObservableCollection<RoundBuilderElement> RoundElements
public async Task Get()
{
get { return _roundElements; }
set
{
_roundElements = value;
RaisePropertyChanged(nameof(RoundElements));
}
}
public Collection<PlayerColumn> PlayerColumns
{
get { return _playerColumns; }
set
{
_playerColumns = value;
RaisePropertyChanged(nameof(PlayerColumns));
}
}
public RoundBuilderElement BuilderObject
{
get { return _builderObject; }
set
{
_builderObject = value;
RaisePropertyChanged(nameof(BuilderObject));
}
}
public ObservableCollection<RoundBuilderElement> Get()
{
if (_objectMessage.CurrentGroup != null)
{
@ -97,29 +87,20 @@ public class RoundRunningViewModel : ViewModelBase
}
foreach (var item in _objectMessage.CurrentGroup.Elements)
{
_roundElements.Add(item);
RoundElements.Add(item);
}
// Räkna ut vem som är nästa spelare
var nxt = nextPlayerElement();
// Aktuell spelare sätts som BuilderObject
BuilderObject.ParticipantName = _objectMessage.CurrentGroup.Elements[nxt].ParticipantName;
BuilderObject.GameRoundId = _objectMessage.CurrentGroup.GameRoundId;
BuilderObject.ParticipantId = _objectMessage.CurrentGroup.Elements[nxt].ParticipantId;
BuilderObject.Status = _objectMessage.CurrentGroup.Status;
// Alla poängposter från samtliga spelare i rundan samlas ihop och fördelas per deltagare
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
UpdateAndShow();
FillupResultTable(localElements);
TriggerRebuild();
}
return RoundElements;
}
public void StoreAndHandlePoints()
[RelayCommand]
private void StoreAndHandlePointsAsync()
{
var game = _roundsRepo.Get(BuilderObject.GameRoundId).GetAwaiter().GetResult();
var regNr = RoundElements.Count > 0 ? RoundElements.Max(e => e.GameRoundRegNr) + 1 : 1;
@ -153,20 +134,10 @@ public class RoundRunningViewModel : ViewModelBase
RoundElements.Add(item);
}
// Uppdatera spelaren som skall spela nästa
var nxt = nextPlayerElement();
BuilderObject.GameRegPoints = 0;
BuilderObject.ParticipantName = RoundElements[nxt].ParticipantName;
BuilderObject.ParticipantId = RoundElements[nxt].ParticipantId;
BuilderObject.GameRoundId = RoundElements[0].GameRoundId;
UpdateAndShow();
Shell.Current.GoToAsync("..").GetAwaiter().GetResult();
var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId);
FillupResultTable(localElements);
foreach (var col in _playerColumns)
{
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
}
TriggerRebuild();
}
private int nextPlayerElement()
@ -181,17 +152,76 @@ public class RoundRunningViewModel : ViewModelBase
return -1;
}
private void UpdateAndShow()
{
// Räkna ut vem som är nästa spelare
var nxt = nextPlayerElement();
// Aktuell spelare sätts som BuilderObject
BuilderObject.ParticipantName = _objectMessage.CurrentGroup.Elements[nxt].ParticipantName;
BuilderObject.ParticipantId = _objectMessage.CurrentGroup.Elements[nxt].ParticipantId;
BuilderObject.GameRoundId = _objectMessage.CurrentGroup.GameRoundId;
// Alla poängposter från samtliga spelare i rundan samlas ihop och fördelas per deltagare
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
FillupResultTable(localElements);
// Fix for CS8602: Add null check before dereferencing FirstOrDefault result
foreach (var col in PlayerColumns)
{
var roundElement = RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId);
if (roundElement != null)
{
roundElement.GameRegPoints = col.PlayerPoints;
}
}
// Fix for MVVMTK0034: Use the generated property 'PlayerColumns' instead of the backing field 'playerColumns'
BuildScore(PlayerColumns);
}
private void Show_a_Popup(string ppName, string ppTitle, string ppMessage)
{
//if (!PopupVisad)
//{
var queryAttributes = new Dictionary<string, object>
{
[nameof(InfoPopupViewModel.Title)] = ppTitle,
[nameof(InfoPopupViewModel.Message)] = ppMessage,
[nameof(InfoPopupViewModel.Name)] = ppName,
};
_popupService.ShowPopup<InfoPopupViewModel>(
Shell.Current,
options: PopupOptions.Empty,
shellParameters: queryAttributes);
_activePopupId = LatestPopup.valueGuid;
//}
}
private async void infoPopupViewModel_ClosePopupRequested(object? sender, PopupCloseEventArgs e)
{
if (e.PopupId != _activePopupId)
{
return;
}
//PopupVisad = true;
await _popupService.ClosePopupAsync(Shell.Current);
}
private void FillupResultTable(IEnumerable<RoundBuilderElement> elements)
{
if (_playerColumns != null)
if (PlayerColumns != null)
{
_playerColumns.Clear();
PlayerColumns.Clear();
}
else
{
_playerColumns = new Collection<PlayerColumn>();
PlayerColumns = new Collection<PlayerColumn>();
}
// if (elements.Any(g => g.GameRegPoints > 0))
@ -199,10 +229,12 @@ public class RoundRunningViewModel : ViewModelBase
{
PlayerColumn player = new PlayerColumn();
var regMax = elements.Max(e => e.GameRoundRegNr);
var existingWinning = elements.FirstOrDefault(e => e.Status == GamePointStatus.Winning);
foreach (var element in elements)
{
player = _playerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId);
player = PlayerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId)!;
if (player == null)
{
player = new PlayerColumn
@ -216,13 +248,17 @@ public class RoundRunningViewModel : ViewModelBase
if (element.GameRegPoints > 0)
{
player.Values.Add(element.GameRegPoints.ToString());
var playerPointsOld = player.PlayerPoints;
player.PlayerPoints += element.GameRegPoints;
}
//oldPart = element.ParticipantId;
if (!_playerColumns.Contains(player))
if (player.PlayerPoints > 10000)
{
_playerColumns.Add(player);
HandlePlayerReachedWinningThreshold(player, regMax, element, playerPointsOld, existingWinning);
}
}
if (!PlayerColumns.Contains(player))
{
PlayerColumns.Add(player);
}
}
}
@ -234,7 +270,9 @@ public class RoundRunningViewModel : ViewModelBase
{
var player = new PlayerColumn
{
PlayerName = element.ParticipantName
PlayerName = element.ParticipantName,
PlayerId = element.ParticipantId,
PlayerPoints = 0
};
for (int i = 0; i < slumper.Next(6); i++)
@ -242,11 +280,91 @@ public class RoundRunningViewModel : ViewModelBase
player.Values.Add(slumper.Next(1, 10).ToString());
}
_playerColumns.Add(player);
PlayerColumns.Add(player);
}
}
}
private void HandlePlayerReachedWinningThreshold(
PlayerColumn player,
int regMax,
RoundBuilderElement element,
int playerPointsOld,
RoundBuilderElement existingWinning
)
{
var nextPlayer = RoundElements[AfterNext()].ParticipantName;
Debug.WriteLine($"Spelare {nextPlayer} samma som {player.PlayerName} ???.");
if (existingWinning != null && existingWinning.ParticipantId != player.PlayerId)
{
// Det finns redan en vinnare, sätt dennes status tillbaka till InProgress
existingWinning.Status = GamePointStatus.InProgress;
}
// Om det redan finns en vinnare, sätt dennes status tillbaka till InProgress, kanske
var winner = RoundElements.FirstOrDefault(e => e.ParticipantId == player.PlayerId);
var oldStatus = winner.Status;
winner.Status = GamePointStatus.Winning;
if (playerPointsOld < 10000 && oldStatus != winner.Status && regMax == element.GameRoundRegNr)
{
//PopupVisad = false;
Show_a_Popup(
player.PlayerName,
"Se upp för denne spelare !",
$"Du har nått en poängnivå över 10000 ({player.PlayerPoints})\r" +
$"Alla övriga får nu en chans att överträffa\r" +
$"om någon kommer till samma poäng som\r" +
$"{player.PlayerName}\r" +
$"får hen försvara sig med nytt kast\r" +
$"Om kastet inte blir godkänt (ger poäng)\r" +
$"Vinner den upphinnande spelaren"
);
}
}
private int AfterNext()
{
var comingUp = nextPlayerElement();
if (RoundElements.Count - 1 == comingUp)
{
return 0;
}
return comingUp;
}
public void BuildScore(IEnumerable<PlayerColumn> 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);
}
}
}

View File

@ -1,4 +1,6 @@
using Common.Library;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
@ -7,7 +9,7 @@ using System.Diagnostics;
namespace GreadyPoang.ViewModelLayer;
public class RoundStartingViewModel : ViewModelBase
public partial class RoundStartingViewModel : ObservableObject
{
#region Constructors
public RoundStartingViewModel() : base()
@ -27,52 +29,44 @@ public class RoundStartingViewModel : ViewModelBase
_sharingService = sharingService;
_combined = combined;
_objectMessage = objectMessage;
_roundElements = new ObservableCollection<RoundBuilderElement>();
RoundElements = new ObservableCollection<RoundBuilderElement>();
}
#endregion
private GameRound? _GameRoundObject = new();
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
private ObservableCollection<Participant> _ParticipantList = new();
private readonly IRepository<GameRound>? _roundsRepo;
private readonly IRepository<GamePoint> _pointsRepo;
private readonly IMethodSharingService<Participant> _sharingService;
private readonly ICombinedRepository _combined;
private readonly IObjectMessageService _objectMessage;
private Participant _selectedItem;
private ObservableCollection<RoundBuilderElement> _roundElements;
public ObservableCollection<RoundBuilderElement> RoundElements
[ObservableProperty]
private Participant selectedItem;
partial void OnSelectedItemChanged(Participant value)
{
get { return _roundElements; }
set
if (value != null)
{
_roundElements = value;
RaisePropertyChanged(nameof(RoundElements));
OnItemSelected(value);
}
}
[ObservableProperty]
private ObservableCollection<RoundBuilderElement> roundElements;
public Participant SelectedItem
{
get => _selectedItem;
set
{
if (_selectedItem != value)
{
[ObservableProperty]
private GameRound? gameRoundObject = new();
[ObservableProperty]
private ObservableCollection<RoundBuilderGroup> gameRoundList = new();
[ObservableProperty]
private ObservableCollection<Participant> participantList = new();
_selectedItem = value;
RaisePropertyChanged(nameof(SelectedItem));
OnItemSelected(value); // Metod som triggas vid val
}
}
}
private void OnItemSelected(Participant item)
{
if (_roundElements.Count == 0)
if (RoundElements.Count == 0)
{
var GameRound = new GameRound
{
@ -110,41 +104,12 @@ public class RoundStartingViewModel : ViewModelBase
newElement.GameRoundId = GamePointStart.GameRoundId;
newElement.GamePointId = GamePointStart.GamePointId;
_roundElements.Add(newElement);
RoundElements.Add(newElement);
// Gör något med det valda objektet
Debug.WriteLine($"Du valde: {item.LastNameFirstName}");
}
public GameRound? GameRoundObject
{
get { return _GameRoundObject; }
set
{
_GameRoundObject = value;
RaisePropertyChanged(nameof(GameRoundObject));
}
}
public ObservableCollection<RoundBuilderGroup> GameRoundList
{
get { return _GameRoundList; }
set
{
_GameRoundList = value;
RaisePropertyChanged(nameof(GameRoundList));
}
}
public ObservableCollection<Participant> ParticipantList
{
get { return _ParticipantList; }
set
{
_ParticipantList = value;
RaisePropertyChanged(nameof(ParticipantList));
}
}
#region Get Method
public ObservableCollection<RoundBuilderGroup> Get()
@ -205,7 +170,9 @@ public class RoundStartingViewModel : ViewModelBase
return GameRoundObject;
}
public virtual bool Save()
[RelayCommand]
public async Task<bool> SaveAsync()
{
if (_roundsRepo == null || GameRoundObject == null)
{
@ -218,11 +185,13 @@ public class RoundStartingViewModel : ViewModelBase
GameRoundObject = new GameRound();
RoundElements.Clear();
this.Get();
await Shell.Current.GoToAsync("..");
}
return tmp;
}
public void Rensa()
[RelayCommand]
private async Task RensaAsync()
{
foreach (var element in RoundElements)
{
@ -230,22 +199,29 @@ public class RoundStartingViewModel : ViewModelBase
}
_roundsRepo?.DeleteById(GameRoundObject?.GameRoundId ?? 0);
RoundElements.Clear();
await Shell.Current.GoToAsync("..");
}
public void RoundSelected(RoundBuilderElement element)
[RelayCommand]
public async Task RoundSelected(RoundBuilderElement element)
{
var rbGroup = GameRoundList.FirstOrDefault(g => g.GameRoundId == element.GameRoundId);
Debug.WriteLine($"Du valde raden med Runda {element.GameRoundId} och spelare: {element.ParticipantName}");
if (rbGroup != null)
{
_objectMessage.CurrentGroup = rbGroup;
Shell.Current.GoToAsync("//RoundRunningView");
//await Shell.Current.GoToAsync("//RoundRunningView");
await Shell.Current.GoToAsync("//RoundRunningView");
}
}
public void SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
[RelayCommand]
public async Task<bool> SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
{
bool goneOk = false;
Debug.WriteLine($"Du valde raden med Runda {roundBuilder.GameRoundId} och spelare: {roundBuilder.ParticipantName}");
goneOk = true;
return goneOk;
}
#endregion

View File

@ -1,66 +0,0 @@
using Common.Library;
using GreadyPoang.EntityLayer;
using GreadyPoang.ViewModelLayer;
using System.Windows.Input;
namespace GreadyPoang.CommandClasses;
public class ParticipantViewModelCommands : ParticipantViewModel
{
#region constructors
public ParticipantViewModelCommands() : base()
{
}
public ParticipantViewModelCommands(IRepository<Participant> repo, IMethodSharingService<Participant> sharingService) : base(repo, sharingService)
{
}
#endregion
#region Private Variables
private bool _IsSaveCommandEnabled = true;
#endregion
#region Public Properties
public bool IsSaveCommandEnabled
{
get { return _IsSaveCommandEnabled; }
set
{
_IsSaveCommandEnabled = value;
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
}
}
#endregion
#region Commands
public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
#endregion
#region Init Method
public override void Init()
{
base.Init();
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
}
#endregion
protected async Task EditAsync(int id)
{
await Shell.Current.GoToAsync($"{nameof(Views.ParticipantListView)}?id={id}");
}
public async Task<bool> SaveAsync()
{
var ret = base.Save();
if (ret)
{
await Shell.Current.GoToAsync("..");
}
return ret;
}
}

View File

@ -1,56 +0,0 @@
using Common.Library;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
using System.Windows.Input;
namespace GreadyPoang.CommandClasses;
public class RoundRunningViewModelCommands : RoundRunningViewModel
{
public RoundRunningViewModelCommands() : base()
{
}
public RoundRunningViewModelCommands(
IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined,
IObjectMessageService objectMessage)
: base(roundsRepo,
pointsRepo,
sharingService,
combined,
objectMessage)
{
}
#region Commands
public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
public ICommand RensaCommand { get; private set; }
public ICommand ElementTappedCommand { get; private set; }
public ICommand ParticipantTappedCommand { get; private set; }
public ICommand StoreAndHandlePointsCommand { get; private set; }
#endregion
public override void Init()
{
base.Init();
StoreAndHandlePointsCommand = new Command(async () => StoreAndHandleAsync());
//EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
//RensaCommand = new Command(async () => RensaAsync());
//ParticipantTappedCommand = new Command<RoundBuilderElement>(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant));
//ElementTappedCommand = new Command<RoundBuilderElement>((selectedElement) => RoundSelected(selectedElement));
}
private async Task StoreAndHandleAsync()
{
base.StoreAndHandlePoints();
await Shell.Current.GoToAsync("..");
}
}

View File

@ -1,107 +0,0 @@
using Common.Library;
using GreadyPoang.DataLayer;
using GreadyPoang.EntityLayer;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
using System.Windows.Input;
namespace GreadyPoang.CommandClasses;
public class RoundStartingViewModelCommands : RoundStartingViewModel
{
public RoundStartingViewModelCommands() : base()
{
}
public RoundStartingViewModelCommands(
IRepository<GameRound> roundsRepo,
IRepository<GamePoint> pointsRepo,
IMethodSharingService<Participant> sharingService,
ICombinedRepository combined,
IObjectMessageService objectMessage)
: base(roundsRepo,
pointsRepo,
sharingService,
combined,
objectMessage)
{
}
#region Private Variables
private bool _IsSaveCommandEnabled = true;
#endregion
#region Public Properties
public bool IsSaveCommandEnabled
{
get { return _IsSaveCommandEnabled; }
set
{
_IsSaveCommandEnabled = value;
RaisePropertyChanged(nameof(IsSaveCommandEnabled));
}
}
#endregion
#region Commands
public ICommand SaveCommand { get; private set; }
public ICommand EditCommand { get; private set; }
public ICommand RensaCommand { get; private set; }
public ICommand ElementTappedCommand { get; private set; }
public ICommand ParticipantTappedCommand { get; private set; }
#endregion
#region Init Method
public override void Init()
{
base.Init();
SaveCommand = new Command(async () => SaveAsync(), () => IsSaveCommandEnabled);
EditCommand = new Command<int>(async (id) => await EditAsync(id), (id) => id > 0);
RensaCommand = new Command(async () => RensaAsync());
ParticipantTappedCommand = new Command<RoundBuilderElement>(async (selectedParticipant) => SelectNewlyAddedParticipant(selectedParticipant));
ElementTappedCommand = new Command<RoundBuilderElement>((selectedElement) => RoundSelected(selectedElement));
}
private async Task RensaAsync()
{
base.Rensa();
await Shell.Current.GoToAsync("..");
}
#endregion
protected async Task EditAsync(int id)
{
await Shell.Current.GoToAsync($"{nameof(Views.RoundStartingView)}?id={id}");
}
public async Task<bool> SaveAsync()
{
var ret = base.Save();
if (ret)
{
await Shell.Current.GoToAsync("..");
}
return ret;
}
public async Task<bool> RoundSelected(RoundBuilderElement element)
{
bool goneOk = false;
base.RoundSelected(element);
goneOk = true;
return goneOk;
}
public async Task<bool> SelectNewlyAddedParticipant(RoundBuilderElement roundBuilder)
{
bool goneOk = false;
base.SelectNewlyAddedParticipant(roundBuilder);
goneOk = true;
return goneOk;
}
}

View File

@ -60,6 +60,16 @@
</ItemGroup>
<ItemGroup>
<Compile Remove="Views\RoundRunningViewOld.xaml.cs" />
</ItemGroup>
<ItemGroup>
<MauiXaml Remove="Views\RoundRunningViewOld.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="12.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.100" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
@ -75,6 +85,9 @@
</ItemGroup>
<ItemGroup>
<Compile Update="Popups\InfoPopup.xaml.cs">
<DependentUpon>InfoPopup.xaml</DependentUpon>
</Compile>
<Compile Update="Views\ParticipantListView.xaml.cs">
<DependentUpon>ParticipantListView.xaml</DependentUpon>
</Compile>
@ -87,6 +100,9 @@
<MauiXaml Update="ViewsPartial\HeaderView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Popups\InfoPopup.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ParticipantListView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

View File

@ -1,8 +1,9 @@
using Common.Library;
using GreadyPoang.CommandClasses;
using CommunityToolkit.Maui;
using GreadyPoang.DataLayer;
using GreadyPoang.DataLayer.Database;
using GreadyPoang.EntityLayer;
using GreadyPoang.Popups;
using GreadyPoang.Services;
using GreadyPoang.ViewModelLayer;
using GreadyPoang.Views;
@ -19,6 +20,8 @@ public static class MauiProgram
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit(options =>
options.SetShouldEnableSnackbarOnWindows(true))
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
@ -30,33 +33,36 @@ public static class MauiProgram
builder.Services.AddDbContext<DataContext>(options =>
{
var MauiDataPath = FileSystem.Current.AppDataDirectory;
if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"))) ;
{
File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"), MauiDataPath);
}
//if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"))) ;
//{
// File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MauiDataPath_GreadyPoang.txt"), MauiDataPath);
//}
var dbPath = Path.Combine(MauiDataPath, "PoangDB.db");
options.UseSqlite($"Data Source={dbPath}");
});
builder.Services.AddScoped<IRepository<Participant>, ParticipantRepository>();
builder.Services.AddScoped<ParticipantViewModelCommands>();
builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>();
builder.Services.AddScoped<ParticipantViewModel>();
builder.Services.AddScoped<ParticipantListView>();
builder.Services.AddScoped<IRepository<GameRound>, GameRoundRepository>();
builder.Services.AddScoped<RoundStartingViewModelCommands>();
builder.Services.AddScoped<RoundStartingViewModel>();
builder.Services.AddScoped<RoundStartingView>();
builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>();
builder.Services.AddScoped<RoundRunningViewModelCommands>();
builder.Services.AddScoped<RoundRunningView>();
builder.Services.AddScoped<IRepository<GamePoint>, GamePointRepository>();
builder.Services.AddScoped<IMethodSharingService<Participant>, MethodSharingService>();
builder.Services.AddScoped<RoundRunningViewModel>();
builder.Services.AddScoped<RoundRunningView>();
builder.Services.AddScoped<ICombinedRepository, CombinedRepository>();
builder.Services.AddSingleton<IObjectMessageService, ObjectMessageService>();
builder.Services.AddTransientPopup<InfoPopup, InfoPopupViewModel>();
builder.Services.AddSingleton<IPopupEventHub, PopupEventHub>();
#if DEBUG
builder.Logging.AddDebug();

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModels="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
x:Class="GreadyPoang.Popups.InfoPopup"
HorizontalOptions="Center"
VerticalOptions="Center"
Padding="0"
x:DataType="viewModels:InfoPopupViewModel"
BackgroundColor="Transparent">
<VerticalStackLayout BackgroundColor="Aquamarine" Padding="5" Margin="0">
<Label HorizontalOptions="Center" TextColor="BlueViolet" Text="{Binding Title}" Style="{StaticResource Headline}" />
<Label HorizontalOptions="Center" Text="{Binding Name}" Style="{StaticResource SubHeadline}"/>
<Label HorizontalOptions="Center" Text="{Binding Message}" Style="{StaticResource StatusLabelStyle}"/>
<!--<Label Text="What is your name?" />
<Entry Text="{Binding Name}" />
<Button Text="Save" Command="{Binding SaveCommand}" />-->
<Button Margin="10" Text="Cancel" Command="{Binding CancelCommand}" Style="{StaticResource HoverButtonBlueStyle}" />
</VerticalStackLayout>
</ContentView>

View File

@ -0,0 +1,13 @@
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Popups;
public partial class InfoPopup : ContentView
{
public InfoPopup(InfoPopupViewModel ipViewModel)
{
InitializeComponent();
BindingContext = ipViewModel;
}
}

View File

@ -2,7 +2,10 @@
<?xaml-comp compile="true" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common" >
<local:HeaderColorConverter x:Key="HeaderColorConverter" />
<Style TargetType="StackLayout" x:Key="ResponsiveStackStyle">
<Setter Property="Orientation" Value="Horizontal"/>
@ -55,6 +58,12 @@
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Cancelled">
<Setter Property="BackgroundColor" Value="LightCoral" />
</DataTrigger>
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Winning">
<Setter Property="BackgroundColor" Value="Yellow" />
</DataTrigger>
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Winner">
<Setter Property="BackgroundColor" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>

View File

@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
xmlns:vm="clr-namespace:GreadyPoang.CommandClasses"
xmlns:vm="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:Class="GreadyPoang.Views.ParticipantListView"
x:DataType="vm:ParticipantViewModelCommands"
x:DataType="vm:ParticipantViewModel"
x:Name="ParticipantListPage"
Title="Deltagar Lista">
<!--xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"-->
<Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
@ -20,11 +23,16 @@
Grid.ColumnSpan="2"
ViewTitle="Deltagare"
ViewDescription="Lägg till deltagare här" />
<Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" Grid.Row="1">
<ActivityIndicator Grid.Row="1" IsRunning="{Binding IsBusy}"
IsVisible="{Binding IsBusy}"
Color="DarkBlue"
HeightRequest="40" />
<Border Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" Grid.Row="2">
<VerticalStackLayout Spacing="4" >
<Label Style="{StaticResource Label}"
<!--<Label Style="{StaticResource SubHeadline}"
Text="Deltagare "
FontAttributes="Bold" FontSize="Large"/>
FontAttributes="Bold" />-->
<Grid ColumnDefinitions="Auto,Auto,*" RowDefinitions="Auto,auto,auto,auto"
Padding="10" RowSpacing="8">
<Label Grid.Row="0" Grid.Column="0" Style="{StaticResource Label}"
@ -58,7 +66,7 @@
</Grid>
</VerticalStackLayout>
</Border>
<Border Grid.Row="2" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5">
<Border Grid.Row="3" Stroke="Gold" BackgroundColor="Ivory" StrokeThickness="2" Padding="5">
<CollectionView
x:Name="participants"
SelectionMode="Single"
@ -67,7 +75,6 @@
ItemsUpdatingScrollMode="KeepLastItemInView">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Participant">
<!--Stroke="DarkGray" BackgroundColor="Cornsilk"-->
<Border Margin="8" Padding="12" >
<VerticalStackLayout Spacing="4">
<Label FontAttributes="Bold"
@ -76,7 +83,14 @@
Text="{Binding LastNameFirstName}" />
<HorizontalStackLayout >
<Button Text="Edit" Style="{StaticResource HoverButtonBlueStyle}" CommandParameter="{Binding EditCommand}"/>
<Button Style="{StaticResource HoverButtonRedStyle}" Text="Delete" />
<Button Text="Delete" Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding Source={RelativeSource AncestorType={x:Type vm:ParticipantViewModel}}, Path=DeleteAsyncCommand}"
CommandParameter="{Binding .}" />
<!--Command="{Binding BindingContext.ParticipantTappedCommand, Source={x:Reference Name=ParticipantList}}"
CommandParameter="{Binding .}" />-->
</HorizontalStackLayout>
</VerticalStackLayout>
</Border>
@ -84,6 +98,7 @@
</CollectionView.ItemTemplate>
</CollectionView>
</Border>
</Grid>
</Border>
</ContentPage>

View File

@ -1,16 +1,16 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Views;
public partial class ParticipantListView : ContentPage
{
public ParticipantListView(ParticipantViewModelCommands viewModel)
public ParticipantListView(ParticipantViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
}
public ParticipantViewModelCommands ViewModel { get; set; }
public ParticipantViewModel ViewModel { get; set; }
public int ParticipantId { get; set; }
protected override void OnAppearing()
@ -20,8 +20,11 @@ public partial class ParticipantListView : ContentPage
ViewModel.Get();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ViewModel.PopupVisad = false;
}
}

View File

@ -3,14 +3,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
x:Class="GreadyPoang.Views.RoundRunningView"
xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses"
xmlns:vm ="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
xmlns:behaviors="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common"
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundRunningViewModelCommands"
x:DataType="vm:RoundRunningViewModel"
Title="RoundRunningView">
<Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Border
behaviors:LoadedBehavior.Command="{Binding OnLoadedCommand}"
Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@ -27,6 +27,7 @@
<CollectionView Grid.Row="1"
ItemsSource="{Binding RoundElements}"
ItemsLayout="HorizontalList"
HeightRequest="125"
Margin="2">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement">
@ -78,23 +79,44 @@
<Entry.Behaviors>
<behaviors:DigitsOnlyBehavior/>
<behaviors:EventToCommandBehavior EventName="Completed"
Command="{Binding StoreAndHandlePointsCommand}" />
Command="{Binding StoreAndHandlePointsAsyncCommand}" />
</Entry.Behaviors>
</Entry>
</Grid>
<Button Text="Register Points"
Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding StoreAndHandlePointsCommand}"/>
Command="{Binding StoreAndHandlePointsAsyncCommand}"/>
</HorizontalStackLayout>
</Border>
<ScrollView Grid.Row="4" Orientation="Horizontal">
<Grid
x:Name="ScoreGrid"
ColumnSpacing="5"
RowSpacing="5"
Padding="3"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
<HorizontalStackLayout
BindableLayout.ItemsSource="{Binding ScoreColumns}"
x:Name="ScoreGrid">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:ScoreColumn">
<VerticalStackLayout BindableLayout.ItemsSource="{Binding Cells}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:ScoreCell">
<Border
Stroke="Gray"
StrokeThickness="1"
BackgroundColor="{Binding IsHeader, Converter={StaticResource HeaderColorConverter}}"
Margin="1"
Padding="2">
<Label
Text="{Binding Text}"
FontAttributes="{Binding IsHeader, Converter={StaticResource FontWeightConverter}}"
TextColor="{Binding IsHeader, Converter={StaticResource TextColorConverter}}"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Border>
</DataTemplate>
</BindableLayout.ItemTemplate>
</VerticalStackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</HorizontalStackLayout>
</ScrollView>
</Grid>
</Border>

View File

@ -1,95 +1,12 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.EntityLayer;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Views;
public partial class RoundRunningView : ContentPage
{
public RoundRunningView(RoundRunningViewModelCommands viewModel)
public RoundRunningView(RoundRunningViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = ViewModel;
ViewModel.Get();
//BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
ViewModel.RebuildRequested += ViewModel_RebuildRequested;
}
private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
}
//protected override
public RoundRunningViewModelCommands ViewModel { get; set; }
private void BuildScoreGrid(IEnumerable<PlayerColumn> columns)
{
ScoreGrid.ColumnDefinitions.Clear();
ScoreGrid.RowDefinitions.Clear();
ScoreGrid.Children.Clear();
int maxRows = columns.Max(c => c.Values.Count);
// Skapa rader
for (int row = 0; row < maxRows + 1; row++) // +1 f<>r rubrikraden
{
ScoreGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
}
int colIndex = 0;
foreach (var column in columns)
{
ScoreGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var headerCell = CreateCell(column.PlayerName, isHeader: true);
ScoreGrid.Children.Add(headerCell);
Grid.SetRow(headerCell, 0);
Grid.SetColumn(headerCell, colIndex);
// V<>rdeceller
for (int rowIndex = 0; rowIndex < column.Values.Count; rowIndex++)
{
var value = column.Values[rowIndex];
var cell = CreateCell(value);
ScoreGrid.Children.Add(cell);
Grid.SetRow(cell, rowIndex + 1); // +1 f<>r att hoppa <20>ver rubrikraden
Grid.SetColumn(cell, colIndex);
}
colIndex++;
BindingContext = viewModel;
}
}
private View CreateCell(string text, bool isHeader = false)
{
return new Border
{
Stroke = Colors.Gray,
StrokeThickness = 1,
BackgroundColor = isHeader ? Colors.DarkGray : Colors.Yellow,
Margin = 1,
Padding = 2,
Content = new Label
{
Text = text,
FontAttributes = isHeader ? FontAttributes.Bold : FontAttributes.None,
TextColor = isHeader ? Colors.White : Colors.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
}
};
}
}

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
x:Class="GreadyPoang.Views.RoundRunningView"
xmlns:vm ="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
xmlns:behaviors="clr-namespace:GreadyPoang.Common;assembly=GreadyPoang.Common"
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundRunningViewModel"
Title="RoundRunningView">
<Border Style="{StaticResource Border.Page}" StrokeThickness="4">
<Grid Style="{StaticResource Grid.Page}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<partial:HeaderView Grid.Row="0"
Grid.ColumnSpan="2"
ViewTitle="Starta eller fortsätt en registrerad Runda"
ViewDescription="Deltagarna visas först!" />
<CollectionView Grid.Row="1"
ItemsSource="{Binding RoundElements}"
ItemsLayout="HorizontalList"
Margin="2">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement">
<Border Stroke="Gray"
Padding="10"
Margin="5"
StrokeShape="RoundRectangle 10"
Style="{StaticResource StatusBorderStyle}">
<Border.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ParticipantTappedCommand}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Grid VerticalOptions="Fill" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="Spelare" />
<Label Grid.Row="1" Text="{Binding ParticipantName}" FontAttributes="Bold" Style="{StaticResource StatusLabelStyle}" />
<Label Grid.Row="2" Text="{Binding GameRegPoints, StringFormat='Poäng: {0}'}" Style="{StaticResource StatusLabelStyle}" />
<Label Grid.Row="3" Text="{Binding Status}" Style="{StaticResource StatusLabelStyle}"/>
<Label Grid.Row="4" Text="{Binding GameRoundStartDate, StringFormat='Start: {0:yyyy-MM-dd}'}" Style="{StaticResource StatusLabelStyle}"/>
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<BoxView
Grid.Row="2"
Grid.ColumnSpan="2"
Margin="0,0,0,5"
HeightRequest="1"
Color="Black" />
<Border Grid.Row="3">
<HorizontalStackLayout>
<Grid VerticalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Text="{Binding BuilderObject.GameRoundId, StringFormat='Runda: {0}'}"/>
<Label Grid.Row="1" Text="{Binding BuilderObject.ParticipantName}" FontAttributes="Bold" FontSize="Subtitle" />
<Entry Grid.Row="2" x:Name="Points" Placeholder="Latest Points" Text="{Binding BuilderObject.GameRegPoints}" FontAttributes="Bold" FontSize="20" >
<Entry.Behaviors>
<behaviors:DigitsOnlyBehavior/>
<behaviors:EventToCommandBehavior EventName="Completed"
Command="{Binding StoreAndHandlePointsAsyncCommand}" />
</Entry.Behaviors>
</Entry>
</Grid>
<Button Text="Register Points"
Style="{StaticResource HoverButtonRedStyle}"
Command="{Binding StoreAndHandlePointsAsyncCommand}"/>
</HorizontalStackLayout>
</Border>
<ScrollView Grid.Row="4" Orientation="Horizontal">
<Grid
x:Name="ScoreGrid"
ColumnSpacing="5"
RowSpacing="5"
Padding="3"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
</ScrollView>
</Grid>
</Border>
</ContentPage>

View File

@ -0,0 +1,105 @@
using GreadyPoang.EntityLayer;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Views;
public partial class RoundRunningView : ContentPage
{
public RoundRunningView(RoundRunningViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
ViewModel.RebuildRequested += ViewModel_RebuildRequested;
this.Loaded += OnPageLoaded;
}
private void OnPageLoaded(object? sender, EventArgs e)
{
ViewModel.Get();
}
protected override void OnAppearing()
{
base.OnAppearing();
BindingContext = ViewModel;
}
private void ViewModel_RebuildRequested(object? sender, EventArgs e)
{
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
}
//protected override
public RoundRunningViewModel ViewModel { get; set; }
private void BuildScoreGrid(IEnumerable<PlayerColumn> columns)
{
ScoreGrid.ColumnDefinitions.Clear();
ScoreGrid.RowDefinitions.Clear();
ScoreGrid.Children.Clear();
int maxRows = columns.Max(c => c.Values.Count);
// Skapa rader
for (int row = 0; row < maxRows + 1; row++) // +1 f<>r rubrikraden
{
ScoreGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
}
int colIndex = 0;
foreach (var column in columns)
{
ScoreGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
var headerCell = CreateCell(column.PlayerName, isHeader: true);
ScoreGrid.Children.Add(headerCell);
Grid.SetRow(headerCell, 0);
Grid.SetColumn(headerCell, colIndex);
// V<>rdeceller
for (int rowIndex = 0; rowIndex < column.Values.Count; rowIndex++)
{
var value = column.Values[rowIndex];
var cell = CreateCell(value);
ScoreGrid.Children.Add(cell);
Grid.SetRow(cell, column.Values.Count - rowIndex); // +1 f<>r att hoppa <20>ver rubrikraden
Grid.SetColumn(cell, colIndex);
}
colIndex++;
}
}
private View CreateCell(string text, bool isHeader = false)
{
return new Border
{
Stroke = Colors.Gray,
StrokeThickness = 1,
BackgroundColor = isHeader ? Colors.DarkGray : Colors.Yellow,
Margin = 1,
Padding = 2,
Content = new Label
{
Text = text,
FontAttributes = isHeader ? FontAttributes.Bold : FontAttributes.None,
TextColor = isHeader ? Colors.White : Colors.Black,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
}
};
}
protected override void OnDisappearing()
{
base.OnDisappearing();
ViewModel.PopupVisad = false;
}
}

View File

@ -3,10 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
x:Class="GreadyPoang.Views.RoundStartingView"
xmlns:vm="clr-namespace:GreadyPoang.CommandClasses"
xmlns:vm="clr-namespace:GreadyPoang.ViewModelLayer;assembly=GreadyPoang.ViewModelLayer"
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
x:DataType="vm:RoundStartingViewModelCommands"
x:DataType="vm:RoundStartingViewModel"
x:Name="GameRoundStartingPage"
Title="Starta ny Runda">
@ -25,7 +25,7 @@
ViewDescription="Välj deltagare och initiera spel" />
<Border Grid.Row="1" Stroke="Gold" StrokeThickness="2" BackgroundColor="LemonChiffon" >
<ScrollView Orientation="Horizontal">
<StackLayout x:Name="ResponsiveStack" Spacing="5" Style="{StaticResource ResponsiveStackStyle}" >
<StackLayout x:Name="ResponsiveStack" Spacing="5" HeightRequest="125" Style="{StaticResource ResponsiveStackStyle}" >
<Border Stroke="Gray"
StrokeThickness="2"
BackgroundColor="LightGray"
@ -64,7 +64,7 @@
>
<Border.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding BindingContext.ParticipantTappedCommand, Source={x:Reference Name=ParticipantList}}"
Command="{Binding BindingContext.SelectNewlyAddedParticipantCommand, Source={x:Reference Name=ParticipantList}}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Border Margin="1" Padding="2" StrokeThickness="3" >
@ -119,6 +119,7 @@
ItemsLayout="HorizontalList"
x:Name="InnerList"
Margin="0,10,0,10"
HeightRequest="90"
ItemSizingStrategy="MeasureAllItems">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:RoundBuilderElement">
@ -129,7 +130,7 @@
Style="{StaticResource StatusBorderStyle}" >
<Border.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Path=BindingContext.ElementTappedCommand,Source={x:Reference OuterList}}"
Command="{Binding Path=BindingContext.RoundSelectedCommand ,Source={x:Reference OuterList}}"
CommandParameter="{Binding .}" />
</Border.GestureRecognizers>

View File

@ -1,4 +1,4 @@
using GreadyPoang.CommandClasses;
using GreadyPoang.ViewModelLayer;
namespace GreadyPoang.Views;
@ -6,12 +6,12 @@ public partial class RoundStartingView : ContentPage
{
public RoundStartingView(RoundStartingViewModelCommands viewModel)
public RoundStartingView(RoundStartingViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
}
public RoundStartingViewModelCommands ViewModel { get; set; }
public RoundStartingViewModel ViewModel { get; set; }
public int GameRoundId { get; set; }