Commit 97b8399b authored by Yuanle Song's avatar Yuanle Song
Browse files

add clearTrail, clearStack, reset features

add function in fsm and add relevant buttons on UI.
parent 01b1b38b
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -65,10 +65,11 @@
	  height: 30px;
      }
      .trail-op {
	  min-width: 10px;
	  min-width: 40px;
	  text-align: right;
      }
      .trail-num {
	  padding-left: 10px;
	  min-width: 10px;
	  text-align: left;
      }
@@ -81,11 +82,11 @@
  <body>
    <div id="container">
      <div id="stack">
	<p>Stack</p>
	<p>Stack <a title="clear stack" id="clear-stack" href="#">Clear Stack</a></p>
	<div id="stack-content"></div>
      </div>
      <div id="keyboard">
	<p>Keyboard</p>
	<p>Keyboard <a title="reset RPN calculator" id="reset" href="#">Reset All</a></p>
	<div class="keyboard">
	  <table>
	    <tr>
@@ -128,7 +129,7 @@
	</div>
      </div>
      <div id="trail">
	<p>Trail</p>
	<p>Trail <a title="clear trail" id="clear-trail" href="#">Clear Trail</a></p>
	<div id="trail-content"></div>
      </div>
    </div>
@@ -393,8 +394,8 @@
		  trNode.append($('<td>').text(trailNum).addClass("trail-num"));
		  trailTable.append(trNode);
	      }
	      if (trailSize > 0) {
	      $("#trail-content").children().remove();
	      if (trailSize > 0) {
		  $("#trail-content").append(trailTable).scrollTop(900); // TODO how to scroll to bottom?
	      }
	  };
@@ -420,6 +421,21 @@
		  updateUI(rpnCalculator);
	      }
	  });
	  $('#clear-trail').click(function (evt) {
	      rpnCalculator.clearTrail();
	      updateUI(rpnCalculator);
	      return false;
	  });
	  $('#clear-stack').click(function (evt) {
	      rpnCalculator.clearStack();
	      updateUI(rpnCalculator);
	      return false;
	  });
	  $('#reset').click(function (evt) {
	      rpnCalculator.reset();
	      updateUI(rpnCalculator);
	      return false;
	  });
      }());
    </script>
  </body>
+19 −1
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@ var fifo = function () {
	this.pop = function () {
	    return this.data.shift();
	};
	this.clear = function () {
	    this.data = [];
	};
    };

    /**
@@ -40,6 +43,9 @@ var fifo = function () {
	this.pop = function () {
	    return this.data.shift();
	};
	this.clear = function () {
	    this.data = [];
	};
    };

    const testFIFO = function () {
@@ -68,9 +74,21 @@ var fifo = function () {
	console.assert(q.pop() === 3);
	console.assert(q.pop() === 4);
    };
    const testClearFunction = function () {
	q = new BoundedQueue(3);
	q.push(1);
	q.push(2);
	q.clear();
	console.assert(q.pop() === undefined);
	console.assert(q.data.length === 0);
    };
    const runAllTests = function () {
	testFIFO();
	testClearFunction();
    };

    // run all tests
    testFIFO();
    runAllTests();

    return {
	Queue: Queue,
+13 −0
Original line number Diff line number Diff line
@@ -433,6 +433,19 @@ var fsm = function () {
	    this.clearErrorMsg();
    	    return this.currentState;
    	};
	this.clearTrail = function () {
	    this.trail.clear();
	};
	this.clearStack = function () {
	    this.numberStack = [];
	};
	this.reset = function () {
	    this.currentState = stateIdle;
    	    this.numberStack = [];
    	    this.currentNumber = "";
	    this.lastError = null;
	    this.trail = new fifo.BoundedQueue(trailHistorySize);
	};

	const runTests = function () {
	    testChangeNumberString();
+13 −1
Original line number Diff line number Diff line
@@ -48,7 +48,18 @@ the parent DOM.

* current                                                             :entry:
** 
** 2017-01-27 add a reset button. browser refresh button is not always easily accessible, esp on mobile.
** 2017-01-27 design a layout for mobile.
- layout on mobile:
  stack

  keyboard

  trail

- stack and trail has smaller height as well.
- 200+300+200=700
  apply css when width < 720.

** 2017-01-27 make trail work
- when is trail being updated?
  - when a number is committed to number stack. return.
@@ -98,6 +109,7 @@ trail cache. it's not a problem.
- DONE make DUP and SWP work
- make trail work
* done                                                                :entry:
** 2017-01-27 add a reset button. browser refresh button is not always easily accessible, esp on mobile.
** 2017-01-27 stack, trail: overflow problem.
- when there is not enough room, show scrollbar.
- always show the title section.