Skip to content

Commit

Permalink
progress with new user settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelo420 committed Dec 12, 2023
1 parent 9bd347f commit a92a7dd
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 16 deletions.
2 changes: 2 additions & 0 deletions gamevault/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ public class User
public bool? Activated { get; set; }
[JsonPropertyName("deleted_at")]
public string DeletedAt { get; set; }
[JsonPropertyName("created_at")]
public DateTime? CreatedAt { get; set; }
}
}
18 changes: 10 additions & 8 deletions gamevault/UserControls/AdminConsoleUserControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ await Task.Run(async () =>

private void EditUser_Clicked(object sender, MouseButtonEventArgs e)
{
uiUserEditPopup.Visibility = Visibility.Visible;
var obj = new UserEditUserControl((User)((FrameworkElement)sender).DataContext);
obj.UserSaved += UserSaved;
if (uiUserEditPopup.Children.Count != 0)
{
uiUserEditPopup.Children.Clear();
}
uiUserEditPopup.Children.Add(obj);
//uiUserEditPopup.Visibility = Visibility.Visible;
//var obj = new UserEditUserControl((User)((FrameworkElement)sender).DataContext);
//obj.UserSaved += UserSaved;
//if (uiUserEditPopup.Children.Count != 0)
//{
// uiUserEditPopup.Children.Clear();
//}
//uiUserEditPopup.Children.Add(obj);
User user = JsonSerializer.Deserialize<User>(JsonSerializer.Serialize((User)((FrameworkElement)sender).DataContext));
MainWindowViewModel.Instance.OpenPopup(new UserSettingsUserControl(user) { Width = 1200, Height = 800, Margin = new Thickness(50) });
}
private void BackupRestore_Click(object sender, RoutedEventArgs e)
{
Expand Down
10 changes: 5 additions & 5 deletions gamevault/UserControls/GeneralControls/IconButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:gamevault.UserControls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="450" d:DesignWidth="800" Name="parent">
<Border CornerRadius="5" Cursor="Hand">
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="{Binding Background}"/>
<Setter Property="Background" Value="{Binding ElementName=parent,Path=Background}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Background}" Value="{x:Null}">
<DataTrigger Binding="{Binding ElementName=parent,Path=Background}" Value="{x:Null}">
<Setter Property="Background" Value="{DynamicResource MainColor}"/>
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
Expand All @@ -24,8 +24,8 @@
</Style>
</Border.Style>
<StackPanel Orientation="Horizontal">
<Path Data="{Binding Icon}" Fill="White" VerticalAlignment="Center" Margin="4,0,0,4"/>
<TextBlock Text="{Binding Content}" FontSize="15" FontWeight="Bold" VerticalAlignment="Center" Margin="4,0,0,3"/>
<Path Data="{Binding ElementName=parent,Path=Icon}" Fill="White" VerticalAlignment="Center" Margin="4,0,0,4"/>
<TextBlock Text="{Binding ElementName=parent,Path=Content}" FontSize="15" FontWeight="Bold" VerticalAlignment="Center" Margin="4,0,0,3"/>
</StackPanel>
</Border>
</UserControl>
3 changes: 1 addition & 2 deletions gamevault/UserControls/GeneralControls/IconButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public partial class IconButton : UserControl
DependencyProperty.Register("Background", typeof(Brush), typeof(IconButton));
public IconButton()
{
InitializeComponent();
this.DataContext = this;
InitializeComponent();
}
public Geometry Icon
{
Expand Down
288 changes: 288 additions & 0 deletions gamevault/UserControls/UserSettingsUserControl.xaml

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions gamevault/UserControls/UserSettingsUserControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using gamevault.Helper;
using gamevault.Models;
using gamevault.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace gamevault.UserControls
{
/// <summary>
/// Interaction logic for UserSettingsUserControl.xaml
/// </summary>
public partial class UserSettingsUserControl : UserControl
{
private UserSettingsViewModel ViewModel { get; set; }
private bool loaded = false;
internal UserSettingsUserControl(User user)
{
ViewModel = new UserSettingsViewModel();
ViewModel.User = user;
InitializeComponent();
this.DataContext = ViewModel;
}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.Focus();
loaded = true;
}

private void CommandHelper_Executed(object sender, object e)
{
MainWindowViewModel.Instance.ClosePopup();
}

private void Close_Click(object sender, MouseButtonEventArgs e)
{
MainWindowViewModel.Instance.ClosePopup();
}

private void SettingsTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
uiSettingsContent.SelectedIndex = ((TabControl)sender).SelectedIndex;
}
#region Image Change
private void BackgroundImage_Drop(object sender, DragEventArgs e)
{

}

private void BackgroundImage_ChooseImage(object sender, MouseButtonEventArgs e)
{

}

private void Image_Paste(object sender, KeyEventArgs e)
{

}

private void BackgroundImage_Save(object sender, MouseButtonEventArgs e)
{

}
private void AvatarImage_Save(object sender, MouseButtonEventArgs e)
{

}
private void AvatarImage_Drop(object sender, DragEventArgs e)
{

}

private void AvatarImage_ChooseImage(object sender, MouseButtonEventArgs e)
{

}
private void BackgoundImageUrl_TextChanged(object sender, TextChangedEventArgs e)
{

}
private void AvatarImageUrl_TextChanged(object sender, TextChangedEventArgs e)
{

}
#endregion

private void UserDetails_TextChanged(object sender, RoutedEventArgs e)
{
if (loaded)
{
ViewModel.UserDetailsChanged = true;
}
}

private async void SaveUserDetails_Click(object sender, MouseButtonEventArgs e)
{
ViewModel.UserDetailsChanged = false;
this.IsEnabled = false;

User selectedUser = ViewModel.User;
string newPassword = uiUserPassword.Password;

if (newPassword != "")
selectedUser.Password = newPassword;

bool error = false;
await Task.Run(() =>
{
try
{
WebHelper.Put(@$"{SettingsViewModel.Instance.ServerUrl}/api/users/{selectedUser.ID}", JsonSerializer.Serialize(selectedUser));
MainWindowViewModel.Instance.AppBarText = "Sucessfully saved user changes";
}
catch (WebException ex)
{
error = true;
string msg = WebExceptionHelper.GetServerMessage(ex);
MainWindowViewModel.Instance.AppBarText = msg;
}
});
if (!error)
{
await HandleChangesOnCurrentUser(selectedUser);
}
this.IsEnabled = true;
}
private async Task HandleChangesOnCurrentUser(User selectedUser)
{
if (LoginManager.Instance.GetCurrentUser().ID == selectedUser.ID)
{
await LoginManager.Instance.ManualLogin(selectedUser.Username, string.IsNullOrEmpty(selectedUser.Password) ? WebHelper.GetCredentials()[1] : selectedUser.Password);
MainWindowViewModel.Instance.UserIcon = LoginManager.Instance.GetCurrentUser();
}
await MainWindowViewModel.Instance.AdminConsole.InitUserList();
}
}
}
27 changes: 27 additions & 0 deletions gamevault/ViewModels/UserSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using gamevault.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace gamevault.ViewModels
{
internal class UserSettingsViewModel : ViewModelBase
{
#region Privates
private User user { get; set; }
private bool userDetailsChanged { get; set; }
#endregion
public User User
{
get { return user; }
set { user = value; OnPropertyChanged(); }
}
public bool UserDetailsChanged
{
get { return userDetailsChanged; }
set { userDetailsChanged = value; OnPropertyChanged(); }
}
}
}
2 changes: 1 addition & 1 deletion gamevault/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Button Click="WindowCommand_Clicked" Content="💸 Kofi" FontSize="18" Cursor="Hand" Tag="https://ko-fi.com/phalcode"/>
<Button Click="WindowCommand_Clicked" Content="💬 Discord" FontSize="18" Cursor="Hand" Tag="https://discord.com/invite/NEdNen2dSu"/>
<Button Click="WindowCommand_Clicked" Content="📜 Documentation" FontSize="18" Cursor="Hand" Tag="https://gamevau.lt/docs/intro"/>
<Button Click="WindowCommand_Clicked" Content="🧑‍💻 Github" FontSize="18" Cursor="Hand" Tag="https://github.com/orgs/Phalcode/repositories"/>
<Button Click="WindowCommand_Clicked" Content="💻 Github" FontSize="18" Cursor="Hand" Tag="https://github.com/orgs/Phalcode/repositories"/>
<Button Click="WindowCommand_Clicked" Content="⚠️ Bug Report" FontSize="18" Cursor="Hand" Tag="https://github.com/Phalcode/gamevault-app/issues/new/choose"/>
</mah:WindowCommands>
</mah:MetroWindow.RightWindowCommands>
Expand Down

0 comments on commit a92a7dd

Please sign in to comment.