[#138] move saveQuery to ViewCtrl

This commit is contained in:
Amir Nissim
2014-03-23 15:37:52 +02:00
parent 5ffd2615e7
commit 4493d22ec9
2 changed files with 25 additions and 25 deletions

View File

@@ -13,29 +13,6 @@
$scope.newVisualization = undefined;
$scope.saveQuery = function(duplicate, oldId) {
if (!oldId) {
oldId = $scope.query.id;
}
delete $scope.query.latest_query_data;
$scope.query.$save(function(savedQuery) {
$scope.isDirty = false;
if (duplicate) {
growl.addSuccessMessage("Query forked");
} else {
growl.addSuccessMessage("Query saved");
}
if (oldId != savedQuery.id) {
$location.url($location.url().replace(oldId, savedQuery.id)).replace();
}
}, function(httpResponse) {
growl.addErrorMessage("Query could not be saved");
});
};
$scope.deleteVisualization = function($e, vis) {
$e.preventDefault();
if (confirm('Are you sure you want to delete ' + vis.name + ' ?')) {

View File

@@ -1,7 +1,7 @@
(function() {
'use strict';
function QueryViewCtrl($scope, $route, $location, notifications, Query) {
function QueryViewCtrl($scope, $route, $location, notifications, Query, growl) {
var DEFAULT_TAB = 'table';
$scope.query = $route.current.locals.query;
@@ -15,6 +15,29 @@
$scope.queryExecuting = lock;
};
$scope.saveQuery = function(duplicate, oldId) {
if (!oldId) {
oldId = $scope.query.id;
}
delete $scope.query.latest_query_data;
$scope.query.$save(function(savedQuery) {
$scope.isDirty = false;
if (duplicate) {
growl.addSuccessMessage("Query forked");
} else {
growl.addSuccessMessage("Query saved");
}
if (oldId != savedQuery.id) {
$location.url($location.url().replace(oldId, savedQuery.id)).replace();
}
}, function(httpResponse) {
growl.addErrorMessage("Query could not be saved");
});
};
$scope.duplicateQuery = function() {
var oldId = $scope.query.id;
$scope.query.id = null;
@@ -100,5 +123,5 @@
angular.module('redash.controllers')
.controller('QueryViewCtrl',
['$scope', '$route', '$location', 'notifications', 'Query', QueryViewCtrl]);
['$scope', '$route', '$location', 'notifications', 'Query', 'growl', QueryViewCtrl]);
})();