Skip to content

Commit

Permalink
Added backend logic for dashboard options
Browse files Browse the repository at this point in the history
  • Loading branch information
rafawendel committed Nov 24, 2020
1 parent dec8cfe commit 41ae2ce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions migrations/versions/dfeaacdd7624_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""empty message
Revision ID: dfeaacdd7624
Revises: e5c7a4e2df4d
Create Date: 2020-11-20 19:11:29.497508
"""
import json
from alembic import op
import sqlalchemy as sa

from redash.models import MutableDict, PseudoJSON

# revision identifiers, used by Alembic.
revision = 'dfeaacdd7624'
down_revision = 'e5c7a4e2df4d'
branch_labels = None
depends_on = None


def upgrade():
# create "dashboard options" column as a dict type
op.add_column(
"dashboards",
sa.Column(
"options",
MutableDict.as_mutable(PseudoJSON),
nullable=False,
server_default=json.dumps({}),
)
)


def downgrade():
op.drop_column("dashboards", "options")
2 changes: 2 additions & 0 deletions redash/handlers/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def get(self, dashboard_id=None):
:>json boolean is_draft: Whether this dashboard is a draft or not.
:>json array layout: Array of arrays containing widget IDs, corresponding to the rows and columns the widgets are displayed in
:>json array widgets: Array of arrays containing :ref:`widget <widget-response-label>` data
:>json object options: Dashboard options
.. _widget-response-label:
Expand Down Expand Up @@ -205,6 +206,7 @@ def post(self, dashboard_id):
"is_draft",
"is_archived",
"dashboard_filters_enabled",
"options"
),
)

Expand Down
1 change: 1 addition & 0 deletions redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ class Dashboard(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model
tags = Column(
"tags", MutableList.as_mutable(postgresql.ARRAY(db.Unicode)), nullable=True
)
options = Column(db.Text)

__tablename__ = "dashboards"
__mapper_args__ = {"version_id_col": version}
Expand Down
2 changes: 2 additions & 0 deletions redash/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def serialize_alert(alert, full=True):

def serialize_dashboard(obj, with_widgets=False, user=None, with_favorite_state=True):
layout = json_loads(obj.layout)
options = json_loads(obj.options)

widgets = []

Expand Down Expand Up @@ -256,6 +257,7 @@ def serialize_dashboard(obj, with_widgets=False, user=None, with_favorite_state=
},
"layout": layout,
"dashboard_filters_enabled": obj.dashboard_filters_enabled,
"options": options,
"widgets": widgets,
"is_archived": obj.is_archived,
"is_draft": obj.is_draft,
Expand Down

0 comments on commit 41ae2ce

Please sign in to comment.