Class: Superset::Dashboard::Copy

Inherits:
Request
  • Object
show all
Defined in:
lib/superset/dashboard/copy.rb

Constant Summary

Constants inherited from Request

Request::PAGE_SIZE

Instance Attribute Summary collapse

Attributes inherited from Request

#page_num

Instance Method Summary collapse

Methods inherited from Request

call, #query_params, #result, #superset_host

Methods included from Superset::Display

#display_headers, #headings, #list, #list_attributes, #result, #rows, #table, #title

Constructor Details

#initialize(source_dashboard_id:, duplicate_slices: false, clear_shared_label_colors: false) ⇒ Copy

Returns a new instance of Copy.



11
12
13
14
15
# File 'lib/superset/dashboard/copy.rb', line 11

def initialize(source_dashboard_id: , duplicate_slices: false, clear_shared_label_colors: false)
  @source_dashboard_id = source_dashboard_id
  @duplicate_slices = duplicate_slices # boolean indicates whether to duplicate charts OR keep the new dashboard pointing to the same charts as the original
  @clear_shared_label_colors = clear_shared_label_colors
end

Instance Attribute Details

#clear_shared_label_colorsObject (readonly)

Returns the value of attribute clear_shared_label_colors.



9
10
11
# File 'lib/superset/dashboard/copy.rb', line 9

def clear_shared_label_colors
  @clear_shared_label_colors
end

#duplicate_slicesObject (readonly)

Returns the value of attribute duplicate_slices.



9
10
11
# File 'lib/superset/dashboard/copy.rb', line 9

def duplicate_slices
  @duplicate_slices
end

#source_dashboard_idObject (readonly)

Returns the value of attribute source_dashboard_id.



9
10
11
# File 'lib/superset/dashboard/copy.rb', line 9

def source_dashboard_id
  @source_dashboard_id
end

Instance Method Details

#idObject



39
40
41
# File 'lib/superset/dashboard/copy.rb', line 39

def id
  response["result"]["id"]
end

#paramsObject



26
27
28
29
30
31
32
33
# File 'lib/superset/dashboard/copy.rb', line 26

def params
  {
    "css" => "{}",
    "dashboard_title" => "#{source_dashboard.title}",
    "duplicate_slices" => duplicate_slices,
    "json_metadata" => .to_json,
  }
end

#performObject



17
18
19
20
21
22
23
24
# File 'lib/superset/dashboard/copy.rb', line 17

def perform
  raise "Error: source_dashboard_id integer is required" unless source_dashboard_id.present? && source_dashboard_id.is_a?(Integer)
  raise "Error: duplicate_slices must be a boolean" unless duplicate_slices_is_boolean?

  
  response
  Superset::Dashboard::Get.new(id).perform  # return the full new dashboard object
end

#responseObject



35
36
37
# File 'lib/superset/dashboard/copy.rb', line 35

def response
  @response ||= client.post(route, params)
end