From 1b7fb335900547edb4d9feb2314e607863e695d4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 29 Jul 2019 13:23:36 +0300 Subject: Added ColorCatalogGuid to job. Added catalog selection to job creation. --- .../Dialogs/CatalogSelectionView.xaml | 69 ++++++++++++++++++++++ .../Dialogs/CatalogSelectionView.xaml.cs | 34 +++++++++++ .../Dialogs/CatalogSelectionViewVM.cs | 51 ++++++++++++++++ .../Modules/Tango.PPC.Jobs/JobsModuleSettings.cs | 5 ++ .../Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj | 10 +++- .../Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs | 10 ++++ .../Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 16 ++++- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 42 ++++++++++++- .../Tango.PPC.Jobs/Views/TwineCatalogView.xaml | 5 +- 9 files changed, 236 insertions(+), 6 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionViewVM.cs (limited to 'Software/Visual_Studio/PPC/Modules') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml new file mode 100644 index 000000000..e1edb66f2 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + CANCEL + CREATE + + + + Select Catalog + Please select the desired color catalog and press 'create'. + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml.cs new file mode 100644 index 000000000..65d03e531 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionView.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.BL.Enumerations; + +namespace Tango.PPC.Jobs.Dialogs +{ + /// + /// Represents the new job creation dialog. + /// + /// + /// + public partial class CatalogSelectionView : UserControl + { + /// + /// Initializes a new instance of the class. + /// + public CatalogSelectionView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionViewVM.cs new file mode 100644 index 000000000..0c4cd72f6 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/CatalogSelectionViewVM.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.SharedUI; + +namespace Tango.PPC.Jobs.Dialogs +{ + /// + /// Represents a catalog picker. + /// + /// + public class CatalogSelectionViewVM : DialogViewVM + { + + private ObservableCollection _catalogs; + /// + /// Gets or sets the catalogs. + /// + public ObservableCollection Catalogs + { + get { return _catalogs; } + set { _catalogs = value; RaisePropertyChangedAuto(); } + } + + private ColorCatalog _selectedCatalog; + /// + /// Gets or sets the selected catalog. + /// + public ColorCatalog SelectedCatalog + { + get { return _selectedCatalog; } + set { _selectedCatalog = value; RaisePropertyChangedAuto(); } + } + + /// + /// Initializes a new instance of the class. + /// + /// The catalogs. + /// The selected catalog. + public CatalogSelectionViewVM(List catalogs, ColorCatalog selectedCatalog) : base() + { + Catalogs = catalogs.ToObservableCollection(); + SelectedCatalog = selectedCatalog; + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs index 15b859168..3d72509e0 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModuleSettings.cs @@ -34,6 +34,11 @@ namespace Tango.PPC.Jobs /// public JobTypes? LastJobType { get; set; } + /// + /// Gets or sets the last selected catalog unique identifier. + /// + public String LastSelectedCatalogGuid { get; set; } + /// /// Initializes a new instance of the class. /// diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj index 5531c1c4c..8ed2ff80e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj @@ -112,6 +112,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -204,9 +208,13 @@ + + CatalogSelectionView.xaml + JobCreationView.xaml + SpoolChangeView.xaml @@ -464,7 +472,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs index 847edb52f..69d8b090f 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs @@ -107,6 +107,16 @@ namespace Tango.PPC.Jobs.ViewModels _context = obj.Context; Job = obj.Job; + if (Job.ColorSpace.Space == BL.Enumerations.ColorSpaces.Catalog) + { + if (_context.ColorCatalogs.SingleOrDefault(x => x.Guid == Job.ColorCatalogGuid) == null) + { + await NotificationProvider.ShowError("The selected color catalog for this job could not be found.\nCannot load job."); + await NavigationManager.NavigateBack(); + return; + } + } + Job = await new JobBuilder(_context).Set(Job.Guid) .WithConfiguration() .WithRML() diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs index 7ecfb7d27..2ae9df7fb 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs @@ -474,8 +474,20 @@ namespace Tango.PPC.Jobs.ViewModels if (Job.ColorSpace.Space == BL.Enumerations.ColorSpaces.Catalog) { - SelectedCatalog = await new ColorCatalogBuilder(_db).SetFirst().WithGroups().WithItems().BuildAsync(); - CatalogItems = SelectedCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).OrderBy(x => x.ItemIndex).ToList(); + SelectedCatalog = await new ColorCatalogBuilder(_db).Set(Job.ColorCatalogGuid).WithGroups().WithItems().BuildAsync(); + + if (SelectedCatalog != null) + { + CatalogItems = SelectedCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).OrderBy(x => x.ItemIndex).ToList(); + } + else + { + await NotificationProvider.ShowError("The selected color catalog for this job could not be found.\nCannot load job."); + Job = null; + _can_navigate_back = true; + await NavigationManager.NavigateBack(); + return; + } } foreach (var segment in Job.Segments) 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 b7a6ad94a..3ea7ae6f4 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 @@ -46,6 +46,7 @@ namespace Tango.PPC.Jobs.ViewModels public class JobsViewVM : PPCViewModel { private ObservablesContext _db; //Holds the db context for the job list. + private ObservableCollection _catalogs; //Holds the available color catalogs. public enum JobsCategory { @@ -401,6 +402,8 @@ namespace Tango.PPC.Jobs.ViewModels { LogManager.Log("Adding new job..."); + var settings = SettingsManager.Default.GetOrCreate(); + var machine = MachineProvider.Machine; JobCreationViewVM vm = new JobCreationViewVM( @@ -408,7 +411,7 @@ namespace Tango.PPC.Jobs.ViewModels machine.SupportedColorSpaces.Count > 0 ? machine.SupportedColorSpaces : Enum.GetValues(typeof(ColorSpaces)).Cast().Where(x => x.IsUserSpace() || (ApplicationManager.IsInTechnicianMode && x == ColorSpaces.Volume)).ToList() ); - var settings = SettingsManager.Default.GetOrCreate(); + CatalogSelectionViewVM catalogVM = new CatalogSelectionViewVM(_catalogs.ToList(), _catalogs.ToList().SingleOrDefault(x => x.Guid == settings.LastSelectedCatalogGuid)); if (settings.LastJobType != null) { @@ -447,6 +450,24 @@ namespace Tango.PPC.Jobs.ViewModels { vm = await NotificationProvider.ShowDialog(vm); if (!vm.DialogResult) return; + + if (vm.SelectedColorSpace == ColorSpaces.Catalog) + { + if (catalogVM.SelectedCatalog == null) + { + catalogVM.SelectedCatalog = _catalogs.FirstOrDefault(); + } + + if (_catalogs.Count == 0) + { + await NotificationProvider.ShowError("No color catalogs found. Please selected another color space."); + return; + } + else if (_catalogs.Count > 1) + { + catalogVM = await NotificationProvider.ShowDialog(catalogVM); + } + } } else { @@ -457,6 +478,12 @@ namespace Tango.PPC.Jobs.ViewModels settings.LastJobType = vm.SelectedJobType; settings.LastJobColorSpace = vm.SelectedColorSpace; + + if (vm.SelectedColorSpace == ColorSpaces.Catalog) + { + settings.LastSelectedCatalogGuid = catalogVM.SelectedCatalog.Guid; + } + settings.Save(); Job job = new Job(); @@ -475,6 +502,11 @@ namespace Tango.PPC.Jobs.ViewModels job.WindingMethodGuid = Adapter.WindingMethods.FirstOrDefault().Guid; job.SpoolTypeGuid = machine.DefaultSpoolType != null ? machine.DefaultSpoolTypeGuid : Adapter.SpoolTypes.FirstOrDefault().Guid; + if (vm.SelectedColorSpace == ColorSpaces.Catalog) + { + job.ColorCatalogGuid = catalogVM.SelectedCatalog.Guid; + } + if (Jobs.Count > 0) { job.JobIndex = Jobs.Max(x => x.JobIndex) + 1; @@ -679,12 +711,18 @@ namespace Tango.PPC.Jobs.ViewModels ExternalBridgeService.ColorProfileRequest += ExternalBridgeService_ColorProfileRequest; } - public override void OnApplicationReady() + public async override void OnApplicationReady() { base.OnApplicationReady(); StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Job.Extension, HandleJobFileLoaded); StorageProvider.RegisterFileHandler(ExplorerFileDefinition.ColorProfile.Extension, HandleColorProfileFileLoaded); StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Pulse.Extension, HandlePulseFileLoaded); + + //Load catalogs. + using (ObservablesContext c = ObservablesContext.CreateDefault()) + { + _catalogs = (await c.ColorCatalogs.ToListAsync()).ToObservableCollection(); + } } public override void OnNavigatedTo() diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/TwineCatalogView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/TwineCatalogView.xaml index d4522d288..19e1f722f 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/TwineCatalogView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/TwineCatalogView.xaml @@ -18,7 +18,10 @@ - Twine Catalog + + + Catalog + -- cgit v1.3.1