Skip to content

Commit

Permalink
Merge pull request #50 from #49-sell-aircraft-system
Browse files Browse the repository at this point in the history
Added sell aircraft to system method
  • Loading branch information
markus-korbel authored Dec 23, 2021
2 parents 8121d73 + e3c2a64 commit e1055e8
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!--
====================================================================================================================
<copyright file="FilterWithPopupControl.xaml" company="OpenSky">
<copyright file="MinMaxDoubleFilterWithPopupControl.xaml" company="OpenSky">
OpenSky project 2021
</copyright>
<summary>
Filter with range min/max popup control control
Filter with range min/max double popup control
</summary>
====================================================================================================================
-->

<Control x:Name="Control" x:Class="OpenSky.Client.Controls.FilterWithPopupControl"
<Control x:Name="Control" x:Class="OpenSky.Client.Controls.MinMaxDoubleFilterWithPopupControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down Expand Up @@ -37,7 +37,7 @@
</ToggleButton.Style>
<!-- Reuse the standard icon, but change color to green -->
</ToggleButton>
<Control Style="{DynamicResource {x:Static dgx:DataGridFilter.IconStyleKey}}" Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Center" />
<Control Style="{DynamicResource {x:Static dgx:DataGridFilter.IconStyleKey}}" Foreground="Gray" VerticalAlignment="Center" HorizontalAlignment="Center" IsHitTestVisible="False" />
<Popup x:Name="popup" IsOpen="{Binding Path=IsPopupVisible, ElementName=Control, Mode=TwoWay}"
AllowsTransparency="True"
DataContext="{Binding ElementName=Control}" StaysOpen="False">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FilterWithPopupControl.xaml.cs" company="OpenSky">
// <copyright file="MinMaxDoubleFilterWithPopupControl.xaml.cs" company="OpenSky">
// OpenSky project 2021
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace OpenSky.Client.Controls
{
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

using DataGridExtensions;

Expand All @@ -16,7 +18,7 @@ namespace OpenSky.Client.Controls
/// Filter with range min/max popup control control.
/// </content>
/// -------------------------------------------------------------------------------------------------
public partial class FilterWithPopupControl
public partial class MinMaxDoubleFilterWithPopupControl
{
/// -------------------------------------------------------------------------------------------------
/// <summary>
Expand All @@ -26,7 +28,7 @@ public partial class FilterWithPopupControl
public static readonly DependencyProperty CaptionProperty = DependencyProperty.Register(
"Caption",
typeof(string),
typeof(FilterWithPopupControl),
typeof(MinMaxDoubleFilterWithPopupControl),
new FrameworkPropertyMetadata("Specify the limits:", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

/// -------------------------------------------------------------------------------------------------
Expand All @@ -38,16 +40,16 @@ public partial class FilterWithPopupControl
DependencyProperty.Register(
"Filter",
typeof(IContentFilter),
typeof(FilterWithPopupControl),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, _) => ((FilterWithPopupControl)sender).FilterChanged()));
typeof(MinMaxDoubleFilterWithPopupControl),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, _) => ((MinMaxDoubleFilterWithPopupControl)sender).FilterChanged(sender)));

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The is popup visible property.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public static readonly DependencyProperty IsPopupVisibleProperty =
DependencyProperty.Register("IsPopupVisible", typeof(bool), typeof(FilterWithPopupControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
DependencyProperty.Register("IsPopupVisible", typeof(bool), typeof(MinMaxDoubleFilterWithPopupControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

/// -------------------------------------------------------------------------------------------------
/// <summary>
Expand All @@ -57,8 +59,8 @@ public partial class FilterWithPopupControl
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register(
"Maximum",
typeof(double),
typeof(FilterWithPopupControl),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, _) => ((FilterWithPopupControl)sender).RangeChanged()));
typeof(MinMaxDoubleFilterWithPopupControl),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, _) => ((MinMaxDoubleFilterWithPopupControl)sender).RangeChanged()));

/// -------------------------------------------------------------------------------------------------
/// <summary>
Expand All @@ -68,18 +70,18 @@ public partial class FilterWithPopupControl
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register(
"Minimum",
typeof(double),
typeof(FilterWithPopupControl),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, _) => ((FilterWithPopupControl)sender).RangeChanged()));
typeof(MinMaxDoubleFilterWithPopupControl),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, _) => ((MinMaxDoubleFilterWithPopupControl)sender).RangeChanged()));

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="FilterWithPopupControl"/> class.
/// Initializes a new instance of the <see cref="MinMaxDoubleFilterWithPopupControl"/> class.
/// </summary>
/// <remarks>
/// sushi.at, 23/12/2021.
/// </remarks>
/// -------------------------------------------------------------------------------------------------
public FilterWithPopupControl()
public MinMaxDoubleFilterWithPopupControl()
{
this.InitializeComponent();
}
Expand All @@ -95,6 +97,13 @@ public string Caption
set => this.SetValue(CaptionProperty, value);
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the converter parameter.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public object ConverterParameter { get; set; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the filter.
Expand Down Expand Up @@ -139,6 +148,13 @@ public double Minimum
set => this.SetValue(MinimumProperty, value);
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the value converter.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public IValueConverter ValueConverter { get; set; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Filter changed.
Expand All @@ -147,30 +163,34 @@ public double Minimum
/// sushi.at, 23/12/2021.
/// </remarks>
/// -------------------------------------------------------------------------------------------------
private void FilterChanged()
private void FilterChanged(object sender)
{
if (this.Filter is not MinMaxDoubleFilter filter)
{
return;
}

this.Minimum = filter.Min;
this.Maximum = filter.Max;
if (sender is not MinMaxDoubleFilterWithPopupControl)
{
this.Minimum = filter.Min;
this.Maximum = filter.Max;
}
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Filter range changed.
/// Filter text box on lost focus.
/// </summary>
/// <remarks>
/// sushi.at, 23/12/2021.
/// </remarks>
/// <param name="sender">
/// Source of the event.
/// </param>
/// <param name="e">
/// Routed event information.
/// </param>
/// -------------------------------------------------------------------------------------------------
private void RangeChanged()
{
this.Filter = this.Maximum != 0 || this.Minimum != 0 ? new MinMaxDoubleFilter(this.Minimum, this.Maximum) : null;
}

private void FilterTextBoxOnLostFocus(object sender, RoutedEventArgs e)
{
if (sender is TextBox textBox)
Expand All @@ -181,6 +201,45 @@ private void FilterTextBoxOnLostFocus(object sender, RoutedEventArgs e)
}
}
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Filter range changed.
/// </summary>
/// <remarks>
/// sushi.at, 23/12/2021.
/// </remarks>
/// -------------------------------------------------------------------------------------------------
private void RangeChanged()
{
if (this.Maximum != 0 || this.Minimum != 0)
{
var maximum = this.Maximum;
var minimum = this.Minimum;

if (this.ValueConverter != null)
{
var convertedMaximum = (double?)this.ValueConverter.ConvertBack($"{maximum}", typeof(double), this.ConverterParameter, CultureInfo.CurrentCulture);
var convertedMinimum = (double?)this.ValueConverter.ConvertBack($"{minimum}", typeof(double), this.ConverterParameter, CultureInfo.CurrentCulture);

if (convertedMaximum.HasValue)
{
maximum = convertedMaximum.Value;
}

if (convertedMinimum.HasValue)
{
minimum = convertedMinimum.Value;
}
}

this.Filter = new MinMaxDoubleFilter(minimum, maximum);
}
else
{
this.Filter = null;
}
}
}

/// -------------------------------------------------------------------------------------------------
Expand Down
81 changes: 81 additions & 0 deletions OpenSky.Client/OpenAPIs/swagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,87 @@ public async System.Threading.Tasks.Task<AircraftIEnumerableApiResponse> SearchA
}
}

/// <summary>Sell aircraft back to system.</summary>
/// <param name="registry">The registry of the aircraft to sell.</param>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public System.Threading.Tasks.Task<StringApiResponse> SellAircraftToSystemAsync(string registry)
{
return SellAircraftToSystemAsync(registry, System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>Sell aircraft back to system.</summary>
/// <param name="registry">The registry of the aircraft to sell.</param>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public async System.Threading.Tasks.Task<StringApiResponse> SellAircraftToSystemAsync(string registry, System.Threading.CancellationToken cancellationToken)
{
if (registry == null)
throw new System.ArgumentNullException("registry");

var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/Aircraft/sellToSystem/{registry}");
urlBuilder_.Replace("{registry}", System.Uri.EscapeDataString(ConvertToString(registry, System.Globalization.CultureInfo.InvariantCulture)));

var client_ = _httpClient;
var disposeClient_ = false;
try
{
using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false))
{
request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "text/plain");
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain"));

PrepareRequest(client_, request_, urlBuilder_);
var url_ = urlBuilder_.ToString();
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
PrepareRequest(client_, request_, url_);

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
var disposeResponse_ = true;
try
{
var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
if (response_.Content != null && response_.Content.Headers != null)
{
foreach (var item_ in response_.Content.Headers)
headers_[item_.Key] = item_.Value;
}

ProcessResponse(client_, response_);

var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync<StringApiResponse>(response_, headers_).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
}
return objectResponse_.Object;
}
else
{
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
}
}
finally
{
if (disposeResponse_)
response_.Dispose();
}
}
}
finally
{
if (disposeClient_)
client_.Dispose();
}
}

/// <summary>Updates the specified aircraft (user editable properties only)</summary>
/// <param name="body">The update aircraft.</param>
/// <returns>Success</returns>
Expand Down
43 changes: 43 additions & 0 deletions OpenSky.Client/OpenAPIs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,49 @@
}
}
},
"/Aircraft/sellToSystem/{registry}": {
"post": {
"tags": [
"Aircraft"
],
"summary": "Sell aircraft back to system.",
"description": "sushi.at, 23/12/2021.",
"operationId": "SellAircraftToSystem",
"parameters": [
{
"name": "registry",
"in": "path",
"description": "The registry of the aircraft to sell.",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/StringApiResponse"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/StringApiResponse"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/StringApiResponse"
}
}
}
}
}
}
},
"/Aircraft": {
"put": {
"tags": [
Expand Down
6 changes: 3 additions & 3 deletions OpenSky.Client/OpenSky.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Controls\Animations\MapPathAnimation.cs" />
<Compile Include="Controls\FilterWithPopupControl.xaml.cs">
<DependentUpon>FilterWithPopupControl.xaml</DependentUpon>
<Compile Include="Controls\MinMaxDoubleFilterWithPopupControl.xaml.cs">
<DependentUpon>MinMaxDoubleFilterWithPopupControl.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\ListContainsValueCheckbox.xaml.cs">
<DependentUpon>ListContainsValueCheckbox.xaml</DependentUpon>
Expand Down Expand Up @@ -287,7 +287,7 @@
<Compile Include="Views\Startup.xaml.cs">
<DependentUpon>Startup.xaml</DependentUpon>
</Compile>
<Page Include="Controls\FilterWithPopupControl.xaml">
<Page Include="Controls\MinMaxDoubleFilterWithPopupControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
Loading

0 comments on commit e1055e8

Please sign in to comment.