added GlobalAlertsView/VM
This commit is contained in:
1 parent
d1960850e8
commit
8de1fa00aa
10 files changed
+540
No files matched your search
@@ -0,0 +1,39 @@
|
||||
<Window
|
||||
x:Class="mbts.ui.spark.GlobalAlertsDialog"
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
Content="{Binding}"
|
||||
Title="Alerts"
|
||||
Style="{StaticResource BTSDialog}"
|
||||
>
|
||||
<Window.ContentTemplate>
|
||||
<DataTemplate DataType="{x:Type usp:GlobalAlertsVM}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<usp:GlobalAlertsView/>
|
||||
<c:DialogSkirt Grid.Row="1" Padding="{StaticResource DialogSkirtPadding}">
|
||||
<c:DialogSkirt.RightItems>
|
||||
<x:Array Type="{x:Type Button}">
|
||||
<Button Margin="{StaticResource DialogSkirtButtonMargin}" Command="{Binding apply_cmd}">
|
||||
Apply
|
||||
</Button>
|
||||
<Button Margin="{StaticResource DialogSkirtButtonMargin}" Command="{Binding ok_cmd}" IsDefault="True">
|
||||
OK
|
||||
</Button>
|
||||
<Button Margin="{StaticResource DialogSkirtButtonMargin}" Command="{x:Static ApplicationCommands.Close}" IsCancel="True">
|
||||
Cancel
|
||||
</Button>
|
||||
</x:Array>
|
||||
</c:DialogSkirt.RightItems>
|
||||
</c:DialogSkirt>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</Window.ContentTemplate>
|
||||
</Window>
|
||||
@@ -0,0 +1,14 @@
|
||||
using mbts.ui.utility;
|
||||
using System.Windows;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
/// <summary>
|
||||
/// Interaction logic for GlobalAlertsDialog.xaml
|
||||
/// </summary>
|
||||
partial class GlobalAlertsDialog : Window {
|
||||
public GlobalAlertsDialog() {
|
||||
InitializeComponent();
|
||||
WindowUtilities.listen_for_close_requests(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
<UserControl
|
||||
x:Class="mbts.ui.spark.GlobalAlertsView"
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mbts="clr-namespace:mbts"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:stg="clr-namespace:mbts.ui.settings"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
>
|
||||
<Grid>
|
||||
<Grid.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/view/Controls/DIYGrid/Settings/Animation/SoundAnimationView.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<sys:Double x:Key="SecurityWidth">130</sys:Double>
|
||||
<sys:Double x:Key="DoublePredicateWidth">210</sys:Double>
|
||||
<sys:Double x:Key="SideWidth">100</sys:Double>
|
||||
<sys:Double x:Key="SoundWidth">163</sys:Double>
|
||||
<Thickness x:Key="CellPadding">10,8</Thickness>
|
||||
<!--Converters-->
|
||||
<cv:AppendTextConverter x:Key="DropDownSharedSizeGroupConverter" Suffix="_DropDownWidth"/>
|
||||
<AlternationConverter x:Key="AlternatingBackgroundConverter">
|
||||
<SolidColorBrush Color="{u:BTSColor Grid.input_cell_background}"/>
|
||||
<SolidColorBrush Color="{u:BTSColor Grid.alternate_row_background}"/>
|
||||
</AlternationConverter>
|
||||
<!--Styles-->
|
||||
<Style x:Key="DisabledColumnHeader" TargetType="GridViewColumnHeader">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="GridViewColumnHeader">
|
||||
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{x:Static u:BTSColors.header_brush}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<!--Data Templates-->
|
||||
<DataTemplate x:Key="DoublePredicateTypeTemplate">
|
||||
<TextBlock Text="{Binding Converter={x:Static usp:GlobalAlertsView.DoublePredicateTypeDisplayNameConverter}}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="ColumnHeaderTemplate">
|
||||
<TextBlock Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="None"/>
|
||||
<DataTemplate x:Key="DisabledTickUpDown">
|
||||
<c:TickUpDown IsEnabled="False">
|
||||
<TextBlock Foreground="Gray" Margin="4,0,0,0">(N/A)</TextBlock>
|
||||
</c:TickUpDown>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="TickUpDownDouble">
|
||||
<c:TickUpDownDouble Value="{Binding}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="DoubleMinimum" DataType="{x:Type sp:DoublePredicateVM}">
|
||||
<c:TickUpDownDouble Value="{Binding minimum}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="DoubleMaximum" DataType="{x:Type sp:DoublePredicateVM}">
|
||||
<c:TickUpDownDouble Value="{Binding maximum}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="DoubleRange" DataType="{x:Type sp:DoublePredicateVM}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:TickUpDownDouble Value="{Binding minimum}"/>
|
||||
<TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="2,0" Text="and"/>
|
||||
<c:TickUpDownDouble Grid.Column="2" Value="{Binding maximum}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type sp:DoublePredicateVM}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="{Binding Path='(c:DIYGrid.ColumnKey)', RelativeSource={RelativeSource AncestorType=ContentControl}, Converter={StaticResource DropDownSharedSizeGroupConverter}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox ItemsSource="{u:EnumBindingSource {u:Nested mbts:DoublePredicate.PredicateTypeOneofCase}}" SelectedItem="{Binding type}" ItemTemplate="{StaticResource DoublePredicateTypeTemplate}"/>
|
||||
<ContentControl Grid.Column="1" Margin="6,0,0,0" Content="{Binding}">
|
||||
<ContentControl.ContentTemplate>
|
||||
<Binding Path="type">
|
||||
<Binding.Converter>
|
||||
<cv:ValueMap>
|
||||
<cv:KeyValue Key="{x:Static None, MemberType={u:Nested mbts:DoublePredicate.PredicateTypeOneofCase}}" Value="{StaticResource DisabledTickUpDown}"/>
|
||||
<cv:KeyValue Key="{x:Static LessThan, MemberType={u:Nested mbts:DoublePredicate.PredicateTypeOneofCase}}" Value="{StaticResource DoubleMaximum}"/>
|
||||
<cv:KeyValue Key="{x:Static GreaterThan, MemberType={u:Nested mbts:DoublePredicate.PredicateTypeOneofCase}}" Value="{StaticResource DoubleMinimum}"/>
|
||||
<cv:KeyValue Key="{x:Static InsideRange, MemberType={u:Nested mbts:DoublePredicate.PredicateTypeOneofCase}}" Value="{StaticResource DoubleRange}"/>
|
||||
<cv:KeyValue Key="{x:Static OutsideRange, MemberType={u:Nested mbts:DoublePredicate.PredicateTypeOneofCase}}" Value="{StaticResource DoubleRange}"/>
|
||||
</cv:ValueMap>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</ContentControl.ContentTemplate>
|
||||
</ContentControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type stg:SoundAnimationVM}">
|
||||
<c:SoundAnimationView Bus="{DynamicResource Bus}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type sys:Boolean}">
|
||||
<CheckBox IsChecked="{Binding}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="SecurityCriteriaTemplate">
|
||||
<c:ContractPickerPopup
|
||||
c:DIYGrid.ColumnKey="Security"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
AllowEmpty="True"
|
||||
CloseOnOK="True"
|
||||
CloseOnCancel="True"
|
||||
MaxWidth="180"
|
||||
DataContext="{Binding predicate}"
|
||||
SecurityMap="{Binding DataContext.security_map, RelativeSource={RelativeSource AncestorType=usp:GlobalAlertsView}}"
|
||||
Header="{Binding security_criteria}"
|
||||
ShowDialogSkirt="True"
|
||||
ToolTip="{Binding security_criteria, Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}, Mode=OneWay}"
|
||||
OKClick="{x:Static c:ContractPickerPopup.FlushSelectedCriteriaHandler}"
|
||||
SelectedCriteria="{Binding security_criteria, UpdateSourceTrigger=Explicit}"
|
||||
>
|
||||
<c:ContractPickerPopup.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}}" TextTrimming="CharacterEllipsis"/>
|
||||
</DataTemplate>
|
||||
</c:ContractPickerPopup.HeaderTemplate>
|
||||
</c:ContractPickerPopup>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type usp:TradeAlertsVM}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<c:DIYGrid
|
||||
Grid.Row="0"
|
||||
Grid.IsSharedSizeScope="True"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="1"
|
||||
Rows="{Binding alerts}"
|
||||
RowsHorizontalScrollBarVisibility="Collapsed"
|
||||
SelectionMode="Single"
|
||||
>
|
||||
<c:DIYGrid.Columns>
|
||||
<c:DIYGridColumnCollection>
|
||||
<usp:GlobalAlertsColumn key="Delete" HeaderContainerStyle="{StaticResource DisabledColumnHeader}" Width="23" is_visible="True"/>
|
||||
<usp:GlobalAlertsColumn key="IsEnabled" HeaderContainerStyle="{StaticResource DisabledColumnHeader}" Width="66" is_visible="True"/>
|
||||
<usp:GlobalAlertsColumn key="Security" Header="Security" Width="{StaticResource SecurityWidth}" is_visible="True"/>
|
||||
<usp:GlobalAlertsColumn key="Price" Header="Price Condition" Width="{StaticResource DoublePredicateWidth}" is_visible="True"/>
|
||||
<usp:GlobalAlertsColumn key="Quantity" Header="Size Condition" Width="{StaticResource DoublePredicateWidth}" is_visible="True"/>
|
||||
<usp:GlobalAlertsColumn key="Side" Header="Side" Width="{StaticResource SideWidth}" is_visible="True"/>
|
||||
<usp:GlobalAlertsColumn key="Sound" Header="Sound" Width="{StaticResource SoundWidth}" is_visible="True"/>
|
||||
</c:DIYGridColumnCollection>
|
||||
</c:DIYGrid.Columns>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate DataType="{x:Type usp:TradeAlertVM}">
|
||||
<Grid c:DIYGrid.SyncWithColumnGeometry="True">
|
||||
<Button
|
||||
c:DIYGrid.ColumnKey="Delete"
|
||||
HorizontalAlignment="Center"
|
||||
Command="{Binding DataContext.delete_alert_cmd, RelativeSource={RelativeSource AncestorType=c:DIYGrid}}"
|
||||
CommandParameter="{Binding}"
|
||||
Style="{StaticResource RoundCloseButton}"
|
||||
ToolTip="Delete"
|
||||
/>
|
||||
<ToggleButton c:DIYGrid.ColumnKey="IsEnabled" IsChecked="{Binding is_enabled}" Style="{StaticResource ToggleSwitch}"/>
|
||||
<c:ContractPickerPopup
|
||||
c:DIYGrid.ColumnKey="Security"
|
||||
Grid.Column="0"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
AllowEmpty="True"
|
||||
CloseOnOK="True"
|
||||
CloseOnCancel="True"
|
||||
MaxWidth="180"
|
||||
DataContext="{Binding predicate}"
|
||||
SecurityMap="{Binding DataContext.security_map, RelativeSource={RelativeSource AncestorType=usp:GlobalAlertsView}}"
|
||||
Header="{Binding security_criteria}"
|
||||
ShowDialogSkirt="True"
|
||||
ToolTip="{Binding security_criteria, Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}, Mode=OneWay}"
|
||||
OKClick="{x:Static c:ContractPickerPopup.FlushSelectedCriteriaHandler}"
|
||||
SelectedCriteria="{Binding security_criteria, UpdateSourceTrigger=Explicit}"
|
||||
>
|
||||
<c:ContractPickerPopup.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}}" TextTrimming="CharacterEllipsis"/>
|
||||
</DataTemplate>
|
||||
</c:ContractPickerPopup.HeaderTemplate>
|
||||
</c:ContractPickerPopup>
|
||||
<ContentControl c:DIYGrid.ColumnKey="Price" Margin="{StaticResource CellPadding}" Content="{Binding predicate.price}"/>
|
||||
<ContentControl c:DIYGrid.ColumnKey="Quantity" Margin="{StaticResource CellPadding}" Content="{Binding predicate.quantity}"/>
|
||||
<ComboBox
|
||||
c:DIYGrid.ColumnKey="Side"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
ItemsSource="{Binding predicate.side_options}"
|
||||
SelectedItem="{Binding predicate.side}"
|
||||
ItemTemplate="{StaticResource EnumFlagsDescriptionTemplate}"
|
||||
/>
|
||||
<Grid c:DIYGrid.ColumnKey="Sound" Margin="{StaticResource CellPadding}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox
|
||||
ItemsSource="{Binding sound.system_sound_options}"
|
||||
SelectedItem="{Binding sound.system_sound}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
HorizontalAlignment="Stretch"
|
||||
/>
|
||||
<Button
|
||||
Grid.Column="1"
|
||||
Margin="4,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
Command="{x:Static c:SoundAnimationView.PreviewSoundCommand}"
|
||||
CommandParameter="{Binding sound.system_sound}"
|
||||
Style="{StaticResource RoundPlayButton}"
|
||||
/>
|
||||
</Grid>
|
||||
<Rectangle Grid.Column="0" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="1" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="2" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="3" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="4" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="5" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
<TextBlock Grid.Row="1" HorizontalAlignment="Left" Margin="4,8">
|
||||
<Hyperlink Command="{Binding add_alert_cmd}">
|
||||
Click to Add Alert
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
<!--<DataTemplate DataType-->
|
||||
</ResourceDictionary>
|
||||
</Grid.Resources>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TabControl>
|
||||
<TabItem Header="Trade Alerts" Content="{Binding trade_alerts}">
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,41 @@
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.utilities;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
/// <summary>
|
||||
/// Interaction logic for ShellSettingsDialog.xaml
|
||||
/// </summary>
|
||||
partial class GlobalAlertsView : UserControl {
|
||||
public static readonly IValueConverter
|
||||
DoublePredicateTypeDisplayNameConverter = ValueConverter.create<DoublePredicate.PredicateTypeOneofCase, string>(t => {
|
||||
switch (t) {
|
||||
case DoublePredicate.PredicateTypeOneofCase.InsideRange: return "Between";
|
||||
case DoublePredicate.PredicateTypeOneofCase.OutsideRange: return "Not Between";
|
||||
case DoublePredicate.PredicateTypeOneofCase.None: return "(None)";
|
||||
default: return DisplayNameHelper.camel_to_title_case(t.ToString());
|
||||
}
|
||||
});
|
||||
|
||||
public GlobalAlertsView() =>
|
||||
InitializeComponent();
|
||||
|
||||
public enum Columns {
|
||||
None = 0,
|
||||
Delete,
|
||||
IsEnabled,
|
||||
Security,
|
||||
Price,
|
||||
Quantity,
|
||||
Side,
|
||||
Sound
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalAlertsColumn : DIYGrid.ColumnBase<GlobalAlertsView.Columns> {
|
||||
protected override void on_key_initialized(GlobalAlertsView.Columns key) =>
|
||||
id = key.ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using mbts.spark;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
class GlobalAlertsVM : ViewModelBase, IValueFactory<GlobalAlertSettings>, IRequestViewClose {
|
||||
IReadOnlyDictionary<uint, SecurityMD> _security_map = DictionaryHelper.empty<uint, SecurityMD>();
|
||||
|
||||
public GlobalAlertsVM() {
|
||||
ok_cmd = new DelegateCommand(() => {
|
||||
apply();
|
||||
RequestClose?.Invoke(this, EventArgs.Empty);
|
||||
});
|
||||
apply_cmd = new DelegateCommand(apply);
|
||||
void apply() =>
|
||||
request_commit?.Invoke();
|
||||
}
|
||||
|
||||
public event Action request_commit;
|
||||
public event EventHandler RequestClose;
|
||||
|
||||
public TradeAlertsVM trade_alerts { get; } = new TradeAlertsVM();
|
||||
public ICommand apply_cmd { get; }
|
||||
public ICommand ok_cmd { get; }
|
||||
|
||||
public IReadOnlyDictionary<uint, SecurityMD> security_map {
|
||||
get => _security_map;
|
||||
set {
|
||||
_security_map = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public GlobalAlertSettings create() =>
|
||||
new GlobalAlertSettings(trade_alerts.create().ToArray());
|
||||
|
||||
public void load_from(GlobalAlertSettings value) {
|
||||
trade_alerts.load_from(value.trade_alerts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using bts.shell;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mbts.spark {
|
||||
class SoundNotificationVM : DisposableViewModelBase {
|
||||
SoundNotification.SystemSound _system_sound;
|
||||
|
||||
public SoundNotificationVM() {
|
||||
}
|
||||
|
||||
public SoundNotification.SystemSound system_sound { get => _system_sound; set => Set(ref _system_sound, value); }
|
||||
public IReadOnlyList<SoundNotification.SystemSound> system_sound_options => EnumHelper.get_values<SoundNotification.SystemSound>();
|
||||
|
||||
public SoundNotification create() =>
|
||||
new SoundNotification {
|
||||
system_sound = system_sound
|
||||
};
|
||||
|
||||
public void load_from(SoundNotification value) {
|
||||
switch (value.sound_type_case) {
|
||||
case SoundNotification.SoundTypeOneofCase.System: system_sound = value.system_sound.Value; break;
|
||||
case SoundNotification.SoundTypeOneofCase.Uri: /*todo*/ break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using bts.api;
|
||||
using mbts.spark;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
class TradeAlertPredicateVM : ViewModelBase, IValueFactory<TradeAlertPredicate> {
|
||||
SecurityCriteria _security_criteria;
|
||||
Side _side;
|
||||
|
||||
public SecurityCriteria security_criteria { get => _security_criteria; set => Set(ref _security_criteria, value); }
|
||||
public DoublePredicateVM price { get; } = new DoublePredicateVM();
|
||||
public DoublePredicateVM quantity { get; } = new DoublePredicateVM();
|
||||
public Side side { get => _side; set => Set(ref _side, value); }
|
||||
public IEnumerable<Side> side_options {
|
||||
get {
|
||||
yield return Side.Buy;
|
||||
yield return Side.Sell;
|
||||
yield return Side.Buy | Side.Sell;
|
||||
}
|
||||
}
|
||||
|
||||
public void load_from(TradeAlertPredicate value) {
|
||||
security_criteria = value.security_criteria;
|
||||
quantity.load_from(value.quantity);
|
||||
price.load_from(value.price);
|
||||
side = value.side.Aggregate(Side.Undefined, (flags, s) => flags | s);
|
||||
}
|
||||
|
||||
public TradeAlertPredicate create() =>
|
||||
new TradeAlertPredicate(
|
||||
security_criteria,
|
||||
quantity.create(),
|
||||
price.create(),
|
||||
EnumHelper.split_flags(side).ToArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using mbts.spark;
|
||||
using mbts.ui.shell;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
class TradeAlertVM : ViewModelBase, IValueFactory<TradeAlert> {
|
||||
bool _is_enabled;
|
||||
|
||||
public TradeAlertPredicateVM predicate { get; } = new TradeAlertPredicateVM();
|
||||
public SoundNotificationVM sound { get; } = new SoundNotificationVM();
|
||||
public bool is_enabled { get => _is_enabled; set => Set(ref _is_enabled, value); }
|
||||
|
||||
public TradeAlert create() =>
|
||||
new TradeAlert(
|
||||
predicate.create(),
|
||||
sound.create(),
|
||||
is_enabled);
|
||||
|
||||
public void load_from(TradeAlert value) {
|
||||
predicate.load_from(value.predicate);
|
||||
sound.load_from(value.sound);
|
||||
is_enabled = value.is_enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using bts.api;
|
||||
using bts.shell;
|
||||
using mbts.spark;
|
||||
using mbts.ui.shell;
|
||||
using mbts.utils;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
class TradeAlertsVM : ViewModelBase, IValueFactory<IReadOnlyList<TradeAlert>> {
|
||||
public TradeAlertsVM() {
|
||||
add_alert_cmd = new DelegateCommand(() => {
|
||||
var a = new TradeAlertVM();
|
||||
a.load_from(_default_alert());
|
||||
alerts.Add(a);
|
||||
});
|
||||
delete_alert_cmd = new DelegateCommand<TradeAlertVM>(a => alerts.Remove(a));
|
||||
}
|
||||
|
||||
public ObservableCollection<TradeAlertVM> alerts { get; } = new ObservableCollection<TradeAlertVM>();
|
||||
|
||||
public ICommand add_alert_cmd { get; }
|
||||
public ICommand delete_alert_cmd { get; }
|
||||
|
||||
public IReadOnlyList<TradeAlert> create() =>
|
||||
alerts.Select(a => a.create()).ToList();
|
||||
|
||||
public void load_from(IReadOnlyList<TradeAlert> value) =>
|
||||
alerts.sync_with_models(value);
|
||||
|
||||
static TradeAlert _default_alert() =>
|
||||
new TradeAlert(
|
||||
new TradeAlertPredicate(side: new[] { Side.Buy, Side.Sell }),
|
||||
new SoundNotification {
|
||||
system_sound = SoundNotification.SystemSound.BellCounter
|
||||
},
|
||||
true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
using mbts.collections;
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
class TradeSoundsVM : DisposableViewModelBase {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user