Fix: view going into infinite loop of calling getQueryResult.

This commit is contained in:
Arik Fraimovich 2014-07-06 18:17:23 +03:00
parent 62ab1fda80
commit bc0a5160ac
3 changed files with 16 additions and 20 deletions

View File

@ -111,26 +111,23 @@
scope.editRawOptions = currentUser.hasPermission('edit_raw_chart');
scope.visTypes = Visualization.visualizationTypes;
scope.newVisualization = function (q) {
scope.newVisualization = function () {
return {
'query_id': q.id,
'type': Visualization.defaultVisualization.type,
'name': Visualization.defaultVisualization.name,
'description': q.description || '',
'description': '',
'options': Visualization.defaultVisualization.defaultOptions
};
}
if (!scope.visualization) {
// create new visualization
// wait for query to load to populate with defaults
var unwatch = scope.$watch('query', function (q) {
if (q && q.id) {
var unwatch = scope.$watch('query.id', function (queryId) {
if (queryId) {
unwatch();
scope.visualization = scope.newVisualization(q);
scope.visualization = scope.newVisualization();
}
}, true);
});
}
scope.$watch('visualization.type', function (type, oldType) {
@ -148,6 +145,8 @@
Events.record(currentUser, "create", "visualization", null, {'type': scope.visualization.type});
}
scope.visualization.query_id = scope.query.id;
Visualization.save(scope.visualization, function success(result) {
growl.addSuccessMessage("Visualization saved");

View File

@ -33,9 +33,8 @@
$scope.chartSeries = [];
$scope.chartOptions = {};
// TODO: add delay to reloadData?
var reloadData = function(data) {
if (!data || $scope.queryResult.getData() == null) {
var reloadData = _.throttle(function(data) {
if (!data || ($scope.queryResult && $scope.queryResult.getData()) == null) {
$scope.chartSeries.splice(0, $scope.chartSeries.length);
} else {
$scope.chartSeries.splice(0, $scope.chartSeries.length);
@ -51,7 +50,7 @@
$scope.chartSeries.push(_.extend(s, additional));
});
}
};
}, 500);
$scope.$watch('options', function (chartOptions) {
if (chartOptions) {
@ -72,7 +71,7 @@
reloadData(data);
});
}]
}
};
});
chartVisualization.directive('chartEditor', function () {
@ -121,8 +120,8 @@
var chartOptionsUnwatch = null,
columnsWatch = null;
scope.$watch('visualization', function (visualization) {
if (visualization && visualization.type == 'CHART') {
scope.$watch('visualization.type', function (visualizationType) {
if (visualizationType == 'CHART') {
if (scope.visualization.options.series.stacking === null) {
scope.stacking = "none";
} else if (scope.visualization.options.series.stacking === undefined) {
@ -131,7 +130,7 @@
scope.stacking = scope.visualization.options.series.stacking;
}
columnsWatch = scope.$watchCollection('query.getQueryResult().getId()', function(id) {
columnsWatch = scope.$watch('queryResult.getId()', function(id) {
if (!id) {
return;
}
@ -165,8 +164,6 @@
});
});
scope.$watchCollection('columnTypeSelection', function(selections) {
_.each(scope.columnTypeSelection, function(type, name) {
scope.visualization.options.columnMapping[name] = type;

View File

@ -172,7 +172,7 @@
<div ng-show="selectedTab == 'add'">
<visualization-renderer visualization="newVisualization" query-result="queryResult"></visualization-renderer>
<edit-visulatization-form visualization="newVisualization" query="query" ng-show="canEdit" open-editor="true" on-new-success="setVisualizationTab"></edit-visulatization-form>
<edit-visulatization-form visualization="newVisualization" query="query" query-result="queryResult" ng-show="canEdit" open-editor="true" on-new-success="setVisualizationTab"></edit-visulatization-form>
</div>
</div>
</div>