From 04c710d1d4f92fe1e7328d39e72f54d629be511f Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Tue, 27 Aug 2019 10:28:38 +0200 Subject: [PATCH] Added ask-confirm layer on file manager --- Client/Browser_Tools/BrowserJSObject.cs | 108 ++++++++++-------- Step/wwwroot/assets/styles/base/modals.less | 1 + Step/wwwroot/assets/styles/style.css | 4 + .../base-components/modal-load-program.ts | 30 ++++- .../base-components/modal-load-program.vue | 21 +++- 5 files changed, 109 insertions(+), 55 deletions(-) diff --git a/Client/Browser_Tools/BrowserJSObject.cs b/Client/Browser_Tools/BrowserJSObject.cs index 6f634a97..b178cf65 100644 --- a/Client/Browser_Tools/BrowserJSObject.cs +++ b/Client/Browser_Tools/BrowserJSObject.cs @@ -462,7 +462,6 @@ namespace Active_Client.Browser_Tools public async void uploadAndActivateProgram(object sender, CfrV8HandlerExecuteEventArgs e) { string fileToUpload = ""; - bool uploadAllFiles = false; byte[] filecontent = null, imagecontent = null; string fileNameNoExt; string imageName = ""; @@ -486,7 +485,8 @@ namespace Active_Client.Browser_Tools } // Check if must be uploaded all files - uploadAllFiles = e.Arguments[1].BoolValue; + bool uploadAllFiles = e.Arguments[1].BoolValue; + bool uploadRecents = e.Arguments[2].BoolValue; // Get names and content of the file fileNameNoExt = Path.GetFileNameWithoutExtension(fileToUpload); @@ -511,21 +511,33 @@ namespace Active_Client.Browser_Tools // Create the new FORM MultipartFormDataContent form = new MultipartFormDataContent { - // Add the content to the form + // Add the main program to the form { new ByteArrayContent(filecontent), "main", fileName } }; + if (uploadAllFiles) { + // Load all the programs in the selected folder 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(File.ReadAllBytes(subfileName)), "file", Path.GetFileName(subfileName)); - } } } + + if (uploadRecents) + { + List files = GetLastUploadedFiles(); + + foreach(FileModel file in files) + { + if(file.FileExist) + form.Add(new ByteArrayContent(File.ReadAllBytes(file.AbsolutePath)), "file", file.Name); + } + } + if (imagecontent != null) form.Add(new ByteArrayContent(imagecontent), "image", imageName); @@ -557,7 +569,7 @@ namespace Active_Client.Browser_Tools string imageDirectory; int reps = 0; - //Check the arguments numbers + // Check the arguments numbers if (e.Arguments.Length < 1 || e.Arguments[0] == null) { e.SetReturnValue(UPLOAD_ADD_QUEUE + "INVALID_ARGUMENTS"); @@ -574,12 +586,12 @@ namespace Active_Client.Browser_Tools return; } - //Get names and content of the file + // Get names and content of the file fileNameNoExt = Path.GetFileNameWithoutExtension(fileToUpload); fileName = Path.GetFileName(fileToUpload); ; filecontent = File.ReadAllBytes(fileToUpload); - //Get all bytes of the image (if exists) + // Get all bytes of the image (if exists) imageDirectory = Path.GetDirectoryName(fileToUpload); foreach (string ext in _validImages) { @@ -591,7 +603,7 @@ namespace Active_Client.Browser_Tools } } - //Send all to the server + // Send all to the server using (HttpClient httpClient = new HttpClient()) { //Create the new FORM @@ -680,7 +692,7 @@ namespace Active_Client.Browser_Tools e.SetReturnValue(JsonConvert.SerializeObject(file)); } - // launch FIle editor + // Launch file editor public void editProgram(object sender, CfrV8HandlerExecuteEventArgs e) { if (e.Arguments.Count() < 2) @@ -778,42 +790,6 @@ namespace Active_Client.Browser_Tools CallJSFunction(_currentEditorObject.func, null, _currentEditorObject.context); } - // Private functions - private string ElaborateName(string name, string letter, DriveType type) - { - var retName = ""; - - if (!string.IsNullOrWhiteSpace(name)) - retName = name; - else - { - switch (type) - { - case DriveType.Fixed: retName = "Hard_Disk";break; - case DriveType.Removable: retName = "Usb_Disk"; break; - case DriveType.Network: retName = "Netword_Disk"; break; - default: retName = "Undefined"; break; - } - } - - - if (!string.IsNullOrWhiteSpace(letter)) - retName = retName + " (" + letter + ")"; - - return retName; - } - - private string ElaborateType(DriveType type) - { - switch (type) - { - case DriveType.Fixed: return "HD"; - case DriveType.Removable: return "USB"; - case DriveType.Network: return "NTW"; - } - return "SPFO"; - } - private void WriteLastUploadedFile(string main, bool uploadAllFiles) { StringBuilder stringBuilder = new StringBuilder(); @@ -864,11 +840,47 @@ namespace Active_Client.Browser_Tools return files; } + private string ElaborateType(DriveType type) + { + switch (type) + { + case DriveType.Fixed: return "HD"; + case DriveType.Removable: return "USB"; + case DriveType.Network: return "NTW"; + } + return "SPFO"; + } + + // Private functions + private string ElaborateName(string name, string letter, DriveType type) + { + var retName = ""; + + if (!string.IsNullOrWhiteSpace(name)) + retName = name; + else + { + switch (type) + { + case DriveType.Fixed: retName = "Hard_Disk"; break; + case DriveType.Removable: retName = "Usb_Disk"; break; + case DriveType.Network: retName = "Netword_Disk"; break; + default: retName = "Undefined"; break; + } + } + + + if (!string.IsNullOrWhiteSpace(letter)) + retName = retName + " (" + letter + ")"; + + return retName; + } + #endregion FILESYSTEM_METHODS /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - + #region RECALL_METHOD - + private static void CallJSFunction(CfrV8Value functionIstance, string arguments, CfrV8Context context) { //Create & enter function context diff --git a/Step/wwwroot/assets/styles/base/modals.less b/Step/wwwroot/assets/styles/base/modals.less index 04e83d42..54b1f933 100644 --- a/Step/wwwroot/assets/styles/base/modals.less +++ b/Step/wwwroot/assets/styles/base/modals.less @@ -1371,6 +1371,7 @@ position: relative; flex-flow: row; + .ask-confirm, .cleanTempFolder { top: 0; left: 0; diff --git a/Step/wwwroot/assets/styles/style.css b/Step/wwwroot/assets/styles/style.css index 4da64489..2657aa65 100644 --- a/Step/wwwroot/assets/styles/style.css +++ b/Step/wwwroot/assets/styles/style.css @@ -1313,6 +1313,10 @@ position: relative; flex-flow: row; } +.modal.modal-load-program .modal-load-program-body .ask-confirm, +.modal.modal-add-element-queue .modal-load-program-body .ask-confirm, +.modal.modal-load-program .modal-add-element-queue-body .ask-confirm, +.modal.modal-add-element-queue .modal-add-element-queue-body .ask-confirm, .modal.modal-load-program .modal-load-program-body .cleanTempFolder, .modal.modal-add-element-queue .modal-load-program-body .cleanTempFolder, .modal.modal-load-program .modal-add-element-queue-body .cleanTempFolder, 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 d37c0313..1650dc80 100644 --- a/Step/wwwroot/src/modules/base-components/modal-load-program.ts +++ b/Step/wwwroot/src/modules/base-components/modal-load-program.ts @@ -74,6 +74,8 @@ export default class ModalLoadProgram extends Vue { offLabel: string = "Off"; recentPath: string = "" thereAreFileEliminated: boolean = false + askConfirmLayer: boolean = false + loadClicked: boolean = false get machineInfo() { return this.$store.state.machineInfo; @@ -88,6 +90,8 @@ export default class ModalLoadProgram extends Vue { this.driveList = JSON.parse(cmsClient.getOSdriveList()); this.recentPath = cmsClient.RECENT_FOLDER_KEY } + + this.loadClicked = false } async navigateTo(path: string, absolutePath: string, local: boolean, todepth: number, fromdepth: number) { @@ -141,7 +145,6 @@ export default class ModalLoadProgram extends Vue { this.thereAreFileEliminated = false; } - console.log(this.thereAreFileEliminated) this.calcBreadCrumb(absolutePath); this.cleanFileWatcher(); } @@ -310,10 +313,19 @@ export default class ModalLoadProgram extends Vue { } async load(item: FileInfo) { - if (item.IsJob) - this.loadJob(item.AbsolutePath); - else - this.loadProgram(item.AbsolutePath); + if(!this.thereAreFileEliminated || this.askConfirmLayer) { + this.loadClicked = true + + if (item.IsJob) + this.loadJob(item.AbsolutePath); + else + this.loadProgram(item.AbsolutePath); + + this.askConfirmLayer = false + } + else { + this.askConfirmLayer = true + } } async loadProgram (path: string) { @@ -401,4 +413,12 @@ export default class ModalLoadProgram extends Vue { this.fileIsChanged = false; cmsClient.cleanFileWatcher() } + + askConfirmOkClick(){ + this.load(this.selectedFile) + } + + askConfirmCancelClick(){ + this.askConfirmLayer = false; + } } 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 9ef2a6cd..66d39794 100644 --- a/Step/wwwroot/src/modules/base-components/modal-load-program.vue +++ b/Step/wwwroot/src/modules/base-components/modal-load-program.vue @@ -216,7 +216,24 @@ + +
+ {{'modal_load_program_lbl_ask_confirm' | localize('Ci sono dei file che sono stati spostati o eliminati, caricare comunque?')}} +
+ + +
+
+