Merge pull request #222 from EverythingMe/feature_download_from_dashboard

Feature download from dashboard
This commit is contained in:
Arik Fraimovich 2014-05-19 16:31:53 +03:00
commit 5b998269b3
5 changed files with 233 additions and 211 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

@ -51,7 +51,9 @@
template: '<li class="rd-tab" ng-class="{active: tabId==selectedTab}"><a href="#{{tabId}}">{{name}}<span ng-transclude></span></a></li>', template: '<li class="rd-tab" ng-class="{active: tabId==selectedTab}"><a href="#{{tabId}}">{{name}}<span ng-transclude></span></a></li>',
replace: true, replace: true,
link: function (scope) { link: function (scope) {
scope.$watch(function(){return scope.$parent.selectedTab}, function(tab) { scope.$watch(function () {
return scope.$parent.selectedTab
}, function (tab) {
scope.selectedTab = tab; scope.selectedTab = tab;
}); });
} }
@ -69,10 +71,14 @@
replace: true, replace: true,
link: function ($scope, element, attrs) { link: function ($scope, element, attrs) {
$scope.selectTab = function (tabKey) { $scope.selectTab = function (tabKey) {
$scope.selectedTab = _.find($scope.tabsCollection, function(tab) { return tab.key == tabKey; }); $scope.selectedTab = _.find($scope.tabsCollection, function (tab) {
return tab.key == tabKey;
});
} }
$scope.$watch(function() { return $location.hash()}, function(hash) { $scope.$watch(function () {
return $location.hash()
}, function (hash) {
if (hash) { if (hash) {
$scope.selectTab($location.hash()); $scope.selectTab($location.hash());
} else { } else {
@ -166,9 +172,11 @@
function into(input) { function into(input) {
return JSON.parse(input); return JSON.parse(input);
} }
function out(data) { function out(data) {
return JSON.stringify(data, undefined, 2); return JSON.stringify(data, undefined, 2);
} }
ngModel.$parsers.push(into); ngModel.$parsers.push(into);
ngModel.$formatters.push(out); ngModel.$formatters.push(out);

View File

@ -38,6 +38,26 @@
} }
} }
function queryResultCSVLink() {
return {
restrict: 'A',
link: function (scope, element) {
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 +155,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>