diff --git a/EgwCoreLib.BlazorTest/Components/AddAppointmentPage.razor b/EgwCoreLib.BlazorTest/Components/AddAppointmentPage.razor new file mode 100644 index 0000000..ec52458 --- /dev/null +++ b/EgwCoreLib.BlazorTest/Components/AddAppointmentPage.razor @@ -0,0 +1,49 @@ +@inject DialogService DialogService + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@code { + [Parameter] + public DateTime Start { get; set; } + + [Parameter] + public DateTime End { get; set; } + + Appointment model = new Appointment(); + + protected override void OnParametersSet() + { + model.Start = Start; + model.End = End; + } + + void OnSubmit(Appointment model) + { + DialogService.Close(model); + } +} \ No newline at end of file diff --git a/EgwCoreLib.BlazorTest/Components/Appointment.cs b/EgwCoreLib.BlazorTest/Components/Appointment.cs new file mode 100644 index 0000000..4122194 --- /dev/null +++ b/EgwCoreLib.BlazorTest/Components/Appointment.cs @@ -0,0 +1,11 @@ +namespace EgwCoreLib.BlazorTest.Components +{ + public class Appointment + { + public DateTime Start { get; set; } + public DateTime End { get; set; } + + public string Text { get; set; } = ""; + public string Detail { get; set; } = ""; + } +} diff --git a/EgwCoreLib.BlazorTest/Components/EditAppointmentPage.razor b/EgwCoreLib.BlazorTest/Components/EditAppointmentPage.razor new file mode 100644 index 0000000..f5c6cb1 --- /dev/null +++ b/EgwCoreLib.BlazorTest/Components/EditAppointmentPage.razor @@ -0,0 +1,45 @@ +@inject DialogService DialogService + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@code { + [Parameter] + public Appointment Appointment { get; set; } + + Appointment model = new Appointment(); + + protected override void OnParametersSet() + { + model = Appointment; + } + + void OnSubmit(Appointment model) + { + DialogService.Close(model); + } +} \ No newline at end of file diff --git a/EgwCoreLib.BlazorTest/Components/EventConsole.razor b/EgwCoreLib.BlazorTest/Components/EventConsole.razor new file mode 100644 index 0000000..261b2bc --- /dev/null +++ b/EgwCoreLib.BlazorTest/Components/EventConsole.razor @@ -0,0 +1,64 @@ +@using Radzen +@using System.Text.Json +@inject IJSRuntime JSRuntime + + + + Console log + + + + @foreach (var message in messages) + { + + @message.Date.ToString("HH:mm:ss.ff") @message.Text + + } + + + + +@code { + class Message + { + public DateTime Date { get; set; } + public string Text { get; set; } + public AlertStyle AlertStyle { get; set; } + } + + [Parameter(CaptureUnmatchedValues = true)] + public IDictionary Attributes { get; set; } + IList messages = new List(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (!firstRender) + { + await JSRuntime.InvokeVoidAsync("eval", $"document.getElementById('event-console').scrollTop = document.getElementById('event-console').scrollHeight"); + } + } + + void OnClearClick() + { + Clear(); + } + + public void Clear() + { + messages.Clear(); + + InvokeAsync(StateHasChanged); + } + + public void Log(string message, AlertStyle alertStyle = AlertStyle.Info) + { + messages.Add(new Message { Date = DateTime.Now, Text = message, AlertStyle = alertStyle }); + + InvokeAsync(StateHasChanged); + } + + public void Log(object value) + { + Log(JsonSerializer.Serialize(value)); + } +} \ No newline at end of file diff --git a/EgwCoreLib.BlazorTest/Data/TestData.cs b/EgwCoreLib.BlazorTest/Data/TestData.cs index 5a7a05a..8596a96 100644 --- a/EgwCoreLib.BlazorTest/Data/TestData.cs +++ b/EgwCoreLib.BlazorTest/Data/TestData.cs @@ -17,6 +17,7 @@ namespace EgwCoreLib.BlazorTest.Data {"TestSvgDraw", "Test SVG draw"}, {"TestGauges", "Test Gauges"}, {"TestChart", "Test Chart.js"}, + {"TestRadzenSched", "Test Radzen Scheduler" } }; } } diff --git a/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj b/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj index 0996797..794fdad 100644 --- a/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj +++ b/EgwCoreLib.BlazorTest/EgwCoreLib.BlazorTest.csproj @@ -19,6 +19,10 @@ + + + + diff --git a/EgwCoreLib.BlazorTest/Pages/TestRadzenSched.razor b/EgwCoreLib.BlazorTest/Pages/TestRadzenSched.razor new file mode 100644 index 0000000..a96ccdb --- /dev/null +++ b/EgwCoreLib.BlazorTest/Pages/TestRadzenSched.razor @@ -0,0 +1,170 @@ +@page "/TestRadzenSched" +@inject DialogService DialogService + +Test Radzen Scheduler + +
+
+

Test Radzen Scheduler

+
+
+ @if (currView == "year" || currView == "planner") + { + + + + + + } + else + { +

@currView

+ } +
+ + + + + + + + @* *@ + + + +
+ +
+
+ +@code { + RadzenScheduler scheduler; + EventConsole console; + Dictionary events = new Dictionary(); + + Month startMonth = Month.January; + + bool showSelMonth { get; set; } = true; + + async Task StartMonthChange() + { + await scheduler.Reload(); + } + + + IList appointments = new List + { + new Appointment { Start = DateTime.Today.AddDays(-2), End = DateTime.Today.AddDays(-2), Text = "Birthday", Detail="My Birthday" }, + new Appointment { Start = DateTime.Today.AddDays(-11), End = DateTime.Today.AddDays(-10), Text = "Day off", Detail="Rest required" }, + new Appointment { Start = DateTime.Today.AddDays(-10), End = DateTime.Today.AddDays(-8), Text = "Work from home", Detail="WIP from remote" }, + new Appointment { Start = DateTime.Today.AddHours(10), End = DateTime.Today.AddHours(12), Text = "Online meeting", Detail="Teams" }, + new Appointment { Start = DateTime.Today.AddHours(10), End = DateTime.Today.AddHours(13), Text = "Skype call", Detail="Google Meet?" }, + new Appointment { Start = DateTime.Today.AddHours(14), End = DateTime.Today.AddHours(14).AddMinutes(30), Text = "Dentist appointment", Detail="Anestetics" }, + new Appointment { Start = DateTime.Today.AddDays(1), End = DateTime.Today.AddDays(12), Text = "Vacation", Detail="Long awaited!!!" }, + }; + + void OnSlotRender(SchedulerSlotRenderEventArgs args) + { + // Highlight today in month view + if (args.View.Text == "Month" && args.Start.Date == DateTime.Today) + { + args.Attributes["style"] = "background: var(--rz-scheduler-highlight-background-color, rgba(255,220,40,.2));"; + } + + // Highlight working hours (9-18) + if ((args.View.Text == "Week" || args.View.Text == "Day") && args.Start.Hour > 8 && args.Start.Hour < 19) + { + args.Attributes["style"] = "background: var(--rz-scheduler-highlight-background-color, rgba(255,220,40,.2));"; + } + } + + async Task OnSlotSelect(SchedulerSlotSelectEventArgs args) + { + console.Log($"SlotSelect: Start={args.Start} End={args.End}"); + + if (args.View.Text != "Year") + { + Appointment data = await DialogService.OpenAsync("Add Appointment", + new Dictionary { { "Start", args.Start }, { "End", args.End } }); + + if (data != null) + { + appointments.Add(data); + // Either call the Reload method or reassign the Data property of the Scheduler + await scheduler.Reload(); + } + } + } + + async Task OnAppointmentSelect(SchedulerAppointmentSelectEventArgs args) + { + console.Log($"AppointmentSelect: Appointment={args.Data.Text}"); + + var copy = new Appointment + { + Start = args.Data.Start, + End = args.Data.End, + Text = args.Data.Text, + Detail = args.Data.Detail + }; + + var data = await DialogService.OpenAsync("Edit Appointment", new Dictionary { { "Appointment", copy } }); + + if (data != null) + { + // Update the appointment + args.Data.Start = data.Start; + args.Data.End = data.End; + args.Data.Text = data.Text; + args.Data.Detail = data.Detail; + } + + await scheduler.Reload(); + } + + void OnAppointmentRender(SchedulerAppointmentRenderEventArgs args) + { + // Never call StateHasChanged in AppointmentRender - would lead to infinite loop + + if (args.Data.Text == "Birthday") + { + args.Attributes["style"] = "background: red"; + } + } + + async Task OnAppointmentMove(SchedulerAppointmentMoveEventArgs args) + { + var draggedAppointment = appointments.FirstOrDefault(x => x == args.Appointment.Data); + + if (draggedAppointment != null) + { + draggedAppointment.Start = draggedAppointment.Start + args.TimeSpan; + + draggedAppointment.End = draggedAppointment.End + args.TimeSpan; + + await scheduler.Reload(); + } + } + + async Task OnLoadData(SchedulerLoadDataEventArgs args) + { + await Task.Delay(1); + currView = scheduler.SelectedView.Text.ToLowerInvariant(); + + schedHeight = (currView == "year" || currView == "planner") ? "height: 50rem;" : "height: 40rem;"; + // // Get the appointments for between the Start and End + // data = await MyAppointmentService.GetData(args.Start, args.End); + } + private string currView { get; set; } = ""; + private string schedHeight { get; set; } = "height: 40rem;"; +} \ No newline at end of file diff --git a/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml b/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml index fa505cf..e27bf5f 100644 --- a/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml +++ b/EgwCoreLib.BlazorTest/Pages/_Layout.cshtml @@ -1,4 +1,5 @@ @using Microsoft.AspNetCore.Components.Web +@using Radzen.Blazor @namespace EgwCoreLib.BlazorTest.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @@ -13,6 +14,7 @@ + @RenderBody() @@ -63,5 +65,6 @@ @*Gestione ricollegamento successivo: https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-6.0*@ @* *@ + diff --git a/EgwCoreLib.BlazorTest/Program.cs b/EgwCoreLib.BlazorTest/Program.cs index 11f57c6..14b7b33 100644 --- a/EgwCoreLib.BlazorTest/Program.cs +++ b/EgwCoreLib.BlazorTest/Program.cs @@ -1,6 +1,7 @@ using EgwCoreLib.BlazorTest; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; +using Radzen; var builder = WebApplication.CreateBuilder(args); @@ -8,6 +9,15 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); +// aggiunto compressione +builder.Services.AddResponseCompression(options => +{ + options.EnableForHttps = true; +}); + +// aggiungo componenti radzen +builder.Services.AddRadzenComponents(); + var app = builder.Build(); // Configure the HTTP request pipeline. @@ -18,11 +28,11 @@ if (!app.Environment.IsDevelopment()) app.UseHsts(); } -//// disabilita risposta compressa in debug -//if (!app.Environment.IsDevelopment()) -//{ -// app.UseResponseCompression(); -//} +// disabilita risposta compressa in debug +if (!app.Environment.IsDevelopment()) +{ + app.UseResponseCompression(); +} app.UseHttpsRedirection(); diff --git a/EgwCoreLib.BlazorTest/Shared/MainLayout.razor b/EgwCoreLib.BlazorTest/Shared/MainLayout.razor index 2f45961..8544dfd 100644 --- a/EgwCoreLib.BlazorTest/Shared/MainLayout.razor +++ b/EgwCoreLib.BlazorTest/Shared/MainLayout.razor @@ -13,6 +13,7 @@
@Body +
diff --git a/EgwCoreLib.BlazorTest/_Imports.razor b/EgwCoreLib.BlazorTest/_Imports.razor index fed008e..9d88a93 100644 --- a/EgwCoreLib.BlazorTest/_Imports.razor +++ b/EgwCoreLib.BlazorTest/_Imports.razor @@ -10,4 +10,6 @@ @using EgwCoreLib.BlazorTest.Components @using EgwCoreLib.BlazorTest.Shared @using EgwCoreLib.Razor -@using EgwCoreLib.Razor.Data \ No newline at end of file +@using EgwCoreLib.Razor.Data +@using Radzen +@using Radzen.Blazor \ No newline at end of file