diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 62 |
1 files changed, 58 insertions, 4 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 index 30f444a6f..d29323412 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -127,6 +127,7 @@ namespace Tango.PPC.Jobs.ViewModels _selectedCategoryIndex = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(SelectedCategory)); + Filter = null; } } @@ -138,10 +139,24 @@ namespace Tango.PPC.Jobs.ViewModels get { return (JobsCategory)SelectedCategoryIndex; } set { - SelectedCategoryIndex = value.ToInt32(); + if (SelectedCategoryIndex != value.ToInt32()) + { + SelectedCategoryIndex = value.ToInt32(); + Filter = null; + } } } + private String _filter; + /// <summary> + /// Gets or sets the search filter. + /// </summary> + public String Filter + { + get { return _filter; } + set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } + } + #endregion #region Commands @@ -284,19 +299,43 @@ namespace Tango.PPC.Jobs.ViewModels _db = ObservablesContext.CreateDefault(); - var jobs = new JobsCollectionBuilder(_db).Set(x => x.MachineGuid == MachineProvider.Machine.Guid).WithSegments().WithBrushStops().Build(); + var jobs = new JobsCollectionBuilder(_db).Set(x => x.MachineGuid == MachineProvider.Machine.Guid).WithSegments().WithBrushStops().WithCustomer().Build(); InvokeUI(() => { Jobs = jobs; DraftJobsCollectionView = new ListCollectionView(Jobs); DraftJobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - DraftJobsCollectionView.Filter = new Predicate<object>(x => (x as Job).JobStatus == JobStatuses.Draft); + DraftJobsCollectionView.Filter = new Predicate<object>(x => + { + var job = x as Job; + + if (String.IsNullOrWhiteSpace(Filter)) + { + return job.JobStatus == JobStatuses.Draft; + } + else + { + return job.JobStatus == JobStatuses.Draft && (job.Name.ToLower().StartsWith(Filter) || (job.Customer != null && job.Customer.Name.ToLower().StartsWith(Filter))); + } + }); HistoryJobsCollectionView = new ListCollectionView(Jobs); HistoryJobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - HistoryJobsCollectionView.Filter = new Predicate<object>(x => (x as Job).JobStatus != JobStatuses.Draft); + HistoryJobsCollectionView.Filter = new Predicate<object>(x => + { + var job = x as Job; + + if (String.IsNullOrWhiteSpace(Filter)) + { + return job.JobStatus != JobStatuses.Draft; + } + else + { + return job.JobStatus != JobStatuses.Draft && (job.Name.ToLower().StartsWith(Filter) || (job.Customer != null && job.Customer.Name.ToLower().StartsWith(Filter))); + } + }); IsLoadingJobs = false; LogManager.Log("Machine jobs loaded!"); @@ -485,6 +524,21 @@ namespace Tango.PPC.Jobs.ViewModels } } + /// <summary> + /// Called when the search filter has been changed + /// </summary> + private void OnFilterChanged() + { + if (SelectedCategory == JobsCategory.Draft) + { + DraftJobsCollectionView.Refresh(); + } + else if (SelectedCategory == JobsCategory.History) + { + HistoryJobsCollectionView.Refresh(); + } + } + #endregion #region Message Handling |
