diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 124 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs | 17 |
2 files changed, 141 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs new file mode 100644 index 000000000..12d811c42 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.BL; +using Tango.BL.Entities; +using Tango.Core.Commands; +using Tango.DragAndDrop; +using Tango.PPC.Common; + +namespace Tango.PPC.Jobs.ViewModels +{ + public class JobsViewVM : PPCViewModel + { + private ObservablesContext _jobsContext; + + private ObservableCollection<Job> _jobs; + public ObservableCollection<Job> Jobs + { + get { return _jobs; } + set { _jobs = value; RaisePropertyChangedAuto(); } + } + + private ICollectionView _jobsCollectionView; + /// <summary> + /// Gets or sets the jobs collection view. + /// </summary> + public ICollectionView JobsCollectionView + { + get { return _jobsCollectionView; } + set + { + _jobsCollectionView = value; + RaisePropertyChangedAuto(); + } + } + + public RelayCommand JobSelectedCommand { get; set; } + + public RelayCommand<DropEventArgs> OnDragAndDropCommand { get; set; } + + public RelayCommand<Job> RemoveJobCommand { get; set; } + + private void OnDragAndDropJobs(Job draggedJob, Job droppedJob) + { + Debug.WriteLine(draggedJob.Name + " Dragged on to " + droppedJob.Name); + + if (draggedJob.JobIndex > droppedJob.JobIndex) + { + draggedJob.JobIndex = droppedJob.JobIndex - 1; + } + else + { + draggedJob.JobIndex = droppedJob.JobIndex + 1; + } + + int index = 1; + + foreach (var job in Jobs.OrderBy(x => x.JobIndex)) + { + job.JobIndex = index++; + } + + JobsCollectionView.Refresh(); + } + + private async void JobSelected(Job job) + { + Debug.WriteLine(job.Name); + await NotificationProvider.ShowInfo("Job details not yet implemented..."); + } + + public JobsViewVM() + { + Jobs = new ObservableCollection<Job>(); + + JobSelectedCommand = new RelayCommand((x) => JobSelected(x as Job)); + OnDragAndDropCommand = new RelayCommand<DropEventArgs>((e) => + { + Job draggedJob = e.Draggable.DataContext as Job; + Job droppedJob = e.Droppable.DataContext as Job; + + OnDragAndDropJobs(draggedJob, droppedJob); + }); + + RemoveJobCommand = new RelayCommand<Job>(RemoveJob); + } + + private void RemoveJob(Job job) + { + NotificationProvider.ShowQuestion("Are you sure you want to remove " + job.Name); + } + + public override void OnApplicationStarted() + { + LoadJobs(); + } + + private void LoadJobs() + { + Task.Factory.StartNew(() => + { + Thread.Sleep(500); + + if (_jobsContext != null) + { + _jobsContext.Dispose(); + } + + _jobsContext = ObservablesContext.CreateDefault(); + + Jobs = _jobsContext.Jobs.Where(x => x.Machine.SerialNumber == Settings.MachineSerialNumber).ToObservableCollection(); + JobsCollectionView = CollectionViewSource.GetDefaultView(Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + }); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs new file mode 100644 index 000000000..9750652f7 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; + +namespace Tango.PPC.Jobs.ViewModels +{ + public class MainViewVM : PPCViewModel + { + public override void OnApplicationStarted() + { + + } + } +} |
