From 6372de0bfeb47da07d5811f2844bcdb2a515b9a2 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Tue, 16 Mar 2021 08:26:02 +0300 Subject: [PATCH] AuthViewModel.cs: ACTerm login UI --- ACTerm/ACTerm.csproj | 3 ++ ACTerm/DialogService.cs | 22 +++++++++++++ ACTerm/Program.cs | 34 +++++++++++++++++-- ACTerm/Views/AuthDialog.cs | 44 +++++++++++++++++++++++++ ACTerm/autocat.db | Bin 20480 -> 0 bytes AutoCatCore/ViewModel/AuthViewModel.cs | 5 ++- 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 ACTerm/DialogService.cs create mode 100644 ACTerm/Views/AuthDialog.cs delete mode 100644 ACTerm/autocat.db diff --git a/ACTerm/ACTerm.csproj b/ACTerm/ACTerm.csproj index 95ceb9e..9a6d6a9 100644 --- a/ACTerm/ACTerm.csproj +++ b/ACTerm/ACTerm.csproj @@ -18,4 +18,7 @@ + + + diff --git a/ACTerm/DialogService.cs b/ACTerm/DialogService.cs new file mode 100644 index 0000000..8b7fdb1 --- /dev/null +++ b/ACTerm/DialogService.cs @@ -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"); + } + } +} diff --git a/ACTerm/Program.cs b/ACTerm/Program.cs index ff0eacc..0bdb1ef 100644 --- a/ACTerm/Program.cs +++ b/ACTerm/Program.cs @@ -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(); } } } diff --git a/ACTerm/Views/AuthDialog.cs b/ACTerm/Views/AuthDialog.cs new file mode 100644 index 0000000..b2c32fd --- /dev/null +++ b/ACTerm/Views/AuthDialog.cs @@ -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()); + } + } +} diff --git a/ACTerm/autocat.db b/ACTerm/autocat.db deleted file mode 100644 index 7462f41db1fcffa2419202ed9352471a9ad33d40..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI%F;Ck-6bJBUJ3t%Bn9ZWolcz>PQA~m|ph^v?Q7w#<8mEGxvP^SOt05M)ky>?v zFVl%H!@$VKcj#EfB&4luRWQ-&{~Ijd)4TKC(=F%Qd*?)%;G;M>2{Ufe3du6PW+ozq zh!$v0CZfu`NzyOxWfZEnSk-<|MZKowEA3LfUjAN|3;+NC0000Fb?z!lx~@wX-?H#< zBnGKS()>~BdRE7`*zasP78`lY;FoHZnc1*T!f0f$Z|(c+_I!2+j>FxayXSiy+x6M# z?*!8>eb3(Qcn7>=9jr}z`|)Qnp7kC$&MdwiCE_qlg+2URh9`~^k$(C!O|8~yl|}uP zE>ScdiZAKuD9S_-o@H^~zME5E=2KfZ-i)+47?PpT}wDiKNA4QV$I-D3a%000000Pr-hq-?IPH`dLD*=U)qjSaIIbQ2L~;>}jG zZr064H9!B~l6LzvW()uT000000FU%S*?eB|7hrP#Pb-fc7XSbN00000{t1)&f1LjT N000000091PKLM