fix: a lots of issues are fixed
This commit is contained in:
parent
3d413e76cb
commit
e6eb19aba6
@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Reactive.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
@ -61,17 +62,22 @@ public partial class SettingViewModel : RoutableViewModelBase
|
|||||||
|
|
||||||
public SettingViewModel(IScreen hostScreen) : base(hostScreen)
|
public SettingViewModel(IScreen hostScreen) : base(hostScreen)
|
||||||
{
|
{
|
||||||
LoadClientSettings();
|
_ = LoadClientSettingsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadServerData()
|
private async Task LoadServerDataAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
using (UIHelper.MakeLoading("Fetch server data..."))
|
||||||
|
{
|
||||||
|
await RefreshUsersCommand.Execute();
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
ServerBlacklist = sb.AppendJoin(",\n", await Api.C.Gateway.IpWhitelistGet()).ToString();
|
ServerBlacklist = sb.AppendJoin(",\n", await Api.C.Gateway.IpWhitelistGet()).ToString();
|
||||||
ServerBlacklist = sb.Clear().AppendJoin(",\n", await Api.C.Gateway.IpBlacklistGet()).ToString();
|
ServerBlacklist = sb.Clear().AppendJoin(",\n", await Api.C.Gateway.IpBlacklistGet()).ToString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
UIHelper.NotifyError(ex);
|
UIHelper.NotifyError(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!))!;
|
LoginUser = (await UserService.C.GetOrDownloadUserInfoAsync(Api.C.Username.Value!))!;
|
||||||
|
|
||||||
@ -96,7 +102,7 @@ public partial class SettingViewModel : RoutableViewModelBase
|
|||||||
Gender = LoginUser.Sex;
|
Gender = LoginUser.Sex;
|
||||||
Bio = LoginUser.Bio;
|
Bio = LoginUser.Bio;
|
||||||
|
|
||||||
if (LoginUser.IsAdmin) await LoadServerData();
|
if (LoginUser.IsAdmin) await LoadServerDataAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ReactiveCommand]
|
[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]
|
[ReactiveCommand]
|
||||||
private async Task CreateUserAsync()
|
private async Task CreateUserAsync()
|
||||||
{
|
{
|
||||||
@ -248,7 +278,7 @@ public partial class SettingViewModel : RoutableViewModelBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Api.C.Gateway.Register(new RegisterRequest()
|
await Api.C.Gateway.Register(new RegisterRequest
|
||||||
{
|
{
|
||||||
Username = result.Username,
|
Username = result.Username,
|
||||||
Password = result.Password,
|
Password = result.Password,
|
||||||
@ -348,6 +378,7 @@ public partial class SettingViewModel : RoutableViewModelBase
|
|||||||
if (active) await Api.C.Gateway.Enable(username);
|
if (active) await Api.C.Gateway.Enable(username);
|
||||||
else await Api.C.Gateway.Disable(username);
|
else await Api.C.Gateway.Disable(username);
|
||||||
|
|
||||||
|
Users.First(x => x.Username == username).IsActive = active;
|
||||||
UIHelper.NotifySuccess($"{username} has already {(active ? "enabled" : "disabled")}.");
|
UIHelper.NotifySuccess($"{username} has already {(active ? "enabled" : "disabled")}.");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
MinWidth="400"
|
MinWidth="400"
|
||||||
x:Class="Flawless.Client.Views.ModalBox.MergeDialogView">
|
x:Class="Flawless.Client.Views.ModalBox.MergeDialogView">
|
||||||
<ListBox ItemsSource="{Binding MergeFiles}">
|
<ListBox HorizontalAlignment="Stretch" ItemsSource="{Binding MergeFiles}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<ListBoxItem>
|
<ListBoxItem>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
x:DataType="vm:PasswordChangeDialogViewModel"
|
x:DataType="vm:PasswordChangeDialogViewModel"
|
||||||
MinWidth="400">
|
MinWidth="400">
|
||||||
|
|
||||||
<Grid Margin="10" RowDefinitions="Auto,Auto,Auto">
|
<Grid Margin="10" HorizontalAlignment="Stretch" RowDefinitions="Auto,Auto,Auto">
|
||||||
<TextBox Watermark="Old Password"
|
<TextBox Watermark="Old Password"
|
||||||
PasswordChar="*"
|
PasswordChar="*"
|
||||||
Text="{Binding OldPassword}"/>
|
Text="{Binding OldPassword}"/>
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
x:Class="Flawless.Client.Views.ModalBox.UserCreateDialogView"
|
x:Class="Flawless.Client.Views.ModalBox.UserCreateDialogView"
|
||||||
x:DataType="vm:UserCreateDialogViewModel">
|
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="0" Watermark="Username" Text="{Binding Username}"/>
|
||||||
<TextBox Grid.Row="1" Watermark="Password"
|
<TextBox Grid.Row="1" Watermark="Password"
|
||||||
PasswordChar="*" Text="{Binding Password}"/>
|
PasswordChar="*" Text="{Binding Password}"/>
|
||||||
|
|||||||
@ -64,8 +64,6 @@
|
|||||||
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Server">
|
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Server">
|
||||||
<ScrollViewer Width="600" HorizontalAlignment="Left" Margin="6">
|
<ScrollViewer Width="600" HorizontalAlignment="Left" Margin="6">
|
||||||
<u:Form HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
<u:Form HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||||
<!-- <TextBox u:FormItem.Label="Server Public Name"/> -->
|
|
||||||
<!-- <ToggleSwitch u:FormItem.Label="Allow Public Register"/> -->
|
|
||||||
<u:FormGroup>
|
<u:FormGroup>
|
||||||
<TextBox u:FormItem.Label="IP Whitelist" Classes="TextArea" AcceptsReturn="True"
|
<TextBox u:FormItem.Label="IP Whitelist" Classes="TextArea" AcceptsReturn="True"
|
||||||
Text="{Binding ServerWhitelist}"/>
|
Text="{Binding ServerWhitelist}"/>
|
||||||
@ -83,18 +81,18 @@
|
|||||||
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Users">
|
<TabItem IsVisible="{Binding LoginUser.IsAdmin}" Header="Users">
|
||||||
<Grid RowDefinitions="Auto, *" Margin="10">
|
<Grid RowDefinitions="Auto, *" Margin="10">
|
||||||
|
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal" Spacing="6">
|
||||||
<Button Content="Refresh"
|
<Button Content="Refresh"
|
||||||
VerticalAlignment="Bottom"
|
VerticalAlignment="Bottom"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Command="{Binding CreateUserCommand}"/>
|
Command="{Binding RefreshUsersCommand}"/>
|
||||||
<Button Content="Add"
|
<Button Content="Add"
|
||||||
VerticalAlignment="Bottom"
|
VerticalAlignment="Bottom"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
Command="{Binding CreateUserCommand}"/>
|
Command="{Binding CreateUserCommand}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<DataGrid Grid.Row="1" ItemsSource="{Binding Users}" AutoGenerateColumns="False">
|
<DataGrid Grid.Row="1" ItemsSource="{Binding Users, Mode=TwoWay}" AutoGenerateColumns="False">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Header="Username" Binding="{Binding Username}" Width="*"/>
|
<DataGridTextColumn Header="Username" Binding="{Binding Username}" Width="*"/>
|
||||||
|
|
||||||
@ -167,7 +165,7 @@
|
|||||||
<u:IconButton Icon="{StaticResource SemiIconSearch}"
|
<u:IconButton Icon="{StaticResource SemiIconSearch}"
|
||||||
Command="{Binding DownloadServerLogCommand}"/>
|
Command="{Binding DownloadServerLogCommand}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ListBox ItemsSource="{Binding Logs}">
|
<ListBox ItemsSource="{Binding Logs, Mode=TwoWay}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<Grid RowDefinitions="Auto, *" ColumnDefinitions="Auto,*,Auto">
|
<Grid RowDefinitions="Auto, *" ColumnDefinitions="Auto,*,Auto">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user