diff --git a/src/WorkFlowCheck.MAUI/App.xaml.cs b/src/WorkFlowCheck.MAUI/App.xaml.cs index 0a4b0cd..f32e821 100644 --- a/src/WorkFlowCheck.MAUI/App.xaml.cs +++ b/src/WorkFlowCheck.MAUI/App.xaml.cs @@ -1,5 +1,8 @@ -using Microsoft.EntityFrameworkCore; +using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Maui.Core; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using System.Threading; using WorkFlowCheck.Common.DTO; using WorkFlowCheck.MAUI.DataLayer; using WorkFlowCheck.MAUI.Services; @@ -10,22 +13,29 @@ namespace WorkFlowCheck.MAUI public partial class App : Application { private readonly AppDbContext _dbContext; + private readonly IUserService _userService; + private readonly ISyncService _syncService; + private CancellationTokenSource _cancellationTokenSource; + public App(IServiceProvider serviceProvider) { InitializeComponent(); _dbContext = serviceProvider.GetRequiredService(); + _userService = serviceProvider.GetRequiredService(); + _syncService = serviceProvider.GetRequiredService(); _dbContext.Database.EnsureDeleted(); // Adatbázis törlése _dbContext.Database.EnsureCreated(); // Új adatbázis létrehozása - + StartBackgroundTask(); MainPage = new AppShell(); //MainPage = new NavigationPage(new MainPage(serviceProvider.GetRequiredService())); } protected async override void OnResume() { + StartBackgroundTask(); base.OnResume(); var isLogged = await SecureStorage.Default.GetAsync("WFCUser"); if (isLogged == null) @@ -35,6 +45,7 @@ namespace WorkFlowCheck.MAUI } protected override void OnSleep() { + _cancellationTokenSource?.Cancel(); SecureStorage.Default.Remove("WFCUser"); base.OnSleep(); } @@ -44,6 +55,67 @@ namespace WorkFlowCheck.MAUI SecureStorage.Default.Remove("WFCUser"); await Shell.Current.GoToAsync("//LoginPage"); } + + + private void StartBackgroundTask() + { + _cancellationTokenSource = new CancellationTokenSource(); + Task.Run(() => BackgroundTask(_cancellationTokenSource.Token)); + } + private async Task BackgroundTask(CancellationToken cancellationToken) + { + while (!cancellationToken.IsCancellationRequested) + { + try + { + var userDTO = _userService.GetCurrentUser(); + + if (userDTO != null && userDTO.Id > 0) + { + if (userDTO.RoleDTO?.Count > 0) + { + foreach (var roleDTO in userDTO.RoleDTO) + { + if (roleDTO.CanEnableBlocked) + { + var deviceMessageDTOList = await _syncService.DeviceMessageReadUnreaded(_userService.DeviceId.ToUpper()); + if (deviceMessageDTOList != null && deviceMessageDTOList.Count > 0) + { + await ShowSnackbar(deviceMessageDTOList[0].Message); + break; + } + } + } + } + } + } + catch (Exception ex) + { + + } + await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); + } + } + private async Task ShowSnackbar(string message) + { + var visualOptions = new SnackbarOptions + { + ActionButtonTextColor = Colors.Yellow, + CornerRadius = new CornerRadius(5), + Font = Microsoft.Maui.Font.SystemFontOfSize(16), + BackgroundColor = Microsoft.Maui.Graphics.Color.Parse("Red"), + TextColor = Colors.Yellow + + }; + var snackbar = Snackbar.Make(message, + duration: TimeSpan.FromSeconds(10), + action: () => Console.WriteLine("Snackbar dismissed"), + actionButtonText: "OK", + visualOptions: visualOptions + ); + + await snackbar.Show(); + } private async Task> CheckSecurity() { var isLogged = await SecureStorage.Default.GetAsync("WFCUser"); diff --git a/src/WorkFlowCheck.MAUI/MainPage.xaml b/src/WorkFlowCheck.MAUI/MainPage.xaml index 4475319..8f347e2 100644 --- a/src/WorkFlowCheck.MAUI/MainPage.xaml +++ b/src/WorkFlowCheck.MAUI/MainPage.xaml @@ -5,20 +5,46 @@ Title="Főmenü" BackgroundColor="#f0f0f0"> - - - - - + + + + - - - - + + + diff --git a/src/WorkFlowCheck.MAUI/MainPage.xaml.cs b/src/WorkFlowCheck.MAUI/MainPage.xaml.cs index e703887..f5874f7 100644 --- a/src/WorkFlowCheck.MAUI/MainPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/MainPage.xaml.cs @@ -1,12 +1,14 @@ -using WorkFlowCheck.Common.DTO; +using DevExpress.Entity.Model.Metadata; +using WorkFlowCheck.Common.DTO; using WorkFlowCheck.MAUI.Pages.Media; using WorkFlowCheck.MAUI.Services.Interfaces; namespace WorkFlowCheck.MAUI { public partial class MainPage : ContentPage { - int count = 0; + private IUserService _userService; + private UserDTO _currentUser; public MainPage(IUserService userService) { @@ -14,31 +16,31 @@ namespace WorkFlowCheck.MAUI _userService = userService; } + private void SetInfo() + { + _currentUser = _userService.GetCurrentUser(); + DeviceId.Text = _userService.DeviceId; + UserInfo.Text = $"{_currentUser?.FirstName} {_currentUser?.LastName}"; + } override protected async void OnAppearing() { base.OnAppearing(); - var currentUser = _userService.GetCurrentUser(); - DeviceId.Text = _userService.DeviceId; - if (currentUser != null) + SetInfo(); + if (_currentUser != null) { - foreach (var role in currentUser.RoleDTO) + AdminFrame.IsVisible = false; + foreach (var role in _currentUser?.RoleDTO) { - if (role.RoleName == "Admin") - { + if (role.IsAdmin) AdminFrame.IsVisible = true; - } - else - { - - } } - } - + } + } private async void OnButtonAction(object sender, EventArgs e) { - } + } private void OnButtonDownloadAPK(object sender, EventArgs e) { Shell.Current.GoToAsync("//DownloadAPKPage"); @@ -57,6 +59,7 @@ namespace WorkFlowCheck.MAUI } private void OnButtonLogout(object sender, EventArgs e) { + _userService.SetCurrentUser(null); SecureStorage.Default.Remove("WFCUser"); SecureStorage.Default.Remove("AuthToken"); Shell.Current.GoToAsync("//LoginPage"); diff --git a/src/WorkFlowCheck.MAUI/Pages/BasePage.xaml b/src/WorkFlowCheck.MAUI/Pages/BasePage.xaml new file mode 100644 index 0000000..eded1fa --- /dev/null +++ b/src/WorkFlowCheck.MAUI/Pages/BasePage.xaml @@ -0,0 +1,42 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Pages/BasePage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/BasePage.xaml.cs new file mode 100644 index 0000000..8018965 --- /dev/null +++ b/src/WorkFlowCheck.MAUI/Pages/BasePage.xaml.cs @@ -0,0 +1,14 @@ +namespace WorkFlowCheck.MAUI.Pages; + +public partial class BasePage : ContentPage +{ + public BasePage() + { + InitializeComponent(); + } + protected void SetContent(View content) + { + MainGrid.Children.Add(content); + + } +} \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml index 5eb8c4f..c7abd21 100644 --- a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml +++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml @@ -5,6 +5,39 @@ x:Class="WorkFlowCheck.MAUI.Pages.CheckList.CheckListPage" Title="Ellenőrzések" BackgroundColor="#f0f0f0"> + + + + (OnBlockItem); } + private void SetInfo() + { + _currentUser = _userService.GetCurrentUser(); + DeviceId.Text = _userService.DeviceId; + UserInfo.Text = $"{_currentUser?.FirstName} {_currentUser?.LastName}"; + } protected override bool OnBackButtonPressed() { Shell.Current.GoToAsync("//MainPage"); @@ -50,7 +56,7 @@ public partial class CheckListPage : ContentPage protected override async void OnAppearing() { base.OnAppearing(); - + SetInfo(); BindingContext = this; await LoadCheckListTemplate(); await LoadCheckList(); @@ -90,15 +96,15 @@ public partial class CheckListPage : ContentPage private async Task LoadCheckListTemplate() { IsLoading = true; - var userId = _userService.GetCurrentUser()?.Id; - CheckListTemplate.ItemsSource = await _checkListService.GetCheckListTemplates(userId ?? 1); + + CheckListTemplate.ItemsSource = await _checkListService.GetCheckListTemplates(_currentUser.Id); IsLoading = false; } private async Task LoadCheckList() { IsLoading = true; - var userId = _userService.GetCurrentUser()?.Id; - CheckList.ItemsSource = await _checkListService.GetCheckLists(userId ?? 1); + + CheckList.ItemsSource = await _checkListService.GetCheckLists(_currentUser.Id); IsLoading = false; } diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml index 0f170f5..eda4002 100644 --- a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml +++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml @@ -6,6 +6,39 @@ xmlns:local="clr-namespace:WorkFlowCheck.MAUI.Pages.CheckList" BackgroundColor="#f0f0f0" Title=""> + + + +