Přidání nového projektu - pokus o explorer

This commit is contained in:
Matěj Kubíček committed 2026-10-13 20:13:07 +02:00
1 parent b0b0b3ee34
commit d06a9f332b
48 files changed
+1429

No files matched your search

@@ -0,0 +1,261 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="winui_learning_2.Views.HomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="using:winui_learning_2.Models"
mc:Ignorable="d">
<Page.Resources>
<Style x:Key="DashboardStatCardStyle" TargetType="Border">
<Setter Property="Width" Value="180"/>
<Setter Property="Padding" Value="16"/>
<Setter Property="CornerRadius" Value="8"/>
<Setter Property="Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}"/>
<Setter Property="BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
<Style x:Key="DashboardStatNumberStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="24"/>
<Setter Property="FontWeight" Value="SemiBold"/>
</Style>
<Style x:Key="DashboardStatTitleStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="13"/>
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}"/>
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
<Style x:Key="DashboardPanelStyle" TargetType="Border">
<Setter Property="Padding" Value="16"/>
<Setter Property="CornerRadius" Value="8"/>
<Setter Property="Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}"/>
<Setter Property="BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
<DataTemplate x:Key="ActivityRowTemplate" x:DataType="models:ActivityDisplayItem">
<Grid Padding="0,10" ColumnSpacing="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="0.8*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="{x:Bind Username}"
VerticalAlignment="Center"/>
<TextBlock Grid.Column="1"
Text="{x:Bind Action}"
TextWrapping="Wrap"
VerticalAlignment="Center"/>
<Border Grid.Column="2"
Padding="8,4"
CornerRadius="4"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<Border.Background>
<SolidColorBrush Color="{x:Bind CategoryColor}"/>
</Border.Background>
<TextBlock Text="{x:Bind CategoryLabel}"
FontSize="12"
Foreground="White"/>
</Border>
<TextBlock Grid.Column="3"
Text="{x:Bind TimestampText}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"/>
</Grid>
</DataTemplate>
</Page.Resources>
<Grid>
<ScrollViewer x:Name="DashboardScrollViewer">
<StackPanel Padding="24" Spacing="20">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Spacing="4">
<TextBlock Text="Dashboard"
Style="{ThemeResource TitleLargeTextBlockStyle}"/>
<TextBlock x:Name="IntroText"
Style="{ThemeResource BodyTextBlockStyle}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"/>
</StackPanel>
<Button Grid.Column="1"
Content="Odhlásit se"
VerticalAlignment="Center"
Click="SignOutButton_Click"/>
</Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto"
HorizontalScrollMode="Auto"
VerticalScrollBarVisibility="Disabled">
<StackPanel Orientation="Horizontal" Spacing="12">
<Border x:Name="UsersStatCard" Style="{StaticResource DashboardStatCardStyle}">
<StackPanel Spacing="8">
<FontIcon Glyph="&#xE716;" FontSize="20"/>
<TextBlock x:Name="TotalUsersText" Style="{StaticResource DashboardStatNumberStyle}"/>
<TextBlock Text="Celkem uživatelů" Style="{StaticResource DashboardStatTitleStyle}"/>
</StackPanel>
</Border>
<Border x:Name="ChallengesStatCard" Style="{StaticResource DashboardStatCardStyle}">
<StackPanel Spacing="8">
<FontIcon Glyph="&#xE912;" FontSize="20"/>
<TextBlock x:Name="ActiveChallengesText" Style="{StaticResource DashboardStatNumberStyle}"/>
<TextBlock Text="Výzvy v systému" Style="{StaticResource DashboardStatTitleStyle}"/>
</StackPanel>
</Border>
<Border x:Name="GamesStatCard" Style="{StaticResource DashboardStatCardStyle}">
<StackPanel Spacing="8">
<FontIcon Glyph="&#xE7FC;" FontSize="20"/>
<TextBlock x:Name="RegisteredGamesText" Style="{StaticResource DashboardStatNumberStyle}"/>
<TextBlock Text="Registrované hry" Style="{StaticResource DashboardStatTitleStyle}"/>
</StackPanel>
</Border>
<Border Style="{StaticResource DashboardStatCardStyle}">
<StackPanel Spacing="8">
<FontIcon Glyph="&#xE8C7;" FontSize="20"/>
<TextBlock x:Name="TotalNodCoinsText" Style="{StaticResource DashboardStatNumberStyle}"/>
<TextBlock Text="NodCoiny v oběhu" Style="{StaticResource DashboardStatTitleStyle}"/>
</StackPanel>
</Border>
<Border Style="{StaticResource DashboardStatCardStyle}">
<StackPanel Spacing="8">
<FontIcon Glyph="&#xE9D9;" FontSize="20"/>
<TextBlock x:Name="ProfitNcText" Style="{StaticResource DashboardStatNumberStyle}"/>
<TextBlock Text="Poplatky z proher" Style="{StaticResource DashboardStatTitleStyle}"/>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
<Grid ColumnSpacing="16">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource DashboardPanelStyle}">
<StackPanel Spacing="12">
<TextBlock x:Name="ActivityTitleText"
Style="{ThemeResource SubtitleTextBlockStyle}"/>
<Grid Padding="0,0,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="0.8*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Uživatel" FontWeight="SemiBold"/>
<TextBlock Grid.Column="1" Text="Akce" FontWeight="SemiBold"/>
<TextBlock Grid.Column="2" Text="Typ" FontWeight="SemiBold"/>
<TextBlock Grid.Column="3" Text="Datum" FontWeight="SemiBold" HorizontalAlignment="Right"/>
</Grid>
<ItemsRepeater x:Name="ActivityRepeater"
ItemTemplate="{StaticResource ActivityRowTemplate}"/>
<TextBlock x:Name="EmptyActivityText"
Text="Zatím žádná aktivita"
HorizontalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Visibility="Collapsed"/>
<StackPanel x:Name="PaginationPanel"
Orientation="Horizontal"
HorizontalAlignment="Center"
Spacing="8"
Visibility="Collapsed">
<Button x:Name="PreviousPageButton"
Content="Předchozí"
Click="PreviousPageButton_Click"/>
<TextBlock x:Name="PageInfoText"
VerticalAlignment="Center"/>
<Button x:Name="NextPageButton"
Content="Další"
Click="NextPageButton_Click"/>
</StackPanel>
</StackPanel>
</Border>
<StackPanel Grid.Column="1" Spacing="16">
<Border Style="{StaticResource DashboardPanelStyle}">
<StackPanel Spacing="12">
<TextBlock Text="Rychlé akce"
Style="{ThemeResource SubtitleTextBlockStyle}"/>
<StackPanel Spacing="8">
<Button Content="Přidat / spravovat hry" HorizontalAlignment="Stretch"/>
<Button Content="Spravovat výzvy" HorizontalAlignment="Stretch"/>
<Button Content="Spravovat uživatele" HorizontalAlignment="Stretch"/>
<Button Content="Aktuality" HorizontalAlignment="Stretch"/>
<Button Content="Pravidla" HorizontalAlignment="Stretch"/>
</StackPanel>
</StackPanel>
</Border>
<Border Style="{StaticResource DashboardPanelStyle}">
<StackPanel Spacing="12">
<TextBlock Text="Souhrn"
Style="{ThemeResource SubtitleTextBlockStyle}"/>
<StackPanel Spacing="8">
<Grid>
<TextBlock Text="Uživatelé"/>
<TextBlock x:Name="SummaryUsersText" HorizontalAlignment="Right" FontWeight="SemiBold"/>
</Grid>
<Grid>
<TextBlock Text="Výzvy"/>
<TextBlock x:Name="SummaryChallengesText" HorizontalAlignment="Right" FontWeight="SemiBold"/>
</Grid>
<Grid>
<TextBlock Text="Hry"/>
<TextBlock x:Name="SummaryGamesText" HorizontalAlignment="Right" FontWeight="SemiBold"/>
</Grid>
<Grid>
<TextBlock Text="NodCoiny v oběhu"/>
<TextBlock x:Name="SummaryNodCoinsText" HorizontalAlignment="Right" FontWeight="SemiBold"/>
</Grid>
<Grid>
<TextBlock Text="Poplatky"/>
<TextBlock x:Name="SummaryProfitText" HorizontalAlignment="Right" FontWeight="SemiBold"/>
</Grid>
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
</Grid>
</StackPanel>
</ScrollViewer>
<ProgressRing x:Name="LoadingRing"
Width="40"
Height="40"
IsActive="False"
Visibility="Collapsed"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<InfoBar x:Name="ErrorInfoBar"
IsOpen="False"
Severity="Error"
IsClosable="True"
VerticalAlignment="Top"/>
</Grid>
</Page>
@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using winui_learning_2.Helpers;
using winui_learning_2.Models;
using winui_learning_2.Services;
namespace winui_learning_2.Views;
public sealed partial class HomePage : Page
{
private readonly NodplayAdminService _adminService = new();
private DashBoardViewModel? _dashboard;
private int _currentPage = 1;
public HomePage()
{
InitializeComponent();
}
protected override async void OnNavigatedTo(Microsoft.UI.Xaml.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
IntroText.Text = $"Přehled platformy Nodplay · {DashboardFormatting.FormatIntroDateTime()}";
await LoadDashboardAsync(_currentPage);
}
private async Task LoadDashboardAsync(int page)
{
SetLoading(true);
HideError();
try
{
_dashboard = await _adminService.GetDashboardAsync(page);
if (_dashboard == null)
{
ShowError("Dashboard data nebyla vrácena.");
return;
}
_currentPage = _dashboard.ActivityPage > 0 ? _dashboard.ActivityPage : page;
BindDashboard(_dashboard);
}
catch (NodplayApiException ex) when (ex.StatusCode is 401 or 403)
{
AuthSession.SignOut();
Frame?.Navigate(typeof(LoginPage));
}
catch (Exception)
{
ShowError("Nepodařilo se načíst dashboard. Zkontrolujte připojení a zkuste to znovu.");
}
finally
{
SetLoading(false);
}
}
private void BindDashboard(DashBoardViewModel dashboard)
{
TotalUsersText.Text = DashboardFormatting.FormatCount(dashboard.TotalUsers);
ActiveChallengesText.Text = DashboardFormatting.FormatCount(dashboard.ActiveChallenges);
RegisteredGamesText.Text = DashboardFormatting.FormatCount(dashboard.RegisteredGames);
TotalNodCoinsText.Text = DashboardFormatting.FormatCoins(dashboard.TotalNodCoins);
ProfitNcText.Text = DashboardFormatting.FormatCoins(dashboard.ProfitNc);
SummaryUsersText.Text = DashboardFormatting.FormatCount(dashboard.TotalUsers);
SummaryChallengesText.Text = DashboardFormatting.FormatCount(dashboard.ActiveChallenges);
SummaryGamesText.Text = DashboardFormatting.FormatCount(dashboard.RegisteredGames);
SummaryNodCoinsText.Text = DashboardFormatting.FormatCoins(dashboard.TotalNodCoins);
SummaryProfitText.Text = DashboardFormatting.FormatCoins(dashboard.ProfitNc);
ActivityTitleText.Text =
$"Aktivita ({DashboardFormatting.FormatCount(dashboard.TotalActivities)})";
var activities = dashboard.RecentActivities?
.Select(ActivityDisplayItem.From)
.ToList() ?? new List<ActivityDisplayItem>();
ActivityRepeater.ItemsSource = activities;
EmptyActivityText.Visibility = activities.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
var maxPages = Math.Max(dashboard.ActivityMaxPages, 1);
var showPagination = dashboard.TotalActivities > 0;
PaginationPanel.Visibility = showPagination ? Visibility.Visible : Visibility.Collapsed;
if (showPagination)
{
PageInfoText.Text = $"Strana {_currentPage} z {maxPages}";
PreviousPageButton.IsEnabled = _currentPage > 1;
NextPageButton.IsEnabled = _currentPage < maxPages;
}
}
private async void PreviousPageButton_Click(object sender, RoutedEventArgs e)
{
if (_currentPage > 1)
{
await LoadDashboardAsync(_currentPage - 1);
}
}
private async void NextPageButton_Click(object sender, RoutedEventArgs e)
{
var maxPages = Math.Max(_dashboard?.ActivityMaxPages ?? 1, 1);
if (_currentPage < maxPages)
{
await LoadDashboardAsync(_currentPage + 1);
}
}
private void SignOutButton_Click(object sender, RoutedEventArgs e)
{
AuthSession.SignOut();
Frame?.Navigate(typeof(LoginPage));
}
private void SetLoading(bool isLoading)
{
LoadingRing.IsActive = isLoading;
LoadingRing.Visibility = isLoading ? Visibility.Visible : Visibility.Collapsed;
DashboardScrollViewer.IsEnabled = !isLoading;
}
private void ShowError(string message)
{
ErrorInfoBar.Message = message;
ErrorInfoBar.IsOpen = true;
}
private void HideError()
{
ErrorInfoBar.IsOpen = false;
}
}
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Page
x:Class="winui_learning_2.Views.LoginPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Padding="32">
<StackPanel VerticalAlignment="Center"
HorizontalAlignment="Center"
Spacing="12"
MaxWidth="360"
Width="360">
<TextBlock Text="Nodplay"
HorizontalAlignment="Center"
Style="{ThemeResource TitleLargeTextBlockStyle}"/>
<TextBlock Text="Sign in to continue"
HorizontalAlignment="Center"
Style="{ThemeResource BodyTextBlockStyle}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"/>
<TextBox x:Name="UsernameBox"
Header="Username"
PlaceholderText="Username"
KeyDown="InputBox_KeyDown"/>
<PasswordBox x:Name="PasswordBox"
Header="Password"
PlaceholderText="Password"
KeyDown="InputBox_KeyDown"/>
<TextBlock x:Name="ErrorText"
Foreground="{ThemeResource SystemFillColorCriticalBrush}"
TextWrapping="Wrap"
Visibility="Collapsed"/>
<Button x:Name="LoginButton"
Content="Sign in"
HorizontalAlignment="Stretch"
Click="LoginButton_Click"/>
</StackPanel>
<ProgressRing x:Name="LoadingRing"
Width="32"
Height="32"
IsActive="False"
Visibility="Collapsed"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</Page>
@@ -0,0 +1,91 @@
using System;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using winui_learning_2.Services;
namespace winui_learning_2.Views;
public sealed partial class LoginPage : Page
{
private readonly NodplayAuthService _authService = new();
public LoginPage()
{
InitializeComponent();
}
private async void LoginButton_Click(object sender, RoutedEventArgs e)
{
await TryLoginAsync();
}
private async void InputBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
await TryLoginAsync();
}
}
private async Task TryLoginAsync()
{
ErrorText.Visibility = Visibility.Collapsed;
ErrorText.Text = string.Empty;
var username = UsernameBox.Text.Trim();
var password = PasswordBox.Password;
if (string.IsNullOrWhiteSpace(username))
{
ShowError("Username is required.");
return;
}
if (string.IsNullOrEmpty(password))
{
ShowError("Password is required.");
return;
}
SetLoading(true);
try
{
var result = await _authService.LoginAsync(username, password);
if (!result.IsSuccess)
{
ShowError(result.ErrorMessage ?? "Login failed.");
return;
}
AuthSession.SignIn(result.Username ?? username, result.Token);
Frame?.Navigate(typeof(HomePage));
}
catch (Exception)
{
ShowError("Could not reach the Nodplay API. Check your connection and try again.");
}
finally
{
SetLoading(false);
}
}
private void ShowError(string message)
{
ErrorText.Text = message;
ErrorText.Visibility = Visibility.Visible;
}
private void SetLoading(bool isLoading)
{
LoginButton.IsEnabled = !isLoading;
UsernameBox.IsEnabled = !isLoading;
PasswordBox.IsEnabled = !isLoading;
LoadingRing.IsActive = isLoading;
LoadingRing.Visibility = isLoading ? Visibility.Visible : Visibility.Collapsed;
}
}