Přeskočit obsah
For the complete DHIS2 documentation index, see llms.txt.

Object style

Některé prvky zahrnují vlastnost nazvanou "styl", která definuje ikonu a barvu. Tyto vizuální informace jsou velmi užitečné pro rychlou navigaci v aplikaci. Některé typické případy použití:

  • Rozlišujte různé programy a trackedEntityTypes v seznamu programů.
  • Ve formulářích pro zadávání dat s optionSet zobrazte volby s ikonami a barvami místo jmen.
  • Různé programStages v rámci programu.

Tato vlastnost je volitelná a ve většině případů není definována. Styl objektu může mít ikonu nebo barvu nebo obojí.

Ikona

DHIS2 includes a predefined set of icons. Those icons are included in the SDK and are located within the resources, in the "drawable" folder.

Staring on version v41, it is possible to upload user-defined icons and assign them to metadata objects. The actual images of these icons are stored as a FileResource and must be explicitly downloaded in a separate query.

d2.fileResourceModule().fileResourceDownloader()
    .byDomainType().eq(FileResourceDomainType.ICON)
    .download()

You can get the information about a particular icon by using the IconCollectionRepository. It returns an Icon object, which is a sealed class with two possible values: Default or Custom.

The way to render the actual image will depend on the Icon type.

val icon = d2.iconModule().icons().key("icon_key").blockingGet()

icon?.let {
    when (icon) {
        is Icon.Custom -> {
            val path = icon.path
            val fileResourceUid = icon.fileResourceUid
            // Use this information to load the file
        }

        is Icon.Default -> {
            val resourceName = icon.key
            // Use this information to load the resource
        }
    }
}

Barva

Obsahuje hexadecimální hodnotu barvy. Lze jej použít k přizpůsobení pozadí, barvy textu, nadpisů řádků atd.

program.style().color()    // For example #9C33FF