SPARK-620 - Contract Picker's world view can now be filterd via a SecurityCriteria
This commit is contained in:
1 parent
6cfc519d2d
commit
e59587a0ea
3 files changed
+49
-11
No files matched your search
@@ -24,6 +24,7 @@ namespace bts {
|
||||
_bus = bus;
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.ShowPickOne).ObserveOnDispatcher().Subscribe(show_pick_one),
|
||||
bus.subscribe(SparkTags.FilterPickOne).ObserveOnDispatcher().Subscribe(show_filtered_pick_one),
|
||||
bus.subscribe(SparkTags.ShowPickMultiple).ObserveOnDispatcher().Subscribe(show_pick_multiple),
|
||||
bus.subscribe(SparkTags.ShowAndEditPickMultiple).ObserveOnDispatcher().Subscribe(show_and_edit_pick_multiple)
|
||||
);
|
||||
@@ -52,6 +53,29 @@ namespace bts {
|
||||
picker.Show();
|
||||
}
|
||||
|
||||
void show_filtered_pick_one((PartialCommand<SecurityMD> message, SecurityCriteria global_filter) message_and_filter) {
|
||||
var vm = new ContractPickerModel(_bus, false, null, message_and_filter.global_filter);
|
||||
var view = new ContractPickerView(vm);
|
||||
|
||||
Window picker = new Window {
|
||||
Content = view,
|
||||
Title = $"Select a Security for {message_and_filter.message.title}",
|
||||
Icon = message_and_filter.message.icon,
|
||||
Height = view.Height,
|
||||
Width = view.Width
|
||||
};
|
||||
picker.Style = picker.TryFindResource("BTSWindow") as Style;
|
||||
view.Height = Double.NaN;
|
||||
view.Width = Double.NaN;
|
||||
|
||||
vm.ok_action = () => {
|
||||
picker.Close();
|
||||
message_and_filter.message.complete(vm.result).execute(_bus);
|
||||
};
|
||||
picker.move_to_mouse();
|
||||
picker.Show();
|
||||
}
|
||||
|
||||
void show_pick_multiple(PartialCommand<SecurityCriteria> message) {
|
||||
var vm = new ContractPickerModel(_bus, true, null);
|
||||
var view = new ContractPickerView(vm);
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace mbts.spark
|
||||
public static ITag<(PartialCommand<SecurityCriteria>, SecurityCriteria)> ShowAndEditPickMultiple { get; } = new SparkTag<(PartialCommand<SecurityCriteria>, SecurityCriteria)>("EditPickN");
|
||||
public static ITag<PartialCommand<SecurityCriteria>> ShowPickMultiple { get; } = new SparkTag<PartialCommand<SecurityCriteria>>("PickN");
|
||||
public static ITag<PartialCommand<SecurityMD>> ShowPickOne { get; } = new SparkTag<PartialCommand<SecurityMD>>("Pick1");
|
||||
public static ITag<(PartialCommand<SecurityMD>, SecurityCriteria)> FilterPickOne { get; } = new SparkTag<(PartialCommand<SecurityMD>, SecurityCriteria)>("FilterPick1");
|
||||
|
||||
public static ITag<IShellWindow> ShowWindow { get; } = new SparkTag<IShellWindow>("Show Window");
|
||||
public static ITag<Nothing> ShowWorkspaces { get; } = new SparkTag<Nothing>(nameof(ShowWorkspaces));
|
||||
|
||||
@@ -29,12 +29,13 @@ namespace mbts.spark
|
||||
|
||||
private const string dot = "•";
|
||||
|
||||
public ContractPickerModel(IBus bus, bool edit_mode, SecurityCriteria existing_criteria) {
|
||||
public ContractPickerModel(IBus bus, bool edit_mode, SecurityCriteria existing_criteria, SecurityCriteria world_view_filter = null) {
|
||||
_bus = bus;
|
||||
if (existing_criteria?.clauses?.Length > 0) {
|
||||
security_criteria_clauses.AddRange(existing_criteria.clauses);
|
||||
}
|
||||
is_edit_mode = edit_mode;
|
||||
_world_view_filter = world_view_filter;
|
||||
securities_view = CollectionViewSource.GetDefaultView(securities);
|
||||
(securities_view as ListCollectionView).CustomSort = new SecuritySorter();
|
||||
_subs.Add(_bus.subscribe(SecuritiesTag).ObserveOnDispatcher().Subscribe(on_securities_changed));
|
||||
@@ -203,10 +204,20 @@ namespace mbts.spark
|
||||
}
|
||||
|
||||
private void on_securities_changed(IReadOnlyDictionary<uint, SecurityMD> changed_securities) {
|
||||
all_securities = changed_securities;
|
||||
securities.sync_with(changed_securities
|
||||
if (_world_view_filter != null) {
|
||||
all_securities = changed_securities
|
||||
.Where(x => security_in_criteria(_world_view_filter, x.Value.security))
|
||||
.ToReadOnlyDictionary(x => x.Key, v => v.Value);
|
||||
} else {
|
||||
all_securities = changed_securities;
|
||||
}
|
||||
|
||||
securities.sync_with(all_securities
|
||||
.Select(entry => entry.Value.security)
|
||||
);
|
||||
|
||||
_update_security_types();
|
||||
_update_symbols();
|
||||
_update_securities();
|
||||
}
|
||||
internal void criteria_selection_changed(IEnumerable<SecurityCriteriaClause> selected_clauses) {
|
||||
@@ -280,6 +291,8 @@ namespace mbts.spark
|
||||
}
|
||||
}
|
||||
|
||||
private SecurityCriteria _world_view_filter;
|
||||
|
||||
public Action ok_action { get; set; }
|
||||
public Action cancel_action { get; set; }
|
||||
|
||||
@@ -303,21 +316,21 @@ namespace mbts.spark
|
||||
}
|
||||
|
||||
private void _update_security_types() {
|
||||
security_types.sync_with(UserSymbol.get_all()
|
||||
security_types.sync_with(all_securities
|
||||
.Where(s => selected_exchanges
|
||||
.Any(exchange => exchange == s.exchange))
|
||||
.Select(s => s.type)
|
||||
.Distinct()
|
||||
.Any(exchange => exchange == s.Value.security.Exchange))
|
||||
.Select(s => s.Value.security.security_type())
|
||||
.Distinct()
|
||||
);
|
||||
}
|
||||
|
||||
private void _update_symbols() {
|
||||
symbols.sync_with(UserSymbol.get_all()
|
||||
symbols.sync_with(all_securities
|
||||
.Where(s => selected_exchanges
|
||||
.Any(exchange => exchange == s.exchange))
|
||||
.Any(exchange => exchange == s.Value.security.Exchange))
|
||||
.Where( s => selected_security_types
|
||||
.Any(s_type => s_type == s.type))
|
||||
.Select(s => s.symbol)
|
||||
.Any(s_type => s_type == s.Value.security.security_type()))
|
||||
.Select(s => s.Value.security.Symbol)
|
||||
.Distinct()
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user