Spanish Total.js
Français
Documentation Pour les agents IA
Sommaire

Data sources

Give widgets data from your own code with dashboard.source() on the server.

.md Site web

Cette page n’est pas encore traduite. Tu lis l’original.

Sur cette page

Reports with chart data are one data source. A widget file can register more in exports.install. Their entries then appear in the Dataset picker next to the reports, and instance.dataset() loads their data.

An example

This file, saved as dashboard/visits.html, adds the entry Demo visits with three fixed points:

<script total>
    exports.name = 'Visits source';
    exports.hidden = true;

    var ITEM = { id: 'visits', name: 'Demo visits', icon: 'ti ti-users', color: '#FBBC05' };

    exports.install = function(dashboard) {
        dashboard.source('visits', {
            search: function(model, next) {
                next(model.type === 'chart' ? [ITEM] : []);
            },
            detail: function(model, next) {
                next(model.id === 'visits' ? ITEM : null);
            },
            action: function(model, next) {
                next([{ id: 'visits', name: 'Demo visits', format: '{0}', decimals: 0, data: [{ x: 'Mon', y: 120 }, { x: 'Tue', y: 150 }, { x: 'Wed', y: 90 }] }]);
            }
        });
    };

    exports.uninstall = function(dashboard) {
        dashboard.source('visits', null);
    };
</script>

The built-in widgets ask for the type chart, so return your entries for that type.

API

method

dashboard.source(name, options)

Registers a data source, or removes it when options is null.
ParamètreTypeDescription
name String The name of the source.
options Object The functions search, detail and action, or null to remove the source.

Call it in exports.install of a widget file. The name must be unique and must not contain ~.

event

search: function(model, next) {}

Returns the entries that the Dataset picker offers.
ParamètreTypeDescription
model.search? String The text typed in the picker. It can be empty.
model.type String The type the widget asks for, for example chart.
model.user Object The signed-in user. Return only the entries this user may see.
next Function next(list) returns the entries.

Return a list of objects with id, name, icon and color.

event

detail: function(model, next) {}

Returns the name, icon and colour of one entry.
ParamètreTypeDescription
model.id String The id of the entry.
model.type String The type the widget asks for.
model.user Object The signed-in user.
next Function next(object) returns the entry.

Dashboard calls it when the settings of a widget open. Return null for an entry that no longer exists; it is taken off the Dataset.

event

action: function(model, next) {}

Returns the data of one entry.
ParamètreTypeDescription
model.id String The id of the entry.
model.type String The type the widget asks for.
model.user Object The signed-in user.
model.query Object The query arguments of the request.
next Function next(data) returns the data.

For the type chart, return a list of series. Each series has id, name, icon, color, format, decimals and data, a list of points with x and y.

Fabriqué en Europe