adding calendar and try catch
Some checks are pending
ci / build (8.0.x) (push) Waiting to run
ci / build-Docker (push) Blocked by required conditions

This commit is contained in:
Andy Pack 2024-06-10 19:09:26 +01:00
parent ff3db603ba
commit 9331519649
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
6 changed files with 164 additions and 5 deletions

View File

@ -0,0 +1,109 @@
@using Overflow.SouthernWater
@rendermode RenderMode.InteractiveAuto
@inject DialogService DialogService
@if (Job == null)
{
<p>
<em>Loading...</em>
</p>
}
else
{
<RadzenScheduler @ref=@scheduler SlotRender=@OnSlotRender style="height: 768px;" TItem="Spill" Data=@Job.Spills StartProperty="eventStart" EndProperty="eventStop"
TextProperty="bathingSite" SelectedIndex="2"
SlotSelect=@OnSlotSelect AppointmentSelect=@OnAppointmentSelect AppointmentRender=@OnAppointmentRender
AppointmentMove=@OnAppointmentMove >
<RadzenDayView />
<RadzenWeekView />
<RadzenMonthView />
<RadzenYearPlannerView />
<RadzenYearTimelineView />
<RadzenYearView />
</RadzenScheduler>
}
@code {
RadzenScheduler<Spill> scheduler;
[Parameter] public SouthernWaterApiJob? Job { get; set; }
Dictionary<DateTime, string> events = new Dictionary<DateTime, string>();
void OnSlotRender(SchedulerSlotRenderEventArgs args)
{
// // Highlight today in month view
// if (args.View.Text == "Month" && args.Start.Date == DateTime.Today)
// {
// args.Attributes["style"] = "background: 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: rgba(255,220,40,.2);";
// }
}
async Task OnSlotSelect(SchedulerSlotSelectEventArgs args)
{
// if (args.View.Text != "Year")
// {
// Spill data = await DialogService.OpenAsync<AddAppointmentPage>("Add Appointment",
// new Dictionary<string, object> { { "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<Spill> args)
{
// var copy = new Appointment
// {
// Start = args.Data.Start,
// End = args.Data.End,
// Text = args.Data.Text
// };
//
// var data = await DialogService.OpenAsync<EditAppointmentPage>("Edit Appointment", new Dictionary<string, object> { { "Appointment", copy } });
//
// if (data != null)
// {
// // Update the appointment
// args.Data.Start = data.Start;
// args.Data.End = data.End;
// args.Data.Text = data.Text;
// }
//
// await scheduler.Reload();
}
void OnAppointmentRender(SchedulerAppointmentRenderEventArgs<Spill> 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();
// }
}
}

View File

@ -14,4 +14,6 @@
An unhandled error has occurred. An unhandled error has occurred.
<a href="" class="reload">Reload</a> <a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a> <a class="dismiss">🗙</a>
</div> </div>
<RadzenComponents/>

View File

@ -1,8 +1,11 @@
<RadzenMenu Click="OnParentClicked"> @rendermode InteractiveServer
<RadzenMenu Click="OnParentClicked">
<RadzenMenuItem Text="Home" Icon="home" Path="/"> <RadzenMenuItem Text="Home" Icon="home" Path="/">
</RadzenMenuItem> </RadzenMenuItem>
<RadzenMenuItem Text="Southern Water" Icon="water_drop"> <RadzenMenuItem Text="Southern Water" Icon="water_drop">
<RadzenMenuItem Text="Spills Data" Path="/spills" Icon="table_view"></RadzenMenuItem> <RadzenMenuItem Text="Spills Data" Path="/spills" Icon="table_view"></RadzenMenuItem>
<RadzenMenuItem Text="Spill Events" Path="/spills-cal" Icon="event"></RadzenMenuItem>
</RadzenMenuItem> </RadzenMenuItem>
</RadzenMenu> </RadzenMenu>

View File

@ -0,0 +1,35 @@
@page "/spills-cal"
@using MongoDB.Driver
@using Overflow.SouthernWater
@rendermode RenderMode.InteractiveServer
<PageTitle>Southern Water Spills</PageTitle>
<h1>Spills</h1>
<p>This shows the data that you can see on the Southern Water Beachbuoy system</p>
<RadzenCard class="my-4">
<RadzenStack Orientation="Orientation.Vertical" AlignItems="AlignItems.Start" Wrap="FlexWrap.Wrap">
@if (job is not null)
{
<RadzenText TextStyle="TextStyle.Body1">Last updated at <b>@job.EndTime</b></RadzenText>
}
</RadzenStack>
</RadzenCard>
<SpillsCalendar Job="@job" />
@code {
private SouthernWaterApiJob? job;
[Inject] private IMongoDatabase database { get; set; }
// private bool showIds;
protected override async Task OnInitializedAsync()
{
job = database.GetCollection<SouthernWaterApiJob>(Static.CollectionName)
.AsQueryable()
.OrderByDescending(j => j.EndTime)
.FirstOrDefault();
}
}

View File

@ -1,12 +1,12 @@
using Overflow.Web.Components; using Overflow.Web.Components;
using Overflow; using Overflow;
using MongoDB.Driver; using MongoDB.Driver;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using Overflow.SouthernWater; using Overflow.SouthernWater;
using Quartz; using Quartz;
using Quartz.AspNetCore; using Quartz.AspNetCore;
using Radzen;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -74,6 +74,8 @@ builder.Services.AddSingleton<SouthernWaterApi>();
builder.Services.AddScoped<SouthernWaterApiJobRunner, SouthernWaterApiJobRunnerPersisting>(); builder.Services.AddScoped<SouthernWaterApiJobRunner, SouthernWaterApiJobRunnerPersisting>();
builder.Services.AddTransient<SouthernWaterJob>(); builder.Services.AddTransient<SouthernWaterJob>();
builder.Services.AddRadzenComponents();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

View File

@ -1,11 +1,19 @@
using Microsoft.Extensions.Logging;
using Quartz; using Quartz;
namespace Overflow.SouthernWater; namespace Overflow.SouthernWater;
public class SouthernWaterJob(SouthernWaterApiJobRunner jobRunner) : IJob public class SouthernWaterJob(ILogger<SouthernWaterJob> logger, SouthernWaterApiJobRunner jobRunner) : IJob
{ {
public async Task Execute(IJobExecutionContext context) public async Task Execute(IJobExecutionContext context)
{ {
await jobRunner.LoadSpills(); try
{
await jobRunner.LoadSpills();
}
catch (Exception e)
{
logger.LogError(e, "Exception while running Southern Water API Job");
}
} }
} }