diff --git a/Thor.BlazorWAsm/Components/AttachmentSend.razor b/Thor.BlazorWAsm/Components/AttachmentSend.razor new file mode 100644 index 0000000..b3f1648 --- /dev/null +++ b/Thor.BlazorWAsm/Components/AttachmentSend.razor @@ -0,0 +1,59 @@ +@if (!Uploading) +{ + +} +@Status + +@code { + [Parameter] + public InspectionRegister Register { get; set; } + + [Parameter] + public string ItemId { get; set; } + + public bool Uploading { get; set; } = false; + public string Status { get; set; } = ""; + + async Task OnFileChanged(InputFileChangeEventArgs e) + { + Console.WriteLine("Début de l'envoi"); + Status = "Envoi en cours..."; + Uploading = true; + _ = InvokeAsync(StateHasChanged); + try + { + foreach (var file in e.GetMultipleFiles()) + { + Console.WriteLine($"DEbut envoi {file.Name}"); + Status = $"Envoi : {file.Name}."; + _ = InvokeAsync(StateHasChanged); + + using var memstr = new MemoryStream(); + await file.OpenReadStream(maxAllowedSize: long.MaxValue).CopyToAsync(memstr); ; + + + Register.Add(new() + { + Identifier = Guid.NewGuid().ToString(), + Author = "(null)", + Type = InspectionEntry.EntryType.Attachement, + Target = ItemId, + Attachment = memstr.ToArray(), + AttachmentName = file.Name + }); + Console.WriteLine($"Added attachment {file.Name}, size: {memstr.Length}."); + } + } + catch (Exception ex) + { + Status = $"Échec de l'envoi : {ex}."; + _ = InvokeAsync(StateHasChanged); + Console.WriteLine($"Echec de l'envoi: {ex}"); + } + + Uploading = false; + Status = ""; + _ = InvokeAsync(StateHasChanged); + Console.WriteLine("Envoi réussi"); + } +} diff --git a/Thor.BlazorWAsm/Components/AttachmentsView.razor b/Thor.BlazorWAsm/Components/AttachmentsView.razor new file mode 100644 index 0000000..1354e8b --- /dev/null +++ b/Thor.BlazorWAsm/Components/AttachmentsView.razor @@ -0,0 +1,31 @@ +
+ @foreach(var a in Attachments) + { +

@a.Name

+ } +
+ + + +@code { + [Parameter] + public InspectionRegister Register { get; set; } + + [Parameter] + public string ItemId { get; set; } + + List Attachments { get; set; } = new(); + + public async Task Refresh() + { + Attachments.Clear(); + Attachments = Register.GetAttachments(ItemId).ToList(); + StateHasChanged(); + } + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + await Refresh(); + } +} diff --git a/Thor.BlazorWAsm/Components/CommentsView.razor b/Thor.BlazorWAsm/Components/CommentsView.razor index 4f0f9f4..16e82ae 100644 --- a/Thor.BlazorWAsm/Components/CommentsView.razor +++ b/Thor.BlazorWAsm/Components/CommentsView.razor @@ -1,5 +1,42 @@ -

CommentsView

+ + +
+ @foreach (var c in Comments) + { +
+ @(c.Author ?? "Inconnu"): + @c.Content +
+ } + + +
@code { + [Parameter] + public InspectionRegister Register { get; set; } + List Comments { get; } = new(); + string NewCommentText { get; set; } = ""; + + protected async override Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + Comments.Add(new() + { + Content = "test comment" + }); + } } diff --git a/Thor.BlazorWAsm/Components/HistoryView.razor b/Thor.BlazorWAsm/Components/HistoryView.razor new file mode 100644 index 0000000..3481d3b --- /dev/null +++ b/Thor.BlazorWAsm/Components/HistoryView.razor @@ -0,0 +1,92 @@ +@using System.Timers + + + + @context.Author + + + + @FormatDate(context.When) + + + + @FormatEntry(context) + + + + + +@code { + [Parameter] + public InspectionRegister Register { get; set; } + + [Parameter] + public string ItemId { get; set; } + + private System.Timers.Timer Timer = new(1000); + Grid Grid = default!; + + private async Task> EmployeesDataProvider(GridDataProviderRequest request) + { + var entries = Register.GetEntriesOrdered(ItemId); + return await Task.FromResult(request.ApplyTo(entries)); + } + + protected override void OnInitialized() + { + base.OnInitialized(); + Timer.Elapsed += async (object? sender, ElapsedEventArgs e) => + { + await InvokeAsync(async() => { + await Grid.RefreshDataAsync(); + StateHasChanged(); + }); + }; + Timer.Enabled = true; + } + + public string FormatDate(DateTime dt) + { + return dt.ToString("M MMM hh:mm"); + } + + public string FormatEntry(InspectionEntry e) + { + if (e.Type == InspectionEntry.EntryType.Attachement) + return "Ajout d'une pièce jointe."; + else if(e.Type == InspectionEntry.EntryType.Set) + return $"Changement de l'état vers {FormatState(e.State)}."; + else + return e.Type.ToString(); + } + + public string FormatState(ItemAnswer.State? s) + { + if (s is null) + return "(null)"; + else if (s == ItemAnswer.State.NotAnswed) + return "non répondu"; + else if (s == ItemAnswer.State.Compliant) + return "conforme"; + else if (s == ItemAnswer.State.PartiallyCompliant) + return "partiellement conforme"; + else if (s == ItemAnswer.State.Improper) + return "non conforme"; + else if (s == ItemAnswer.State.Invalid) + return "sans objet"; + else if (s == ItemAnswer.State.Ignored) + return "non instruit"; + + return s.ToString(); + } +} diff --git a/Thor.BlazorWAsm/Components/InspectionFiller.razor b/Thor.BlazorWAsm/Components/InspectionFiller.razor new file mode 100644 index 0000000..01061bc --- /dev/null +++ b/Thor.BlazorWAsm/Components/InspectionFiller.razor @@ -0,0 +1,42 @@ +

@Inspection.Name

+ +
+ +
+ +@foreach (var item in DisplayedItems) +{ + +} + +@code +{ + [Parameter] + public Inspection Inspection { get; set; } + + string? _filter { get; set; } = null; + + public List DisplayedItems { get; set; } = new(); + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + Refresh(); + } + + public void Refresh() + { + DisplayedItems = Inspection.Grid.GetItems().ToList(); + + if(!String.IsNullOrEmpty(_filter)) + DisplayedItems = DisplayedItems.Where(x => x.Label.Contains(_filter) || x.Identifier.Contains(_filter)).ToList(); + + StateHasChanged(); + } + + private async Task OnInput(ChangeEventArgs e) + { + _filter = e.Value?.ToString(); + Refresh(); + } +} diff --git a/Thor.BlazorWAsm/Components/InspectionItemFiller.razor b/Thor.BlazorWAsm/Components/InspectionItemFiller.razor index 71762f8..98200e3 100644 --- a/Thor.BlazorWAsm/Components/InspectionItemFiller.razor +++ b/Thor.BlazorWAsm/Components/InspectionItemFiller.razor @@ -93,7 +93,7 @@ public Item Item { get; set; } [Parameter] - public Register? Register { get; set; } + public InspectionRegister? Register { get; set; } private Modal Details = default!; diff --git a/Thor.BlazorWAsm/Components/InspectionItemFillerDetail.razor b/Thor.BlazorWAsm/Components/InspectionItemFillerDetail.razor index ec4ca01..de95762 100644 --- a/Thor.BlazorWAsm/Components/InspectionItemFillerDetail.razor +++ b/Thor.BlazorWAsm/Components/InspectionItemFillerDetail.razor @@ -1,4 +1,11 @@ -@if (Item.Force == ItemVerification.VerificationForce.Optionnal) + + +@if (Item.Force == ItemVerification.VerificationForce.Optionnal) { @@ -22,28 +29,44 @@ else if (Item.Force == ItemVerification.VerificationForce.Mandatory)

@Item.Label

-
Statut
- +
+
Statut
+ +
-@if (String.IsNullOrEmpty(Item.Description)) -{ -
Description
-

@Item.Description

-} +
+ @if (String.IsNullOrEmpty(Item.Description)) + { +
Description
+

@Item.Description

+ } +
-
Références
-

@Item.References

-
Commentaires
-

+
+
Références
+

@Item.References

+
-
Historique des modifications
-

+
+
Pièces jointes
+ +
+ +
+
Commentaires
+ +
+ +
+
Historique des modifications
+ +
@code { [Parameter] public ItemVerification Item { get; set; } [Parameter] - public Register? Register { get; set; } + public InspectionRegister? Register { get; set; } } diff --git a/Thor.BlazorWAsm/Components/InspectionItemQuickAnswerSelector.razor b/Thor.BlazorWAsm/Components/InspectionItemQuickAnswerSelector.razor index 8f7d276..346e991 100644 --- a/Thor.BlazorWAsm/Components/InspectionItemQuickAnswerSelector.razor +++ b/Thor.BlazorWAsm/Components/InspectionItemQuickAnswerSelector.razor @@ -13,7 +13,7 @@ public ItemVerification Item { get; set; } [Parameter] - public Register Register { get; set; } + public InspectionRegister Register { get; set; } ItemAnswer.State Value { @@ -27,7 +27,7 @@ { Identifier = Guid.NewGuid().ToString(), Author = "(null)", - Type = Entry.EntryType.Set, + Type = InspectionEntry.EntryType.Set, Target = Item.Identifier, State = value }); diff --git a/Thor.BlazorWAsm/Components/InspectionRow.razor b/Thor.BlazorWAsm/Components/InspectionRow.razor deleted file mode 100644 index ef176a5..0000000 --- a/Thor.BlazorWAsm/Components/InspectionRow.razor +++ /dev/null @@ -1,160 +0,0 @@ - - -
- -@if(Row is not null) -{ - @if(Row.IsTitle) - { - - @Row.Item.OrderId - @Row.Item.Label - - } - else if(Row.Item is ItemVerification verification) - { -
- - - - - - @if (verification.Force == ItemVerification.VerificationForce.Optionnal) - { - - - - } - else if(verification.Force == ItemVerification.VerificationForce.Recommandation) - { - - - - } - else if(verification.Force == ItemVerification.VerificationForce.Mandatory) - { - - - - } -
-
- @Row.Item.OrderId -
-
- @Row.Item.Label -
-
- @Row.Item.References -
-
- -

Out: @Row.Answer.CurrentState

-
- } -} -else -{ - -} -
- - - -@code { - public Shared.InspectionRow? _row; - - [Parameter] - public Shared.InspectionRow? Row - { - get - { - return _row; - } - - set - { - if (_row != value) - { - _row = value; - if (RowChanged.HasDelegate) - RowChanged.InvokeAsync(_row); - } - } - } - - [Parameter] - public EventCallback RowChanged { get; set; } - - - private Modal detailsModal = default!; - - protected override Task OnInitializedAsync() - { - return base.OnInitializedAsync(); - } - - - public string Class - { - get - { - if (Row is null) - return ""; - - if (!Row.IsTitle) - return "verification"; - - return "title order-" + Row.Order; - } - } - - private async Task ShowDetails() - { - if (Row is null) - return; //TODO: add error message - - Action callback = (Shared.InspectionRow row) => - { - StateHasChanged(); - }; - - var parameters = new Dictionary(); - parameters.Add("Row", Row); - parameters.Add("RowChanged", callback); - - await detailsModal.ShowAsync(title: "Détails", parameters: parameters); - } -} diff --git a/Thor.BlazorWAsm/Components/InspectionRowDetails.razor b/Thor.BlazorWAsm/Components/InspectionRowDetails.razor deleted file mode 100644 index 3e018b0..0000000 --- a/Thor.BlazorWAsm/Components/InspectionRowDetails.razor +++ /dev/null @@ -1,71 +0,0 @@ -@if (Row is not null && Verification is not null) -{ - @if (Verification.Force == ItemVerification.VerificationForce.Optionnal) - { - - - Cet item est une indication, il ne relève ni d'une recommandation, ni d'une obligation. - - } - else if (Verification.Force == ItemVerification.VerificationForce.Recommandation) - { - - - Cet item relève de la recommandation, il relève des recommandations opposables. - - } - else if (Verification.Force == ItemVerification.VerificationForce.Mandatory) - { - - - Cet item doit obligatoirement être suivi, car il fait l'objet d'un référentiel opposable. - - } - -

@Row.Item.Label

- -
Statut
- - - @if(String.IsNullOrEmpty(Row.Item.Description)) - { -
Description
-

@Row.Item.Description

- } - -
Références
-

@Row.Item.References

- -
Commentaires
-

- -
Historique des modifications
-

-} -else -{ - -} - -@code { - [Parameter] - public Shared.InspectionRow? Row { get; set; } - - public Shared.ItemVerification? Verification { get { - if (Row == null) - return null; - - return (Shared.ItemVerification)Row.Item ?? null; - } } - - [Parameter] - public Action RowChanged { get; set; } = (Shared.InspectionRow r) => { }; -} diff --git a/Thor.BlazorWAsm/Components/TemplateFiller.razor b/Thor.BlazorWAsm/Components/TemplateFiller.razor new file mode 100644 index 0000000..baeba55 --- /dev/null +++ b/Thor.BlazorWAsm/Components/TemplateFiller.razor @@ -0,0 +1,48 @@ +

@Grid.Name

+ +@foreach (var i in Grid.Register.Forge()) +{ + await AddChildTitle(i.Identifier))/> +} + +@code { + [Parameter] + public TemplateGrid Grid { get; set; } = default!; + + protected async Task AddChildTitle(string? parent = null) + { + var id = Guid.NewGuid().ToString(); + + Grid.Register.Add(new() + { + Identifier = Guid.NewGuid().ToString(), + Target = id, + Author = "", + Type = TemplateEntry.EntryType.Set, + Field = TemplateEntry.FieldType.Type, + Content = TemplateEntry.TYPE_TITLE, + }); + + Grid.Register.Add(new() + { + Identifier = Guid.NewGuid().ToString(), + Target = id, + Author = "", + Type = TemplateEntry.EntryType.Set, + Field = TemplateEntry.FieldType.Parent, + Content = parent + }); + + Grid.Register.Add(new() + { + Identifier = Guid.NewGuid().ToString(), + Target = id, + Author = "", + Type = TemplateEntry.EntryType.Set, + Field = TemplateEntry.FieldType.Label, + Content = "TEST " + }); + + StateHasChanged(); + } +} diff --git a/Thor.BlazorWAsm/Components/TemplateFillerDetail.razor b/Thor.BlazorWAsm/Components/TemplateFillerDetail.razor new file mode 100644 index 0000000..60b2e91 --- /dev/null +++ b/Thor.BlazorWAsm/Components/TemplateFillerDetail.razor @@ -0,0 +1,9 @@ +

TemplateFillerDetail

+ +@code { + [Parameter] + public TemplateGrid Grid { get; set; } = default!; + + [Parameter] + public Item Item { get; set; } = default!; +} diff --git a/Thor.BlazorWAsm/Components/TemplateFillerItem.razor b/Thor.BlazorWAsm/Components/TemplateFillerItem.razor new file mode 100644 index 0000000..e434456 --- /dev/null +++ b/Thor.BlazorWAsm/Components/TemplateFillerItem.razor @@ -0,0 +1,113 @@ + + +
+
+ + + + + + + + + @if (Item is ItemTitle t) + { + + + + } +
+ + +
+ @if (Item is ItemTitle title) + { + + @title.OrderId - @title.Label + + } + else if (Item is ItemVerification verif) + { + @verif.Label + } +
+ + + +
+ + + +@code { + [Parameter] + public TemplateGrid Grid { get; set; } = default!; + + [Parameter] + public Item Item { get; set; } = default!; + + [Parameter] + public EventCallback OnAddChild { get; set; } = default!; + + private Modal Details = default!; + + public string Class + { + get + { + if (Item is not ItemTitle) + return "verification"; + + return "title order-" + Item.Order; + } + } + + private async Task ShowDetails() + { + var parameters = new Dictionary(); + parameters.Add(nameof(TemplateFillerDetail.Grid), Grid); + parameters.Add(nameof(TemplateFillerDetail.Item), Item); + + await Details.ShowAsync(title: "Détails", parameters: parameters); + } + + private void OnModalHidden() + { + StateHasChanged(); + } +} diff --git a/Thor.BlazorWAsm/Components/TemplateTable.razor b/Thor.BlazorWAsm/Components/TemplateTable.razor index bdbac8b..9b6f06e 100644 --- a/Thor.BlazorWAsm/Components/TemplateTable.razor +++ b/Thor.BlazorWAsm/Components/TemplateTable.razor @@ -1,4 +1,61 @@ -

Liste des modèles

+@inject TemplateService Templates; + + + + + @foreach(var i in Grids) + { +
+ @i.Name +
+ } + + + + + + + + + @code { + private Modal modal = default!; + + [Parameter] + public string Name { get; set; } = String.Empty; + + public List Grids { get; set; } = []; + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + await Refresh(); + } + + + public async Task ShowNewModal() + { + await modal.ShowAsync(); + } + + async Task CreateNewModal() + { + await modal.HideAsync(); + var n = await Templates.Create(Name); + //todo: switch to correct page + await Refresh(); + } + + public async Task Refresh() + { + Grids.Clear(); + await foreach (var i in Templates.Get()) + Grids.Add(i); + + StateHasChanged(); + } } diff --git a/Thor.BlazorWAsm/Layout/NavMenu.razor b/Thor.BlazorWAsm/Layout/NavMenu.razor index d8c7134..1b55973 100644 --- a/Thor.BlazorWAsm/Layout/NavMenu.razor +++ b/Thor.BlazorWAsm/Layout/NavMenu.razor @@ -7,7 +7,7 @@ -