DATA - Enumerate – cavaliba.com
Description: Reference

`CTRL K`

Documentation
Data
DATA - Enumerate

# DATA - Enumerate

Enumerate are predefined lists of values which can be used as Field attributes when defining DataClass models. Enumerate values have various additional options : display widget, description or intended use, etc.

When editing DataClass objects, user will be presented with a list of available values only.

When displaying a DataClass objets, nice widgets can be presented to users.

Enumerate usecase examples:

- status : OK, KO, N/A
- maturity_level : Good, Medium, Average, Bad, Terrible, NotAvailable, Unkown, ToBeChecked, …
- grade : A,B,C,D,E
- fruits : apple, pear, mango, …
- publish_status : draft, published, retracted
- color : red, blue, yellow

## Enumerate objects

Enumerate are implemented as regular DataClass objects and can thus be managed from the Web UI, REST API, console CLI, import/export, etc.

    # optional Role definitions to manage DataView authorizations
    _role:role_data_enumerate_ro:
        displayname: Role data:data_enumerate:ro
        subgroups:
          - admin_meteosi

    _role:role_data_enumerate_rw:
        displayname: Role data:data_enumerate:rw
        subgroups:
          - admin_meteosi

    _role:role_data_enumerate_admin:
        displayname: Role data:data_enumerate:admin
        subgroups:
          - admin_meteosi

    # Enumerate definition as a specific DataClass structure
    _schema:data_enumerate:
        _displayname: Data Enumerates
        _is_enabled: yes
        _icon: fa-table
        _order: 810
        _page: Internal
        _role_show: role_data_enumerate_ro
        _role_access: role_data_enumerate_ro
        _role_read: role_data_enumerate_ro
        _role_create: role_data_enumerate_rw
        _role_update: role_data_enumerate_rw
        _role_delete: role_data_enumerate_rw
        _role_onoff: role_data_enumerate_rw
        _role_import: role_data_enumerate_admin
        _role_export: role_data_enumerate_admin
        description:
            #_action: create_or_update
            displayname: Description
            order: 100
            dataformat: string
            dataformat_ext: ""
            cardinal_min: 0
            cardinal_max: 1
            default : ""
        # nested YAML content, with values, widget, see below
        content:
            displayname: content
            cardinal_min: 0
            cardinal_max: 1
            page: input
            order: 120
            dataformat: text
            dataformat_ext: yaml

## Enumerate Content format

The content attribute defines available values and their options:

- value : short value to display
- value_long : longer value to display
- value_num : used in aggregate function accross fields (min, max, avg, …)
- is_enabled : available for selection
- description : explain what/when this value can be selected

Example:

    - value: "A"
      value_long: "A - good"
      value_num: 1
      is_enabled: True
      widget: "green_circle"
      description: "A value to use when eveything is good"

    - value: "Z"
      is_enabled: False
      description: "deprecated; not available"

## Available Widget values

            "red_circle":    "&#x1f534;",
            "orange_circle": "&#x1F7E0;",
            "yellow_circle": "&#x1F7E1;",
            "green_circle":  "&#x1F7E2;",
            "purple_circle": "&#1F7E3;",
            "brown_circle":  "&#1F7E4;",
            "blue_circle":   "&#x1F535;",
            "white_circle":  "&#x25EF;",
            "black_circle":  "&#x2B24;;",
            "default" : ""

## Using Enumerate in Data Schemas

    _schema:my_test_class:
        #_action: create
        _displayname: TestClass

        # (...)

        my_enumerate_abc:
            displayname: MyEnumerate_ABC
            dataformat: enumerate
            dataformat_ext: enum_ABC
            description: Choose an enum_ABC value
            order: 520
            page: Static-Enum
            cardinal_min: 0
            cardinal_max: 1

        my_enumerate_abc_multi:
            displayname: MyEnumerate_ABC_Multi
            dataformat: enumerate
            dataformat_ext: enum_ABC
            description: Choose enum_ABC values
            order: 525
            page: Static-Enum
            cardinal_min: 0
            cardinal_max: 0

        # (...)

## Enumerate Examples

    # ---------------------
    # standard enumerates
    # ---------------------

    data_enumerate:enum_ABC:
      # ACTION
      is_enabled: True
      displayname: "ABC Scale"
      description: "Neutral ABC Scale"
      content: |
        - value: "A"
          widget: "green_circle"
          description: "A"
          value_num: 1

        - value: "B"
          widget: "orange_circle"
          value_num: 2

        - value: "C"
          widget: "red_circle"
          value_num: 3

    data_enumerate:maturite_ABCDE:
      # ACTION
      is_enabled: True
      displayname: "ABCDE Maturity scale"
      description: "Use for product assessment"
      content: |
        - value: "A"
          value_long: "A - Perfect"
          #is_enabled: True
          widget: "green_circle"
          description: "Use if perfect"
          value_num: 1

        - value: "B"
          value_long: "B - Correct"
          widget: "yellow_circle"
          value_num: 2

        - value: "C"
          value_long: "C - Average"
          widget: "orange_circle"
          value_num: 3

        - value: "D"
          value_long: "D - Bad"
          widget: "red_circle"
          value_num: 4

        - value: "E"
          value_long: "E - Alert"
          widget: "black_circle"
          value_num: 5

        - value: "n/a"
          value_long: "n/a"
          widget: "white_circle"

        - value: "?"
          value_long: "to be checked"
          widget: "blue_circle"

    data_enumerate:enum_OK_KO:
      # ACTION
      is_enabled: True
      displayname: "OK/KO Scale"
      content: |
        - value: "OK"
          widget: "green_circle"
          description: "OK"
          value_num: 1

        - value: "KO"
          widget: "red_circle"
          value_num: 2

    data_enumerate:enum_OK_KO_NA:
      # ACTION
      is_enabled: True
      displayname: "OK/KO/NA Scale"
      content: |
        - value: "OK"
          widget: "green_circle"
          description: "OK"
          value_num: 1

        - value: "KO"
          widget: "red_circle"
          value_num: 2

        - value: "n/a"
          widget: "white_circle"

        - value: "?"

DATA - DataViews DATA - Authorizations