ce qui fonctionne => master
continuous-integration/drone/push Build is passing Details

Popup_qui_marche_pas
Anthony RICHARD 2 years ago
commit a6f0abbecc

@ -74,8 +74,10 @@ namespace Model
}
private ObservableCollection<string> tags;
public ReadOnlyCollection<Review> Reviews => reviews.AsReadOnly();
[DataMember]
public List<Review> Reviews { get; private init; }
private readonly List<Review> reviews;
public double Average => Reviews.Any() ? Math.Round(Reviews.Select(review => review.Rate).Average(), 1) : 0;
@ -104,7 +106,7 @@ namespace Model
else Cover = cover;
if (string.IsNullOrWhiteSpace(c_lien)) Lien = "Pas de lien";
else Lien = c_lien;
Reviews = new List<Review>();
reviews = new List<Review>();
}
public event PropertyChangedEventHandler? PropertyChanged;
@ -147,11 +149,16 @@ namespace Model
public void AddReview(Review review)
{
Reviews.Add(review);
reviews.Add(review);
NotifyPropertyChanged(nameof(Reviews));
NotifyPropertyChanged(nameof(Average));
}
public void RemoveReview(Review review)
{
Reviews.Remove(review);
reviews.Remove(review);
NotifyPropertyChanged(nameof(Reviews));
NotifyPropertyChanged(nameof(Average));
}
public void DescChange(string newdesc)
{

@ -7,7 +7,7 @@ namespace Model
public class Manager
{
public readonly IPersistance mgrpersistance;
public ReadOnlyCollection<Game> GameList { get; private set; }
public ReadOnlyCollection<Game> GameList => gameList.AsReadOnly();
private readonly List<Game> gameList;
public Game? SelectedGame { get; set; }
public User? CurrentUser { get; set; }
@ -17,7 +17,6 @@ namespace Model
{
mgrpersistance = persistance;
gameList = persistance.LoadGame();
GameList = new ReadOnlyCollection<Game>(gameList);
Users = persistance.LoadUser();
}
@ -54,7 +53,11 @@ namespace Model
gameList.Remove(game);
mgrpersistance.SaveGame(gameList);
}
[ExcludeFromCodeCoverage]
public void SaveGames()
{
mgrpersistance.SaveGame(gameList);
}
public User? SearchUser(string username)
{
foreach (User user in Users)
@ -63,5 +66,10 @@ namespace Model
}
return null;
}
[ExcludeFromCodeCoverage]
public void SaveUser()
{
mgrpersistance.SaveUser(Users);
}
}
}

@ -58,7 +58,7 @@ namespace Model
}
public void EditRate(double newval)
{
Rate= newval;
if (newval >= 0 && newval <= 5) Rate= newval;
}
}
}

@ -38,7 +38,7 @@ namespace Model
public string Biographie
{
get => biographie;
private set
set
{
if (string.IsNullOrWhiteSpace(value)) biographie = "Pas de biographie";
else biographie = value;
@ -50,12 +50,15 @@ namespace Model
public string Email
{
get => email;
private set
set
{
Regex rg_email = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$");
if (!(string.IsNullOrWhiteSpace(value)) && rg_email.IsMatch(value)) email = value;
Regex rg_email = new Regex("^([a-zA-Z0-9_-]+[.])*[a-zA-Z0-9_-]+@([a-zA-Z0-9_-]+[.])+[a-zA-Z0-9_-]{2,4}$");
if (!(string.IsNullOrWhiteSpace(value)) && rg_email.IsMatch(value))
{
email = value;
NotifyPropertyChanged();
}
else email = "Default";
NotifyPropertyChanged();
}
}
private string email = default!;
@ -63,7 +66,7 @@ namespace Model
public string Password
{
get => password;
private set
set
{
Regex rg = new Regex("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$");
if (string.IsNullOrWhiteSpace(value) || !rg.IsMatch(value)) throw new ArgumentNullException(value);
@ -122,7 +125,7 @@ namespace Model
return 0;
}
public void AddReview(Game game, float rate, string text)
public void AddReview(Game game, double rate, string text)
{
game.AddReview(new Review(Username, rate, text));
}
@ -155,5 +158,6 @@ namespace Model
foreach (Game game in Followed_Games) builder.Append($"{game.Name}\n");
return builder.ToString();
}
}
}

@ -16,7 +16,7 @@ public partial class Create : ContentPage
{
if (((App)App.Current).Manager.SearchUser(Username.Text) == null)
{
Regex rg = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$");
Regex rg = new Regex("^([a-zA-Z0-9_-]+[.])*[a-zA-Z0-9_-]+@([a-zA-Z0-9_-]+[.])+[a-zA-Z0-9_-]{2,4}$");
if (rg.IsMatch(Email.Text))
{
rg = new Regex("^(?=.*[A-Za-z])(?=.*[0-9@$!%*#?&])[A-Za-z-0-9@$!%*#?&]{8,}$");

@ -1,6 +1,5 @@
using CommunityToolkit.Maui.Views;
using Model;
using StimPersistance;
namespace Stim;
@ -9,8 +8,8 @@ public partial class DetailledPage : ContentPage
public DetailledPage()
{
InitializeComponent();
BindingContext = (App.Current as App).Manager.SelectedGame;
if ((App.Current as App).Manager.SelectedGame is null) Navigation.RemovePage(this);
BindingContext = (App.Current as App).Manager.SelectedGame;
}
private async void GoToMainPage(object sender, EventArgs e)
@ -18,9 +17,9 @@ public partial class DetailledPage : ContentPage
await Navigation.PushModalAsync(new MainPage());
}
private void AddReview(object sender, EventArgs e)
private async void AddReview(object sender, EventArgs e)
{
//popup add review
await this.ShowPopupAsync(new ReviewPopUp());
}
private async void AddFollow(object sender, EventArgs e)

@ -10,5 +10,6 @@
<Entry Grid.Row="1" x:Name="Entrytxt" VerticalOptions="Center" HorizontalOptions="Center"/>
<Button Grid.Row="2" Text="Valider" Style="{StaticResource popupButton}" Clicked="Valider"/>
<Button Grid.Row="3" Text="Annuler" Style="{StaticResource popupButton}" Clicked="CloseButton"/>
</Grid>
<HorizontalStackLayout x:Name="Error"/>
</Grid>
</toolkit:Popup>

@ -12,11 +12,12 @@ public partial class EntryPopup : Popup
public void CloseButton(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Entrytxt.Text)) Close(Entrytxt.Text);
Close();
}
private void Valider(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Entrytxt.Text)) Close(Entrytxt.Text);
else Error.Children.Add(new Label { Text="Champ vide", TextColor=Colors.Red });
}
}

@ -5,10 +5,10 @@
Title="LoginPage">
<ScrollView>
<Grid BackgroundColor="{StaticResource Tertiary}" ColumnDefinitions="*, 5*, *" RowDefinitions="auto, *">
<VerticalStackLayout BackgroundColor="Black" Grid.Column="0"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="2"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="0" Grid.Row="1"/>
<VerticalStackLayout BackgroundColor="Black" Grid.Column="2" Grid.Row="1"/>
<VerticalStackLayout Style="{StaticResource pageBorder}" Grid.Column="0"/>
<VerticalStackLayout Style="{StaticResource pageBorder}" Grid.Column="2"/>
<VerticalStackLayout Style="{StaticResource pageBorder}" Grid.Column="0" Grid.Row="1"/>
<VerticalStackLayout Style="{StaticResource pageBorder}" Grid.Column="2" Grid.Row="1"/>
<Grid Grid.Column="1" RowDefinitions="500, auto, auto">
<Image Source="no_cover.png" HeightRequest="490" Margin="0,10,0,0"/>
<Grid Grid.Row="1" RowDefinitions="auto, auto, auto">

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup 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"
x:Class="Stim.ReviewPopUp"
CanBeDismissedByTappingOutsideOfPopup="False">
<Grid ColumnDefinitions="*" RowDefinitions="*, *, *, *, *">
<Label x:Name="placeholder" Style="{StaticResource popupLabel}"/>
<Entry Grid.Row="1" x:Name="Entrytxt" VerticalOptions="Center" HorizontalOptions="Center"/>
<Entry Grid.Row="2" x:Name="Val" VerticalOptions="Center" HorizontalOptions="Center"/>
<Button Grid.Row="3" Text="Valider" Style="{StaticResource popupButton}" Clicked="Valider"/>
<Button Grid.Row="4" Text="Annuler" Style="{StaticResource popupButton}" Clicked="CloseButton"/>
<HorizontalStackLayout x:Name="Error"/>
</Grid>
</toolkit:Popup>

@ -0,0 +1,34 @@
using CommunityToolkit.Maui.Views;
using Model;
using System.Globalization;
namespace Stim;
public partial class ReviewPopUp : Popup
{
public ReviewPopUp()
{
InitializeComponent();
}
public void CloseButton(object sender, EventArgs e)
{
Close();
}
private void Valider(object sender, EventArgs e)
{
if ((App.Current as App).Manager.SelectedGame == null)
{
throw new Exception();
}
bool isDouble = double.TryParse(Val.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out double rate);
if (!string.IsNullOrWhiteSpace(Entrytxt.Text) && isDouble)
{
((App)App.Current).Manager.CurrentUser.AddReview((App.Current as App).Manager.SelectedGame, rate, Entrytxt.Text);
((App)App.Current).Manager.SaveGames();
Close();
}
else Error.Children.Add(new Label { Text="Champ vide ou invalide", TextColor=Colors.Red });
}
}

@ -65,6 +65,9 @@
<Compile Update="DetailledPage - Copier.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
<Compile Update="ReviewPopUp.xaml.cs">
<DependentUpon>ReviewPopUp.xaml</DependentUpon>
</Compile>
<Compile Update="LoginPage.xaml.cs">
<DependentUpon>LoginPage.xaml</DependentUpon>
</Compile>
@ -89,6 +92,9 @@
<MauiXaml Update="DetailledPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="ReviewPopUp.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="EntryPopup.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -58,9 +58,9 @@ namespace Test
{
Review rev = new("User 1", 3, "rev");
rev.EditRate(-2);
Assert.Equal(0, rev.Rate);
Assert.Equal(3, rev.Rate);
rev.EditRate(18);
Assert.Equal(0, rev.Rate);
Assert.Equal(3, rev.Rate);
rev.EditRate(4.5f);
Assert.Equal(4.5f, rev.Rate);
}

@ -112,6 +112,7 @@ namespace Test
public void Hashcode()
{
User user = new("userimage", "username", "biographie", "adresse.mail@gmail.com", "Azerty123*");
Assert.Equal(user.GetHashCode(), user.Username?.GetHashCode());
}
}
}

Loading…
Cancel
Save