# HG changeset patch # User phrebejk # Date 1358880490 -3600 # Node ID 7400dc9f48fb3f40429fa08a670156ca0e9b29cc # Parent 927a5f9fa43054e4891622d0f98ae68e92704f1c Error badges + auto reload. diff -r 927a5f9fa430 -r 7400dc9f48fb launcher/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css Mon Jan 21 22:10:08 2013 +0100 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/css/app.css Tue Jan 22 19:48:10 2013 +0100 @@ -39,3 +39,16 @@ } +.issues { + width: 16px; +} + +.issue { + height: 16px; + width: 16px; + vertical-align: middle; + background-repeat: no-repeat; + background-image: url("../img/error.png"); + /* color: #822; */ +} + diff -r 927a5f9fa430 -r 7400dc9f48fb launcher/src/main/resources/org/apidesign/bck2brwsr/dew/img/error.png Binary file launcher/src/main/resources/org/apidesign/bck2brwsr/dew/img/error.png has changed diff -r 927a5f9fa430 -r 7400dc9f48fb launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html Mon Jan 21 22:10:08 2013 +0100 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html Tue Jan 22 19:48:10 2013 +0100 @@ -56,7 +56,7 @@ Java
- +
{{doc.modelError.toString()}}
diff -r 927a5f9fa430 -r 7400dc9f48fb launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Mon Jan 21 22:10:08 2013 +0100 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Tue Jan 22 19:48:10 2013 +0100 @@ -120,19 +120,59 @@ + "}\n"; + $scope.makeMarker = function( editor, line ) { + var marker = document.createElement("div"); + marker.innerHTML = " "; + marker.className = "issue"; + + var info = editor.lineInfo(line); + editor.setGutterMarker(line, "issues", info.markers ? null : marker); + + return marker; + }; + + + // Returns a function, that, as long as it continues to be invoked, will not + // be triggered. The function will be called after it stops being called for + // N milliseconds. If `immediate` is passed, trigger the function on the + // leading edge, instead of the trailing. + $scope.debounce = function(func, wait, immediate) { + var timeout, result; + return function() { + var context = this, args = arguments; + var later = function() { + timeout = null; + if (!immediate) result = func.apply(context, args); + }; + var callNow = immediate && !timeout; + clearTimeout(timeout); + timeout = setTimeout(later, wait); + if (callNow) result = func.apply(context, args); + return result; + }; + }; + $scope.reload = function() { $scope.errors = null; var frame = document.getElementById("result"); frame.src = "result.html"; frame.contentDocument.location.reload(true); frame.contentWindow.location.reload(); + document.getElementById("editorJava").codeMirror.clearGutter("issues"); }; $scope.fail = function( data ) { $scope.errors = eval( data ); + var editor = document.getElementById("editorJava").codeMirror; + editor.clearGutter( "issues" ); + + for( var i = 0; i < $scope.errors.length; i ++ ) { + $scope.makeMarker( editor, $scope.errors[i].line - 1 ); + } + }; - $scope.post = function(html, java) { + $scope.post = function() { return $http({url: ".", method: "POST", //headers: this.headers, @@ -151,7 +191,7 @@ $scope.gotoError = function( line, col ) { var editor = document.getElementById("editorJava").codeMirror; - editor.setCursor({ line: line - 1, ch : col }); + editor.setCursor({ line: line - 1, ch : col - 1 }); editor.focus(); }; @@ -159,11 +199,8 @@ $scope.html= templateHtml; $scope.java = templateJava; - $scope.tabActive = function( tab ) { - return tab === $scope.tab ? "active" : ""; - }; - - // $scope.$watch( "html", htmlChange ); + $scope.$watch( "html", $scope.debounce( $scope.post, 2000 ) ); + $scope.$watch( "java", $scope.debounce( $scope.post, 2000 ) ); $scope.post(); }