Skip to content
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

Allowing for templated urls in iFrame #460

Merged
merged 3 commits into from
May 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions caravel/assets/javascripts/modules/caravel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var $ = require('jquery');
var jQuery = $;
var d3 = require('d3');
var Mustache = require('mustache');

// vis sources
var sourceMap = {
Expand Down Expand Up @@ -215,6 +216,13 @@ var px = (function () {
getWidgetHeader: function () {
return this.container.parents("li.widget").find(".chart-header");
},
render_template: function (s) {
var context = {
width: this.width,
height: this.height
};
return Mustache.render(s, context);
},
jsonEndpoint: function () {
var parser = document.createElement('a');
parser.href = data.json_endpoint;
Expand Down
1 change: 1 addition & 0 deletions caravel/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"jquery-ui": "^1.10.5",
"less": "^2.6.1",
"less-loader": "^2.2.2",
"mustache": "^2.2.1",
"nvd3": "1.8.2",
"react": "^0.14.7",
"react-bootstrap": "^0.28.3",
Expand Down
3 changes: 2 additions & 1 deletion caravel/assets/visualizations/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ function iframeWidget(slice) {
function refresh() {
$('#code').attr('rows', '15');
$.getJSON(slice.jsonEndpoint(), function (payload) {
var url = slice.render_template(payload.form_data.url);
slice.container.html('<iframe style="width:100%;"></iframe>');
var iframe = slice.container.find('iframe');
iframe.css('height', slice.height());
iframe.attr('src', payload.form_data.url);
iframe.attr('src', url);
slice.done();
})
.fail(function (xhr) {
Expand Down
7 changes: 6 additions & 1 deletion caravel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ def __init__(self, viz):
default=default_metric,
choices=datasource.metrics_combo),
'url': TextField(
'URL', default='https://www.youtube.com/embed/JkI5rg_VcQ4',),
'URL',
description=(
"The URL, this field is templated, so you can integrate "
"{{ width }} and/or {{ height }} in your URL string."
),
default='https://www.youtube.com/embed/JkI5rg_VcQ4',),
'where': TextField(
'Custom WHERE clause', default='',
description=(
Expand Down