From f6753afa75dc1229f5b5ab4188808b66b9be9962 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 17 Sep 2015 18:06:03 -0700 Subject: [PATCH] Panoramix v1 dashboards is up --- panoramix/highchart.py | 2 +- panoramix/models.py | 29 +++- panoramix/templates/panoramix/dashboard.html | 147 +++++++++++++----- .../templates/panoramix/viz_highcharts.html | 39 +++-- panoramix/templates/panoramix/viz_table.html | 7 +- panoramix/utils.py | 28 ++++ panoramix/views.py | 39 ++++- panoramix/viz.py | 69 +++++--- setup.py | 2 +- 9 files changed, 265 insertions(+), 97 deletions(-) diff --git a/panoramix/highchart.py b/panoramix/highchart.py index 9f3cf2d48d186..e2fdd7596a4c4 100644 --- a/panoramix/highchart.py +++ b/panoramix/highchart.py @@ -196,7 +196,7 @@ def serialize_yaxis(self): class HighchartBubble(BaseHighchart): - def __init__(self, df, target_div='chart', height=800): + def __init__(self, df, target_div=None, height=None): self.df = df self.chart = { 'chart': { diff --git a/panoramix/models.py b/panoramix/models.py index 20197e90cefbe..93610b75f0131 100644 --- a/panoramix/models.py +++ b/panoramix/models.py @@ -8,11 +8,11 @@ from pydruid.utils.filters import Dimension, Filter from sqlalchemy import ( Column, Integer, String, ForeignKey, Text, Boolean, DateTime) -from panoramix.utils import JSONEncodedDict from sqlalchemy import Table as sqlaTable from sqlalchemy import create_engine, MetaData, desc, select, and_, Table from sqlalchemy.orm import relationship from sqlalchemy.sql import table, literal_column, text +from flask import request from copy import deepcopy, copy from collections import namedtuple @@ -22,8 +22,8 @@ import requests import textwrap -from panoramix import db, get_session -import config +from panoramix import db, get_session, config, utils +from panoramix.viz import viz_types QueryResult = namedtuple('namedtuple', ['df', 'query', 'duration']) @@ -52,18 +52,32 @@ def __repr__(self): def datasource(self): return self.table or self.druid_datasource + @property + @utils.memoized + def viz(self): + d = json.loads(self.params) + viz = viz_types[self.viz_type]( + self.datasource, + form_data=d) + return viz + @property def datasource_id(self): datasource = self.datasource return datasource.id if datasource else None @property - def slice_link(self): + def slice_url(self): d = json.loads(self.params) - kwargs = "&".join([k + '=' + v for k, v in d.iteritems()]) - url = ( + from werkzeug.urls import Href + href = Href( "/panoramix/{self.datasource_type}/" - "{self.datasource_id}/?{kwargs}").format(**locals()) + "{self.datasource_id}/".format(self=self)) + return href(d) + + @property + def slice_link(self): + url = self.slice_url return '{self.slice_name}'.format(**locals()) @property @@ -92,6 +106,7 @@ class Dashboard(Model, AuditMixin): __tablename__ = 'dashboards' id = Column(Integer, primary_key=True) dashboard_title = Column(String(500)) + position_json = Column(Text) slices = relationship( 'Slice', secondary=dashboard_slices, backref='dashboards') diff --git a/panoramix/templates/panoramix/dashboard.html b/panoramix/templates/panoramix/dashboard.html index 23fc55519a3ba..28600eda4366d 100644 --- a/panoramix/templates/panoramix/dashboard.html +++ b/panoramix/templates/panoramix/dashboard.html @@ -7,12 +7,30 @@ {% endfor %}