diff --git a/FrontendAvalonia/.gitignore b/FrontendAvalonia/.gitignore new file mode 100644 index 0000000..8afdcb6 --- /dev/null +++ b/FrontendAvalonia/.gitignore @@ -0,0 +1,454 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/FrontendAvalonia/App.axaml b/FrontendAvalonia/App.axaml new file mode 100644 index 0000000..ddc0b60 --- /dev/null +++ b/FrontendAvalonia/App.axaml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/FrontendAvalonia/App.axaml.cs b/FrontendAvalonia/App.axaml.cs new file mode 100644 index 0000000..de00bbe --- /dev/null +++ b/FrontendAvalonia/App.axaml.cs @@ -0,0 +1,23 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +namespace FrontendAvalonia; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow(); + } + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/FrontendAvalonia/Directory.Build.props b/FrontendAvalonia/Directory.Build.props new file mode 100644 index 0000000..5a014d1 --- /dev/null +++ b/FrontendAvalonia/Directory.Build.props @@ -0,0 +1,6 @@ + + + enable + 11.0.0-rc1.1 + + diff --git a/FrontendAvalonia/FrontendAvalonia.Android/FrontendAvalonia.Android.csproj b/FrontendAvalonia/FrontendAvalonia.Android/FrontendAvalonia.Android.csproj new file mode 100644 index 0000000..21a38ae --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/FrontendAvalonia.Android.csproj @@ -0,0 +1,27 @@ + + + Exe + net7.0-android + 21 + enable + com.CompanyName.FrontendAvalonia + 1 + 1.0 + apk + False + + + + + Resources\drawable\Icon.png + + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.Android/Icon.png b/FrontendAvalonia/FrontendAvalonia.Android/Icon.png new file mode 100644 index 0000000..41a2a61 Binary files /dev/null and b/FrontendAvalonia/FrontendAvalonia.Android/Icon.png differ diff --git a/FrontendAvalonia/FrontendAvalonia.Android/MainActivity.cs b/FrontendAvalonia/FrontendAvalonia.Android/MainActivity.cs new file mode 100644 index 0000000..264b801 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/MainActivity.cs @@ -0,0 +1,10 @@ +using Android.App; +using Android.Content.PM; +using Avalonia.Android; + +namespace FrontendAvalonia.Android; + +[Activity(Label = "FrontendAvalonia.Android", Theme = "@style/MyTheme.NoActionBar", Icon = "@drawable/icon", LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)] +public class MainActivity : AvaloniaMainActivity +{ +} diff --git a/FrontendAvalonia/FrontendAvalonia.Android/Properties/AndroidManifest.xml b/FrontendAvalonia/FrontendAvalonia.Android/Properties/AndroidManifest.xml new file mode 100644 index 0000000..8d25d30 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/Properties/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.Android/Resources/drawable/splash_screen.xml b/FrontendAvalonia/FrontendAvalonia.Android/Resources/drawable/splash_screen.xml new file mode 100644 index 0000000..2e920b4 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/Resources/drawable/splash_screen.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.Android/Resources/values-night/colors.xml b/FrontendAvalonia/FrontendAvalonia.Android/Resources/values-night/colors.xml new file mode 100644 index 0000000..3d47b6f --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/Resources/values-night/colors.xml @@ -0,0 +1,4 @@ + + + #212121 + diff --git a/FrontendAvalonia/FrontendAvalonia.Android/Resources/values/colors.xml b/FrontendAvalonia/FrontendAvalonia.Android/Resources/values/colors.xml new file mode 100644 index 0000000..59279d5 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/Resources/values/colors.xml @@ -0,0 +1,4 @@ + + + #FFFFFF + diff --git a/FrontendAvalonia/FrontendAvalonia.Android/Resources/values/styles.xml b/FrontendAvalonia/FrontendAvalonia.Android/Resources/values/styles.xml new file mode 100644 index 0000000..2759d29 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/Resources/values/styles.xml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.Android/SplashActivity.cs b/FrontendAvalonia/FrontendAvalonia.Android/SplashActivity.cs new file mode 100644 index 0000000..a2cda26 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Android/SplashActivity.cs @@ -0,0 +1,32 @@ +//using Android.App; +//using Android.Content; +//using Android.OS; +//using Application = Android.App.Application; +//using Avalonia; +//using Avalonia.Android; +//using Avalonia.ReactiveUI; + +//namespace FrontendAvalonia.Android; + +//[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)] +//public class SplashActivity : AvaloniaSplashActivity +//{ +// protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) +// { +// return base.CustomizeAppBuilder(builder) +// .WithInterFont() +// .UseReactiveUI(); +// } + +// protected override void OnCreate(Bundle? savedInstanceState) +// { +// base.OnCreate(savedInstanceState); +// } + +// protected override void OnResume() +// { +// base.OnResume(); + +// StartActivity(new Intent(Application.Context, typeof(MainActivity))); +// } +//} diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/Logo.svg b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/Logo.svg new file mode 100644 index 0000000..9685a23 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/Logo.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/app.css b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/app.css new file mode 100644 index 0000000..a424538 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/app.css @@ -0,0 +1,74 @@ +:root { + --sat: env(safe-area-inset-top); + --sar: env(safe-area-inset-right); + --sab: env(safe-area-inset-bottom); + --sal: env(safe-area-inset-left); +} + +/* HTML styles for the splash screen */ + +.highlight { + color: white; + font-size: 2.5rem; + display: block; +} + +.purple { + color: #8b44ac; +} + +.icon { + opacity: 0.05; + height: 35%; + width: 35%; + position: absolute; + background-repeat: no-repeat; + right: 0px; + bottom: 0px; + margin-right: 3%; + margin-bottom: 5%; + z-index: 5000; + background-position: right bottom; + pointer-events: none; +} + +#avalonia-splash a { + color: whitesmoke; + text-decoration: none; +} + +.center { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} + +#avalonia-splash { + position: relative; + height: 100%; + width: 100%; + color: whitesmoke; + background: #1b2a4e; + font-family: 'Nunito', sans-serif; + background-position: center; + background-size: cover; + background-repeat: no-repeat; + justify-content: center; + align-items: center; +} + +.splash-close { + animation: fadeout 0.25s linear forwards; +} + +@keyframes fadeout { + 0% { + opacity: 100%; + } + + 100% { + opacity: 0; + visibility: collapse; + } +} diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/favicon.ico b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/favicon.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/favicon.ico differ diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/index.html b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/index.html new file mode 100644 index 0000000..1ff09ae --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/index.html @@ -0,0 +1,30 @@ + + + + + FrontendAvalonia.Browser + + + + + + + + + + +
+
+
+

+ Powered by + Avalonia UI +

+
+ Avalonia Logo +
+
+ + + + \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/main.js b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/main.js new file mode 100644 index 0000000..0dbe2e4 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/AppBundle/main.js @@ -0,0 +1,13 @@ +import { dotnet } from './dotnet.js' + +const is_browser = typeof window != "undefined"; +if (!is_browser) throw new Error(`Expected to be running in a browser`); + +const dotnetRuntime = await dotnet + .withDiagnosticTracing(false) + .withApplicationArgumentsFromQuery() + .create(); + +const config = dotnetRuntime.getConfig(); + +await dotnetRuntime.runMainAndExit(config.mainAssemblyName, [window.location.search]); \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/FrontendAvalonia.Browser.csproj b/FrontendAvalonia/FrontendAvalonia.Browser/FrontendAvalonia.Browser.csproj new file mode 100644 index 0000000..70e35b6 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/FrontendAvalonia.Browser.csproj @@ -0,0 +1,20 @@ + + + net7.0 + browser-wasm + AppBundle\main.js + Exe + + + + + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/Program.cs b/FrontendAvalonia/FrontendAvalonia.Browser/Program.cs new file mode 100644 index 0000000..16eecc7 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/Program.cs @@ -0,0 +1,19 @@ +using System.Runtime.Versioning; +using System.Threading.Tasks; +using Avalonia; +using Avalonia.Browser; +using Avalonia.ReactiveUI; +using FrontendAvalonia; + +[assembly: SupportedOSPlatform("browser")] + +internal partial class Program +{ + private static async Task Main(string[] args) => await BuildAvaloniaApp() + .WithInterFont() + .UseReactiveUI() + .StartBrowserAppAsync("out"); + + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure(); +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/Properties/launchSettings.json b/FrontendAvalonia/FrontendAvalonia.Browser/Properties/launchSettings.json new file mode 100644 index 0000000..cefdffd --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/Properties/launchSettings.json @@ -0,0 +1,13 @@ +{ + "profiles": { + "FrontendAvalonia.Browser": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/debug?browser={browserInspectUri}" + } + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia.Browser/runtimeconfig.template.json b/FrontendAvalonia/FrontendAvalonia.Browser/runtimeconfig.template.json new file mode 100644 index 0000000..c6990ba --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Browser/runtimeconfig.template.json @@ -0,0 +1,11 @@ +{ + "wasmHostProperties": { + "perHostConfig": [ + { + "name": "browser", + "html-path": "index.html", + "Host": "browser" + } + ] + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia.Desktop/.avalonia-build-tasks/id b/FrontendAvalonia/FrontendAvalonia.Desktop/.avalonia-build-tasks/id new file mode 100644 index 0000000..0105b2b --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Desktop/.avalonia-build-tasks/id @@ -0,0 +1 @@ +Åÿg/‘L¼õ“Ѓ^/™ \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia.Desktop/FrontendAvalonia.Desktop.csproj b/FrontendAvalonia/FrontendAvalonia.Desktop/FrontendAvalonia.Desktop.csproj new file mode 100644 index 0000000..4d5cf0d --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Desktop/FrontendAvalonia.Desktop.csproj @@ -0,0 +1,24 @@ + + + WinExe + + net7.0 + enable + true + + + + app.manifest + + + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.Desktop/Program.cs b/FrontendAvalonia/FrontendAvalonia.Desktop/Program.cs new file mode 100644 index 0000000..711d4c0 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Desktop/Program.cs @@ -0,0 +1,23 @@ +using System; +using Avalonia; +using Avalonia.ReactiveUI; + +namespace FrontendAvalonia.Desktop; + +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() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace() + .UseReactiveUI(); +} diff --git a/FrontendAvalonia/FrontendAvalonia.Desktop/Properties/launchSettings.json b/FrontendAvalonia/FrontendAvalonia.Desktop/Properties/launchSettings.json new file mode 100644 index 0000000..dacc6e2 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Desktop/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "FrontendAvalonia.Desktop": { + "commandName": "Project" + }, + "WSL": { + "commandName": "WSL2", + "distributionName": "" + } + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia.Desktop/app.manifest b/FrontendAvalonia/FrontendAvalonia.Desktop/app.manifest new file mode 100644 index 0000000..bd198f9 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.Desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.csproj b/FrontendAvalonia/FrontendAvalonia.csproj new file mode 100644 index 0000000..dceb682 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.csproj @@ -0,0 +1,22 @@ + + + WinExe + net6.0 + enable + true + app.manifest + + + + + + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.iOS/AppDelegate.cs b/FrontendAvalonia/FrontendAvalonia.iOS/AppDelegate.cs new file mode 100644 index 0000000..c5c2ef7 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.iOS/AppDelegate.cs @@ -0,0 +1,23 @@ +using Foundation; +using UIKit; +using Avalonia; +using Avalonia.Controls; +using Avalonia.iOS; +using Avalonia.Media; +using Avalonia.ReactiveUI; + +namespace FrontendAvalonia.iOS; + +// The UIApplicationDelegate for the application. This class is responsible for launching the +// User Interface of the application, as well as listening (and optionally responding) to +// application events from iOS. +[Register("AppDelegate")] +public partial class AppDelegate : AvaloniaAppDelegate +{ + protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) + { + return base.CustomizeAppBuilder(builder) + .WithInterFont() + .UseReactiveUI(); + } +} diff --git a/FrontendAvalonia/FrontendAvalonia.iOS/Entitlements.plist b/FrontendAvalonia/FrontendAvalonia.iOS/Entitlements.plist new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.iOS/Entitlements.plist @@ -0,0 +1,5 @@ + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.iOS/FrontendAvalonia.iOS.csproj b/FrontendAvalonia/FrontendAvalonia.iOS/FrontendAvalonia.iOS.csproj new file mode 100644 index 0000000..c8e91c2 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.iOS/FrontendAvalonia.iOS.csproj @@ -0,0 +1,22 @@ + + + Exe + net7.0-ios + 10.0 + manual + enable + iossimulator-x64 + + + + + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.iOS/Info.plist b/FrontendAvalonia/FrontendAvalonia.iOS/Info.plist new file mode 100644 index 0000000..742b690 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.iOS/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDisplayName + FrontendAvalonia + CFBundleIdentifier + companyName.FrontendAvalonia + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 10.0 + UIDeviceFamily + + 1 + 2 + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIStatusBarHidden + + UIViewControllerBasedStatusBarAppearance + + + diff --git a/FrontendAvalonia/FrontendAvalonia.iOS/Main.cs b/FrontendAvalonia/FrontendAvalonia.iOS/Main.cs new file mode 100644 index 0000000..77d1306 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.iOS/Main.cs @@ -0,0 +1,14 @@ +using UIKit; + +namespace FrontendAvalonia.iOS; + +public class Application +{ + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } +} diff --git a/FrontendAvalonia/FrontendAvalonia.iOS/Resources/LaunchScreen.xib b/FrontendAvalonia/FrontendAvalonia.iOS/Resources/LaunchScreen.xib new file mode 100644 index 0000000..efe278d --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.iOS/Resources/LaunchScreen.xib @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia.sln b/FrontendAvalonia/FrontendAvalonia.sln new file mode 100644 index 0000000..e8931b2 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia.sln @@ -0,0 +1,54 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32811.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendAvalonia", "FrontendAvalonia\FrontendAvalonia.csproj", "{EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendAvalonia.Desktop", "FrontendAvalonia.Desktop\FrontendAvalonia.Desktop.csproj", "{ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendAvalonia.Browser", "FrontendAvalonia.Browser\FrontendAvalonia.Browser.csproj", "{1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendAvalonia.iOS", "FrontendAvalonia.iOS\FrontendAvalonia.iOS.csproj", "{EBD9022F-BC83-4846-9A11-6F7F3772DC64}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendAvalonia.Android", "FrontendAvalonia.Android\FrontendAvalonia.Android.csproj", "{7AD1DAC8-7FBE-49D5-8614-7321233DB82E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3DA99C4E-89E3-4049-9C22-0A7EC60D83D8}" + ProjectSection(SolutionItems) = preProject + Directory.Build.props = Directory.Build.props + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}.Release|Any CPU.Build.0 = Release|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABC31E74-02FF-46EB-B3B2-4E6AE43B456C}.Release|Any CPU.Build.0 = Release|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C1A049E-235C-4CD0-B6FA-D53AC418F4DA}.Release|Any CPU.Build.0 = Release|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBD9022F-BC83-4846-9A11-6F7F3772DC64}.Release|Any CPU.Build.0 = Release|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7AD1DAC8-7FBE-49D5-8614-7321233DB82E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {83CB65B8-011F-4ED7-BCD3-A6CFA935EF7E} + EndGlobalSection +EndGlobal diff --git a/FrontendAvalonia/FrontendAvalonia/.avalonia-build-tasks/id b/FrontendAvalonia/FrontendAvalonia/.avalonia-build-tasks/id new file mode 100644 index 0000000..61fd20c --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/.avalonia-build-tasks/id @@ -0,0 +1 @@ +À¼óÂ˵šBºNèÓÑ_Θ \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/App.axaml b/FrontendAvalonia/FrontendAvalonia/App.axaml new file mode 100644 index 0000000..a0753df --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/App.axaml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/App.axaml.cs b/FrontendAvalonia/FrontendAvalonia/App.axaml.cs new file mode 100644 index 0000000..15663c3 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/App.axaml.cs @@ -0,0 +1,71 @@ +using System; +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using FrontendAvalonia.Extensions; +using FrontendAvalonia.Models; +using FrontendAvalonia.Services.GamenightApi; +using FrontendAvalonia.ViewModels; +using FrontendAvalonia.Views; +using ReactiveUI; +using Refit; +using Splat; + +namespace FrontendAvalonia; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + var mutable = Locator.CurrentMutable; + var locator = Locator.Current ?? throw new InvalidOperationException("Locator should not be null here."); + mutable.RegisterLazySingleton(() => new GamenightModel()); + + mutable.RegisterLazySingleton(() => new MainScreenViewModel()); + mutable.RegisterLazySingleton(() => RestService.For("http://localhost:8080")); + + mutable.Register(() => new AddGamenightViewModel( + locator.GetRequiredService(), + locator.GetRequiredService())); + mutable.Register(() => new LoginViewModel( + locator.GetRequiredService(), + locator.GetRequiredService(), + locator.GetRequiredService())); + mutable.Register(() => new GamenightsViewModel( + locator.GetRequiredService(), + locator.GetRequiredService(), + locator.GetRequiredService(), + locator.GetRequiredService())); + mutable.Register(() => new MainViewModel( + locator.GetRequiredService(), + locator.GetRequiredService(), + locator.GetRequiredService(), + locator.GetRequiredService(), + locator.GetRequiredService())); + + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = Locator.Current.GetService() + }; + } + else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + { + singleViewPlatform.MainView = new MainView + { + DataContext = Locator.Current.GetService() + }; + } + + Locator.Current.GetService()?.Router.Navigate.Execute(Locator.Current.GetService() ?? throw new InvalidOperationException("Could not find initial viewmodel to navigate to")); + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/Assets/avalonia-logo.ico b/FrontendAvalonia/FrontendAvalonia/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/FrontendAvalonia/FrontendAvalonia/Assets/avalonia-logo.ico differ diff --git a/FrontendAvalonia/FrontendAvalonia/Extensions/SplatExtensions.cs b/FrontendAvalonia/FrontendAvalonia/Extensions/SplatExtensions.cs new file mode 100644 index 0000000..96498a9 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/Extensions/SplatExtensions.cs @@ -0,0 +1,22 @@ +using Splat; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FrontendAvalonia.Extensions +{ + public static class SplatExtensions + { + public static T GetRequiredService(this IReadonlyDependencyResolver resolver, string? contract = null) + { + if (resolver is null) + { + throw new ArgumentNullException(nameof(resolver)); + } + + return resolver.GetService(contract) ?? throw new InvalidOperationException($"Service {typeof(T).Name} was required but was not registered."); + } + } +} diff --git a/FrontendAvalonia/FrontendAvalonia/FrontendAvalonia.csproj b/FrontendAvalonia/FrontendAvalonia/FrontendAvalonia.csproj new file mode 100644 index 0000000..99f812d --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/FrontendAvalonia.csproj @@ -0,0 +1,47 @@ + + + net7.0 + enable + latest + true + + + + + + + + + + + + + + + + + + + + True + True + Gamenight.yaml + + + LoginView.axaml + + + GamenightsView.axaml + + + AddGamenight.axaml + + + + + + RefitterCodeGenerator + Gamenight.cs + + + diff --git a/FrontendAvalonia/FrontendAvalonia/Models/GamenightModel.cs b/FrontendAvalonia/FrontendAvalonia/Models/GamenightModel.cs new file mode 100644 index 0000000..0cc78a9 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/Models/GamenightModel.cs @@ -0,0 +1,16 @@ + +using ReactiveUI; + +namespace FrontendAvalonia.Models +{ + public class GamenightModel : ReactiveObject + { + private string? _userToken; + + public string? UserToken + { + get => _userToken; + set => this.RaiseAndSetIfChanged(ref _userToken, value); + } + } +} diff --git a/FrontendAvalonia/FrontendAvalonia/Services/GamenightApi/Gamenight.cs b/FrontendAvalonia/FrontendAvalonia/Services/GamenightApi/Gamenight.cs new file mode 100644 index 0000000..509ea44 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/Services/GamenightApi/Gamenight.cs @@ -0,0 +1,240 @@ + +//---------------------- +// +// Generated REST API Client Code Generator v1.7.17.0 on 6/26/2023 11:20:46 AM +// Using the tool Refitter v0.6.0 +// +//---------------------- + + +// +// This code was generated by Refitter. +// + +using Refit; +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.Threading; +using System.Threading.Tasks; + +namespace FrontendAvalonia.Services.GamenightApi +{ + public interface IGamenight + { + /// + /// Submit your credentials to get a JWT-token to use with the rest of the api. + /// + [Post("/token")] + Task> GetToken([Body] object body, CancellationToken cancellationToken = default); + + /// + /// Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match. + /// + [Post("/user")] + Task PostRegister([Body] object body, CancellationToken cancellationToken = default); + + /// + /// Retrieve the list of gamenights on this gamenight server. Requires authorization. + /// + [Get("/gamenights")] + Task>> GetGamenights(CancellationToken cancellationToken = default); + + /// + /// Add a gamenight by providing a name and a date, only available when providing an JWT token. + /// + [Post("/gamenight")] + Task PostGamenight([Body] object body, [Authorize("Bearer")] string token, CancellationToken cancellationToken = default); + + [Get("/gamenight")] + Task> GetGamenight([Body] object body, CancellationToken cancellationToken = default); + + + } +} + + +//---------------------- +// +// Generated using the NSwag toolchain v13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0)) (http://NSwag.org) +// +//---------------------- + +#pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended." +#pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword." +#pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?' +#pragma warning disable 612 // Disable "CS0612 '...' is obsolete" +#pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ... +#pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..." +#pragma warning disable 8073 // Disable "CS8073 The result of the expression is always 'false' since a value of type 'T' is never equal to 'null' of type 'T?'" +#pragma warning disable 3016 // Disable "CS3016 Arrays as attribute arguments is not CLS-compliant" +#pragma warning disable 8603 // Disable "CS8603 Possible null reference return" + +namespace FrontendAvalonia.Services.GamenightApi +{ + using System = global::System; + + + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")] + public partial class Gamenight + { + + [JsonPropertyName("id")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Id { get; set; } + + [JsonPropertyName("name")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Name { get; set; } + + [JsonPropertyName("datetime")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Datetime { get; set; } + + [JsonPropertyName("owner_id")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Owner_id { get; set; } + + private IDictionary _additionalProperties; + + [JsonExtensionData] + public IDictionary AdditionalProperties + { + get { return _additionalProperties ?? (_additionalProperties = new Dictionary()); } + set { _additionalProperties = value; } + } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")] + public partial class Failure + { + + [JsonPropertyName("message")] + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Message { get; set; } + + private IDictionary _additionalProperties; + + [JsonExtensionData] + public IDictionary AdditionalProperties + { + get { return _additionalProperties ?? (_additionalProperties = new Dictionary()); } + set { _additionalProperties = value; } + } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")] + public partial class Token + { + + [JsonPropertyName("jwt_token")] + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public string Jwt_token { get; set; } + + private IDictionary _additionalProperties; + + [JsonExtensionData] + public IDictionary AdditionalProperties + { + get { return _additionalProperties ?? (_additionalProperties = new Dictionary()); } + set { _additionalProperties = value; } + } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")] + public partial class Login + { + + [JsonPropertyName("username")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Username { get; set; } + + [JsonPropertyName("password")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Password { get; set; } + + private IDictionary _additionalProperties; + + [JsonExtensionData] + public IDictionary AdditionalProperties + { + get { return _additionalProperties ?? (_additionalProperties = new Dictionary()); } + set { _additionalProperties = value; } + } + + } + + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")] + public partial class Registration + { + + [JsonPropertyName("username")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Username { get; set; } + + [JsonPropertyName("email")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Email { get; set; } + + [JsonPropertyName("password")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Password { get; set; } + + [JsonPropertyName("password_repeat")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Password_repeat { get; set; } + + [JsonPropertyName("registration_token")] + + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] + public string Registration_token { get; set; } + + private IDictionary _additionalProperties; + + [JsonExtensionData] + public IDictionary AdditionalProperties + { + get { return _additionalProperties ?? (_additionalProperties = new Dictionary()); } + set { _additionalProperties = value; } + } + + } + + +} + +#pragma warning restore 108 +#pragma warning restore 114 +#pragma warning restore 472 +#pragma warning restore 612 +#pragma warning restore 1573 +#pragma warning restore 1591 +#pragma warning restore 8073 +#pragma warning restore 3016 +#pragma warning restore 8603 diff --git a/FrontendAvalonia/FrontendAvalonia/Services/GamenightApi/Gamenight.yaml b/FrontendAvalonia/FrontendAvalonia/Services/GamenightApi/Gamenight.yaml new file mode 100644 index 0000000..ea992bc --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/Services/GamenightApi/Gamenight.yaml @@ -0,0 +1,224 @@ +openapi: 3.0.0 +x-stoplight: + id: w776sltk0h1bo +info: + title: Gamenight + version: '1.0' + contact: + name: Dennis Brentjes + email: dennis@brentj.es + url: 'https://brentj.es' + description: Api specifaction for a Gamenight server + license: + name: MIT +servers: + - url: 'http://localhost:8080' + description: Gamenight +paths: + /token: + post: + summary: '' + operationId: get-token + responses: + '200': + $ref: '#/components/responses/TokenResponse' + '401': + $ref: '#/components/responses/FailureResponse' + requestBody: + $ref: '#/components/requestBodies/LoginRequest' + description: Submit your credentials to get a JWT-token to use with the rest of the api. + parameters: [] + /user: + post: + summary: '' + operationId: post-register + requestBody: + $ref: '#/components/requestBodies/RegisterRequest' + responses: + '200': + description: '' + '422': + $ref: '#/components/responses/FailureResponse' + description: 'Create a new user given a registration token and user information, username and email must be unique, and password and password_repeat must match.' + parameters: [] + /gamenights: + get: + summary: Your GET endpoint + responses: + '200': + $ref: '#/components/responses/GamenightsResponse' + '400': + $ref: '#/components/responses/FailureResponse' + '401': + $ref: '#/components/responses/FailureResponse' + operationId: get-gamenights + security: + - JWT-Auth: [] + description: Retrieve the list of gamenights on this gamenight server. Requires authorization. + /gamenight: + post: + summary: '' + operationId: post-gamenight + responses: + '200': + description: OK + '401': + $ref: '#/components/responses/FailureResponse' + '422': + $ref: '#/components/responses/FailureResponse' + security: + - JWT-Auth: [] + requestBody: + $ref: '#/components/requestBodies/AddGamenight' + description: 'Add a gamenight by providing a name and a date, only available when providing an JWT token.' + get: + summary: '' + operationId: get-gamenight + responses: + '200': + $ref: '#/components/responses/GamenightResponse' + '401': + $ref: '#/components/responses/FailureResponse' + '422': + $ref: '#/components/responses/FailureResponse' + requestBody: + $ref: '#/components/requestBodies/GetGamenight' + security: + - JWT-Auth: [] +components: + schemas: + Gamenight: + title: Gamenight + x-stoplight: + id: 0nmru75ph5wh3 + type: object + properties: + id: + type: string + name: + type: string + datetime: + type: string + owner_id: + type: string + required: + - id + - name + - datetime + - owner_id + Failure: + title: Failure + type: object + properties: + message: + type: string + description: '' + Token: + title: Token + x-stoplight: + id: 8pz19kigm1jer + type: object + properties: + jwt_token: + type: string + Login: + title: Login + type: object + properties: + username: + type: string + password: + type: string + required: + - username + - password + Registration: + title: Registration + type: object + properties: + username: + type: string + email: + type: string + password: + type: string + password_repeat: + type: string + registration_token: + type: string + required: + - username + - email + - password + - password_repeat + - registration_token + requestBodies: + LoginRequest: + content: + application/json: + schema: + $ref: '#/components/schemas/Login' + RegisterRequest: + content: + application/json: + schema: + $ref: '#/components/schemas/Registration' + AddGamenight: + content: + application/json: + schema: + type: object + properties: + name: + type: string + datetime: + type: string + GetGamenight: + content: + application/json: + schema: + type: object + properties: + id: + type: string + responses: + TokenResponse: + description: Example response + content: + application/json: + schema: + $ref: '#/components/schemas/Token' + FailureResponse: + description: Example response + content: + application/json: + schema: + $ref: '#/components/schemas/Failure' + application/xml: + schema: + type: object + properties: + message: + type: string + required: + - message + GamenightsResponse: + description: Example response + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Gamenight' + GamenightResponse: + description: Example response + content: + application/json: + schema: + $ref: '#/components/schemas/Gamenight' + securitySchemes: + JWT-Auth: + type: http + scheme: bearer + bearerFormat: JWT + description: '' diff --git a/FrontendAvalonia/FrontendAvalonia/ViewLocator.cs b/FrontendAvalonia/FrontendAvalonia/ViewLocator.cs new file mode 100644 index 0000000..7849ce6 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewLocator.cs @@ -0,0 +1,22 @@ +using System; +using System.Runtime.Serialization; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using FrontendAvalonia.ViewModels; +using FrontendAvalonia.Views; +using ReactiveUI; + +namespace FrontendAvalonia; + +public class ViewLocator : IViewLocator +{ + public IViewFor? ResolveView(T? viewModel, string? contract = null) + { + return viewModel switch + { + GamenightsViewModel context => new GamenightsView { DataContext = context }, + LoginViewModel context => new LoginView { DataContext = context }, + _ => throw new InvalidOperationException($"Cannot find view for {viewModel?.GetType().Name}") + }; + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/AddGamenightViewModel.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/AddGamenightViewModel.cs new file mode 100644 index 0000000..8e1b05a --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/AddGamenightViewModel.cs @@ -0,0 +1,86 @@ +using System; +using System.Runtime.InteropServices.JavaScript; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Input; +using FrontendAvalonia.Models; +using FrontendAvalonia.Services.GamenightApi; +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels; + +public class AddGamenightViewModel : ViewModelBase +{ + private IGamenight Gamenight { get; } + + private GamenightModel GamenightModel { get; } + + private bool _expanded; + + public bool Expanded + { + get => _expanded; + set => this.RaiseAndSetIfChanged(ref _expanded, value); + } + + public AddGamenightViewModel(IGamenight gamenight, GamenightModel gamenightModel) + { + Gamenight = gamenight; + GamenightModel = gamenightModel; + StartDate = DateTime.Now.Date; + EndDate = DateTime.Now.Date; + AddCommand = ReactiveCommand.CreateFromTask(AddGamenight); + } + + private async Task AddGamenight(CancellationToken ct) + { + var body = new Gamenight + { + Name = Name, + Datetime = (StartDate + StartTime).ToString("u").Replace(" ", "T"), + }; + await Gamenight.PostGamenight(body, GamenightModel.UserToken, ct); + } + + private string _name = string.Empty; + + public string Name + { + get => _name; + set => this.RaiseAndSetIfChanged(ref _name, value); + } + + private DateTimeOffset _startDate; + + public DateTimeOffset StartDate + { + get => _startDate; + set => this.RaiseAndSetIfChanged(ref _startDate, value); + } + + private TimeSpan _startTime; + + public TimeSpan StartTime + { + get => _startTime; + set => this.RaiseAndSetIfChanged(ref _startTime, value); + } + + private DateTimeOffset _endDate; + + public DateTimeOffset EndDate + { + get => _endDate; + set => this.RaiseAndSetIfChanged(ref _endDate, value); + } + + private TimeSpan _endTime; + + public TimeSpan EndTime + { + get => _endTime; + set => this.RaiseAndSetIfChanged(ref _endTime, value); + } + + public ICommand AddCommand { get; } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/GamenightsViewModel.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/GamenightsViewModel.cs new file mode 100644 index 0000000..754c7b4 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/GamenightsViewModel.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using DynamicData.Binding; +using FrontendAvalonia.Models; +using FrontendAvalonia.Services.GamenightApi; +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels; + +public class GamenightsViewModel : PageViewModelBase +{ + private IGamenight Gamenight { get; } + private GamenightModel Model { get; } + private LoginViewModel LoginViewModel { get; } + + public AddGamenightViewModel AddGamenightViewModel { get; } + + private ObservableCollectionExtended _gamenightItems = new ObservableCollectionExtended(); + public ObservableCollectionExtended GamenightItems { + get => _gamenightItems; + set => this.RaiseAndSetIfChanged(ref _gamenightItems, value); + } + + public GamenightsViewModel(IScreen screen, IGamenight gamenight, GamenightModel model, LoginViewModel loginViewModel) + : base(screen) + { + Gamenight = gamenight; + Model = model; + LoginViewModel = loginViewModel; + AddGamenightViewModel = new AddGamenightViewModel(Gamenight, model); + this._gamenightItems.Add(AddGamenightViewModel); + this.WhenActivated(OnActivated); + } + + private IEnumerable OnActivated() + { + if (Model.UserToken == null) + { + HostScreen.Router.Navigate.Execute(LoginViewModel); + } + return Enumerable.Empty(); + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/LoginViewModel.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/LoginViewModel.cs new file mode 100644 index 0000000..d4e25d8 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/LoginViewModel.cs @@ -0,0 +1,37 @@ +using System.Threading.Tasks; +using System.Windows.Input; +using FrontendAvalonia.Models; +using FrontendAvalonia.Services.GamenightApi; +using FrontendAvalonia.Views; +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels; + +public class LoginViewModel : PageViewModelBase +{ + private IGamenight GamenightApi { get; } + private GamenightModel Model { get; } + + public string Username { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public ICommand LoginCommand { get; } + + public LoginViewModel(IScreen screen, IGamenight gamenightApi, GamenightModel model) + :base(screen) + { + GamenightApi = gamenightApi; + Model = model; + + LoginCommand = ReactiveCommand.CreateFromTask(Login); + } + + private async Task Login() + { + var result = await GamenightApi.GetToken(new Login { Username = Username, Password = Password }); + if (result is { IsSuccessStatusCode: true }) + { + Model.UserToken = result.Content?.Jwt_token; + HostScreen.Router.NavigateBack.Execute(); + } + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/MainScreenViewModel.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/MainScreenViewModel.cs new file mode 100644 index 0000000..eb5789a --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/MainScreenViewModel.cs @@ -0,0 +1,8 @@ +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels; + +public class MainScreenViewModel : IScreen +{ + public RoutingState Router { get; } = new(); +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/MainViewModel.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..97b4e6d --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/MainViewModel.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reactive; +using System.Threading.Tasks; +using System.Windows.Input; +using Avalonia.Controls; +using Avalonia.Input; +using DynamicData.Binding; +using FrontendAvalonia.Models; +using FrontendAvalonia.Services.GamenightApi; +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels; + +public class MainViewModel : PageViewModelBase +{ + private GamenightModel GamenightModel { get; } + + private List _MenuItems = new(); + + public List MenuItems + { + get => _MenuItems; + set => this.RaiseAndSetIfChanged(ref _MenuItems, value); + } + + public IGamenight? Gamenight { get; } + + private LoginViewModel LoginViewModel { get; } + + private GamenightsViewModel GamenightsViewModel { get; } + + public MainViewModel(IScreen screen, GamenightModel gamenightModel, IGamenight gamenight, LoginViewModel loginViewModel, GamenightsViewModel gamenightsViewModel) + :base(screen) + { + GamenightModel = gamenightModel; + MenuItems = new List(); + Gamenight = gamenight; + LoginViewModel = loginViewModel; + GamenightsViewModel = gamenightsViewModel; + + gamenightModel.WhenAnyValue(m => m.UserToken).Subscribe(CreateMenuItems); + } + + private Task NavigateToLoginPage() + { + return Task.FromResult(HostScreen.Router.Navigate.Execute(LoginViewModel)); + } + + private Task NavigateToGamenightsPage() + { + return Task.FromResult(HostScreen.Router.NavigateAndReset.Execute(GamenightsViewModel)); + } + + private void CreateMenuItems(string? userToken) + { + if (userToken != null) + { + MenuItems = new List + { + new() + { + Header = "_Logout", + Command = ReactiveCommand.Create(async () => + { + GamenightModel.UserToken = null; + await NavigateToGamenightsPage(); + }), + CommandParameter = null!, + Items = new List(), + } + }; + } + else + { + MenuItems = new List + { + new() + { + Header = "_Login", + Command = ReactiveCommand.CreateFromTask(NavigateToLoginPage), + CommandParameter = null!, + Items = new List(), + } + }; + } + } + + // The command that navigates a user back. + public ReactiveCommand GoBack => HostScreen.Router.NavigateBack; +} diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/MenuItemViewModel.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/MenuItemViewModel.cs new file mode 100644 index 0000000..7ad6ec1 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/MenuItemViewModel.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Windows.Input; +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels +{ + public class MenuItemViewModel : ViewModelBase + { + public string Header { get; set; } = "Placeholder"; + public ICommand Command { get; set; } = ReactiveCommand.Create(() => { }); + public object? CommandParameter { get; set; } = null; + public IList Items { get; set; } = new List(); + } +} diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/PageViewModelBase.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/PageViewModelBase.cs new file mode 100644 index 0000000..66d8bd9 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/PageViewModelBase.cs @@ -0,0 +1,16 @@ +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels; + +public class PageViewModelBase : ViewModelBase, IRoutableViewModel, IActivatableViewModel +{ + public PageViewModelBase(IScreen screen) + { + UrlPathSegment = GetType().Name.Replace("ViewModel", ""); + HostScreen = screen; + } + + public string? UrlPathSegment { get; } + public IScreen HostScreen { get; } + public ViewModelActivator Activator { get; } = new(); +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/ViewModels/ViewModelBase.cs b/FrontendAvalonia/FrontendAvalonia/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..65e9afc --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/ViewModels/ViewModelBase.cs @@ -0,0 +1,8 @@ +using Microsoft.CodeAnalysis.CSharp.Syntax; +using ReactiveUI; + +namespace FrontendAvalonia.ViewModels; + +public class ViewModelBase : ReactiveObject +{ +} diff --git a/FrontendAvalonia/FrontendAvalonia/Views/AddGamenight.axaml b/FrontendAvalonia/FrontendAvalonia/Views/AddGamenight.axaml new file mode 100644 index 0000000..53bdfc8 --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/Views/AddGamenight.axaml @@ -0,0 +1,26 @@ + + + + + + diff --git a/FrontendAvalonia/FrontendAvalonia/Views/LoginView.axaml.cs b/FrontendAvalonia/FrontendAvalonia/Views/LoginView.axaml.cs new file mode 100644 index 0000000..c23f90f --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/Views/LoginView.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia.ReactiveUI; +using FrontendAvalonia.ViewModels; +using ReactiveUI; + +namespace FrontendAvalonia.Views; + +public partial class LoginView : ReactiveUserControl +{ + public LoginView() + { + this.WhenActivated(disposables => { }); + InitializeComponent(); + } +} \ No newline at end of file diff --git a/FrontendAvalonia/FrontendAvalonia/Views/MainView.axaml b/FrontendAvalonia/FrontendAvalonia/Views/MainView.axaml new file mode 100644 index 0000000..cdab6ab --- /dev/null +++ b/FrontendAvalonia/FrontendAvalonia/Views/MainView.axaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +