Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logic to import multiple files when prompted (fixes issues #31) #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 60 additions & 55 deletions main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -565,74 +565,79 @@

{ 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]);
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(fileName[0]);
importbutton.className = 'button import';
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{
importbutton.className = 'button import spinner';

// send to conversion server
var url = config.getSync('conversionServer');
if(!url){
url = defaultConversionServer;
// 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;
}*/
}

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(fileName[0]));
// dirpath is used for loading images embedded in svg files
// converted svgs will not have images
importData(body, filename, null, con, dxfFlag);
}
}

});
}, 50);

};


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){
Expand Down