fixed bugs and cleanup

This commit is contained in:
Chris Cromer 2016-07-26 21:27:29 -04:00
parent 0a7f973068
commit 78a6c2e6fa
6 changed files with 99 additions and 93 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,5 +1,5 @@
var fileContents = new Array();
var fileNames = new Array();
var fileContents = [];
var fileNames = [];
function handleFileSelect(evt) {
evt.stopPropagation();
@ -46,8 +46,8 @@ function compareFiles(fileContents, fileNames) {
}
function resetArrays() {
fileNames = new Array();
fileContents = new Array();
fileNames = [];
fileContents = [];
}
function handleDragOver(evt) {

View File

@ -67,7 +67,7 @@ body {
}
.scrollcode {
margin: 0px auto;
margin: 0 auto;
width: 100%;
height: 300px;
overflow: scroll;
@ -75,11 +75,10 @@ body {
}
.scrollresult {
margin: 0px auto;
margin: 0 auto;
width: 100%;
height: 300px;
overflow: scroll;
overflow-x: scroll;
}
.input_prompt {
@ -126,7 +125,7 @@ body {
text-align: center;
width: 100%;
color: #FF0000;
margin: 0px auto;
margin: 0 auto;
}
.blur {
@ -137,7 +136,6 @@ body {
top: 0;
bottom: 0;
z-index: 900;
background-color: #000000;
opacity: 0.7;
visibility: hidden;
}

View File

@ -32,8 +32,7 @@
<div id="input_prompt" class="input_prompt">
<span class="input_prompt_vertical">
{{strings.input_value}}
<input autocomplete="off" type="text" name="rda" id="rda" />
<label for="rda">{{strings.input_value}}</label><input autocomplete="off" type="text" name="rda" id="rda"/>
<input ng-click="rda_value_received();" type="button" value="Ingresar" />
</span>
</div>
@ -43,13 +42,18 @@
<table class="title_table">
<tr>
<td class="blank_title_cell"><img src="ubblogo.png" /></td>
<td class="project_name">{{strings.project_name}} <input type="text" id="project_name" name="project_name" value="" /></td>
<td class="project_name"><label for="project_name">{{strings.project_name}} </label><input type="text"
id="project_name"
name="project_name"
value=""/></td>
<td class="options">
<input ng-click="show_help();" type="button" value="{{strings.help}}" />
<label>
<select ng-change="change_language();" ng-model="language">
<option value="0">{{strings.spanish}}</option>
<option value="1">{{strings.english}}</option>
</select>
</label>
</td>
</tr>
</table>
@ -62,8 +66,16 @@
<table align="center" class="table_background">
<tr ng-repeat="(key, line) in code_lines">
<td id="line1_{{key}}" ng-click="select_line(key, false);" class="table_cell line_number_td" >{{line.line}}</td>
<td id="line2_{{key}}" class="table_cell"><select ng-model="line.command" ng-options="command.name for command in commands"></select></td>
<td id="line3_{{key}}" class="table_cell"><input type="text" ng-model="line.value" /></td>
<td id="line2_{{key}}" class="table_cell">
<label>
<select ng-model="line.command" ng-options="command.name for command in commands"></select>
</label>
</td>
<td id="line3_{{key}}" class="table_cell">
<label>
<input type="text" ng-model="line.value"/>
</label>
</td>
</tr>
</table>
</div>
@ -125,6 +137,7 @@
<input ng-click="execute_code();" id="execute_code" type="button" value="{{strings.execute_code}}" />
<input ng-click="pause_code();" id="pause_code" type="button" value="{{strings.pause_code}}" disabled="disabled" />
<input ng-click="stop_code();" id="stop_code" type="button" value="{{strings.stop_code}}" disabled="disabled" />
<label>
{{strings.interval}}
<select ng-change="change_speed();" ng-model="speed">
<option value="0">0</option>
@ -134,15 +147,16 @@
<option value="4">4</option>
<option value="5">5</option>
</select>
</label>
</td>
</tr>
</table>
<div class="credits">
<b>JVON Web</b><br />
{{strings.credits_description}}&nbsp;<b>{{strings.credits_john}}</b><br />
{{strings.credits_cromer}}<br />
Ingeniería Civil en Informática, Universidad del Bío Bío, 2015<br />
<a target="_blank" href="jvon-1.0.0.0.apk">Version android</href>
<b>JVON Web</b><br/>
{{strings.credits_description}}&nbsp;<b>{{strings.credits_john}}</b><br/>
{{strings.credits_cromer}}<br/>
Ingeniería Civil en Informática, Universidad del Bío Bío, 2015<br/>
<a target="_blank" href="jvon-1.0.0.0.apk">Version android</a>
</div>
</body>
</html>

View File

@ -1,4 +1,5 @@
// This is the angular controller and the code pane
//noinspection JSUnresolvedFunction
var jvonapp = angular.module("JVON", ["ngTouch", "ngSanitize"]);
jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", function ($scope, $timeout ,$interval) {
@ -6,13 +7,13 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
$scope.commands = commands;
// The code pane
$scope.code_lines = new Array();
$scope.code_lines = [];
// The result pane
$scope.results = new Array();
$scope.results = [];
// What is displayed on the screen
$scope.screen = new Array();
$scope.screen = [];
$scope.execution_started = false;
@ -67,14 +68,14 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
}
else {
$interval.cancel($scope.blink_promise);
element = document.getElementById("pause_code");
var element = document.getElementById("pause_code");
element.style.opacity = 1;
element.style.filter = "alpha(opacity=" + 1 * 100 + ")";
element.style.filter = "alpha(opacity=100)";
}
};
$scope.blink = function () {
element = document.getElementById("pause_code");
var element = document.getElementById("pause_code");
if ($scope.blink_state == false) {
if ($scope.opacity <= 0.1) {
$scope.blink_state = true;
@ -177,7 +178,8 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
if ($scope.code_lines.length > 0) {
// Find the last highlighted line
var highlighted = null;
for (var i = $scope.code_lines.length - 1; i >= 0; i--) {
var i;
for (i = $scope.code_lines.length - 1; i >= 0; i--) {
if ($scope.code_lines[i].highlighted == true) {
highlighted = i;
break;
@ -188,9 +190,9 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
}
// Add a line after the last highlighted
var new_code_lines = new Array();
var new_code_lines = [];
var j = 1;
for (var i = 0; i < $scope.code_lines.length; i++) {
for (i = 0; i < $scope.code_lines.length; i++) {
if (highlighted == i) {
$scope.code_lines[i].line = j.toString();
new_code_lines.push($scope.code_lines[i]);
@ -217,7 +219,7 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
// Delete the highlighted lines
$scope.delete_line = function () {
var new_code_lines = new Array();
var new_code_lines = [];
var j = 1;
for (var i = 0; i < $scope.code_lines.length; i++) {
if (!$scope.code_lines[i].highlighted) {
@ -231,17 +233,18 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
// Delete all code lines
$scope.clear_code = function () {
$scope.code_lines = new Array();
$scope.code_lines = [];
};
$scope.select_line = function (line_number, result) {
var line;
// If execution finished remove all highlights
if ($scope.finished == true) {
$scope.finished = false;
for (var i = 0; i < $scope.code_lines.length; i++) {
if ($scope.code_lines[i].highlighted == true) {
// Unhighlight
var line;
line = document.getElementById("line1_" + i.toString());
line.className = line.className.substring(0,line.className.length - 21);
line = document.getElementById("line2_" + i.toString());
@ -256,7 +259,6 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
if ($scope.executing == true && result == true) {
if ($scope.code_lines[line_number].highlighted == false) {
// Highlight
var line;
line = document.getElementById("line1_" + line_number.toString());
line.className += " code_number_selected";
line = document.getElementById("line2_" + line_number.toString());
@ -267,7 +269,6 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
}
else {
// Unhighlight
var line;
line = document.getElementById("line1_" + line_number.toString());
line.className = line.className.substring(0,line.className.length - 21);
line = document.getElementById("line2_" + line_number.toString());
@ -280,7 +281,6 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
else if ($scope.executing == false && result == false) {
if ($scope.code_lines[line_number].highlighted == false) {
// Highlight
var line;
line = document.getElementById("line1_" + line_number.toString());
line.className += " line_number_selected";
line = document.getElementById("line2_" + line_number.toString());
@ -291,7 +291,6 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
}
else {
// Unhighlight
var line;
line = document.getElementById("line1_" + line_number.toString());
line.className = line.className.substring(0,line.className.length - 21);
line = document.getElementById("line2_" + line_number.toString());
@ -380,7 +379,7 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
};
// Watch for changes to the code from external sources and update accordingly
$scope.$watch('imported_code',function(newValue, oldValue) {
$scope.$watch('imported_code', function (newValue) {
if (newValue) {
$scope.code_lines = newValue;
$scope.imported_code = false;
@ -417,7 +416,7 @@ jvonapp.controller('JVONController', ["$scope", "$timeout", "$interval", functio
jvonapp.directive("importFile", function () {
return {
restrict: "A",
link: function ($scope, element, attributes) {
link: function ($scope, element) {
element.bind('change', function (event) {
var file = event.target.files[0];
@ -435,9 +434,9 @@ jvonapp.directive("importFile", function () {
$scope.select_line(i, true);
}
}
$scope.code_lines = new Array();
$scope.code_lines = [];
$scope.$apply();
}
};
reader.readAsText(file);
}

View File

@ -18,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.finished = false;
$scope.ac = "";
$scope.memory = new Array();
$scope.memory = [];
$scope.memory[0] = null; // 80
$scope.memory[1] = null; // 81
$scope.memory[2] = null; // 82
@ -39,8 +39,8 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.disable_code_buttons();
$scope.results = new Array();
$scope.screen = new Array();
$scope.results = [];
$scope.screen = [];
$scope.line_number = 0;
$scope.repeater();
}
@ -135,7 +135,7 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.pow($scope.code_lines[$scope.line_number].value);
break;
case "End":
$scope.End($scope.code_lines[$scope.line_number].value);
$scope.End();
break;
default:
alert($scope.code_lines[$scope.line_number].command.name + " is not implemented yet.");
@ -148,12 +148,13 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.check_syntax = function (value) {
var result;
var regex;
if (value == "") {
return {type: "blank", value: ""};
}
var regex = /^(\d+)$/;
regex = /^(\d+)$/;
if ((result = regex.exec(value)) !== null) {
if (result.index === regex.lastIndex) {
regex.lastIndex++;
@ -162,7 +163,7 @@ document.addEventListener('DOMContentLoaded', function () {
return {type: "memory", value: result[1]};
}
var regex = /^\[(\d+)\]$/;
regex = /^\[(\d+)]$/;
if ((result = regex.exec(value)) !== null) {
if (result.index === regex.lastIndex) {
regex.lastIndex++;
@ -171,7 +172,7 @@ document.addEventListener('DOMContentLoaded', function () {
return {type: "address", value: result[1]};
}
var regex = /^#(-?[0-9]*?\.?[0-9]+)$/;
regex = /^#(-?[0-9]*?\.?[0-9]+)$/;
if ((result = regex.exec(value)) !== null) {
if (result.index === regex.lastIndex) {
regex.lastIndex++;
@ -185,18 +186,12 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.check_memory_address = function(value) {
value = parseFloat(value);
if (value < 80 || value > 85) {
return false;
}
return true;
return !(value < 80 || value > 85);
};
$scope.check_memory_value = function(value) {
value = parseFloat(value) - 80;
if ($scope.memory[value] == null) {
return false;
}
return true;
return $scope.memory[value] != null;
};
$scope.rda = function (value) {
@ -223,9 +218,8 @@ document.addEventListener('DOMContentLoaded', function () {
var new_memory = $scope.memory[syntax.value];
var regex = /^\d+$/;
var result;
if ((result = regex.exec(new_memory)) !== null && $scope.check_memory_address(new_memory) == true) {
if (regex.exec(new_memory) !== null && $scope.check_memory_address(new_memory) == true) {
$scope.rda_value = new_memory;
$scope.show_input_prompt();
}
@ -245,9 +239,8 @@ document.addEventListener('DOMContentLoaded', function () {
var value = document.getElementById("rda").value;
var regex = /^-?[0-9]*?\.?[0-9]+$/;
var result;
if ((result = regex.exec(value)) !== null) {
if (regex.exec(value) !== null) {
value = parseFloat(value);
$scope.rda_value = parseFloat($scope.rda_value);
@ -329,7 +322,7 @@ document.addEventListener('DOMContentLoaded', function () {
}
else if (syntax.type == "memory") {
if ($scope.check_memory_address(value) == true) {
new_value = parseFloat(value) - 80;
var new_value = parseFloat(value) - 80;
$scope.memory[new_value] = $scope.ac;
$scope.create_result($scope.line_number, parseFloat(value), $scope.ac);
@ -350,9 +343,8 @@ document.addEventListener('DOMContentLoaded', function () {
var new_memory = $scope.memory[syntax.value];
var regex = /^\d+$/;
var result;
if ((result = regex.exec(new_memory)) !== null && $scope.check_memory_address(new_memory) == true) {
if (regex.exec(new_memory) !== null && $scope.check_memory_address(new_memory) == true) {
new_memory = parseFloat(new_memory) - 80;
$scope.memory[new_memory] = $scope.ac;
@ -519,13 +511,13 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.div = function (value) {
var syntax = $scope.check_syntax(value);
var regex;
if (syntax.type == "number") {
$scope.ac = parseFloat($scope.ac) / parseFloat(syntax.value);
var regex = /^-?[0-9]*\.?[0-9]+$/;
var result;
regex = /^-?[0-9]*\.?[0-9]+$/;
if ((result = regex.exec($scope.ac)) !== null) {
if (regex.exec($scope.ac) !== null) {
$scope.create_result($scope.line_number, "ac", $scope.ac);
$scope.line_number++;
$scope.repeater();
@ -540,10 +532,9 @@ document.addEventListener('DOMContentLoaded', function () {
value = $scope.memory[value - 80];
$scope.ac = parseFloat($scope.ac) / parseFloat(value);
var regex = /^-?[0-9]*\.?[0-9]+$/;
var result;
regex = /^-?[0-9]*\.?[0-9]+$/;
if ((result = regex.exec($scope.ac)) !== null) {
if (regex.exec($scope.ac) !== null) {
$scope.create_result($scope.line_number, "ac", $scope.ac);
$scope.line_number++;
$scope.repeater();
@ -564,10 +555,9 @@ document.addEventListener('DOMContentLoaded', function () {
value = parseFloat($scope.memory[temp_value - 80]);
$scope.ac = parseFloat($scope.ac) / value;
var regex = /^-?[0-9]*\.?[0-9]+$/;
var result;
regex = /^-?[0-9]*\.?[0-9]+$/;
if ((result = regex.exec($scope.ac)) !== null) {
if (regex.exec($scope.ac) !== null) {
$scope.create_result($scope.line_number, "ac", $scope.ac);
$scope.line_number++;
$scope.repeater();
@ -686,13 +676,14 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.sqr = function (value) {
var syntax = $scope.check_syntax(value);
var sqr;
if (syntax.type == "blank") {
if ($scope.ac == "") {
alert($scope.strings.error_ac);
$scope.stop_code();
}
else {
var sqr = Math.sqrt(parseFloat($scope.ac));
sqr = Math.sqrt(parseFloat($scope.ac));
if (sqr == "NaN") {
alert($scope.strings.error_math);
$scope.stop_code();
@ -706,7 +697,7 @@ document.addEventListener('DOMContentLoaded', function () {
}
}
else if (syntax.type == "number") {
var sqr = Math.sqrt(syntax.value);
sqr = Math.sqrt(parseFloat(syntax.value));
if (sqr == "NaN") {
alert($scope.strings.error_math);
$scope.stop_code();
@ -721,7 +712,7 @@ document.addEventListener('DOMContentLoaded', function () {
else if (syntax.type == "memory") {
if ($scope.check_memory_address(value) == true && $scope.check_memory_value(value) == true) {
value = parseFloat($scope.memory[value - 80]);
var sqr = Math.sqrt(value);
sqr = Math.sqrt(value);
if (sqr == "NaN") {
alert($scope.strings.error_math);
$scope.stop_code();
@ -742,7 +733,7 @@ document.addEventListener('DOMContentLoaded', function () {
var temp_value = $scope.memory[syntax.value - 80];
if ($scope.check_memory_address(temp_value) == true && $scope.check_memory_value(temp_value) == true) {
value = parseFloat($scope.memory[temp_value - 80]);
var sqr = Math.sqrt(value);
sqr = Math.sqrt(value);
if (sqr == "NaN") {
alert($scope.strings.error_math);
$scope.stop_code();
@ -767,9 +758,9 @@ document.addEventListener('DOMContentLoaded', function () {
$scope.pow = function (value) {
var syntax = $scope.check_syntax(value);
var new_value;
if (syntax.type == "number") {
if ($scope.ac != "" || $scope.ac == 0) {
var new_value;
value = parseFloat(syntax.value);
if (value < 0) {
// The exponent is negative
@ -793,7 +784,6 @@ document.addEventListener('DOMContentLoaded', function () {
else if (syntax.type == "memory") {
if ($scope.check_memory_address(value) == true) {
value = parseFloat($scope.memory[value - 80]);
var new_value;
if (value < 0) {
// The exponent is negative
value = Math.abs(parseFloat(value));
@ -817,7 +807,6 @@ document.addEventListener('DOMContentLoaded', function () {
var temp_value = $scope.memory[syntax.value - 80];
if ($scope.check_memory_address(temp_value) == true) {
value = parseFloat($scope.memory[temp_value - 80]);
var new_value;
if (value < 0) {
// The exponent is negative
value = Math.abs(parseFloat(value));
@ -850,9 +839,9 @@ document.addEventListener('DOMContentLoaded', function () {
else {
return base * $scope.pow_repeat(exponent -1, base);
}
}
};
$scope.End = function (value) {
$scope.End = function () {
// Rap-up everything
$scope.stop_code();
};