From ab9578a45faadbe6390a9a87a5e8c4232cb5840a Mon Sep 17 00:00:00 2001 From: MarcoE Date: Mon, 2 Mar 2026 10:50:34 +0100 Subject: [PATCH] Gestiti salvataggi rest --- .idea/.idea.SteUp/.idea/.gitignore | 15 -- .idea/.idea.SteUp/.idea/.name | 1 - .../.idea/AndroidProjectSystem.xml | 6 - .../.idea/deploymentTargetSelector.xml | 10 - .idea/.idea.SteUp/.idea/encodings.xml | 4 - .idea/.idea.SteUp/.idea/indexLayout.xml | 8 - .../androidx_annotation_annotation.xml | 9 - .../androidx_annotation_annotation_jvm.xml | 9 - .../androidx_arch_core_core_common.xml | 9 - .../androidx_collection_collection.xml | 9 - .../androidx_collection_collection_jvm.xml | 9 - .../androidx_collection_collection_ktx.xml | 9 - ...androidx_concurrent_concurrent_futures.xml | 9 - ...constraintlayout_constraintlayout_core.xml | 9 - .../androidx_lifecycle_lifecycle_common.xml | 9 - ...roidx_lifecycle_lifecycle_common_java8.xml | 9 - ...ndroidx_lifecycle_lifecycle_common_jvm.xml | 9 - ...spection_resourceinspection_annotation.xml | 9 - .idea/.idea.SteUp/.idea/vcs.xml | 6 - .../EntityServices/IspezioniService.cs | 60 ++++- ...0260226155235_ModDataIspezione.Designer.cs | 148 +++++++++++++ .../20260226155235_ModDataIspezione.cs | 22 ++ .../20260227102100_AddActivityId.Designer.cs | 154 +++++++++++++ .../20260227102100_AddActivityId.cs | 38 ++++ .../Migrations/AppDbContextModelSnapshot.cs | 10 +- SteUp.Maui/Core/CoreModule.cs | 2 + SteUp.Maui/Core/Services/AttachedService.cs | 209 +++++++++++++++--- .../Android/Core/HoneywellScannerService.cs | 2 + SteUp.Shared/Components/Layout/NavMenu.razor | 23 +- .../Components/Pages/IspezionePage.razor | 139 +++++++++++- .../Components/Pages/IspezionePage.razor.css | 6 + SteUp.Shared/Components/Pages/LoginPage.razor | 2 + .../Pages/Utility/AuthorizingPage.razor | 2 + SteUp.Shared/Components/Routes.razor | 47 ++-- .../SingleElements/Card/SchedaCard.razor | 74 ++++++- .../SingleElements/Card/ShopCard.razor | 2 +- .../Modal/ModalFormScheda.razor | 166 ++++++++++---- SteUp.Shared/Core/Data/SteupDataService.cs | 47 +++- SteUp.Shared/Core/Dto/AttachedDto.cs | 1 + .../Dto/RetrieveStatoIspezioniRequestDto.cs | 9 + SteUp.Shared/Core/Dto/SaveRequestDto.cs | 37 ++++ .../Core/Dto/SaveSchedaResponseDto.cs | 24 ++ SteUp.Shared/Core/Dto/StbActivityDto.cs | 12 + SteUp.Shared/Core/Entities/Ispezione.cs | 4 +- SteUp.Shared/Core/Entities/Scheda.cs | 5 +- SteUp.Shared/Core/Enum/ScadenzaEnum.cs | 9 + SteUp.Shared/Core/Enum/StatusEnum.cs | 3 +- SteUp.Shared/Core/Helpers/ModalHelper.cs | 2 +- SteUp.Shared/Core/Helpers/ObjectExtensions.cs | 4 + SteUp.Shared/Core/Helpers/StatusEnumHelper.cs | 20 +- .../IntegryApi/IIntegrySteupService.cs | 7 + .../Interface/LocalDb/IIspezioniService.cs | 16 +- .../Core/Interface/System/IAttachedService.cs | 16 +- .../Ispezione/CompleteInspectionMessage.cs | 5 + .../Ispezione/CompleteInspectionService.cs | 13 ++ .../Core/Services/IntegryApiService.cs | 1 + .../Core/Services/IntegrySteupService.cs | 37 +++- SteUp.Shared/_Imports.razor | 4 +- 58 files changed, 1235 insertions(+), 305 deletions(-) delete mode 100644 .idea/.idea.SteUp/.idea/.gitignore delete mode 100644 .idea/.idea.SteUp/.idea/.name delete mode 100644 .idea/.idea.SteUp/.idea/AndroidProjectSystem.xml delete mode 100644 .idea/.idea.SteUp/.idea/deploymentTargetSelector.xml delete mode 100644 .idea/.idea.SteUp/.idea/encodings.xml delete mode 100644 .idea/.idea.SteUp/.idea/indexLayout.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation_jvm.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_arch_core_core_common.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_collection_collection.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_jvm.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_ktx.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_concurrent_concurrent_futures.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_constraintlayout_constraintlayout_core.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_jvm.xml delete mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_resourceinspection_resourceinspection_annotation.xml delete mode 100644 .idea/.idea.SteUp/.idea/vcs.xml create mode 100644 SteUp.Data/Migrations/20260226155235_ModDataIspezione.Designer.cs create mode 100644 SteUp.Data/Migrations/20260226155235_ModDataIspezione.cs create mode 100644 SteUp.Data/Migrations/20260227102100_AddActivityId.Designer.cs create mode 100644 SteUp.Data/Migrations/20260227102100_AddActivityId.cs create mode 100644 SteUp.Shared/Components/Pages/Utility/AuthorizingPage.razor create mode 100644 SteUp.Shared/Core/Dto/RetrieveStatoIspezioniRequestDto.cs create mode 100644 SteUp.Shared/Core/Dto/SaveRequestDto.cs create mode 100644 SteUp.Shared/Core/Dto/SaveSchedaResponseDto.cs create mode 100644 SteUp.Shared/Core/Dto/StbActivityDto.cs create mode 100644 SteUp.Shared/Core/Enum/ScadenzaEnum.cs create mode 100644 SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionMessage.cs create mode 100644 SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionService.cs diff --git a/.idea/.idea.SteUp/.idea/.gitignore b/.idea/.idea.SteUp/.idea/.gitignore deleted file mode 100644 index 6235314..0000000 --- a/.idea/.idea.SteUp/.idea/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/modules.xml -/projectSettingsUpdater.xml -/.idea.SteUp.iml -/contentModel.xml -# Ignored default folder with query files -/queries/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/.idea.SteUp/.idea/.name b/.idea/.idea.SteUp/.idea/.name deleted file mode 100644 index b23cc04..0000000 --- a/.idea/.idea.SteUp/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -SteUp \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/AndroidProjectSystem.xml b/.idea/.idea.SteUp/.idea/AndroidProjectSystem.xml deleted file mode 100644 index e82600c..0000000 --- a/.idea/.idea.SteUp/.idea/AndroidProjectSystem.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/deploymentTargetSelector.xml b/.idea/.idea.SteUp/.idea/deploymentTargetSelector.xml deleted file mode 100644 index e4966f8..0000000 --- a/.idea/.idea.SteUp/.idea/deploymentTargetSelector.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/encodings.xml b/.idea/.idea.SteUp/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/.idea/.idea.SteUp/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/indexLayout.xml b/.idea/.idea.SteUp/.idea/indexLayout.xml deleted file mode 100644 index 7b08163..0000000 --- a/.idea/.idea.SteUp/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation.xml deleted file mode 100644 index ef552ef..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation_jvm.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation_jvm.xml deleted file mode 100644 index 05a7adc..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_annotation_annotation_jvm.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_arch_core_core_common.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_arch_core_core_common.xml deleted file mode 100644 index d3fed0b..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_arch_core_core_common.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection.xml deleted file mode 100644 index 1fbdfc4..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_jvm.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_jvm.xml deleted file mode 100644 index e916fc5..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_jvm.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_ktx.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_ktx.xml deleted file mode 100644 index d7beaa7..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_collection_collection_ktx.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_concurrent_concurrent_futures.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_concurrent_concurrent_futures.xml deleted file mode 100644 index bf6ad25..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_concurrent_concurrent_futures.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_constraintlayout_constraintlayout_core.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_constraintlayout_constraintlayout_core.xml deleted file mode 100644 index f4ebaee..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_constraintlayout_constraintlayout_core.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common.xml deleted file mode 100644 index 1c0e22c..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml deleted file mode 100644 index f6d16a8..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_jvm.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_jvm.xml deleted file mode 100644 index d50ac06..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_jvm.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_resourceinspection_resourceinspection_annotation.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_resourceinspection_resourceinspection_annotation.xml deleted file mode 100644 index 9ac54c0..0000000 --- a/.idea/.idea.SteUp/.idea/libraries/androidx_resourceinspection_resourceinspection_annotation.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/vcs.xml b/.idea/.idea.SteUp/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/.idea.SteUp/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs b/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs index 17a9c97..42f20f8 100644 --- a/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs +++ b/SteUp.Data/LocalDb/EntityServices/IspezioniService.cs @@ -1,12 +1,14 @@ using Microsoft.EntityFrameworkCore; using SteUp.Shared.Core.Entities; +using SteUp.Shared.Core.Enum; +using SteUp.Shared.Core.Helpers; using SteUp.Shared.Core.Interface.LocalDb; namespace SteUp.Data.LocalDb.EntityServices; public class IspezioniService(AppDbContext db) : IIspezioniService { - public Task GetIspezioneAsync(string codMdep, DateOnly data, string rilevatore) => + public Task GetIspezioneAsync(string codMdep, DateTime data, string rilevatore) => db.Ispezioni .Include(x => x.Schede) .ThenInclude(s => s.Articoli) @@ -29,7 +31,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService await db.SaveChangesAsync(); } - public async Task GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore) + public async Task GetOrCreateIspezioneAsync(string codMdep, DateTime data, string rilevatore) { var existing = await db.Ispezioni .AsNoTracking() @@ -65,11 +67,46 @@ public class IspezioniService(AppDbContext db) : IIspezioniService await db.SaveChangesAsync(); return true; } + + public async Task UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore, StatusEnum stato) + { + var ispezione = await db.Ispezioni + .FirstOrDefaultAsync(x => + x.CodMdep == codMdep && + x.Data == data && + x.Rilevatore == rilevatore); + + if (ispezione is null) + return false; + + ispezione.Stato = stato; + db.Ispezioni.Update(ispezione); + await db.SaveChangesAsync(); + return true; + } + + public async Task UpdateActivityIdIspezioneAsync(string codMdep, DateTime data, string rilevatore, + string? activityId) + { + var ispezione = await db.Ispezioni + .FirstOrDefaultAsync(x => + x.CodMdep == codMdep && + x.Data == data && + x.Rilevatore == rilevatore); + + if (ispezione is null) + return false; + + ispezione.ActivityId = activityId; + db.Ispezioni.Update(ispezione); + await db.SaveChangesAsync(); + return true; + } /// /// Cancella l'ispezione e tutte le schede collegate (e relativi articoli via cascade). /// - public async Task DeleteIspezioneAsync(string codMdep, DateOnly data, string rilevatore) + public async Task DeleteIspezioneAsync(string codMdep, DateTime data, string rilevatore) { var ispezione = await db.Ispezioni .FirstOrDefaultAsync(x => @@ -85,7 +122,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService return true; } - public async Task AddSchedaAsync(string codMdep, DateOnly data, string rilevatore, Scheda scheda) + public async Task AddSchedaAsync(string codMdep, DateTime data, string rilevatore, Scheda scheda) { await GetOrCreateIspezioneAsync(codMdep, data, rilevatore); @@ -105,7 +142,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService await db.SaveChangesAsync(); } - public Task> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore) => + public Task> GetAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore) => db.Schede .AsNoTracking() .Include(s => s.Articoli) @@ -127,6 +164,17 @@ public class IspezioniService(AppDbContext db) : IIspezioniService .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == schedaId); + public async Task UpdateActivityIdSchedaAsync(int schedaId, string? activityId) + { + var scheda = await db.Schede.FirstOrDefaultAsync(x => x.Id == schedaId); + if (scheda is null) return false; + + scheda.ActivityId = activityId; + db.Schede.Update(scheda); + await db.SaveChangesAsync(); + return true; + } + public async Task DeleteSchedaAsync(int schedaId) { var scheda = await db.Schede.FirstOrDefaultAsync(x => x.Id == schedaId); @@ -197,7 +245,7 @@ public class IspezioniService(AppDbContext db) : IIspezioniService /// /// Cancella tutte le schede di una ispezione senza cancellare l'ispezione. /// - public async Task DeleteAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore) + public async Task DeleteAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore) { var schede = await db.Schede .Where(s => diff --git a/SteUp.Data/Migrations/20260226155235_ModDataIspezione.Designer.cs b/SteUp.Data/Migrations/20260226155235_ModDataIspezione.Designer.cs new file mode 100644 index 0000000..f7414f2 --- /dev/null +++ b/SteUp.Data/Migrations/20260226155235_ModDataIspezione.Designer.cs @@ -0,0 +1,148 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SteUp.Data.LocalDb; + +#nullable disable + +namespace SteUp.Data.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20260226155235_ModDataIspezione")] + partial class ModDataIspezione + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.3"); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b => + { + b.Property("CodMdep") + .HasColumnType("TEXT"); + + b.Property("Data") + .HasColumnType("TEXT"); + + b.Property("Rilevatore") + .HasColumnType("TEXT"); + + b.Property("Stato") + .HasColumnType("INTEGER"); + + b.HasKey("CodMdep", "Data", "Rilevatore"); + + b.ToTable("Ispezioni"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActivityTypeId") + .HasColumnType("TEXT"); + + b.Property("CodJfas") + .HasColumnType("TEXT"); + + b.Property("CodMdep") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Data") + .HasColumnType("TEXT"); + + b.Property("DescrizioneReparto") + .HasColumnType("TEXT"); + + b.Property("ImageNames") + .HasColumnType("TEXT"); + + b.Property("Note") + .HasColumnType("TEXT"); + + b.Property("Responsabile") + .HasColumnType("TEXT"); + + b.Property("Rilevatore") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Scadenza") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("CodMdep", "Data", "Rilevatore"); + + b.ToTable("Schede"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Barcode") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.Property("Descrizione") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("SchedaId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("SchedaId", "Barcode") + .IsUnique(); + + b.ToTable("SchedaArticoli"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b => + { + b.HasOne("SteUp.Shared.Core.Entities.Ispezione", "Ispezione") + .WithMany("Schede") + .HasForeignKey("CodMdep", "Data", "Rilevatore") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ispezione"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b => + { + b.HasOne("SteUp.Shared.Core.Entities.Scheda", "Scheda") + .WithMany("Articoli") + .HasForeignKey("SchedaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Scheda"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b => + { + b.Navigation("Schede"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b => + { + b.Navigation("Articoli"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SteUp.Data/Migrations/20260226155235_ModDataIspezione.cs b/SteUp.Data/Migrations/20260226155235_ModDataIspezione.cs new file mode 100644 index 0000000..ab1e7bc --- /dev/null +++ b/SteUp.Data/Migrations/20260226155235_ModDataIspezione.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SteUp.Data.Migrations +{ + /// + public partial class ModDataIspezione : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/SteUp.Data/Migrations/20260227102100_AddActivityId.Designer.cs b/SteUp.Data/Migrations/20260227102100_AddActivityId.Designer.cs new file mode 100644 index 0000000..dca2dea --- /dev/null +++ b/SteUp.Data/Migrations/20260227102100_AddActivityId.Designer.cs @@ -0,0 +1,154 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SteUp.Data.LocalDb; + +#nullable disable + +namespace SteUp.Data.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20260227102100_AddActivityId")] + partial class AddActivityId + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "10.0.3"); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b => + { + b.Property("CodMdep") + .HasColumnType("TEXT"); + + b.Property("Data") + .HasColumnType("TEXT"); + + b.Property("Rilevatore") + .HasColumnType("TEXT"); + + b.Property("ActivityId") + .HasColumnType("TEXT"); + + b.Property("Stato") + .HasColumnType("INTEGER"); + + b.HasKey("CodMdep", "Data", "Rilevatore"); + + b.ToTable("Ispezioni"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActivityId") + .HasColumnType("TEXT"); + + b.Property("ActivityTypeId") + .HasColumnType("TEXT"); + + b.Property("CodJfas") + .HasColumnType("TEXT"); + + b.Property("CodMdep") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Data") + .HasColumnType("TEXT"); + + b.Property("DescrizioneReparto") + .HasColumnType("TEXT"); + + b.Property("ImageNames") + .HasColumnType("TEXT"); + + b.Property("Note") + .HasColumnType("TEXT"); + + b.Property("Responsabile") + .HasColumnType("TEXT"); + + b.Property("Rilevatore") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Scadenza") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("CodMdep", "Data", "Rilevatore"); + + b.ToTable("Schede"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Barcode") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.Property("Descrizione") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("SchedaId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("SchedaId", "Barcode") + .IsUnique(); + + b.ToTable("SchedaArticoli"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b => + { + b.HasOne("SteUp.Shared.Core.Entities.Ispezione", "Ispezione") + .WithMany("Schede") + .HasForeignKey("CodMdep", "Data", "Rilevatore") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Ispezione"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.SchedaArticolo", b => + { + b.HasOne("SteUp.Shared.Core.Entities.Scheda", "Scheda") + .WithMany("Articoli") + .HasForeignKey("SchedaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Scheda"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Ispezione", b => + { + b.Navigation("Schede"); + }); + + modelBuilder.Entity("SteUp.Shared.Core.Entities.Scheda", b => + { + b.Navigation("Articoli"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SteUp.Data/Migrations/20260227102100_AddActivityId.cs b/SteUp.Data/Migrations/20260227102100_AddActivityId.cs new file mode 100644 index 0000000..a67d175 --- /dev/null +++ b/SteUp.Data/Migrations/20260227102100_AddActivityId.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SteUp.Data.Migrations +{ + /// + public partial class AddActivityId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ActivityId", + table: "Schede", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "ActivityId", + table: "Ispezioni", + type: "TEXT", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ActivityId", + table: "Schede"); + + migrationBuilder.DropColumn( + name: "ActivityId", + table: "Ispezioni"); + } + } +} diff --git a/SteUp.Data/Migrations/AppDbContextModelSnapshot.cs b/SteUp.Data/Migrations/AppDbContextModelSnapshot.cs index 6c39e20..21aa4ae 100644 --- a/SteUp.Data/Migrations/AppDbContextModelSnapshot.cs +++ b/SteUp.Data/Migrations/AppDbContextModelSnapshot.cs @@ -22,12 +22,15 @@ namespace SteUp.Data.Migrations b.Property("CodMdep") .HasColumnType("TEXT"); - b.Property("Data") + b.Property("Data") .HasColumnType("TEXT"); b.Property("Rilevatore") .HasColumnType("TEXT"); + b.Property("ActivityId") + .HasColumnType("TEXT"); + b.Property("Stato") .HasColumnType("INTEGER"); @@ -42,6 +45,9 @@ namespace SteUp.Data.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("ActivityId") + .HasColumnType("TEXT"); + b.Property("ActivityTypeId") .HasColumnType("TEXT"); @@ -52,7 +58,7 @@ namespace SteUp.Data.Migrations .IsRequired() .HasColumnType("TEXT"); - b.Property("Data") + b.Property("Data") .HasColumnType("TEXT"); b.Property("DescrizioneReparto") diff --git a/SteUp.Maui/Core/CoreModule.cs b/SteUp.Maui/Core/CoreModule.cs index 0229573..3a9131c 100644 --- a/SteUp.Maui/Core/CoreModule.cs +++ b/SteUp.Maui/Core/CoreModule.cs @@ -15,6 +15,7 @@ using SteUp.Shared.Core.Interface.IntegryApi; using SteUp.Shared.Core.Interface.LocalDb; using SteUp.Shared.Core.Interface.System; using SteUp.Shared.Core.Interface.System.Network; +using SteUp.Shared.Core.Messages.Ispezione; using SteUp.Shared.Core.Messages.Scanner; using SteUp.Shared.Core.Messages.Scheda; using SteUp.Shared.Core.Services; @@ -60,6 +61,7 @@ public static class CoreModule builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); } public void RegisterDbServices() diff --git a/SteUp.Maui/Core/Services/AttachedService.cs b/SteUp.Maui/Core/Services/AttachedService.cs index 19de1a5..37875e5 100644 --- a/SteUp.Maui/Core/Services/AttachedService.cs +++ b/SteUp.Maui/Core/Services/AttachedService.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Logging.Abstractions; -using SteUp.Shared.Core.Dto; +using SteUp.Shared.Core.Dto; using SteUp.Shared.Core.Entities; using SteUp.Shared.Core.Helpers; using SteUp.Shared.Core.Interface.System; @@ -82,10 +81,10 @@ public class AttachedService : IAttachedService }; } - private async Task ConvertToDto(FileInfo file, AttachedDto.TypeAttached type) + private async Task ConvertToDto(FileInfo file, AttachedDto.TypeAttached type, bool isFromToUpload) { var (origUrl, thumbUrl) = await SaveAndCreateThumbAsync( - await File.ReadAllBytesAsync(file.FullName), + await File.ReadAllBytesAsync(file.FullName), file.Name ); @@ -96,64 +95,202 @@ public class AttachedService : IAttachedService TempPath = origUrl, ThumbPath = thumbUrl, Type = type, - SavedOnAppData = true + SavedOnAppData = true, + ToUpload = isFromToUpload }; } - public async Task?> GetInspectionFiles(Ispezione ispezione) + private const string ToUploadFolderName = "toUpload"; + + private string GetInspectionBaseDir(Ispezione ispezione) { var baseDir = FileSystem.AppDataDirectory; - var inspectionDir = Path.Combine(baseDir, $"attached_{GetInspectionKey(ispezione)}"); - var directory = new DirectoryInfo(inspectionDir); - - if (!directory.Exists) return null; - - var fileList = directory.GetFiles().ToList(); - - var returnList = new List(); - foreach (var file in fileList) - { - returnList.Add(await ConvertToDto(file, AttachedDto.TypeAttached.Image)); - } - - return returnList; + return Path.Combine(baseDir, $"attached_{GetInspectionKey(ispezione)}"); } - public async Task SaveInspectionFile(Ispezione ispezione, byte[] file, string fileName, + private string GetInspectionToUploadDir(Ispezione ispezione) + => Path.Combine(GetInspectionBaseDir(ispezione), ToUploadFolderName); + + private string GetInspectionFinalDir(Ispezione ispezione) + => GetInspectionBaseDir(ispezione); + + /// + /// Ritorna i file dell'ispezione filtrati per nome. + /// Per default include sia "final" sia "toUpload" (utile per UI). + /// + public async Task?> GetInspectionFiles( + Ispezione ispezione, + List fileNameFilter, + bool includeToUpload, + CancellationToken ct) + { + ArgumentNullException.ThrowIfNull(ispezione); + ArgumentNullException.ThrowIfNull(fileNameFilter); + + var baseDir = GetInspectionBaseDir(ispezione); + if (!Directory.Exists(baseDir)) return null; + + var result = new List(); + + var finalDir = GetInspectionFinalDir(ispezione); + if (Directory.Exists(finalDir)) + { + var finalFiles = new DirectoryInfo(finalDir) + .GetFiles("*", SearchOption.TopDirectoryOnly); + + foreach (var file in finalFiles) + { + if (file.Directory?.Name == ToUploadFolderName) + continue; + + if (!fileNameFilter.Contains(file.Name)) + continue; + + ct.ThrowIfCancellationRequested(); + + result.Add(await ConvertToDto( + file, + AttachedDto.TypeAttached.Image, + isFromToUpload: false)); + } + } + + if (!includeToUpload) return result; + + var toUploadDir = GetInspectionToUploadDir(ispezione); + if (!Directory.Exists(toUploadDir)) return result; + + var toUploadFiles = new DirectoryInfo(toUploadDir) + .GetFiles("*", SearchOption.TopDirectoryOnly); + + foreach (var file in toUploadFiles) + { + if (!fileNameFilter.Contains(file.Name)) + continue; + + ct.ThrowIfCancellationRequested(); + + result.Add(await ConvertToDto( + file, + AttachedDto.TypeAttached.Image, + isFromToUpload: true)); + } + + return result; + } + + /// + /// Salva SEMPRE in /toUpload. + /// + public async Task SaveInspectionFile( + Ispezione ispezione, + byte[] file, + string fileName, CancellationToken ct) { ArgumentNullException.ThrowIfNull(ispezione); ArgumentNullException.ThrowIfNull(file); ArgumentException.ThrowIfNullOrWhiteSpace(fileName); - var baseDir = FileSystem.AppDataDirectory; - var inspectionDir = Path.Combine(baseDir, $"attached_{GetInspectionKey(ispezione)}"); - if (!Directory.Exists(inspectionDir)) Directory.CreateDirectory(inspectionDir); + var toUploadDir = GetInspectionToUploadDir(ispezione); + Directory.CreateDirectory(toUploadDir); - var filePath = Path.Combine(inspectionDir, fileName); + var filePath = Path.Combine(toUploadDir, fileName); await File.WriteAllBytesAsync(filePath, file, ct); return filePath; } - public bool RemoveInspectionFile(Ispezione ispezione, string fileName) + public Task MoveInspectionFileFromToUploadToFinal( + Ispezione ispezione, + string fileName, + bool overwrite, + CancellationToken ct) { - var baseDir = FileSystem.AppDataDirectory; - var inspectionDir = Path.Combine(baseDir, $"attached_{GetInspectionKey(ispezione)}"); + ArgumentNullException.ThrowIfNull(ispezione); + ArgumentException.ThrowIfNullOrWhiteSpace(fileName); - if (!Directory.Exists(inspectionDir)) return false; + ct.ThrowIfCancellationRequested(); + + var toUploadDir = GetInspectionToUploadDir(ispezione); + var finalDir = GetInspectionFinalDir(ispezione); + + if (!Directory.Exists(toUploadDir)) return Task.FromResult(false); + + var sourcePath = Path.Combine(toUploadDir, fileName); + if (!File.Exists(sourcePath)) return Task.FromResult(false); + + Directory.CreateDirectory(finalDir); + + var destPath = Path.Combine(finalDir, fileName); + + if (File.Exists(destPath)) + { + if (!overwrite) return Task.FromResult(false); + File.Delete(destPath); + } + + File.Move(sourcePath, destPath); + + // Pulizia: se /toUpload resta vuota la elimino + CleanupDirectoriesIfEmpty(ispezione); + + return Task.FromResult(true); + } + + /// + /// Rimuove un file cercandolo prima in /toUpload e poi in final (o viceversa). + /// Default: prova a cancellare ovunque. + /// + public bool RemoveInspectionFile( + Ispezione ispezione, + string fileName, + bool removeAlsoFromFinal, + bool removeAlsoFromToUpload) + { + ArgumentNullException.ThrowIfNull(ispezione); if (string.IsNullOrWhiteSpace(fileName)) return false; - var filePath = Path.Combine(inspectionDir, fileName); + var removed = false; - if (!File.Exists(filePath)) return false; - - File.Delete(filePath); + if (removeAlsoFromToUpload) + { + var toUploadPath = Path.Combine(GetInspectionToUploadDir(ispezione), fileName); + if (File.Exists(toUploadPath)) + { + File.Delete(toUploadPath); + removed = true; + } + } - if (!Directory.EnumerateFileSystemEntries(inspectionDir).Any()) - Directory.Delete(inspectionDir); + if (removeAlsoFromFinal) + { + var finalPath = Path.Combine(GetInspectionFinalDir(ispezione), fileName); + if (File.Exists(finalPath)) + { + File.Delete(finalPath); + removed = true; + } + } - return true; + if (removed) + CleanupDirectoriesIfEmpty(ispezione); + + return removed; + } + + private void CleanupDirectoriesIfEmpty(Ispezione ispezione) + { + var baseDir = GetInspectionBaseDir(ispezione); + var toUploadDir = GetInspectionToUploadDir(ispezione); + + // 1) se /toUpload esiste e vuota => delete + if (Directory.Exists(toUploadDir) && !Directory.EnumerateFileSystemEntries(toUploadDir).Any()) + Directory.Delete(toUploadDir); + + // 2) se base dir vuota (attenzione: dopo delete toUpload) => delete + if (Directory.Exists(baseDir) && !Directory.EnumerateFileSystemEntries(baseDir).Any()) + Directory.Delete(baseDir); } public async Task SaveToTempStorage(Stream file, string fileName, CancellationToken ct = default) diff --git a/SteUp.Maui/Platforms/Android/Core/HoneywellScannerService.cs b/SteUp.Maui/Platforms/Android/Core/HoneywellScannerService.cs index c1bacbb..6a30c6a 100644 --- a/SteUp.Maui/Platforms/Android/Core/HoneywellScannerService.cs +++ b/SteUp.Maui/Platforms/Android/Core/HoneywellScannerService.cs @@ -123,6 +123,8 @@ public partial class HoneywellScannerService } catch (Exception ex) { + Console.WriteLine(ex.Message); + service.OnScanFailed?.Invoke(ex); } diff --git a/SteUp.Shared/Components/Layout/NavMenu.razor b/SteUp.Shared/Components/Layout/NavMenu.razor index b74706d..fd07947 100644 --- a/SteUp.Shared/Components/Layout/NavMenu.razor +++ b/SteUp.Shared/Components/Layout/NavMenu.razor @@ -1,5 +1,8 @@ @using CommunityToolkit.Mvvm.Messaging +@using SteUp.Shared.Core.Entities +@using SteUp.Shared.Core.Interface.IntegryApi @using SteUp.Shared.Core.Interface.System.Network +@using SteUp.Shared.Core.Messages.Ispezione @using SteUp.Shared.Core.Messages.Scheda @inject INetworkService NetworkService @inject IDialogService Dialog @@ -31,17 +34,24 @@ @if (PlusVisible) { - @if (SchedaVisible) { - + } + + } else { - } @@ -53,6 +63,7 @@ { private bool IsVisible { get; set; } = true; private bool PlusVisible { get; set; } = true; + private bool ShowCompleteInspection { get; set; } private bool SchedaVisible { get; set; } protected override Task OnInitializedAsync() @@ -81,6 +92,9 @@ _ = ModalHelper.OpenSelectShop(Dialog); } + private void CompleteInspection() => + Messenger.Send(new CompleteInspectionMessage()); + private async Task NewScheda() { var ispezione = SteupDataService.InspectionPageState.Ispezione; @@ -95,6 +109,7 @@ var location = NavigationManager.Uri.Remove(0, NavigationManager.BaseUri.Length); SchedaVisible = new List { "ispezione" }.Contains(location); + ShowCompleteInspection = !SteupDataService.InspectionPageState.Ispezione.ActivityId.IsNullOrEmpty(); StateHasChanged(); } } \ No newline at end of file diff --git a/SteUp.Shared/Components/Pages/IspezionePage.razor b/SteUp.Shared/Components/Pages/IspezionePage.razor index 4069e36..c8cc8f0 100644 --- a/SteUp.Shared/Components/Pages/IspezionePage.razor +++ b/SteUp.Shared/Components/Pages/IspezionePage.razor @@ -1,13 +1,19 @@ @page "/ispezione" @using SteUp.Shared.Components.Layout +@using SteUp.Shared.Components.Layout.Overlay @using SteUp.Shared.Components.SingleElements.Card @using SteUp.Shared.Core.Dto @using SteUp.Shared.Core.Entities +@using SteUp.Shared.Core.Enum +@using SteUp.Shared.Core.Interface.IntegryApi @using SteUp.Shared.Core.Interface.LocalDb +@using SteUp.Shared.Core.Messages.Ispezione @using SteUp.Shared.Core.Messages.Scheda @inject NewSchedaService NewScheda +@inject CompleteInspectionService CompleteInspection @inject IIspezioniService IspezioniService @inject IDialogService Dialog +@inject IIntegrySteupService IntegrySteupService @implements IDisposable @@ -30,9 +36,23 @@
- + @if (NetworkService.IsNetworkAvailable()) + { + + + + } + else + { + + }
@@ -51,13 +71,18 @@ } + + @code { private List SchedeList { get; set; } = []; private Dictionary> SchedeGrouped { get; set; } = []; + private bool VisibleOverlay { get; set; } + protected override void OnInitialized() { NewScheda.OnNewScheda += LoadSchede; + CompleteInspection.OnComplete += HandleCompleteInspection; LoadSchede(); } @@ -77,6 +102,48 @@ }); } + private async void HandleCompleteInspection() + { + try + { + await InvokeAsync(() => + { + VisibleOverlay = true; + StateHasChanged(); + }); + + var ispezione = SteupDataService.InspectionPageState.Ispezione; + + SteupDataService.InspectionPageState.Ispezione.Stato = StatusEnum.Completata; + + await IntegrySteupService.CompleteInspection(ispezione.ActivityId!); + await IspezioniService.UpdateStatoIspezioneAsync( + ispezione.CodMdep, + ispezione.Data, + ispezione.Rilevatore, + StatusEnum.Completata + ); + + await InvokeAsync(() => + { + VisibleOverlay = false; + StateHasChanged(); + }); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + + await InvokeAsync(() => + { + VisibleOverlay = false; + StateHasChanged(); + }); + + OnError(e.Message); + } + } + private void GroupSchede() { SchedeGrouped = SchedeList @@ -114,12 +181,76 @@ new Scheda { Reparto = jtbFasi } ); - if (modal is {Canceled: false}) LoadSchede(); + if (modal is { Canceled: false }) LoadSchede(); + } + + private async Task ExportReparto(JtbFasiDto jtbFasi) + { + VisibleOverlay = true; + StateHasChanged(); + + var ispezione = SteupDataService.InspectionPageState.Ispezione; + + var saveRequest = SchedeGrouped[jtbFasi].ConvertAll(x => + { + return new SaveRequestDto + { + LocalIdScheda = x.Id, + ActivityTypeId = x.ActivityTypeId, + CodJfas = x.CodJfas, + CodMdep = ispezione.CodMdep, + DataCreazione = ispezione.Data, + Note = x.Note, + PersonaRif = x.Responsabile, + Barcodes = x.Articoli.ConvertAll(y => y.Barcode), + Scandeza = (ScadenzaEnum)x.Scadenza, + ParentActivityId = x.Ispezione?.ActivityId + }; + }); + + var apiResponse = await IntegrySteupService.SaveMultipleSchede(saveRequest); + + if (apiResponse != null) + { + SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione; + + await IspezioniService.UpdateActivityIdIspezioneAsync(ispezione.CodMdep, ispezione.Data, + UserSession.User.Username, apiResponse.ActivityIdIspezione + ); + + if (apiResponse.ActivityIdSchedaList.IsNullOrEmpty()) return; + + foreach (var scheda in SchedeGrouped[jtbFasi]) + { + scheda.ActivityId = apiResponse.ActivityIdScheda; + await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId); + + var activityId = apiResponse.ActivityIdSchedaList!.Find(x => + x.LocalId != null && x.LocalId == scheda.Id + )?.ActivityId; + + if (activityId == null) return; + + scheda.ActivityId = activityId; + await IspezioniService.UpdateActivityIdSchedaAsync(scheda.Id, scheda.ActivityId); + } + } + + VisibleOverlay = false; + StateHasChanged(); + } + + private void OnError(string? errorMessage) + { + if (errorMessage == null) return; + + _ = ModalHelper.ShowError(Dialog, errorMessage); } void IDisposable.Dispose() { NewScheda.OnNewScheda -= LoadSchede; + CompleteInspection.OnComplete -= HandleCompleteInspection; } } \ No newline at end of file diff --git a/SteUp.Shared/Components/Pages/IspezionePage.razor.css b/SteUp.Shared/Components/Pages/IspezionePage.razor.css index 10d089d..16668eb 100644 --- a/SteUp.Shared/Components/Pages/IspezionePage.razor.css +++ b/SteUp.Shared/Components/Pages/IspezionePage.razor.css @@ -2,4 +2,10 @@ display: flex; flex-direction: column; gap: 1.5rem; +} + +.action-scheda-group { + display: flex; + align-items: center; + justify-content: space-around; } \ No newline at end of file diff --git a/SteUp.Shared/Components/Pages/LoginPage.razor b/SteUp.Shared/Components/Pages/LoginPage.razor index a5174f5..b20601f 100644 --- a/SteUp.Shared/Components/Pages/LoginPage.razor +++ b/SteUp.Shared/Components/Pages/LoginPage.razor @@ -100,6 +100,8 @@ else } catch (Exception e) { + Console.WriteLine(e.Message); + Spinner = false; StateHasChanged(); diff --git a/SteUp.Shared/Components/Pages/Utility/AuthorizingPage.razor b/SteUp.Shared/Components/Pages/Utility/AuthorizingPage.razor new file mode 100644 index 0000000..6b59879 --- /dev/null +++ b/SteUp.Shared/Components/Pages/Utility/AuthorizingPage.razor @@ -0,0 +1,2 @@ +@using SteUp.Shared.Components.Layout.Spinner + \ No newline at end of file diff --git a/SteUp.Shared/Components/Routes.razor b/SteUp.Shared/Components/Routes.razor index 91e187b..9ae8c35 100644 --- a/SteUp.Shared/Components/Routes.razor +++ b/SteUp.Shared/Components/Routes.razor @@ -1,3 +1,4 @@ +@using SteUp.Shared.Components.Pages.Utility @using SteUp.Shared.Components.SingleElements.Modal.ExceptionModal @using SteUp.Shared.Core.BarcodeReader.Contracts @inject NavigationManager NavigationManager @@ -8,21 +9,29 @@ - - -

Authorizing page

-
- - @if (context.User.Identity?.IsAuthenticated != true) - { - NavigationManager.NavigateTo("/login"); - } - else - { -

You are not authorized to access this resource.

- } -
-
+ @if (!LoadData) + { + + + + + + @if (context.User.Identity?.IsAuthenticated != true) + { + NavigationManager.NavigateTo("/login"); + } + else + { +

You are not authorized to access this resource.

+ } +
+
+ } + else + { + + } +
@@ -38,13 +47,21 @@ @code { + private bool LoadData { get; set; } private ErrorBoundary? ErrorBoundary { get; set; } private ExceptionModal ExceptionModal { get; set; } = null!; protected override async Task OnInitializedAsync() { + LoadData = true; + StateHasChanged(); + await SteupDataService.Init(); BarcodeManager.Init(); + + LoadData = false; + StateHasChanged(); } + } \ No newline at end of file diff --git a/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor index 4a6e6a1..0efb813 100644 --- a/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor +++ b/SteUp.Shared/Components/SingleElements/Card/SchedaCard.razor @@ -1,8 +1,12 @@ @using SteUp.Shared.Components.Layout.Overlay @using SteUp.Shared.Components.SingleElements.MessageBox +@using SteUp.Shared.Core.Dto @using SteUp.Shared.Core.Entities +@using SteUp.Shared.Core.Enum +@using SteUp.Shared.Core.Interface.IntegryApi @using SteUp.Shared.Core.Interface.LocalDb @inject IIspezioniService IspezioniService +@inject IIntegrySteupService IntegrySteupService @inject IDialogService Dialog
@@ -14,36 +18,48 @@
- 0 + @Scheda.ImageNames.Count() - 0 + @Scheda.Articoli.Count
- - Modifica - - - Cancella - + @if (NetworkService.IsNetworkAvailable()) + { + + + + } + else + { + + Modifica + + + Cancella + + }
+ @code{ [Parameter] public string CodMdep { get; set; } = string.Empty; - [Parameter] public DateOnly Data { get; set; } + [Parameter] public DateTime Data { get; set; } [Parameter] public required Scheda Scheda { get; set; } [Parameter] public EventCallback OnSchedaModified { get; set; } [Parameter] public EventCallback OnSchedaDeleted { get; set; } + private bool VisibleOverlay { get; set; } + private ConfirmDeleteMessageBox _deleteMessageBox = null!; private async Task UpdateScheda() @@ -63,4 +79,40 @@ } } + private async Task ExportScheda() + { + VisibleOverlay = true; + StateHasChanged(); + + var apiResponse = await IntegrySteupService.SaveScheda( + new SaveRequestDto + { + LocalIdScheda = Scheda.Id, + ActivityTypeId = Scheda.ActivityTypeId, + CodJfas = Scheda.CodJfas, + CodMdep = CodMdep, + DataCreazione = Data, + Note = Scheda.Note, + PersonaRif = Scheda.Responsabile, + Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode), + Scandeza = (ScadenzaEnum)Scheda.Scadenza, + ParentActivityId = Scheda.Ispezione?.ActivityId + } + ); + + if (apiResponse != null) + { + Scheda.ActivityId = apiResponse.ActivityIdScheda; + SteupDataService.InspectionPageState.Ispezione.ActivityId = apiResponse.ActivityIdIspezione; + + await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data, + UserSession.User.Username, apiResponse.ActivityIdIspezione + ); + await IspezioniService.UpdateActivityIdSchedaAsync(Scheda.Id, Scheda.ActivityId); + } + + VisibleOverlay = false; + StateHasChanged(); + } + } \ No newline at end of file diff --git a/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor b/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor index a956c8a..968fde7 100644 --- a/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor +++ b/SteUp.Shared/Components/SingleElements/Card/ShopCard.razor @@ -47,7 +47,7 @@ SteupDataService.InspectionPageState.Ispezione = await IspezioniService.GetOrCreateIspezioneAsync( PuntoVendita.CodMdep!, - DateOnly.FromDateTime(DateTime.Today), + DateTime.Now, UserSession.User.Username ); diff --git a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor index d0b7bdc..72d3643 100644 --- a/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor +++ b/SteUp.Shared/Components/SingleElements/Modal/ModalFormScheda.razor @@ -5,10 +5,10 @@ @using SteUp.Shared.Components.SingleElements.MessageBox @using SteUp.Shared.Core.Dto @using SteUp.Shared.Core.Entities +@using SteUp.Shared.Core.Enum @using SteUp.Shared.Core.Interface.IntegryApi @using SteUp.Shared.Core.Interface.LocalDb @using SteUp.Shared.Core.Interface.System -@using SteUp.Shared.Core.Interface.System.Network @using SteUp.Shared.Core.Messages.Scanner @inject INetworkService NetworkService @inject IDialogService Dialog @@ -27,7 +27,7 @@
- @@ -41,7 +41,7 @@ - @@ -75,10 +75,13 @@ } @item.p.Name - + @if (IsNew) + { + + } } @@ -87,19 +90,16 @@ } - @if (!IsView) - { -
- - Aggiungi foto - -
- } +
+ + Aggiungi foto + +
@@ -113,7 +113,8 @@
@foreach (var articolo in Scheda.Articoli) { - + @articolo.Descrizione @@ -143,23 +144,23 @@ } - - - - - + + + + - - @@ -187,7 +188,7 @@ @code { [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!; [Parameter] public required string CodMdep { get; set; } - [Parameter] public required DateOnly Data { get; set; } + [Parameter] public required DateTime Data { get; set; } [Parameter] public bool IsNew { get; set; } [Parameter] public Scheda Scheda { get; set; } = new(); @@ -214,7 +215,7 @@ protected override void OnInitialized() { Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter; - + OnScannerService.OnNewScanSuccessful += HandleNewScanSuccessful; OnScannerService.OnErrorScan += OnErrorScan; @@ -226,6 +227,8 @@ private void LoadAttached() { + if (Scheda.ImageNames == null) return; + FileLoading = true; StateHasChanged(); @@ -237,7 +240,8 @@ CodMdep = CodMdep, Data = Data, Rilevatore = UserSession.User.Username - } + }, + Scheda.ImageNames ); await InvokeAsync(() => @@ -254,9 +258,40 @@ { VisibleOverlay = true; StateHasChanged(); + + SaveSchedaResponseDto? apiResponse = null; + try + { + if (!IsView) + { + apiResponse = await IntegrySteupService.SaveScheda( + new SaveRequestDto + { + LocalIdScheda = Scheda.Id, + ActivityTypeId = Scheda.ActivityTypeId, + CodJfas = Scheda.CodJfas, + CodMdep = CodMdep, + DataCreazione = Data, + Note = Scheda.Note, + PersonaRif = Scheda.Responsabile, + Barcodes = Scheda.Articoli.ConvertAll(x => x.Barcode), + Scandeza = (ScadenzaEnum)Scheda.Scadenza, + ParentActivityId = IsNew ? null : Scheda.Ispezione?.ActivityId + } + ); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + + await ModalHelper.ShowError(Dialog, e.Message); + } - if (IsNew) await NewSave(); - else await Update(); + if (IsNew) await NewSave(apiResponse); + else await Update(apiResponse); + + if (Scheda.ActivityId.IsValorized()) await UploadFile(Scheda.ActivityId!); await AttachedService.CleanTempStorageAsync(); @@ -268,7 +303,7 @@ MudDialog.Close(Scheda); } - private async Task NewSave() + private async Task NewSave(SaveSchedaResponseDto? apiResponse) { if (!AttachedList.IsNullOrEmpty()) { @@ -291,10 +326,18 @@ } } + if (apiResponse != null) + { + await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data, + UserSession.User.Username, apiResponse.ActivityIdIspezione + ); + Scheda.ActivityId = apiResponse.ActivityIdScheda; + } + await IspezioniService.AddSchedaAsync(CodMdep, Data, UserSession.User.Username, Scheda); } - private async Task Update() + private async Task Update(SaveSchedaResponseDto? apiResponse) { if (!AttachedList.IsNullOrEmpty()) { @@ -324,7 +367,33 @@ } } + Scheda.ActivityId = apiResponse?.ActivityIdScheda; await IspezioniService.UpdateSchedaAsync(Scheda); + + if (apiResponse != null) + await IspezioniService.UpdateActivityIdIspezioneAsync(CodMdep, Data, + UserSession.User.Username, apiResponse.ActivityIdIspezione + ); + } + + private async Task UploadFile(string activityId) + { + if (AttachedList.IsNullOrEmpty()) return; + + var ispezione = new Ispezione + { + CodMdep = CodMdep, + Data = Data, + Rilevatore = UserSession.User.Username + }; + + foreach (var file in AttachedList!.Where(x => x.ToUpload)) + { + if (file.FileBytes == null || file.Name == null) continue; + + await IntegrySteupService.UploadFile(activityId, file.FileBytes, file.Name); + await AttachedService.MoveInspectionFileFromToUploadToFinal(ispezione, file.Name); + } } private async Task Cancel() @@ -436,6 +505,7 @@ var target = AttachedList![AttachedList.Count - attachedList.Count + i]; target.TempPath = origUrl; target.ThumbPath = thumbUrl; + target.ToUpload = true; StateHasChanged(); }); } @@ -456,7 +526,7 @@ Snackbar.Add("Selezionare prima il reparto", Severity.Error); return; } - + OnLoading = true; TextLoading = "Download articoli in griglia"; StateHasChanged(); @@ -477,25 +547,27 @@ } catch (Exception e) { + Console.WriteLine(e.Message); + await InvokeAsync(() => { OnLoading = false; TextLoading = null; StateHasChanged(); - + OnError(e.Message); }); - + return; } - + var modal = await ModalHelper.OpenSelectArt(Dialog, articoli); - + await InvokeAsync(() => { OnLoading = false; TextLoading = null; - + StateHasChanged(); }); @@ -581,17 +653,17 @@ { OnLoading = false; StateHasChanged(); - + if (art != null) { RecalcDirty(true); - + Scheda.Articoli.Add(new SchedaArticolo { Barcode = art.Barcode, Descrizione = art.Descrizione }); - + StateHasChanged(); } else @@ -602,12 +674,14 @@ } catch (Exception e) { + Console.WriteLine(e.Message); + await InvokeAsync(() => { OnLoading = false; StateHasChanged(); }); - + OnError(e.Message); } } @@ -627,7 +701,7 @@ { var index = Scheda.Articoli.FindIndex(x => x.Barcode.Equals(barcode)); if (index < 0) return; - + RecalcDirty(true); Scheda.Articoli.RemoveAt(index); StateHasChanged(); diff --git a/SteUp.Shared/Core/Data/SteupDataService.cs b/SteUp.Shared/Core/Data/SteupDataService.cs index 0e55d5a..ade3df5 100644 --- a/SteUp.Shared/Core/Data/SteupDataService.cs +++ b/SteUp.Shared/Core/Data/SteupDataService.cs @@ -1,12 +1,13 @@ using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account; using IntegryApiClient.Core.Domain.Abstraction.Contracts.Device; -using SteUp.Shared.Core.BarcodeReader.Contracts; using SteUp.Shared.Core.Data.Contracts; using SteUp.Shared.Core.Dto; using SteUp.Shared.Core.Dto.PageState; +using SteUp.Shared.Core.Helpers; using SteUp.Shared.Core.Interface.IntegryApi; using SteUp.Shared.Core.Interface.LocalDb; using SteUp.Shared.Core.Interface.System; +using SteUp.Shared.Core.Interface.System.Network; namespace SteUp.Shared.Core.Data; @@ -15,12 +16,14 @@ public class SteupDataService( IUserSession userSession, IDeviceService deviceService, IGenericSystemService genericSystemService, + IIspezioniService ispezioniService, IDbInitializer dbInitializer) : ISteupDataService { public async Task Init() { await dbInitializer.InitializeAsync(); await LoadDataAsync(); + await CheckAndUpdateStatus(); RegisterAppVersion(); } @@ -31,6 +34,48 @@ public class SteupDataService( ); } + private async Task CheckAndUpdateStatus() + { + var ispezioni = await ispezioniService.GetAllIspezioniWithSchedeAsync(); + var listActivityId = ispezioni + .Where(x => x.ActivityId != null) + .Select(x => x.ActivityId!) + .ToList(); + + if (!listActivityId.IsNullOrEmpty()) + { + var stati = await integrySteupService.RetrieveStatoIspezioni( + new RetrieveStatoIspezioniRequestDto + { + ActivityIdList = listActivityId + } + ); + + if (stati != null) + { + foreach (var stato in stati) + { + var ispezione = ispezioni.Find(x => + x.ActivityId != null && + x.ActivityId.EqualsIgnoreCase(stato.ActivityId) + ); + + var newStatus = StatusEnumHelper.ConvertToStatusEnum(stato.ActivityResultId); + + if (ispezione != null && ispezione.Stato != newStatus) + { + await ispezioniService.UpdateStatoIspezioneAsync( + ispezione.CodMdep, + ispezione.Data, + ispezione.Rilevatore, + newStatus + ); + } + } + } + } + } + private async Task LoadDataAsync() { if (!await userSession.IsLoggedIn()) return; diff --git a/SteUp.Shared/Core/Dto/AttachedDto.cs b/SteUp.Shared/Core/Dto/AttachedDto.cs index 61b908c..60a747b 100644 --- a/SteUp.Shared/Core/Dto/AttachedDto.cs +++ b/SteUp.Shared/Core/Dto/AttachedDto.cs @@ -16,6 +16,7 @@ public class AttachedDto public bool SavedOnAppData { get; set; } public bool ToRemove { get; set; } + public bool ToUpload { get; set; } public Stream? FileContent => FileBytes is null ? null : new MemoryStream(FileBytes); diff --git a/SteUp.Shared/Core/Dto/RetrieveStatoIspezioniRequestDto.cs b/SteUp.Shared/Core/Dto/RetrieveStatoIspezioniRequestDto.cs new file mode 100644 index 0000000..c6d70a5 --- /dev/null +++ b/SteUp.Shared/Core/Dto/RetrieveStatoIspezioniRequestDto.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace SteUp.Shared.Core.Dto; + +public class RetrieveStatoIspezioniRequestDto +{ + [JsonPropertyName("activityIdList")] + public required List ActivityIdList { get; set; } +} \ No newline at end of file diff --git a/SteUp.Shared/Core/Dto/SaveRequestDto.cs b/SteUp.Shared/Core/Dto/SaveRequestDto.cs new file mode 100644 index 0000000..7abc596 --- /dev/null +++ b/SteUp.Shared/Core/Dto/SaveRequestDto.cs @@ -0,0 +1,37 @@ +using System.Text.Json.Serialization; +using SteUp.Shared.Core.Enum; + +namespace SteUp.Shared.Core.Dto; + +public class SaveRequestDto +{ + [JsonPropertyName("localIdScheda")] + public int? LocalIdScheda { get; set; } + + [JsonPropertyName("codMdep")] + public string? CodMdep { get; set; } + + [JsonPropertyName("note")] + public string? Note { get; set; } + + [JsonPropertyName("parentActivityId")] + public string? ParentActivityId { get; set; } + + [JsonPropertyName("activityTypeId")] + public string? ActivityTypeId { get; set; } + + [JsonPropertyName("codJfas")] + public string? CodJfas { get; set; } + + [JsonPropertyName("personaRif")] + public string? PersonaRif { get; set; } + + [JsonPropertyName("scandeza")] + public ScadenzaEnum Scandeza { get; set; } + + [JsonPropertyName("dataCreazione")] + public DateTime? DataCreazione { get; set; } + + [JsonPropertyName("barcodes")] + public List? Barcodes { get; set; } +} \ No newline at end of file diff --git a/SteUp.Shared/Core/Dto/SaveSchedaResponseDto.cs b/SteUp.Shared/Core/Dto/SaveSchedaResponseDto.cs new file mode 100644 index 0000000..fea2816 --- /dev/null +++ b/SteUp.Shared/Core/Dto/SaveSchedaResponseDto.cs @@ -0,0 +1,24 @@ +using System.Text.Json.Serialization; + +namespace SteUp.Shared.Core.Dto; + +public class SaveSchedaResponseDto +{ + [JsonPropertyName("activityIdIspezione")] + public string? ActivityIdIspezione { get; set; } + + [JsonPropertyName("activityIdScheda")] + public string? ActivityIdScheda { get; set; } + + [JsonPropertyName("activityIdSchedaList")] + public List? ActivityIdSchedaList { get; set; } + + public class SchedaActivityId + { + [JsonPropertyName("localId")] + public int? LocalId { get; set; } + + [JsonPropertyName("activityId")] + public string? ActivityId { get; set; } + } +} \ No newline at end of file diff --git a/SteUp.Shared/Core/Dto/StbActivityDto.cs b/SteUp.Shared/Core/Dto/StbActivityDto.cs new file mode 100644 index 0000000..142b0ab --- /dev/null +++ b/SteUp.Shared/Core/Dto/StbActivityDto.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace SteUp.Shared.Core.Dto; + +public class StbActivityDto +{ + [JsonPropertyName("activityId")] + public string ActivityId { get; set; } = string.Empty; + + [JsonPropertyName("activityResultId")] + public string ActivityResultId { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/SteUp.Shared/Core/Entities/Ispezione.cs b/SteUp.Shared/Core/Entities/Ispezione.cs index 283065b..82f6e1c 100644 --- a/SteUp.Shared/Core/Entities/Ispezione.cs +++ b/SteUp.Shared/Core/Entities/Ispezione.cs @@ -7,10 +7,12 @@ public class Ispezione : EntityBase { [Required] public string CodMdep { get; set; } = string.Empty; - public DateOnly Data { get; set; } + public DateTime Data { get; set; } [Required] public string Rilevatore { get; set; } = string.Empty; + public string? ActivityId { get; set; } + public StatusEnum Stato { get; set; } = StatusEnum.InCorso; public List Schede { get; set; } = []; diff --git a/SteUp.Shared/Core/Entities/Scheda.cs b/SteUp.Shared/Core/Entities/Scheda.cs index 75d34a5..2aba30a 100644 --- a/SteUp.Shared/Core/Entities/Scheda.cs +++ b/SteUp.Shared/Core/Entities/Scheda.cs @@ -8,11 +8,12 @@ public class Scheda : EntityBase { [Key] public int Id { get; set; } + public string? ActivityId { get; set; } public string? CodJfas { get; set; } [Required] public string CodMdep { get; set; } = string.Empty; - public DateOnly Data { get; set; } + public DateTime Data { get; set; } [Required] public string Rilevatore { get; set; } = string.Empty; public Ispezione? Ispezione { get; set; } @@ -24,7 +25,7 @@ public class Scheda : EntityBase public string? ActivityTypeId { get; set; } public string? Note { get; set; } public string? Responsabile { get; set; } - public int Scadenza { get; set; } = 1460; + public int Scadenza { get; set; } [NotMapped] public JtbFasiDto? Reparto diff --git a/SteUp.Shared/Core/Enum/ScadenzaEnum.cs b/SteUp.Shared/Core/Enum/ScadenzaEnum.cs new file mode 100644 index 0000000..2c27025 --- /dev/null +++ b/SteUp.Shared/Core/Enum/ScadenzaEnum.cs @@ -0,0 +1,9 @@ +namespace SteUp.Shared.Core.Enum; + +public enum ScadenzaEnum +{ + Bassa2Mesi = 0, + Media1Mese = 1, + Alta1Settimana = 2, + Altissima24Ore = 3 +} \ No newline at end of file diff --git a/SteUp.Shared/Core/Enum/StatusEnum.cs b/SteUp.Shared/Core/Enum/StatusEnum.cs index 9c76cfe..6d0eaa5 100644 --- a/SteUp.Shared/Core/Enum/StatusEnum.cs +++ b/SteUp.Shared/Core/Enum/StatusEnum.cs @@ -4,5 +4,6 @@ public enum StatusEnum { InCorso = 0, Completata = 1, - Esporta = 2 + Verifica = 2, + Annullata = 3 } \ No newline at end of file diff --git a/SteUp.Shared/Core/Helpers/ModalHelper.cs b/SteUp.Shared/Core/Helpers/ModalHelper.cs index b3f8de5..9dc0afe 100644 --- a/SteUp.Shared/Core/Helpers/ModalHelper.cs +++ b/SteUp.Shared/Core/Helpers/ModalHelper.cs @@ -25,7 +25,7 @@ public abstract class ModalHelper return await modal.Result; } - public static async Task OpenFormScheda(IDialogService dialog, string codMdep, DateOnly data, + public static async Task OpenFormScheda(IDialogService dialog, string codMdep, DateTime data, bool isNew = false, Scheda? scheda = null) { scheda = isNew && scheda == null ? new Scheda() : scheda; diff --git a/SteUp.Shared/Core/Helpers/ObjectExtensions.cs b/SteUp.Shared/Core/Helpers/ObjectExtensions.cs index 7054358..ab3c514 100644 --- a/SteUp.Shared/Core/Helpers/ObjectExtensions.cs +++ b/SteUp.Shared/Core/Helpers/ObjectExtensions.cs @@ -10,9 +10,13 @@ public static class ObjectExtensions public static bool IsNullOrEmpty(this string? obj) => string.IsNullOrEmpty(obj); + public static bool IsValorized(this string? obj) => !obj.IsNullOrEmpty(); + public static bool EqualsIgnoreCase(this string obj, string other) => string.Equals(obj, other, StringComparison.InvariantCultureIgnoreCase); public static bool ContainsIgnoreCase(this string obj, string other) => obj.Contains(other, StringComparison.InvariantCultureIgnoreCase); + + public static int Count(this List? obj) => obj?.Count ?? 0; } \ No newline at end of file diff --git a/SteUp.Shared/Core/Helpers/StatusEnumHelper.cs b/SteUp.Shared/Core/Helpers/StatusEnumHelper.cs index e674a7c..997a99a 100644 --- a/SteUp.Shared/Core/Helpers/StatusEnumHelper.cs +++ b/SteUp.Shared/Core/Helpers/StatusEnumHelper.cs @@ -11,18 +11,30 @@ public static class StatusEnumHelper { StatusEnum.InCorso => "IN CORSO", StatusEnum.Completata => "COMPLETATA", - StatusEnum.Esporta => "ESPORTATA", + StatusEnum.Verifica => "VERIFICA", + StatusEnum.Annullata => "ANNULLATA", _ => throw new ArgumentOutOfRangeException(nameof(enumValue), enumValue, null) }; } + public static StatusEnum ConvertToStatusEnum(string stringValue) + { + return stringValue switch + { + "COMPLETATA" => StatusEnum.Completata, + "ANNULLATA" => StatusEnum.Annullata, + "VERIFICA" => StatusEnum.Verifica, + _ => StatusEnum.InCorso + }; + } + public static Color GetColor(this StatusEnum enumValue) { return enumValue switch { - StatusEnum.InCorso => Color.Warning, - StatusEnum.Completata or - StatusEnum.Esporta => Color.Success, + StatusEnum.InCorso or StatusEnum.Verifica => Color.Warning, + StatusEnum.Completata => Color.Success, + StatusEnum.Annullata => Color.Error, _ => Color.Default }; } diff --git a/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs b/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs index 429343f..f4fe3be 100644 --- a/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs +++ b/SteUp.Shared/Core/Interface/IntegryApi/IIntegrySteupService.cs @@ -10,4 +10,11 @@ public interface IIntegrySteupService Task> RetrieveActivityType(); Task?> RetrieveGrigliaPlu(RetrieveGrigliaPluRequestDto request); Task RetrieveArtFromBarcode(string barcode); + Task?> RetrieveStatoIspezioni(RetrieveStatoIspezioniRequestDto request); + + //Save + Task SaveScheda(SaveRequestDto request); + Task SaveMultipleSchede(List request); + Task CompleteInspection(string activityId); + Task UploadFile(string activityId, byte[] file, string fileName); } \ No newline at end of file diff --git a/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs b/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs index acfab30..9fa10d8 100644 --- a/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs +++ b/SteUp.Shared/Core/Interface/LocalDb/IIspezioniService.cs @@ -1,23 +1,27 @@ using SteUp.Shared.Core.Entities; +using SteUp.Shared.Core.Enum; namespace SteUp.Shared.Core.Interface.LocalDb; public interface IIspezioniService { // ISPEZIONI - Task GetIspezioneAsync(string codMdep, DateOnly data, string rilevatore); + Task GetIspezioneAsync(string codMdep, DateTime data, string rilevatore); Task> GetAllIspezioniWithSchedeAsync(); Task AddIspezioneAsync(Ispezione ispezione); - Task GetOrCreateIspezioneAsync(string codMdep, DateOnly data, string rilevatore); + Task GetOrCreateIspezioneAsync(string codMdep, DateTime data, string rilevatore); Task UpdateIspezioneAsync(Ispezione ispezione); - Task DeleteIspezioneAsync(string codMdep, DateOnly data, string rilevatore); + Task UpdateStatoIspezioneAsync(string codMdep, DateTime data, string rilevatore, StatusEnum stato); + Task UpdateActivityIdIspezioneAsync(string codMdep, DateTime data, string rilevatore, string? activityId); + Task DeleteIspezioneAsync(string codMdep, DateTime data, string rilevatore); // SCHEDE - Task AddSchedaAsync(string codMdep, DateOnly data, string rilevatore, Scheda scheda); - Task> GetAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore); + Task AddSchedaAsync(string codMdep, DateTime data, string rilevatore, Scheda scheda); + Task> GetAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore); Task GetSchedaAsync(int schedaId); Task GetSchedaWithIspezioneAsync(int schedaId); Task UpdateSchedaAsync(Scheda scheda); + Task UpdateActivityIdSchedaAsync(int schedaId, string? activityId); Task DeleteSchedaAsync(int schedaId); - Task DeleteAllSchedeOfIspezioneAsync(string codMdep, DateOnly data, string rilevatore); + Task DeleteAllSchedeOfIspezioneAsync(string codMdep, DateTime data, string rilevatore); } \ No newline at end of file diff --git a/SteUp.Shared/Core/Interface/System/IAttachedService.cs b/SteUp.Shared/Core/Interface/System/IAttachedService.cs index 09e32d2..67e11db 100644 --- a/SteUp.Shared/Core/Interface/System/IAttachedService.cs +++ b/SteUp.Shared/Core/Interface/System/IAttachedService.cs @@ -8,13 +8,21 @@ public interface IAttachedService Task SelectImageFromCamera(); Task?> SelectImageFromGallery(); - Task?> GetInspectionFiles(Ispezione ispezione); + Task?> GetInspectionFiles(Ispezione ispezione, List fileNameFilter, + bool includeToUpload = true, CancellationToken ct = default); + Task SaveInspectionFile(Ispezione ispezione, byte[] file, string fileName, CancellationToken ct = default); - bool RemoveInspectionFile(Ispezione ispezione, string fileName); - + + bool RemoveInspectionFile(Ispezione ispezione, string fileName, bool removeAlsoFromFinal = true, + bool removeAlsoFromToUpload = true); + + Task MoveInspectionFileFromToUploadToFinal(Ispezione ispezione, string fileName, bool overwrite = true, + CancellationToken ct = default); + Task SaveToTempStorage(Stream file, string fileName, CancellationToken ct = default); Task CleanTempStorageAsync(CancellationToken ct = default); Task OpenFile(string fileName, string filePath); - Task<(string originalUrl, string thumbUrl)> SaveAndCreateThumbAsync(byte[] bytes, string fileName, CancellationToken ct = default); + Task<(string originalUrl, string thumbUrl)> SaveAndCreateThumbAsync(byte[] bytes, string fileName, + CancellationToken ct = default); } \ No newline at end of file diff --git a/SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionMessage.cs b/SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionMessage.cs new file mode 100644 index 0000000..252c97d --- /dev/null +++ b/SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionMessage.cs @@ -0,0 +1,5 @@ +using CommunityToolkit.Mvvm.Messaging.Messages; + +namespace SteUp.Shared.Core.Messages.Ispezione; + +public class CompleteInspectionMessage(object? value = null) : ValueChangedMessage(value); \ No newline at end of file diff --git a/SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionService.cs b/SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionService.cs new file mode 100644 index 0000000..d1a7b86 --- /dev/null +++ b/SteUp.Shared/Core/Messages/Ispezione/CompleteInspectionService.cs @@ -0,0 +1,13 @@ +using CommunityToolkit.Mvvm.Messaging; + +namespace SteUp.Shared.Core.Messages.Ispezione; + +public class CompleteInspectionService +{ + public event Action? OnComplete; + + public CompleteInspectionService(IMessenger messenger) + { + messenger.Register(this, (_, _) => { OnComplete?.Invoke(); }); + } +} \ No newline at end of file diff --git a/SteUp.Shared/Core/Services/IntegryApiService.cs b/SteUp.Shared/Core/Services/IntegryApiService.cs index 2285a68..73d8220 100644 --- a/SteUp.Shared/Core/Services/IntegryApiService.cs +++ b/SteUp.Shared/Core/Services/IntegryApiService.cs @@ -19,6 +19,7 @@ public class IntegryApiService( } catch (Exception e) { + Console.WriteLine(e.Message); return false; } } diff --git a/SteUp.Shared/Core/Services/IntegrySteupService.cs b/SteUp.Shared/Core/Services/IntegrySteupService.cs index efa8f93..579f02f 100644 --- a/SteUp.Shared/Core/Services/IntegrySteupService.cs +++ b/SteUp.Shared/Core/Services/IntegrySteupService.cs @@ -1,4 +1,5 @@ -using IntegryApiClient.Core.Domain.RestClient.Contacts; +using System.Net.Http.Headers; +using IntegryApiClient.Core.Domain.RestClient.Contacts; using SteUp.Shared.Core.Dto; using SteUp.Shared.Core.Interface.IntegryApi; @@ -31,5 +32,39 @@ public class IntegrySteupService(IIntegryApiRestClient integryApiRestClient) : I } ); + public Task?> RetrieveStatoIspezioni(RetrieveStatoIspezioniRequestDto request) => + integryApiRestClient.AuthorizedPost?>($"{BaseRequest}/retrieveStatoIspezioni", request); + #endregion + + #region Save + + public Task SaveScheda(SaveRequestDto request) => + integryApiRestClient.AuthorizedPost($"{BaseRequest}/saveScheda", request); + + public Task SaveMultipleSchede(List request) => + integryApiRestClient.AuthorizedPost($"{BaseRequest}/saveMultipleSchede", request); + + public Task CompleteInspection(string activityId) => + integryApiRestClient.AuthorizedPost( + $"{BaseRequest}/complete", + new Dictionary + { + { "activityId", activityId } + } + ); + + #endregion + + public Task UploadFile(string activityId, byte[] file, string fileName) + { + var queryParams = new Dictionary { { "activityId", activityId } }; + + using var content = new MultipartFormDataContent(); + var fileContent = new ByteArrayContent(file); + fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data"); + content.Add(fileContent, "file", fileName); + + return integryApiRestClient.Post($"{BaseRequest}/uploadAttachment", content, queryParams!); + } } \ No newline at end of file diff --git a/SteUp.Shared/_Imports.razor b/SteUp.Shared/_Imports.razor index e90f727..fae6c4f 100644 --- a/SteUp.Shared/_Imports.razor +++ b/SteUp.Shared/_Imports.razor @@ -14,10 +14,12 @@ @using MudExtensions @using SteUp.Shared.Core.Data.Contracts @using SteUp.Shared.Core.Helpers +@using SteUp.Shared.Core.Interface.System.Network @using static InteractiveRenderSettings @inject NavigationManager NavigationManager @inject IUserSession UserSession @inject ILocalStorage LocalStorage @inject ISnackbar Snackbar -@inject ISteupDataService SteupDataService \ No newline at end of file +@inject ISteupDataService SteupDataService +@inject INetworkService NetworkService \ No newline at end of file