Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Unige.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OgeSharp", "OgeSharp\OgeSha
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnigeWebUtility", "UnigeWebUtility\UnigeWebUtility.csproj", "{3568E75E-90CB-4A03-B2E3-D8F413ABF68E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnigeSoftware", "UnigeSoftware\UnigeSoftware.csproj", "{991CA739-1B61-4D43-B7BF-88840944C08C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{3568E75E-90CB-4A03-B2E3-D8F413ABF68E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3568E75E-90CB-4A03-B2E3-D8F413ABF68E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3568E75E-90CB-4A03-B2E3-D8F413ABF68E}.Release|Any CPU.Build.0 = Release|Any CPU
{991CA739-1B61-4D43-B7BF-88840944C08C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{991CA739-1B61-4D43-B7BF-88840944C08C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{991CA739-1B61-4D43-B7BF-88840944C08C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{991CA739-1B61-4D43-B7BF-88840944C08C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 12 additions & 0 deletions UnigeSoftware/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UnigeSoftware"
x:Class="UnigeSoftware.App">
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<FluentTheme Mode="Light"/>
</Application.Styles>
</Application>
21 changes: 21 additions & 0 deletions UnigeSoftware/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using UnigeSoftware.ViewModels;
using UnigeSoftware.Views;

namespace UnigeSoftware {
public class App : Application {
public override void Initialize() => AvaloniaXamlLoader.Load(this);

public override void OnFrameworkInitializationCompleted() {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
desktop.MainWindow = new MainWindow {
DataContext = new MainWindowViewModel(),
};
}

base.OnFrameworkInitializationCompleted();
}
}
}
Binary file added UnigeSoftware/Assets/avalonia-logo.ico
Binary file not shown.
Binary file added UnigeSoftware/Assets/discord-mark-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added UnigeSoftware/Assets/github-mark-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions UnigeSoftware/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ReactiveUI />
</Weavers>
22 changes: 22 additions & 0 deletions UnigeSoftware/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
using System;

namespace UnigeSoftware {
class Program {
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
}
}
32 changes: 32 additions & 0 deletions UnigeSoftware/UnigeSoftware.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<InstallAvalonia>true</InstallAvalonia>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.10" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.10" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.10" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.10" />
<PackageReference Include="DeviceId" Version="6.0.0" />
<PackageReference Include="DeviceId.Linux" Version="6.0.0" />
<PackageReference Include="DeviceId.Windows" Version="6.0.0" />
<PackageReference Include="MessageBox.Avalonia" Version="1.5.5" />
<PackageReference Include="ReactiveUI.Fody" Version="16.3.5" />
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1" />
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OgeSharp\OgeSharp.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions UnigeSoftware/ViewLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using ReactiveUI;
using System;

namespace UnigeSoftware {
public class ViewLocator : IDataTemplate {
public IControl Build(object data) {
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);

if (type != null) {
return (Control)Activator.CreateInstance(type)!;
} else {
return new TextBlock { Text = "Not Found: " + name };
}
}

public bool Match(object data) => data is ReactiveObject;

}
}
63 changes: 63 additions & 0 deletions UnigeSoftware/ViewModels/ConnectViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using ReactiveUI.Validation.Abstractions;
using ReactiveUI.Validation.Contexts;
using ReactiveUI.Validation.Extensions;
using System;
using System.Diagnostics;
using System.Reactive;
using System.Reactive.Linq;

namespace UnigeSoftware.ViewModels {

public class ConnectViewModel : ReactiveObject, IValidatableViewModel {

private readonly MainWindowViewModel MainWindow;
public ValidationContext ValidationContext { get; } = new ValidationContext();

[Reactive] public string Username { get; set; }
[Reactive] public string Password { get; set; }

public ConnectViewModel(MainWindowViewModel mainWindow) {

// Save the main window view model
MainWindow = mainWindow;

// Create the commands
ConnectCommand = ReactiveCommand.CreateFromObservable(DoConnect);
OpenFromExplorerCommand = ReactiveCommand.Create<string>(DoOpenWebpage);

// Username and password cannot be empty
this.ValidationRule(viewModel => viewModel.Username, username => !string.IsNullOrEmpty(username), "Le nom d'utilisateur ne peut pas être vide");
this.ValidationRule(viewModel => viewModel.Password, password => !string.IsNullOrEmpty(password), "Le mot de passe ne peut pas être vide");

}

#region Commands

public ReactiveCommand<Unit, Unit> ConnectCommand { get; }
public ReactiveCommand<string, Unit> OpenFromExplorerCommand { get; }

// TODO: Maybe not working on other OS
private void DoOpenWebpage(string url) => Process.Start("explorer", url);

private IObservable<Unit> DoConnect() => Observable.Start(() => {

// If the fields are not validated
if (!ValidationContext.GetIsValid()) return;

// If the credentials are correct
if (MainWindow.Oge.Login(Username, Password)) {

// Tell the main window that we are connected
MainWindow.OnConnected();

}

});

#endregion

}

}
16 changes: 16 additions & 0 deletions UnigeSoftware/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace UnigeSoftware.ViewModels {

public class HomeViewModel : ReactiveObject {

[Reactive] public string Note { get; set; }

public HomeViewModel(MainWindowViewModel mainWindow) {

}

}

}
22 changes: 22 additions & 0 deletions UnigeSoftware/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using OgeSharp;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace UnigeSoftware.ViewModels {
public class MainWindowViewModel : ReactiveObject {

public Oge Oge = new Oge();

[Reactive] public ReactiveObject Content { get; set; }

public MainWindowViewModel() {

// Initialize the connect view model
Content = new ConnectViewModel(this);

}

public void OnConnected() => Content = new HomeViewModel(this);

}
}
53 changes: 53 additions & 0 deletions UnigeSoftware/Views/ConnectView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:UnigeSoftware.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="UnigeSoftware.Views.ConnectView">

<Panel>

<StackPanel Margin="0,0,0,32" Width="360" VerticalAlignment="Center">

<TextBlock Margin="0,0,0,16" HorizontalAlignment="Center">Connexion à OGE</TextBlock>

<!-- Username -->
<TextBlock Margin="0,0,0,4">Nom d'utilisateur:</TextBlock>
<TextBox Text="{Binding Username}" Watermark="xy012345"></TextBox>
<TextBlock x:Name="UsernameError" Foreground="Red"/>

<!-- Password -->
<TextBlock Margin="0,8,0,4">Mot de passe:</TextBlock>
<TextBox Text="{Binding Password}" Watermark="*****" PasswordChar="*" RevealPassword="{Binding #RevealPassword.IsChecked}"></TextBox>
<TextBlock x:Name="PasswordError" Foreground="Red"/>

<!-- Show password -->
<CheckBox x:Name="RevealPassword" HorizontalAlignment="Right" Content="Afficher le mot de passe" Margin="0,8,0,0"/>

<!-- Connect -->
<Button Content="Se connecter" IsEnabled="{Binding !IsConnecting}" Command="{Binding ConnectCommand}" Margin="0,8,0,0" HorizontalContentAlignment="Center" HorizontalAlignment="Stretch"/>

</StackPanel>

<!-- Utility buttons -->
<StackPanel Margin="8" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right">

<!-- Github -->
<Button Command="{Binding OpenFromExplorerCommand}" CommandParameter="https://github.com/NaolShow/Unige" ToolTip.Tip="Ou retrouver Unige ?">
<Image Height="24" Source="/Assets/github-mark-light.png"></Image>
</Button>
<!-- Discord -->
<Button Command="{Binding OpenFromExplorerCommand}" CommandParameter="https://discord.gg/m7CZ6md" ToolTip.Tip="Besoin d'aide ? Discord du développeur!">
<Image Height="24" Source="/Assets/discord-mark-light.png"></Image>
</Button>
<!-- Help -->
<Button Command="{Binding OpenFromExplorerCommand}" CommandParameter="https://github.com/NaolShow/Unige/wiki" ToolTip.Tip="Qu'est-ce qu'Unige?">
<TextBlock FontWeight="ExtraBold" Height="24" Padding="3">?</TextBlock>
</Button>

</StackPanel>

</Panel>

</UserControl>
25 changes: 25 additions & 0 deletions UnigeSoftware/Views/ConnectView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Avalonia.ReactiveUI;
using ReactiveUI;
using ReactiveUI.Validation.Extensions;
using System.Reactive.Disposables;
using UnigeSoftware.ViewModels;

namespace UnigeSoftware.Views {

public partial class ConnectView : ReactiveUserControl<ConnectViewModel> {

public ConnectView() {
InitializeComponent();

// Input validation
this.WhenActivated(disposables => {

this.BindValidation(ViewModel, viewModel => viewModel.Username, view => view.UsernameError.Text).DisposeWith(disposables);
this.BindValidation(ViewModel, viewModel => viewModel.Password, view => view.PasswordError.Text).DisposeWith(disposables);

});

}

}
}
11 changes: 11 additions & 0 deletions UnigeSoftware/Views/HomeView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:UnigeSoftware.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="UnigeSoftware.Views.HomeView">

<TextBlock Text="{Binding Note}"></TextBlock>

</UserControl>
11 changes: 11 additions & 0 deletions UnigeSoftware/Views/HomeView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace UnigeSoftware.Views {
public partial class HomeView : UserControl {

public HomeView() => InitializeComponent();
private void InitializeComponent() => AvaloniaXamlLoader.Load(this);

}
}
20 changes: 20 additions & 0 deletions UnigeSoftware/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:UnigeSoftware.ViewModels"
xmlns:views="using:UnigeSoftware.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="UnigeSoftware.Views.MainWindow"

Icon="/Assets/avalonia-logo.ico"
Title="Unige"

CanResize="False"

Width="720"
Height="405"

Content="{Binding Content}">

</Window>
18 changes: 18 additions & 0 deletions UnigeSoftware/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace UnigeSoftware.Views {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}

private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}
}
}