Skip to content

Commit b686c83

Browse files
committed
5316: add documentation, lint and change some names to make more sense
1 parent ac5bcd9 commit b686c83

File tree

4 files changed

+179
-53
lines changed

4 files changed

+179
-53
lines changed

README.md

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Further documentation can be found in the
5151
## Content Structure
5252

5353
| Component | Description | Accessible by |
54-
|-----------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------|
54+
| --------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ |
5555
| Slide | A slide is the visible content on a screen. | Admin, editor |
5656
| Media | Media is either images or videos used as content for slides. | Admin, editor |
5757
| Theme | A theme has css, that can override the slide css. | Admin |
@@ -318,7 +318,7 @@ See the `docker-compose.override.yml` playwright entry and the version imported
318318

319319
This project includes a test script that handles building assets, running
320320
Playwright tests, and stops and starts the node container. This script tests the
321-
*built* files. This is the approach the GitHub Action uses.
321+
_built_ files. This is the approach the GitHub Action uses.
322322

323323
```shell
324324
task test:frontend-built
@@ -404,6 +404,7 @@ TRACK_SCREEN_INFO_UPDATE_INTERVAL_SECONDS=300
404404
The format of the interval should follow <https://www.php.net/manual/en/dateinterval.construct.php>.
405405

406406
**Default**: 2 days.
407+
407408
- APP_KEY_VAULT_SOURCE: Source of key-value pair for `src/Service/KeyVaultService`. Atm. "ENVIRONMENT" is the only
408409
option.
409410
- APP_KEY_VAULT_JSON: A json object formatted as a string. Contains key-value pairs that can be accessed by through
@@ -431,23 +432,26 @@ ADMIN_ENHANCED_PREVIEW=false
431432
See [https://labs.rejseplanen.dk/](https://labs.rejseplanen.dk/) for information about acquiring an API key.
432433

433434
**Default**: Not set.
435+
434436
- ADMIN_SHOW_SCREEN_STATUS: Should the status of the screen be shown in the Admin (true|false)?
435437

436438
**Default**: Disabled.
439+
437440
- ADMIN_TOUCH_BUTTON_REGIONS: Should the option of setting a button name for a slide be enabled in the Admin?
438441
This option is used by the Client if a region is configured to be a "touch-buttons" region.
439442

440443
**Default**: Disabled.
444+
441445
- ADMIN_LOGIN_METHODS: Which login methods should be displayed in the admin (array of objects as json string)?
442446

443447
Available types: "oidc" | "username-password".
444448

445449
```json
446450
{
447-
"type": "oidc",
448-
"provider": "internal",
449-
"label": "Button text",
450-
"icon": "faCity"
451+
"type": "oidc",
452+
"provider": "internal",
453+
"label": "Button text",
454+
"icon": "faCity"
451455
}
452456
```
453457

@@ -456,17 +460,18 @@ ADMIN_ENHANCED_PREVIEW=false
456460
- icon: Name of the fontawesome icon to use for the button or "mitID" for MitID logo.
457461

458462
```json
459-
{
460-
"type": "username-password",
461-
"provider": "username-password",
462-
"label": ""
463-
}
463+
{
464+
"type": "username-password",
465+
"provider": "username-password",
466+
"label": ""
467+
}
464468
```
465469

466470
- provider: "username-password"
467471
- label: Label for the username password login section
468472

469473
**Default**: Username and password login option is enabled.
474+
470475
- ADMIN_ENHANCED_PREVIEW: Should the enhanced preview mode be active (true|false)? When enabled, previews will be
471476
handled by iFraming in the Client app. This will allow the option of previewing playlists and screens.
472477
If disabled, only slides can be previewed. This will be with the "live" method. This preview is not as precise.
@@ -494,18 +499,23 @@ CLIENT_DEBUG=false
494499
waiting for being activated in the administration.
495500

496501
**Default**: 20 s.
502+
497503
- CLIENT_REFRESH_TOKEN_TIMEOUT: How often (milliseconds) should it be checked whether the token needs to be refreshed?
498504

499505
**Default**: 30 s.
506+
500507
- CLIENT_REFRESH_TOKEN_TIMEOUT: How often (milliseconds) should it be checked whether the token needs to be refreshed?
501508

502509
**Default**: 60 s.
510+
503511
- CLIENT_SCHEDULING_INTERVAL: How often (milliseconds) should the scheduling be run for the logged in screen?
504512

505513
**Default**: 60 s.
514+
506515
- CLIENT_PULL_STRATEGY_INTERVAL: How often (milliseconds) should data be pulled from the API?
507516

508517
**Default**: 1 m. and 30 s.
518+
509519
- CLIENT_COLOR_SCHEME: Which colour scheme should be enabled? Should be a json object as string.
510520
This is used to signal how changes to darkmode are handled.
511521
Options are:
@@ -514,6 +524,7 @@ CLIENT_DEBUG=false
514524
activates darkmode according to sunrise/sunset of the location given by the longitude/latitude (lat/lng).
515525

516526
**Default**: Library mode with a lat/lng set in Denmark.
527+
517528
- CLIENT_DEBUG: Should the Client be in debug mode (true|false). When not in debug mode the mouse pointer is hidden.
518529

519530
**Default**: Disabled.
@@ -654,7 +665,7 @@ actual "machine" running the screen data.
654665
This status can be:
655666

656667
- "+ Tilkobl": The screen is not connected to a machine.
657-
- ✓ (green): The machine is connected and running the latest code.
668+
- ✓ (green): The machine is connected and running the latest code.
658669
- i (yellow circle): The machine is not running the newest released code.
659670
- ! (red triangle): The machine has not called the API within the last hour or the access token is expired.
660671

@@ -828,7 +839,32 @@ The slide is responsible for signaling that it is done executing.
828839
This is done by calling the slideDone() function. If the slide should just run for X milliseconds then you can use the
829840
BaseSlideExecution class to handle this. See the example for this approach.
830841

831-
##### Admin Form
842+
#### custom-template-name.json
843+
844+
The `.json` should include:
845+
846+
```
847+
{
848+
"title": "Billede og tekst",
849+
"id": "01FP2SNGFN0BZQH03KCBXHKYHG", // ULID, https://ulidgenerator.com/
850+
"options": {} // Optional, can contain extra options such as `disableLivePreview` that disables live preview in the admin UI
851+
"adminForm": {} // Optional, described below
852+
}
853+
```
854+
855+
##### Admin Form not set in json
856+
857+
It is possible to create an interactive admin form in a `.jsx`-file. As described above with renderSlide, when a template has a custom `.jsx` admin form, it needs to implement a `renderAdminForm` function in the base file.
858+
859+
- renderAdminForm(formStateObject, onChange, handleMedia, mediaData) - Should return the JSX for the admin form.
860+
- slideContent: The slide data object from the admin, could e.g. contain a title `slideContent["title"]`
861+
- onSlideContentChange: A callback for changes on the slide content.
862+
- handleMedia: A function that handles saving media (only necessary if the slide has media)
863+
- mediaData: An object that can contain already saved media (only necessary if the slide has media)
864+
865+
For an example of a custom template see `assets/shared/custom-templates-example/`.
866+
867+
##### Admin Form set in json
832868

833869
To get content into the slide the config.adminForm field should be set. This should be an array of objects with the
834870
following attributes:

assets/shared/custom-templates-example/custom-template-example.jsx

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { useEffect } from "react";
22
import templateConfig from "./custom-template-example.json";
33
import BaseSlideExecution from "../slide-utils/base-slide-execution.js";
44
import { ThemeStyles } from "../slide-utils/slide-util.jsx";
5+
import i18next from "i18next";
6+
import adminTranslations from "./translations.json";
7+
import { useTranslation } from "react-i18next";
8+
import getInputFiles from "../admin-util/helper.js";
59

610
/**
711
* Get the ULID of the template.
@@ -38,6 +42,17 @@ function renderSlide(slide, run, slideDone) {
3842
);
3943
}
4044

45+
function renderAdminForm(formStateObject, onChange, handleMedia, mediaData) {
46+
return (
47+
<CustomTemplateAdminExample
48+
formStateObject={formStateObject}
49+
onChange={onChange}
50+
handleMedia={handleMedia}
51+
mediaData={mediaData}
52+
/>
53+
);
54+
}
55+
4156
/**
4257
* @param {object} props Props.
4358
* @param {object} props.slide The slide.
@@ -82,4 +97,69 @@ function CustomTemplateExample({
8297
);
8398
}
8499

85-
export default { id, config, renderSlide };
100+
/**
101+
* @param {object} props Props.
102+
* @param {object} props.slideContent The slide content.
103+
* @param {Function} props.onSlideContentChange on slide content change.
104+
* @param {Function} props.handleMedia on slide media change.
105+
* @param {object} props.mediaData The media object.
106+
* @returns {JSX.Element} The component.
107+
*/
108+
function CustomTemplateAdminExample({
109+
slideContent,
110+
onSlideContentChange,
111+
handleMedia = () => {},
112+
mediaData = {},
113+
}) {
114+
const { t } = useTranslation("custom-template-admin-example");
115+
116+
useEffect(() => {
117+
const currentLang = i18next.language;
118+
if (
119+
!i18next.hasResourceBundle(currentLang, "custom-template-admin-example")
120+
) {
121+
i18next.addResourceBundle(
122+
currentLang,
123+
"custom-template-admin-example",
124+
adminTranslations["custom-template-admin-example"],
125+
true,
126+
true,
127+
);
128+
}
129+
}, []);
130+
131+
return (
132+
<>
133+
<h2 className="h4 mb-3">{t("header")}</h2>
134+
<fieldset>
135+
<legend className="h5 mb-3">{t("content-sub-header")}</legend>
136+
<label className="form-label">
137+
{t("slide-title-label")}
138+
<textarea
139+
onChange={onSlideContentChange}
140+
id="title"
141+
className="col-md-6 form-control"
142+
rows="3"
143+
defaultValue={slideContent["title"]}
144+
/>
145+
<small className="form-text d-flex">
146+
{t("slide-title-help-text")}
147+
</small>
148+
</label>
149+
<label className="form-label mb-0 col-9">
150+
{t("images-label")}
151+
<FileSelector
152+
files={getInputFiles(slideContent["image"], mediaData)}
153+
multiple={true}
154+
onFilesChange={handleMedia}
155+
name="image"
156+
acceptedMimetypes="image/*"
157+
/>
158+
</label>
159+
<small>{t("images-help-text")}</small>
160+
</fieldset>
161+
</>
162+
);
163+
}
164+
165+
export default { id, config, renderSlide, renderAdminForm };
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"custom-template-admin-example": {
3+
"header": "Example header",
4+
"content-sub-header": "Indhold",
5+
"slide-title-label": "Overskrift på slide",
6+
"slide-title-help-text": "Her kan du skrive overskriften til slidet",
7+
"images-label": "Billeder",
8+
"images-help-text": "Her tilføjer du bare et billede"
9+
}
10+
}

0 commit comments

Comments
 (0)