mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
Merge pull request #55 from EverythingMe/feature-queryform
use ngForm in queryFiddle page for detecting pristine and dirty states
This commit is contained in:
commit
1865ca945b
@ -35,10 +35,9 @@
|
||||
|
||||
var QueryFiddleCtrl = function ($scope, $window, $routeParams, $http, $location, growl, notifications, Query) {
|
||||
var leavingPageText = "You will lose your changes if you leave";
|
||||
var pristineQuery = null;
|
||||
|
||||
$window.onbeforeunload = function(){
|
||||
if (currentUser.canEdit($scope.query) && $scope.queryChanged) {
|
||||
if (currentUser.canEdit($scope.query) && $scope.queryForm.$dirty) {
|
||||
return leavingPageText;
|
||||
}
|
||||
}
|
||||
@ -60,7 +59,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if($scope.queryChanged &&
|
||||
if($scope.queryForm.$dirty &&
|
||||
!confirm(leavingPageText + "\n\nAre you sure you want to leave this page?")) {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
@ -92,8 +91,7 @@
|
||||
}
|
||||
delete $scope.query.latest_query_data;
|
||||
$scope.query.$save(function (q) {
|
||||
pristineQuery = q.query;
|
||||
$scope.queryChanged = false;
|
||||
$scope.queryForm.$setPristine();
|
||||
|
||||
if (duplicate) {
|
||||
growl.addInfoMessage("Query duplicated.", {ttl: 2000});
|
||||
@ -186,7 +184,7 @@
|
||||
|
||||
if ($routeParams.queryId != undefined) {
|
||||
$scope.query = Query.get({id: $routeParams.queryId}, function(q) {
|
||||
pristineQuery = q.query;
|
||||
$scope.queryForm.$setPristine();
|
||||
$scope.queryResult = $scope.query.getQueryResult();
|
||||
});
|
||||
} else {
|
||||
@ -197,11 +195,6 @@
|
||||
$scope.$watch('query.name', function() {
|
||||
$scope.$parent.pageTitle = $scope.query.name;
|
||||
});
|
||||
$scope.$watch('query.query', function(q) {
|
||||
if (q) {
|
||||
$scope.queryChanged = (q != pristineQuery);
|
||||
}
|
||||
});
|
||||
|
||||
$scope.executeQuery = function() {
|
||||
$scope.queryResult = $scope.query.getQueryResult(0);
|
||||
|
@ -1,5 +1,6 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<form name="queryForm">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">
|
||||
@ -23,7 +24,7 @@
|
||||
<div class="btn-group pull-right">
|
||||
<button type="button" class="btn btn-default" ng-click="duplicateQuery()">Duplicate</button>
|
||||
<button type="button" class="btn btn-default" ng-disabled="!currentUser.canEdit(query)" ng-click="saveQuery()">Save
|
||||
<span ng-show="queryChanged">*</span>
|
||||
<span ng-show="queryForm.$dirty">*</span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary" ng-disabled="queryExecuting" ng-click="executeQuery()">Execute</button>
|
||||
</div>
|
||||
@ -48,6 +49,7 @@
|
||||
<button type="button" class="btn btn-warning btn-xs pull-right" ng-disabled="cancelling" ng-click="cancelExecution()">Cancel</button>
|
||||
</div>
|
||||
<div class="alert alert-danger" ng-show="queryResult.getError()">Error running query: <strong>{{queryResult.getError()}}</strong></div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="row" ng-show="queryResult.getStatus() == 'done'">
|
||||
|
Loading…
Reference in New Issue
Block a user