Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion content/en/building/reference/_partial_cht_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ aliases:
Introduced in v3.12.0
{{< /callout >}}

Provides CHT Core Framework's functions to contact summary, targets and tasks. The API is available in the `cht` reserved variable under the `v1` version.
Provides CHT Core Framework's functions to contact summary, targets, tasks, etc. The API is available in the `cht` reserved variable under the `v1` version.

| Function | Arguments | Description |
|------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| hasPermissions(permissions, userRoles) | `permissions`: String or array of permission name(s).<br>`userRoles`: (Optional) Array of user roles. Default to the current logged in user. | Returns true if the user has the permission(s), otherwise returns false. |
| hasAnyPermission(permissionsGroups, userRoles) | `permissionsGroups`: Array of groups of permission name(s).<br>`userRoles`: (Optional) Array of user roles. Default to the current logged in user. | Returns true if the user has all the permissions of any of the provided groups, otherwise returns false. |
| getExtensionLib(name) | `name`: String of script name | Returns an executable function identified by the given name configured as [extension-libs](/building/reference/extension-libs). |
| analytics.getTargetDocs() | | Returns three [target](/technical-overview/data/db-schema#targets) documents of the contact, calculated for the last three reporting intervals, including the current one. When viewing one of the current logged in user's associated facilities, returns the target documents for the contact associated with the current logged in user. Returns an empty array if no target documents are found (for example when viewing a contact that does not upload targets). _Introduced in v4.11.0_ |
| translate(key, interpolateParams) | `key`: The translation key.<br>`interpolateParams`: (Optional) Object containing values to be used in the translated string. | Returns the value in the current user's language from the [app translations](/building/translations/localizing/) for the given key. |
| getResource(name) | `name`: The name key of the resource to get | Returns the data for a [configured resource](/building/branding/resources/). The returned object contains a `content_type` property defining the type of resource (e.g. `image/png`). The `data` property contains the Base64 representation of the resource. |

### CHT API's code samples

Expand Down
33 changes: 19 additions & 14 deletions content/en/building/reference/app-settings/header_tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,46 @@ aliases:
---

## `app_settings.js .header_tabs`
As of `3.10.0`, app header tabs icons can be configured by modifying the `header_tabs` section in the app settings.
As of `3.10.0`, app header tabs can be configured by modifying the `header_tabs` section in the app settings.
The `header_tabs` section consists of key:value pairs, where the key is the name of the tab to configure.
These values can also be changed from the Admin console, on the Images page under the "Header tabs icons" tab.

As of `5.2.0`, the ordering of the app header tabs can be customized by setting the `weight` property. Tabs with a lower weight value will be displayed first (higher on the bar). The tab with the lowest `weight` will be the one loaded when the user first opens the app.

```json
{
"messages": {
"icon": "fa-user"
"icon": "fa-user",
"weight": 42
},
"tasks": {
"resource_icon": "medic-health-center"
},
"analytics": {
"icon": "fa-flag",
"resource_icon": "icon-treatment"
"resource_icon": "icon-treatment",
"weight": 0.5
}
}
```

#### Available tabs

| tab name | default [FontAwesome](https://fontawesome.com/v4.7.0/) icon |
| ---------| -------------|
| `messages` | `fa-envelope` |
| `tasks` | `fa-flag` |
| `reports` | `fa-list-alt` |
| `contacts` | `fa-user` |
| `analytics` | `fa-bar-chart-o` |
| tab name | default [FontAwesome](https://fontawesome.com/v4.7.0/) icon | Default Weight |
|-------------|-------------------------------------------------------------|----------------|
| `messages` | `fa-envelope` | 1 |
| `tasks` | `fa-flag` | 2 |
| `reports` | `fa-list-alt` | 3 |
| `contacts` | `fa-user` | 4 |
| `analytics` | `fa-bar-chart-o` | 5 |

#### `app_settings.js .header_tabs.<tab_name>`

| property | type | required | description |
| -------- | ---- | -------- | ----------- |
| `icon` | string | no | [FontAwesome](https://fontawesome.com/v4.7.0/) icon name |
| `resource_icon` | string | no | [Resource icon](/building/branding/resources) name.
| property | type | required | description |
|-----------------|--------|----------|-------------------------------------------------------------------------------------------------------|
| `icon` | string | no | [FontAwesome](https://fontawesome.com/v4.7.0/) icon name |
| `resource_icon` | string | no | [Resource icon](/building/branding/resources) name. |
| `weight` | number | no | Added in `5.2.0`. The numerical "weight" used to determine the tab ordering. Lower values come first. |

> [!NOTE]
> Selected Resource icons take precedence over selected FontAwesome icons.
Expand Down
139 changes: 139 additions & 0 deletions content/en/building/reference/ui-extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
title: "ui-extensions"
linkTitle: "ui-extensions"
weight: 5
description: Custom user interfaces
keywords: extension UI extensibility user interface web component
---

_Introduced in v5.2.0_

UI Extensions are [custom web components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) that can extend the functionality/content of the CHT web application. This is an advanced feature and requires an app developer with some software development experience.

An example of a use for this feature is a custom landing page for users containing content specific to a deployment.

## Types

Currently, there are two supported types of UI Extensions.

### Header tab extensions

Extensions with the `header_tab` type are included in the webapp interface as a new top-level tab (along with "People", "Tasks", etc).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful to include a screenshot to exemplify the two types.


Use the `weight` [property](#ui-extension-properties) to control the placement of the UI Extensions in relation to the other visible [header tabs](/building/reference/app-settings/header_tabs/). Tabs with a lower weight will be listed first and the first tab will be the default landing page when the app first opens.

Use the `accent_color` [property](#ui-extension-properties) to control the color of the tool-bar at the top of the interface.

### Sidebar tab extensions

Extensions with the `sidebar_tab` type are included in the webapp interface as new tabs available from the sidebar menu (along with "Training Materials", "About", etc).

Use the `accent_color` [property](#ui-extension-properties) to control the color of the tool-bar at the top of the interface.

## Building

The configuration for a UI Extension consists of a JavaScript file which exports a `class` extending `HTMLElement` and a `properties.json` file containing the configuration for the extension. These files should be added into the `/ui-extensions` directory in the project's config directory.

```
- config
- ui-extensions
- my-extension.js
- my-extension.properties.json
```

### UI Extension Properties

The `.properties.json` file contains the configuration for each UI Extension.

| Property | Required | Description |
|-----------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type` | Yes | The type of the extension (`header_tab`, `sidebar_tab`). |
| `title` | Yes | The translation key for the title of the UI Extension. |
| `roles` | | An array of [user role names](/building/reference/app-settings/user-roles/) that have access to the extension. Only users with one (or more) of the specified roles will be able to access the extension. If no `roles` are set, the extension will be available to all users. |
| `icon` | | The FontAwesome class (beginning with `fa-`) to use as the extension icon. Must not be combined with `resource_icon`. |
| `resource_icon` | | The [resources key](/building/branding/resources/) for the image to use as the extension icon. Must not be combined with `icon`. |
| `accent_color` | | A [CSS color value](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Colors/Color_values) to use as the accent color for the extension. |
| `weight` | | The numerical "weight" used to determine the extension ordering. Lower values come first. |
| `config` | | Custom object containing any properties that should be passed to the constructed web component via `this.inputs.config`. |

### Web component class

The extension JavaScript file must export a `class` that extends `HTMLElement`. This class represents the custom web component that will be available to the user in the webapp. The functionality that can be included in this web component is essentially limitless. Additionally, a number of resources are provided to the web component allowing for better integration with the CHT data model.

#### Constructor

The `constructor` of the class is called when the element is created, but before it is inserted on the DOM. It can be used to do any initialization that does not require access to the DOM or other external context. This is a good place to attach the [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components#shadow_dom_2) to properly insulate the web component from the rest of the web app.

```js
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
```

#### `connectedCallback()`

The `connectedCallback()` method is called when the element is added to the DOM. This is a good place to finalize the component initialization (set up event listeners, fetch data, render content, etc).

This basic example demonstrates how HTML and CSS for the component can be set:

```js
connectedCallback() {
this.shadowRoot.innerHTML = `
<style>
h1 {
color: blue;
}
</style>
<h1>Hello World</h1>
`;
}
```

#### Input data

Input data is available to the component logic in the `this.inputs` root level property.

| Property | Description |
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `userContactSummary` | The [contact-summary context](/building/contact-summary/contact-summary-templated/) for the contact associated with the logged in user. |
| `config` | Optional. This object will contain the data loaded from `config` property of the UI Extension's `properties.json` file (if it exists). |

#### CHT API

{{< read-content file="building/reference/_partial_cht_api.md" >}}

##### CHT Data model

The `cht` API can also be used to interact directly with the CHT data model to read/create/update data for contacts, reports, etc. See [the cht-datasource docs](https://docs.communityhealthtoolkit.org/cht-datasource/) for more details.

```.js
const contactId = this.inputs.userContactSummary.contact_id;
const userContact = await this.cht.v1.person.getByUuid(contactId);
```

## Uploading/deleting UI Extensions

Use cht-conf to upload all configured UI Extensions:

```shell
cht --url=${COUCH_URL} upload-ui-extensions
```

Individual UI extensions can be uploaded by including their name when running the command. If you have a UI extension defined in `hello.js`/`hello.properties.json`, running this command will only upload that extension:

```shell
cht --url=${COUCH_URL} upload-ui-extensions -- hello
```

cht-conf can also be used to delete all UI Extensions from an instance:

```shell
cht --url=${COUCH_URL} delete-ui-extensions
```

Additionally, individual UI Extensions can be deleted by including their name when running the command:

```shell
cht --url=${COUCH_URL} delete-ui-extensions -- hello
```
Loading