Merged in feature/widget-names (pull request #48)

Add name for widgets
develop
Ensar Sarajcic 2018-11-03 14:48:23 +00:00
commit 30666f2fe3
5 changed files with 61 additions and 13 deletions

View File

@ -11,13 +11,14 @@ from app.api.schemas import BaseResourceSchema
class BasicDashboardWidgetSchema(Schema): class BasicDashboardWidgetSchema(Schema):
id = fields.Integer(dump_only=True) id = fields.Integer(dump_only=True)
device_id = fields.Integer() device_id = fields.Integer(required=True)
height = fields.Integer() name = fields.String(required=True)
width = fields.Integer() height = fields.Integer(required=True)
x = fields.Integer() width = fields.Integer(required=True)
y = fields.Integer() x = fields.Integer(required=True)
chart_type = fields.String() y = fields.Integer(required=True)
filters = fields.Raw() chart_type = fields.String(required=True)
filters = fields.Raw(required=True)
class DashboardWidgetSchema(BaseResourceSchema, BasicDashboardWidgetSchema): class DashboardWidgetSchema(BaseResourceSchema, BasicDashboardWidgetSchema):
@ -27,8 +28,8 @@ class DashboardWidgetSchema(BaseResourceSchema, BasicDashboardWidgetSchema):
class DashboardSchema(BaseResourceSchema): class DashboardSchema(BaseResourceSchema):
id = fields.Integer(dump_only=True) id = fields.Integer(dump_only=True)
active = fields.Boolean(required=False) active = fields.Boolean(required=False)
dashboard_data = fields.Raw() dashboard_data = fields.Raw(required=True)
name = fields.String() name = fields.String(required=True)
widgets = fields.Nested(BasicDashboardWidgetSchema, dump_only=True, widgets = fields.Nested(BasicDashboardWidgetSchema, dump_only=True,
many=True) many=True)
@ -112,6 +113,7 @@ class DashboardWidgetListResource(ProtectedResource):
created_widget = dashboard.create_widget( created_widget = dashboard.create_widget(
dashboard_id, dashboard_id,
args['device_id'], args['device_id'],
args['name'],
args['height'], args['height'],
args['width'], args['width'],
args['x'], args['x'],
@ -142,6 +144,7 @@ class DashboardWidgetResource(ProtectedResource):
updated_widget = dashboard.patch_widget( updated_widget = dashboard.patch_widget(
widget_id, widget_id,
args['device_id'], args['device_id'],
args['name'],
args['height'], args['height'],
args['width'], args['width'],
args['x'], args['x'],
@ -159,6 +162,7 @@ class DashboardWidgetResource(ProtectedResource):
updated_widget = dashboard.patch_widget( updated_widget = dashboard.patch_widget(
widget_id, widget_id,
args.get('device_id'), args.get('device_id'),
args.get('name'),
args.get('height'), args.get('height'),
args.get('width'), args.get('width'),
args.get('x'), args.get('x'),

View File

@ -106,12 +106,13 @@ def get_dashboards(account_id, active):
return Dashboard.get_many_filtered(account_id=account_id, active=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): chart_type, filters):
""" """
Tries to create a dashboard widget 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) chart_type, filters)
widget.save() widget.save()
return widget return widget
@ -152,7 +153,7 @@ def get_widget(widget_id):
return DashboardWidget.get(id=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): x=None, y=None, chart_type=None, filters=None):
""" """
Tries to update widget with given parameters 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: if height is not None:
widget.height = height widget.height = height
if name is not None:
widget.name = name
if width is not None: if width is not None:
widget.width = width widget.width = width

View File

@ -126,6 +126,7 @@ class DashboardWidget(db.Model):
nullable=False) nullable=False)
device_id = db.Column(db.Integer, db.ForeignKey('devices.id'), device_id = db.Column(db.Integer, db.ForeignKey('devices.id'),
nullable=False) nullable=False)
name = db.Column(db.String, nullable=False)
height = db.Column(db.Integer, nullable=False) height = db.Column(db.Integer, nullable=False)
width = db.Column(db.Integer, nullable=False) width = db.Column(db.Integer, nullable=False)
x = 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]) 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): chart_type, filters):
self.dashboard_id = dashboard_id self.dashboard_id = dashboard_id
self.device_id = device_id self.device_id = device_id
self.name = name
self.height = height self.height = height
self.width = width self.width = width
self.x = x self.x = x

View File

@ -219,6 +219,8 @@ definitions:
- id - id
- name - name
- device_type - device_type
- created_at
- modified_at
properties: properties:
id: id:
$ref: '#/definitions/id' $ref: '#/definitions/id'
@ -226,6 +228,10 @@ definitions:
$ref: '#/definitions/devicename' $ref: '#/definitions/devicename'
device_type: device_type:
$ref: '#/definitions/DeviceType' $ref: '#/definitions/DeviceType'
created_at:
$ref: '#/definitions/datetime'
modified_at:
$ref: '#/definitions/datetime'
DeviceShareTokenCreation: DeviceShareTokenCreation:
type: object type: object
@ -328,6 +334,7 @@ definitions:
- id - id
- dashboard_id - dashboard_id
- device_id - device_id
- name
- width - width
- height - height
- x - x
@ -341,6 +348,8 @@ definitions:
$ref: '#/definitions/id' $ref: '#/definitions/id'
device_id: device_id:
$ref: '#/definitions/id' $ref: '#/definitions/id'
name:
$ref: '#/definitions/genericname'
width: width:
$ref: '#/definitions/id' $ref: '#/definitions/id'
height: height:

View File

@ -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 ###