diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs index c075d44..4c92669 100644 --- a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs @@ -1,3 +1,5 @@ +using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Maui.Core; using System.Diagnostics; using System.Globalization; using System.Threading.Tasks; @@ -13,6 +15,7 @@ public partial class CheckListPage : ContentPage { private readonly ICheckListService _checkListService; private readonly IUserService _userService; + private readonly ISyncService _syncService; private bool _isLoading; private UserDTO _currentUser; @@ -36,6 +39,7 @@ public partial class CheckListPage : ContentPage InitializeComponent(); _checkListService = MauiProgram.ServiceProvider.GetRequiredService(); _userService = MauiProgram.ServiceProvider.GetRequiredService(); + _syncService = MauiProgram.ServiceProvider.GetRequiredService(); NewCommand = new Command(OnNewItem); ContinueCommand = new Command(OnContinueItem); UnblockCommand = new Command(OnUnblockItem); @@ -64,13 +68,48 @@ public partial class CheckListPage : ContentPage private async void OnNewItem(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO) { IsLoading = true; - await _checkListService.StartNew( + var response = await _checkListService.StartNew( new CheckListHeaderNewDTO() { UserId = _userService.GetCurrentUser().Id, CheckListTemplateHeaderId = checkListTemplateHeaderDTO.Id }); IsLoading = false; + + if (response != null && response.IsSuccess) + { + await Task.Run(async () => + { + await _syncService.SyncCheckListHeader_Down((percentage, infostring) => + { + // Direkt UI frissítés + MainThread.BeginInvokeOnMainThread(() => + { + //progressBar.Progress = percentage / 100; + //progressLabel.Text = $"{infostring}: {percentage:0.00}%"; + }); + }); + }); + await LoadCheckList(); + var visualOptions = new SnackbarOptions + { + ActionButtonTextColor = Colors.White, + CornerRadius = new CornerRadius(10), + Font = Microsoft.Maui.Font.SystemFontOfSize(16), + BackgroundColor = Microsoft.Maui.Graphics.Color.Parse("Green"), + TextColor = Colors.White + + }; + var snackbar = Snackbar.Make( + $"Új ellenőrzés indult! {response.Data.DocumentNumber}", + duration: TimeSpan.FromSeconds(10), + action: () => Console.WriteLine("Snackbar dismissed"), + actionButtonText: "OK", + visualOptions: visualOptions + ); + + await snackbar.Show(); + } } private async void OnContinueItem(CheckListHeaderDTO checkListHeaderDTO) { @@ -96,15 +135,34 @@ public partial class CheckListPage : ContentPage private async Task LoadCheckListTemplate() { IsLoading = true; - + CheckListTemplate.ItemsSource = await _checkListService.GetCheckListTemplates(_currentUser.Id); IsLoading = false; } private async Task LoadCheckList() { IsLoading = true; - - CheckList.ItemsSource = await _checkListService.GetCheckLists(_currentUser.Id); + + var checkListHeaderDTOs = await _checkListService.GetCheckLists(_currentUser.Id); + var isAdmin = false; + var userDTO = _userService.GetCurrentUser(); + foreach (var roleDTO in userDTO.RoleDTO) + { + if (roleDTO.IsAdmin) + { + isAdmin = true; + CheckList.ItemsSource = checkListHeaderDTOs; + break; + } + } + + if (!isAdmin) + { + var result = checkListHeaderDTOs + .Where(w => w.UserId == userDTO.Id && w.CheckStatus != CheckStatus.Blocked).ToList(); + CheckList.ItemsSource = result; + } + IsLoading = false; } diff --git a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml index 5cb8602..50bc67d 100644 --- a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml +++ b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="WorkFlowCheck.MAUI.Pages.Security.LoginPage" xmlns:local="clr-namespace:WorkFlowCheck.MAUI.Pages" - Title="BejelentkezĂ©s" + Title="Workflow Check Application (v0.988)" BackgroundColor="#f0f0f0"> @@ -45,7 +45,7 @@ (); try { - var res = await _dbContext.CheckListHeaders.ToListAsync(); + var res = await _dbContext.CheckListHeaders + .Where(w => w.CheckStatus == CheckStatus.Open || + w.CheckStatus == CheckStatus.InProgress || + w.CheckStatus == CheckStatus.Blocked) + .ToListAsync(); retVal = _mapper.Map>(res); } catch (Exception ex) diff --git a/src/WorkFlowCheck.MAUI/Services/SyncService.cs b/src/WorkFlowCheck.MAUI/Services/SyncService.cs index 4c4809e..dad7eef 100644 --- a/src/WorkFlowCheck.MAUI/Services/SyncService.cs +++ b/src/WorkFlowCheck.MAUI/Services/SyncService.cs @@ -151,7 +151,7 @@ namespace WorkFlowCheck.MAUI.Services var checkPointListDTO = _mapper.Map>(checkPointList); var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllCheckPoint"; - var json = JsonConvert.SerializeObject(checkPointListDTO); + var json = JsonConvert.SerializeObject(checkPointListDTO, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var jsonBytes = Encoding.UTF8.GetBytes(json); var jsonStream = new MemoryStream(jsonBytes); @@ -314,11 +314,7 @@ namespace WorkFlowCheck.MAUI.Services var checkListHeaderDTO = _mapper.Map(checkListHeader); var endpoint = $"{_httpClient.BaseAddress}api/Sync/SendCheckListHeader"; - var json = JsonConvert.SerializeObject(checkListHeaderDTO, - new JsonSerializerSettings - { - ReferenceLoopHandling = ReferenceLoopHandling.Ignore - }); + var json = JsonConvert.SerializeObject(checkListHeaderDTO, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var jsonBytes = Encoding.UTF8.GetBytes(json); var jsonStream = new MemoryStream(jsonBytes); diff --git a/src/WorkFlowCheck.MAUI/Services/UserService.cs b/src/WorkFlowCheck.MAUI/Services/UserService.cs index eac5c9e..e099b7c 100644 --- a/src/WorkFlowCheck.MAUI/Services/UserService.cs +++ b/src/WorkFlowCheck.MAUI/Services/UserService.cs @@ -160,7 +160,7 @@ namespace WorkFlowCheck.MAUI.Services var userListDTO = _mapper.Map>(userList); var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllUser"; - var json = JsonConvert.SerializeObject(userListDTO); + var json = JsonConvert.SerializeObject(userListDTO, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var jsonBytes = Encoding.UTF8.GetBytes(json); var jsonStream = new MemoryStream(jsonBytes); @@ -187,7 +187,7 @@ namespace WorkFlowCheck.MAUI.Services } return retVal; } - + public void SetCurrentUser(UserDTO user) { CurrentUser = user;