Skip to content

Commit

Permalink
Added flight details to the aircraft lookup dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalker5 committed Sep 28, 2023
1 parent 0bad720 commit 76c22a5
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public AirLabsActiveFlightApi(ITrackerLogger logger, ITrackerHttpClient client,
{ ApiProperty.FlightIATA, apiResponse!["flight_iata"]?.GetValue<string>() ?? "" },
{ ApiProperty.FlightICAO, apiResponse!["flight_icao"]?.GetValue<string>() ?? "" }
};

// Log the properties dictionary
LogProperties(properties!);
}
catch (Exception ex)
{
Expand Down
3 changes: 3 additions & 0 deletions src/BaseStationReader.Logic/Api/AirLabs/AirLabsAircraftApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public AirLabsAircraftApi(ITrackerLogger logger, ITrackerHttpClient client, stri
{ ApiProperty.ModelIATA, apiResponse!["iata"]?.GetValue<string>() ?? "" },
{ ApiProperty.ModelICAO, apiResponse!["icao"]?.GetValue<string>() ?? "" }
};

// Log the properties dictionary
LogProperties(properties!);
}
catch (Exception ex)
{
Expand Down
3 changes: 3 additions & 0 deletions src/BaseStationReader.Logic/Api/AirLabs/AirLabsAirlinesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public AirLabsAirlinesApi(ITrackerLogger logger, ITrackerHttpClient client, stri
{ ApiProperty.AirlineICAO, apiResponse!["icao_code"]?.GetValue<string>() ?? "" },
{ ApiProperty.AirlineName, apiResponse!["name"]?.GetValue<string>() ?? "" },
};

// Log the properties dictionary
LogProperties(properties!);
}
catch (Exception ex)
{
Expand Down
18 changes: 17 additions & 1 deletion src/BaseStationReader.UI/Models/AircraftLookupModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AircraftLookupModel(ITrackerLogger logger, TrackerApplicationSettings set
/// Look up the details of the specified aircraft
/// </summary>
/// <param name="address"></param>
public AircraftDetails? Search(string? address)
public AircraftDetails? LookupAircraft(string? address)
{
AircraftDetails? details = null;

Expand All @@ -56,5 +56,21 @@ public AircraftLookupModel(ITrackerLogger logger, TrackerApplicationSettings set

return details;
}

/// <summary>
/// Look for active flights for the aircraft with the specified ICAO address
/// </summary>
/// <param name="address"></param>
public FlightDetails? LookupActiveFlight(string? address)
{
FlightDetails? details = null;

if (!string.IsNullOrEmpty(address))
{
details = Task.Run(() => _lookupManager.LookupActiveFlight(address)).Result;
}

return details;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ public AircraftLookupWindowViewModel(ITrackerLogger logger, TrackerApplicationSe
}

/// <summary>
/// Search for the specified aircraft address
/// Search for the specified aircraft
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public AircraftDetails? Search(string? address)
=> _aircraftLookup.Search(address);
public AircraftDetails? LookupAircraft(string? address)
=> _aircraftLookup.LookupAircraft(address);

/// <summary>
/// Search for an active flight for the specified aircraft
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public FlightDetails? LookupActiveFlight(string? address)
=> _aircraftLookup.LookupActiveFlight(address);
}
}
15 changes: 12 additions & 3 deletions src/BaseStationReader.UI/Views/AircraftLookupWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,40 @@
x:Class="BaseStationReader.UI.AircraftLookupWindow"
x:DataType="vm:AircraftLookupWindowViewModel"
Icon="/Assets/aircraft.png"
Title="Aircraft Lookup"
Title="Aircraft and Flight Details"
Loaded="OnLoaded"
WindowStartupLocation="CenterOwner"
SizeToContent="WidthAndHeight">
<DockPanel Margin="10 10 10 10">
<Grid ColumnDefinitions="Auto, Auto" RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto">
<Grid ColumnDefinitions="Auto, Auto, Auto, Auto" RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto">
<Label Grid.Row="0" Grid.Column="0" Margin="0 0 10 10">ICAO Address:</Label>
<TextBox Grid.Row="0" Grid.Column="1" Name="Address" Margin="0 0 10 10"/>

<Label Grid.Row="1" Grid.Column="0" Margin="0 0 10 10">Airline:</Label>
<TextBlock Grid.Row="1" Grid.Column="1" Name="AirlineName" Margin="0 0 10 10"/>

<Label Grid.Row="1" Grid.Column="2" Margin="0 0 10 10">Flight Number:</Label>
<TextBlock Grid.Row="1" Grid.Column="3" Name="FlightNumber" Margin="0 0 10 10"/>

<Label Grid.Row="2" Grid.Column="0" Margin="0 0 10 10">Manufacturer:</Label>
<TextBlock Grid.Row="2" Grid.Column="1" Name="ManufacturerName" Margin="0 0 10 10"/>

<Label Grid.Row="2" Grid.Column="2" Margin="0 0 10 10">Departure:</Label>
<TextBlock Grid.Row="2" Grid.Column="3" Name="DepartureIATA" Margin="0 0 10 10"/>

<Label Grid.Row="3" Grid.Column="0" Margin="0 0 10 10">Manufacturer:</Label>
<TextBlock Grid.Row="3" Grid.Column="1" Name="ModelName" Margin="0 0 10 10"/>

<Label Grid.Row="3" Grid.Column="2" Margin="0 0 10 10">Destination:</Label>
<TextBlock Grid.Row="3" Grid.Column="3" Name="DestinationIATA" Margin="0 0 10 10"/>

<Label Grid.Row="4" Grid.Column="0" Margin="0 0 10 10">IATA:</Label>
<TextBlock Grid.Row="4" Grid.Column="1" Name="ModelIATA" Margin="0 0 10 10"/>

<Label Grid.Row="5" Grid.Column="0" Margin="0 0 10 10">ICAO:</Label>
<TextBlock Grid.Row="5" Grid.Column="1" Name="ModelICAO" Margin="0 0 10 10"/>

<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="1" Margin="0 10 0 0">
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="4" Margin="0 10 0 0">
<Button Click="OnLookup">Lookup</Button>
<Button Margin="10 0 0 0" Command="{Binding CloseCommand}">Close</Button>
</StackPanel>
Expand Down
53 changes: 37 additions & 16 deletions src/BaseStationReader.UI/Views/AircraftLookupWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void OnLoaded(object? source, RoutedEventArgs e)
Address.Text = ViewModel?.Address ?? "";
if (!string.IsNullOrEmpty(Address.Text))
{
LookupAircraftDetails();
LookupAircraftAndFlightDetails();
}
}

Expand All @@ -40,38 +40,59 @@ private void OnLoaded(object? source, RoutedEventArgs e)
/// <param name="e"></param>
private void OnLookup(object source, RoutedEventArgs e)
{
LookupAircraftDetails();
LookupAircraftAndFlightDetails();
}

/// <summary>
/// Look up the aircraft details and populate the dialog with the results
/// Look up the aircraft and active flight details and populate the dialog with the results
/// </summary>
private void LookupAircraftDetails()
private void LookupAircraftAndFlightDetails()
{
// Search for the current ICAO address
// Set a busy cursor
var originalCursor = Cursor;
Cursor = new Cursor(StandardCursorType.Wait);
var details = ViewModel!.Search(Address.Text);
Cursor = originalCursor;

// Check we have some valid details
if (details != null)
// Search for the current ICAO address
var aircraftDetails = ViewModel!.LookupAircraft(Address.Text);
var flightDetails = ViewModel!.LookupActiveFlight(Address.Text);

// Do we have valid aircraft details?
if (aircraftDetails != null)
{
// Result is valid, so populate the text blocks with the aircraft details
AirlineName.Text = details.Airline?.Name ?? DetailsNotAvailableText;
ManufacturerName.Text = details.Model?.Manufacturer.Name ?? DetailsNotAvailableText;
ModelName.Text = details.Model?.Name ?? DetailsNotAvailableText;
ModelIATA.Text = details.Model?.IATA ?? DetailsNotAvailableText;
ModelICAO.Text = details.Model?.ICAO ?? DetailsNotAvailableText;
// Aircraft details are valid, so populate the text blocks with the aircraft details
AirlineName.Text = aircraftDetails.Airline?.Name ?? DetailsNotAvailableText;
ManufacturerName.Text = aircraftDetails.Model?.Manufacturer.Name ?? DetailsNotAvailableText;
ModelName.Text = aircraftDetails.Model?.Name ?? DetailsNotAvailableText;
ModelIATA.Text = aircraftDetails.Model?.IATA ?? DetailsNotAvailableText;
ModelICAO.Text = aircraftDetails.Model?.ICAO ?? DetailsNotAvailableText;
}
else
{
// No details availables, so set the default "not available" text
// No details available, so set the default "not available" text
AirlineName.Text = DetailsNotAvailableText;
ManufacturerName.Text = DetailsNotAvailableText;
ModelName.Text = DetailsNotAvailableText;
ModelIATA.Text = DetailsNotAvailableText;
ModelICAO.Text = DetailsNotAvailableText;
}

// Do we have valid flight details?
if (aircraftDetails != null)
{
// Flight details are valid, so populate the text blocks with the flight details
FlightNumber.Text = flightDetails?.FlightNumberIATA ?? DetailsNotAvailableText;
DepartureIATA.Text = flightDetails?.DepartureAirportIATA ?? DetailsNotAvailableText;
DestinationIATA.Text = flightDetails?.DestinationAirportIATA ?? DetailsNotAvailableText;
}
else
{
// No details available, so set the default "not available" text
FlightNumber.Text = DetailsNotAvailableText;
DepartureIATA.Text = DetailsNotAvailableText;
DestinationIATA.Text = DetailsNotAvailableText;
}

// Restore the cursor
Cursor = originalCursor;
}
}

0 comments on commit 76c22a5

Please sign in to comment.