pawamoy/django-suit-dashboard

Refactor

pawamoy opened this issue · 0 comments

  • Sometimes the class names are confusing: a Widget contains WidgetItems and WidgetGroups, a WidgetGroup can also contain WidgetItems...

    Widget should be called something like Box or Card, because it actually is a box when rendered in admin interface (a square separated from the others). Besides widget is already a term used by Django for HTML inputs...

    A Box could then contain Items or ItemGroups, and ItemGroups could contain Items.

  • Now Items and ItemGroups are not so smarts. ItemGroups are currently a way to output lists or tables. We could maybe just use items, with nested lists for values, default rendering behaviours and a template option for the user to set a specific HTML output.

  • We could also have a template class to inherit from so we don't have to set 'dashboard_grid' context variable each time. We would just write (for example):

    from suit_dashboard.layout import Grid, Row, Column
    class MainView(DashboardView):
        template = 'some/template.html'
        grid = Grid([Row([Column([Box1(), Box2()])])
        crumb = ('crumb_name', 'crumb_url') 
        extra_context = {'something': 'extra'}
    
    
    class NestedView(MainView):
        grid = Grid([Row([Column([Box3()])])
        crumb = ('crumb_name2', 'crumb_url2') 
  • Finally, instead of importing Grid, Row and Column each time, we could just import Grid, and use it like:

    grid = Grid(
        (
            (Box(), Box2()),
            (Box3(), )
        ),
        (
            (Box4(), Box5(), Box6()), 
        )
    )

    But maybe it is not more readable... And how to specify column width?
    Then maybe use Grid, Row and Column with *args:

    class Grid(object):
        def __init__(self, *rows, **kwargs):
            pass  # same for Row and Column
    
    
    grid = Grid(
        Row(Column(Box1(), Box2(), width=4),
        Row(Column(Box3(), width=8))
    )