-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add embeddable charts #268
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
.chart-container { | ||
clear: both; | ||
} | ||
|
||
.chart-container h4 { | ||
text-align: center; | ||
} | ||
|
||
.chart-container h4 a { | ||
color: inherit; | ||
} | ||
|
||
.query-error { | ||
color: red; | ||
} | ||
|
||
.chart-container { | ||
margin-bottom: 30px; | ||
} | ||
|
||
.chart { | ||
height: 300px; | ||
text-align: center; | ||
display: flex; | ||
justify-content: center; | ||
flex-direction: column; | ||
} | ||
|
||
.chart > .results-container { | ||
height: 300px; | ||
border: solid 1px #ddd; | ||
overflow: scroll; | ||
text-align: left; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<% unless defined?(@blazer_query_assets_loaded) && @blazer_query_assets_loaded %> | ||
<%= stylesheet_link_tag "blazer/chart" %> | ||
<%= javascript_include_tag "blazer/application" %> | ||
<% @blazer_query_assets_loaded = true %> | ||
<% end %> | ||
|
||
<div class="chart-container"> | ||
<h4><%= link_to query.friendly_name, blazer.query_path(query, local_assigns[:params] || {}), target: "_blank" %></h4> | ||
<div id="chart-<%= query.id %>" class="chart"> | ||
<p class="text-muted">Loading...</p> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
<%= blazer_js_var "rootPath", blazer.root_path %> | ||
<%= blazer_js_var "data", {statement: query.statement, query_id: query.id, data_source: query.data_source, only_chart: true} %> | ||
|
||
runQuery(data, function (data) { | ||
$("#chart-<%= query.id %>").html(data) | ||
$("#chart-<%= query.id %> table").stupidtable(stupidtableCustomSettings) | ||
}, function (message) { | ||
$("#chart-<%= query.id %>").addClass("query-error").html(message) | ||
}); | ||
</script> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,14 @@ class Engine < ::Rails::Engine | |
isolate_namespace Blazer | ||
|
||
initializer "blazer" do |app| | ||
ActiveSupport.on_load :action_view do | ||
include Blazer::BaseHelper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required so we can call I don't think this is a concern, especially as we have prefixed all methods with Can anyone think of trouble this could cause? |
||
end | ||
|
||
if defined?(Sprockets) && Sprockets::VERSION >= "4" | ||
app.config.assets.precompile << "blazer/application.js" | ||
app.config.assets.precompile << "blazer/application.css" | ||
app.config.assets.precompile << "blazer/chart.css" | ||
app.config.assets.precompile << "blazer/glyphicons-halflings-regular.eot" | ||
app.config.assets.precompile << "blazer/glyphicons-halflings-regular.svg" | ||
app.config.assets.precompile << "blazer/glyphicons-halflings-regular.ttf" | ||
|
@@ -15,6 +20,7 @@ class Engine < ::Rails::Engine | |
else | ||
# use a proc instead of a string | ||
app.config.assets.precompile << proc { |path| path =~ /\Ablazer\/application\.(js|css)\z/ } | ||
app.config.assets.precompile << proc { |path| path =~ /\Ablazer\/chart\.css\z/ } | ||
app.config.assets.precompile << proc { |path| path =~ /\Ablazer\/.+\.(eot|svg|ttf|woff|woff2)\z/ } | ||
app.config.assets.precompile << proc { |path| path == "blazer/favicon.png" } | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken from https://github.com/ankane/blazer/blob/master/app/views/blazer/dashboards/show.html.erb#L35-L50
I chose not to use this fragment there as I also wanted to embed some
stylesheet_link_tag
andjavascript_include_tag
and we had a call torootPath
as well.