diff --git a/src/Backend/Inspections.API/Features/Checklists/CheckListsController.cs b/src/Backend/Inspections.API/Features/Checklists/CheckListsController.cs index 0bfbde5f..dc728182 100644 --- a/src/Backend/Inspections.API/Features/Checklists/CheckListsController.cs +++ b/src/Backend/Inspections.API/Features/Checklists/CheckListsController.cs @@ -158,7 +158,7 @@ public async Task DeleteCheckList(int id) [ProducesDefaultResponseType] public async Task DeleteCheckListItem(int id, int idItem) { - if (await _mediator.Send(new DeleteCheckListItem(id, idItem)).ConfigureAwait(false)) + if (await _mediator.Send(new DeleteCheckListItemCommand(id, idItem)).ConfigureAwait(false)) return Ok(); return BadRequest(); @@ -207,9 +207,9 @@ public async Task GetCheckListById(int id) [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesDefaultResponseType] - public IActionResult GetCheckList(string filter) + public IActionResult GetCheckList(string filter, int? reportConfigurationId, int? reportId, bool? inConfigurationOnly = null) { - var checkList = _checkListsQueries.GetByFilter(filter); + var checkList = _checkListsQueries.GetByFilter(filter, inConfigurationOnly, reportConfigurationId, reportId); if (checkList is null) return NotFound(); diff --git a/src/Backend/Inspections.API/Features/Checklists/Commands/DeleteCheckListItem.cs b/src/Backend/Inspections.API/Features/Checklists/Commands/DeleteCheckListItemCommand.cs similarity index 73% rename from src/Backend/Inspections.API/Features/Checklists/Commands/DeleteCheckListItem.cs rename to src/Backend/Inspections.API/Features/Checklists/Commands/DeleteCheckListItemCommand.cs index f7713d5f..6e74cbf9 100644 --- a/src/Backend/Inspections.API/Features/Checklists/Commands/DeleteCheckListItem.cs +++ b/src/Backend/Inspections.API/Features/Checklists/Commands/DeleteCheckListItemCommand.cs @@ -6,11 +6,11 @@ namespace Inspections.API.Features.Checklists.Commands { - public class DeleteCheckListItem : IRequest + public class DeleteCheckListItemCommand : IRequest { public int IdCheckList { get; set; } public int IdCheckListItem { get; set; } - public DeleteCheckListItem(int idCheckList, int idCheckListItem) + public DeleteCheckListItemCommand(int idCheckList, int idCheckListItem) { IdCheckList = idCheckList; IdCheckListItem = idCheckListItem; diff --git a/src/Backend/Inspections.API/Features/Checklists/Handlers/AddCheckListCommandHandler.cs b/src/Backend/Inspections.API/Features/Checklists/Handlers/AddCheckListCommandHandler.cs index e160b59c..795b57fc 100644 --- a/src/Backend/Inspections.API/Features/Checklists/Handlers/AddCheckListCommandHandler.cs +++ b/src/Backend/Inspections.API/Features/Checklists/Handlers/AddCheckListCommandHandler.cs @@ -29,7 +29,6 @@ public async Task Handle(AddCheckListCommand request, CancellationToken ca CheckListMappingHelper.MapParams(request.TextParams), request.Annotation, false); - checkList.AddCheckItems(CheckListMappingHelper.MapItems(request.Items)); var result = await _checkListsRepository.AddAsync(checkList).ConfigureAwait(false); diff --git a/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListCommandHandler.cs b/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListCommandHandler.cs new file mode 100644 index 00000000..b5c1cff8 --- /dev/null +++ b/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListCommandHandler.cs @@ -0,0 +1,29 @@ +using Ardalis.GuardClauses; +using Inspections.API.Features.Checklists.Commands; +using Inspections.API.Features.Checklists.Mapping; +using Inspections.Core.Domain.CheckListAggregate; +using Inspections.Core.Interfaces; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Inspections.API.Features.Checklists.Handlers +{ + public class DeleteCheckListCommandHandler : IRequestHandler + { + private readonly ICheckListsRepository _checkListsRepository; + + public DeleteCheckListCommandHandler(ICheckListsRepository checkListsRepository) + { + _checkListsRepository = checkListsRepository ?? throw new ArgumentNullException(nameof(checkListsRepository)); + } + + public async Task Handle(DeleteCheckListCommand request, CancellationToken cancellationToken) + { + return true; + } + } +} diff --git a/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListItemCommandHandler.cs b/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListItemCommandHandler.cs new file mode 100644 index 00000000..d185934e --- /dev/null +++ b/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListItemCommandHandler.cs @@ -0,0 +1,38 @@ +using Inspections.API.Features.Checklists.Commands; +using Inspections.API.Features.Checklists.Mapping; +using Inspections.API.Features.Checklists.Models; +using Inspections.Core.Domain.CheckListAggregate; +using Inspections.Core.Interfaces; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Inspections.API.Features.Checklists.Handlers +{ + public class DeleteCheckListItemCommandHandler : IRequestHandler + { + private readonly ICheckListsRepository _checkListsRepository; + + public DeleteCheckListItemCommandHandler(ICheckListsRepository checkListsRepository) + { + _checkListsRepository = checkListsRepository ?? throw new ArgumentNullException(nameof(checkListsRepository)); + } + + public async Task Handle(DeleteCheckListItemCommand request, CancellationToken cancellationToken) + { + var item = await _checkListsRepository.GetItemByIdAsync(request!.IdCheckListItem).ConfigureAwait(false); + if (item is null) + return false; + + var checklist = await _checkListsRepository.GetByIdAsync(request.IdCheckList).ConfigureAwait(false); + checklist.RemoveCheckItems(item); + await _checkListsRepository.UpdateAsync(checklist).ConfigureAwait(false); + + return true; + } + + } +} diff --git a/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListParamCommandHandler.cs b/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListParamCommandHandler.cs new file mode 100644 index 00000000..6a383719 --- /dev/null +++ b/src/Backend/Inspections.API/Features/Checklists/Handlers/DeleteCheckListParamCommandHandler.cs @@ -0,0 +1,29 @@ +using Ardalis.GuardClauses; +using Inspections.API.Features.Checklists.Commands; +using Inspections.Core.Domain.CheckListAggregate; +using Inspections.Core.Interfaces; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Inspections.API.Features.Checklists.Handlers +{ + public class DeleteCheckListParamCommandHandler : IRequestHandler + { + private readonly ICheckListsRepository _checkListsRepository; + + public DeleteCheckListParamCommandHandler(ICheckListsRepository checkListsRepository) + { + _checkListsRepository = checkListsRepository ?? throw new ArgumentNullException(nameof(checkListsRepository)); + } + + public async Task Handle(DeleteCheckListParamCommand request, CancellationToken cancellationToken) + { + Guard.Against.Null(request, nameof(request)); + + return true; + } + } +} diff --git a/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListCommandHandler.cs b/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListCommandHandler.cs new file mode 100644 index 00000000..e2f8ca2f --- /dev/null +++ b/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListCommandHandler.cs @@ -0,0 +1,35 @@ +using Ardalis.GuardClauses; +using Inspections.API.Features.Checklists.Commands; +using Inspections.API.Features.Checklists.Mapping; +using Inspections.Core.Domain.CheckListAggregate; +using Inspections.Core.Interfaces; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Inspections.API.Features.Checklists.Handlers +{ + public class UpdateCheckListCommandHandler : IRequestHandler + { + private readonly ICheckListsRepository _checkListsRepository; + + public UpdateCheckListCommandHandler(ICheckListsRepository checkListsRepository) + { + _checkListsRepository = checkListsRepository ?? throw new ArgumentNullException(nameof(checkListsRepository)); + } + + public async Task Handle(UpdateCheckListCommand request, CancellationToken cancellationToken) + { + Guard.Against.Null(request, nameof(request)); + + var checkList = await _checkListsRepository.GetByIdAsync(request.IdCheckList).ConfigureAwait(false); + checkList.Edit(request.Text, request.Annotation); + await _checkListsRepository.UpdateAsync(checkList).ConfigureAwait(false); + + return true; + } + } +} diff --git a/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListItemCommandHandler.cs b/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListItemCommandHandler.cs new file mode 100644 index 00000000..367a2043 --- /dev/null +++ b/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListItemCommandHandler.cs @@ -0,0 +1,42 @@ +using Inspections.API.Features.Checklists.Commands; +using Inspections.API.Features.Checklists.Mapping; +using Inspections.API.Features.Checklists.Models; +using Inspections.Core.Domain.CheckListAggregate; +using Inspections.Core.Interfaces; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Inspections.API.Features.Checklists.Handlers +{ + public class UpdateCheckListItemCommandHandler : IRequestHandler + { + private readonly ICheckListsRepository _checkListsRepository; + + public UpdateCheckListItemCommandHandler(ICheckListsRepository checkListsRepository) + { + _checkListsRepository = checkListsRepository ?? throw new ArgumentNullException(nameof(checkListsRepository)); + } + + public async Task Handle(UpdateCheckListItemCommand request, CancellationToken cancellationToken) + { + var checkList = await _checkListsRepository.GetByIdAsync(request.CheckListId).ConfigureAwait(false); + var item = await _checkListsRepository.GetItemByIdAsync(request.Id).ConfigureAwait(false); + + checkList.RemoveCheckItems(item); + item.Checked = request.Checked; + item.Remarks = request.Remarks; + item.Required = request.Required; + item.Text = request.Text; + checkList.AddCheckItems(item); + + await _checkListsRepository.UpdateAsync(checkList).ConfigureAwait(false); + + return true; + } + + } +} diff --git a/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListParamCommandHandler.cs b/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListParamCommandHandler.cs new file mode 100644 index 00000000..611ea5a7 --- /dev/null +++ b/src/Backend/Inspections.API/Features/Checklists/Handlers/UpdateCheckListParamCommandHandler.cs @@ -0,0 +1,27 @@ +using Ardalis.GuardClauses; +using Inspections.API.Features.Checklists.Commands; +using Inspections.Core.Domain.CheckListAggregate; +using Inspections.Core.Interfaces; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Inspections.API.Features.Checklists.Handlers +{ + public class UpdateCheckListParamCommandHandler : IRequestHandler + { + private readonly ICheckListsRepository _checkListsRepository; + + public UpdateCheckListParamCommandHandler(ICheckListsRepository checkListsRepository) + { + _checkListsRepository = checkListsRepository ?? throw new ArgumentNullException(nameof(checkListsRepository)); + } + + public async Task Handle(UpdateCheckListParamCommand request, CancellationToken cancellationToken) + { + return true; + } + } +} diff --git a/src/Backend/Inspections.API/Features/Reports/Commands/DeleteReportCommand.cs b/src/Backend/Inspections.API/Features/Reports/Commands/DeleteReportCommand.cs deleted file mode 100644 index 2cfd32b3..00000000 --- a/src/Backend/Inspections.API/Features/Reports/Commands/DeleteReportCommand.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using MediatR; - -namespace Inspections.API.Features.Inspections.Commands -{ - public class DeleteReportCommand : IRequest - { - public DeleteReportCommand() - { - } - } -} diff --git a/src/Backend/Inspections.API/Features/Reports/Handlers/CreateInspectionHandler.cs b/src/Backend/Inspections.API/Features/Reports/Handlers/CreateInspectionHandler.cs index 887a750e..aaf90b1d 100644 --- a/src/Backend/Inspections.API/Features/Reports/Handlers/CreateInspectionHandler.cs +++ b/src/Backend/Inspections.API/Features/Reports/Handlers/CreateInspectionHandler.cs @@ -22,8 +22,7 @@ public CreateInspectionHandler(IReportsRepository reportsRepository, IReportConf public async Task Handle(CreateReportCommand request, CancellationToken cancellationToken) { - // must be one configuratio per type - var cfg = await _reportConfigurationsRepository.GetByIdAsync(1).ConfigureAwait(false); + var cfg = await _reportConfigurationsRepository.GetByIdAsync(request.ConfigurationId).ConfigureAwait(false); IReportsBuilder _reportsBuilder = new ReportsBuilder(cfg); var newReport = _reportsBuilder diff --git a/src/Backend/Inspections.API/Features/Reports/Handlers/DeleteReportCommandHandler.cs b/src/Backend/Inspections.API/Features/Reports/Handlers/DeleteReportCommandHandler.cs new file mode 100644 index 00000000..0b9d1832 --- /dev/null +++ b/src/Backend/Inspections.API/Features/Reports/Handlers/DeleteReportCommandHandler.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Inspections.API.Features.Inspections.Commands; +using Inspections.Core.Interfaces; +using MediatR; + +namespace Inspections.API.Features.Reports.Handlers +{ + public class DeleteReportCommandHandler : IRequestHandler + { + private readonly IReportsRepository _reportsRepository; + + public DeleteReportCommandHandler(IReportsRepository reportsRepository, ISignaturesRepository signaturesRepository, ICheckListsRepository checkListsRepository) + { + this._reportsRepository = reportsRepository ?? throw new ArgumentNullException(nameof(reportsRepository)); + } + public async Task Handle(DeleteReportCommand request, CancellationToken cancellationToken) + { + var report = await _reportsRepository.GetByIdAsync(request.Id).ConfigureAwait(false); + + if (!report.IsClosed) + { + await _reportsRepository.DeleteAsync(report).ConfigureAwait(false); + return true; + } + + return false; + + } + } +} diff --git a/src/Backend/Inspections.API/Features/Reports/ReportsController.cs b/src/Backend/Inspections.API/Features/Reports/ReportsController.cs index eaec7e62..f1413325 100644 --- a/src/Backend/Inspections.API/Features/Reports/ReportsController.cs +++ b/src/Backend/Inspections.API/Features/Reports/ReportsController.cs @@ -39,11 +39,31 @@ public async Task Post([FromBody] CreateReportCommand createData) [HttpGet] public async Task GetAll(string filter) { - var result = await _reportsRepository.GetAll(filter); + var result = await _reportsRepository.GetAll(filter).ConfigureAwait(false); if (result is null) return NoContent(); return Ok(result); } + + [HttpGet("{id:int}")] + public async Task GetReport(int id) + { + var result = await _reportsRepository.GetByIdAsync(id).ConfigureAwait(false); + if (result is null) + return NoContent(); + + return Ok(result); + } + + [HttpDelete("{id:int}")] + public async Task DeleteReport(int id) + { + var result = await _mediator.Send(new DeleteReportCommand(id)).ConfigureAwait(false); + if (!result) + return BadRequest(); + + return NoContent(); + } } } diff --git a/src/Backend/Inspections.API/Features/Signatures/Commands/AddSignatureCommand.cs b/src/Backend/Inspections.API/Features/Signatures/Commands/AddSignatureCommand.cs index be4b5de9..5b53fd0e 100644 --- a/src/Backend/Inspections.API/Features/Signatures/Commands/AddSignatureCommand.cs +++ b/src/Backend/Inspections.API/Features/Signatures/Commands/AddSignatureCommand.cs @@ -16,7 +16,9 @@ public AddSignatureCommand(string title, string designation, string remarks, DateTimeOffset date, - bool principal) + bool principal, + int reportId, + int reportConfigurationId) { Title = title; Annotation = annotation; @@ -26,6 +28,8 @@ public AddSignatureCommand(string title, Remarks = remarks; Date = date; Principal = principal; + ReportId = reportId; + ReportConfigurationId = reportConfigurationId; } private AddSignatureCommand() { } @@ -38,5 +42,8 @@ private AddSignatureCommand() { } public string Remarks { get; set; } public DateTimeOffset Date { get; set; } public bool Principal { get; set; } + public bool IsConfiguration { get; set; } + public int? ReportId{ get; set; } + public int? ReportConfigurationId { get; set; } } } diff --git a/src/Backend/Inspections.API/Features/Signatures/Handlers/AddSignatureCommandHandler.cs b/src/Backend/Inspections.API/Features/Signatures/Handlers/AddSignatureCommandHandler.cs index 13a71c8e..cf9057c1 100644 --- a/src/Backend/Inspections.API/Features/Signatures/Handlers/AddSignatureCommandHandler.cs +++ b/src/Backend/Inspections.API/Features/Signatures/Handlers/AddSignatureCommandHandler.cs @@ -30,7 +30,9 @@ public async Task Handle(AddSignatureCommand request, CancellationToken ca Date = request.Date, Principal = request.Principal, Responsable = new Responsable() { Name= request.ResponsableName, Type= request.ResponsableType }, - IsConfiguration = false + IsConfiguration = request.ReportConfigurationId>0, + ReportConfigurationId = request.ReportConfigurationId == 0 ? default:request.ReportConfigurationId, + ReportId = request.ReportId == 0 ? default : request.ReportId }; var result = await _signaturesRepository.AddAsync(newSignature).ConfigureAwait(false); diff --git a/src/Backend/Inspections.API/Features/Signatures/Models/SignatureDTO.cs b/src/Backend/Inspections.API/Features/Signatures/Models/SignatureDTO.cs index 3b098db5..21597fac 100644 --- a/src/Backend/Inspections.API/Features/Signatures/Models/SignatureDTO.cs +++ b/src/Backend/Inspections.API/Features/Signatures/Models/SignatureDTO.cs @@ -18,6 +18,8 @@ public class SignatureDTO public string Remarks { get; set; } public DateTimeOffset Date { get; set; } public bool Principal { get; set; } + public int? ReportId { get; set; } + public int? ReportConfigurationId { get; set; } public SignatureDTO(Signature signature) { @@ -35,6 +37,8 @@ public SignatureDTO(Signature signature) ResponsableType = signature.Responsable.Type; ResponsableName = signature.Responsable.Name; } + ReportConfigurationId = signature.ReportConfigurationId; + ReportId = signature.ReportId; } } } diff --git a/src/Backend/Inspections.API/Features/Signatures/SignaturesController.cs b/src/Backend/Inspections.API/Features/Signatures/SignaturesController.cs index 99167533..5c2b7b55 100644 --- a/src/Backend/Inspections.API/Features/Signatures/SignaturesController.cs +++ b/src/Backend/Inspections.API/Features/Signatures/SignaturesController.cs @@ -36,7 +36,7 @@ public SignaturesController(IMediator mediator [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesDefaultResponseType] - public async Task CreateSignature([FromBody] AddSignatureCommand signature) + public async Task CreateSignature([FromBody]AddSignatureCommand signature) { if (await _mediator.Send(signature).ConfigureAwait(false)) return Ok(); @@ -90,14 +90,14 @@ public async Task GetSignatureById(int id) [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesDefaultResponseType] - public async Task>> GetSignatures(string filter) + public async Task>> GetSignatures(string filter, int? reportConfigurationId, int? reportId, bool? inConfigurationOnly = null) { - var signatures = await _signaturesQueries.GetAllAsync(filter).ConfigureAwait(false); + var signatures = await _signaturesQueries.GetAllAsync(filter, inConfigurationOnly, reportConfigurationId, reportId).ConfigureAwait(false); if (signatures is null) return NoContent(); - return Ok(signatures.Select(x=>new SignatureDTO(x))); + return Ok(signatures.Select(x => new SignatureDTO(x))); } } } diff --git a/src/Backend/Inspections.API/Inspections.API.csproj b/src/Backend/Inspections.API/Inspections.API.csproj index e19db5c0..b9ea423e 100644 --- a/src/Backend/Inspections.API/Inspections.API.csproj +++ b/src/Backend/Inspections.API/Inspections.API.csproj @@ -16,6 +16,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -23,6 +24,7 @@ + diff --git a/src/Backend/Inspections.API/Startup.cs b/src/Backend/Inspections.API/Startup.cs index 72ebdfb4..2a890b61 100644 --- a/src/Backend/Inspections.API/Startup.cs +++ b/src/Backend/Inspections.API/Startup.cs @@ -31,6 +31,7 @@ using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; using ZadERP.Api.Middleware; +//using Microsoft.AspNetCore.Mvc.NewtonsoftJson namespace Inspections.API { @@ -47,7 +48,7 @@ public void ConfigureServices(IServiceCollection services) { services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly); - services.AddControllers(); + services.AddControllers().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); services.AddCors(); services.AddAuthentication(options => { @@ -182,7 +183,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { builder.WithOrigins("*").AllowAnyHeader().AllowAnyMethod(); }); - + app.UseAuthentication(); app.UseAuthorization(); diff --git a/src/Backend/Inspections.Core/Domain/CheckListAggregate/CheckList.cs b/src/Backend/Inspections.Core/Domain/CheckListAggregate/CheckList.cs index e3d0637c..6cd8c555 100644 --- a/src/Backend/Inspections.Core/Domain/CheckListAggregate/CheckList.cs +++ b/src/Backend/Inspections.Core/Domain/CheckListAggregate/CheckList.cs @@ -28,13 +28,21 @@ public CheckList(string text, List textParams, string annotation TextParams = textParams; Annotation = annotation; IsConfiguration = isConfiguration; + ReportId = null; } private CheckList() { } //Required by EF public IReadOnlyList Checks => _checks.AsReadOnly(); - public bool Completed => Checks.Any(c => c.Checked == CheckValue.False || c.Checked == CheckValue.NA); + public bool Completed => !Checks.Any(c => c.Required && (c.Checked != CheckValue.False || c.Checked != CheckValue.NA)); + public void Edit(string text, string annotation) + { + ValidateCanEdit(); + + Text = text; + Annotation = annotation; + } public void AddCheckItems(CheckListItem checkListItem) { @@ -46,7 +54,7 @@ public void AddCheckItems(CheckListItem checkListItem) private void ValidateCanEdit() { - if (Completed && !IsConfiguration) + if (Completed && Id > 0 && !IsConfiguration) throw new InvalidOperationException($"add items to {nameof(Completed)} {nameof(CheckList)} isn't allowed"); } @@ -58,6 +66,14 @@ public void AddCheckItems(IEnumerable checkListItem) _checks.AddRange(checkListItem); } + public void RemoveCheckItems(CheckListItem checkListItem) + { + Guard.Against.Null(checkListItem, nameof(checkListItem)); + ValidateCanEdit(); + + _checks.Remove(checkListItem); + } + public void AddCheckListParams(CheckListParam checkListParam) { Guard.Against.Null(checkListParam, nameof(checkListParam)); @@ -74,13 +90,20 @@ public void AddCheckListParams(IEnumerable checkListParams) TextParams.AddRange(checkListParams); } - public CheckList PreparteForNewReport() + public CheckList CloneForReport() { - var newCheckList = this.MemberwiseClone() as CheckList; - newCheckList.Id = 0; - newCheckList.ReportId = 0; - newCheckList.ReportConfigurationId = null; - newCheckList.IsConfiguration = false; + var newCheckList = new CheckList(this.Text, null, this.Annotation, false); + newCheckList.ReportConfigurationId = this.ReportConfigurationId; + + foreach (var check in Checks) + { + var parameters = new List(); + foreach (var param in check.TextParams) + { + parameters.Add(new CheckListParam(null, 0, param.Key, param.Value, param.Type)); + } + newCheckList.AddCheckItems(new CheckListItem(0, check.Text, check.Checked, check.Required, check.Remarks, parameters)); + } return newCheckList; } } diff --git a/src/Backend/Inspections.Core/Domain/ReportsAggregate/Report.cs b/src/Backend/Inspections.Core/Domain/ReportsAggregate/Report.cs index ce6aba09..f91ef9f7 100644 --- a/src/Backend/Inspections.Core/Domain/ReportsAggregate/Report.cs +++ b/src/Backend/Inspections.Core/Domain/ReportsAggregate/Report.cs @@ -115,7 +115,7 @@ internal void AddCheckList(IEnumerable checkList) CheckIfClosed(); foreach (var check in checkList) { - this.checkList.Add(check.PreparteForNewReport()); + this.checkList.Add(check.CloneForReport()); } } diff --git a/src/Backend/Inspections.Core/Interfaces/Queries/ICheckListsQueries.cs b/src/Backend/Inspections.Core/Interfaces/Queries/ICheckListsQueries.cs index d2b4856c..5e4d086c 100644 --- a/src/Backend/Inspections.Core/Interfaces/Queries/ICheckListsQueries.cs +++ b/src/Backend/Inspections.Core/Interfaces/Queries/ICheckListsQueries.cs @@ -8,6 +8,6 @@ namespace Inspections.Core.Interfaces.Queries { public interface ICheckListsQueries { - IEnumerable GetByFilter(string filter); + IEnumerable GetByFilter(string filter, bool? inConfigurationOnly, int? reportConfigurationId, int? reportId); } } diff --git a/src/Backend/Inspections.Core/Interfaces/Queries/ISignaturesQueries.cs b/src/Backend/Inspections.Core/Interfaces/Queries/ISignaturesQueries.cs index 8f83b4f5..010d5c65 100644 --- a/src/Backend/Inspections.Core/Interfaces/Queries/ISignaturesQueries.cs +++ b/src/Backend/Inspections.Core/Interfaces/Queries/ISignaturesQueries.cs @@ -6,6 +6,6 @@ namespace Inspections.Core.Interfaces.Queries { public interface ISignaturesQueries { - Task> GetAllAsync(string filter); + Task> GetAllAsync(string filter, bool? inConfigurationOnly, int? reportConfigurationId, int? reportId); } -} \ No newline at end of file +} diff --git a/src/Backend/Inspections.Infrastructure/Data/InspectionsContext.cs b/src/Backend/Inspections.Infrastructure/Data/InspectionsContext.cs index 2cbec74c..cad957fa 100644 --- a/src/Backend/Inspections.Infrastructure/Data/InspectionsContext.cs +++ b/src/Backend/Inspections.Infrastructure/Data/InspectionsContext.cs @@ -1,4 +1,4 @@ -using Inspections.Core; +using Inspections.Core; using Inspections.Core.Domain; using Inspections.Core.Domain.CheckListAggregate; using Inspections.Core.Domain.ReportConfigurationAggregate; @@ -39,7 +39,7 @@ public InspectionsContext(DbContextOptions options, IMediator mediator, IUserNam } - public DbSet Inspections { get; set; } + public DbSet Reports { get; set; } public DbSet CheckLists { get; set; } public DbSet CheckListItems { get; set; } public DbSet CheckListParams { get; set; } diff --git a/src/Backend/Inspections.Infrastructure/Data/InspectionsSeed.cs b/src/Backend/Inspections.Infrastructure/Data/InspectionsSeed.cs index f7345c81..e22ac5f0 100644 --- a/src/Backend/Inspections.Infrastructure/Data/InspectionsSeed.cs +++ b/src/Backend/Inspections.Infrastructure/Data/InspectionsSeed.cs @@ -21,10 +21,6 @@ public static async Task SeedAsync(InspectionsContext context, ILoggerFactory lo if (!context.Database.IsInMemory()) context.Database.Migrate(); - // TODO OJOOOOO: remove when ready for production - //context.Database.EnsureDeleted(); //this was killing my azure invoice xD - context.Database.Migrate(); - var log = logger.CreateLogger(); int retries = retriesNumber.Value; try @@ -135,7 +131,78 @@ private static IEnumerable AddCheckLists(InspectionsContext context) CheckValue.False, true, string.Empty, null)); item3.AddCheckItems(new CheckListItem(0, "Danger sign", CheckValue.False, true, string.Empty, null)); - return new CheckList[] { item1, item2, item3 }; + + var item4 = new CheckList( + "SWITCHBOARD REQUIREMENTS", + null, + "", + true + ); + item4.AddCheckItems(new CheckListItem(0, "Earth bar c/w proper labeling", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Earth pits condition", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Earth pits (R = {0} Ω tested on {1)", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Earth electrode inspection chamber", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Warning notice", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Equipotential bonding of metallic trunking, metal conduits & water / gas pipe.", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Protection of fingers to direct live parts (at least IP2X)", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Incoming & outgoing lights, voltmeter & Ammeter", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Proper Neutral links sizing", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Appropriate circuit breakers size & type", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Sufficient support & mechanical protection for cables", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Labelling of circuits", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Sign of Corrosion", + CheckValue.False, true, string.Empty, null)); + item4.AddCheckItems(new CheckListItem(0, "Servicing of Switchboard (Last Done: {0})", + CheckValue.False, true, string.Empty, null)); + + + var item5 = new CheckList( + "OPERATIONAL REQUIREMENTS", + null, + "", + true + ); + item5.AddCheckItems(new CheckListItem(0, "Incoming load L1: {0}A L2:{1}A L3:{2}A", + CheckValue.False, true, string.Empty, null)); + item5.AddCheckItems(new CheckListItem(0, "Voltage L1-N:{0}V L2-N:{1}V L3-N:{2}V L-L:{3}V", + CheckValue.False, true, string.Empty, null)); + item5.AddCheckItems(new CheckListItem(0, "Earth loop impedance (* power disruption) L-E:{0}Ω", + CheckValue.False, true, string.Empty, null)); + item5.AddCheckItems(new CheckListItem(0, "Main Breakers’ relay settings Itrip:{0}A t:{1}s", + CheckValue.False, true, string.Empty, null)); + item5.AddCheckItems(new CheckListItem(0, "Function test of RCD (* power disruption)", + CheckValue.False, true, string.Empty, null)); + + var item6 = new CheckList( + "OUTGOING DB / CIRCUITS", + null, + "", + true + ); + item6.AddCheckItems(new CheckListItem(0, "Appropriate rated fittings/fixtures (i.e. outdoor IP rating, fire rated, explosion proof etc) ", + CheckValue.False, true, string.Empty, null)); + item6.AddCheckItems(new CheckListItem(0, "30mA RCCBs in sensitive areas or public areas", + CheckValue.False, true, string.Empty, null)); + item6.AddCheckItems(new CheckListItem(0, "Standby Generator", + CheckValue.False, true, string.Empty, null)); + item6.AddCheckItems(new CheckListItem(0, "PV system / electric charger system", + CheckValue.False, true, string.Empty, null)); + item6.AddCheckItems(new CheckListItem(0, "No unused wires/cables or illegal wiring", + CheckValue.False, true, string.Empty, null)); + + return new CheckList[] { item1, item2, item3, item4, item5, item6 }; } } } diff --git a/src/Backend/Inspections.Infrastructure/Inspections.Infrastructure.csproj b/src/Backend/Inspections.Infrastructure/Inspections.Infrastructure.csproj index 560d02f5..fbb933ff 100644 --- a/src/Backend/Inspections.Infrastructure/Inspections.Infrastructure.csproj +++ b/src/Backend/Inspections.Infrastructure/Inspections.Infrastructure.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Backend/Inspections.Infrastructure/Queries/CheckListsQueries.cs b/src/Backend/Inspections.Infrastructure/Queries/CheckListsQueries.cs index 569c0503..74eb4909 100644 --- a/src/Backend/Inspections.Infrastructure/Queries/CheckListsQueries.cs +++ b/src/Backend/Inspections.Infrastructure/Queries/CheckListsQueries.cs @@ -20,8 +20,11 @@ public CheckListsQueries(InspectionsContext context) _context = context ?? throw new ArgumentNullException(nameof(context)); } - public IEnumerable GetByFilter(string filter) + public IEnumerable GetByFilter(string filter, bool? inConfigurationOnly, int? reportConfigurationId, int? reportId) { + if (inConfigurationOnly == false) + inConfigurationOnly = null; + return _context.ResumenCheckLists.FromSqlRaw(@" SELECT Id, Text, @@ -32,21 +35,24 @@ public IEnumerable GetByFilter(string filter) LastEditUser FROM Inspections.CheckLists cl LEFT JOIN ( - SELECT CheckListId, COUNT([Key]) AS TotalParams + SELECT CheckListId, COUNT([Key]) AS TotalParams FROM Inspections.CheckListParams GROUP BY CheckListId - ) Params + ) Params ON cl.Id = Params.CheckListId LEFT JOIN ( - SELECT CheckListId, COUNT(Id) AS TotalItems + SELECT CheckListId, COUNT(Id) AS TotalItems FROM Inspections.CheckListItems GROUP BY CheckListId - ) Items + ) Items ON cl.Id = Items.CheckListId WHERE 1=1 AND ([Text] LIKE {0} - OR Annotation LIKE {0}) - ", $"%{filter ?? string.Empty}%"); + OR Annotation LIKE {0}) + AND (cl.ReportId = {1} OR {1} IS NULL) + AND (cl.IsConfiguration = {2} OR {2} IS NULL) + AND (cl.ReportConfigurationId = {3} OR {3} IS NULL) + ", $"%{filter ?? string.Empty}%", reportId, inConfigurationOnly, reportConfigurationId); } } } diff --git a/src/Backend/Inspections.Infrastructure/Queries/ReportConfigsQueries.cs b/src/Backend/Inspections.Infrastructure/Queries/ReportConfigsQueries.cs index 779f151d..0e5a869c 100644 --- a/src/Backend/Inspections.Infrastructure/Queries/ReportConfigsQueries.cs +++ b/src/Backend/Inspections.Infrastructure/Queries/ReportConfigsQueries.cs @@ -30,7 +30,7 @@ SELECT [Id] , [RemarksLabelText] , ISNULL(DefinedCheckLists.CheckLists,0) as DefinedCheckLists , ISNULL(DefinedSignatures.Signatures,0) as DefinedSignatures - , 0 as UsedByReports + , Reports as UsedByReports , LastEdit , LastEditUser FROM Inspections.ReportsConfiguration Config @@ -46,13 +46,12 @@ FROM Inspections.Signatures GROUP BY ReportConfigurationId ) AS DefinedSignatures ON DefinedSignatures.ReportConfigurationId = Config.Id - -- COMMENTED UNTIL Reports back is ready - -- LEFT OUTER JOIN ( - -- SELECT ReportConfigurationId, COUNT(ReportConfigurationId) AS CheckLists - -- FROM Inspections.Reports - -- GROUP BY ReportConfigurationId - -- ) AS Reports - -- ON Reports.ReportConfigurationId = Config.Id + LEFT OUTER JOIN ( + SELECT ReportConfigurationId, COUNT(DISTINCT ReportId) AS Reports + FROM Inspections.CheckLists + GROUP BY ReportConfigurationId + ) AS Reports + ON Reports.ReportConfigurationId = Config.Id WHERE 1=1 ").Where(p=> EF.Functions.Like(p.Title, $"%{filter ?? string.Empty}%") || EF.Functions.Like(p.FormName, $"%{filter ?? string.Empty}%")); } diff --git a/src/Backend/Inspections.Infrastructure/Queries/SignaturesQueries.cs b/src/Backend/Inspections.Infrastructure/Queries/SignaturesQueries.cs index 237d86f0..0403af06 100644 --- a/src/Backend/Inspections.Infrastructure/Queries/SignaturesQueries.cs +++ b/src/Backend/Inspections.Infrastructure/Queries/SignaturesQueries.cs @@ -19,9 +19,17 @@ public SignaturesQueries(InspectionsContext context) _context = context ?? throw new ArgumentNullException(nameof(context)); } - public Task> GetAllAsync(string filter) + public Task> GetAllAsync(string filter, bool? inConfigurationOnly, int? reportConfigurationId, int? reportId) { - return Task.FromResult(_context.Set().Where(s => EF.Functions.Like(s.Title, $"%{filter}%")).AsEnumerable()); + if (inConfigurationOnly == false) + inConfigurationOnly = null; + + return Task.FromResult(_context.Set() + .Where(s => EF.Functions.Like(s.Title, $"%{filter}%") + && (s.IsConfiguration == inConfigurationOnly || inConfigurationOnly == null) + && (s.ReportConfigurationId == reportConfigurationId || reportConfigurationId == null) + && (s.ReportId == reportId || reportId == null)) + .AsEnumerable()); } } } diff --git a/src/Backend/Inspections.Infrastructure/Repositories/CheckListsRepository.cs b/src/Backend/Inspections.Infrastructure/Repositories/CheckListsRepository.cs index d953c01a..aa13e629 100644 --- a/src/Backend/Inspections.Infrastructure/Repositories/CheckListsRepository.cs +++ b/src/Backend/Inspections.Infrastructure/Repositories/CheckListsRepository.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; +using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; @@ -38,7 +39,11 @@ public async Task DeleteAsync(CheckList entity) public async Task GetByIdAsync(int id) { - return await _context.Set().FindAsync(id); + return await _context.Set() + .Include("Checks") + .Include("Checks.TextParams") + .Include("TextParams") + .Where(c=>c.Id == id).SingleOrDefaultAsync(); } public async Task GetItemByIdAsync(int id) diff --git a/src/Backend/Inspections.Infrastructure/Repositories/ReportsConfigurationsRepository.cs b/src/Backend/Inspections.Infrastructure/Repositories/ReportsConfigurationsRepository.cs index 1f548ae2..882a7db2 100644 --- a/src/Backend/Inspections.Infrastructure/Repositories/ReportsConfigurationsRepository.cs +++ b/src/Backend/Inspections.Infrastructure/Repositories/ReportsConfigurationsRepository.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Z.EntityFramework.Plus; namespace Inspections.Infrastructure.Repositories { @@ -39,7 +40,28 @@ public async Task DeleteAsync(ReportConfiguration entity) public async Task GetByIdAsync(int id) { - return await _context.ReportConfigurations.Where(s=>s.Id==id).Include("ChecksDefinition").Include("SignatureDefinitions").SingleOrDefaultAsync(); + var result = await _context.ReportConfigurations + .Where(s => s.Id == id) + .IncludeOptimized(p => p.SignatureDefinitions.Where(s => s.IsConfiguration && s.ReportId == null && s.ReportConfigurationId == id)) + .IncludeOptimized(p => p.ChecksDefinition.Where(cd => cd.IsConfiguration && cd.ReportId == null && cd.ReportConfigurationId == id)) + .IncludeOptimized(p => p.ChecksDefinition.Where(cd => cd.IsConfiguration && cd.ReportId == null && cd.ReportConfigurationId == id) + .Select(sm => sm.Checks.Where(c => c.Text.Length > 0))) + .IncludeOptimized(p => p.ChecksDefinition.Where(cd => cd.IsConfiguration && cd.ReportId == null && cd.ReportConfigurationId == id) + .Select(sm => sm.TextParams.Where(c => c.Key.Length > 0))) + .SingleOrDefaultAsync(); + + //EF limitations make me do it this way + foreach (var check in result.ChecksDefinition) + { + foreach (var checkItem in check.Checks) + { + var checksParams = _context.CheckListParams.Where(clp => clp.CheckListItemId == checkItem.Id).AsEnumerable(); + checkItem.TextParams.AddRange(checksParams); + } + } + + + return result; } public async Task UpdateAsync(ReportConfiguration entity) diff --git a/src/Backend/Inspections.Infrastructure/Repositories/ReportsRepository.cs b/src/Backend/Inspections.Infrastructure/Repositories/ReportsRepository.cs index 1ed21fd3..23d2c522 100644 --- a/src/Backend/Inspections.Infrastructure/Repositories/ReportsRepository.cs +++ b/src/Backend/Inspections.Infrastructure/Repositories/ReportsRepository.cs @@ -24,8 +24,6 @@ public ReportsRepository(InspectionsContext context, ILogger public async Task AddAsync(Report entity) { - - await _context.AddAsync(entity); await _context.SaveChangesAsync(); @@ -35,17 +33,33 @@ public async Task AddAsync(Report entity) public async Task> GetAll(string filter) { // TODO: Change - return await _context.Inspections.ToListAsync(); + return await _context.Reports + .Include(p => p.CheckList) + .Include(p=>p.Signatures) + .Include(p=>p.Notes) + .Include(p => p.PhotoRecords) + .ToListAsync(); } public Task DeleteAsync(Report entity) { - throw new NotImplementedException(); + _context.CheckLists.RemoveRange(entity.CheckList); + _context.Signatures.RemoveRange(entity.Signatures); + _context.Reports.Remove(entity); + _context.SaveChangesAsync(); + + return Task.CompletedTask; } - public Task GetByIdAsync(int id) + public async Task GetByIdAsync(int id) { - throw new NotImplementedException(); + return await _context.Reports.Where(r=>r.Id == id) + .Include(p => p.CheckList) + .ThenInclude(p=>p.Checks) + .Include(p => p.Signatures) + .Include(p => p.Notes) + .Include(p => p.PhotoRecords) + .SingleOrDefaultAsync(); } public Task UpdateAsync(Report entity) diff --git a/src/Backend/Inspections.Shared/Entity.cs b/src/Backend/Inspections.Shared/Entity.cs index c29d66e5..8d7f7de9 100644 --- a/src/Backend/Inspections.Shared/Entity.cs +++ b/src/Backend/Inspections.Shared/Entity.cs @@ -20,7 +20,7 @@ public virtual T Id { return _Id; } - protected set + set { _Id = value; } @@ -91,4 +91,4 @@ public override int GetHashCode() } } -} \ No newline at end of file +} diff --git a/src/Backend/docker-compose.yml b/src/Backend/docker-compose.yml index 7d5bc75b..75d938a0 100644 --- a/src/Backend/docker-compose.yml +++ b/src/Backend/docker-compose.yml @@ -17,6 +17,7 @@ services: - sql.data ports: - "8088:80" + - "44388:443" image: ${DOCKER_REGISTRY-}inspectionsapi build: context: . diff --git a/src/ClientApp/.eslintrc.js b/src/ClientApp/.eslintrc.js index e8cfcef6..958a6e51 100644 --- a/src/ClientApp/.eslintrc.js +++ b/src/ClientApp/.eslintrc.js @@ -8,6 +8,9 @@ module.exports = { '@nuxtjs/eslint-config-typescript', 'plugin:nuxt/recommended' ], + excludes:[ + "**/node_modules/**" + ], // add your custom rules here rules: { } diff --git a/src/ClientApp/components/AlertDialog.vue b/src/ClientApp/components/AlertDialog.vue index ca9871eb..ef0232a0 100644 --- a/src/ClientApp/components/AlertDialog.vue +++ b/src/ClientApp/components/AlertDialog.vue @@ -2,19 +2,17 @@ - + mdi-arrow-left {{ title }} - diff --git a/src/ClientApp/components/DatePickerBase.vue b/src/ClientApp/components/DatePickerBase.vue new file mode 100644 index 00000000..1629c177 --- /dev/null +++ b/src/ClientApp/components/DatePickerBase.vue @@ -0,0 +1,88 @@ + + + + + diff --git a/src/ClientApp/components/DateRangeBase.vue b/src/ClientApp/components/DateRangeBase.vue new file mode 100644 index 00000000..e504d781 --- /dev/null +++ b/src/ClientApp/components/DateRangeBase.vue @@ -0,0 +1,52 @@ + + + + + diff --git a/src/ClientApp/components/FileUploader.vue b/src/ClientApp/components/FileUploader.vue new file mode 100644 index 00000000..5400376b --- /dev/null +++ b/src/ClientApp/components/FileUploader.vue @@ -0,0 +1,75 @@ + + + + + diff --git a/src/ClientApp/components/MessageDialog.vue b/src/ClientApp/components/MessageDialog.vue index cdf19334..7be77c4b 100644 --- a/src/ClientApp/components/MessageDialog.vue +++ b/src/ClientApp/components/MessageDialog.vue @@ -2,11 +2,12 @@ - + mdi-arrow-left diff --git a/src/ClientApp/components/dashboard/ReportStatus.vue b/src/ClientApp/components/dashboard/ReportStatus.vue new file mode 100644 index 00000000..342b15a0 --- /dev/null +++ b/src/ClientApp/components/dashboard/ReportStatus.vue @@ -0,0 +1,49 @@ + diff --git a/src/ClientApp/components/dashboard/ReportsByInspector.vue b/src/ClientApp/components/dashboard/ReportsByInspector.vue new file mode 100644 index 00000000..f3690d9b --- /dev/null +++ b/src/ClientApp/components/dashboard/ReportsByInspector.vue @@ -0,0 +1,49 @@ + diff --git a/src/ClientApp/layouts/default.vue b/src/ClientApp/layouts/default.vue index 264dadc2..1f28e85d 100644 --- a/src/ClientApp/layouts/default.vue +++ b/src/ClientApp/layouts/default.vue @@ -11,7 +11,7 @@ - + @@ -21,7 +21,17 @@ - + + + + mdi-home + + + Home + + + + mdi-file-chart @@ -31,7 +41,7 @@ - + mdi-format-list-checks @@ -41,7 +51,7 @@ - + mdi-draw @@ -51,7 +61,7 @@ - + mdi-cog-outline @@ -72,6 +82,7 @@ Inspections + mdi-logout diff --git a/src/ClientApp/layouts/guest.vue b/src/ClientApp/layouts/guest.vue index bbccf904..fcc1458c 100644 --- a/src/ClientApp/layouts/guest.vue +++ b/src/ClientApp/layouts/guest.vue @@ -1,7 +1,5 @@ - - diff --git a/src/ClientApp/pages/CheckLists/_id/index.vue b/src/ClientApp/pages/CheckLists/_id/index.vue new file mode 100644 index 00000000..8b5358e1 --- /dev/null +++ b/src/ClientApp/pages/CheckLists/_id/index.vue @@ -0,0 +1,308 @@ + + \ No newline at end of file diff --git a/src/ClientApp/pages/CheckLists/index.vue b/src/ClientApp/pages/CheckLists/index.vue new file mode 100644 index 00000000..8d47fd73 --- /dev/null +++ b/src/ClientApp/pages/CheckLists/index.vue @@ -0,0 +1,210 @@ + + + + + diff --git a/src/ClientApp/pages/CheckListsParams.vue b/src/ClientApp/pages/CheckListsParams.vue deleted file mode 100644 index 1a2a7d56..00000000 --- a/src/ClientApp/pages/CheckListsParams.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/ClientApp/pages/Configurations/_id/index.vue b/src/ClientApp/pages/Configurations/_id/index.vue new file mode 100644 index 00000000..a8ae96ab --- /dev/null +++ b/src/ClientApp/pages/Configurations/_id/index.vue @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/src/ClientApp/pages/ReportsConfiguration.vue b/src/ClientApp/pages/Configurations/index.vue similarity index 100% rename from src/ClientApp/pages/ReportsConfiguration.vue rename to src/ClientApp/pages/Configurations/index.vue diff --git a/src/ClientApp/pages/Login.vue b/src/ClientApp/pages/Login.vue index 892f34f5..87417550 100644 --- a/src/ClientApp/pages/Login.vue +++ b/src/ClientApp/pages/Login.vue @@ -1,57 +1,75 @@ @@ -65,9 +83,18 @@ import { Vue, Component } from 'nuxt-property-decorator' export default class LoginPage extends Vue { userName: string = '' password: string = '' + loading: Boolean = false + hasError: Boolean = false async login () { - await this.$auth.loginWith('local', { data: { userName: this.userName, password: this.password } }) + this.loading = true; + await this.$auth.login({ data: { userName: this.userName, password: this.password } }) + .catch(() => { + this.hasError = true + + setTimeout(() => { this.hasError = false }, 3000) + }) + .finally(() => { this.loading = false }) } } diff --git a/src/ClientApp/pages/Reports/_id/index.vue b/src/ClientApp/pages/Reports/_id/index.vue new file mode 100644 index 00000000..fd9bfa65 --- /dev/null +++ b/src/ClientApp/pages/Reports/_id/index.vue @@ -0,0 +1,319 @@ + + + \ No newline at end of file diff --git a/src/ClientApp/pages/Reports.vue b/src/ClientApp/pages/Reports/index.vue similarity index 63% rename from src/ClientApp/pages/Reports.vue rename to src/ClientApp/pages/Reports/index.vue index 947a1b29..ba64ad68 100644 --- a/src/ClientApp/pages/Reports.vue +++ b/src/ClientApp/pages/Reports/index.vue @@ -6,40 +6,52 @@ message="This operation will remove this report and all data related" :code="selectedItem.id" :description="selectedItem.name" + @yes="deleteReport();" /> - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -99,20 +120,19 @@ import moment from 'moment' import { Vue, Component } from 'nuxt-property-decorator' import { ReportConfigurationState } from 'store/configurations' import { ReportsState } from 'store/reportstrore' - -import AlertDialog from '@/components/AlertDialog.vue' -import MessageDialog from '@/components/MessageDialog.vue' -import GridFilter from '@/components/GridFilter.vue' +import { ValidationObserver, ValidationProvider } from 'vee-validate' import { Report, CreateReport, ReportConfiguration } from '~/types' @Component({ components: { - AlertDialog, - MessageDialog, - GridFilter + ValidationObserver, + ValidationProvider } }) export default class ReportsPage extends Vue { + $refs!: { + obs: InstanceType + } dialog: Boolean = false dialogRemove: Boolean = false selectedItem: Report = {} as Report @@ -161,6 +181,13 @@ export default class ReportsPage extends Vue { align: 'center', class: 'secundary' }, + { + text: 'Signatures', + value: 'signatures', + sortable: true, + align: 'center', + class: 'secundary' + }, { text: 'Photos', value: 'photoRecords', @@ -213,13 +240,26 @@ export default class ReportsPage extends Vue { return moment(date).format('YYYY-MM-DD HH:mm') } - createReport () { + // only if i've more time then expected + get idValid () { + return this.$refs.obs.flags.valid + } + + async createReport () { + if(await this.$refs.obs.validate() === true) this.$store.dispatch('reportstrore/createReport', this.newReport, { root: true }) .then(() => { this.$store.dispatch('reportstrore/getReports', '', { root: true }) this.dialog = false }) } + + deleteReport () { + this.$store.dispatch('reportstrore/deleteReport', this.selectedItem.id, { root: true }) + .then(() => { + this.dialog = false + }) + } } diff --git a/src/ClientApp/pages/Signatures.vue b/src/ClientApp/pages/Signatures.vue deleted file mode 100644 index 74dda9f3..00000000 --- a/src/ClientApp/pages/Signatures.vue +++ /dev/null @@ -1,119 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/ClientApp/pages/Signatures/index.vue b/src/ClientApp/pages/Signatures/index.vue new file mode 100644 index 00000000..bb3787e6 --- /dev/null +++ b/src/ClientApp/pages/Signatures/index.vue @@ -0,0 +1,270 @@ + + + + + \ No newline at end of file diff --git a/src/ClientApp/pages/index.vue b/src/ClientApp/pages/index.vue index f9625e45..40dc0160 100644 --- a/src/ClientApp/pages/index.vue +++ b/src/ClientApp/pages/index.vue @@ -1,69 +1,31 @@ - diff --git a/src/ClientApp/plugins/vee-validate.ts b/src/ClientApp/plugins/vee-validate.ts new file mode 100644 index 00000000..39bec4e3 --- /dev/null +++ b/src/ClientApp/plugins/vee-validate.ts @@ -0,0 +1,28 @@ +import { extend } from 'vee-validate' +import { required, email } from 'vee-validate/dist/rules' + +extend('required', { + ...required, + message: 'Required Field' +}) + +extend('email', { + ...email, + message: 'Invalid Email' +}) + +extend('precedesDate', { + validate: (dateTo, { dateFrom }: any) => { + return dateTo >= dateFrom + }, + message: 'Invalid Dates Range', + params: [{ name: 'dateFrom', isTarget: true }] +}) + +extend('password', { + params: [{ name: 'other', isTarget: true }], + validate: (value, { other }: any) => { + return value === other + }, + message: 'Passwords do not match.' +}) diff --git a/src/ClientApp/static/LoginBackground.jpg b/src/ClientApp/static/LoginBackground.jpg new file mode 100644 index 00000000..6b61c928 Binary files /dev/null and b/src/ClientApp/static/LoginBackground.jpg differ diff --git a/src/ClientApp/static/Logo.jpeg b/src/ClientApp/static/Logo.jpeg new file mode 100644 index 00000000..992101fd Binary files /dev/null and b/src/ClientApp/static/Logo.jpeg differ diff --git a/src/ClientApp/store/checklists.ts b/src/ClientApp/store/checklists.ts index 8270d276..96af13d6 100644 --- a/src/ClientApp/store/checklists.ts +++ b/src/ClientApp/store/checklists.ts @@ -1,20 +1,69 @@ import { ActionTree, MutationTree } from 'vuex' import { RootState } from 'store' -import { CheckList } from '~/types' +import { CheckList, UpdateCheckListCommand, DeleteCheckListItem, UpdateCheckListItemCommand, AddCheckListItemCommand, CheckValue } from '~/types' export const state = () => ({ - checkLists: [] as CheckList[] + checkLists: [] as CheckList[], + currentCheckList: {} as CheckList }) export type CheckListsState = ReturnType export const mutations: MutationTree = { - SET_CHECKLISTS: (state, value: CheckList[]) => (state.checkLists = value) + SET_CHECKLISTS: (state, value: CheckList[]) => (state.checkLists = value), + SET_CURRENT_CHECKLIST: (state, value: CheckList) => (state.currentCheckList = value), + UPDATE_CHECKLIST: (state, value: CheckList) => { + state.currentCheckList.annotation = value.annotation + state.currentCheckList.text = value.text + }, + DELETE_CHECKLIST_ITEM: (state, value: number) => { + state.currentCheckList.checks = state.currentCheckList.checks.filter(ci=>ci.id !== value) + }, + DELETE_CHECKLIST: (state, value: number) => { + // const index: number = state.currentCheckList.checks.findIndex(ci=>ci.id === value) + state.checkLists = state.checkLists.filter(c=>c.id !== value) + }, + UPDATE_CHECKLIST_ITEM: (state, value: UpdateCheckListItemCommand) => { + const index: number = state.currentCheckList.checks.findIndex(ci=>ci.id === value.id) + let temp = state.currentCheckList.checks[index] + temp.checked = value.checked === CheckValue.False ? false:true + temp.remarks = value.remarks + temp.required = value.required + temp.text = value.text + state.currentCheckList.checks.splice(index, 1, temp) + } } export const actions: ActionTree = { async getChecklists ({ commit }, payload) { - const checks = await this.$axios.$get(`checklists?${payload ?? ''}`) + const checks = await this.$axios.$get('checklists', { params: payload }) commit('SET_CHECKLISTS', checks) + }, + async getCheckListItemsById ({ commit }, payload) { + const checkListResult = await this.$axios.$get(`checklists/${payload}`) + commit('SET_CURRENT_CHECKLIST', checkListResult) + return checkListResult + }, + async updateCheckList({commit}, payload: UpdateCheckListCommand) { + await this.$axios.$put(`checklists/${payload.idCheckList}`, payload) + commit('UPDATE_CHECKLIST', payload) + }, + async deleteCheckList({commit}, payload) { + await this.$axios.$delete(`checklists/${payload.idCheckList}`) + commit('DELETE_CHECKLIST', payload.id) + }, + async createCheckListItem({commit}, payload: AddCheckListItemCommand) { + await this.$axios.$post(`checklists/${payload.idCheckList}/items/`, payload) + }, + async updateCheckListItem({commit}, payload) { + await this.$axios.$put(`checklists/${payload.checkListId}/items/${payload.id}`, payload) + commit('UPDATE_CHECKLIST_ITEM', payload) + }, + async deleteCheckListItem({commit}, payload:DeleteCheckListItem) { + await this.$axios.$delete(`checklists/${payload.idCheckList}/items/${payload.idCheckListItem}`) + commit('DELETE_CHECKLIST_ITEM', payload.idCheckListItem) + }, + async updateCheckListItemParams({commit}, payload) { + await this.$axios.$put(`checklists/${payload.idCheckList}/items/${payload.idCheckListItem}`, payload) } } diff --git a/src/ClientApp/store/reportstrore.ts b/src/ClientApp/store/reportstrore.ts index e0d87ac4..d4846546 100644 --- a/src/ClientApp/store/reportstrore.ts +++ b/src/ClientApp/store/reportstrore.ts @@ -9,7 +9,8 @@ export const state = () => ({ export type ReportsState = ReturnType export const mutations: MutationTree = { - SET_REPORT_LIST: (state, value: Report[]) => (state.reportList = value) + SET_REPORT_LIST: (state, value: Report[]) => (state.reportList = value), + REMOVE_REPORT: (state, value: number) => (state.reportList = state.reportList.filter(r=>r.id !== value)) } export const actions: ActionTree = { @@ -17,8 +18,16 @@ export const actions: ActionTree = { const configs = await this.$axios.$get(`reports?${payload ?? ''}`) commit('SET_REPORT_LIST', configs) }, + async getReportById ({ }, payload) { + const report = await this.$axios.$get(`reports/${payload}`) + return report + }, // eslint-disable-next-line no-empty-pattern async createReport ({}, payload: CreateReport) { - await this.$axios.$post(`reports`, payload) + await this.$axios.$post('reports', payload) + }, + async deleteReport ({ commit }, payload: number) { + await this.$axios.$delete(`reports/${payload}`) + commit('REMOVE_REPORT', payload) } } diff --git a/src/ClientApp/store/signatures.ts b/src/ClientApp/store/signatures.ts index 18ec2d83..c1944107 100644 --- a/src/ClientApp/store/signatures.ts +++ b/src/ClientApp/store/signatures.ts @@ -9,12 +9,35 @@ export const state = () => ({ export type SignatureState = ReturnType export const mutations: MutationTree = { - SET_SIGNATURES_LIST: (state, value: SignatureDTO[]) => (state.signaturesList = value) + SET_SIGNATURES_LIST: (state, value: SignatureDTO[]) => (state.signaturesList = value), + REMOVE_SIGNATURE: (state, value: number) => (state.signaturesList = state.signaturesList.filter(s=>s.id !== value)), + ADD_SIGNATURE: (state, value: SignatureDTO) => (state.signaturesList.splice(0,0,value)), + UPDATE_SIGNATURE: (state, value: SignatureDTO) => { + const index = state.signaturesList.findIndex(s=>s.id === value.id) + state.signaturesList.splice(index,1,value) + } } export const actions: ActionTree = { async getSignatures ({ commit }, payload) { - const sign = await this.$axios.$get(`signatures?${payload ?? ''}`) + const sign = await this.$axios.$get('signatures', { params: payload }) commit('SET_SIGNATURES_LIST', sign) + }, + + async getSignatureById ({ commit }, payload) { + return await this.$axios.$get(`signatures/${payload}`) + }, + + async deleteSignature ({ commit }, payload) { + await this.$axios.$delete(`signatures/${payload}`) + commit('REMOVE_SIGNATURE', payload) + }, + async createSignature ({ commit }, payload) { + await this.$axios.$post(`signatures`, payload) + commit('ADD_SIGNATURE', payload) + }, + async updateSignature ({ commit }, payload) { + await this.$axios.$put(`signatures/${payload.id}`, payload) + commit('UPDATE_SIGNATURE', payload) } } diff --git a/src/ClientApp/types/CheckLists/Commands/UpdateCheckListItemCommand.ts b/src/ClientApp/types/CheckLists/Commands/UpdateCheckListItemCommand.ts index 062147ed..c70f8c46 100644 --- a/src/ClientApp/types/CheckLists/Commands/UpdateCheckListItemCommand.ts +++ b/src/ClientApp/types/CheckLists/Commands/UpdateCheckListItemCommand.ts @@ -1,10 +1,10 @@ -import { CheckValue } from '../Models/CheckValue' +import { CheckValue } from ".."; export interface UpdateCheckListItemCommand { id: number; checkListId: number; text: string; - checked: CheckValue; + checked: CheckValue required: boolean; remarks: string; } diff --git a/src/ClientApp/types/CheckLists/Models/CheckList.ts b/src/ClientApp/types/CheckLists/Models/CheckList.ts index 271ffe45..1b8144aa 100644 --- a/src/ClientApp/types/CheckLists/Models/CheckList.ts +++ b/src/ClientApp/types/CheckLists/Models/CheckList.ts @@ -1,6 +1,7 @@ import { CheckListParam } from './CheckListParam' import { ReportConfiguration } from '~/types/Reports/Models/ReportConfiguration' +import { CheckListItem } from './CheckListItem' export interface CheckList { id: number; @@ -9,6 +10,7 @@ export interface CheckList { reportConfigurationId: number | null; reportConfiguration: ReportConfiguration; text: string; + checks: CheckListItem[]; textParams: CheckListParam[]; annotation: string; isConfiguration: boolean; diff --git a/src/ClientApp/types/CheckLists/Models/CheckListItem.ts b/src/ClientApp/types/CheckLists/Models/CheckListItem.ts index 4c10db26..ac0ce46e 100644 --- a/src/ClientApp/types/CheckLists/Models/CheckListItem.ts +++ b/src/ClientApp/types/CheckLists/Models/CheckListItem.ts @@ -5,7 +5,7 @@ export interface CheckListItem { id: number; checkListId: number; text: string; - checked: CheckValue; + checked: boolean; required: boolean; remarks: string; textParams: CheckListParam[]; diff --git a/src/ClientApp/types/Filter.ts b/src/ClientApp/types/Filter.ts new file mode 100644 index 00000000..8ca6a5c0 --- /dev/null +++ b/src/ClientApp/types/Filter.ts @@ -0,0 +1,6 @@ +export interface FilterType { + filterText: String; + inConfigurationOnly: Boolean | undefined; + repotId: number | undefined; + reportConfigurationId: number | undefined; +} diff --git a/src/ClientApp/types/index.ts b/src/ClientApp/types/index.ts index 117388d8..4975dabc 100644 --- a/src/ClientApp/types/index.ts +++ b/src/ClientApp/types/index.ts @@ -1,3 +1,4 @@ export * from './CheckLists' export * from './Reports' export * from './Signatures' +export * from './Filter'