From 1d29a97384af9e0a48cc7b91cfead7f0b26e8f6a Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Wed, 3 Oct 2018 12:55:57 +0200 Subject: [PATCH] Fix job images Added Active file info API --- Step.NC/NcHandler.cs | 15 ++++++++++++++- Step/Controllers/WebApi/NcFileController.cs | 15 +++++++++++++++ Step/wwwroot/src/services/fileService.ts | 10 ++++++++++ Step/wwwroot/src/services/hub.ts | 8 +++----- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index d07cd9cc..ca5ca2b0 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -81,13 +81,23 @@ namespace Step.NC { fileInfo = new InfoFile(); + if (File.Exists(path)) + return GetQueueFileInfo(path, out fileInfo); + else + return numericalControl.FILES_RGetFileInfo(path, ref fileInfo); + } + + public CmsError GetActiveFileInfo(string path, out InfoFile fileInfo) + { + fileInfo = new InfoFile(); + PROGRAM_TYPE_ENUM program = PROGRAM_TYPE_ENUM.NONE; CmsError cmsError = numericalControl.FILES_RGetProgramType(ref program); if (cmsError.IsError()) return cmsError; // If the program is a job - if(program == PROGRAM_TYPE_ENUM.JOB) + if (program == PROGRAM_TYPE_ENUM.JOB) { ushort selectedProcess = 0; cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); @@ -98,6 +108,9 @@ namespace Step.NC string jobFolderPath = JOB_TMP_DIRECTORY + "\\" + selectedProcess + "\\"; DTOJobModel model = SupportFunctions.ReadExtractedJobMetadata(selectedProcess); + if (model == null) + return FILE_NOT_FOUND_ERROR; + string base64Img = model.Metadata.Generics.Images.Count() > 0 ? model.Metadata.Generics.Images[0].Base64 : ""; fileInfo = new InfoFile() diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index 002c7dc3..b66f9e18 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -51,6 +51,21 @@ namespace Step.Controllers.WebApi } } + [Route("file/active/info"), HttpGet] + public IHttpActionResult GetActiveFileInfo([FromUri]string filePath) + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + CmsError cmsError = ncHandler.GetActiveFileInfo(filePath, out InfoFile fileInfo); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(fileInfo); + } + } + [Route("file/active"), HttpPut] public IHttpActionResult SetActiveProgram([FromUri]string filePath) { diff --git a/Step/wwwroot/src/services/fileService.ts b/Step/wwwroot/src/services/fileService.ts index 5d609377..c52ce859 100644 --- a/Step/wwwroot/src/services/fileService.ts +++ b/Step/wwwroot/src/services/fileService.ts @@ -20,6 +20,16 @@ export class FileService extends baseRestService { return result; } + + async getActiveFileInfo(path: string) { + var result = await this.Get(this.BASE_URL + "file/active/info", true, { + filePath: path + }); + + result.AbsolutePath = path; + + return result; + } async activateProgram(path: string) { return await this.Put(this.BASE_URL + "file/active?filePath=" + path, null); diff --git a/Step/wwwroot/src/services/hub.ts b/Step/wwwroot/src/services/hub.ts index 5c35f771..764a7180 100644 --- a/Step/wwwroot/src/services/hub.ts +++ b/Step/wwwroot/src/services/hub.ts @@ -112,16 +112,14 @@ export class Hub { } private static activeProgramData(data) { - // Controllo se devo ricaricare l'immagine - var cp = (store.state as AppModel).process.currentProgram; - if(data.path != "" && (!cp || cp.path != data.path)){ - fileService.getFileInfo(data.path).then(r => { + if(data.path != ""){ + fileService.getActiveFileInfo(data.path).then(r => { var image = r.previewBase64; processModelActions.setCurrentProgramImage(store, image); processModelActions.setCurrentProgramName(store, r.name); }); } - else if(data.path =="") + else if(data.path == "") { processModelActions.setCurrentProgramImage(store, null); processModelActions.setCurrentProgramName(store, null);