gazer 0.2.36 → 0.2.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b171fe3c480e72780a9b90a0373654e7e9e3dafc2e22e148f229fae80cbacdb
4
- data.tar.gz: 1e46749fc5a805f9a3632ff832bd147530d5da7c651e90aa4b6f6baaceaa39d6
3
+ metadata.gz: f5250ec3e944f1bc95ef659290ad1c703387ceca113aac02aebae90aa38f0183
4
+ data.tar.gz: 43f01e229c1a2f417b28b035f3534273c4732e28b14861b5b2e13d7aa802ed5f
5
5
  SHA512:
6
- metadata.gz: 64ff99189d390dd6d98bdad6339a094c3b2aa0565c498c6af38b0b81ffe595ace06531e9482b580c83c5916e812459fb507901d8906caf0699687e0579c59fa3
7
- data.tar.gz: 6b7cb1b39903606563c13f79ca9c7467c70108840fbe9a00e8a3594ccad4c4506235f434dba054751285ed328b7949a176cbe540cdf68f86eb1b671a9b6a916f
6
+ metadata.gz: a0735c0b31a6b9dfee9f2b40b7915396e5eeea376385effafccc19761d73727715d9475709c86335800736b71b91a90c4ebfcb6b89de01185eb13f95ba91d99d
7
+ data.tar.gz: a9593497bb276fed67cfc3967465d5be31eaa624deb0d33d6423210c70f02460f9c9dde277508369920777930b630b55f62f76fedcee200f181755c9a3ba8eef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gazer (0.2.36)
4
+ gazer (0.2.37)
5
5
  looker-sdk (~> 0.0.7)
6
6
  netrc (~> 0.11.0)
7
7
  pastel (~> 0.7.2)
@@ -55,31 +55,60 @@ module Gzr
55
55
 
56
56
  dashboard = sync_dashboard(data,@dest_space_id, output: output)
57
57
 
58
+
59
+ dashboard[:dashboard_filters] ||= []
58
60
  source_filters = data[:dashboard_filters].sort { |a,b| a[:row] <=> b[:row] }
59
- existing_filters = dashboard.dashboard_filters.sort { |a,b| a.row <=> b.row }
60
- existing_filters.collect! do |e|
61
- matches_by_name_title = source_filters.select { |s| s[:row] != e.row && (s[:title] == e.title || s[:name] == e.name) }
62
- if matches_by_name_title.length > 0
63
- delete_dashboard_filter(e.id)
64
- nil
65
- else
66
- e
61
+ source_filters.each do |new_filter|
62
+ filter = new_filter.select do |k,v|
63
+ (keys_to_keep('create_dashboard_filter') + [:row]).include? k
67
64
  end
68
- end
69
- pairs(source_filters,existing_filters,dashboard.id) do |source,target,id|
70
- say_warning("Synching dashboard filter for dashboard #{id}", output: output) if @options[:debug]
71
- sync_dashboard_filter(source,target,id)
65
+ filter[:dashboard_id] = dashboard.id
66
+ say_warning "Creating filter" if @options[:debug]
67
+ dashboard[:dashboard_filters].append create_dashboard_filter(filter)
72
68
  end
73
69
 
74
- elem_table = pairs(data[:dashboard_elements],dashboard.dashboard_elements,dashboard.id) do |source,target,id|
75
- sync_dashboard_element(source,target,id)
70
+ dashboard[:dashboard_elements] ||= []
71
+ elem_table = data[:dashboard_elements].map do |new_element|
72
+ element = new_element.select do |k,v|
73
+ (keys_to_keep('create_dashboard_element') - [:dashboard_id, :look_id, :query_id, :merge_result_id, :result_maker_id]).include? k
74
+ end
75
+ (element[:query_id],element[:look_id],element[:merge_result_id]) = process_dashboard_element(new_element)
76
+ say_warning "Creating dashboard element #{element.inspect}" if @options[:debug]
77
+ element[:dashboard_id] = dashboard.id
78
+ result_maker = copy_result_maker_filterables(new_element)
79
+ element[:result_maker] = result_maker if result_maker
80
+ dashboard_element = create_dashboard_element(element)
81
+ dashboard[:dashboard_elements].push dashboard_element
82
+ [new_element[:id], dashboard_element.id]
76
83
  end
77
84
 
78
- source_dashboard_layouts = data[:dashboard_layouts].sort_by { |v| (v[:active] ? 0 : 1) }
79
- existing_dashboard_layouts = dashboard.dashboard_layouts.sort_by { |v| (v.active ? 0 : 1) }
80
- pairs(source_dashboard_layouts,existing_dashboard_layouts) do |s,t|
81
- sync_dashboard_layout(dashboard.id,s,t) do |s,t|
82
- sync_dashboard_layout_component(s,t,elem_table)
85
+ source_dashboard_layouts = data[:dashboard_layouts].map do |new_layout|
86
+ layout_obj = nil
87
+ if new_layout[:active]
88
+ layout_obj = get_dashboard_layout(dashboard[:dashboard_layouts].first.id)
89
+ say_warning "Updating layout #{layout_obj.id}" if @options[:debug]
90
+ else
91
+ layout = new_layout.select do |k,v|
92
+ (keys_to_keep('create_dashboard_layout') - [:dashboard_id]).include? k
93
+ end
94
+ layout[:dashboard_id] = dashboard.id
95
+ say_warning "Creating dashboard layout #{layout}" if @options[:debug]
96
+ layout_obj = create_dashboard_layout(layout)
97
+ end
98
+ layout_components = new_layout[:dashboard_layout_components].zip(layout_obj.dashboard_layout_components)
99
+ layout_components.each do |source,target|
100
+ component = keys_to_keep('update_dashboard_layout_component').collect do |e|
101
+ [e,nil]
102
+ end.to_h
103
+ component[:dashboard_layout_id] = target.dashboard_layout_id
104
+
105
+ component.merge!(source.select do |k,v|
106
+ (keys_to_keep('update_dashboard_layout_component') - [:id,:dashboard_layout_id]).include? k
107
+ end)
108
+
109
+ component[:dashboard_element_id] = elem_table.assoc(source[:dashboard_element_id])[1]
110
+ say_warning "Updating dashboard layout component #{target.id}" if @options[:debug]
111
+ update_dashboard_layout_component(target.id,component)
83
112
  end
84
113
  end
85
114
  upsert_plans_for_dashboard(dashboard.id,@me.id,data[:scheduled_plans]) if data[:scheduled_plans]
@@ -127,7 +156,24 @@ module Gzr
127
156
  end
128
157
  new_dash[:slug] = source[:slug] unless slug_used
129
158
  new_dash[:deleted] = false if existing_dashboard[:deleted]
130
- return update_dashboard(existing_dashboard.id,new_dash)
159
+ d = update_dashboard(existing_dashboard.id,new_dash)
160
+
161
+ d.dashboard_filters.each do |f|
162
+ delete_dashboard_filter(f.id)
163
+ end
164
+ d.dashboard_filters = []
165
+
166
+ d.dashboard_elements.each do |e|
167
+ delete_dashboard_element(e.id)
168
+ end
169
+ d.dashboard_elements = []
170
+
171
+ d.dashboard_layouts.each do |l|
172
+ delete_dashboard_layout(l.id) unless l.active
173
+ end
174
+ d.dashboard_layouts.select! { |l| l.active }
175
+
176
+ return d
131
177
  else
132
178
  new_dash = source.select do |k,v|
133
179
  (keys_to_keep('create_dashboard') - [:space_id,:folder_id,:user_id,:slug]).include? k
@@ -139,26 +185,6 @@ module Gzr
139
185
  end
140
186
  end
141
187
 
142
- def sync_dashboard_filter(new_filter,existing_filter,dashboard_id)
143
- if new_filter && !existing_filter then
144
- filter = new_filter.select do |k,v|
145
- (keys_to_keep('create_dashboard_filter') + [:row]).include? k
146
- end
147
- filter[:dashboard_id] = dashboard_id
148
- say_warning "Creating filter" if @options[:debug]
149
- return create_dashboard_filter(filter)
150
- end
151
- if existing_filter && new_filter then
152
- filter = new_filter.select do |k,v|
153
- (keys_to_keep('update_dashboard_filter') + [:row]).include? k
154
- end
155
- say_warning "Updating filter #{existing_filter.id}" if @options[:debug]
156
- return update_dashboard_filter(existing_filter.id,filter)
157
- end
158
- say_warning "Deleting filter #{existing_filter.id}" if @options[:debug]
159
- return delete_dashboard_filter(existing_filter.id)
160
- end
161
-
162
188
  def copy_result_maker_filterables(new_element)
163
189
  return nil unless new_element[:result_maker]
164
190
  if new_element[:result_maker].fetch(:filterables,[]).length > 0
@@ -173,51 +199,6 @@ module Gzr
173
199
  nil
174
200
  end
175
201
 
176
- def sync_dashboard_element(new_element,existing_element,dashboard_id)
177
- if (new_element&.fetch(:type) == 'text' && existing_element && existing_element[:type] != 'text')
178
- say_warning "Deleting dashboard element #{existing_element.id} to recreate it" if @options[:debug]
179
- delete_dashboard_element(existing_element.id)
180
- existing_element = nil
181
- end
182
-
183
- if new_element && !existing_element then
184
- element = new_element.select do |k,v|
185
- (keys_to_keep('create_dashboard_element') - [:dashboard_id, :look_id, :query_id, :merge_result_id]).include? k
186
- end
187
- (element[:query_id],element[:look_id],element[:merge_result_id]) = process_dashboard_element(new_element)
188
- say_warning "Creating dashboard element #{element.inspect}" if @options[:debug]
189
- element[:dashboard_id] = dashboard_id
190
- result_maker = copy_result_maker_filterables(new_element)
191
- element[:result_maker] = result_maker if result_maker
192
- return [new_element[:id], create_dashboard_element(element).id]
193
- end
194
- if existing_element && new_element then
195
- element = keys_to_keep('update_dashboard_element').collect do |e|
196
- [e,nil]
197
- end.to_h
198
-
199
- element[:dashboard_id] = dashboard_id
200
-
201
- element.merge!( new_element.select do |k,v|
202
- (keys_to_keep('update_dashboard_element') - [:dashboard_id, :look_id, :query_id, :merge_result_id]).include? k
203
- end
204
- )
205
- (element[:query_id],element[:look_id],element[:merge_result_id]) = process_dashboard_element(new_element)
206
- if existing_element[:result_maker] && !new_element[:result_maker]
207
- element[:result_maker] = nil
208
- elsif new_element[:result_maker]
209
- result_maker = copy_result_maker_filterables(new_element)
210
- element[:result_maker] = result_maker if result_maker
211
- end
212
-
213
- say_warning "Updating dashboard element #{existing_element.id}" if @options[:debug]
214
- return [new_element[:id], update_dashboard_element(existing_element.id,element).id]
215
- end
216
- say_warning "Deleting dashboard element #{existing_element.id}" if @options[:debug]
217
- delete_dashboard_element(existing_element.id)
218
- return [nil,existing_element.id]
219
- end
220
-
221
202
  def process_dashboard_element(dash_elem)
222
203
  return [nil, upsert_look(@me.id, create_fetch_query(dash_elem[:look][:query]).id, @dest_space_id, dash_elem[:look]).id, nil] if dash_elem[:look]
223
204
 
@@ -230,56 +211,6 @@ module Gzr
230
211
  [nil,nil,nil]
231
212
  end
232
213
 
233
- def sync_dashboard_layout(dashboard_id,new_layout,existing_layout)
234
- layout_obj = nil
235
- if new_layout && !existing_layout then
236
- layout = new_layout.select do |k,v|
237
- (keys_to_keep('create_dashboard_layout') - [:dashboard_id]).include? k
238
- end
239
- layout[:dashboard_id] = dashboard_id
240
- say_warning "Creating dashboard layout #{layout}" if @options[:debug]
241
- layout_obj = create_dashboard_layout(layout)
242
- end
243
- if new_layout && existing_layout then
244
- layout = new_layout.select do |k,v|
245
- (keys_to_keep('update_dashboard_layout') - [:dashboard_id]).include? k
246
- end
247
- say_warning "Updating dashboard layout #{existing_layout.id}" if @options[:debug]
248
- layout_obj = update_dashboard_layout(existing_layout.id,layout)
249
- end
250
- if !new_layout && existing_layout then
251
- say_warning "Deleting dashboard layout #{existing_layout.id}" if @options[:debug]
252
- delete_dashboard_layout(existing_layout.id)
253
- end
254
-
255
- return unless layout_obj
256
-
257
- #say_warning "new_layout[:active] is #{new_layout&.fetch(:active)} for #{layout_obj.id}"
258
- #if layout_obj && new_layout&.fetch(:active,false)
259
- # say_warning "Setting layout #{layout_obj.id} active"
260
- # update_dashboard_layout(layout_obj.id, { :active => true })
261
- #end
262
-
263
- layout_components = new_layout[:dashboard_layout_components].zip(layout_obj.dashboard_layout_components)
264
- return layout_components unless block_given?
265
-
266
- layout_components.each { |s,t| yield(s,t) }
267
- end
268
-
269
- def sync_dashboard_layout_component(source, target, elem_table)
270
- component = keys_to_keep('update_dashboard_layout_component').collect do |e|
271
- [e,nil]
272
- end.to_h
273
- component[:dashboard_layout_id] = target.dashboard_layout_id
274
-
275
- component.merge!(source.select do |k,v|
276
- (keys_to_keep('update_dashboard_layout_component') - [:id,:dashboard_layout_id]).include? k
277
- end)
278
-
279
- component[:dashboard_element_id] = elem_table.assoc(source[:dashboard_element_id])[1]
280
- say_warning "Updating dashboard layout component #{target.id}" if @options[:debug]
281
- update_dashboard_layout_component(target.id,component)
282
- end
283
214
  end
284
215
  end
285
216
  end
@@ -139,6 +139,17 @@ module Gzr
139
139
  data
140
140
  end
141
141
 
142
+ def get_dashboard_layout(id)
143
+ begin
144
+ data = @sdk.dashboard_layout(id)
145
+ rescue LookerSDK::Error => e
146
+ say_error "Error getting dashboard_layout(#{id})"
147
+ say_error e.message
148
+ raise
149
+ end
150
+ data
151
+ end
152
+
142
153
  def create_dashboard_layout(dash_layout)
143
154
  begin
144
155
  data = @sdk.create_dashboard_layout(dash_layout)
data/lib/gzr/version.rb CHANGED
@@ -20,5 +20,5 @@
20
20
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  module Gzr
23
- VERSION = "0.2.36"
23
+ VERSION = "0.2.37"
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.36
4
+ version: 0.2.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike DeAngelo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-04 00:00:00.000000000 Z
11
+ date: 2020-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-reader
@@ -357,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
357
357
  - !ruby/object:Gem::Version
358
358
  version: '0'
359
359
  requirements: []
360
- rubygems_version: 3.0.6
360
+ rubygems_version: 3.0.8
361
361
  signing_key:
362
362
  specification_version: 4
363
363
  summary: Command line tool to manage the content of a Looker instance.