1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

Alleluia git add . Downloading xls from front is working

This commit is contained in:
Sylvain 2016-07-06 15:53:09 +02:00
parent d307f91983
commit e8b1c99d2a
5 changed files with 52 additions and 38 deletions

View File

@ -285,29 +285,15 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
dates: ->
start: $scope.datePickerStart.selected
end: $scope.datePickerEnd.selected
query: ->
custom = buildCustomFilterQuery()
buildElasticDataQuery($scope.type.active.key, custom, $scope.agePicker.start, $scope.agePicker.end, moment($scope.datePickerStart.selected), moment($scope.datePickerEnd.selected), $scope.sorting)
key: ->
key: $scope.selectedIndex.es_type_key
$uibModal.open options
.result['finally'](null).then (info)->
# export requested
if info.type == 'current'
custom = buildCustomFilterQuery()
$scope.exportUrl = '/stats/'+$scope.selectedIndex.es_type_key+'/export'
$scope.exportQuery = buildElasticDataQuery($scope.type.active.key, custom, $scope.agePicker.start, $scope.agePicker.end, moment($scope.datePickerStart.selected), moment($scope.datePickerEnd.selected), $scope.sorting)
angular.element('#export-stats').submit()
else if info.type == 'global'
$scope.exportUrl = '/stats/global/export'
$scope.exportQuery =
"query":
"bool":
"must": [
{
"range":
"date":
"gte": moment(info.dates.start).format()
"lte": moment(info.dates.end).format()
}
]
angular.element('#export-stats').submit()
console.log(info)
@ -543,11 +529,25 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', ($scope, $uibModalInstance, dates) ->
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', 'query', 'key', 'CSRF'
, ($scope, $uibModalInstance, dates, query, key, CSRF) ->
CSRF.setMetaTags()
## Bindings for date range
$scope.dates = dates
## Body of the query to export
$scope.query = JSON.stringify(query)
## API URL where the form will be posted
$scope.actionUrl = '/stats/'+key.key+'/export'
## Form action on the above URL
$scope.method = "post"
$scope.csrfToken = angular.element('meta[name="csrf-token"]')[0].content
## Binding of the export type (global / current)
$scope.export =
type: 'current'
@ -590,10 +590,29 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
$scope.setRequest = ->
if $scope.export.type == 'global'
$scope.actionUrl = '/stats/global/export'
$scope.query = JSON.stringify(query)
else
$scope.actionUrl = '/stats/'+key.key+'/export'
$scope.query = JSON.stringify(
"query":
"bool":
"must": [
{
"range":
"date":
"gte": moment(info.dates.start).format()
"lte": moment(info.dates.end).format()
}
]
)
##
# Callback to close the modal, telling the caller to start the export with the selected parameters
##
$scope.ok = ->
$scope.exportData = ->
info =
type: $scope.export.type

View File

@ -2,10 +2,5 @@
Application.Services.factory 'Export', ["$http", ($http)->
stats: (scope, query) ->
$http.post('/stats/'+scope+'/export', query).then((res) ->
console.log(res)
, (err) ->
console.error(err)
)
$http.post('/stats/'+scope+'/export', query)
]

View File

@ -5,7 +5,7 @@
<div class="modal-body">
<form>
<div class="radio">
<label><input type="radio" name="scope" ng-model="export.type" value="global">{{ 'export_all_statistics' | translate }}</label>
<label><input type="radio" name="scope" ng-model="export.type" value="global" ng-change="setRequest()">{{ 'export_all_statistics' | translate }}</label>
</div>
<div ng-show="export.type == 'global'">
<ul class="list-unstyled">
@ -58,11 +58,16 @@
</ul>
</div>
<div class="radio">
<label><input type="radio" name="scope" ng-model="export.type" value="current">{{ 'export_the_current_search_results' | translate }}</label>
<label><input type="radio" name="scope" ng-model="export.type" value="current" ng-change="setRequest()">{{ 'export_the_current_search_results' | translate }}</label>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-info" ng-click="ok()" translate>{{ 'export' }}</button>
<form role=form" ng-submit="exportData()" name="exportForm" method="post" action="{{ actionUrl }}">
<input name="authenticity_token" type="hidden" ng-value="csrfToken"/>
<input name="_method" type="hidden" ng-value="method"/>
<input name="body" type="hidden" ng-value="query"/>
<input type="submit" class="btn btn-info" value="{{ 'export' | translate }}"/>
<button class="btn btn-default" ng-click="cancel()" translate>{{ 'cancel' }}</button>
</form>
</div>

View File

@ -288,8 +288,3 @@
</div>
</section>
<form id="export-stats" enctype="multipart/form-data" method="post" action="{{exportUrl}}" formtarget="_blank">
<input type="hidden" ng-value="exportQuery" name="body" >
</form>

View File

@ -17,7 +17,7 @@ class API::StatisticsController < API::ApiController
def export_#{path}
authorize :statistic, :#{path}?
query = MultiJson.load(request.body.read)
query = MultiJson.load(params[:body])
@results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
render xlsx: 'export_#{path}.xlsx', filename: "#{path}.xlsx"
end