mirror of
https://github.com/getredash/redash.git
synced 2025-12-25 01:03:20 -05:00
apply reviews
This commit is contained in:
@@ -38,10 +38,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
function queryResultCSVLink() {
|
||||
function queryResultLink() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function (scope, element) {
|
||||
link: function (scope, element, attrs) {
|
||||
|
||||
var fileType = attrs.fileType ? attrs.fileType : "csv";
|
||||
scope.$watch('queryResult && queryResult.getData()', function(data) {
|
||||
if (!data) {
|
||||
return;
|
||||
@@ -50,28 +52,8 @@
|
||||
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 queryResultExcelLink() {
|
||||
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() + '.xlsx');
|
||||
element.attr('download', scope.query.name.replace(" ", "_") + moment(scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") + ".xlsx");
|
||||
element.attr('href', 'api/queries/' + scope.query.id + '/results/' + scope.queryResult.getId() + '.' + fileType);
|
||||
element.attr('download', scope.query.name.replace(" ", "_") + moment(scope.queryResult.getUpdatedAt()).format("_YYYY_MM_DD") + "." + fileType);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -306,8 +288,7 @@
|
||||
angular.module('redash.directives')
|
||||
.directive('queryLink', queryLink)
|
||||
.directive('querySourceLink', querySourceLink)
|
||||
.directive('queryResultCsvLink', queryResultCSVLink)
|
||||
.directive('queryResultXlsxLink', queryResultExcelLink)
|
||||
.directive('queryResultLink', queryResultLink)
|
||||
.directive('queryEditor', queryEditor)
|
||||
.directive('queryRefreshSelect', queryRefreshSelect)
|
||||
.directive('queryTimePicker', queryTimePicker)
|
||||
|
||||
@@ -159,12 +159,12 @@
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<a class="btn btn-primary btn-sm" ng-disabled="queryExecuting || !queryResult.getData()" query-result-csv-link 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>Download Csv</span>
|
||||
<span>Download CSV</span>
|
||||
</a>
|
||||
|
||||
<a class="btn btn-primary btn-sm" ng-disabled="queryExecuting || !queryResult.getData()" query-result-xlsx-link target="_self">
|
||||
<a class="btn btn-primary btn-sm" ng-disabled="queryExecuting || !queryResult.getData()" file-type="xlsx" query-result-link target="_self">
|
||||
<span class="glyphicon glyphicon-cloud-download"></span>
|
||||
<span>Download Excel</span>
|
||||
</a>
|
||||
|
||||
@@ -146,18 +146,14 @@ class QueryResultAPI(BaseResource):
|
||||
query_data = json.loads(query_result.data)
|
||||
book = xlsxwriter.Workbook(s)
|
||||
sheet = book.add_worksheet("result")
|
||||
logging.info(query_data['columns'])
|
||||
|
||||
list = []
|
||||
column_names = []
|
||||
for (c, col) in enumerate(query_data['columns']):
|
||||
sheet.write(0, c, col['name'])
|
||||
list.append(col['name'])
|
||||
column_names.append(col['name'])
|
||||
|
||||
for (r, row) in enumerate(query_data['rows']):
|
||||
logging.info(row)
|
||||
for (c, name) in enumerate(list):
|
||||
logging.info(c)
|
||||
logging.info(name)
|
||||
for (c, name) in enumerate(column_names):
|
||||
sheet.write(r+1, c, row[name])
|
||||
|
||||
book.close()
|
||||
|
||||
Reference in New Issue
Block a user