132 lines
5.1 KiB
C#
132 lines
5.1 KiB
C#
using DTS.Common.Base;
|
|
using DTS.Common.Events;
|
|
using DTS.Common.Interactivity;
|
|
using DTS.Common.Interface;
|
|
using Prism.Events;
|
|
using Prism.Regions;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Unity;
|
|
|
|
namespace DTS.Viewer.PSDReportSettings
|
|
{
|
|
public class PSDReportSettingsViewModel : BaseViewModel<IPSDReportSettingsModel>, IPSDReportSettingsViewModel
|
|
{
|
|
public IBaseView View { get; set; }
|
|
//public bool Standalone { get; set; }
|
|
|
|
public IBaseViewModel Parent { get; set; }
|
|
|
|
private IPSDReportSettingsModel _model;
|
|
public new IPSDReportSettingsModel Model { get => _model; set { _model = value; OnPropertyChanged("Model"); } }
|
|
private IEventAggregator _eventAggregator { get; set; }
|
|
private IUnityContainer _unityContainer { get; set; }
|
|
|
|
public InteractionRequest<Notification> NotificationRequest { get; private set; }
|
|
public new InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
|
|
/// <summary>
|
|
/// Creates a new instance of the MainViewModel.
|
|
/// </summary>
|
|
|
|
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
|
|
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
|
|
/// <param name="unityContainer">The Unity container.</param>
|
|
public PSDReportSettingsViewModel(IPSDReportSettingsView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
|
|
: base(regionManager, eventAggregator, unityContainer)
|
|
{
|
|
View = view;
|
|
View.DataContext = this;
|
|
|
|
NotificationRequest = new InteractionRequest<Notification>();
|
|
ConfirmationRequest = new InteractionRequest<Confirmation>();
|
|
|
|
_eventAggregator = eventAggregator;
|
|
_unityContainer = unityContainer;
|
|
}
|
|
|
|
#region Methods
|
|
|
|
public override void Initialize()
|
|
{
|
|
|
|
}
|
|
|
|
public override void Initialize(object parameter)
|
|
{
|
|
Parent = (IBaseViewModel)parameter;
|
|
|
|
Subscribe();
|
|
Model = _unityContainer.Resolve<IPSDReportSettingsModel>();
|
|
Model.Parent = this;
|
|
//View.DataContext = Model;
|
|
}
|
|
|
|
private void Subscribe()
|
|
{
|
|
//_eventAggregator.GetEvent<CursorsAlailableChangedEvent>().Subscribe(OnCursorsAlailableChanged);
|
|
_eventAggregator.GetEvent<GraphSelectedChannelsNotification>().Subscribe(OnGraphSelectedChannelsChanged);
|
|
_eventAggregator.GetEvent<GraphClearNotification>().Subscribe(OnGraphCleared);
|
|
_eventAggregator.GetEvent<ChartAxisChangedEvent>().Subscribe(OnChartAxisChanged);
|
|
}
|
|
|
|
|
|
|
|
private void OnChartAxisChanged(ChartAxisChangedEventArg arg)
|
|
{
|
|
if (arg?.ParentVM != Parent) return;
|
|
|
|
switch (arg.Axis)
|
|
{
|
|
case "Y":
|
|
//Model.MinFixedY = args.MinValue;
|
|
//Model.MaxFixedY = args.MaxValue;
|
|
break;
|
|
case "X":
|
|
Model.CanPublishChanges = false;
|
|
Model.DataStart = arg.MinValue;
|
|
Model.DataEnd = arg.MaxValue;
|
|
Model.CanPublishChanges = true;
|
|
PublishChanges();
|
|
break;
|
|
}
|
|
//throw new NotImplementedException();
|
|
}
|
|
private void OnGraphCleared(GraphClearNotificationArg obj)
|
|
{
|
|
//Graph's been cleared. Init our settings
|
|
Model.ReadData = false;
|
|
PublishChanges();
|
|
}
|
|
|
|
private void OnGraphSelectedChannelsChanged(GraphSelectedChannelsNotificationArg arg)
|
|
{
|
|
if (Parent != arg?.ParentVM) return;
|
|
var channels = arg.SelectedChannels;
|
|
Model.Parent = this;
|
|
|
|
//PublishChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Private Event handler for RaiseNotification event.
|
|
/// </summary>
|
|
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
|
|
{
|
|
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
|
|
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message, eventArgsWithTitle.MessageDetails, eventArgsWithTitle.Image);
|
|
|
|
NotificationRequest.Raise(new Notification
|
|
{
|
|
Content = eventArgsWithoutTitle,
|
|
Title = eventArgsWithTitle.Title
|
|
});
|
|
}
|
|
|
|
public void PublishChanges()
|
|
{
|
|
_eventAggregator.GetEvent<PSDReportSettingsChangedEvent>().Publish(new PSDReportSettingsChangedEventArg() { Model = Model, ParentVM = Parent });
|
|
}
|
|
#endregion
|
|
}
|
|
}
|