Feature: download dataset button in dashboard

This commit is contained in:
Arik Fraimovich 2014-05-19 16:28:25 +03:00
parent 2b524075d9
commit 30f98e9796
4 changed files with 29 additions and 14 deletions

View File

@ -107,19 +107,6 @@
} }
$scope.filters = $scope.queryResult.getFilters(); $scope.filters = $scope.queryResult.getFilters();
if ($scope.queryResult.getId() == null) {
$scope.dataUri = "";
} else {
$scope.dataUri =
'/api/queries/' + $scope.query.id + '/results/' +
$scope.queryResult.getId() + '.csv';
$scope.dataFilename =
$scope.query.name.replace(" ", "_") +
moment($scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") +
".csv";
}
}); });
$scope.$watch("queryResult && queryResult.getStatus()", function(status) { $scope.$watch("queryResult && queryResult.getStatus()", function(status) {

View File

@ -38,6 +38,27 @@
} }
} }
function queryResultCSVLink() {
return {
restrict: 'A',
link: function (scope, element) {
console.log('hello world');
scope.$watch('queryResult && queryResult.getData()', function(data) {
if (!data) {
return;
}
if (scope.queryResult.getId() == null) {
element.attr('href', '');
} else {
element.attr('href', '/api/queries/' + scope.query.id + '/results/' + scope.queryResult.getId() + '.csv');
element.attr('download', scope.query.name.replace(" ", "_") + moment(scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") + ".csv");
}
});
}
}
}
function queryEditor() { function queryEditor() {
return { return {
restrict: 'E', restrict: 'E',
@ -135,6 +156,7 @@
angular.module('redash.directives') angular.module('redash.directives')
.directive('queryLink', queryLink) .directive('queryLink', queryLink)
.directive('querySourceLink', querySourceLink) .directive('querySourceLink', querySourceLink)
.directive('queryResultLink', queryResultCSVLink)
.directive('queryEditor', queryEditor) .directive('queryEditor', queryEditor)
.directive('queryRefreshSelect', queryRefreshSelect) .directive('queryRefreshSelect', queryRefreshSelect)
.directive('queryFormatter', ['$http', queryFormatter]); .directive('queryFormatter', ['$http', queryFormatter]);

View File

@ -44,6 +44,12 @@
<a class="btn btn-default btn-xs" ng-href="/queries/{{query.id}}#{{widget.visualization.id}}" ng-show="currentUser.hasPermission('view_query')"><span class="glyphicon glyphicon-link"></span></a> <a class="btn btn-default btn-xs" ng-href="/queries/{{query.id}}#{{widget.visualization.id}}" ng-show="currentUser.hasPermission('view_query')"><span class="glyphicon glyphicon-link"></span></a>
<button type="button" class="btn btn-default btn-xs" ng-show="dashboard.canEdit()" ng-click="deleteWidget()" title="Remove Widget"><span class="glyphicon glyphicon-trash"></span></button> <button type="button" class="btn btn-default btn-xs" ng-show="dashboard.canEdit()" ng-click="deleteWidget()" title="Remove Widget"><span class="glyphicon glyphicon-trash"></span></button>
</span> </span>
<span class="pull-right">
<a class="btn btn-default btn-xs" ng-disabled="!queryResult.getData()" query-result-link target="_self">
<span class="glyphicon glyphicon-cloud-download"></span>
</a>
</span>
</div> </div>
</div> </div>

View File

@ -122,7 +122,7 @@
<hr> <hr>
<p> <p>
<a class="btn btn-primary btn-sm" ng-disabled="queryExecuting || !queryResult.getData()" ng-href="{{dataUri}}" download="{{dataFilename}}" target="_self"> <a class="btn btn-primary btn-sm" ng-disabled="queryExecuting || !queryResult.getData()" query-result-link target="_self">
<span class="glyphicon glyphicon-cloud-download"></span> <span class="glyphicon glyphicon-cloud-download"></span>
<span class="rd-hidden-xs">Download Dataset</span> <span class="rd-hidden-xs">Download Dataset</span>
</a> </a>