Class: Gzr::Commands::Dashboard::Cat
- Inherits:
-
Gzr::Command
- Object
- Gzr::Command
- Gzr::Commands::Dashboard::Cat
- Includes:
- Dashboard, FileHelper, Plan
- Defined in:
- lib/gzr/commands/dashboard/cat.rb
Instance Method Summary collapse
- #execute(*args, input: $stdin, output: $stdout) ⇒ Object
-
#initialize(dashboard_id, options) ⇒ Cat
constructor
A new instance of Cat.
Methods included from Plan
#create_scheduled_plan, #delete_scheduled_plan, #query_all_scheduled_plans, #query_scheduled_plan, #query_scheduled_plans_for_dashboard, #query_scheduled_plans_for_look, #run_scheduled_plan, #update_scheduled_plan, #upsert_plan_for_dashboard, #upsert_plan_for_look, #upsert_plan_for_obj, #upsert_plans_for_dashboard, #upsert_plans_for_look, #upsert_plans_for_obj
Methods included from FileHelper
Methods included from Dashboard
#create_dashboard, #create_dashboard_element, #create_dashboard_filter, #create_dashboard_layout, #delete_dashboard, #delete_dashboard_element, #delete_dashboard_filter, #delete_dashboard_layout, #get_dashboard_layout, #query_dashboard, #search_dashboards_by_slug, #search_dashboards_by_title, #update_dashboard, #update_dashboard_element, #update_dashboard_filter, #update_dashboard_layout, #update_dashboard_layout_component
Methods inherited from Gzr::Command
#all_color_collections, #color_collection, #color_palette_lookup!, #create_merge_query, #create_query, #default_color_collection, #field_expression, #field_names, #find_color_palette_reference, #find_vis_config_reference, #keys_to_keep, #merge_query, #pairs, #query, #render_csv, #rewrite_color_palette!, #run_inline_query, #update_color_palette!
Methods included from Session
#build_connection_hash, #login, #logout_all, #pastel, #say_error, #say_ok, #say_warning, #sufficient_version?, #with_session
Constructor Details
#initialize(dashboard_id, options) ⇒ Cat
Returns a new instance of Cat.
37 38 39 40 41 |
# File 'lib/gzr/commands/dashboard/cat.rb', line 37 def initialize(dashboard_id,) super() @dashboard_id = dashboard_id = end |
Instance Method Details
#execute(*args, input: $stdin, output: $stdout) ⇒ Object
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gzr/commands/dashboard/cat.rb', line 43 def execute(*args, input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}") if [:debug] with_session("3.1") do data = query_dashboard(@dashboard_id).to_attrs data[:dashboard_elements].each_index do |i| element = data[:dashboard_elements][i] find_vis_config_reference(element) do |vis_config| find_color_palette_reference(vis_config) do |o,default_colors| rewrite_color_palette!(o,default_colors) end end merge_result = merge_query(element[:merge_result_id])&.to_attrs if element[:merge_result_id] if merge_result merge_result[:source_queries].each_index do |j| source_query = merge_result[:source_queries][j] merge_result[:source_queries][j][:query] = query(source_query[:query_id]).to_attrs end find_vis_config_reference(merge_result) do |vis_config| find_color_palette_reference(vis_config) do |o,default_colors| rewrite_color_palette!(o,default_colors) end end data[:dashboard_elements][i][:merge_result] = merge_result end end data[:scheduled_plans] = query_scheduled_plans_for_dashboard(@dashboard_id,"all").to_attrs if [:plans] replacements = {} if [:transform] max_row = 0 data[:dashboard_layouts][0][:dashboard_layout_components].each_index do |i| component = data[:dashboard_layouts][0][:dashboard_layout_components][i] if component[:row] + component[:height] > max_row max_row = component[:row] + component[:height] + 4 end end read_file([:transform]) do |transform| i = 0 transform[:dashboard_elements].collect! do |e| i += 1 # there is no significance to 9900, we just need to prevent ID collisions e['id'] = 9900 + i data[:dashboard_elements] << e # when inserting an element into the top row, shift the other elements down according to the height of the inserted element if e[:position] === 'top' data[:dashboard_layouts][0][:dashboard_layout_components].each_index do |i| component = data[:dashboard_layouts][0][:dashboard_layout_components][i] component[:row] = component[:row] + e[:height] end row = '0' elsif e[:position] === 'bottom' row = max_row.to_s end column = '0' width = e[:width].to_s height = e[:height].to_s data[:dashboard_layouts][0][:dashboard_layout_components] << JSON.parse('{"id":' + e['id'].to_s + ',"dashboard_layout_id":1,"dashboard_element_id":' + e['id'].to_s + ''',"row":' + row + ',"column":' + column + ',"width":' + width + ',"height":' + height + ',"deleted":false,"element_title_hidden":false,"vis_type":"' + e[:type].to_s + '","can":{"index":true,"show":true,"create":true,"update":true,"destroy":true}}') end transform[:replacements].collect! do |e| replacements[e.keys.first.to_s] = e[e.keys[0]] end end end outputJSON = JSON.pretty_generate(data) replacements.each do |k,v| say_warning("Replaced #{k} with #{v}") if [:debug] outputJSON.gsub! k,v end file_name = if [:dir] [:simple_filename] ? "Dashboard_#{data[:id]}.json" : "Dashboard_#{data[:id]}_#{data[:title]}.json" else nil end write_file(file_name, [:dir], nil, output) do |f| f.puts outputJSON end end end |