Skip to content

Commit

Permalink
Merge pull request #104 from opensky-to/job-payload-distances
Browse files Browse the repository at this point in the history
Added support for my jobs distances
  • Loading branch information
sushiat authored Dec 20, 2023
2 parents 615c594 + 82285c3 commit 22c1045
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
20 changes: 19 additions & 1 deletion OpenSky.Client/Converters/PayloadDistanceConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
if (value is Payload payload)
{
if (!string.IsNullOrWhiteSpace(payload.AirportICAO))
if (!string.IsNullOrEmpty(payload.AirportICAO))
{
var airportPackage = AirportPackageClientHandler.GetPackage();
var origin = airportPackage?.Airports.SingleOrDefault(a => a.ICAO == payload.AirportICAO);
Expand All @@ -73,6 +73,24 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
return distance;
}
}

if (!string.IsNullOrEmpty(payload.AircraftRegistry))
{
var airportPackage = AirportPackageClientHandler.GetPackage();
var destination = airportPackage?.Airports.SingleOrDefault(a => a.ICAO == payload.DestinationICAO);

if (destination != null)
{
var distance = new GeoCoordinate(payload.AircraftLatitude ?? 0, payload.AircraftLongitude ?? 0).GetDistanceTo(new GeoCoordinate(destination.Latitude, destination.Longitude)) / 1852;

if (targetType == typeof(string))
{
return new SettingsUnitConverter().Convert(distance, typeof(string), "distance|F0|true", CultureInfo.CurrentCulture);
}

return distance;
}
}
}

if (targetType == typeof(string))
Expand Down
12 changes: 12 additions & 0 deletions OpenSky.Client/OpenAPIs/swagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13698,6 +13698,18 @@ public enum OnlineNetwork
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")]
public partial class Payload
{
/// <summary>
/// Gets or sets the aircraft latitude (if currently loaded onto an aircraft).
/// </summary>
[Newtonsoft.Json.JsonProperty("aircraftLatitude", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double? AircraftLatitude { get; set; }

/// <summary>
/// Gets or sets the aircraft longitude (if currently loaded onto an aircraft).
/// </summary>
[Newtonsoft.Json.JsonProperty("aircraftLongitude", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double? AircraftLongitude { get; set; }

/// <summary>
/// Gets or sets the aircraft registry the payload is currently loaded on, or NULL if stored at an airport.
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions OpenSky.Client/OpenAPIs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8798,6 +8798,18 @@
],
"type": "object",
"properties": {
"aircraftLatitude": {
"type": "number",
"description": "Gets or sets the aircraft latitude (if currently loaded onto an aircraft).",
"format": "double",
"nullable": true
},
"aircraftLongitude": {
"type": "number",
"description": "Gets or sets the aircraft longitude (if currently loaded onto an aircraft).",
"format": "double",
"nullable": true
},
"aircraftRegistry": {
"maxLength": 12,
"minLength": 6,
Expand Down
3 changes: 3 additions & 0 deletions OpenSky.Client/Pages/MyJobs.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</CollectionViewSource>
<converters:SettingsUnitConverter x:Key="SettingsUnitConverter" />
<converters:JobTypeConverter x:Key="JobCategoryConverter" />
<converters:PayloadDistanceConverter x:Key="PayloadDistanceConverter" />
</UserControl.Resources>
<UserControl.InputBindings>
<KeyBinding Key="F5" Command="{Binding RefreshJobsCommand}" />
Expand Down Expand Up @@ -89,6 +90,7 @@
<DataGridTemplateColumn Header="Value" CellTemplate="{StaticResource JobValueCellTemplate}" SortMemberPath="Value" CanUserSort="True" dgx:DataGridFilterColumn.Template="{StaticResource MinMaxDoubleFilterWithPopupControl}" />
<DataGridTemplateColumn Header="Expires" CellTemplate="{StaticResource JobExpiryCellTemplate}" SortMemberPath="ExpiresAt" CanUserSort="True" />
<DataGridTextColumn Header="Weight" Binding="{Binding TotalWeight, Converter={StaticResource SettingsUnitConverter}, ConverterParameter=weight|F1|true}" dgx:DataGridFilterColumn.Template="{StaticResource MinMaxDoubleFilterWithPopupControlWeight}" />
<DataGridTextColumn Header="Max distance" Binding="{Binding MaxDistance, Converter={StaticResource SettingsUnitConverter}, ConverterParameter=distance|F0|true}" dgx:DataGridFilterColumn.Template="{StaticResource MinMaxDoubleFilterWithPopupControlDistance}" />
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate DataType="openSkyApi:Job">
Expand All @@ -99,6 +101,7 @@
>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding LocationDestinationInfo}" FontFamily="Consolas" />
<DataGridTextColumn Binding="{Binding .,Converter={StaticResource PayloadDistanceConverter}}" />
<DataGridTextColumn Binding="{Binding Weight, Converter={StaticResource SettingsUnitConverter}, ConverterParameter=weight|F1|true}" Width="Auto" />
<DataGridTextColumn Binding="{Binding Description}" />
</DataGrid.Columns>
Expand Down
4 changes: 2 additions & 2 deletions OpenSky.Client/Pages/Notifications.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
ItemsSource="{Binding Recipients}"
AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" SelectionMode="Single" SelectionUnit="FullRow"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" MinColumnWidth="80" HeadersVisibility="Column" Margin="30,20,0,40"
ColumnHeaderStyle="{StaticResource FilteredDataGridColumnHeaderStyle}" CellStyle="{StaticResource FullRowSelectDataGridCellStyle}">
ColumnHeaderStyle="{StaticResource FilteredDataGridColumnHeaderStyle}" CellStyle="{StaticResource FullRowSelectDataGridCellStyle}" MaxHeight="500">
<DataGrid.Resources>
<converters:BooleanToImageConverter x:Key="BooleanToImageConverter" />
<DataTemplate x:Key="ClientPickupCellTemplate" DataType="{x:Type openSkyApi:GroupedNotificationRecipient}">
Expand Down Expand Up @@ -155,7 +155,7 @@
ItemsSource="{Binding Recipients}"
AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" SelectionMode="Single" SelectionUnit="FullRow"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" MinColumnWidth="80" HeadersVisibility="Column" Margin="30,20,0,40"
ColumnHeaderStyle="{StaticResource FilteredDataGridColumnHeaderStyle}" CellStyle="{StaticResource FullRowSelectDataGridCellStyle}">
ColumnHeaderStyle="{StaticResource FilteredDataGridColumnHeaderStyle}" CellStyle="{StaticResource FullRowSelectDataGridCellStyle}" MaxHeight="200">
<DataGrid.Resources>
<converters:BooleanToImageConverter x:Key="BooleanToImageConverter" />
<DataTemplate x:Key="ClientPickupCellTemplate" DataType="{x:Type openSkyApi:GroupedNotificationRecipient}">
Expand Down
4 changes: 2 additions & 2 deletions OpenSky.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyVersion("0.5.8")]
[assembly: AssemblyFileVersion("0.5.8")]
[assembly: AssemblyVersion("0.5.9")]
[assembly: AssemblyFileVersion("0.5.9")]

// This allows us to detect debug mode in XAML
#if DEBUG
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
OpenSky Client Changelog
======================================================================================

--------------------------------------------------------------------------------------
Version 0.5.9 (ALPHA5)
--------------------------------------------------------------------------------------
- Fixed max grid height in notifications page
- Added distance information to "My jobs" page

--------------------------------------------------------------------------------------
Version 0.5.8 (ALPHA5)
--------------------------------------------------------------------------------------
Expand Down

0 comments on commit 22c1045

Please sign in to comment.