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. --- .../Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs | 10 ++++++ .../Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 16 +++++++-- .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 42 ++++++++++++++++++++-- 3 files changed, 64 insertions(+), 4 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels') 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() -- cgit v1.3.1