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;
|
||||
_objectMessage = objectMessage;
|
||||
_roundElements = new ObservableCollection<RoundBuilderElement>();
|
||||
_builderObject = new();
|
||||
}
|
||||
|
||||
private readonly IRepository<GameRound>? _roundsRepo;
|
||||
@ -40,6 +41,7 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
|
||||
private ObservableCollection<RoundBuilderGroup> _GameRoundList = new();
|
||||
private ObservableCollection<Participant> _ParticipantList = new();
|
||||
private Collection<PlayerColumn> _playerColumns;
|
||||
|
||||
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()
|
||||
{
|
||||
BuilderObject.ParticipantName = "Kalle Default";
|
||||
|
||||
if (_objectMessage.CurrentGroup != null)
|
||||
{
|
||||
Debug.WriteLine($"Chosen round: {_objectMessage.CurrentGroup.GameRoundId}");
|
||||
@ -65,9 +93,38 @@ public class RoundRunningViewModel : ViewModelBase
|
||||
{
|
||||
_roundElements.Add(item);
|
||||
}
|
||||
FillupResultTable(_objectMessage.CurrentGroup.Elements);
|
||||
}
|
||||
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 ElementTappedCommand { get; private set; }
|
||||
public ICommand ParticipantTappedCommand { get; private set; }
|
||||
public ICommand StoreAndHandlePontsCommand { get; private set; }
|
||||
|
||||
#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"
|
||||
x:Class="GreadyPoang.Views.RoundRunningView"
|
||||
xmlns:vm ="clr-namespace:GreadyPoang.CommandClasses"
|
||||
xmlns:behaviors="clr-namespace:GreadyPoang.ViewHelpers"
|
||||
xmlns:local="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
||||
xmlns:model="clr-namespace:GreadyPoang.EntityLayer;assembly=GreadyPoang.EntityLayer"
|
||||
x:DataType="vm:RoundRunningViewModelCommands"
|
||||
@ -12,6 +13,9 @@
|
||||
<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="*" />
|
||||
@ -23,29 +27,83 @@
|
||||
<CollectionView Grid.Row="1"
|
||||
ItemsSource="{Binding RoundElements}"
|
||||
ItemsLayout="HorizontalList"
|
||||
Margin="5">
|
||||
Margin="2">
|
||||
<CollectionView.ItemTemplate>
|
||||
<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>
|
||||
<TapGestureRecognizer
|
||||
Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ParticipantTappedCommand}"
|
||||
CommandParameter="{Binding .}" />
|
||||
</Border.GestureRecognizers>
|
||||
|
||||
<VerticalStackLayout VerticalOptions="FillAndExpand">
|
||||
<Label Text="Spelare" />
|
||||
<Label Text="{Binding ParticipantName}" FontAttributes="Bold" />
|
||||
<Label Text="{Binding GameRegPoints, StringFormat='Poäng: {0}'}" />
|
||||
<Label Text="{Binding Status}" />
|
||||
<Label Text="{Binding GameRoundStartDate, StringFormat='Start: {0:yyyy-MM-dd}'}" />
|
||||
</VerticalStackLayout>
|
||||
<Border.Triggers>
|
||||
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="New">
|
||||
<Setter Property="BackgroundColor" Value="LightGreen" />
|
||||
</DataTrigger>
|
||||
<DataTrigger TargetType="Border" Binding="{Binding Status}" Value="InProgress">
|
||||
<Setter Property="BackgroundColor" Value="LightYellow" />
|
||||
</DataTrigger>
|
||||
<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>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</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>
|
||||
|
||||
</Border>
|
||||
</ContentPage>
|
||||
@ -1,4 +1,5 @@
|
||||
using GreadyPoang.CommandClasses;
|
||||
using GreadyPoang.EntityLayer;
|
||||
|
||||
namespace GreadyPoang.Views;
|
||||
|
||||
@ -15,7 +16,48 @@ public partial class RoundRunningView : ContentPage
|
||||
base.OnAppearing();
|
||||
BindingContext = ViewModel;
|
||||
ViewModel.Get();
|
||||
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
|
||||
|
||||
}
|
||||
public RoundRunningViewModelCommands ViewModel { 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
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="0,0,0,20"
|
||||
Margin="0,0,0,5"
|
||||
HeightRequest="1"
|
||||
Color="Black" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user