SPARK-697 trade ticket when brought up to modify an order should not have a cancel order button

This commit is contained in:
John Colvin committed 2018-03-26 11:51:55 -04:00
1 parent 46f4163e5c
commit c30f3afdfd
2 files changed
+43 -20

No files matched your search

@@ -14,6 +14,7 @@ namespace mbts.spark {
readonly Property<TimeInForce> _current_time_in_force;
readonly Property<CustomOrderDefinition.CustomOneofCase> _current_order_type;
readonly DelegateProperty<bool> _price_dirty, _size_dirty, _account_dirty, _time_in_force_dirty, _order_type_dirty;
IDisposable _modify_enabled_sub;
public ExistingOrderTicketVM(OrdersModel model, IObservable<OrderRecordTuple> order_source, IObservable<int[]> calculator_buttons)
: base(model, order_source.Where(ot => ot.security_md.HasValue).Select(ot => ot.security_md.Value.security),
@@ -41,7 +42,7 @@ namespace mbts.spark {
Observable.Merge(_price_dirty, _size_dirty, _account_dirty, _time_in_force_dirty, _order_type_dirty)
.ObserveOnDispatcher().Subscribe(_ => RaisePropertyChanged(nameof(dirty_items_text)))
);
modify_order = new DelegateCommand(() => {
var modify_order = new ObservantCommand(() => {
if (key.HasValue) {
_price_dirty.refresh();
_size_dirty.refresh();
@@ -61,12 +62,14 @@ namespace mbts.spark {
RequestClose?.Invoke(this, new EventArgs());
}
});
cancel_order = new DelegateCommand(() => {
if (key.HasValue) {
model.cancel_order(key.Value).ignore();
RequestClose?.Invoke(this, new EventArgs());
}
});
var price_dirty_source = _price_dirty.Select(vals => vals.newval).StartWith(false);
var size_dirty_source = _size_dirty.Select(vals => vals.newval).StartWith(false);
_modify_enabled_sub = price_dirty_source
.CombineLatest(size_dirty_source, (pd, sd) => pd || sd)
.DistinctUntilChanged()
.ObserveOnDispatcher()
.Subscribe(modify_order);
this.modify_order = modify_order;
}
public event EventHandler RequestClose;
@@ -81,13 +84,29 @@ namespace mbts.spark {
public override bool? account_dirty => _account_dirty.Value;
public override bool? time_in_force_dirty => _time_in_force_dirty.Value;
public override bool? order_type_dirty => _order_type_dirty.Value;
public string dirty_items_text => string.Join(", ", _dirty_items());
public string dirty_items_text {
get {
var dirty_items = _dirty_items().ToList();
if (dirty_items.Count == 0)
return "(no changes)";
else return "changes " + string.Join(", ", dirty_items);
}
}
public bool can_change_account { get; } = false;
public bool can_change_time_in_force { get; } = false;
public bool can_change_order_type { get; } = false;
public BBOVM bbo { get; }
public ICommand modify_order { get; }
public ICommand cancel_order { get; }
protected override void _on_price_changed(double value) => _price_dirty.refresh();
protected override void _on_size_changed(uint? value) => _size_dirty.refresh();
protected override void _on_selected_account_changed(string value) => _account_dirty.refresh();
protected override void _on_selected_time_in_force_changed(TimeInForce value) => _time_in_force_dirty.refresh();
protected override void _on_selected_order_type_changed(IOrderTypeVM value) => _order_type_dirty.refresh();
protected override void Dispose(bool disposing) {
Disposable.dispose(ref _modify_enabled_sub);
base.Dispose(disposing);
}
IEnumerable<string> _dirty_items() {
if (_price_dirty.Value) yield return "price";
@@ -96,10 +115,5 @@ namespace mbts.spark {
if (_time_in_force_dirty.Value) yield return "tif";
if (_order_type_dirty.Value) yield return "type";
}
protected override void _on_price_changed(double value) => _price_dirty.refresh();
protected override void _on_size_changed(uint? value) => _size_dirty.refresh();
protected override void _on_selected_account_changed(string value) => _account_dirty.refresh();
protected override void _on_selected_time_in_force_changed(TimeInForce value) => _time_in_force_dirty.refresh();
protected override void _on_selected_order_type_changed(IOrderTypeVM value) => _order_type_dirty.refresh();
}
}
@@ -35,22 +35,31 @@
</Grid.ColumnDefinitions>
<usp:OrderModificationControl Grid.ColumnSpan="3"/>
<Button
Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
MinHeight="40" Foreground="Red" FontWeight="Bold" Command="{Binding cancel_order}"
Grid.Row="2"
Command="ApplicationCommands.Close"
FontWeight="Bold"
IsCancel="True"
MinHeight="40"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<TextBlock TextWrapping="Wrap">Cancel Order</TextBlock>
Cancel
</Button>
<Button
Grid.Row="2" Grid.Column="2" MinHeight="40"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Grid.Row="2"
Grid.Column="2"
Command="{Binding modify_order}"
IsDefault="True"
MinHeight="40"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Center" FontWeight="Bold">Modify</TextBlock>
<TextBlock HorizontalAlignment="Center" FontWeight="Bold">OK</TextBlock>
<TextBlock
Grid.Row="1" HorizontalAlignment="Center" Margin="0,2,0,0" FontSize="9" Text="{Binding dirty_items_text}"
Visibility="{Binding dirty_items_text, Converter={StaticResource DirtyItemsVisibilityConverter}}"