1
0

fix: a lots of issues are fixed

This commit is contained in:
Ca2didi 2025-05-20 00:10:22 +08:00
parent 3d413e76cb
commit e6eb19aba6
5 changed files with 46 additions and 17 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Threading;
@ -61,16 +62,21 @@ public partial class SettingViewModel : RoutableViewModelBase
public SettingViewModel(IScreen hostScreen) : base(hostScreen)
{
LoadClientSettings();
_ = LoadClientSettingsAsync();
}
private async Task LoadServerData()
private async Task LoadServerDataAsync()
{
try
{
var sb = new StringBuilder();
ServerBlacklist = sb.AppendJoin(",\n", await Api.C.Gateway.IpWhitelistGet()).ToString();
ServerBlacklist = sb.Clear().AppendJoin(",\n", await Api.C.Gateway.IpBlacklistGet()).ToString();
using (UIHelper.MakeLoading("Fetch server data..."))
{
await RefreshUsersCommand.Execute();
var sb = new StringBuilder();
ServerBlacklist = sb.AppendJoin(",\n", await Api.C.Gateway.IpWhitelistGet()).ToString();
ServerBlacklist = sb.Clear().AppendJoin(",\n", await Api.C.Gateway.IpBlacklistGet()).ToString();
}
}
catch (Exception ex)
{
@ -86,7 +92,7 @@ public partial class SettingViewModel : RoutableViewModelBase
}
}
private async Task LoadClientSettings()
private async Task LoadClientSettingsAsync()
{
LoginUser = (await UserService.C.GetOrDownloadUserInfoAsync(Api.C.Username.Value!))!;
@ -96,7 +102,7 @@ public partial class SettingViewModel : RoutableViewModelBase
Gender = LoginUser.Sex;
Bio = LoginUser.Bio;
if (LoginUser.IsAdmin) await LoadServerData();
if (LoginUser.IsAdmin) await LoadServerDataAsync();
}
[ReactiveCommand]
@ -231,6 +237,30 @@ public partial class SettingViewModel : RoutableViewModelBase
}
}
[ReactiveCommand]
private async Task RefreshUsersAsync()
{
try
{
var users = await Api.C.Gateway.List();
Users.Clear();
foreach (var user in users)
{
Users.Add(new UserModel
{
Username = user.Username,
Email = user.Email,
IsActive = user.IsActive,
IsAdmin = user.IsAdmin ?? false
});
}
}
catch (ApiException ex)
{
UIHelper.NotifyError(ex);
}
}
[ReactiveCommand]
private async Task CreateUserAsync()
{
@ -248,7 +278,7 @@ public partial class SettingViewModel : RoutableViewModelBase
try
{
await Api.C.Gateway.Register(new RegisterRequest()
await Api.C.Gateway.Register(new RegisterRequest
{
Username = result.Username,
Password = result.Password,
@ -348,6 +378,7 @@ public partial class SettingViewModel : RoutableViewModelBase
if (active) await Api.C.Gateway.Enable(username);
else await Api.C.Gateway.Disable(username);
Users.First(x => x.Username == username).IsActive = active;
UIHelper.NotifySuccess($"{username} has already {(active ? "enabled" : "disabled")}.");
}
catch (Exception ex)

View File

@ -8,7 +8,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
MinWidth="400"
x:Class="Flawless.Client.Views.ModalBox.MergeDialogView">
<ListBox ItemsSource="{Binding MergeFiles}">
<ListBox HorizontalAlignment="Stretch" ItemsSource="{Binding MergeFiles}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>

View File

@ -5,7 +5,7 @@
x:DataType="vm:PasswordChangeDialogViewModel"
MinWidth="400">
<Grid Margin="10" RowDefinitions="Auto,Auto,Auto">
<Grid Margin="10" HorizontalAlignment="Stretch" RowDefinitions="Auto,Auto,Auto">
<TextBox Watermark="Old Password"
PasswordChar="*"
Text="{Binding OldPassword}"/>

View File

@ -4,7 +4,7 @@
x:Class="Flawless.Client.Views.ModalBox.UserCreateDialogView"
x:DataType="vm:UserCreateDialogViewModel">
<Grid Margin="10" RowDefinitions="Auto,Auto,Auto">
<Grid Margin="10" HorizontalAlignment="Stretch" RowDefinitions="Auto,Auto,Auto">
<TextBox Grid.Row="0" Watermark="Username" Text="{Binding Username}"/>
<TextBox Grid.Row="1" Watermark="Password"
PasswordChar="*" Text="{Binding Password}"/>

View File

@ -64,8 +64,6 @@
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Server">
<ScrollViewer Width="600" HorizontalAlignment="Left" Margin="6">
<u:Form HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<!-- <TextBox u:FormItem.Label="Server Public Name"/> -->
<!-- <ToggleSwitch u:FormItem.Label="Allow Public Register"/> -->
<u:FormGroup>
<TextBox u:FormItem.Label="IP Whitelist" Classes="TextArea" AcceptsReturn="True"
Text="{Binding ServerWhitelist}"/>
@ -83,18 +81,18 @@
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Users">
<Grid RowDefinitions="Auto, *" Margin="10">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Spacing="6">
<Button Content="Refresh"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Command="{Binding CreateUserCommand}"/>
Command="{Binding RefreshUsersCommand}"/>
<Button Content="Add"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Command="{Binding CreateUserCommand}"/>
</StackPanel>
<DataGrid Grid.Row="1" ItemsSource="{Binding Users}" AutoGenerateColumns="False">
<DataGrid Grid.Row="1" ItemsSource="{Binding Users, Mode=TwoWay}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Username" Binding="{Binding Username}" Width="*"/>
@ -167,7 +165,7 @@
<u:IconButton Icon="{StaticResource SemiIconSearch}"
Command="{Binding DownloadServerLogCommand}"/>
</StackPanel>
<ListBox ItemsSource="{Binding Logs}">
<ListBox ItemsSource="{Binding Logs, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid RowDefinitions="Auto, *" ColumnDefinitions="Auto,*,Auto">