-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the initial Flight Finder Sample (with stylecop formatting applied).
References #27.
- Loading branch information
Showing
47 changed files
with
2,233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
public class Class1 | ||
{ | ||
public Class1() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// <copyright file="AirportsList.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
// these files except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed | ||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
// </copyright> | ||
|
||
namespace FlightFinder.Client.Components | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using FlightFinder.Shared; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// A component that displays a list of airpoirts. | ||
/// </summary> | ||
public partial class AirportsList | ||
{ | ||
/// <summary> | ||
/// An array of airports. | ||
/// </summary> | ||
private Airport[] airports = Array.Empty<Airport>(); | ||
|
||
/// <summary> | ||
/// Gets or Sets The Http Client to use. | ||
/// </summary> | ||
[Inject] | ||
public HttpClient Http { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes this component. Gets the list of airports from the api. | ||
/// </summary> | ||
/// <returns>The list of airports.</returns> | ||
protected override async Task OnInitializedAsync() | ||
{ | ||
this.airports = await this.Http.GetJsonAsync<Airport[]>("api/airports"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<datalist id="airports"> | ||
@foreach (var airport in airports) | ||
{ | ||
<option value="@airport.Code">@airport.DisplayName (@airport.Code)</option> | ||
} | ||
</datalist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// <copyright file="GreyOutZone.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
// these files except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed | ||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
// </copyright> | ||
|
||
namespace FlightFinder.Client.Components | ||
{ | ||
using Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// A component that places its child content in a Greyed Out zone. | ||
/// </summary> | ||
public partial class GreyOutZone | ||
{ | ||
/// <summary> | ||
/// Gets or sets the Child content for a GreyOutZone. | ||
/// </summary> | ||
[Parameter] | ||
public RenderFragment ChildContent { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the Child content is Greyed Out. | ||
/// </summary> | ||
[Parameter] | ||
public bool IsGreyedOut { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="@(IsGreyedOut ? "greyout" : null)"> | ||
<div class="cover"></div> | ||
@ChildContent | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// <copyright file="Search.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
// these files except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed | ||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
// </copyright> | ||
|
||
namespace FlightFinder.Client.Components | ||
{ | ||
using FlightFinder.Shared; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Search Component. | ||
/// </summary> | ||
public partial class Search | ||
{ | ||
/// <summary> | ||
/// The search criteria that will be returned. | ||
/// </summary> | ||
private readonly SearchCriteria criteria = new SearchCriteria("LHR", "SEA"); | ||
|
||
/// <summary> | ||
/// Gets or sets the callback that will provide the search criteria for a search. | ||
/// </summary> | ||
[Parameter] | ||
public EventCallback<SearchCriteria> OnSearch { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<div class="col"> | ||
<!-- Airport selection --> | ||
<div class="row py-1"> | ||
<!-- From airport --> | ||
<div class="col pr-0"> | ||
<div class="form-control d-flex"> | ||
<div><i>✈</i> From:</div> | ||
<input list="airports" placeholder="..." @bind="criteria.FromAirport" /> | ||
</div> | ||
</div> | ||
<div class="col px-2 py-1 align-self-end arrow">➝</div> | ||
|
||
<!-- To airport --> | ||
<div class="col pl-0"> | ||
<div class="form-control d-flex"> | ||
<div><i>✈</i> To:</div> | ||
<input list="airports" placeholder="..." @bind="criteria.ToAirport" /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Departure / return dates --> | ||
<div class="row py-1"> | ||
<!-- Depart date --> | ||
<div class="col pr-0"> | ||
<div class="form-control d-flex"> | ||
<div><i>🗓</i> Depart:</div> | ||
<input type="date" @bind="criteria.OutboundDate" @bind:format="yyyy-MM-dd" /> | ||
</div> | ||
</div> | ||
<div class="col px-2 py-1 align-self-end arrow">➝</div> | ||
|
||
<!-- Return date --> | ||
<div class="col pl-0"> | ||
<div class="form-control d-flex"> | ||
<div><i>🗓</i> Return:</div> | ||
<input type="date" @bind="criteria.ReturnDate" @bind:format="yyyy-MM-dd" /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Class / search --> | ||
<div class="row py-1 d-flex px-3"> | ||
<div> | ||
<select class="custom-select" @bind="criteria.TicketClass"> | ||
<option value=@TicketClass.Economy>Economy</option> | ||
<option value=@TicketClass.PremiumEconomy>Premium Economy</option> | ||
<option value=@TicketClass.Business>Business</option> | ||
<option value=@TicketClass.First>First</option> | ||
</select> | ||
</div> | ||
<div class="ml-auto"> | ||
<button @onclick="() => OnSearch.InvokeAsync(criteria)" type="button" class="btn btn-danger px-5"> | ||
Search ➝ | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
<AirportsList /> |
38 changes: 38 additions & 0 deletions
38
samples/FlightFinder.Client/Components/SearchResultFlightSegment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// <copyright file="SearchResultFlightSegment.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
// these files except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed | ||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
// </copyright> | ||
|
||
namespace FlightFinder.Client.Components | ||
{ | ||
using FlightFinder.Shared; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// Displays a flight segment of a search result. | ||
/// </summary> | ||
public partial class SearchResultFlightSegment | ||
{ | ||
/// <summary> | ||
/// Gets or sets the Symbol. | ||
/// </summary> | ||
[Parameter] | ||
public string Symbol { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the flight information. | ||
/// </summary> | ||
[Parameter] | ||
public FlightSegment Flight { get; set; } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
samples/FlightFinder.Client/Components/SearchResultFlightSegment.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="symbol"> | ||
@Symbol | ||
</div> | ||
|
||
<div class="airline"> | ||
@Flight.Airline | ||
<small>@Flight.TicketClass.ToDisplayString()</small> | ||
</div> | ||
|
||
<div class="departure"> | ||
<h4>@Flight.DepartureTime.ToShortTimeString()</h4> | ||
@Flight.DepartureTime.ToString("ddd MMM d") (@Flight.FromAirportCode) | ||
</div> | ||
|
||
<div class="arrow">➝</div> | ||
|
||
<div class="return"> | ||
<h4>@Flight.ReturnTime.ToShortTimeString()</h4> | ||
@Flight.ReturnTime.ToString("ddd MMM d") (@Flight.ToAirportCode) | ||
</div> | ||
|
||
<div class="duration"> | ||
@Flight.DurationHours hours | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// <copyright file="SearchResults.cs" company=".NET Foundation"> | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
// these files except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed | ||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
// </copyright> | ||
|
||
namespace FlightFinder.Client.Components | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FlightFinder.Shared; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
/// <summary> | ||
/// A component that displays a search result. | ||
/// </summary> | ||
public partial class SearchResults | ||
{ | ||
/// <summary> | ||
/// The sort order enumeration. | ||
/// </summary> | ||
private enum SortOrder | ||
{ | ||
/// <summary> | ||
/// Sort the Itineraries on price. | ||
/// </summary> | ||
Price, | ||
|
||
/// <summary> | ||
/// Sort the Itineraries on duration. | ||
/// </summary> | ||
Duration, | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the Itinerary. | ||
/// </summary> | ||
// Parameters | ||
[Parameter] | ||
public IReadOnlyList<Itinerary> Itineraries { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a callback that is called when the Itinerary is added. | ||
/// </summary> | ||
[Parameter] | ||
public EventCallback<Itinerary> OnAddItinerary { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the sport order of the Search Results. | ||
/// </summary> | ||
private SortOrder ChosenSortOder { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the list of sorted Itineraries. | ||
/// </summary> | ||
private IEnumerable<Itinerary> SortedItineraries | ||
=> this.ChosenSortOder == SortOrder.Price | ||
? this.Itineraries.OrderBy(x => x.Price) | ||
: this.Itineraries.OrderBy(x => x.TotalDurationHours); | ||
} | ||
} |
Oops, something went wrong.