From 388f06ad61b9872d3b24f9a09119f215b6a0e6ca Mon Sep 17 00:00:00 2001 From: jsmwoolf Date: Mon, 26 Nov 2018 21:08:35 -0800 Subject: [PATCH 1/2] Added logic to import multiple files when prompted. --- main/index.html | 105 +++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/main/index.html b/main/index.html index a119f7061..12122d499 100644 --- a/main/index.html +++ b/main/index.html @@ -565,67 +565,72 @@ { name: 'CAD formats', extensions: ['svg', 'dxf', 'cdr'] } - ]}, function (fileName) { + ], + properties:['openFile', 'multiSelections'] + + }, function (fileName) { if(fileName === undefined){ importbutton.className = 'button import'; console.log("No file selected"); } else{ - var ext = path.extname(fileName[0]); - var filename = path.basename(fileName[0]); + fileName.forEach((file) => { + var ext = path.extname(file); + var filename = path.basename(file); - if(ext.toLowerCase() == '.svg'){ - readFile(fileName[0]); - importbutton.className = 'button import'; - } - else{ - importbutton.className = 'button import spinner'; - - // send to conversion server - var url = config.getSync('conversionServer'); - if(!url){ - url = defaultConversionServer; - } - - var req = request.post(url, function (err, resp, body) { + if(ext.toLowerCase() == '.svg'){ + readFile(file); importbutton.className = 'button import'; - if (err) { - message('could not contact file conversion server', true); - } else { - if(body.substring(0, 5) == 'error'){ - message(body, true); - } - else{ - // expected input dimensions on server is points - // scale based on unit preferences - var con = null; - var dxfFlag = false; - if(ext.toLowerCase() == '.dxf'){ - //var unit = config.getSync('units'); - con = Number(config.getSync('dxfImportScale')); - dxfFlag = true; - console.log('con', con); - - /*if(unit == 'inch'){ - con = 72; + } + else{ + importbutton.className = 'button import spinner'; + + // send to conversion server + var url = config.getSync('conversionServer'); + if(!url){ + url = defaultConversionServer; + } + + var req = request.post(url, function (err, resp, body) { + importbutton.className = 'button import'; + if (err) { + message('could not contact file conversion server', true); + } else { + if(body.substring(0, 5) == 'error'){ + message(body, true); + } + else{ + // expected input dimensions on server is points + // scale based on unit preferences + var con = null; + var dxfFlag = false; + if(ext.toLowerCase() == '.dxf'){ + //var unit = config.getSync('units'); + con = Number(config.getSync('dxfImportScale')); + dxfFlag = true; + console.log('con', con); + + /*if(unit == 'inch'){ + con = 72; + } + else{ + // mm + con = 2.83465; + }*/ } - else{ - // mm - con = 2.83465; - }*/ + + // dirpath is used for loading images embedded in svg files + // converted svgs will not have images + importData(body, filename, null, con, dxfFlag); } - - // dirpath is used for loading images embedded in svg files - // converted svgs will not have images - importData(body, filename, null, con, dxfFlag); } - } - }); + }); - var form = req.form(); - form.append('format', 'svg'); - form.append('fileUpload', fs.createReadStream(fileName[0])); - } + var form = req.form(); + form.append('format', 'svg'); + form.append('fileUpload', fs.createReadStream(file)); + } + }); } }); From cbfa9e68b5cb342b9ec6ca7deffd911e034e1d62 Mon Sep 17 00:00:00 2001 From: jsmwoolf Date: Mon, 26 Nov 2018 21:50:56 -0800 Subject: [PATCH 2/2] Moved import file logic to different function. --- main/index.html | 116 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/main/index.html b/main/index.html index 12122d499..46cfa3d40 100644 --- a/main/index.html +++ b/main/index.html @@ -574,70 +574,70 @@ console.log("No file selected"); } else{ - fileName.forEach((file) => { - var ext = path.extname(file); - var filename = path.basename(file); - - if(ext.toLowerCase() == '.svg'){ - readFile(file); - importbutton.className = 'button import'; - } - else{ - importbutton.className = 'button import spinner'; - - // send to conversion server - var url = config.getSync('conversionServer'); - if(!url){ - url = defaultConversionServer; - } - - var req = request.post(url, function (err, resp, body) { - importbutton.className = 'button import'; - if (err) { - message('could not contact file conversion server', true); - } else { - if(body.substring(0, 5) == 'error'){ - message(body, true); - } - else{ - // expected input dimensions on server is points - // scale based on unit preferences - var con = null; - var dxfFlag = false; - if(ext.toLowerCase() == '.dxf'){ - //var unit = config.getSync('units'); - con = Number(config.getSync('dxfImportScale')); - dxfFlag = true; - console.log('con', con); - - /*if(unit == 'inch'){ - con = 72; - } - else{ - // mm - con = 2.83465; - }*/ - } - - // dirpath is used for loading images embedded in svg files - // converted svgs will not have images - importData(body, filename, null, con, dxfFlag); - } - } - }); - - var form = req.form(); - form.append('format', 'svg'); - form.append('fileUpload', fs.createReadStream(file)); - } + importbutton.className = 'button import spinner'; + fileName.forEach(function(file) { + processFile(file); }); + importbutton.className = 'button import'; } - }); }, 50); - }; + function processFile(file) { + var ext = path.extname(file); + var filename = path.basename(file); + + if(ext.toLowerCase() == '.svg'){ + readFile(file); + } + else{ + // send to conversion server + var url = config.getSync('conversionServer'); + if(!url){ + url = defaultConversionServer; + } + + var req = request.post(url, function (err, resp, body) { + if (err) { + message('could not contact file conversion server', true); + } else { + if(body.substring(0, 5) == 'error'){ + message(body, true); + } + else{ + // expected input dimensions on server is points + // scale based on unit preferences + var con = null; + var dxfFlag = false; + if(ext.toLowerCase() == '.dxf'){ + //var unit = config.getSync('units'); + con = Number(config.getSync('dxfImportScale')); + dxfFlag = true; + console.log('con', con); + + /*if(unit == 'inch'){ + con = 72; + } + else{ + // mm + con = 2.83465; + }*/ + } + + // dirpath is used for loading images embedded in svg files + // converted svgs will not have images + importData(body, filename, null, con, dxfFlag); + } + } + }); + + var form = req.form(); + form.append('format', 'svg'); + form.append('fileUpload', fs.createReadStream(file)); + } + } + function readFile(filepath){ fs.readFile(filepath, 'utf-8', function (err, data) { if(err){