AuthViewModel.cs: ACTerm login UI
This commit is contained in:
parent
a622c84467
commit
6372de0bfe
@ -18,4 +18,7 @@
|
||||
<ProjectReference Include="..\AutoCatCore\AutoCatCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
22
ACTerm/DialogService.cs
Normal file
22
ACTerm/DialogService.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCatCore.MVVM;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace ACTerm
|
||||
{
|
||||
class DialogService : IDialogService
|
||||
{
|
||||
public async Task ShowErrorDialogAsync(string message, string title = "Error")
|
||||
{
|
||||
//var ok = new Button("OK");
|
||||
//var text = new Label(message) { X = 1, Y = 1, Width = Dim.Fill() - 1, Height = Dim.Fill() - 1, TextAlignment = TextAlignment.Centered };
|
||||
//var dialog = new Dialog(title, 40, 8, ok);
|
||||
//dialog.Add(text);
|
||||
//ok.Clicked += () => { Application.RequestStop(); };
|
||||
//Application.Run(dialog);
|
||||
|
||||
MessageBox.ErrorQuery(title, message, "OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,42 @@
|
||||
using System;
|
||||
using Terminal.Gui;
|
||||
using ACTerm.Views;
|
||||
using System.Threading.Tasks;
|
||||
using AutoCatCore.ViewModel;
|
||||
|
||||
namespace ACTerm
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
Application.Init();
|
||||
|
||||
var authVM = new AuthViewModel(new DialogService());
|
||||
await authVM.Init();
|
||||
|
||||
if (!authVM.isLoggedIn)
|
||||
{
|
||||
var loginDialog = AuthDialog.CreateNew(authVM);
|
||||
Application.Top.Add(loginDialog);
|
||||
}
|
||||
else
|
||||
{
|
||||
//var mainWindow = new Window("Wnd");
|
||||
//top.Add(mainWindow);
|
||||
var history = new FrameView("History") { X = 0, Y = 0, Width = Dim.Percent(30), Height = Dim.Fill() - 1 };
|
||||
var detail = new FrameView("Vehicle details") { X = Pos.Percent(30), Y = 0, Width = Dim.Percent(70), Height = Dim.Fill() - 1 };
|
||||
|
||||
// Statusbar
|
||||
var about = new StatusItem(Key.F1, "~F1~ - About", () => { });
|
||||
var quit = new StatusItem(Key.ControlQ, "~Ctrl+Q~ - Quit", () => { Application.Shutdown(); });
|
||||
var statusBar = new StatusBar(new[] { about, quit });
|
||||
|
||||
Application.Top.Add(history, detail, statusBar);
|
||||
Application.Top.StatusBar = statusBar;
|
||||
}
|
||||
|
||||
Application.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
ACTerm/Views/AuthDialog.cs
Normal file
44
ACTerm/Views/AuthDialog.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using AutoCatCore.ViewModel;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace ACTerm.Views
|
||||
{
|
||||
public class AuthDialog: Dialog
|
||||
{
|
||||
private AuthViewModel viewModel;
|
||||
private TextField emailField;
|
||||
private TextField passwordField;
|
||||
|
||||
|
||||
public AuthDialog(NStack.ustring title, int width, int height, params Button[] buttons): base(title, width, height, buttons)
|
||||
{
|
||||
}
|
||||
|
||||
public static AuthDialog CreateNew(AuthViewModel VM)
|
||||
{
|
||||
var login = new Button("Login");
|
||||
var cancel = new Button("Cancel");
|
||||
|
||||
var loginLabel = new Label("Email:") { X = 1, Y = 2, Width = 10, Height = 1 };
|
||||
var passwordLabel = new Label("Password:") { X = 1, Y = 4, Width = 10, Height = 1 };
|
||||
var dialog = new AuthDialog("AutoCat Login", 60, 10, login, cancel);
|
||||
dialog.emailField = new TextField() { X = 11, Y = 2, Width = Dim.Fill() - 1, Height = 1 };
|
||||
dialog.passwordField = new TextField() { X = 11, Y = 4, Width = Dim.Fill() - 1, Height = 1, Secret = true };
|
||||
dialog.Add(loginLabel, dialog.emailField, passwordLabel, dialog.passwordField);
|
||||
|
||||
dialog.emailField.SetFocus();
|
||||
dialog.viewModel = VM;
|
||||
|
||||
cancel.Clicked += () => { Application.RequestStop(); };
|
||||
login.Clicked += dialog.LoginClicked;
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
async void LoginClicked()
|
||||
{
|
||||
await viewModel.Login(emailField.Text.ToString(), passwordField.Text.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -8,7 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace AutoCat.ViewModel
|
||||
namespace AutoCatCore.ViewModel
|
||||
{
|
||||
public class AuthViewModel
|
||||
{
|
||||
@ -23,10 +23,9 @@ namespace AutoCat.ViewModel
|
||||
public AuthViewModel(IDialogService dialogService)
|
||||
{
|
||||
this.dialogService = dialogService;
|
||||
Init();
|
||||
}
|
||||
|
||||
private async void Init()
|
||||
public async Task Init()
|
||||
{
|
||||
dbContext = new AutoCatDbContext();
|
||||
await dbContext.Database.EnsureCreatedAsync();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user