Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support for JSON query formatting (Mongo, ElasticSearch) #1129

Merged
merged 1 commit into from
Jun 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions rd_ui/app/scripts/directives/query_directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
};
}

function queryFormatter($http) {
function queryFormatter($http, growl) {
return {
restrict: 'E',
// don't create new scope to avoid ui-codemirror bug
Expand All @@ -165,18 +165,29 @@
template: '<button type="button" class="btn btn-default btn-s"\
ng-click="formatQuery()">\
<span class="zmdi zmdi-format-indent-increase"></span>\
Format SQL\
Format Query\
</button>',
link: function($scope) {
$scope.formatQuery = function formatQuery() {
if ($scope.dataSource.syntax == 'json') {
try {
$scope.query.query = JSON.stringify(JSON.parse($scope.query.query), ' ', 4);
} catch(err) {
growl.addErrorMessage(err);
}
} else if ($scope.dataSource.syntax =='sql') {

$scope.queryFormatting = true;
$http.post('api/queries/format', {
'query': $scope.query.query
'query': $scope.query.query
}).success(function (response) {
$scope.query.query = response;
$scope.query.query = response;
}).finally(function () {
$scope.queryFormatting = false;
});
} else {
growl.addInfoMessage("Query formatting is not supported for your data source syntax.");
}
};
}
}
Expand Down Expand Up @@ -290,5 +301,5 @@
.directive('queryEditor', queryEditor)
.directive('queryRefreshSelect', queryRefreshSelect)
.directive('queryTimePicker', queryTimePicker)
.directive('queryFormatter', ['$http', queryFormatter]);
.directive('queryFormatter', ['$http', 'growl', queryFormatter]);
})();