2021-07-03 12:19:53 +00:00
|
|
|
@page "/"
|
|
|
|
|
|
|
|
@using BlazorApp.Data
|
|
|
|
@inject CalendarService _calendarService
|
|
|
|
|
|
|
|
@if (_calendars == null)
|
|
|
|
{
|
|
|
|
<p>
|
|
|
|
<em>Loading...</em>
|
|
|
|
</p>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<h1>Calendars</h1>
|
|
|
|
<ul>
|
|
|
|
@foreach (var calendar in _calendars)
|
|
|
|
{
|
|
|
|
<li>
|
|
|
|
<a href="/calendars/@calendar.Id">@calendar.Name</a>
|
2021-07-04 10:28:21 +00:00
|
|
|
(
|
|
|
|
<a href="#" @onclick="() => DeleteCalendar(calendar)">
|
2021-07-04 10:16:51 +00:00
|
|
|
@if (_confirmDeleteId == calendar.Id)
|
|
|
|
{
|
2021-07-04 10:28:21 +00:00
|
|
|
@:Confirm deletion?
|
2021-07-04 10:16:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<span class="oi oi-x"></span>
|
|
|
|
}
|
2021-07-04 10:28:21 +00:00
|
|
|
</a>
|
|
|
|
)
|
2021-07-03 12:19:53 +00:00
|
|
|
</li>
|
|
|
|
}
|
|
|
|
</ul>
|
|
|
|
|
2021-07-04 10:16:51 +00:00
|
|
|
@if (_calendarModel != null)
|
2021-07-03 12:19:53 +00:00
|
|
|
{
|
|
|
|
<h2>Add New Calendar</h2>
|
2021-07-04 10:16:51 +00:00
|
|
|
|
|
|
|
<EditForm Model="@_calendarModel" OnValidSubmit="@HandleValidSubmit">
|
2021-07-04 10:28:21 +00:00
|
|
|
<DataAnnotationsValidator/>
|
|
|
|
<ValidationSummary/>
|
|
|
|
|
2021-07-03 12:19:53 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<label for="url">URL</label>
|
2021-07-04 10:28:21 +00:00
|
|
|
<InputText id="url" class="form-control" placeholder="Enter URL" @bind-Value="_calendarModel.Url"/>
|
2021-07-03 12:19:53 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-group">
|
|
|
|
<label for="username">Username</label>
|
2021-07-04 10:28:21 +00:00
|
|
|
<InputText
|
2021-07-04 10:16:51 +00:00
|
|
|
id="username" class="form-control" placeholder="Enter username"
|
2021-07-04 10:28:21 +00:00
|
|
|
@bind-Value="_calendarModel.Username"/>
|
2021-07-03 12:19:53 +00:00
|
|
|
</div>
|
2021-07-04 10:16:51 +00:00
|
|
|
|
2021-07-03 12:19:53 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<label for="password">Password</label>
|
2021-07-04 10:16:51 +00:00
|
|
|
<InputText
|
|
|
|
type="password" id="password" class="form-control" placeholder="Enter password"
|
2021-07-04 10:28:21 +00:00
|
|
|
@bind-Value="_calendarModel.Password"/>
|
2021-07-03 12:19:53 +00:00
|
|
|
</div>
|
2021-07-04 10:16:51 +00:00
|
|
|
|
2021-07-03 12:19:53 +00:00
|
|
|
<div class="form-group">
|
|
|
|
<label for="name">Name</label>
|
2021-07-04 10:16:51 +00:00
|
|
|
<InputText
|
|
|
|
type="text" id="name" class="form-control" placeholder="Enter name"
|
2021-07-04 10:28:21 +00:00
|
|
|
@bind-Value="_calendarModel.Name"/>
|
2021-07-03 12:19:53 +00:00
|
|
|
</div>
|
2021-07-04 10:16:51 +00:00
|
|
|
|
2021-07-03 12:19:53 +00:00
|
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
|
|
</EditForm>
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
<button class="btn btn-primary" @onclick="ShowAddCalendar">Add Calendar</button>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@code
|
|
|
|
{
|
|
|
|
private List<Data.Calendar> _calendars;
|
2021-07-04 10:16:51 +00:00
|
|
|
private int? _confirmDeleteId = null;
|
|
|
|
private Data.Calendar _calendarModel = null;
|
2021-07-03 12:19:53 +00:00
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
{
|
|
|
|
_calendars = await CalendarService.GetCalendars();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ShowAddCalendar()
|
|
|
|
{
|
2021-07-04 10:16:51 +00:00
|
|
|
_calendarModel = new Data.Calendar();
|
2021-07-03 12:19:53 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 10:16:51 +00:00
|
|
|
private async Task HandleValidSubmit()
|
2021-07-03 12:19:53 +00:00
|
|
|
{
|
2021-07-04 10:16:51 +00:00
|
|
|
await CalendarService.CreateCalendar(_calendarModel);
|
|
|
|
_calendarModel = null;
|
|
|
|
_calendars = await CalendarService.GetCalendars();
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task DeleteCalendar(Data.Calendar calendar)
|
|
|
|
{
|
|
|
|
if (_confirmDeleteId != calendar.Id)
|
|
|
|
{
|
|
|
|
_confirmDeleteId = calendar.Id;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await CalendarService.DeleteCalendar(calendar);
|
|
|
|
_calendars = await CalendarService.GetCalendars();
|
|
|
|
_confirmDeleteId = null;
|
2021-07-03 12:19:53 +00:00
|
|
|
}
|
|
|
|
}
|