Imported Upstream version 6.6.0.89

Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-09-24 08:53:40 +00:00
parent cf815e07e0
commit 95fdb59ea6
2556 changed files with 138145 additions and 47453 deletions

View File

@@ -0,0 +1,83 @@
@page "/checkout"
@inject OrderState OrderState
@inject HttpClient HttpClient
@inject IUriHelper UriHelper
@inject IJSRuntime JSRuntime
<div class="main">
<AuthorizeView Context="authContext">
<NotAuthorized>
<h2>Redirecting you...</h2>
</NotAuthorized>
<Authorized>
<EditForm Model="@OrderState.Order.DeliveryAddress" OnValidSubmit="@PlaceOrder">
<div class="checkout-cols">
<div class="checkout-order-details">
<h4>Review order</h4>
<OrderReview Order="@OrderState.Order" />
</div>
<div class="checkout-delivery-address">
<h4>Deliver to...</h4>
<AddressEditor Address="@OrderState.Order.DeliveryAddress" />
</div>
</div>
<button type="submit" class="checkout-button btn btn-warning" disabled="@isSubmitting">
Place order
</button>
<DataAnnotationsValidator />
</EditForm>
</Authorized>
</AuthorizeView>
</div>
@functions {
bool isSubmitting;
[CascadingParameter] Task<AuthenticationState> AuthenticationStateTask { get; set; }
protected override async Task OnInitAsync()
{
var authState = await AuthenticationStateTask;
if (!authState.User.Identity.IsAuthenticated)
{
// The server won't accept orders from unauthenticated users, so avoid
// an error by making them log in at this point
await LocalStorage.SetAsync(JSRuntime, "currentorder", OrderState.Order);
UriHelper.NavigateTo("user/signin?redirectUri=/checkout", true);
}
// Try to recover any temporary saved order
if (!OrderState.Order.Pizzas.Any())
{
var savedOrder = await LocalStorage.GetAsync<Order>(JSRuntime, "currentorder");
if (savedOrder != null)
{
OrderState.ReplaceOrder(savedOrder);
await LocalStorage.DeleteAsync(JSRuntime, "currentorder");
}
else
{
// There's nothing check out - go to home
UriHelper.NavigateTo("");
}
}
}
async Task PlaceOrder()
{
isSubmitting = true;
try
{
var newOrderId = await HttpClient.PostJsonAsync<int>("orders", OrderState.Order);
OrderState.ResetOrder();
UriHelper.NavigateTo($"myorders/{newOrderId}");
}
finally
{
isSubmitting = false;
}
}
}

View File

@@ -0,0 +1,74 @@
@page "/"
@inject HttpClient HttpClient
@inject OrderState OrderState
@inject IUriHelper UriHelper
@inject IJSRuntime JS
<div class="main">
<ul class="pizza-cards">
@if (specials != null)
{
@foreach (var special in specials)
{
<li @onclick="@(() => OrderState.ShowConfigurePizzaDialog(special))" style="background-image: url('@special.ImageUrl')">
<div class="pizza-info">
<span class="title">@special.Name</span>
@special.Description
<span class="price">@special.GetFormattedBasePrice()</span>
</div>
</li>
}
}
</ul>
</div>
<div class="sidebar">
@if (Order.Pizzas.Any())
{
<div class="order-contents">
<h2>Your order</h2>
@foreach (var configuredPizza in Order.Pizzas)
{
<ConfiguredPizzaItem Pizza="configuredPizza" OnRemoved="@(() => RemovePizza(configuredPizza))" />
}
</div>
}
else
{
<div class="empty-cart">Choose a pizza<br>to get started</div>
}
<div class="order-total @(Order.Pizzas.Any() ? "" : "hidden")">
Total:
<span class="total-price">@Order.GetFormattedTotalPrice()</span>
<a href="checkout" class="btn btn-warning" disabled="@(Order.Pizzas.Count == 0)">
Order >
</a>
</div>
</div>
<TemplatedDialog Show="OrderState.ShowingConfigureDialog">
<ConfigurePizzaDialog
Pizza="OrderState.ConfiguringPizza"
OnCancel="OrderState.CancelConfigurePizzaDialog"
OnConfirm="OrderState.ConfirmConfigurePizzaDialog" />
</TemplatedDialog>
@functions {
List<PizzaSpecial> specials;
Order Order => OrderState.Order;
protected async override Task OnInitAsync()
{
specials = await HttpClient.GetJsonAsync<List<PizzaSpecial>>("specials");
}
async Task RemovePizza(Pizza configuredPizza)
{
if (await JS.Confirm($"Remove {configuredPizza.Special.Name} pizza from the order?"))
{
OrderState.RemoveConfiguredPizza(configuredPizza);
}
}
}

View File

@@ -0,0 +1,37 @@
@page "/myorders"
@inject HttpClient HttpClient
@attribute [Authorize]
<div class="main">
<TemplatedList Loader="@LoadOrders" ListGroupClass="orders-list">
<LoadingContent>Loading...</LoadingContent>
<EmptyContent>
<h2>No orders placed</h2>
<a class="btn btn-success" href="">Order some pizza</a>
</EmptyContent>
<ItemContent Context="item">
<div class="col">
<h5>@item.Order.CreatedTime.ToLongDateString()</h5>
Items:
<strong>@item.Order.Pizzas.Count()</strong>;
Total price:
<strong>£@item.Order.GetFormattedTotalPrice()</strong>
</div>
<div class="col">
Status: <strong>@item.StatusText</strong>
</div>
<div class="col flex-grow-0">
<a href="myorders/@item.Order.OrderId" class="btn btn-success">
Track &gt;
</a>
</div>
</ItemContent>
</TemplatedList>
</div>
@functions {
async Task<List<OrderWithStatus>> LoadOrders()
{
return await HttpClient.GetJsonAsync<List<OrderWithStatus>>("orders");
}
}

View File

@@ -0,0 +1,83 @@
@page "/myorders/{orderId:int}"
@using System.Threading
@inject HttpClient HttpClient
@implements IDisposable
@attribute [Authorize]
<div class="main">
@if (invalidOrder)
{
<h2>Nope</h2>
<p>Sorry, this order could not be loaded.</p>
}
else if (orderWithStatus == null)
{
<text>Loading...</text>
}
else
{
<div class="track-order">
<div class="track-order-title">
<h2>
Order placed @orderWithStatus.Order.CreatedTime.ToLongDateString()
</h2>
<p class="ml-auto mb-0">
Status: <strong>@orderWithStatus.StatusText</strong>
</p>
</div>
<div class="track-order-body">
<div class="track-order-details">
<OrderReview Order="@orderWithStatus.Order" />
</div>
<div class="track-order-map">
<Map Zoom="13" Markers="@orderWithStatus.MapMarkers" />
</div>
</div>
</div>
}
</div>
@functions {
[Parameter] int OrderId { get; set; }
OrderWithStatus orderWithStatus;
bool invalidOrder;
CancellationTokenSource pollingCancellationToken;
protected override void OnParametersSet()
{
// If we were already polling for a different order, stop doing so
pollingCancellationToken?.Cancel();
// Start a new poll loop
PollForUpdates();
}
void IDisposable.Dispose()
{
pollingCancellationToken?.Cancel();
}
private async void PollForUpdates()
{
pollingCancellationToken = new CancellationTokenSource();
while (!pollingCancellationToken.IsCancellationRequested)
{
try
{
invalidOrder = false;
orderWithStatus = await HttpClient.GetJsonAsync<OrderWithStatus>($"orders/{OrderId}");
}
catch (Exception ex)
{
invalidOrder = true;
pollingCancellationToken.Cancel();
Console.Error.WriteLine(ex);
}
StateHasChanged();
await Task.Delay(4000);
}
}
}

View File

@@ -0,0 +1 @@
@layout MainLayout