From 5f9f95b717ee54f20e43e72a1e2d87a888e04c8a Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Tue, 19 Jan 2016 00:38:15 -0800 Subject: [PATCH 1/2] Adding a basic ifram viz --- panoramix/forms.py | 2 ++ panoramix/static/widgets/viz_iframe.js | 20 ++++++++++++++++++++ panoramix/viz.py | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 panoramix/static/widgets/viz_iframe.js diff --git a/panoramix/forms.py b/panoramix/forms.py index d999a4fefa9d7..dc71eb747fb26 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -288,6 +288,8 @@ def __init__(self, viz): 'Bubble Size', default=default_metric, choices=datasource.metrics_combo), + 'url': TextField( + 'URL', default='www.airbnb.com',), 'where': TextField( 'Custom WHERE clause', default='', description=( diff --git a/panoramix/static/widgets/viz_iframe.js b/panoramix/static/widgets/viz_iframe.js new file mode 100644 index 0000000000000..74a1da3550676 --- /dev/null +++ b/panoramix/static/widgets/viz_iframe.js @@ -0,0 +1,20 @@ +px.registerViz('iframe', function(slice) { + + function refresh() { + $('#code').attr('rows', '15') + $.getJSON(slice.jsonEndpoint(), function(payload) { + slice.container.html( + ''); + console.log(slice); + slice.container.find('iframe').attr('src', payload.form_data.url); + slice.done(); + }) + .fail(function(xhr) { + slice.error(xhr.responseText); + }); + }; + return { + render: refresh, + resize: refresh, + }; +}); diff --git a/panoramix/viz.py b/panoramix/viz.py index 9e513be6667c4..87829807b5511 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -1146,6 +1146,18 @@ def get_json_data(self): return dumps(d) +class IFrameViz(BaseViz): + viz_type = "iframe" + verbose_name = "iFrame" + is_timeseries = False + js_files = ['widgets/viz_iframe.js'] + fieldsets = ( + { + 'label': None, + 'fields': ('url',) + },) + + viz_types_list = [ TableViz, PivotTableViz, @@ -1164,6 +1176,7 @@ def get_json_data(self): SankeyViz, WorldMapViz, FilterBoxViz, + IFrameViz, ] -# This dict is used to + viz_types = OrderedDict([(v.viz_type, v) for v in viz_types_list]) From 5f880682c0887c5ef8e34168ad40da377a474cda Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Tue, 19 Jan 2016 12:58:44 -0800 Subject: [PATCH 2/2] Fixing a bug --- panoramix/models.py | 5 ++++- panoramix/static/widgets/viz_iframe.js | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/panoramix/models.py b/panoramix/models.py index 2b466872080a6..3a036b8cb9f75 100644 --- a/panoramix/models.py +++ b/panoramix/models.py @@ -173,7 +173,10 @@ def url(self): @property def metadata_dejson(self): - return json.loads(self.json_metadata) + if self.json_metadata: + return json.loads(self.json_metadata) + else: + return {} def dashboard_link(self): return '{self.dashboard_title}'.format(self=self) diff --git a/panoramix/static/widgets/viz_iframe.js b/panoramix/static/widgets/viz_iframe.js index 74a1da3550676..fc59b8a8c8a5d 100644 --- a/panoramix/static/widgets/viz_iframe.js +++ b/panoramix/static/widgets/viz_iframe.js @@ -4,9 +4,11 @@ px.registerViz('iframe', function(slice) { $('#code').attr('rows', '15') $.getJSON(slice.jsonEndpoint(), function(payload) { slice.container.html( - ''); + ''); console.log(slice); - slice.container.find('iframe').attr('src', payload.form_data.url); + iframe = slice.container.find('iframe'); + iframe.css('height', slice.height()); + iframe.attr('src', payload.form_data.url); slice.done(); }) .fail(function(xhr) {