blazer 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of blazer might be problematic. Click here for more details.

@@ -107,7 +107,7 @@ module Blazer
107
107
  if query
108
108
  values = @rows.map { |r| r[key] }.compact.uniq
109
109
  rows, error, cached_at = @data_source.run_statement(ActiveRecord::Base.send(:sanitize_sql_array, [query.sub("{value}", "(?)"), values]))
110
- @boom[key] = Hash[rows.map(&:values)]
110
+ @boom[key] = Hash[rows.map(&:values).map { |k, v| [k.to_s, v] }]
111
111
  end
112
112
  end
113
113
 
@@ -150,6 +150,10 @@ module Blazer
150
150
  end
151
151
 
152
152
  def update
153
+ if params[:commit] == "Fork"
154
+ @query = Blazer::Query.new
155
+ @query.creator = blazer_user if @query.respond_to?(:creator)
156
+ end
153
157
  if @query.update(query_params)
154
158
  redirect_to query_path(@query, variable_params)
155
159
  else
@@ -202,7 +206,7 @@ module Blazer
202
206
  csv << rows.first.keys
203
207
  end
204
208
  rows.each do |row|
205
- csv << row.values
209
+ csv << row.values.map { |v| v.is_a?(Time) ? v.in_time_zone(Blazer.time_zone) : v }
206
210
  end
207
211
  end
208
212
  end
@@ -16,6 +16,21 @@ module Blazer
16
16
  end
17
17
  end
18
18
 
19
+ def blazer_column_types(columns, rows, boom)
20
+ columns.map do |k, _|
21
+ v = (rows.find { |r| r[k] } || {})[k]
22
+ if boom[k]
23
+ "string"
24
+ elsif v.is_a?(Numeric)
25
+ "numeric"
26
+ elsif v.is_a?(Time) || v.is_a?(Date)
27
+ "time"
28
+ else
29
+ "string"
30
+ end
31
+ end
32
+ end
33
+
19
34
  def blazer_maps?
20
35
  ENV["MAPBOX_ACCESS_TOKEN"].present?
21
36
  end
@@ -3,6 +3,7 @@ module Blazer
3
3
  belongs_to :creator, class_name: Blazer.user_class.to_s if Blazer.user_class
4
4
  has_many :checks, dependent: :destroy
5
5
  has_many :dashboard_queries, dependent: :destroy
6
+ has_many :dashboards, through: :dashboard_queries
6
7
  has_many :audits
7
8
 
8
9
  validates :name, presence: true
@@ -12,9 +12,13 @@
12
12
  li:hover .glyphicon-remove {
13
13
  display: inline;
14
14
  }
15
+
16
+ .list-group {
17
+ cursor: move;
18
+ }
15
19
  </style>
16
20
 
17
- <%= form_for @dashboard do |f| %>
21
+ <%= form_for @dashboard, url: (@dashboard.persisted? ? dashboard_path(@dashboard, variable_params) : dashboards_path(variable_params)) do |f| %>
18
22
  <div class="form-group">
19
23
  <%= f.label :name %>
20
24
  <%= f.text_field :name, class: "form-control" %>
@@ -24,7 +24,7 @@
24
24
  </h3>
25
25
  </div>
26
26
  <div class="col-sm-3 text-right">
27
- <%= link_to "Edit", edit_dashboard_path(@dashboard), class: "btn btn-info" %>
27
+ <%= link_to "Edit", edit_dashboard_path(@dashboard, variable_params), class: "btn btn-info" %>
28
28
  </div>
29
29
  </div>
30
30
  </div>
@@ -32,6 +32,13 @@
32
32
 
33
33
  <div style="margin-bottom: 60px;"></div>
34
34
 
35
+ <% if @data_sources.any? { |ds| ds.cache } %>
36
+ <p class="text-muted" style="float: right;">
37
+ Some queries are cached
38
+ <%= link_to "Refresh", refresh_dashboard_path(@dashboard, variable_params), method: :post %>
39
+ </p>
40
+ <% end %>
41
+
35
42
  <% if @bind_vars.any? %>
36
43
  <form id="bind" method="get" action="<%= url_for(params) %>" class="form-inline" style="margin-bottom: 10px;">
37
44
  <% date_vars = ["start_time", "end_time"] %>
@@ -54,7 +61,7 @@
54
61
  <%= text_field_tag var, params[var], style: "width: 120px; margin-right: 20px;", autofocus: i == 0 && !var.end_with?("_at") && !params[var], class: "form-control" %>
55
62
  <% if var.end_with?("_at") %>
56
63
  <script>
57
- $("#<%= var %>").datepicker({format: "yyyy-mm-dd", autoclose: true, todayBtn: "linked"})
64
+ $("#<%= var %>").daterangepicker({singleDatePicker: true, locale: {format: "YYYY-MM-DD"}});
58
65
  </script>
59
66
  <% end %>
60
67
  <% end %>
@@ -97,7 +104,9 @@
97
104
  "Last 7 Days": [dateStr(6), dateStr()],
98
105
  "Last 30 Days": [dateStr(29), dateStr()]
99
106
  },
100
- format: format,
107
+ locale: {
108
+ format: format
109
+ },
101
110
  startDate: dateStr(29),
102
111
  endDate: dateStr(),
103
112
  opens: "left"
@@ -44,9 +44,13 @@
44
44
  <div class="text-right">
45
45
  <% if @query.persisted? %>
46
46
  <%= link_to "Delete", query_path(@query), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger" %>
47
+ <%= f.submit "Fork", class: "btn btn-info" %>
47
48
  <% end %>
48
49
  <%= f.submit @query.persisted? ? "Update" : "Create", class: "btn btn-success" %>
49
50
  </div>
51
+ <% if @query.persisted? && (dashboards_count = @query.dashboards.count) > 0 %>
52
+ <div class="alert alert-info" style="margin-top: 10px; padding: 8px 12px;">Part of <%= pluralize(dashboards_count, "dashboard") %>. Be careful when editing.</div>
53
+ <% end %>
50
54
  </div>
51
55
  </div>
52
56
  <% end %>
@@ -26,6 +26,7 @@
26
26
  <% if @rows.any? %>
27
27
  <% values = @rows.first.values %>
28
28
  <% chart_id = SecureRandom.hex %>
29
+ <% column_types = blazer_column_types(@columns, @rows, @boom) %>
29
30
  <% if blazer_maps? && @markers.any? %>
30
31
  <div id="map" style="height: <%= @only_chart ? 300 : 500 %>px;"></div>
31
32
  <script>
@@ -55,14 +56,15 @@
55
56
  featureLayer.setGeoJSON(geojson);
56
57
  map.fitBounds(featureLayer.getBounds());
57
58
  </script>
58
- <% elsif values.size >= 2 && (values.first.is_a?(Time) || values.first.is_a?(Date)) && values[1..-1].all?{|v| v.is_a?(Numeric) } %>
59
+ <% elsif values.size >= 2 && column_types == ["time"] + (values.size - 1).times.map { "numeric" } %>
59
60
  <% time_k = @columns.keys.first %>
60
61
  <%= line_chart @columns.keys[1..-1].map{|k| {name: k, data: @rows.map{|r| [r[time_k], r[k]] }} }, id: chart_id, min: nil %>
61
- <% elsif values.size == 3 && (values.first.is_a?(Time) || values.first.is_a?(Date)) && values[1].is_a?(String) && values[2].is_a?(Numeric) %>
62
+ <% elsif values.size == 3 && column_types == ["time", "string", "numeric"] %>
62
63
  <% keys = @columns.keys %>
63
- <%= line_chart @rows.group_by { |v| v[keys[1]] }.map { |name, v| {name: name, data: v.map { |v2| [v2[keys[0]], v2[keys[2]]] } } }, id: chart_id, min: nil %>
64
- <% elsif values.size == 2 && values.first.is_a?(String) && values.last.is_a?(Numeric) %>
65
- <%= pie_chart @rows.map(&:values), library: {sliceVisibilityThreshold: 1 / 40.0}, id: chart_id %>
64
+ <%= line_chart @rows.group_by { |r| k = keys[1]; v = r[k]; (@boom[k] || {})[v.to_s] || v }.map { |name, v| {name: name, data: v.map { |v2| [v2[keys[0]], v2[keys[2]]] } } }, id: chart_id, min: nil %>
65
+ <% elsif values.size >= 2 && column_types == ["string"] + (values.size - 1).times.map { "numeric" } %>
66
+ <% keys = @columns.keys %>
67
+ <%= column_chart (values.size - 1).times.map { |i| name = @columns.keys[i + 1]; {name: name, data: @rows.first(20).map { |r| [(@boom[keys[0]] || {})[r[keys[0]].to_s] || r[keys[0]], r[keys[i + 1]]] } } }, id: chart_id %>
66
68
  <% elsif @only_chart %>
67
69
  <% if @rows.size == 1 && @rows.first.size == 1 %>
68
70
  <p style="font-size: 160px;"><%= blazer_format_value(@rows.first.keys.first, @rows.first.values.first) %></p>
@@ -104,7 +106,7 @@
104
106
  <%= blazer_format_value(k, v) %>
105
107
  <% end %>
106
108
 
107
- <% if v2 = (@boom[k] || {})[v] %>
109
+ <% if v2 = (@boom[k] || {})[v.to_s] %>
108
110
  <div class="text-muted"><%= v2 %></div>
109
111
  <% end %>
110
112
  <% end %>
@@ -73,7 +73,7 @@
73
73
  <%= text_field_tag var, params[var], style: "width: 120px; margin-right: 20px;", autofocus: i == 0 && !var.end_with?("_at") && !params[var], class: "form-control" %>
74
74
  <% if var.end_with?("_at") %>
75
75
  <script>
76
- $("#<%= var %>").datepicker({format: "yyyy-mm-dd", autoclose: true, todayBtn: "linked"})
76
+ $("#<%= var %>").daterangepicker({singleDatePicker: true, locale: {format: "YYYY-MM-DD"}});
77
77
  </script>
78
78
  <% end %>
79
79
  <% end %>
@@ -116,10 +116,12 @@
116
116
  "Last 7 Days": [dateStr(6), dateStr()],
117
117
  "Last 30 Days": [dateStr(29), dateStr()]
118
118
  },
119
- format: format,
119
+ locale: {
120
+ format: format
121
+ },
120
122
  startDate: dateStr(29),
121
123
  endDate: dateStr(),
122
- opens: "left"
124
+ opens: "right"
123
125
  },
124
126
  function(start, end) {
125
127
  setTimeInputs(start, end);
@@ -6,7 +6,7 @@
6
6
  <meta charset="utf-8" />
7
7
 
8
8
  <%= stylesheet_link_tag "blazer/application" %>
9
- <%= javascript_include_tag "//www.google.com/jsapi", "blazer/application" %>
9
+ <%= javascript_include_tag "https://www.google.com/jsapi", "blazer/application" %>
10
10
  <% if blazer_maps? %>
11
11
  <%= stylesheet_link_tag "https://api.mapbox.com/mapbox.js/v2.2.2/mapbox.css" %>
12
12
  <%= javascript_include_tag "https://api.mapbox.com/mapbox.js/v2.2.2/mapbox.js" %>
data/config/routes.rb CHANGED
@@ -7,6 +7,8 @@ Blazer::Engine.routes.draw do
7
7
  resources :checks, except: [:show] do
8
8
  get :run, on: :member
9
9
  end
10
- resources :dashboards
10
+ resources :dashboards do
11
+ post :refresh, on: :member
12
+ end
11
13
  root to: "queries#home"
12
14
  end
data/lib/blazer.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "csv"
2
+ require "yaml"
2
3
  require "chartkick"
3
4
  require "blazer/version"
4
5
  require "blazer/data_source"
data/lib/blazer/engine.rb CHANGED
@@ -5,6 +5,7 @@ module Blazer
5
5
  initializer "blazer" do |app|
6
6
  # use a proc instead of a string
7
7
  app.config.assets.precompile << proc { |path| path =~ /\Ablazer\/application\.(js|css)\z/ }
8
+ app.config.assets.precompile << proc { |path| path =~ /\Ablazer\/.+\.(eot|svg|ttf|woff)\z/ }
8
9
 
9
10
  Blazer.time_zone ||= Blazer.settings["time_zone"] || Time.zone
10
11
  Blazer.audit = Blazer.settings.key?("audit") ? Blazer.settings["audit"] : true
@@ -1,3 +1,3 @@
1
1
  module Blazer
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-05 00:00:00.000000000 Z
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -79,6 +79,11 @@ files:
79
79
  - LICENSE.txt
80
80
  - README.md
81
81
  - Rakefile
82
+ - app/assets/fonts/blazer/glyphicons-halflings-regular.eot
83
+ - app/assets/fonts/blazer/glyphicons-halflings-regular.svg
84
+ - app/assets/fonts/blazer/glyphicons-halflings-regular.ttf
85
+ - app/assets/fonts/blazer/glyphicons-halflings-regular.woff
86
+ - app/assets/fonts/blazer/glyphicons-halflings-regular.woff2
82
87
  - app/assets/javascripts/blazer/Sortable.js
83
88
  - app/assets/javascripts/blazer/ace/ace.js
84
89
  - app/assets/javascripts/blazer/ace/ext-language_tools.js
@@ -100,7 +105,7 @@ files:
100
105
  - app/assets/javascripts/blazer/selectize.js
101
106
  - app/assets/javascripts/blazer/stupidtable.js
102
107
  - app/assets/stylesheets/blazer/application.css
103
- - app/assets/stylesheets/blazer/bootstrap.css
108
+ - app/assets/stylesheets/blazer/bootstrap.css.erb
104
109
  - app/assets/stylesheets/blazer/daterangepicker-bs3.css
105
110
  - app/assets/stylesheets/blazer/github.css
106
111
  - app/assets/stylesheets/blazer/selectize.default.css
@@ -168,9 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
173
  version: '0'
169
174
  requirements: []
170
175
  rubyforge_project:
171
- rubygems_version: 2.4.5
176
+ rubygems_version: 2.4.5.1
172
177
  signing_key:
173
178
  specification_version: 4
174
179
  summary: Share data effortlessly with your team
175
180
  test_files: []
176
- has_rdoc: