mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
alert user about ongoing running export
This commit is contained in:
parent
7843cd1f8e
commit
b3f56cefd4
@ -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)
|
||||
|
||||
|
||||
|
||||
|
@ -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)
|
||||
]
|
||||
|
@ -31,15 +31,16 @@
|
||||
<div class="col-md-12">
|
||||
<button type="button" class="btn btn-warning m-t m-b" ui-sref="app.admin.members_new" translate>{{ 'add_a_new_member' }}</button>
|
||||
<div class="pull-right">
|
||||
<a class="btn btn-default" ng-href="api/members/export_members.xlsx" target="_blank">
|
||||
<a class="btn btn-default" ng-href="api/members/export_members.xlsx" target="export-frame">
|
||||
<i class="fa fa-file-excel-o"></i> {{ 'members' | translate }}
|
||||
</a>
|
||||
<a class="btn btn-default" ng-href="api/members/export_subscriptions.xlsx" target="_blank" ng-if="!fablabWithoutPlans">
|
||||
<a class="btn btn-default" ng-href="api/members/export_subscriptions.xlsx" target="export-frame" ng-if="!fablabWithoutPlans">
|
||||
<i class="fa fa-file-excel-o"></i> {{ 'subscriptions' | translate }}
|
||||
</a>
|
||||
<a class="btn btn-default" ng-href="api/members/export_reservations.xlsx" target="_blank">
|
||||
<a class="btn btn-default" ng-href="api/members/export_reservations.xlsx" target="export-frame">
|
||||
<i class="fa fa-file-excel-o"></i> {{ 'reservations' | translate }}
|
||||
</a>
|
||||
<iframe name="export-frame" height="0" width="0" class="none"></iframe>
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
<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>
|
||||
<iframe name="export-frame" height="0" width="0" class="none"></iframe>
|
||||
<iframe name="export-frame" height="0" width="0" class="none" id="stats-export-frame"></iframe>
|
||||
<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>
|
||||
|
@ -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])
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user