diff --git a/panoramix/migrations/versions/5a7bad26f2a7_.py b/panoramix/migrations/versions/5a7bad26f2a7_.py new file mode 100644 index 0000000000000..ced2d6e0d1480 --- /dev/null +++ b/panoramix/migrations/versions/5a7bad26f2a7_.py @@ -0,0 +1,24 @@ +"""empty message + +Revision ID: 5a7bad26f2a7 +Revises: 4e6a06bad7a8 +Create Date: 2015-10-05 10:32:15.850753 + +""" + +# revision identifiers, used by Alembic. +revision = '5a7bad26f2a7' +down_revision = '4e6a06bad7a8' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +def upgrade(): + op.add_column('dashboards', sa.Column('css', sa.Text(), nullable=True)) + op.add_column('dashboards', sa.Column('description', sa.Text(), nullable=True)) + + +def downgrade(): + op.drop_column('dashboards', 'description') + op.drop_column('dashboards', 'css') diff --git a/panoramix/models.py b/panoramix/models.py index 7a7534db3c610..6ee24d6936110 100644 --- a/panoramix/models.py +++ b/panoramix/models.py @@ -128,6 +128,8 @@ class Dashboard(Model, AuditMixinNullable): id = Column(Integer, primary_key=True) dashboard_title = Column(String(500)) position_json = Column(Text) + description = Column(Text) + css = Column(Text) slices = relationship( 'Slice', secondary=dashboard_slices, backref='dashboards') diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js index 7d97d273e1b98..0eeedc539de9b 100644 --- a/panoramix/static/panoramix.js +++ b/panoramix/static/panoramix.js @@ -118,7 +118,7 @@ function initializeDatasourceView() { }); } -function initializeDashboardView() { +function initializeDashboardView(dashboard_id) { var gridster = $(".gridster ul").gridster({ widget_margins: [5, 5], widget_base_dimensions: [100, 100], @@ -143,12 +143,17 @@ function initializeDashboardView() { }).data('gridster'); $("div.gridster").css('visibility', 'visible'); $("#savedash").click(function() { - var data = gridster.serialize(); + var data = { + positions: gridster.serialize(), + css: $("#dash_css").val() + }; + console.log(data); $.ajax({ type: "POST", - url: '/panoramix/save_dash/{{ dashboard.id }}/', - data: {data: JSON.stringify(data)}, - success: function() {}, + url: '/panoramix/save_dash/' + dashboard_id + '/', + data: {'data': JSON.stringify(data)}, + success: function() {alert("Saved!")}, + error: function() {alert("Error :(")}, }); }); $("a.closewidget").click(function() { @@ -161,4 +166,8 @@ function initializeDashboardView() { $("table.widget_header").mouseout(function() { $(this).find("td.icons nobr").hide(); }); + $("#dash_css").on("keyup", function(){ + css = $(this).val(); + $("#user_style").html(css); + }); } diff --git a/panoramix/templates/panoramix/dashboard.html b/panoramix/templates/panoramix/dashboard.html index 232816632645e..050bdac69c20e 100644 --- a/panoramix/templates/panoramix/dashboard.html +++ b/panoramix/templates/panoramix/dashboard.html @@ -6,6 +6,9 @@ {% endfor %} + {% for slice in dashboard.slices %} {% set viz = slice.viz %} {% import viz.template as viz_macros %} @@ -15,17 +18,51 @@ {% block content_fluid %}
+ + + +

{{ dashboard.dashboard_title }}
+ - - - + + +

@@ -80,7 +117,9 @@

{% endfor %} {% for slice in dashboard.slices %} {% set viz = slice.viz %} diff --git a/panoramix/views.py b/panoramix/views.py index bb5b4357225df..981fd05bcd88e 100644 --- a/panoramix/views.py +++ b/panoramix/views.py @@ -185,7 +185,7 @@ class SliceModelView(PanoramixModelView, DeleteMixin): class DashboardModelView(PanoramixModelView, DeleteMixin): datamodel = SQLAInterface(models.Dashboard) list_columns = ['dashboard_link', 'created_by'] - edit_columns = ['dashboard_title', 'slices', 'position_json'] + edit_columns = ['dashboard_title', 'slices', 'position_json', 'css'] add_columns = edit_columns @@ -339,12 +339,14 @@ def datasource(self, datasource_type, datasource_id): @expose("/save_dash//", methods=['GET', 'POST']) def save_dash(self, dashboard_id): data = json.loads(request.form.get('data')) - slice_ids = [int(d['slice_id']) for d in data] + positions = data['positions'] + slice_ids = [int(d['slice_id']) for d in positions] session = db.session() Dash = models.Dashboard dash = session.query(Dash).filter_by(id=dashboard_id).first() dash.slices = [o for o in dash.slices if o.id in slice_ids] - dash.position_json = json.dumps(data, indent=4) + dash.position_json = json.dumps(data['positions'], indent=4) + dash.css = data['css'] session.merge(dash) session.commit() session.close()