Class: Superset::Chart::UpdateDataset
- Defined in:
- lib/superset/chart/update_dataset.rb
Constant Summary
Constants inherited from Request
Instance Attribute Summary collapse
-
#chart_id ⇒ Object
readonly
Returns the value of attribute chart_id.
-
#target_dashboard_id ⇒ Object
readonly
Returns the value of attribute target_dashboard_id.
-
#target_dataset_id ⇒ Object
readonly
Returns the value of attribute target_dataset_id.
Attributes inherited from Request
Instance Method Summary collapse
-
#initialize(chart_id:, target_dataset_id:, target_dashboard_id: nil) ⇒ UpdateDataset
constructor
A new instance of UpdateDataset.
- #params_updated ⇒ Object
- #perform ⇒ Object
- #response ⇒ Object
Methods inherited from Request
call, #query_params, #result, #superset_host
Methods included from Display
#display_headers, #headings, #list, #list_attributes, #result, #rows, #table, #title
Constructor Details
#initialize(chart_id:, target_dataset_id:, target_dashboard_id: nil) ⇒ UpdateDataset
Returns a new instance of UpdateDataset.
9 10 11 12 13 |
# File 'lib/superset/chart/update_dataset.rb', line 9 def initialize(chart_id: , target_dataset_id: , target_dashboard_id: nil) @chart_id = chart_id @target_dataset_id = target_dataset_id @target_dashboard_id = target_dashboard_id end |
Instance Attribute Details
#chart_id ⇒ Object (readonly)
Returns the value of attribute chart_id.
7 8 9 |
# File 'lib/superset/chart/update_dataset.rb', line 7 def chart_id @chart_id end |
#target_dashboard_id ⇒ Object (readonly)
Returns the value of attribute target_dashboard_id.
7 8 9 |
# File 'lib/superset/chart/update_dataset.rb', line 7 def target_dashboard_id @target_dashboard_id end |
#target_dataset_id ⇒ Object (readonly)
Returns the value of attribute target_dataset_id.
7 8 9 |
# File 'lib/superset/chart/update_dataset.rb', line 7 def target_dataset_id @target_dataset_id end |
Instance Method Details
#params_updated ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/superset/chart/update_dataset.rb', line 32 def params_updated @params_updated ||= begin new_params = {} # chart updates to point to the new target dataset new_params.merge!("datasource_id": target_dataset_id) # point to the new dataset id new_params.merge!("datasource_type": 'table') # type of dataset ?? not sure of other options new_params.merge!("owners": chart.owner_ids ) # expects an array of user ids new_params.merge!("params": updated_chart_params.to_json) # updated to point to the new params query_context = updated_chart_query_context if query_context new_params.merge!("query_context": query_context.to_json) # update to point to the new query context new_params.merge!("query_context_generation": true) # new param set to true to regenerate the query context end new_params end end |
#perform ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/superset/chart/update_dataset.rb', line 15 def perform validate_proposed_changes response if result['datasource_id'] == target_dataset_id "Successfully updated chart #{chart_id} to the target dataset #{target_dataset_id}" else "Error: Failed to update chart #{chart_id} to #{target_dataset_id}" end end |
#response ⇒ Object
28 29 30 |
# File 'lib/superset/chart/update_dataset.rb', line 28 def response @response ||= client.put(route, params_updated) end |