2021-07-03 12:19:53 +00:00
|
|
|
@page "/calendars/{calendarId:int}/events/{eventUid}"
|
2021-07-08 10:41:20 +00:00
|
|
|
@using System.Globalization
|
2021-07-03 12:19:53 +00:00
|
|
|
@inject Data.CalendarService _calendarService
|
2021-07-05 22:04:24 +00:00
|
|
|
@inject NavigationManager _navigationManager
|
2021-07-03 12:19:53 +00:00
|
|
|
|
2021-07-04 11:38:52 +00:00
|
|
|
<a href="/calendars/@CalendarId">
|
|
|
|
<span class="oi oi-arrow-left"></span> Back
|
|
|
|
</a>
|
|
|
|
|
2021-07-03 12:19:53 +00:00
|
|
|
@if (_event == null)
|
|
|
|
{
|
|
|
|
<p>
|
2021-07-05 22:04:24 +00:00
|
|
|
<em>@(_notFound ? "Event not found" : "Loading...")</em>
|
2021-07-03 12:19:53 +00:00
|
|
|
</p>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-08 10:41:20 +00:00
|
|
|
<h1>Event</h1>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<strong>Summary: </strong>
|
|
|
|
@if (_editing != Editing.Summary)
|
|
|
|
{
|
|
|
|
<span class="property-editable" @onclick="() => _editing = Editing.Summary">
|
|
|
|
@_event.Summary
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<div>
|
|
|
|
<input @bind="@_event.Summary"/>
|
|
|
|
<button @onclick="UpdateEvent">Save</button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<strong>Start: </strong>
|
|
|
|
@if (_editing != Editing.DtStart)
|
|
|
|
{
|
|
|
|
<span class="property-editable" @onclick="() => _editing = Editing.DtStart">
|
|
|
|
@(_event.DtStart?.ToString(DtFormat) ?? "Unknown")
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<input @bind="@_event.DtStart" @bind:format="@DtFormat"/>
|
|
|
|
<button @onclick="UpdateEvent">Save</button>
|
|
|
|
}
|
|
|
|
</div>
|
2021-07-05 19:50:58 +00:00
|
|
|
|
|
|
|
<div>
|
2021-07-08 10:41:20 +00:00
|
|
|
<strong>End: </strong>
|
|
|
|
@if (_editing != Editing.CalculatedEnd)
|
|
|
|
{
|
|
|
|
<span class="property-editable" @onclick="() => _editing = Editing.CalculatedEnd">
|
|
|
|
@(_event.CalculatedEnd?.ToString(DtFormat) ?? "Unknown")
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<input @bind="@_event.CalculatedEnd" @bind:format="@DtFormat"/>
|
|
|
|
<button @onclick="UpdateEvent">Save</button>
|
|
|
|
}
|
2021-07-05 19:50:58 +00:00
|
|
|
</div>
|
2021-07-04 11:39:11 +00:00
|
|
|
|
2021-07-08 10:41:20 +00:00
|
|
|
@if (_editing != Editing.Description)
|
2021-07-04 11:39:11 +00:00
|
|
|
{
|
2021-07-08 10:41:20 +00:00
|
|
|
<p class="event-description" @onclick="() => _editing = Editing.Description">
|
|
|
|
@(_event.Description ?? "No description")
|
|
|
|
</p>
|
2021-07-04 11:39:11 +00:00
|
|
|
}
|
2021-07-08 10:41:20 +00:00
|
|
|
else
|
2021-07-04 11:39:11 +00:00
|
|
|
{
|
|
|
|
<div>
|
2021-07-08 10:41:20 +00:00
|
|
|
<textarea rows="30" cols="100" @bind="@_event.Description"></textarea>
|
|
|
|
<button @onclick="UpdateEvent">Save</button>
|
2021-07-04 11:39:11 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
2021-07-05 22:04:24 +00:00
|
|
|
@if (!_confirmDelete)
|
|
|
|
{
|
|
|
|
<button class="btn btn-outline-danger" @onclick="DeleteEvent">Delete</button>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<button class="btn btn-danger" @onclick="DeleteEvent">Are you sure?</button>
|
|
|
|
}
|
2021-07-03 12:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@code
|
|
|
|
{
|
|
|
|
[Parameter]
|
|
|
|
public int CalendarId { get; set; }
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
public string EventUid { get; set; }
|
|
|
|
|
2021-07-08 10:41:20 +00:00
|
|
|
const string DtFormat = "dd-MM-yyyy HH:mm:ss";
|
|
|
|
|
2021-07-05 19:50:58 +00:00
|
|
|
private Data.Calendar _calendar;
|
2021-07-03 12:19:53 +00:00
|
|
|
private Data.Event _event;
|
2021-07-05 22:04:24 +00:00
|
|
|
|
|
|
|
private bool _notFound;
|
|
|
|
private bool _confirmDelete;
|
2021-07-03 12:19:53 +00:00
|
|
|
|
2021-07-08 10:41:20 +00:00
|
|
|
private enum Editing
|
|
|
|
{
|
|
|
|
Summary,
|
|
|
|
DtStart,
|
|
|
|
CalculatedEnd,
|
|
|
|
Description,
|
|
|
|
}
|
|
|
|
|
|
|
|
private Editing? _editing;
|
|
|
|
|
2021-07-03 12:19:53 +00:00
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
{
|
2021-07-05 19:50:58 +00:00
|
|
|
_calendar = await Data.CalendarService.GetCalendarById(CalendarId);
|
|
|
|
_event = await _calendar.GetEventByUid(EventUid);
|
2021-07-05 22:04:24 +00:00
|
|
|
_notFound = _event == null;
|
2021-07-05 19:50:58 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 22:04:24 +00:00
|
|
|
private async Task UpdateEvent()
|
2021-07-05 19:50:58 +00:00
|
|
|
{
|
|
|
|
_event = await _calendar.UpdateEvent(_event);
|
2021-07-08 10:41:20 +00:00
|
|
|
_editing = null;
|
2021-07-03 12:19:53 +00:00
|
|
|
}
|
2021-07-05 22:04:24 +00:00
|
|
|
|
|
|
|
private async Task DeleteEvent()
|
|
|
|
{
|
|
|
|
if (!_confirmDelete)
|
|
|
|
{
|
|
|
|
_confirmDelete = true;
|
|
|
|
await Task.Delay(2000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await _calendar.DeleteEvent(_event);
|
|
|
|
_navigationManager.NavigateTo($"/calendars/{CalendarId}");
|
|
|
|
}
|
|
|
|
|
|
|
|
_confirmDelete = false;
|
|
|
|
}
|
2021-07-03 12:19:53 +00:00
|
|
|
}
|