Dashboards

Djing dashboards provide a convenient way to build information overview pages that contain a variety of metrics and cards.

Overview

Djing dashboards provide a convenient way to build information overview pages that contain a variety of metrics and cards.

Default Dashboard

Djing ships with a default djing_admin.app.Djing.Dashboards.Main dashboard class containing a cards method. You can customize which cards are present on the default dashboard via this method:

djing_admin/app/Djing/Dashboards/Main.py
from djing.core.Cards.Help import Help
from djing.core.Dashboards.Main import Main as Dashboard


class Main(Dashboard):
    def cards(self):
        return [
            Help(),
        ]

Defining Dashboards

Custom dashboards may be generated using the djing:dashboard CLI command. By default, all new dashboards will be placed in the djing_admin/app/Djing/Dashboards directory:

commander djing:dashboard UserInsights

Once your dashboard class has been generated, you’re ready to customize it. Each dashboard class contains a cards method. This method should return an array of card or metric classes:

djing_admin/app/Djing/Dashboards/UserInsights.py
from djing.core.Dashboards.Main import Main as Dashboard
from djing_admin.app.Djing.Metrics.TotalUsers import TotalUsers


class UserInsights(Dashboard):
    def cards(self):
        return [
            TotalUsers(),
        ]

Dashboard Names

By default, Djing will use the dashboard’s class name to determine the displayable name of your dashboard that should be placed in the left-side navigation bar. You may customize the name of the dashboard displayed in the left-side navigation bar by overriding the name method within your dashboard class:

djing_admin/app/Djing/Dashboards/UserInsights.py
from djing.core.Dashboards.Main import Main as Dashboard


class UserDashboard(Dashboard):
    # ...

    def name(self):
        return "User Dashboard"

Dashboard URI Keys

If you need to change the URI of the dashboard, you may override the dashboard class’ uri_key method. Of course, the URI represents the browser location that Nova will navigate to in when you click on the dashboard link in the left-side navigation bar:

djing_admin/app/Djing/Dashboards/UserInsights.py
from djing.core.Dashboards.Main import Main as Dashboard


class UserDashboard(Dashboard):
    # ...

    def uri_key(self):
        return "user-dashboard"

Registering Dashboards

To register a dashboard, add the dashboard to the array returned by the dashboards method of your application’s djing_admin.app.Providers.DjingServiceProvider class. Once you have added the dashboard to this method, it will become available for navigation in Djing’s left-side navigation bar:

djing_admin/app/Providers/DjingServiceProvider.py
from djing.core.Providers.DjingApplicationServiceProvider import (
    DjingApplicationServiceProvider,
)
from djing_admin.app.Djing.Dashboards.UserInsights import UserInsights


class DjingServiceProvider(DjingApplicationServiceProvider):
    # ...

    def dashboards(self):
        return [
            UserInsights.make(),
        ]

Customizing Dashboard Menus

You can customize the dashboard’s menu by defining a menu method on your dashboard class:

djing_admin/app/Djing/Dashboards/UserDashboard.py
from djing.core.Dashboards.Main import Main as Dashboard
from djing.core.Http.Requests.DjingRequest import DjingRequest


class UserDashboard(Dashboard):
    # ...

    def menu(self, request: DjingRequest):
        return super().menu(request).with_badge("NEW!")

Authorization

If you would like to only expose a given dashboard to certain users, you may invoke the can_see method when registering your dashboard. The can_see method accepts a closure which should return true or false. The closure will receive the incoming HTTP request:

djing_admin/app/Providers/DjingServiceProvider.py
from djing.core.Providers.DjingApplicationServiceProvider import (
    DjingApplicationServiceProvider,
)
from djing_admin.app.Djing.Dashboards.UserInsights import UserInsights


class DjingServiceProvider(DjingApplicationServiceProvider):
    # ...

    def dashboards(self):
        return [
            UserInsights.make().can_see(lambda request: True),
        ]

Last updated