Skip to content

Commit

Permalink
controller.js line 128: if (!tessel && opts.root)
Browse files Browse the repository at this point in the history
tests pass this way - but we need to discuss some things (others tests
have to be rewritten to remove opts.root).
  • Loading branch information
Student007 committed Sep 14, 2015
1 parent c6e687b commit 0ddb61d
Showing 1 changed file with 54 additions and 55 deletions.
109 changes: 54 additions & 55 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,18 @@ Tessel.get = function(opts) {

// Run the heuristics to pick which Tessel to use
return controller.runHeuristics(opts, tessels)
.then(function(tessel){
if(!tessel){
controller.menu.prepareMenu(opts, tessels, resolve, reject,'Please select the default Tessel 2', function(name,index,resolve,reject){
if(!name && name === 'EXIT'){
.then(function(tessel) {
if (!tessel && opts.root) {
controller.menu.prepareMenu(opts, tessels, resolve, reject, 'Please select the default Tessel 2', function(name, index, resolve, reject) {
if (!name && name === 'EXIT') {
reject('No Tessel selected!');
}
logs.info('Selected Tessel: '+name);
logAndFinish(tessels[index]);
logs.info('Selected Tessel: ' + name);
logAndFinish(tessels[index]);
});
} else {
logAndFinish(tessel);
}
logAndFinish(tessel);
}
});
});
}
Expand Down Expand Up @@ -167,8 +167,8 @@ Tessel.get = function(opts) {
// The Tessels that we won't be using should have their connections closed
var connectionsToClose = tessels;
if (tessel) {
if(opts.root){
if (opts.root) {

controller.closeTesselConnections(connectionsToClose)
.then(function() {
controller.ssh.runSSH(0, opts, tessels, resolve, reject);
Expand Down Expand Up @@ -203,7 +203,6 @@ may or may not be open and closes them
controller.closeTesselConnections = function(tessels) {
return new Promise(function(resolve, reject) {
async.each(tessels, function closeThem(tessel, done) {
console.log('error: ',tessel);
// If not an unauthorized LAN Tessel, it's connected
if (!(tessel.lanConnection &&
!tessel.lanConnection.authorized)) {
Expand Down Expand Up @@ -668,51 +667,51 @@ controller.menu = {

prepareMenu: function(opts, tessels, resolve, reject, title, callback) {
//return new Promise(function(resolve, reject) {

var rtm = new Menu({
// width: process.stdout.columns - 4,
width: 55,
x: 1,
y: 2,
bg: 'red'
});
rtm.reset();
rtm.write(title + '\n');
rtm.write(' \n');

// create menu entries
for (var i in tessels) {
controller.menu.makeMenu(tessels[i], i, rtm);
}

rtm.add('EXIT\n');
rtm._draw();
if (!opts.menu) {
// if this is no test, starting the menu as child process
controller.menu.showMenu(rtm, resolve, reject);
} else {
// because the test needs to resolve the promise ...
resolve({
opts: opts,
tessels: tessels
});
}
var rtm = new Menu({
// width: process.stdout.columns - 4,
width: 55,
x: 1,
y: 2,
bg: 'red'
});
rtm.reset();
rtm.write(title + '\n');
rtm.write(' \n');

rtm.once('select', function(label, index) {
rtm.close();
controller.menu.clear();
// create menu entries
for (var i in tessels) {
controller.menu.makeMenu(tessels[i], i, rtm);
}

// Identify the Exit command by first letter (all other entries start with numbers/index)
if (label[0] !== 'E') {
callback(tessels[index].name, index, resolve, reject);
// controller.ssh.runSSH(index, opts, tessels, resolve, reject);
} else {
// going to clear screen and calling exit to resolve promise
controller.menu.clear();
controller.menu.exit(resolve);
}
rtm.add('EXIT\n');
rtm._draw();
if (!opts.menu) {
// if this is no test, starting the menu as child process
controller.menu.showMenu(rtm, resolve, reject);
} else {
// because the test needs to resolve the promise ...
resolve({
opts: opts,
tessels: tessels
});
// });
}

rtm.once('select', function(label, index) {
rtm.close();
controller.menu.clear();

// Identify the Exit command by first letter (all other entries start with numbers/index)
if (label[0] !== 'E') {
callback(tessels[index].name, index, resolve, reject);
// controller.ssh.runSSH(index, opts, tessels, resolve, reject);
} else {
// going to clear screen and calling exit to resolve promise
controller.menu.clear();
controller.menu.exit(resolve);
}
});
// });
},
makeMenu: function(tessel, index, rtm) {
if (tessel.lanConnection) {
Expand All @@ -728,7 +727,7 @@ controller.menu = {
} else {
rtm.add(index + ') ' + tessel.name + ': [USB] (authorized) \n');
}
}
}
// FIXME: Workaround for trouble with dynamic added menu elements
rtm._draw();
},
Expand Down Expand Up @@ -867,8 +866,8 @@ controller.root = function(opts) {
opts.root = true;
return new Promise(function(resolve, reject) {
controller.menu.seek(opts)
.then(resolve)
.catch(reject);
.then(resolve)
.catch(reject);
});
};

Expand Down

0 comments on commit 0ddb61d

Please sign in to comment.