diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs | 84 |
1 files changed, 69 insertions, 15 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs index 2b773c1c2..e5121e709 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/MainViewVM.cs @@ -7,10 +7,13 @@ using System.Text; using System.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; +using Tango.Core.Commands; using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Messages; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; +using Tango.MachineStudio.Logging.Navigation; +using Tango.MachineStudio.Logging.Views; using Tango.SharedUI; namespace Tango.MachineStudio.Logging.ViewModels @@ -20,9 +23,9 @@ namespace Tango.MachineStudio.Logging.ViewModels private INotificationProvider _notification; private IStudioApplicationManager _application; private IEventLogger _eventLogger; - private DateVM _realTimeDate; private ObservableCollection<MachinesEvent> _realTimeEvents; private Machine _connectedMachine; + private LoggingNavigationManager _navigation; private Machine _selectedMachine; public Machine SelectedMachine @@ -45,30 +48,68 @@ namespace Tango.MachineStudio.Logging.ViewModels set { _selectedEvent = value; RaisePropertyChangedAuto(); OnSelectedEventChanged(); } } - private ObservableCollection<DateVM> _dates; - public ObservableCollection<DateVM> Dates + private ObservableCollection<DateTime> _dates; + public ObservableCollection<DateTime> Dates { get { return _dates; } set { _dates = value; RaisePropertyChangedAuto(); } } - private DateVM _selectedDate; - public DateVM SelectedDate + private DateTime _selectedDate; + public DateTime SelectedDate { get { return _selectedDate; } set { _selectedDate = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } } - public MainViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application) + private DateTime _minDate; + public DateTime MinDate { + get { return _minDate; } + set { _minDate = value; RaisePropertyChangedAuto(); } + } + + private DateTime _maxDate; + public DateTime MaxDate + { + get { return _maxDate; } + set { _maxDate = value; RaisePropertyChangedAuto(); } + } + + + private bool _isRealTime; + public bool IsRealTime + { + get { return _isRealTime; } + set { _isRealTime = value; RaisePropertyChangedAuto(); OnSelectedDateChanged(); } + } + + private TimelineViewVM _timelineViewVM; + + public TimelineViewVM TimelineViewVM + { + get { return _timelineViewVM; } + set { _timelineViewVM = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand<MachinesEvent> DisplayTimelineCommand { get; set; } + + public RelayCommand NavigateToEventsCommand { get; set; } + + public MainViewVM(INotificationProvider notification, IEventLogger eventLogger, IStudioApplicationManager application, LoggingNavigationManager navigation) + { + TimelineViewVM = new TimelineViewVM(notification); + + _navigation = navigation; _application = application; _notification = notification; _eventLogger = eventLogger; - _realTimeDate = new DateVM(DateTime.Now) { Description = "Real Time" }; _realTimeEvents = new ObservableCollection<MachinesEvent>(); _eventLogger.NewLog += _eventLogger_NewLog; RegisterMessage<MachineConnectionChangedMessage>(OnMachineConnectionChanged); + DisplayTimelineCommand = new RelayCommand<MachinesEvent>(DisplayTimeline); + NavigateToEventsCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.EventsView)); } private void OnMachineConnectionChanged(MachineConnectionChangedMessage msg) @@ -88,7 +129,7 @@ namespace Tango.MachineStudio.Logging.ViewModels { InvokeUI(() => { - _realTimeEvents.Add(machineEvent); + _realTimeEvents.Insert(0, machineEvent); }); } @@ -96,27 +137,30 @@ namespace Tango.MachineStudio.Logging.ViewModels { if (SelectedMachine != null) { - Dates = new ObservableCollection<DateVM>(); + Dates = new ObservableCollection<DateTime>(); if (SelectedMachine == _connectedMachine) { - Dates.Add(_realTimeDate); + IsRealTime = true; } foreach (var day in SelectedMachine.MachinesEvents.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) { - Dates.Add(new DateVM(day)); + Dates.Add(day); } + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + SelectedDate = Dates.FirstOrDefault(); } } private void OnSelectedDateChanged() { - if (SelectedDate != null) + if (SelectedDate != null && SelectedMachine != null) { - if (SelectedDate == _realTimeDate) + if (IsRealTime) { Events = _realTimeEvents; } @@ -129,10 +173,20 @@ namespace Tango.MachineStudio.Logging.ViewModels private void OnSelectedEventChanged() { - if (SelectedEvent != null) + if (SelectedEvent != null && SelectedEvent.Type != BL.Enumerations.EventTypes.ApplicationStarted) { - _notification.ShowInfo(SelectedEvent.Description); + _notification.ShowModalDialog<EventDetailsViewVM, EventDetailsView>(new EventDetailsViewVM(SelectedEvent), (x) => { }, () => { }); } } + + private void DisplayTimeline(MachinesEvent ev) + { + var events = Events.OrderBy(x => x.DateTime).SkipWhile(x => x != ev).Skip(1).TakeWhile(x => x.DateTime > ev.DateTime && x.Type != BL.Enumerations.EventTypes.ApplicationStarted).ToObservableCollection(); + events.Insert(0, ev); + + TimelineViewVM.Initialize(events.ToList()); + + _navigation.NavigateTo(LoggingNavigationView.TimelineView); + } } } |
