mirror of
https://github.com/apache/superset.git
synced 2024-09-12 08:39:45 -04:00
Merge pull request #128 from mistercrunch/css_templates
Allowing definition of css templates
This commit is contained in:
commit
cf5d290a12
34
panoramix/migrations/versions/d827694c7555_css_templates.py
Normal file
34
panoramix/migrations/versions/d827694c7555_css_templates.py
Normal file
@ -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')
|
@ -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'
|
||||
|
@ -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);
|
||||
|
@ -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 %}
|
||||
@ -58,7 +65,7 @@ body {
|
||||
<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>
|
||||
|
@ -198,6 +198,20 @@ appbuilder.add_view(
|
||||
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
|
||||
@ -539,6 +553,8 @@ class Panoramix(BaseView):
|
||||
else:
|
||||
qry = qry.filter_by(slug=identifier)
|
||||
|
||||
templates = session.query(models.CssTemplate).all()
|
||||
|
||||
dashboard = qry.first()
|
||||
pos_dict = {}
|
||||
if dashboard.position_json:
|
||||
@ -547,6 +563,7 @@ class Panoramix(BaseView):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user