Skip to content

Commit

Permalink
Provide way to specify result line when starting a target
Browse files Browse the repository at this point in the history
Fixes: #19
Signed-off-by: Nathan Cutler <[email protected]>
  • Loading branch information
smithfarm committed Sep 25, 2017
1 parent adf62d3 commit daa8744
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 29 deletions.
64 changes: 41 additions & 23 deletions share/js/core/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,54 @@ define ([
// pop a target and its state off the stack
// ARG1 (optional) - object to be merged into stateObj
// ARG2 (optional) - boolean, whether to call start() (default: true)
pop = function (mo, start) {
start = (start === false) ? false : true;
console.log("Entering stack.pop() with stack", _stack);
var stackObj,
type;
pop = function (mo, opts) {
console.log("Entering stack.pop() with object", mo, "and opts", opts);
var resultLine,
stackState,
stackTarget;

// process opts
if (typeof opts !== "object") {
opts = {};
}
opts['resultLine'] = ('resultLine' in opts) ? opts.resultLine : false;
opts['start'] = ('start' in opts) ? opts.start : true;

// pop item off the stack
_stack.pop();
if (_stack.length === 0) {
console.log("Stack empty - logging out");
target.pull('logout').start();
target.pull('logout').start("Logged out due to stack exhaustion");
return;
}
stackObj = _stack[_stack.length - 1];
console.log(
"After pop, stack length is " + getLength() +
" and top target is " + getTarget()
);
if (typeof mo === 'object') {
console.log("pop() was passed an object", mo);
$.extend(stackObj.state, mo);
stackState = getState();
$.extend(stackState, mo);
setState(stackState);
}
stackObj.push = false;
console.log("Popped " + stackObj.target.name);
type = stackObj.target.type;
if (start) {
lib.clearResult();
stackObj.target.start();
setPush(false);
if (opts.start) {
getTarget().start(opts.resultLine);
}
},

popWithoutStart = function (mo) {
pop(mo, false);
pop(mo, {"start": false});
},

// push a target and its state onto the stack
push = function (tgt, obj, opts) {
console.log("Entering stack.push() with target", tgt, "object", obj, "and opts", opts);
// console.log("and stack", _stack);
var flag,
resultLine,
xtarget;
if (obj === undefined || obj === null) {
if (typeof obj !== 'object' || obj === undefined || obj === null) {
obj = {};
}
if (typeof tgt === "string") {
Expand All @@ -106,21 +118,23 @@ define ([
console.log("ERROR in stack.push() - found no target object");
return;
}
if (typeof opts === "object") {
flag = ('flag' in opts) ? opts.flag : false;
xtarget = ('xtarget' in opts) ? opts.xtarget : null;
console.log("In stack.push(), setting flag", flag, "and xtarget", xtarget);
if (typeof opts !== "object") {
opts = {};
}
opts.flag = ('flag' in opts) ? opts.flag : false;
opts.xtarget = ('xtarget' in opts) ? opts.xtarget : null;
opts.resultLine = ('resultLine' in opts) ? opts.resultLine : null;
console.log("stack.push() opts", opts);
if (tgt.pushable) {
_stack.push({
"flag": flag,
"flag": opts.flag,
"push": true,
"resultLine": opts.resultLine,
"state": obj,
"target": tgt,
"xtarget": xtarget
"xtarget": opts.xtarget
});
}
lib.clearResult();
tgt.start(obj);
},

Expand All @@ -133,6 +147,9 @@ define ([
getPush = function () {
return _stack[_stack.length - 1].push;
},
getResultLine = function () {
return _stack[_stack.length - 1].resultLine;
},
getStack = function () {
// returns the entire stack
return _stack;
Expand Down Expand Up @@ -227,6 +244,7 @@ define ([
"getFlag": getFlag,
"getLength": getLength,
"getPush": getPush,
"getResultLine": getResultLine,
"getStack": getStack,
"getState": getState,
"getTarget": getTarget,
Expand Down
20 changes: 14 additions & 6 deletions share/js/core/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ define ([
}
};
},
dbrowserListen = function () {
dbrowserListen = function (resultLine) {
var dbo = lib.dbrowserState.obj,
set = lib.dbrowserState.set,
pos = lib.dbrowserState.pos;
Expand All @@ -308,8 +308,12 @@ define ([
console.log("Browser set is", set, "cursor position is " + pos);
$('#mainarea').html(dbo.source(set, pos));
// lib.holdObject(set[pos]); // hold object so hooks can get it
$('#result').html("Displaying no. " + (pos + 1) + " of " +
lib.genObjStr(set.length) + " in result set");
if (resultLine) {
lib.displayResult(resultLine);
} else {
lib.displayResult("Displaying no. " + (pos + 1) + " of " +
lib.genObjStr(set.length) + " in result set");
}
$('#' + dbo.name).submit(suppressSubmitEvent);
$('input[name="sel"]').val('').focus();
$('#submitButton').on("click", function (event) {
Expand Down Expand Up @@ -443,11 +447,16 @@ define ([
var dfo = target.pull(dfn);
return function (obj) {
console.log('Entering start.dform with argument: ' + dfn);
var resultLine = stack.getResultLine();
if (resultLine) {
lib.displayResult(resultLine);
} else {
lib.clearResult();
}
if (! obj) {
obj = stack.getState();
}
console.log('The object we are working with is:', obj);
// lib.clearResult();
$('#mainarea').html(dfo.source(obj));
dformListen(dfn, obj);
};
Expand All @@ -460,7 +469,6 @@ define ([
// initialization (i.e., one-time event) -- generate and
// return the start function for this dbrowser
return function (obj) {
lib.clearResult();
console.log('Starting new ' + dbn + ' dbrowser with object', obj);
if (! obj) {
obj = stack.getState();
Expand All @@ -475,7 +483,7 @@ define ([
lib.dbrowserState.pos = obj.pos;
}
// start browsing
dbrowserListen();
dbrowserListen(stack.getResultLine());
};
}
}, // dbrowser
Expand Down

0 comments on commit daa8744

Please sign in to comment.