Skip to content

Commit

Permalink
Bit of work towards #658 and some work towards fixing some error the …
Browse files Browse the repository at this point in the history
…source viewer is throwing...
  • Loading branch information
gashcrumb committed Nov 4, 2013
1 parent 1b970d5 commit fd9bef0
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 110 deletions.
3 changes: 3 additions & 0 deletions hawtio-web/src/main/webapp/app/maven/js/helpers.ts
@@ -1,4 +1,7 @@
module Maven {

export var log:Logging.Logger = Logger.get("Maven");

/**
* Returns the maven indexer mbean (from the hawtio-maven-indexer library)
*/
Expand Down
2 changes: 2 additions & 0 deletions hawtio-web/src/main/webapp/app/source/html/index.html
Expand Up @@ -13,6 +13,8 @@
</div>

<div class="wiki-fixed row-fluid">
<p></p>
<p></p>
<div class="control-group inline-block">
<input class="search-query input-xxlarge" type="text" ng-model="searchText" placeholder="Filter files...">
</div>
Expand Down
7 changes: 6 additions & 1 deletion hawtio-web/src/main/webapp/app/source/html/source.html
Expand Up @@ -16,10 +16,15 @@
</div>
</div>

<div class="wiki-fixed form-horizontal">
<div class="wiki-fixed">
<p></p>
<p></p>
<div class="control-group editor-autoresize">
<textarea id="source" ui-codemirror="codeMirrorOptions" ng-model="source"></textarea>
</div>
<!--
<div hawtio-editor="source" mode="mode" read-only="true" on-change="onChange(codeMirror)"></div>
-->
</div>

<div class="wiki-fixed row-fluid" ng-show="loadingMessage">
Expand Down
2 changes: 2 additions & 0 deletions hawtio-web/src/main/webapp/app/source/js/helpers.ts
@@ -1,5 +1,7 @@
module Source {

export var log:Logging.Logger = Logger.get("Source");

export function getInsightMBean(workspace) {
var mavenStuff = workspace.mbeanTypesToDomain["LogQuery"] || {};
var insight = mavenStuff["org.fusesource.insight"] || {};
Expand Down
25 changes: 16 additions & 9 deletions hawtio-web/src/main/webapp/app/source/js/index.ts
Expand Up @@ -19,7 +19,10 @@ module Source {
filterFileNames();
};

$scope.$watch('workspace.tree', function () {
$scope.$watch('workspace.tree', function (newValue, oldValue) {
if (newValue === oldValue) {
return;
}
if (!$scope.git && Git.getGitMBean(workspace)) {
// lets do this asynchronously to avoid Error: $digest already in progress
//console.log("Reloading the view as we now seem to have a git mbean!");
Expand Down Expand Up @@ -79,20 +82,24 @@ module Source {
}
filterFileNames();
$scope.loadingMessage = null;
if (!response) {
var time = new Date().getTime();
if (!$scope.lastErrorTime || time - $scope.lastErrorTime > 3000) {
$scope.lastErrorTime = time;
notification("error", "Could not download the source code for the maven artifacts: " + $scope.mavenCoords);
}
}
Core.$apply($scope);
}

function updateView() {
if (!$scope.mavenCoords) {
return;
}
var mbean = Source.getInsightMBean(workspace);
if (mbean) {
jolokia.execute(mbean, "getSource", $scope.mavenCoords, null, "/", onSuccess(viewContents));
jolokia.execute(mbean, "getSource", $scope.mavenCoords, null, "/", {
success: viewContents,
error: (response) => {
log.error("Failed to download the source code for the maven artifact: ", $scope.mavenCoords);
log.info("Stack trace: ", response.stacktrace);
$scope.loadingMessage = "Could not download index, please see console for details"
Core.$apply($scope);
}
});
}
}

Expand Down
40 changes: 30 additions & 10 deletions hawtio-web/src/main/webapp/app/source/js/source.ts
Expand Up @@ -70,7 +70,26 @@ module Source {
};
$scope.codeMirrorOptions = CodeEditor.createEditorSettings(options);

$scope.$watch('workspace.tree', function () {
$scope.onChange = (codeMirror) => {
log.debug("codeMirror: ", codeMirror);
if (codeMirror) {
lineNumber -= 1;
var lineText = codeMirror.getLine(lineNumber);
var endChar = (lineText) ? lineText.length : 1000;
var start = {line: lineNumber, ch: 0};
var end = {line: lineNumber, ch: endChar};
codeMirror.scrollIntoView(start);
codeMirror.setCursor(start);
codeMirror.setSelection(start, end);
codeMirror.refresh();
codeMirror.focus();
}
};

$scope.$watch('workspace.tree', function (oldValue, newValue) {
if (newValue === oldValue) {
return;
}
if (!$scope.git && Git.getGitMBean(workspace)) {
// lets do this asynchronously to avoid Error: $digest already in progress
//console.log("Reloading the view as we now seem to have a git mbean!");
Expand All @@ -86,21 +105,22 @@ module Source {
function viewContents(response) {
$scope.source = response;
$scope.loadingMessage = null;
if (!response) {
var time = new Date().getTime();
if (!$scope.lastErrorTime || time - $scope.lastErrorTime > 3000) {
$scope.lastErrorTime = time;
notification("error", "Could not download the source code for the maven artifacts: " + mavenCoords);
}
}
Core.$apply($scope);
}

function updateView() {
var mbean = Source.getInsightMBean(workspace);
if (mbean) {
jolokia.execute(mbean, "getSource", mavenCoords, className, fileName, onSuccess(viewContents));
jolokia.execute(mbean, "getSource", mavenCoords, className, fileName, {
success: viewContents,
error: (response) => {
log.error("Failed to download the source code for the maven artifact: ", mavenCoords);
log.info("Stack trace: ", response.stacktrace);
$scope.loadingMessage = "Could not download file, please see console for details"
Core.$apply($scope);
}
});
}
}
}
}
}
191 changes: 103 additions & 88 deletions hawtio-web/src/main/webapp/app/ui/js/editorDirective.ts
@@ -1,116 +1,131 @@
module UI {

export class Editor {
export function Editor($parse) {

public restrict = 'A';
public replace = true;
return {

public templateUrl = UI.templatePath + "editor.html";
restrict: 'A',
replace: true,

public scope = {
text: '=hawtioEditor',
mode: '=',
dirty: '=',
name: '@'
};
templateUrl: UI.templatePath + "editor.html",

public controller = ($scope, $element, $attrs) => {
scope: {
text: '=hawtioEditor',
mode: '=',
dirty: '=',
name: '@'
},

$scope.codeMirror = null;
$scope.doc = null;
$scope.options = [];
controller: ($scope, $element, $attrs) => {

observe($scope, $attrs, 'name', 'editor');
$scope.codeMirror = null;
$scope.doc = null;
$scope.options = [];

$scope.applyOptions = () => {
if ($scope.codeMirror) {
$scope.options.each(function(option) {
$scope.codeMirror.setOption(option.key, option['value']);
});
$scope.options = [];
}
};

$scope.$watch('doc', () => {
if ($scope.doc) {
$scope.codeMirror.on('change', function(changeObj) {
var phase = $scope.$parent.$$phase;
if (!phase) {
$scope.text = $scope.doc.getValue();
$scope.dirty = !$scope.doc.isClean();
Core.$applyNowOrLater($scope);
}
});
}
});
observe($scope, $attrs, 'name', 'editor');

$scope.$watch('codeMirror', () => {
if ($scope.codeMirror) {
$scope.doc = $scope.codeMirror.getDoc();
}
});
$scope.applyOptions = () => {
if ($scope.codeMirror) {
$scope.options.each(function(option) {
$scope.codeMirror.setOption(option.key, option['value']);
});
$scope.options = [];
}
};

$scope.$watch('doc', () => {
if ($scope.doc) {
$scope.codeMirror.on('change', function(changeObj) {
var phase = $scope.$parent.$$phase;
if (!phase) {
$scope.text = $scope.doc.getValue();
$scope.dirty = !$scope.doc.isClean();
Core.$applyNowOrLater($scope);
}
});
}
});

$scope.$watch('text', function(oldValue, newValue) {
if ($scope.codeMirror && $scope.doc) {
if (!$scope.codeMirror.hasFocus()) {
$scope.doc.setValue($scope.text);
$scope.$watch('codeMirror', () => {
if ($scope.codeMirror) {
$scope.doc = $scope.codeMirror.getDoc();
}
}
});
});

};
$scope.$watch('text', function(oldValue, newValue) {
if ($scope.codeMirror && $scope.doc) {
if (!$scope.codeMirror.hasFocus()) {
$scope.doc.setValue($scope.text);
}
}
});

},

public link = ($scope, $element, $attrs) => {
link: ($scope, $element, $attrs) => {

var config = Object.extended($attrs).clone();
var config = Object.extended($attrs).clone();

delete config['$$element']
delete config['$attr'];
delete config['class'];
delete config['hawtioEditor'];
delete config['mode'];
delete config['dirty'];
delete config['$$element']
delete config['$attr'];
delete config['class'];
delete config['hawtioEditor'];
delete config['mode'];
delete config['dirty'];

angular.forEach(config, function(value, key) {
$scope.options.push({
key: key,
'value': value
if ('onChange' in $attrs) {
var onChange = $attrs['onChange'];
delete config['onChange'];
$scope.options.push({
onChange: (codeMirror) => {
var func = $parse(onChange);
if (func) {
func($scope.$parent, { codeMirror:codeMirror });
}
}
});
}

angular.forEach(config, function(value, key) {
$scope.options.push({
key: key,
'value': value
});
});
});

$scope.$watch('mode', () => {
if ($scope.mode) {
if (!$scope.codeMirror) {
$scope.options.push({
key: 'mode',
'value': $scope.mode
});
} else {
$scope.codeMirror.setOption('mode', $scope.mode);
$scope.$watch('mode', () => {
if ($scope.mode) {
if (!$scope.codeMirror) {
$scope.options.push({
key: 'mode',
'value': $scope.mode
});
} else {
$scope.codeMirror.setOption('mode', $scope.mode);
}
}
}
});
});

$scope.$watch('dirty', () => {
if ($scope.dirty && !$scope.doc.isClean()) {
$scope.doc.markClean();
}
});
$scope.$watch('dirty', () => {
if ($scope.dirty && !$scope.doc.isClean()) {
$scope.doc.markClean();
}
});

$scope.$watch('text', function() {
if (!$scope.codeMirror) {
$scope.$watch('text', function() {
if (!$scope.codeMirror) {

var options:any = {
value: $scope.text
};
var options:any = {
value: $scope.text
};

options = CodeEditor.createEditorSettings(options);
$scope.codeMirror = CodeMirror.fromTextArea($element.find('textarea').get(0), options);
$scope.applyOptions();
}
});
options = CodeEditor.createEditorSettings(options);
$scope.codeMirror = CodeMirror.fromTextArea($element.find('textarea').get(0), options);
$scope.applyOptions();
}
});
}

};

}
}
4 changes: 2 additions & 2 deletions hawtio-web/src/main/webapp/app/ui/js/uiPlugin.ts
Expand Up @@ -18,8 +18,8 @@ module UI {
directive('hawtioPager', function() {
return new UI.TablePager();
}).
directive('hawtioEditor', function() {
return new UI.Editor();
directive('hawtioEditor', function($parse) {
return UI.Editor($parse);
}).directive('hawtioColorPicker', function() {
return new UI.ColorPicker()
}).directive('hawtioFileUpload', () => {
Expand Down

0 comments on commit fd9bef0

Please sign in to comment.