adding calendar and try catch
This commit is contained in:
parent
ff3db603ba
commit
9331519649
109
Overflow.Web.Client/Components/SpillsCalendar.razor
Normal file
109
Overflow.Web.Client/Components/SpillsCalendar.razor
Normal 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();
|
||||
// }
|
||||
}
|
||||
}
|
@ -15,3 +15,5 @@
|
||||
<a href="" class="reload">Reload</a>
|
||||
<a class="dismiss">🗙</a>
|
||||
</div>
|
||||
|
||||
<RadzenComponents/>
|
@ -1,8 +1,11 @@
|
||||
<RadzenMenu Click="OnParentClicked">
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<RadzenMenu Click="OnParentClicked">
|
||||
<RadzenMenuItem Text="Home" Icon="home" Path="/">
|
||||
</RadzenMenuItem>
|
||||
<RadzenMenuItem Text="Southern Water" Icon="water_drop">
|
||||
<RadzenMenuItem Text="Spills Data" Path="/spills" Icon="table_view"></RadzenMenuItem>
|
||||
<RadzenMenuItem Text="Spill Events" Path="/spills-cal" Icon="event"></RadzenMenuItem>
|
||||
</RadzenMenuItem>
|
||||
</RadzenMenu>
|
||||
|
||||
|
35
Overflow.Web/Components/Pages/SpillsCalendarPage.razor
Normal file
35
Overflow.Web/Components/Pages/SpillsCalendarPage.razor
Normal 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();
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
using Overflow.Web.Components;
|
||||
using Overflow;
|
||||
|
||||
|
||||
using MongoDB.Driver;
|
||||
using NLog.Extensions.Logging;
|
||||
using Overflow.SouthernWater;
|
||||
using Quartz;
|
||||
using Quartz.AspNetCore;
|
||||
using Radzen;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@ -74,6 +74,8 @@ builder.Services.AddSingleton<SouthernWaterApi>();
|
||||
builder.Services.AddScoped<SouthernWaterApiJobRunner, SouthernWaterApiJobRunnerPersisting>();
|
||||
builder.Services.AddTransient<SouthernWaterJob>();
|
||||
|
||||
builder.Services.AddRadzenComponents();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@ -1,11 +1,19 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
|
||||
namespace Overflow.SouthernWater;
|
||||
|
||||
public class SouthernWaterJob(SouthernWaterApiJobRunner jobRunner) : IJob
|
||||
public class SouthernWaterJob(ILogger<SouthernWaterJob> logger, SouthernWaterApiJobRunner jobRunner) : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
await jobRunner.LoadSpills();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Exception while running Southern Water API Job");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user