From dbbedc3ba4d814f2ed18113486fc3443b19cff8e Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 3 Feb 2016 18:04:28 -0800 Subject: [PATCH] Allowing definition of css templates --- .../versions/d827694c7555_css_templates.py | 34 +++++++++++++++++++ panoramix/models.py | 8 +++++ panoramix/static/panoramix.js | 7 ++++ panoramix/templates/panoramix/dashboard.html | 11 ++++-- panoramix/views.py | 17 ++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 panoramix/migrations/versions/d827694c7555_css_templates.py diff --git a/panoramix/migrations/versions/d827694c7555_css_templates.py b/panoramix/migrations/versions/d827694c7555_css_templates.py new file mode 100644 index 00000000000..523bedebcef --- /dev/null +++ b/panoramix/migrations/versions/d827694c7555_css_templates.py @@ -0,0 +1,34 @@ +"""css templates + +Revision ID: d827694c7555 +Revises: 43df8de3a5f4 +Create Date: 2016-02-03 17:41:10.944019 + +""" + +# revision identifiers, used by Alembic. +revision = 'd827694c7555' +down_revision = '43df8de3a5f4' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + + +def upgrade(): + op.create_table('css_templates', + sa.Column('created_on', sa.DateTime(), nullable=False), + sa.Column('changed_on', sa.DateTime(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('template_name', sa.String(length=250), nullable=True), + sa.Column('css', sa.Text(), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), nullable=True), + sa.Column('created_by_fk', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), + sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + + +def downgrade(): + op.drop_table('css_templates') diff --git a/panoramix/models.py b/panoramix/models.py index 6aa51213662..91da2f643e8 100644 --- a/panoramix/models.py +++ b/panoramix/models.py @@ -62,6 +62,14 @@ class Url(Model, AuditMixinNullable): url = Column(Text) +class CssTemplate(Model, AuditMixinNullable): + """CSS templates for dashboards""" + __tablename__ = 'css_templates' + id = Column(Integer, primary_key=True) + template_name = Column(String(250)) + css = Column(Text) + + class Slice(Model, AuditMixinNullable): """A slice is essentially a report or a view on data""" __tablename__ = 'slices' diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js index b7f3a2cc8bd..173f62b068d 100644 --- a/panoramix/static/panoramix.js +++ b/panoramix/static/panoramix.js @@ -489,6 +489,13 @@ var px = (function() { error: function() {alert("Error :(")}, }); }); + $(".select2").select2({dropdownAutoWidth : true}); + $("#css_template").on("change", function() { + var css = $(this).find('option:selected').data('css'); + $('#dash_css').val(css); + $("#user_style").html(css); + + }) $("a.closeslice").click(function() { var li = $(this).parents("li"); gridster.remove_widget(li); diff --git a/panoramix/templates/panoramix/dashboard.html b/panoramix/templates/panoramix/dashboard.html index bd196c89d31..8e6cf7165be 100644 --- a/panoramix/templates/panoramix/dashboard.html +++ b/panoramix/templates/panoramix/dashboard.html @@ -23,7 +23,14 @@