mirror of
https://github.com/getredash/redash.git
synced 2025-12-25 01:03:20 -05:00
[#138] move saveQuery to ViewCtrl
This commit is contained in:
@@ -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 + ' ?')) {
|
||||
|
||||
@@ -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]);
|
||||
})();
|
||||
Reference in New Issue
Block a user