From 22c1410a290f18c583309b145fc4645d760fa474 Mon Sep 17 00:00:00 2001 From: Nicola Carminati Date: Tue, 9 Apr 2019 15:50:36 +0200 Subject: [PATCH] Added multiple upload PP --- Client/Browser_Tools/BrowserJSObject.cs | 27 +++++++++--- Step/Controllers/WebApi/NcFileController.cs | 15 ++++++- Step/wwwroot/assets/styles/base/modals.less | 36 ++++++++++++++++ Step/wwwroot/assets/styles/style.css | 43 +++++++++++++++++++ .../modal-add-element-queue.vue | 4 +- .../base-components/modal-load-program.ts | 26 ++++++++--- .../base-components/modal-load-program.vue | 14 ++++-- 7 files changed, 149 insertions(+), 16 deletions(-) diff --git a/Client/Browser_Tools/BrowserJSObject.cs b/Client/Browser_Tools/BrowserJSObject.cs index a1a2a725..55c863a0 100644 --- a/Client/Browser_Tools/BrowserJSObject.cs +++ b/Client/Browser_Tools/BrowserJSObject.cs @@ -27,7 +27,7 @@ namespace Active_Client.Browser_Tools // The first letter of All PUBLIC Variables and Methods must be Lower-Case (CEF Settings) private MainForm mainForm; - private static readonly string[] _validExtensions = { "", ".txt", ".cnc", ".ini", ".mpf", ".spf", ".job", ".zip" }; + private static readonly string[] _validExtensions = { "", ".txt", ".cnc", ".ini", ".mpf", ".spf", /*".job", ".zip"*/ }; private static readonly string[] _validImages = { ".jpg", ".jpeg", ".png" }; private static string jobPath = ""; @@ -408,16 +408,18 @@ namespace Active_Client.Browser_Tools public async void uploadAndActivateProgram(object sender, CfrV8HandlerExecuteEventArgs e) { String fileToUpload = ""; + Boolean uploadAllFiles = false; Byte[] filecontent = null, imagecontent = null; String fileNameNoExt; String imageName = ""; String fileName; String imageDirectory; + String dirName; //Check the arguments numbers - if (e.Arguments.Length < 1 || e.Arguments[0] == null) + if (e.Arguments.Length < 2 || e.Arguments[0] == null || e.Arguments[1] == null) { - e.SetReturnValue(UPLOAD_PAGE + "INVALID_ARGUMENTS"); + e.SetReturnValue(UPLOAD_PAGE + ";INVALID_ARGUMENTS"); return; } @@ -429,9 +431,12 @@ namespace Active_Client.Browser_Tools return; } + //Check if must be uploaded all files + uploadAllFiles = e.Arguments[1].BoolValue; + //Get names and content of the file fileNameNoExt = Path.GetFileNameWithoutExtension(fileToUpload); - fileName = Path.GetFileName(fileToUpload); ; + fileName = Path.GetFileName(fileToUpload); filecontent = System.IO.File.ReadAllBytes(fileToUpload); //Get all bytes of the image (if exists) @@ -453,8 +458,20 @@ namespace Active_Client.Browser_Tools MultipartFormDataContent form = new MultipartFormDataContent { //Add the content to the form - { new ByteArrayContent(filecontent), "file", fileName } + { new ByteArrayContent(filecontent), "main", fileName } }; + if (uploadAllFiles) + { + dirName = Path.GetDirectoryName(fileToUpload); + string[] fileEntries = Directory.GetFiles(dirName); + foreach (string subfileName in fileEntries) + { + if(fileToUpload.ToLower() != subfileName.ToLower() && _validExtensions.Contains(Path.GetExtension(subfileName).ToLower())) + { + form.Add(new ByteArrayContent(System.IO.File.ReadAllBytes(subfileName)), "file", Path.GetFileName(subfileName)); + } + } + } if (imagecontent != null) form.Add(new ByteArrayContent(imagecontent), "image", imageName); diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index 968ae304..36711f18 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -107,7 +107,7 @@ namespace Step.Controllers.WebApi { if (item.IsAFile) { - if (item.ParameterName == "file") + if (item.ParameterName == "main") { using (NcFileHandler ncHandler = new NcFileHandler()) { @@ -120,6 +120,19 @@ namespace Step.Controllers.WebApi return BadRequest(cmsError.localizationKey); } } + else if (item.ParameterName == "file") + { + using (NcFileHandler ncHandler = new NcFileHandler()) + { + ncHandler.Connect(); + + File.WriteAllBytes(TEMP_PP_FOLDER + item.FileName, item.Data); + + CmsError cmsError = ncHandler.UploadPartProgram(TEMP_PP_FOLDER, item.FileName, out string programPath); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + } + } else if (item.ParameterName == "image") { File.WriteAllBytes(PART_PRG_IMAGES + item.FileName, item.Data); diff --git a/Step/wwwroot/assets/styles/base/modals.less b/Step/wwwroot/assets/styles/base/modals.less index fd4a06ae..1ed4f203 100644 --- a/Step/wwwroot/assets/styles/base/modals.less +++ b/Step/wwwroot/assets/styles/base/modals.less @@ -1595,6 +1595,42 @@ align-items: center; justify-content: flex-end; border-top: solid 2px @color-whitethree; + + + .togglebutton { + label { + color: #4b4b4b; + margin-right: 60px; + font-size: 18px; + font-weight: 600; + span.toggle { + width: 92px; + height: 31px; + line-height: 31px; + font-size: 13px; + margin-left: -5px; + } + } + } + + .togglebutton label .toggle:after { + width: 29px; + height: 29px; + border-radius: 27px; + top: 1px; + } + + .togglebutton label input[type=checkbox]:checked+.toggle:after { + left: 48px; + } + + .togglebutton label input[type=checkbox]:checked+.toggle:after { + width: 29px; + height: 29px; + border-radius: 27px; + left: 62px; + } + } .box-description{ diff --git a/Step/wwwroot/assets/styles/style.css b/Step/wwwroot/assets/styles/style.css index 2d6cfb05..56e74756 100644 --- a/Step/wwwroot/assets/styles/style.css +++ b/Step/wwwroot/assets/styles/style.css @@ -1658,6 +1658,49 @@ justify-content: flex-end; border-top: solid 2px #e7e7e7; } +.modal.modal-load-program .modal-load-program-footer .togglebutton label, +.modal.modal-add-element-queue .modal-load-program-footer .togglebutton label, +.modal.modal-load-program .modal-add-element-queue-footer .togglebutton label, +.modal.modal-add-element-queue .modal-add-element-queue-footer .togglebutton label { + color: #4b4b4b; + margin-right: 60px; + font-size: 18px; + font-weight: 600; +} +.modal.modal-load-program .modal-load-program-footer .togglebutton label span.toggle, +.modal.modal-add-element-queue .modal-load-program-footer .togglebutton label span.toggle, +.modal.modal-load-program .modal-add-element-queue-footer .togglebutton label span.toggle, +.modal.modal-add-element-queue .modal-add-element-queue-footer .togglebutton label span.toggle { + width: 92px; + height: 31px; + line-height: 31px; + font-size: 13px; + margin-left: -5px; +} +.modal.modal-load-program .modal-load-program-footer .togglebutton label .toggle:after, +.modal.modal-add-element-queue .modal-load-program-footer .togglebutton label .toggle:after, +.modal.modal-load-program .modal-add-element-queue-footer .togglebutton label .toggle:after, +.modal.modal-add-element-queue .modal-add-element-queue-footer .togglebutton label .toggle:after { + width: 29px; + height: 29px; + border-radius: 27px; + top: 1px; +} +.modal.modal-load-program .modal-load-program-footer .togglebutton label input[type=checkbox]:checked + .toggle:after, +.modal.modal-add-element-queue .modal-load-program-footer .togglebutton label input[type=checkbox]:checked + .toggle:after, +.modal.modal-load-program .modal-add-element-queue-footer .togglebutton label input[type=checkbox]:checked + .toggle:after, +.modal.modal-add-element-queue .modal-add-element-queue-footer .togglebutton label input[type=checkbox]:checked + .toggle:after { + left: 48px; +} +.modal.modal-load-program .modal-load-program-footer .togglebutton label input[type=checkbox]:checked + .toggle:after, +.modal.modal-add-element-queue .modal-load-program-footer .togglebutton label input[type=checkbox]:checked + .toggle:after, +.modal.modal-load-program .modal-add-element-queue-footer .togglebutton label input[type=checkbox]:checked + .toggle:after, +.modal.modal-add-element-queue .modal-add-element-queue-footer .togglebutton label input[type=checkbox]:checked + .toggle:after { + width: 29px; + height: 29px; + border-radius: 27px; + left: 62px; +} .modal.modal-load-program .box-description, .modal.modal-add-element-queue .box-description { box-sizing: border-box; diff --git a/Step/wwwroot/src/modules/base-components/modal-add-element-queue.vue b/Step/wwwroot/src/modules/base-components/modal-add-element-queue.vue index 91546db1..fb71f238 100644 --- a/Step/wwwroot/src/modules/base-components/modal-add-element-queue.vue +++ b/Step/wwwroot/src/modules/base-components/modal-add-element-queue.vue @@ -38,7 +38,7 @@ :name="val.Name" :disabled="!isCnReady() && !isLocalNavigation" :class="{dark: val.AbsolutePath == lastClickPath}" - :selected="isInPath(val.AbsolutePath) || val.AbsolutePath == lastClickPath" + :selected="isInPath(val.AbsolutePath,val.IsDirectory) || val.AbsolutePath == lastClickPath" :withArrow="val.IsDirectory == true" :iconType="val.IsDirectory? 'FOLDER':'FILE'" @click="val.IsDirectory ? navigateTo(val.Path, val.AbsolutePath, isLocalNavigation, 2,1): fileInfo(val.AbsolutePath,1, val.IsJob)"> @@ -60,7 +60,7 @@ :name="val.Name" :disabled="!isCnReady() && !isLocalNavigation" :class="{dark: val.AbsolutePath == lastClickPath}" - :selected="isInPath(val.AbsolutePath) || val.AbsolutePath == lastClickPath" + :selected="isInPath(val.AbsolutePath,val.IsDirectory) || val.AbsolutePath == lastClickPath" :withArrow="val.IsDirectory == true" :iconType="val.IsDirectory? 'FOLDER':'FILE'" @click="val.IsDirectory? navigateTo(val.Path, val.AbsolutePath, isLocalNavigation, 2,2):fileInfo(val.AbsolutePath,2, val.IsJob) "> diff --git a/Step/wwwroot/src/modules/base-components/modal-load-program.ts b/Step/wwwroot/src/modules/base-components/modal-load-program.ts index cc3c6e24..dfe13879 100644 --- a/Step/wwwroot/src/modules/base-components/modal-load-program.ts +++ b/Step/wwwroot/src/modules/base-components/modal-load-program.ts @@ -67,6 +67,10 @@ export default class ModalLoadProgram extends Vue { navigationDepth: number = 0; selectedNumberImage: number = 0; showZoomedImage: boolean = false; + + uploadAllFileInFolder: boolean = false; + onLabel: string = "On"; + offLabel: string = "Off"; mounted() { if (typeof cmsClient != "undefined") { @@ -84,6 +88,8 @@ export default class ModalLoadProgram extends Vue { this.currentPath = absolutePath; this.lastClickPath = absolutePath; this.checkChangeNavigationType(local); + this.selectedFile = null; + this.selectedFileMetadata = null; var files = await this.getFilesForPath(absolutePath, path, local); @@ -100,8 +106,6 @@ export default class ModalLoadProgram extends Vue { this.fillArray(this.firstColumnData, files); this.secondColumnData.splice(0, this.secondColumnData.length); this.currentFilterFirst = ""; - this.selectedFile = null; - this.selectedFileMetadata = null; } if (todepth == 2) { @@ -176,8 +180,14 @@ export default class ModalLoadProgram extends Vue { } } - isInPath(path) { - if (this.currentPath) return this.currentPath.startsWith(path); + isInPath(path,isDirectory) { + + if (this.currentPath) { + if(!this.uploadAllFileInFolder || !this.isLocalNavigation) + return path == this.currentPath; + else + return (path.startsWith(this.currentPath) && !isDirectory) || (path == this.currentPath && isDirectory); + } return false; } @@ -229,6 +239,9 @@ export default class ModalLoadProgram extends Vue { if (!this.isLocalNavigation) this.selectedFile = this.toUpperCaseFileModel( await awaiter(fileService.getFileInfo(str))); + + this.currentPath = this.selectedFile.AbsolutePath.substring(0,this.selectedFile.AbsolutePath.lastIndexOf("\\")); + } beforeMount() { @@ -261,7 +274,7 @@ export default class ModalLoadProgram extends Vue { async loadProgram(path: string) { if (this.isLocalNavigation && typeof cmsClient != "undefined") { - var resp = cmsClient.uploadAndActivateProgram(path); + var resp = cmsClient.uploadAndActivateProgram(path,this.uploadAllFileInFolder); if (resp != "") (iziToast as any).error({ title: resp.split(";")[0], @@ -298,5 +311,8 @@ export default class ModalLoadProgram extends Vue { this.showZoomedImage = !this.showZoomedImage; } + toggleUploadAllFileInFolder(){ + this.uploadAllFileInFolder = !this.uploadAllFileInFolder; + } } diff --git a/Step/wwwroot/src/modules/base-components/modal-load-program.vue b/Step/wwwroot/src/modules/base-components/modal-load-program.vue index d4b9d6fd..647516ab 100644 --- a/Step/wwwroot/src/modules/base-components/modal-load-program.vue +++ b/Step/wwwroot/src/modules/base-components/modal-load-program.vue @@ -45,7 +45,7 @@ :name="val.Name" :disabled="!isCnReady() && !isLocalNavigation" :class="{dark: val.AbsolutePath == lastClickPath}" - :selected="isInPath(val.AbsolutePath) || val.AbsolutePath == lastClickPath" + :selected="isInPath(val.AbsolutePath,val.IsDirectory) || val.AbsolutePath == lastClickPath" :withArrow="val.IsDirectory == true" :iconType="val.IsDirectory? 'FOLDER':'FILE'" @click="val.IsDirectory ? navigateTo(val.Path, val.AbsolutePath, isLocalNavigation, 2,1): fileInfo(val.AbsolutePath,val.IsJob,1)"> @@ -67,7 +67,7 @@ :name="val.Name" :disabled="!isCnReady() && !isLocalNavigation" :class="{dark: val.AbsolutePath == lastClickPath}" - :selected="isInPath(val.AbsolutePath) || val.AbsolutePath == lastClickPath" + :selected="isInPath(val.AbsolutePath,val.IsDirectory) || val.AbsolutePath == lastClickPath" :withArrow="val.IsDirectory == true" :iconType="val.IsDirectory? 'FOLDER':'FILE'" @click="val.IsDirectory? navigateTo(val.Path, val.AbsolutePath, isLocalNavigation, 2,2):fileInfo(val.AbsolutePath,val.IsJob,2) "> @@ -133,10 +133,18 @@