1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-15 00:24:09 +01:00
fab-manager/app/services/availabilities_export_service.rb

27 lines
771 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-03-02 12:34:16 +01:00
require 'abstract_controller'
require 'action_controller'
require 'action_view'
require 'active_record'
# require any helpers
require './app/helpers/application_helper'
# Retrieve all availabilities and their related objects and write the result as a table in an excel file
2017-03-02 12:34:28 +01:00
class AvailabilitiesExportService
# export all availabilities
def export_index(export)
@availabilities = Availability.all.includes(:machines, :trainings, :spaces, :event, :slots)
2017-03-02 12:34:16 +01:00
2023-02-24 17:26:55 +01:00
content = ApplicationController.render(
template: 'exports/availabilities_index',
locals: { availabilities: @availabilities },
handlers: [:axlsx],
formats: [:xlsx]
)
2017-03-02 12:34:16 +01:00
# write content to file
2023-02-24 17:26:55 +01:00
File.binwrite(export.file, content)
2017-03-02 12:34:16 +01:00
end
end