1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

basic UI and API for exporting stats to excel

This commit is contained in:
Sylvain 2016-07-04 17:15:37 +02:00
parent 99aa8120fc
commit 38c00391fc
7 changed files with 166 additions and 3 deletions

View File

@ -1,7 +1,9 @@
'use strict'
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", "Statistics", "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
, ($scope, $state, $rootScope, Statistics, es, Member, _t, membersPromise, statisticsPromise) ->
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", '$uibModal', "Statistics", "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
, ($scope, $state, $rootScope, $uibModal, Statistics, es, Member, _t, membersPromise, statisticsPromise) ->
@ -271,6 +273,27 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
##
# Run the current elastic query on the server and return the result as an Excel file
##
$scope.exportToExcel = ->
options =
templateUrl: '<%= asset_path "admin/statistics/export.html" %>'
size: 'sm'
controller: 'ExportStatisticsController'
resolve:
dates: ->
start: $scope.datePickerStart.selected
end: $scope.datePickerEnd.selected
$uibModal.open options
.result['finally'](null).then (info)->
console.info(info)
, (reason)->
console.error(reason)
### PRIVATE SCOPE ###
##
@ -429,7 +452,7 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
"field": "age"
"total_stat":
"sum":
"field": "sta"
"field": "stat"
}
q
@ -490,3 +513,55 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
initialize()
]
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', ($scope, $uibModalInstance, dates) ->
# bindings for date range
$scope.dates = dates
$scope.export =
type: 'current'
## datePicker parameters for interval beginning
$scope.exportStart =
format: Fablab.uibDateFormat
opened: false # default: datePicker is not shown
minDate: null
maxDate: moment().subtract(1, 'day').toDate()
options:
startingDay: Fablab.weekStartingDay
## datePicker parameters for interval ending
$scope.exportEnd =
format: Fablab.uibDateFormat
opened: false # default: datePicker is not shown
minDate: null
maxDate: moment().subtract(1, 'day').toDate()
options:
startingDay: Fablab.weekStartingDay
##
# Callback to open the datepicker (interval start)
# @param $event {Object} jQuery event object
##
$scope.toggleStartDatePicker = ($event) ->
$scope.exportStart.opened = !$scope.exportStart.opened
##
# Callback to open the datepicker (interval end)
# @param $event {Object} jQuery event object
##
$scope.toggleEndDatePicker = ($event) ->
$scope.exportEnd.opened = !$scope.exportEnd.opened
$scope.ok = (info) ->
$uibModalInstance.close( info )
$scope.cancel = ->
$uibModalInstance.dismiss('cancel')
]

View File

@ -0,0 +1,68 @@
<div class="modal-header">
<img ng-src="{{logoBlack.custom_asset_file_attributes.attachment_url}}" alt="{{logo.custom_asset_file_attributes.attachment}}" class="modal-logo"/>
<h1 translate>{{ 'export_statistics_to_excel' }}</h1>
</div>
<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>
</div>
<div ng-show="export.type == 'global'">
<ul class="list-unstyled">
<li class="row">
<span class="col-md-4" translate>{{ 'start' }}</span>
<div class="input-group black col-md-7 m-r" id="date_pick_start">
<input type="text"
class="form-control"
uib-datepicker-popup="{{exportEnd.format}}"
ng-model="dates.start"
name="startDate"
is-open="exportStart.opened"
min-date="exportStart.minDate"
max-date="exportStart.maxDate"
datepicker-options="exportStart.options"
show-button-bar="false"
placeholder="{{ 'start' | translate }}"
ng-click="toggleStartDatePicker($event)"
required="required"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-search-datepicker" ng-click="toggleStartDatePicker($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</div>
</li>
<li class="row">
<span class="col-md-4" translate>{{ 'end' }}</span>
<div class="input-group black col-md-7 m-r" id="date_pick_end">
<input type="text"
class="form-control"
uib-datepicker-popup="{{exportEnd.format}}"
ng-model="dates.end"
name="endDate"
is-open="exportEnd.opened"
min-date="exportEnd.minDate"
max-date="exportEnd.maxDate"
datepicker-options="datePickerEnd.options"
show-button-bar="false"
placeholder="{{ 'end' | translate }}"
ng-click="toggleEndDatePicker($event)"
required="required"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-search-datepicker" ng-click="toggleEndDatePicker($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</div>
</li>
</ul>
</div>
<div class="radio">
<label><input type="radio" name="scope" ng-model="export.type" value="current">{{ '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>
<button class="btn btn-default" ng-click="cancel()" translate>{{ 'cancel' }}</button>
</div>

View File

@ -12,6 +12,7 @@
</div>
<div class="col-xs-12 col-sm-12 col-md-3 b-t hide-b-md">
<section class="heading-actions wrapper">
<a class="btn btn-lg btn-default rounded m-t-sm text-sm" ng-click="exportToExcel()"><i class="fa fa-file-excel-o"></i></a>
<a class="btn btn-lg btn-warning bg-white b-2x rounded m-t-sm upper text-sm" ui-sref="app.admin.stats_graphs" role="button"><i class="fa fa-line-chart"></i> {{ 'evolution' | translate }}</a>
</section>
</div>

View File

@ -14,6 +14,16 @@ class API::StatisticsController < API::ApiController
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
render json: results
end
def export_#{path}
authorize :statistic, :#{path}?
query = MultiJson.load(request.body.read)
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
respond_to do |format|
format.html
format.xls
end
end
}
end

View File

@ -389,6 +389,10 @@ en:
unknown: "Unknown"
user_id: "User ID"
display_more_results: "Display more results"
export_statistics_to_excel: "Export statistics to Excel"
export_all_statistics: "Export all statistics"
export_the_current_search_results: "Export the current search results"
export: "Export"
stats_graphs:

View File

@ -389,6 +389,10 @@ fr:
unknown: "Inconnu"
user_id: "ID Utilisateur"
display_more_results: "Afficher plus de résultats"
export_statistics_to_excel: "Exporter les statistiques vers Excel"
export_all_statistics: "Exporter toutes les statistiques"
export_the_current_search_results: "Exporter les résultats de la recherche courante"
export: "Exporter"
stats_graphs:

View File

@ -127,6 +127,7 @@ Rails.application.routes.draw do
%w(account event machine project subscription training user).each do |path|
post "/stats/#{path}/_search", to: "api/statistics##{path}"
post "/stats/#{path}/export", to: "api/statistics#export_#{path}"
end
post '_search/scroll', to: "api/statistics#scroll"