Custom display types

Front-end

To develop a front-end for a display type, the library @valtimo/dashboard provides several interfaces which display type front-ends must conform to, in order to be used in an implementation.

Display type specification

First, a display type specification conforming to the DisplayTypeSpecification interface needs to be created. Below is an example specification with explanations for each property:

sample-display-type.specification.ts

import {DisplayTypeSpecification} from '@valtimo/dashboard';
import {SampleConfigurationComponent} from './components/sample-configuration/sample-configuration.component';
import {SampleDisplayComponent} from './components/sample-display/sample-display.component';

const sampleDisplayTypeSpecification: DisplayTypeSpecification = {
    // The display type key. This needs to be the same as the id received from the back-end.
    displayTypeKey: 'sample-display-type',
    // A component of the interface DisplayTypeConfigurationComponent, used to configure the display type
    configurationComponent: SampleConfigurationComponent,
    // A component of the interface DisplayComponent, used to configure the display type
    displayComponent: SampleDisplayComponent,
    // the width in squares the display type component will take up on the dashboard
    width: 1,
    // the height in squares the display type component will take up on the dashboard
    height: 1,
    /*
    each data source specifies what kind of data features it provides. Here you define what data features your
    display type requires, so that your display type can only be selected when a compatible data source is selected.
    */
    requiredDataFeatures: ['number'],
    /* 
    For each language key an implementation supports, translation keys with a translation are provided below. 
    These can then be used in configuration components using the widgetTranslate pipe or the WidgetTranslationService.
    At a minumum, the key 'title' needs to be defined.
     */
    translations: {
        nl: {
            title: 'Weergave',
            ...
        },
        en: {
            title: 'Display',
            ...
        },
        de: {
            title: 'Anzeige',
            ...
        },
    },
};

export {sampleDisplayTypeSpecification};

Display type configuration component

As shown in the display type specification section, display type configuration components need to conform to the interface DisplayTypeConfigurationComponent. Below the interface is shown, with a comment for each required property.

configuration.model.ts

Typing display type configuration data

As mentioned, the display type configuration component accepts prefill data. This prefill data is equal to the display type properties saved in the back-end. Next to this, the display component accepts data. It is advised to also type the way in this data is received.

sample.model.ts

Implementing the display type configuration component

How a configuration component for the sample display type can be implemented is shown below. The way this is implemented can differ, as long as the interfaces are conformed to. Below is sample code of implementing the component using Carbon components and reactive forms.

sample-display-type-configuration.component.ts

The corresponding template file looks like this:

sample-display-type-configuration.component.html

Implementing the display component

Previously, a component was defined which configures the display type. Next, a separate component is defined to display the display type + data source configuration on the dashboard. An example of such a display component is shown below.

An example of the component code:

sample-display.component.ts

An example of the template code:

sample-display.component.html

Translation

Please refer to this page on how to implement translations from your specification in template or component code.

Display type module

Finally, having defined a specification, configuration component and display component, we can construct a module. Keep to the below guidelines in constructing your module. When you finally import this module into the AppModule of your implementation, the display type configuration component should be available in the relevant configuration menus in your front-end, and the data source + display type configuration is displayed on your dashboard.

sample-display-type.module.ts

Last updated