feat: Lets issue popup show right things
This commit is contained in:
parent
0d69634bcc
commit
8a2a7d15e2
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Reactive.Disposables;
|
using System.Reactive.Disposables;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
@ -6,6 +7,8 @@ using Avalonia.Controls.Notifications;
|
|||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
using Flawless.Client.ViewModels.ModalBox;
|
using Flawless.Client.ViewModels.ModalBox;
|
||||||
using Flawless.Client.Views.ModalBox;
|
using Flawless.Client.Views.ModalBox;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Refit;
|
||||||
using Ursa.Controls;
|
using Ursa.Controls;
|
||||||
using Notification = Ursa.Controls.Notification;
|
using Notification = Ursa.Controls.Notification;
|
||||||
using WindowNotificationManager = Ursa.Controls.WindowNotificationManager;
|
using WindowNotificationManager = Ursa.Controls.WindowNotificationManager;
|
||||||
@ -14,6 +17,13 @@ namespace Flawless.Client;
|
|||||||
|
|
||||||
public static class UIHelper
|
public static class UIHelper
|
||||||
{
|
{
|
||||||
|
[Serializable]
|
||||||
|
private struct FailureData
|
||||||
|
{
|
||||||
|
public string? Message;
|
||||||
|
|
||||||
|
public string? Failure;
|
||||||
|
}
|
||||||
|
|
||||||
private static WindowNotificationManager _notificationManager = null!;
|
private static WindowNotificationManager _notificationManager = null!;
|
||||||
|
|
||||||
@ -21,6 +31,8 @@ public static class UIHelper
|
|||||||
|
|
||||||
private static int _loadingReferenceCount = 0;
|
private static int _loadingReferenceCount = 0;
|
||||||
|
|
||||||
|
private static JsonSerializer _serializer = JsonSerializer.Create();
|
||||||
|
|
||||||
public static WindowNotificationManager Notify
|
public static WindowNotificationManager Notify
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -71,18 +83,47 @@ public static class UIHelper
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void NotifyError(Exception ex)
|
public static void NotifyError(Exception ex, string? rewriteTitle = null)
|
||||||
{
|
{
|
||||||
try
|
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) + "...";
|
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);
|
Notify.Show(nf);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Can not notify error to users: " + e);
|
Console.Error.Write("Can not notify error to users: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -81,8 +81,20 @@
|
|||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Users">
|
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Users">
|
||||||
<Grid Margin="10">
|
<Grid RowDefinitions="Auto, *" Margin="10">
|
||||||
<DataGrid ItemsSource="{Binding Users}" AutoGenerateColumns="False">
|
|
||||||
|
<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>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Header="Username" Binding="{Binding Username}" Width="*"/>
|
<DataGridTextColumn Header="Username" Binding="{Binding Username}" Width="*"/>
|
||||||
|
|
||||||
@ -140,11 +152,6 @@
|
|||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
|
|
||||||
<!-- 添加用户按钮 -->
|
|
||||||
<Button Content="添加用户"
|
|
||||||
VerticalAlignment="Bottom"
|
|
||||||
HorizontalAlignment="Right"
|
|
||||||
Command="{Binding CreateUserCommand}"/>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Logfile">
|
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Logfile">
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"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",
|
"LocalStoragePath": "./data/development",
|
||||||
"User": {
|
"User": {
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"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",
|
"LocalStoragePath": "./data/development",
|
||||||
"User": {
|
"User": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user