1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

fix type key transmission

This commit is contained in:
Sylvain 2016-07-07 16:57:23 +02:00
parent 0f7f2c256a
commit 8e968f7813
4 changed files with 14 additions and 8 deletions

View File

@ -288,8 +288,10 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
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: ->
index: ->
key: $scope.selectedIndex.es_type_key
type: ->
key: $scope.type.active.key
$uibModal.open options
.result['finally'](null).then (info)->
@ -529,8 +531,8 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', 'query', 'key', 'CSRF'
, ($scope, $uibModalInstance, dates, query, key, CSRF) ->
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', 'query', 'index', 'type', 'CSRF'
, ($scope, $uibModalInstance, dates, query, index, type, CSRF) ->
## Retrieve Anti-CSRF tokens from cookies
CSRF.setMetaTags()
@ -542,7 +544,10 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
$scope.query = JSON.stringify(query)
## API URL where the form will be posted
$scope.actionUrl = '/stats/'+key.key+'/export'
$scope.actionUrl = '/stats/'+index.key+'/export'
## Key of the current search' statistic type
$scope.typeKey = type.key
## Form action on the above URL
$scope.method = "post"
@ -601,7 +606,7 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
$scope.actionUrl = '/stats/global/export'
$scope.query = JSON.stringify(query)
else
$scope.actionUrl = '/stats/'+key.key+'/export'
$scope.actionUrl = '/stats/'+index.key+'/export'
$scope.query = JSON.stringify(
"query":
"bool":
@ -616,7 +621,7 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
)
##
# Callback to close the modal, telling the caller to start the export with the selected parameters
# Callback to close the modal, telling the caller what is exported
##
$scope.exportData = ->
info =

View File

@ -66,6 +66,7 @@
<form role=form" ng-submit="exportData()" name="exportForm" method="post" action="{{ actionUrl }}" class="inline">
<input name="authenticity_token" type="hidden" ng-value="csrfToken"/>
<input name="_method" type="hidden" ng-value="method"/>
<input name="type_key" type="hidden" ng-value="typeKey"/>
<input name="body" type="hidden" ng-value="query"/>
<input type="submit" class="btn btn-info" value="{{ 'export' | translate }}" formtarget="_blank"/>
</form>

View File

@ -19,6 +19,7 @@ class API::StatisticsController < API::ApiController
authorize :statistic, :#{path}?
query = MultiJson.load(params[:body])
type_key = params[:type_key]
@results = Elasticsearch::Model.client.search({index: 'stats', type: '#{path}', scroll: '30s', body: query})
scroll_id = @results['_scroll_id']
@ -31,7 +32,6 @@ class API::StatisticsController < API::ApiController
ids = @results['hits']['hits'].map { |u| u['_source']['userId'] }
@users = User.includes(:profile).where(:id => ids)
type_key = query['query']['bool']['must'][0]['term']['type'].to_s
@index = StatisticIndex.find_by(es_type_key: '#{path}')
@type = StatisticType.find_by(key: type_key, statistic_index_id: @index.id)
@subtypes = @type.statistic_sub_types

View File

@ -49,7 +49,7 @@ wb.add_worksheet(name: @index.label) do |sheet|
field_data = hit['_source'][f.key]
case f.data_type
when 'date'
data.push Date::strptime(field_data,'%Y-%m-%d')
data.push Date::strptime(field_data, '%Y-%m-%d')
styles.push date
types.push :date
when 'list'