Class: Interchange::ExportsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Interchange::ExportsController
- Defined in:
- app/controllers/interchange/exports_controller.rb
Overview
Controller for export related functionality, as a RESTful resource. We handle both regular exports and exports bound for UIAutomation .js data files.
Instance Method Summary collapse
-
#create ⇒ Object
This responds to the request to do the export.
-
#initialize ⇒ ExportsController
constructor
This constructor sets up Writer class that we offload the low level export work to.
-
#show ⇒ Object
Shows the page of export options, as well as the results of the last export operation, if the server hasn’t been bounced since that was last performed.
Constructor Details
#initialize ⇒ ExportsController
This constructor sets up Writer class that we offload the low level export work to.
8 9 10 11 |
# File 'app/controllers/interchange/exports_controller.rb', line 8 def initialize super @writer = Interchange::Writer.new end |
Instance Method Details
#create ⇒ Object
This responds to the request to do the export. We invoke a helper method to handle the export of a given model class, one class at a time. Possible param values that can be provided:
* export_patients - Whether to export patients. Pass 1 for true.
* export_physicians - Whether to export physicians. Pass 1 for true.
* model_class_name - Indicates a single class we want exported. Use along with model_id to export a single object.
* model_id - The id value of the single object we want to export. Use along with model_class_name to export a single object.
* ids - A specific set of ID values to export (as opposed to all for the specified model class).
* restrict_by_keywords - Whether to restrict models exported to those with one of the keywords provided by keywords_csv.
* keywords_csv - A string of keywords, comma separated. These are keywords a model
must have one of, in order to be included in the export.
We determine what models to export from the params provided. Once complete, we redirect to the show action, with a flash message built from the Interchange::Writer class’ tally of results.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/interchange/exports_controller.rb', line 40 def create log 'In create method. Initiating an export operation now.' log "params: #{params}" # Determine what models are to be included: model_classes = [] model_classes << Patient if params[:export_patients] model_classes << Physician if params[:export_physicians] model_classes << DocumentTemplate if params[:export_document_templates] model_classes << DataSet if params[:export_data_sets] # Did we have a specific model class given for export? if params[:model_class_name] # YES: Export just that class and just the ID provided: model_classes << params[:model_class_name].constantize ids = [params[:model_id]] if params[:model_id] end # If not already specified by model_id, look for a subset of IDs to # restrict the export to: ids = params[:ids] unless ids # Determine if there are keywords requested for us to filter by: keywords = if params[:restrict_by_keywords] && !params[:keywords_csv].blank? params[:keywords_csv].split(',') else nil end keywords.each do | keyword | keyword.strip! end if keywords # Start the export operation block: @writer.mark_export_operation do # Kick off the underlying export operation on the model(s) requested: model_classes.each do |model_class| @writer.export model_class, {keywords: keywords, ids: ids} end end redirect_to interchange_export_path, @writer.operation_results[:flash_hash] end |
#show ⇒ Object
Shows the page of export options, as well as the results of the last export operation, if the server hasn’t been bounced since that was last performed.
16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/interchange/exports_controller.rb', line 16 def show log 'ExportsController: show' = {class: 'active'} 'Export', '#', # breadcrumbs_on_rails call # Retrieve results of the last export, so we can display that in our view: @last_export_summary = Interchange::Writer.instance_variable_get(:@last_export_summary) end |