diff --git a/app/api/resources/dashboard.py b/app/api/resources/dashboard.py index 9c4ada8..96fd211 100644 --- a/app/api/resources/dashboard.py +++ b/app/api/resources/dashboard.py @@ -11,13 +11,14 @@ from app.api.schemas import BaseResourceSchema class BasicDashboardWidgetSchema(Schema): id = fields.Integer(dump_only=True) - device_id = fields.Integer() - height = fields.Integer() - width = fields.Integer() - x = fields.Integer() - y = fields.Integer() - chart_type = fields.String() - filters = fields.Raw() + device_id = fields.Integer(required=True) + name = fields.String(required=True) + height = fields.Integer(required=True) + width = fields.Integer(required=True) + x = fields.Integer(required=True) + y = fields.Integer(required=True) + chart_type = fields.String(required=True) + filters = fields.Raw(required=True) class DashboardWidgetSchema(BaseResourceSchema, BasicDashboardWidgetSchema): @@ -27,8 +28,8 @@ class DashboardWidgetSchema(BaseResourceSchema, BasicDashboardWidgetSchema): class DashboardSchema(BaseResourceSchema): id = fields.Integer(dump_only=True) active = fields.Boolean(required=False) - dashboard_data = fields.Raw() - name = fields.String() + dashboard_data = fields.Raw(required=True) + name = fields.String(required=True) widgets = fields.Nested(BasicDashboardWidgetSchema, dump_only=True, many=True) @@ -112,6 +113,7 @@ class DashboardWidgetListResource(ProtectedResource): created_widget = dashboard.create_widget( dashboard_id, args['device_id'], + args['name'], args['height'], args['width'], args['x'], @@ -142,6 +144,7 @@ class DashboardWidgetResource(ProtectedResource): updated_widget = dashboard.patch_widget( widget_id, args['device_id'], + args['name'], args['height'], args['width'], args['x'], @@ -159,6 +162,7 @@ class DashboardWidgetResource(ProtectedResource): updated_widget = dashboard.patch_widget( widget_id, args.get('device_id'), + args.get('name'), args.get('height'), args.get('width'), args.get('x'), diff --git a/app/dashboards/api.py b/app/dashboards/api.py index 0e4a819..21af487 100644 --- a/app/dashboards/api.py +++ b/app/dashboards/api.py @@ -106,12 +106,13 @@ def get_dashboards(account_id, active): return Dashboard.get_many_filtered(account_id=account_id, active=active) -def create_widget(dashboard_id, device_id, height, width, x, y, +def create_widget(dashboard_id, device_id, name, height, width, x, y, chart_type, filters): """ Tries to create a dashboard widget """ - widget = DashboardWidget(dashboard_id, device_id, height, width, x, y, + widget = DashboardWidget(dashboard_id, device_id, + name, height, width, x, y, chart_type, filters) widget.save() return widget @@ -152,7 +153,7 @@ def get_widget(widget_id): return DashboardWidget.get(id=widget_id) -def patch_widget(widget_id, device_id=None, height=None, width=None, +def patch_widget(widget_id, device_id=None, name=None, height=None, width=None, x=None, y=None, chart_type=None, filters=None): """ Tries to update widget with given parameters @@ -165,6 +166,9 @@ def patch_widget(widget_id, device_id=None, height=None, width=None, if height is not None: widget.height = height + if name is not None: + widget.name = name + if width is not None: widget.width = width diff --git a/app/dashboards/models.py b/app/dashboards/models.py index 091052f..5e6aa61 100644 --- a/app/dashboards/models.py +++ b/app/dashboards/models.py @@ -126,6 +126,7 @@ class DashboardWidget(db.Model): nullable=False) device_id = db.Column(db.Integer, db.ForeignKey('devices.id'), nullable=False) + name = db.Column(db.String, nullable=False) height = db.Column(db.Integer, nullable=False) width = db.Column(db.Integer, nullable=False) x = db.Column(db.Integer, nullable=False) @@ -142,10 +143,11 @@ class DashboardWidget(db.Model): dashboard = db.relationship("Dashboard", foreign_keys=[dashboard_id]) - def __init__(self, dashboard_id, device_id, height, width, x, y, + def __init__(self, dashboard_id, device_id, name, height, width, x, y, chart_type, filters): self.dashboard_id = dashboard_id self.device_id = device_id + self.name = name self.height = height self.width = width self.x = x diff --git a/app/swagger/template.yaml b/app/swagger/template.yaml index f45f263..5d98951 100644 --- a/app/swagger/template.yaml +++ b/app/swagger/template.yaml @@ -219,6 +219,8 @@ definitions: - id - name - device_type + - created_at + - modified_at properties: id: $ref: '#/definitions/id' @@ -226,6 +228,10 @@ definitions: $ref: '#/definitions/devicename' device_type: $ref: '#/definitions/DeviceType' + created_at: + $ref: '#/definitions/datetime' + modified_at: + $ref: '#/definitions/datetime' DeviceShareTokenCreation: type: object @@ -328,6 +334,7 @@ definitions: - id - dashboard_id - device_id + - name - width - height - x @@ -341,6 +348,8 @@ definitions: $ref: '#/definitions/id' device_id: $ref: '#/definitions/id' + name: + $ref: '#/definitions/genericname' width: $ref: '#/definitions/id' height: diff --git a/migrations/versions/3cf41808886b_.py b/migrations/versions/3cf41808886b_.py new file mode 100644 index 0000000..80f338e --- /dev/null +++ b/migrations/versions/3cf41808886b_.py @@ -0,0 +1,29 @@ +"""empty message + +Revision ID: 3cf41808886b +Revises: 764de3c39771 +Create Date: 2018-11-03 15:40:04.384489 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '3cf41808886b' +down_revision = '764de3c39771' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('dashboard_widgets', sa.Column('name', sa.String(), + nullable=False, server_default='Legacy widget')) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('dashboard_widgets', 'name') + # ### end Alembic commands ###