This component displays a user's rewards (badges) in their personal account. The easiest way is to use a profile field of type dictionary_array: badges are created in NRM as dictionary items with images and then assigned to the user.
<ui-badge-box title="My badges" from-array-field="p.achievement_badges" :only-account="true" ></ui-badge-box>
Settings (props)
| Prop | What it does |
|---|---|
from-array-field |
A profile field of type dictionary_array with badges from NRM. The images of the dictionary items are shown, and the item name appears on hover. Items without an image are skipped. |
:badges |
Badges based on conditions: [{ badgeUrl: 'award.png', title: 'Award', rules: [['s.id', 'one_of', '3,4,5']] }]. A rule is [field, operator, value], and the operators are the same as in color-rules: <, >, =, !=, <=, >=, contains, one_of. |
callback |
The name of the function that returns a list of badge IDs. This is a string, so no leading colon is needed. See more below. |
callback-badge-url-template |
The image URL template: {{badgeId}} is replaced with the ID from the callback. If no template is set, the ID itself is used as the image URL. |
:only-account |
true — don't request the position if only account fields (p.*) are needed. Defaults to false. |
:tree-id |
The tree to take the position from when only-account is off. Defaults to 0. |
title |
The window title. |
:single-line |
Show the badges in a single row, without a window. |
background-class |
The window background color, e.g. bg-amber. |
header-class |
The header color, e.g. bg-amber-lighten-1. |
no-badges-text |
The text to show when there are no badges. |
:center |
Center the window content. Defaults to true. |
:badge-width |
Badge width in px. Defaults to 50. |
:badge-height |
Badge height in px. Defaults to 50. |
If several sources are set, the badges are displayed in this order: callback, badges, from-array-field.
Using a callback
<ui-badge-box
title="My badges"
callback="cbBadges"
callback-badge-url-template="/images/badges/{{badgeId}}.png"
></ui-badge-box>
<script lang="javascript">
function cbBadges({ r }) {
const badges = [];
if (r('m.PV') >= 100) badges.push('pv100');
if (r('m.PV') >= 1000) badges.push('pv1000');
return badges;
}
</script>
callback is the name of the function, just like in ui-aux. The parameters are passed in the callback-v2 format, i.e. as a single object, so you can take only the ones you need:
-
p— a function that returns the presentable value of a property:p('p.firstname') -
r— a function that returns the raw value of a property:r('m.PV') -
item— a TableGridItem object where each key is a property name and each value is a{ presentable, raw }object
The function must return an array of badge IDs. Each ID is substituted into callback-badge-url-template in place of {{badgeId}} — that's how the image URL is built.
In the example, with PV = 500 one image /images/badges/pv100.png is shown, and with PV = 1500 two images are shown.
See Badges profile field.