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

API generate valid xlsx files

This commit is contained in:
Sylvain 2016-07-05 16:13:11 +02:00
parent b26bbd18ef
commit 4dcab27af2
6 changed files with 30 additions and 3 deletions

View File

@ -1,5 +1,8 @@
# Changelog Fab Manager
## next release
- [TODO DEPLOY] `bundle install`
## v2.3.0 2016 June 28
- Public API with access management and online documentation

View File

@ -144,3 +144,8 @@ gem 'openlab_ruby'
gem 'api-pagination'
gem 'has_secure_token'
gem 'apipie-rails'
# XLS files generation
gem 'rubyzip', '~> 1.1.0'
gem 'axlsx', '2.1.0.pre'
gem 'axlsx_rails'

View File

@ -54,6 +54,13 @@ GEM
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
axlsx (2.1.0.pre)
htmlentities (~> 4.3.1)
nokogiri (>= 1.4.1)
rubyzip (~> 1.1.7)
axlsx_rails (0.4.0)
axlsx (>= 2.0.1)
rails (>= 3.1)
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
@ -174,6 +181,7 @@ GEM
highline (1.7.1)
hike (1.2.3)
hitimes (1.2.2)
htmlentities (4.3.4)
http (0.6.4)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.2)
@ -325,6 +333,7 @@ GEM
netrc (~> 0.7)
rolify (4.0.0)
ruby-progressbar (1.7.5)
rubyzip (1.1.7)
rufus-scheduler (3.0.9)
tzinfo
rvm-capistrano (1.5.6)
@ -440,6 +449,8 @@ DEPENDENCIES
api-pagination
apipie-rails
awesome_print
axlsx (= 2.1.0.pre)
axlsx_rails
bootstrap-sass
byebug
capistrano
@ -488,6 +499,7 @@ DEPENDENCIES
recurrence
responders (~> 2.0)
rolify
rubyzip (~> 1.1.0)
rvm-capistrano
sass-rails (= 5.0.1)
sdoc (~> 0.4.0)

View File

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

View File

@ -0,0 +1,6 @@
wb = xlsx_package.workbook
wb.add_worksheet(name: "Abonnements") do |sheet|
@results[:hits][:hits].each do |hit|
sheet.add_row [hit[:_source].date, hit[:_source].userId, hit[:_source].gender, hit[:_source].age, hit[:_source].planId, hit[:_source].groupName, hit[:_source].ca]
end
end

View File

@ -4,4 +4,5 @@
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "application/vnd.ms-excel", :xls
Mime::Type.register "application/vnd.ms-excel", :xls
Mime::Type.register "application/xlsx", :xlsx