Added multiple upload PP

This commit is contained in:
Nicola Carminati
2019-04-09 15:50:36 +02:00
parent ab9bfd3602
commit 22c1410a29
7 changed files with 149 additions and 16 deletions
+22 -5
View File
@@ -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);
+14 -1
View File
@@ -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);
@@ -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{
+43
View File
@@ -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;
@@ -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)"></card-folder-path>
@@ -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) "></card-folder-path>
@@ -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;
}
}
@@ -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)"></card-folder-path>
@@ -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) "></card-folder-path>
@@ -133,10 +133,18 @@
</div>
<zoom-image v-if="showZoomedImage && selectedFile && selectedFile.PreviewBase64"
@close="ToggleShowZoomedImage"
:imageSrc=selectedFile.PreviewBase64
:imageSrc="selectedFile.PreviewBase64"
/>
</div>
<div class="modal-load-program-footer">
<div class="togglebutton" v-if="this.isLocalNavigation">
<label>{{'modal_load_program_lbl_upload_all_files' | localize('Upload all files in selected folder')}}
<input type="checkbox" :checked="uploadAllFileInFolder" @click='toggleUploadAllFileInFolder()'>
<span class="toggle">{{uploadAllFileInFolder?onLabel:offLabel}}</span>
</label>
</div>
<button class="btn btn-success"
:disabled="!selectedFile || !isCnReady()"
v-if="!this.isLocalNavigation"