1
0

feat: Lets issue popup show right things

This commit is contained in:
Ca2didi 2025-05-19 00:23:57 +08:00
parent 0d69634bcc
commit 8a2a7d15e2
4 changed files with 61 additions and 13 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Avalonia.Controls.ApplicationLifetimes;
@ -6,6 +7,8 @@ using Avalonia.Controls.Notifications;
using Avalonia.VisualTree;
using Flawless.Client.ViewModels.ModalBox;
using Flawless.Client.Views.ModalBox;
using Newtonsoft.Json;
using Refit;
using Ursa.Controls;
using Notification = Ursa.Controls.Notification;
using WindowNotificationManager = Ursa.Controls.WindowNotificationManager;
@ -14,12 +17,21 @@ namespace Flawless.Client;
public static class UIHelper
{
[Serializable]
private struct FailureData
{
public string? Message;
public string? Failure;
}
private static WindowNotificationManager _notificationManager = null!;
private static LoadingContainer _loadingContainer = null!;
private static int _loadingReferenceCount = 0;
private static JsonSerializer _serializer = JsonSerializer.Create();
public static WindowNotificationManager Notify
{
@ -71,18 +83,47 @@ public static class UIHelper
public static void NotifyError(Exception ex)
public static void NotifyError(Exception ex, string? rewriteTitle = null)
{
try
{
var content = ex.ToString();
Console.Error.Write(ex);
string content;
string title;
if (ex is ApiException aex)
{
title = rewriteTitle ?? $"API Error: {aex.StatusCode.ToString()}";
if (string.IsNullOrEmpty(aex.Content))
{
content = aex.Message;
}
else
{
try
{
var result = _serializer.Deserialize<FailureData>(new JsonTextReader(new StringReader(aex.Content)));
content = result.Message ?? aex.Message;
}
catch (Exception _)
{
content = aex.Content;
}
}
}
else
{
title = rewriteTitle ?? $"Error: {ex.GetType().Name}";
content = ex.ToString();
}
if (content.Length > 100) content = content.Substring(0, 100) + "...";
var nf = new Notification(ex.GetType().Name, content, NotificationType.Error);
var nf = new Notification(title, content, NotificationType.Error);
Notify.Show(nf);
}
catch (Exception e)
{
Console.WriteLine("Can not notify error to users: " + e);
Console.Error.Write("Can not notify error to users: " + e);
}
}

View File

@ -81,8 +81,20 @@
</ScrollViewer>
</TabItem>
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Users">
<Grid Margin="10">
<DataGrid ItemsSource="{Binding Users}" AutoGenerateColumns="False">
<Grid RowDefinitions="Auto, *" Margin="10">
<StackPanel Orientation="Horizontal">
<Button Content="Refresh Users"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Command="{Binding CreateUserCommand}"/>
<Button Content="Add Users"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Command="{Binding CreateUserCommand}"/>
</StackPanel>
<DataGrid Grid.Row="1" ItemsSource="{Binding Users}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Username" Binding="{Binding Username}" Width="*"/>
@ -140,11 +152,6 @@
</DataGrid.Columns>
</DataGrid>
<!-- 添加用户按钮 -->
<Button Content="添加用户"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Command="{Binding CreateUserCommand}"/>
</Grid>
</TabItem>
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Logfile">

View File

@ -7,7 +7,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"CoreDb": "Server=192.168.10.172;Port=5432;User Id=postgres;Password=postgres;Database=flawless"
"CoreDb": "Server=localhost;Port=5432;User Id=postgres;Database=flawless"
},
"LocalStoragePath": "./data/development",
"User": {

View File

@ -7,7 +7,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"CoreDb": "Server=192.168.10.172;Port=5432;User Id=postgres;Password=postgres;Database=flawless"
"CoreDb": "Server=localhost;Port=5432;User Id=postgres;Database=flawless"
},
"LocalStoragePath": "./data/development",
"User": {