Class: DbdocEngine::DbDesignDynamicTableExportService
- Inherits:
-
Object
- Object
- DbdocEngine::DbDesignDynamicTableExportService
- Defined in:
- app/services/dbdoc_engine/db_design_dynamic_table_export_service.rb
Instance Method Summary collapse
-
#export_all ⇒ Object
Handles export of all tables to Excel.
-
#export_single ⇒ Object
Handles export of a single table to Excel.
-
#initialize(params, controller) ⇒ DbDesignDynamicTableExportService
constructor
A new instance of DbDesignDynamicTableExportService.
Constructor Details
#initialize(params, controller) ⇒ DbDesignDynamicTableExportService
Returns a new instance of DbDesignDynamicTableExportService.
4 5 6 7 |
# File 'app/services/dbdoc_engine/db_design_dynamic_table_export_service.rb', line 4 def initialize(params, controller) @params = params # Parameters passed from the controller @controller = controller # Reference to the controller instance end |
Instance Method Details
#export_all ⇒ Object
Handles export of all tables to Excel
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/dbdoc_engine/db_design_dynamic_table_export_service.rb', line 26 def export_all tables = DbdocEngine::DbDesignDynamicTableQueries.all_tables_with_columns_and_groups # Get all tables with columns and groups @controller.instance_variable_set(:@tables, tables) # Set instance variable for use in view @controller.respond_to do |format| # Prepare Excel response format.xlsx do filename = "all_tables_details_#{Date.today.strftime('%Y%m%d')}.xlsx" # Set download filename with today's date @controller.response.headers["Content-Disposition"] = "attachment; filename=#{filename}" end end end |
#export_single ⇒ Object
Handles export of a single table to Excel
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/services/dbdoc_engine/db_design_dynamic_table_export_service.rb', line 10 def export_single table = DbdocEngine::DbDesignDynamicTableQueries.find_table_with_deleted(@params[:id]) # Find table by ID (including soft-deleted) columns = table.db_design_dynamic_columns # Get all columns for the table @controller.instance_variable_set(:@table, table) # Set instance variable for table @controller.instance_variable_set(:@columns, columns) # Set instance variable for columns @controller.respond_to do |format| # Prepare Excel response format.xlsx do filename = "#{table.table_name.parameterize}_details.xlsx" # Set download filename @controller.response.headers["Content-Disposition"] = "attachment; filename=#{filename}" end end end |