Commit 3c0be58e authored by Andrew Cohen's avatar Andrew Cohen

recursive getLeverFileList

parent 79ca067c
......@@ -58,11 +58,13 @@
</div>
<div id='sbImport' style='display:none'>
<table id="ImportTable"> </table>
<button class= sbButton id="Go Export" tabindex="1" onclick="importFolder()" > Import to Folder </button>
<button class= sbButton id="importButton" tabindex="1" onclick="importFolder()" > Import to Folder </button>
<div><br><i class="fa fa-cog fa-spin fa-2x fa-fw" aria-hidden="true" id='busySpinner' style="display:none;"></i> </div>
<div id='importStatus'></div>
</div>
<div id='sbProcess' style='display:none'>
<div id='processControls'>
<i class="fa fa-cog fa-spin fa-2x fa-fw" aria-hidden="true" id='busySpinner' style="display:none;"></i>
<i class="fa fa-cog fa-spin fa-2x fa-fw" aria-hidden="true" id='importSpinner' style="display:none;"></i>
<div style='display:block'> </div>
<button class='sbButton' onclick="processSelected(true)" id="btnProcessAll">
process all <i class="fa fa-play-circle fa-1x" aria-hidden="true"></i></button>
......
......@@ -510,7 +510,7 @@ function refreshExperiments()
}
updateRow(leverStruct,gExperiments.length,flist.length);
gExperiments.push(leverStruct);
if (gExperiments.length==n) {
if (gExperiments.length==flist.length) {
console.timeEnd('updateExp');
progressDiv.style.display='none';
}
......
......@@ -21,7 +21,9 @@ function importFolder()
var importPath;
const dbAlgorithms=require('./dbAlgorithms.js');
var importSpinner=document.getElementById('importSpinner');
importSpinner.style.display='';
// used to detect windows vs unix for process spawn command line
var isWin = /^win/.test(process.platform);
......@@ -36,19 +38,28 @@ function importFolder()
else
global.matlabChild = spawn(importPath,['/usr/local/MATLAB/R2017a/',inputDir,leverDir]);
var status=document.getElementById('importStatus');
global.matlabChild.on('error', (err) => {
console.error('Failed to start child matlab process.' + err);
status.innerText=err;
});
global.matlabChild.stdout.on('data', (data) => {
console.log(`matlab: ${data}`);
var statusText=data.filter(function(data){return data>20;});
if (statusText.indexOf('Done')<0)
status.innerText=statusText;
});
global.matlabChild.stderr.on('data', (data) => {
console.error(`matlab: ${data}`);
status.innerText=err;
});
global.matlabChild.on('close', (code) => {
importSpinner.style.display='none';
console.log(`matlab process exited with code ${code}`);
});
}
......@@ -61,13 +72,22 @@ function requestDialog(varname){
ipcRenderer.send('getDir', () => {
});
ipcRenderer.on('getDir', (event, fullFileName) => {
ipcRenderer.once('getDir', (event, fullFileName) => {
window[varname] = fullFileName;
populateImportTab()
});
}
function setImport()
{
var leverDirInput=document.getElementById('leverDirInput');
var inputDirInput=document.getElementById('inputDirInput');
inputDir=inputDirInput.value;
leverDir=leverDirInput.value;
}
function populateImportTab(){
var sbImport = document.getElementById('sbImport');
......@@ -84,12 +104,12 @@ function populateImportTab(){
if (null===inputDir)
inputDir='';
row.innerHTML = '<td> Input Directory </td> <td> <input type=text oninput="changeinputDir()" size=30 id=inputDir value="' + inputDir + '"</input> </td>' +
row.innerHTML = '<td> Input Directory </td> <td> <input type=text oninput="setImport()" size=30 id="inputDirInput" value="' + inputDir + '"</input> </td>' +
'<td> <button class= sbButton id="TextinputDir" tabindex="1" onclick="requestDialog(\'inputDir\')" > Select Input Folder </button> </td>';
var row=tblImport.insertRow();
row.innerHTML = '<td> LEVER Directory </td> <td> <input type=text oninput="changeleverDir()" size=30 id=leverDir value="'+ leverDir +'"</input></td>' +
row.innerHTML = '<td> LEVER Directory </td> <td> <input type=text oninput="setImport()" size=30 id="leverDirInput" value="'+ leverDir +'"</input></td>' +
'<td> <button class= sbButton id="TextleverDir" tabindex="1" onclick="requestDialog(\'leverDir\')" > Select LEVER Folder </button> </td>';
}
\ No newline at end of file
......@@ -357,6 +357,42 @@ function executeUI(lDB,leverCommand,fnCallback)
});
} // executeUI
function recurseGetFileList(leverFolder)
{
const fs = require('fs');
const path = require('path');
var leverFileNames = [];
var flist = fs.readdirSync(leverFolder);
for (var f = 0; f < flist.length; f++) {
var fname=path.join(leverFolder,flist[f]);
if ('.LEVER' === path.extname(flist[f])) {
leverFileNames.push(fname);
}
else if (fs.statSync(fname).isDirectory()) {
// see if the fname folder is an image folder for a .lever file in this folder, save some recursing
for (var j=0;j<flist.length;j++){
var bSkip=false;
if (path.extname(flist[j])==='.LEVER' && path.basename(flist[j],'.LEVER')===flist[f]) {
bSkip=true;
break;
}
}
if (bSkip)
continue;
var subFolderLeverNames=recurseGetFileList(fname);
leverFileNames=leverFileNames.concat(subFolderLeverNames);
}
}
return leverFileNames;
}
// ------------------------------------ LeverDB class -----------------------------------------------
class LeverDB {
constructor(leverFile) {
......@@ -566,7 +602,15 @@ class LeverDB {
// }); // dbUpdate
}
leverGetFileList(folder, fnCallback) {
if (!IS_NODE) {
if (('undefined'===typeof IS_NODE) || (IS_NODE)) {
var leverFileNames=recurseGetFileList(folder);
// remove root prefix from file names
for (var f=0;f<leverFileNames.length;f++) {
leverFileNames[f]=leverFileNames[f].substring(folder.length+1);
}
fnCallback(leverFileNames);
}
else {
var editReq = new XMLHttpRequest();
editReq.addEventListener("load", function() {
var leverFileNames = JSON.parse(this.responseText);
......@@ -575,17 +619,6 @@ class LeverDB {
editReq.open("GET", folder + "lever/");
editReq.send();
}
else {
const fs = require('fs');
const path = require('path');
var leverFileNames = [];
var flist = fs.readdirSync(folder);
for (var i = 0; i < flist.length; i++)
if ('.LEVER' === path.extname(flist[i])) {
leverFileNames.push(flist[i]);
}
fnCallback(leverFileNames);
}
}
}
......
......@@ -15,7 +15,7 @@ if ~exist('../bin','dir')
end
mcc -a '../../utilities/src/MATLAB/+MicroscopeData/+Original/+BioFormats/bioformats_package.jar'...
-m importFolder.m -d buildOutput
-a sqlite-jdbc-3.14.2.1.jar -m importFolder.m -d buildOutput
mcc -a sqlite-jdbc-3.14.2.1.jar -a +Segment -a +Mitosis -m matlabPollDB.m -d buildOutput
......
function importFolder(rawFolder,leverFolder)
fprintf(1,'importFolder: rawFolder=%d leverFolder=%s\n',rawFolder,leverFolder);
Import.leverImport(rawFolder,leverFolder,[],1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment