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

View File

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

View File

@ -172,7 +172,7 @@
<div ng-show="selectedTab == 'add'"> <div ng-show="selectedTab == 'add'">
<visualization-renderer visualization="newVisualization" query-result="queryResult"></visualization-renderer> <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> </div>
</div> </div>