diff --git a/app/assets/javascripts/controllers/admin/statistics.coffee.erb b/app/assets/javascripts/controllers/admin/statistics.coffee.erb
index d0a33a7bd..e86707d69 100644
--- a/app/assets/javascripts/controllers/admin/statistics.coffee.erb
+++ b/app/assets/javascripts/controllers/admin/statistics.coffee.erb
@@ -2,8 +2,8 @@
-Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", '$uibModal', "Export", "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
-, ($scope, $state, $rootScope, $uibModal, Export, es, Member, _t, membersPromise, statisticsPromise) ->
+Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", '$uibModal', "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
+, ($scope, $state, $rootScope, $uibModal, es, Member, _t, membersPromise, statisticsPromise) ->
@@ -535,8 +535,8 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
-Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', 'query', 'index', 'type', 'CSRF'
-, ($scope, $uibModalInstance, dates, query, index, type, CSRF) ->
+Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'Export','dates', 'query', 'index', 'type', 'CSRF', 'growl', '_t'
+, ($scope, $uibModalInstance, Export, dates, query, index, type, CSRF, growl, _t) ->
## Retrieve Anti-CSRF tokens from cookies
CSRF.setMetaTags()
@@ -630,13 +630,16 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
# Callback to close the modal, telling the caller what is exported
##
$scope.exportData = ->
- info =
- type: $scope.export.type
+ statusQry = {category: 'statistics', type: $scope.export.type, query: $scope.query}
+ unless $scope.export.type == 'global'
+ statusQry['type'] = index.key
+ statusQry['key'] = type.key
- if info.type == 'global'
- info.dates = $scope.dates
+ Export.status(statusQry).then (res) ->
+ unless (res.data.exists)
+ growl.success _t('export_is_running_you_ll_be_notified_when_its_ready')
- $uibModalInstance.close(info)
+ $uibModalInstance.close(statusQry)
diff --git a/app/assets/javascripts/services/export.coffee b/app/assets/javascripts/services/export.coffee
index 2c8d6e4b1..3dd4dafa1 100644
--- a/app/assets/javascripts/services/export.coffee
+++ b/app/assets/javascripts/services/export.coffee
@@ -1,6 +1,6 @@
'use strict'
Application.Services.factory 'Export', ["$http", ($http)->
- stats: (scope, query) ->
- $http.post('/stats/'+scope+'/export', query)
+ status: (query) ->
+ $http.post('/api/exports/status', query)
]
diff --git a/app/assets/templates/admin/members/index.html.erb b/app/assets/templates/admin/members/index.html.erb
index ac38e3beb..8277b85e6 100644
--- a/app/assets/templates/admin/members/index.html.erb
+++ b/app/assets/templates/admin/members/index.html.erb
@@ -31,15 +31,16 @@
diff --git a/app/assets/templates/admin/statistics/index.html.erb b/app/assets/templates/admin/statistics/index.html.erb
index 223ec4a9b..c3770b4d8 100644
--- a/app/assets/templates/admin/statistics/index.html.erb
+++ b/app/assets/templates/admin/statistics/index.html.erb
@@ -13,7 +13,7 @@
diff --git a/app/controllers/api/exports_controller.rb b/app/controllers/api/exports_controller.rb
index 808756280..2735c54b7 100644
--- a/app/controllers/api/exports_controller.rb
+++ b/app/controllers/api/exports_controller.rb
@@ -4,9 +4,21 @@ class API::ExportsController < API::ApiController
def download
authorize @export
+
send_file File.join(Rails.root, @export.file), :type => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', :disposition => 'attachment'
end
+ def status
+ authorize Export
+
+ export = Export.where({category: params[:category], export_type: params[:type], query: params[:query], key: params[:key]}).last
+ if export.nil? || !FileTest.exist?(export.file)
+ render json: {exists: false, id: nil}, status: :ok
+ else
+ render json: {exists: true, id: export.id}, status: :ok
+ end
+ end
+
private
def set_export
@export = Export.find(params[:id])
diff --git a/app/policies/export_policy.rb b/app/policies/export_policy.rb
index 24e351ce4..a29ac0e20 100644
--- a/app/policies/export_policy.rb
+++ b/app/policies/export_policy.rb
@@ -1,5 +1,5 @@
class ExportPolicy < Struct.new(:user, :export)
- %w(export_reservations export_members export_subscriptions download).each do |action|
+ %w(export_reservations export_members export_subscriptions download status).each do |action|
define_method "#{action}?" do
user.is_admin?
end
diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml
index df0d6cadd..d3adc33fa 100644
--- a/config/locales/app.admin.en.yml
+++ b/config/locales/app.admin.en.yml
@@ -409,6 +409,7 @@ en:
export_all_statistics: "Export all statistics"
export_the_current_search_results: "Export the current search results"
export: "Export"
+ export_is_running_you_ll_be_notified_when_its_ready: "Export is running. You'll be notified when it's ready."
stats_graphs:
# statistics graphs
diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml
index 7bf6309d8..8113367b7 100644
--- a/config/locales/app.admin.fr.yml
+++ b/config/locales/app.admin.fr.yml
@@ -409,6 +409,7 @@ fr:
export_all_statistics: "Exporter toutes les statistiques"
export_the_current_search_results: "Exporter les résultats de la recherche courante"
export: "Exporter"
+ export_is_running_you_ll_be_notified_when_its_ready: "L'export est en cours. Vous serez notifié lorsqu'il sera prêt."
stats_graphs:
# graphiques de statistiques
diff --git a/config/routes.rb b/config/routes.rb
index a7c0c6737..37c3937ab 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -116,6 +116,7 @@ Rails.application.routes.draw do
# XLSX exports
get 'exports/:id/download' => 'exports#download'
+ post 'exports/status' => 'exports#status'
end
# open_api