Commit 7859aa6b authored by Andrew Cohen's avatar Andrew Cohen

change the .lever file management for subfolders

parent 87458868
......@@ -33,6 +33,7 @@ const IS_NODE = typeof module !== 'undefined' && module.exports;
var ipcRenderer;
if (IS_NODE) {
// updateBar is for the autoUpdater used with the built version
const updateBar=require('./updateBar.js');
ipcRenderer= require('electron').ipcRenderer;
ipcRenderer.on('autoUpdater', (event, text) => {
......@@ -48,7 +49,7 @@ function processSelected(bAddAll)
var view=gLeverFileMap.get(gExperiments[n].leverFile);
if (view.bChecked || bAddAll) {
var leverCommand={leverFile:gExperiments[n].leverFile,time:1,command:'resegAll',params:[1]};
if (IS_NODE) {
if (IS_NODE) {
addToQ(leverCommand);
updateProcess();
}
......@@ -97,8 +98,11 @@ function buildProcessTables(Q)
for (var i=0;i<Q.inProcessQ.length;i++) {
var iRow=findProcessRow(tbl,Q.inProcessQ[i].nSlot);
var row=row=tbl.insertRow(iRow);
var row=tbl.insertRow(iRow);
var leverFile=Q.inProcessQ[i].leverFile;
if (IS_NODE)
leverFile=leverFile.substring(ROOT.length+1);
var status=Q.inProcessQ[i].status;
row.nSlot=Q.inProcessQ[i].nSlot;
......@@ -128,8 +132,11 @@ function buildProcessTables(Q)
}
for (var i=0;i<Q.toProcessQ.length;i++) {
var row=row=tbl.insertRow();
var leverFile=Q.toProcessQ[i].leverFile;
leverFile=leverFile.substring(ROOT.length+1);
row.innerHTML='<td>+'+(i+1)+': </td><td class="processRow">'+Q.toProcessQ[i].leverFile+'</td>'+
row.innerHTML='<td>+'+(i+1)+': </td><td class="processRow">'+leverFile+'</td>'+
'<td class="processRow">'+Q.toProcessQ[i].command+'</td>'+
'<td class="processRow">'+Q.toProcessQ[i].params+'</td>';
}
......@@ -369,7 +376,10 @@ function updateRow(leverStruct,nExperiment,nFiles)
var row=tbl.insertRow(iRow++);
row.rowID=rowID;
var idString='checkbox'+nExperiment;
var linkImageWindow='<a target="_blank" href=./ImageWindow.html?'+encodeURI(leverStruct.leverFile)+'>'+decodeURI(leverStruct.leverFile)+'</a>';
var leverFile=decodeURI(leverStruct.leverFile);
if (IS_NODE)
leverFile=leverFile.substring(ROOT.length+1);
var linkImageWindow='<a target="_blank" href=./ImageWindow.html?'+encodeURI(leverStruct.leverFile)+'>'+leverFile+'</a>';
row.innerHTML='<td colspan="2" class="borderTop '+rowStripeClass+'"> <input type="checkbox" onclick=clickCheckBox('+nExperiment+') id="'+idString+'"></input> '
+(rowID+1)+'/'+nFiles+') &nbsp &nbsp '+linkImageWindow+'</td>';
var cb=document.getElementById(idString);
......@@ -497,14 +507,24 @@ function refreshExperiments()
if (!IS_NODE)
leverFile=ROOT+encodeURI(flist[n])+'/lever';
else {
// if we're here and it's node - this is electron
// replace the '*'s in leverFilename with the platform correct '/'
const path=require('path');
leverFile=path.join(ROOT,flist[n]);
leverFile=flist[n];
leverFile=leverFile.replace(/\*/g,path.sep);
leverFile=path.join(ROOT,leverFile);
}
leverDB.leverRead(leverFile,n,null,function(err,leverStruct,id){
leverDB.leverRead(leverFile,n,ROOT,function(err,leverStruct,id){
value++;
progress.value=value;
progress.innerHTML=+value+' of '+flist.length;
if (undefined===typeof IS_NODE || IS_NODE) {
const path=require('path');
leverStruct.leverFile=leverStruct.leverFile.replace(/\*/g,path.sep);
leverStruct.leverFile=path.join(ROOT,leverStruct.leverFile);
}
if (undefined===gLeverFileMap.get(leverStruct.leverFile)) {
gLeverFileMap.set(leverStruct.leverFile,{bExpandConstants:false,bExpandAlgorithms:false,bChecked:false,ID:n});
}
......
......@@ -198,25 +198,24 @@ function createNewDB(LEVERfileName,CONSTANTS,fnCompleteCallback)
cmd = 'CREATE TABLE IF NOT EXISTS uiExtFamilies(trackID INTEGER PRIMARY KEY)';
lDB.exec(cmd);
// color table
createColorTable(lDB);
// manual edits
// manual edits
cmd='DROP TABLE IF EXISTS tblManualEdits';
lDB.exec(cmd);
cmd='CREATE TABLE IF NOT EXISTS tblManualEdits(cellID_src INTEGER, cellID_dst INTEGER, dateTime STRING, '+
'userID STRING,PRIMARY KEY(cellID_src,cellID_dst))';
lDB.exec(cmd);
addLeverTable(lDB,function(){
lDB.parallelize();
lDB.close(function(err) {
if (null!=fnCompleteCallback)
fnCompleteCallback();
});
// color table
createColorTable(lDB,function(){
addLeverTable(lDB,function(){
lDB.parallelize();
lDB.close(function(err) {
if (null!=fnCompleteCallback)
fnCompleteCallback();
});
});
});
} // createNewDB
function JSONtoLEVER(JSONfile,LEVERfile,bOverwrite,fnCompleteCallback)
......
......@@ -371,7 +371,7 @@ function recurseGetFileList(leverFolder)
if ('.LEVER' === path.extname(flist[f])) {
leverFileNames.push(fname);
}
else if (fs.statSync(fname).isDirectory()) {
else if (''===path.extname(fname) && fs.lstatSync(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;
......@@ -390,7 +390,13 @@ function recurseGetFileList(leverFolder)
}
return leverFileNames;
}
// replace the path separator in a lever subfolder path with a '*' so we can encode in a url
function encodeSubFolder(filename) {
filename=filename.replace(/\//g,'\*' );
filename=filename.replace(/\\/g,'\*');
return filename;
}
// ------------------------------------ LeverDB class -----------------------------------------------
......@@ -537,7 +543,7 @@ class LeverDB {
_getTrackFeatures(this._lDB,trackID,fnCallback);
} // getTrackFeatures
leverRead(leverFile, id, sanitizeRoot, fnCallback) {
leverRead(leverFile, id, ROOT, fnCallback) {
console.time('lever');
if (('undefined' !== typeof IS_NODE) && !IS_NODE) {
var editReq = new XMLHttpRequest();
......@@ -560,20 +566,16 @@ class LeverDB {
const fs = require('fs');
const sqlite3 = require('sqlite3').verbose();
const lineage = require('./lineage.js');
var leverStruct = {};
var sqlCmd = 'SELECT * from tblConstants';
var bSanitize = (undefined !== sanitizeRoot && null !== sanitizeRoot);
if (bSanitize) {
leverStruct.leverFile = encodeURI(path.basename(leverFile, '.LEVER'));
}
else {
leverStruct.leverFile = leverFile;
}
var leverStruct = {};
leverStruct.leverFile = leverFile.substring(ROOT.length+1);
leverStruct.leverFile = encodeSubFolder(leverStruct.leverFile);
// const dbUpdate = require('./dbUpdate.js');
// dbUpdate.update(leverFile, function() {
var leverDB = new LeverDB(leverFile);
leverDB.getConstants(function(CONSTANTS) {
if (bSanitize) {
if (leverFile.indexOf('http')>=0) {
delete (CONSTANTS.imageData.imageDir);
CONSTANTS.ui.rootImageFolder = leverStruct.leverFile + '/image';
}
......@@ -607,6 +609,9 @@ class LeverDB {
// remove root prefix from file names
for (var f=0;f<leverFileNames.length;f++) {
leverFileNames[f]=leverFileNames[f].substring(folder.length+1);
// for subdirs, replace '/' with '*' - this allows us to encode in url
// so, e.g. path/to/cool.LEVER becomes path*to*cool.LEVER
leverFileNames[f]=encodeSubFolder(leverFileNames[f]);
}
fnCallback(leverFileNames);
}
......
......@@ -110,12 +110,11 @@ function addToQ(leverCommand)
}
// first, see if the leverFile is in the processQ
var commandBase=path.basename(leverCommand.leverFile,'.LEVER');
for (var i=0;i<inProcessQ.length;i++) {
if (undefined===inProcessQ[i].leverFile || null===inProcessQ[i].leverFile)
continue;
var leverBase=path.basename(inProcessQ[i].leverFile,'.LEVER');
if (commandBase===leverBase) {
if (leverCommand.leverFile===inProcessQ[i].leverFile) {
// if status is idle, then we can use this spot, otherwise it goes on toProcessQ
getLeverFileStatus(leverCommand.leverFile,function(leverFile,status){
if ("idle"===status) {
......@@ -261,9 +260,7 @@ function getQ(fnCallback,hrInterval,bSanitizeFileName)
Q.hrtime=process.hrtime();
Q.toProcessQ=toProcessQ;
// for (var i=0;i<Q.toProcessQ.length;i++) {
// Q.toProcessQ[i].leverFile=path.basename(Q.toProcessQ[i].leverFile,'.LEVER');
// }
Q.inProcessQ=[];
// initialize the Q if needed
......@@ -281,8 +278,7 @@ function getQ(fnCallback,hrInterval,bSanitizeFileName)
}
else
ID=inProcessQ[i].ID;
if (bSanitizeFileName)
leverFile=path.basename(leverFile,'.LEVER');
processStatus={leverFile:leverFile,status:status,ID:ID,nSlot:i};
statusQ.push(processStatus);
if (inProcessQ.length===statusQ.length) {
......
......@@ -488,11 +488,10 @@ function reDraw(bForceUpdate){
webgl_render2D();
drawHulls(tCells[gImageTime]);
renderMitoses2D(gImageTime,tCells[gImageTime])
DrawSidebar();
renderMitoses2D(gImageTime,tCells[gImageTime]);
gbDrawComplete=true;
}
DrawSidebar();
//To prevent stutter/frame skipping
if(!gbLoadTextureInProgress && gbPlayMovie){
requestId = window.requestAnimationFrame(render);
......
......@@ -6,8 +6,7 @@ function openDB(ROOT,dbName)
const path=require('path');
const sqlite3=require('sqlite3').verbose();
dbName=decodeURI(dbName);
var leverFile = path.join(ROOT,dbName+'.LEVER');
var leverFile = path.join(ROOT,dbName);
const fs=require('fs');
if (!fs.existsSync(leverFile)) {
......@@ -204,7 +203,7 @@ function getImage(req,res)
// first, check in the current lever folder
var CONSTANTS_local=CONSTANTS;
CONSTANTS_local.ui.rootImageFolder=path.join(req.ROOT,CONSTANTS.imageData.DatasetName);
CONSTANTS_local.ui.rootImageFolder=path.join(path.dirname(req.leverFile),CONSTANTS.imageData.DatasetName);
var bFound=false;
var fname=getImageFileName(CONSTANTS_local,req);
if (fs.existsSync(fname)) {
......
......@@ -324,12 +324,13 @@ function buildEditProcessTables(Q)
for (var i=0;i<Q.inProcessQ.length;i++) {
var localLeverFile=decodeURI(g_db_path);
// replace the * with file delims
localLeverFile=localLeverFile.replace(/\*/g,'\/');
// convert both paths to use '/' for comparison only
localLeverFile=localLeverFile.replace(/\\/g,'\/');
var inProcessLeverFile=decodeURI(Q.inProcessQ[i].leverFile);
if (IS_NODE) {
const path=require('path');
localLeverFile=path.basename(localLeverFile,'.LEVER');
inProcessLeverFile=path.basename(inProcessLeverFile);
}
inProcessLeverFile=inProcessLeverFile.replace(/\\/g,'\/');
if (localLeverFile===inProcessLeverFile) {
// this is the one...
var status=Q.inProcessQ[i].status;
......
......@@ -67,17 +67,19 @@ else {
//--------------- auth0 end -------------------
function setLeverRoot(req,res,next)
{
app.param('LEVER', function (req, res, next, leverFile) {
req.ROOT=ROOT;
req.params.LEVER=decodeURI(req.params.LEVER);
req.params.LEVER=req.params.LEVER.replace(/\*/g,'\/');
req.leverFile=path.join(req.ROOT,req.params.LEVER);
next();
}
});
// called by split,undo,resegAll,resegNext,resegPause
function prepareCommand(req,res,command,params)
{
const process=require('./leverjs/process.js');
var leverFile=path.join(ROOT,decodeURI(req.params.LEVER)+'.LEVER');
var leverFile=req.leverFile;
var user='NA';
if (undefined!==req.user)
user=req.user['https://leverjs.net/email'];
......@@ -137,7 +139,7 @@ app.get('/hiFriend', function(req,res){
});
app.post('/:LEVER/createCells/',checkLWT, jsonParser,function(req,res) {
var leverFile=path.join(ROOT,decodeURI(req.params.LEVER)+'.LEVER');
var leverFile=req.leverFile;
const LeverDB=require();
var leverDB=new LeverDB(leverFile);
leverDB.createCells(req.body,function(cellIDs){
......@@ -150,6 +152,14 @@ app.post('/:LEVER/createCells/',checkLWT, jsonParser,function(req,res) {
app.get('/processQ', function(req,res) {
const process=require('./leverjs/process.js');
var Q=process.getQ(function(Q) {
// remove root from each
for (var i=0;i<Q.inProcessQ.length;i++) {
Q.inProcessQ[i].leverFile=Q.inProcessQ[i].leverFile.substring(ROOT.length+1);
}
for (var i=0;i<Q.toProcessQ.length;i++) {
Q.toProcessQ[i].leverFile=Q.toProcessQ[i].leverFile.substring(ROOT.length+1);
}
res.send(JSON.stringify(Q))
});
});
......@@ -207,7 +217,7 @@ app.post('/:LEVER/resegNext/:time', checkJwt,function(req,res) {
app.post('/:LEVER/resegPause/:time', checkJwt,function(req,res) {
// this goes straight into the commandTable -- no processQ
var leverFile=path.join(ROOT,decodeURI(req.params.LEVER)+'.LEVER');
var leverFile=req.leverFile;
const LeverDB=require('./leverjs/lever.js');
var leverDB=new LeverDB(leverFile);
var leverCommand={leverFile:leverFile,command:"resegPause",time:req.params.time};
......@@ -218,7 +228,7 @@ app.post('/:LEVER/resegPause/:time', checkJwt,function(req,res) {
});
app.post('/:LEVER/eraseAll', checkJwt,function(req,res) {
var leverFile=path.join(ROOT,decodeURI(req.params.LEVER)+'.LEVER');
var leverFile=req.leverFile;
const LeverDB=require('./leverjs/lever.js');
var leverDB=new LeverDB(leverFile);
leverDB.eraseAll(function(){
......@@ -240,7 +250,7 @@ app.post('/:LEVER/addToExtFamilies/:trackID/:time', checkJwt, function(req,res)
});
app.post('/:LEVER/CONSTANTS/', checkJwt, jsonParser, function(req,res) {
var leverFile=path.join(ROOT,decodeURI(req.params.LEVER)+'.LEVER');
var leverFile=req.leverFile;
const LeverDB=require('./leverjs/lever.js');
var leverDB=new LeverDB(leverFile);
var CONSTANTS=req.body;
......@@ -252,7 +262,7 @@ app.post('/:LEVER/CONSTANTS/', checkJwt, jsonParser, function(req,res) {
app.get('/:LEVER/trackFeatures/:trackID', function(req,res){
var leverFile=path.join(ROOT,decodeURI(req.params.LEVER)+'.LEVER');
var leverFile=req.leverFile;
const LeverDB=require('./leverjs/lever.js');
var leverDB=new LeverDB(leverFile);
var trackID=JSON.parse(req.params.trackID);
......@@ -262,7 +272,7 @@ app.get('/:LEVER/trackFeatures/:trackID', function(req,res){
})
app.get('/editStatus/:editID', checkJwt, setLeverRoot, function(req,res) {
app.get('/editStatus/:editID', checkJwt, function(req,res) {
const process=require('./leverjs/process.js');
var editID=JSON.parse(req.params.editID);
var status=process.getStatus(editID);
......@@ -272,86 +282,86 @@ app.get('/editStatus/:editID', checkJwt, setLeverRoot, function(req,res) {
res.status(202).send(status); // busy
});
app.get('/algorithms', setLeverRoot, function(req,res) {
app.get('/algorithms', function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.getAvailableAlgorithms(req,res)
});
app.get('/:LEVER/algorithms', setLeverRoot, function(req,res) {
app.get('/:LEVER/algorithms', function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.getAlgorithms(req,res);
});
app.post('/:LEVER/addAlgorithm/:algInfo', checkJwt, setLeverRoot, function(req,res) {
app.post('/:LEVER/addAlgorithm/:algInfo', checkJwt, function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.setAlgorithmInDB(req,res);
});
app.post('/:LEVER/removeAlgorithm/:algName', checkJwt, setLeverRoot, function(req,res) {
app.post('/:LEVER/removeAlgorithm/:algName', checkJwt, function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.removeAlgorithmFromDB(req,res,false);
});
app.post('/:LEVER/removeAllAlgorithms/', checkJwt, setLeverRoot, function(req,res) {
app.post('/:LEVER/removeAllAlgorithms/', checkJwt, function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.removeAlgorithmFromDB(req,res,true);
});
app.get('/:LEVER/cellPixels/:cellID', setLeverRoot, function(req,res) {
app.get('/:LEVER/cellPixels/:cellID', function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.getCellPixels(req,res);
});
app.get('/:LEVER/cellCentroids/:time', setLeverRoot, function(req,res) {
app.get('/:LEVER/cellCentroids/:time', function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.getCellCentroids(req,res);
});
app.get('/:LEVER/editList', setLeverRoot, function(req,res) {
app.get('/:LEVER/editList', function(req,res) {
const helper=require('./leverjs/serverHelper.js');
helper.getEditList(req,res);
});
app.get('/:LEVER/constants', setLeverRoot, function(req,res){
app.get('/:LEVER/constants', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getConstants(req,res);
});
app.get('/:LEVER/colorTable', setLeverRoot, function(req,res){
app.get('/:LEVER/colorTable', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getColorTable(req,res);
});
app.get('/:LEVER/image/:time/p_:pack/l_:mrLevel/v_:mrChunk', setLeverRoot, function(req,res){
app.get('/:LEVER/image/:time/p_:pack/l_:mrLevel/v_:mrChunk', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getImage(req,res);
});
app.get('/:LEVER/image/:time', setLeverRoot, function(req,res){
app.get('/:LEVER/image/:time', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getImage(req,res);
});
app.get('/:LEVER/image/:time/:channel', setLeverRoot, function(req,res){
app.get('/:LEVER/image/:time/:channel', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getImage(req,res);
});
app.get('/:LEVER/cells/:time/c_:channelList', setLeverRoot, function(req,res){
app.get('/:LEVER/cells/:time/c_:channelList', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getCells(req,res);
});
app.get('/:LEVER/cells/:time', setLeverRoot, function(req,res){
app.get('/:LEVER/cells/:time', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getCells(req,res);
});
app.get('/:LEVER/families', setLeverRoot, function(req,res){
app.get('/:LEVER/families', function(req,res){
const helper=require('./leverjs/serverHelper.js');
helper.getFamilies(req,res);
});
app.get('/lever', setLeverRoot, function(req,res){
app.get('/lever', function(req,res){
const LeverDB=require('./leverjs/lever.js');
var leverDB=new LeverDB();
leverDB.leverGetFileList(ROOT,function(leverFileList){
......@@ -365,7 +375,7 @@ app.get('/:LEVER/lever', function (req, res) {
var leverDB=new LeverDB();
var leverFile=decodeURI(req.params.LEVER);
leverFile = path.join(ROOT,leverFile);
leverDB.leverRead(leverFile,0,req.headers.host,function(err,leverStruct){
leverDB.leverRead(leverFile,0,ROOT,function(err,leverStruct){
if(err) {
res.status(400).send(JSON.stringify(err));
}
......
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