Error badges + auto reload.
1.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css Mon Jan 21 22:10:08 2013 +0100
1.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css Tue Jan 22 19:48:10 2013 +0100
1.3 @@ -39,3 +39,16 @@
1.4
1.5 }
1.6
1.7 +.issues {
1.8 + width: 16px;
1.9 +}
1.10 +
1.11 +.issue {
1.12 + height: 16px;
1.13 + width: 16px;
1.14 + vertical-align: middle;
1.15 + background-repeat: no-repeat;
1.16 + background-image: url("../img/error.png");
1.17 + /* color: #822; */
1.18 +}
1.19 +
2.1 Binary file launcher/src/main/resources/org/apidesign/bck2brwsr/dew/img/error.png has changed
3.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html Mon Jan 21 22:10:08 2013 +0100
3.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html Tue Jan 22 19:48:10 2013 +0100
3.3 @@ -56,7 +56,7 @@
3.4 <tr><td><i class="ic-java"></i> Java</td></tr>
3.5 </table>
3.6 <div>
3.7 - <textarea id="editorJava" ui-codemirror='{ lineNumbers : true, mode : "text/x-java", theme : "elegant", matchBrackets : true, lineWrapping : true }' ng-model="java"></textarea>
3.8 + <textarea id="editorJava" ui-codemirror='{ lineNumbers : true, mode : "text/x-java", theme : "elegant", matchBrackets : true, lineWrapping : true, gutters: ["CodeMirror-linenumbers", "issues"] }' ng-model="java"></textarea>
3.9 <div class="alert alert-error" ng-show="doc.modelError">
3.10 <small>{{doc.modelError.toString()}}</small>
3.11 </div>
4.1 --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Mon Jan 21 22:10:08 2013 +0100
4.2 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Tue Jan 22 19:48:10 2013 +0100
4.3 @@ -120,19 +120,59 @@
4.4 + "}\n";
4.5
4.6
4.7 + $scope.makeMarker = function( editor, line ) {
4.8 + var marker = document.createElement("div");
4.9 + marker.innerHTML = " ";
4.10 + marker.className = "issue";
4.11 +
4.12 + var info = editor.lineInfo(line);
4.13 + editor.setGutterMarker(line, "issues", info.markers ? null : marker);
4.14 +
4.15 + return marker;
4.16 + };
4.17 +
4.18 +
4.19 + // Returns a function, that, as long as it continues to be invoked, will not
4.20 + // be triggered. The function will be called after it stops being called for
4.21 + // N milliseconds. If `immediate` is passed, trigger the function on the
4.22 + // leading edge, instead of the trailing.
4.23 + $scope.debounce = function(func, wait, immediate) {
4.24 + var timeout, result;
4.25 + return function() {
4.26 + var context = this, args = arguments;
4.27 + var later = function() {
4.28 + timeout = null;
4.29 + if (!immediate) result = func.apply(context, args);
4.30 + };
4.31 + var callNow = immediate && !timeout;
4.32 + clearTimeout(timeout);
4.33 + timeout = setTimeout(later, wait);
4.34 + if (callNow) result = func.apply(context, args);
4.35 + return result;
4.36 + };
4.37 + };
4.38 +
4.39 $scope.reload = function() {
4.40 $scope.errors = null;
4.41 var frame = document.getElementById("result");
4.42 frame.src = "result.html";
4.43 frame.contentDocument.location.reload(true);
4.44 frame.contentWindow.location.reload();
4.45 + document.getElementById("editorJava").codeMirror.clearGutter("issues");
4.46 };
4.47
4.48 $scope.fail = function( data ) {
4.49 $scope.errors = eval( data );
4.50 + var editor = document.getElementById("editorJava").codeMirror;
4.51 + editor.clearGutter( "issues" );
4.52 +
4.53 + for( var i = 0; i < $scope.errors.length; i ++ ) {
4.54 + $scope.makeMarker( editor, $scope.errors[i].line - 1 );
4.55 + }
4.56 +
4.57 };
4.58
4.59 - $scope.post = function(html, java) {
4.60 + $scope.post = function() {
4.61 return $http({url: ".",
4.62 method: "POST",
4.63 //headers: this.headers,
4.64 @@ -151,7 +191,7 @@
4.65
4.66 $scope.gotoError = function( line, col ) {
4.67 var editor = document.getElementById("editorJava").codeMirror;
4.68 - editor.setCursor({ line: line - 1, ch : col });
4.69 + editor.setCursor({ line: line - 1, ch : col - 1 });
4.70 editor.focus();
4.71 };
4.72
4.73 @@ -159,11 +199,8 @@
4.74 $scope.html= templateHtml;
4.75 $scope.java = templateJava;
4.76
4.77 - $scope.tabActive = function( tab ) {
4.78 - return tab === $scope.tab ? "active" : "";
4.79 - };
4.80 -
4.81 - // $scope.$watch( "html", htmlChange );
4.82 + $scope.$watch( "html", $scope.debounce( $scope.post, 2000 ) );
4.83 + $scope.$watch( "java", $scope.debounce( $scope.post, 2000 ) );
4.84 $scope.post();
4.85
4.86 }