From 8a59643571080bfff715f0b0e4bb03e2dee4961a Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 12 Jun 2018 15:47:10 +0300 Subject: Starting splitting PPC to modules. --- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 124 +++++++++++++++++++++ .../Tango.PPC.Jobs/ViewModels/MainViewVM.cs | 17 +++ 2 files changed, 141 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels') 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 _jobs; + public ObservableCollection Jobs + { + get { return _jobs; } + set { _jobs = value; RaisePropertyChangedAuto(); } + } + + private ICollectionView _jobsCollectionView; + /// + /// Gets or sets the jobs collection view. + /// + public ICollectionView JobsCollectionView + { + get { return _jobsCollectionView; } + set + { + _jobsCollectionView = value; + RaisePropertyChangedAuto(); + } + } + + public RelayCommand JobSelectedCommand { get; set; } + + public RelayCommand OnDragAndDropCommand { get; set; } + + public RelayCommand 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(); + + JobSelectedCommand = new RelayCommand((x) => JobSelected(x as Job)); + OnDragAndDropCommand = new RelayCommand((e) => + { + Job draggedJob = e.Draggable.DataContext as Job; + Job droppedJob = e.Droppable.DataContext as Job; + + OnDragAndDropJobs(draggedJob, droppedJob); + }); + + RemoveJobCommand = new RelayCommand(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() + { + + } + } +} -- cgit v1.3.1