Nu finns registrering av poäng och struktur för att lägga ut på ett teststadium
This commit is contained in:
32
GreadyPoang.EntityLayer/HelperEntities/PlayerColumn.cs
Normal file
32
GreadyPoang.EntityLayer/HelperEntities/PlayerColumn.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using Common.Library;
|
||||||
|
|
||||||
|
namespace GreadyPoang.EntityLayer;
|
||||||
|
|
||||||
|
public class PlayerColumn : EntityBase
|
||||||
|
{
|
||||||
|
public PlayerColumn()
|
||||||
|
{
|
||||||
|
_playerName = string.Empty;
|
||||||
|
_values = new List<string>();
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,6 +29,7 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
_combined = combined;
|
_combined = combined;
|
||||||
_objectMessage = objectMessage;
|
_objectMessage = objectMessage;
|
||||||
_roundElements = new ObservableCollection<RoundBuilderElement>();
|
_roundElements = new ObservableCollection<RoundBuilderElement>();
|
||||||
|
_builderObject = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IRepository<GameRound>? _roundsRepo;
|
private readonly IRepository<GameRound>? _roundsRepo;
|
||||||
@ -40,6 +41,7 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
|
|
||||||
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
|
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
|
||||||
private ObservableCollection<Participant> _ParticipantList = new();
|
private ObservableCollection<Participant> _ParticipantList = new();
|
||||||
|
private Collection<PlayerColumn> _playerColumns;
|
||||||
|
|
||||||
public ObservableCollection<RoundBuilderElement> RoundElements
|
public ObservableCollection<RoundBuilderElement> RoundElements
|
||||||
{
|
{
|
||||||
@ -51,9 +53,35 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<PlayerColumn> PlayerColumns
|
||||||
|
{
|
||||||
|
get { return _playerColumns; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_playerColumns = value;
|
||||||
|
RaisePropertyChanged(nameof(PlayerColumns));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private RoundBuilderElement _builderObject;
|
||||||
|
|
||||||
|
public RoundBuilderElement BuilderObject
|
||||||
|
{
|
||||||
|
get { return _builderObject; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_builderObject = value;
|
||||||
|
RaisePropertyChanged(nameof(BuilderObject));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ObservableCollection<RoundBuilderElement> Get()
|
public ObservableCollection<RoundBuilderElement> Get()
|
||||||
{
|
{
|
||||||
|
BuilderObject.ParticipantName = "Kalle Default";
|
||||||
|
|
||||||
if (_objectMessage.CurrentGroup != null)
|
if (_objectMessage.CurrentGroup != null)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}");
|
Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}");
|
||||||
@ -65,9 +93,38 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
_roundElements.Add(item);
|
_roundElements.Add(item);
|
||||||
}
|
}
|
||||||
|
FillupResultTable(_objectMessage.CurrentGroup.Elements);
|
||||||
}
|
}
|
||||||
return RoundElements;
|
return RoundElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FillupResultTable(List<RoundBuilderElement> elements)
|
||||||
|
{
|
||||||
|
Random slumper = new Random();
|
||||||
|
if (_playerColumns != null)
|
||||||
|
{
|
||||||
|
_playerColumns.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_playerColumns = new Collection<PlayerColumn>();
|
||||||
|
}
|
||||||
|
foreach (var element in elements)
|
||||||
|
{
|
||||||
|
var player = new PlayerColumn
|
||||||
|
{
|
||||||
|
PlayerName = element.ParticipantName
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < slumper.Next(6); i++)
|
||||||
|
{
|
||||||
|
player.Values.Add(slumper.Next(1, 10).ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
_playerColumns.Add(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,23 @@ public class RoundRunningViewModelCommands : RoundRunningViewModel
|
|||||||
public ICommand RensaCommand { get; private set; }
|
public ICommand RensaCommand { get; private set; }
|
||||||
public ICommand ElementTappedCommand { get; private set; }
|
public ICommand ElementTappedCommand { get; private set; }
|
||||||
public ICommand ParticipantTappedCommand { get; private set; }
|
public ICommand ParticipantTappedCommand { get; private set; }
|
||||||
|
public ICommand StoreAndHandlePontsCommand { get; private set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
base.Init();
|
||||||
|
StoreAndHandlePontsCommand = new Command(async () => StoreAndHandle());
|
||||||
|
//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 void StoreAndHandle()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
GreadyPoang/ViewHelpers/DigitsOnlyBehavior.cs
Normal file
38
GreadyPoang/ViewHelpers/DigitsOnlyBehavior.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace GreadyPoang.ViewHelpers;
|
||||||
|
|
||||||
|
public class DigitsOnlyBehavior : Behavior<Entry>
|
||||||
|
{
|
||||||
|
protected override void OnAttachedTo(Entry entry)
|
||||||
|
{
|
||||||
|
entry.TextChanged += OnTextChanged;
|
||||||
|
base.OnAttachedTo(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDetachingFrom(Entry entry)
|
||||||
|
{
|
||||||
|
entry.TextChanged -= OnTextChanged;
|
||||||
|
base.OnDetachingFrom(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var entry = sender as Entry;
|
||||||
|
if (entry == null) return;
|
||||||
|
|
||||||
|
// Tillåt endast siffror (0–9)
|
||||||
|
if (!Regex.IsMatch(e.NewTextValue, @"^\d*$"))
|
||||||
|
{
|
||||||
|
entry.Text = e.OldTextValue; // Återställ till tidigare giltigt värde
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Vill du tillåta decimaler? Ändra regex till @"^\d*\.?\d*$"
|
||||||
|
Vill du tillåta negativa tal? Använd @"^-?\d*$"
|
||||||
|
Vill du visa en varning när användaren skriver fel?
|
||||||
|
Lägg till en BindableProperty för IsValid och bind den till UI.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@
|
|||||||
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
|
xmlns:partial="clr-namespace:GreadyPoang.ViewsPartial"
|
||||||
x:Class="GreadyPoang.Views.RoundRunningView"
|
x:Class="GreadyPoang.Views.RoundRunningView"
|
||||||
xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses"
|
xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses"
|
||||||
|
xmlns:behaviors="clr-namespace:GreadyPoang.ViewHelpers"
|
||||||
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
||||||
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
||||||
x:DataType="vm:RoundRunningViewModelCommands"
|
x:DataType="vm:RoundRunningViewModelCommands"
|
||||||
@ -12,6 +13,9 @@
|
|||||||
<Border Style="{StaticResource Border.Page}" StrokeThickness="4">
|
<Border Style="{StaticResource Border.Page}" StrokeThickness="4">
|
||||||
<Grid Style="{StaticResource Grid.Page}">
|
<Grid Style="{StaticResource Grid.Page}">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
@ -23,29 +27,83 @@
|
|||||||
<CollectionView Grid.Row="1"
|
<CollectionView Grid.Row="1"
|
||||||
ItemsSource="{Binding RoundElements}"
|
ItemsSource="{Binding RoundElements}"
|
||||||
ItemsLayout="HorizontalList"
|
ItemsLayout="HorizontalList"
|
||||||
Margin="5">
|
Margin="2">
|
||||||
<CollectionView.ItemTemplate>
|
<CollectionView.ItemTemplate>
|
||||||
<DataTemplate x:DataType="model:RoundBuilderElement">
|
<DataTemplate x:DataType="model:RoundBuilderElement">
|
||||||
<Border Stroke="Gray" Padding="10" Margin="5">
|
<Border Stroke="Gray"
|
||||||
|
Padding="10"
|
||||||
|
Margin="5"
|
||||||
|
BackgroundColor="{Binding Status, Converter={StaticResource StatusToColorConverter}}"
|
||||||
|
StrokeShape="RoundRectangle 10">
|
||||||
<Border.GestureRecognizers>
|
<Border.GestureRecognizers>
|
||||||
<TapGestureRecognizer
|
<TapGestureRecognizer
|
||||||
Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ParticipantTappedCommand}"
|
Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ParticipantTappedCommand}"
|
||||||
CommandParameter="{Binding .}" />
|
CommandParameter="{Binding .}" />
|
||||||
</Border.GestureRecognizers>
|
</Border.GestureRecognizers>
|
||||||
|
<Border.Triggers>
|
||||||
<VerticalStackLayout VerticalOptions="FillAndExpand">
|
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="New">
|
||||||
<Label Text="Spelare" />
|
<Setter Property="BackgroundColor" Value="LightGreen" />
|
||||||
<Label Text="{Binding ParticipantName}" FontAttributes="Bold" />
|
</DataTrigger>
|
||||||
<Label Text="{Binding GameRegPoints, StringFormat='Poäng: {0}'}" />
|
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="InProgress">
|
||||||
<Label Text="{Binding Status}" />
|
<Setter Property="BackgroundColor" Value="LightYellow" />
|
||||||
<Label Text="{Binding GameRoundStartDate, StringFormat='Start: {0:yyyy-MM-dd}'}" />
|
</DataTrigger>
|
||||||
</VerticalStackLayout>
|
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Completed">
|
||||||
|
<Setter Property="BackgroundColor" Value="DarkGreen" />
|
||||||
|
</DataTrigger>
|
||||||
|
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="Cancelled">
|
||||||
|
<Setter Property="BackgroundColor" Value="LightCoral" />
|
||||||
|
</DataTrigger>
|
||||||
|
</Border.Triggers>
|
||||||
|
<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" />
|
||||||
|
<Label Grid.Row="2" Text="{Binding GameRegPoints, StringFormat='Poäng: {0}'}" />
|
||||||
|
<Label Grid.Row="3" Text="{Binding Status}" />
|
||||||
|
<Label Grid.Row="4" Text="{Binding GameRoundStartDate, StringFormat='Start: {0:yyyy-MM-dd}'}" />
|
||||||
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</CollectionView.ItemTemplate>
|
</CollectionView.ItemTemplate>
|
||||||
</CollectionView>
|
</CollectionView>
|
||||||
<Label Text="{Binding RoundElements.Count, StringFormat='Antal: {0}'}" />
|
<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" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Label Grid.Row="0" Text="{Binding BuilderObject.ParticipantName}" FontAttributes="Bold" FontSize="Subtitle" />
|
||||||
|
<Entry Grid.Row="1" x:Name="Points" Placeholder="Latest Points" Text="{Binding BuilderObject.GameRegPoints}" FontAttributes="Bold" FontSize="20" >
|
||||||
|
<Entry.Behaviors>
|
||||||
|
<behaviors:DigitsOnlyBehavior/>
|
||||||
|
</Entry.Behaviors>
|
||||||
|
</Entry>
|
||||||
|
</Grid>
|
||||||
|
<Button Text="Register Points" Style="{StaticResource HoverButtonRedStyle}" CommandParameter="{Binding StoreAndHandlePontsCommand}"/>
|
||||||
|
</HorizontalStackLayout>
|
||||||
|
</Border>
|
||||||
|
<ScrollView Grid.Row="4">
|
||||||
|
<Grid
|
||||||
|
x:Name="ScoreGrid"
|
||||||
|
ColumnSpacing="10"
|
||||||
|
RowSpacing="10"
|
||||||
|
Padding="10"
|
||||||
|
HorizontalOptions="FillAndExpand"
|
||||||
|
VerticalOptions="FillAndExpand" />
|
||||||
|
</ScrollView>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</Border>
|
</Border>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using GreadyPoang.CommandClasses;
|
using GreadyPoang.CommandClasses;
|
||||||
|
using GreadyPoang.EntityLayer;
|
||||||
|
|
||||||
namespace GreadyPoang.Views;
|
namespace GreadyPoang.Views;
|
||||||
|
|
||||||
@ -15,7 +16,48 @@ public partial class RoundRunningView : ContentPage
|
|||||||
base.OnAppearing();
|
base.OnAppearing();
|
||||||
BindingContext = ViewModel;
|
BindingContext = ViewModel;
|
||||||
ViewModel.Get();
|
ViewModel.Get();
|
||||||
|
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
|
||||||
|
|
||||||
}
|
}
|
||||||
public RoundRunningViewModelCommands ViewModel { get; set; }
|
public RoundRunningViewModelCommands ViewModel { get; set; }
|
||||||
//public int GameRoundId { get; set; }
|
//public int GameRoundId { get; set; }
|
||||||
}
|
|
||||||
|
//--------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void BuildScoreGrid(IEnumerable<PlayerColumn> columns)
|
||||||
|
{
|
||||||
|
ScoreGrid.ColumnDefinitions.Clear();
|
||||||
|
ScoreGrid.Children.Clear();
|
||||||
|
|
||||||
|
int colIndex = 0;
|
||||||
|
foreach (var column in columns)
|
||||||
|
{
|
||||||
|
ScoreGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||||||
|
|
||||||
|
var stack = new VerticalStackLayout();
|
||||||
|
|
||||||
|
stack.Children.Add(new Label
|
||||||
|
{
|
||||||
|
Text = column.PlayerName,
|
||||||
|
FontAttributes = FontAttributes.Bold,
|
||||||
|
HorizontalOptions = LayoutOptions.Center
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var value in column.Values)
|
||||||
|
{
|
||||||
|
stack.Children.Add(new Label
|
||||||
|
{
|
||||||
|
Text = value,
|
||||||
|
HorizontalOptions = LayoutOptions.Center
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreGrid.Children.Add(stack);
|
||||||
|
Grid.SetColumn(stack, colIndex++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<BoxView
|
<BoxView
|
||||||
Grid.ColumnSpan="2"
|
Grid.ColumnSpan="2"
|
||||||
Margin="0,0,0,20"
|
Margin="0,0,0,5"
|
||||||
HeightRequest="1"
|
HeightRequest="1"
|
||||||
Color="Black" />
|
Color="Black" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user