This commit is contained in:
Christopher Valles 2014-02-25 18:14:47 +00:00
parent d73dbdeee0
commit 8be95262d4
4 changed files with 45 additions and 15 deletions

View File

@ -92,10 +92,15 @@
})
}
$scope.saveQuery = function (duplicate, oldId) {
$scope.saveQuery = function (duplicate, oldId, updateUrl) {
if (!oldId) {
oldId = $scope.query.id;
}
if (updateUrl == undefined) {
updateUrl = true;
}
delete $scope.query.latest_query_data;
$scope.query.$save(function (q) {
pristineHash = q.getHash();
@ -108,7 +113,7 @@
}
if (oldId != q.id) {
if (oldId == undefined) {
if (oldId == undefined && updateUrl) {
$location.path($location.path().replace('new', q.id)).replace();
} else {
// TODO: replace this with a safer method

View File

@ -46,7 +46,7 @@
}
}]);
directives.directive('editVisulatizationForm', ['Visualization', 'growl', function(Visualization, growl) {
directives.directive('editVisulatizationForm', ['Visualization', 'growl', '$location', function(Visualization, growl, $location) {
return {
restrict: 'E',
templateUrl: '/views/edit_visualization.html',
@ -76,7 +76,7 @@
};
scope.stacking = "none";
if (!scope.vis) {
// create new visualization
// wait for query to load to populate with defaults
@ -149,17 +149,42 @@
};
scope.submit = function() {
if (!scope.query.id) {
scope.$parent.saveQuery(false, null, false);
var unwatch = scope.$watch('query', function(q) {
if (q && q.id) {
unwatch();
scope.vis['query_id'] = q.id;
scope.saveVisualization(false);
$location.path($location.path().replace('new', q.id)).replace();
}
}, true);
} else {
scope.saveVisualization();
}
};
scope.saveVisualization = function(updateTabs) {
if (updateTabs == undefined) {
updateTabs = true;
}
Visualization.save(scope.vis, function success(result) {
growl.addSuccessMessage("Visualization saved");
scope.vis = result;
var visIds = _.pluck(scope.query.visualizations, 'id');
var index = visIds.indexOf(result.id);
if (index > -1) {
scope.query.visualizations[index] = result;
} else {
scope.query.visualizations.push(result);
if (updateTabs) {
scope.vis = result;
var visIds = _.pluck(scope.query.visualizations, 'id');
var index = visIds.indexOf(result.id);
if (index > -1) {
scope.query.visualizations[index] = result;
} else {
scope.query.visualizations.push(result);
}
}
}, function error() {
growl.addErrorMessage("Visualization could not be saved");

View File

@ -210,7 +210,7 @@
scope.chart.series[0].remove(false);
};
if (_.some(scope.series[0].data, function (p) {
if (scope.series.length > 0 && _.some(scope.series[0].data, function (p) {
return angular.isString(p.x)
})) {
scope.chart.xAxis[0].update({type: 'category'});

View File

@ -279,7 +279,7 @@
Query.prototype.getHash = function() {
return [this.name, this.description, this.query].join('!#');
};
return Query;
};