Skip to content

Commit

Permalink
Merge pull request #128 from mistercrunch/css_templates
Browse files Browse the repository at this point in the history
Allowing definition of css templates
  • Loading branch information
mistercrunch committed Feb 4, 2016
2 parents 9838fbb + dbbedc3 commit cf5d290
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
34 changes: 34 additions & 0 deletions panoramix/migrations/versions/d827694c7555_css_templates.py
Original file line number Diff line number Diff line change
@@ -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')
8 changes: 8 additions & 0 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions panoramix/templates/panoramix/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
<h4 class="modal-title" id="myModalLabel">Dashboard CSS</h4>
</div>
<div class="modal-body">
<textarea id="dash_css" rows="30" cols="60">
<select id="css_template" class="select2">
{% for t in templates %}
<option value="{{ t.id }}" data-css="{{t.css}}">
{{ t.template_name }}
</option>
{% endfor %}
</select><br>
<textarea id="dash_css" rows="30" cols="60" style="margin-top: 5px;">
{%- if dashboard.css %}
{{- dashboard.css }}
{% else %}
Expand Down Expand Up @@ -58,7 +65,7 @@ <h2>
<i class="fa fa-filter"></i>
</button>
<button type="button" id="css" class="btn btn-default" data-toggle="modal" data-target="#css_modal">
<i class="fa fa-code"></i>
<i class="fa fa-css3"></i>
</button>
<a id="editdash" class="btn btn-default" href="/dashboardmodelview/edit/{{ dashboard.id }}">
<i class="fa fa-edit"></i>
Expand Down
17 changes: 17 additions & 0 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ class ClusterModelView(PanoramixModelView, DeleteMixin):
category_icon='fa-database',)


class CssTemplateModelView(PanoramixModelView, DeleteMixin):
datamodel = SQLAInterface(models.CssTemplate)
list_columns = ['template_name']
edit_columns = ['template_name', 'css']
add_columns = edit_columns

appbuilder.add_view(
CssTemplateModelView,
"CSS Templates",
icon="fa-css3",
category="",
category_icon='',)


class SliceModelView(PanoramixModelView, DeleteMixin):
datamodel = SQLAInterface(models.Slice)
can_add = False
Expand Down Expand Up @@ -539,6 +553,8 @@ def dashboard(self, identifier):
else:
qry = qry.filter_by(slug=identifier)

templates = session.query(models.CssTemplate).all()

dashboard = qry.first()
pos_dict = {}
if dashboard.position_json:
Expand All @@ -547,6 +563,7 @@ def dashboard(self, identifier):
for o in json.loads(dashboard.position_json)}
return self.render_template(
"panoramix/dashboard.html", dashboard=dashboard,
templates=templates,
pos_dict=pos_dict)

@has_access
Expand Down

0 comments on commit cf5d290

Please sign in to comment.