Skip to content

Commit

Permalink
Update: Make item titles optional, create fallback title for dialogs …
Browse files Browse the repository at this point in the history
…and strapline buttons (fixes #308) (#309)

* Make _item titles optional in schema

* Add global fallback title, set up fallback title logic

* Fix typo in PR template

* Add fallback title for strapline buttons
  • Loading branch information
swashbuck authored Jul 2, 2024
1 parent 8ad8923 commit a13f7d3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* A sentence describing each fix

### Update
* A sentence describing each udpate
* A sentence describing each update

### New
* A sentence describing each new feature
Expand Down
14 changes: 13 additions & 1 deletion js/NarrativeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,21 @@ class NarrativeView extends ComponentView {
}

openPopup() {
const globals = Adapt.course.get('_globals');
const narrativeGlobals = globals._components._narrative;
const totalItems = this.model.getChildren().length;
const currentItem = this.model.getActiveItem();
const index = currentItem.get('_index');
const defaultTitle = compile(narrativeGlobals.titleDialog, {
itemNumber: index + 1,
totalItems
});
const title = currentItem.get('title') || currentItem.get('strapline') || defaultTitle;
const isAltTitle = Boolean(!currentItem.get('title'));

notify.popup({
title: currentItem.get('title'),
isAltTitle,
title,
body: currentItem.get('body')
});

Expand Down
24 changes: 22 additions & 2 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@
"inputType": "Text",
"validators": [],
"translatable": true
},
"titleDialog": {
"type": "string",
"required": true,
"title": "Dialog default title",
"description": "Default fallback title to use for dialog popups when not set on an item",
"default": "Item {{itemNumber}} of {{totalItems}}",
"inputType": "Text",
"validators": [],
"translatable": true
},
"titleStrapline": {
"type": "string",
"required": true,
"title": "Strapline default title",
"description": "Default fallback title to use for strapline buttons when not set on an item",
"default": "Find out more",
"inputType": "Text",
"validators": [],
"translatable": true
}
},
"properties": {
Expand Down Expand Up @@ -115,11 +135,11 @@
"properties": {
"title": {
"type": "string",
"required": true,
"required": false,
"default": "",
"title": "Narrative display title",
"inputType": "Text",
"validators": ["required"],
"validators": [],
"help": "",
"translatable": true
},
Expand Down
18 changes: 18 additions & 0 deletions schema/course.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@
"_adapt": {
"translatable": true
}
},
"titleDialog": {
"type": "string",
"title": "Dialog default title",
"help": "Default fallback title to use for dialog popups when not set on an item",
"default": "Item {{itemNumber}} of {{totalItems}}",
"_adapt": {
"translatable": true
}
},
"titleStrapline": {
"type": "string",
"title": "Strapline default title",
"help": "Default fallback title to use for strapline buttons when not set on an item",
"default": "Find out more",
"_adapt": {
"translatable": true
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion templates/narrativeStrapline.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import Adapt from 'core/js/adapt';
import { compile, classes } from 'core/js/reactHelpers';

export default function NarrativeStrapline(props) {
Expand All @@ -17,6 +18,8 @@ export default function NarrativeStrapline(props) {
return false;
}

const globals = Adapt.course.get('_globals')._components._narrative;

return (
<div className="narrative__strapline">

Expand Down Expand Up @@ -48,7 +51,7 @@ export default function NarrativeStrapline(props) {
<span className="narrative__strapline-title">
<span
className="narrative__strapline-title-inner"
dangerouslySetInnerHTML={{ __html: compile(strapline || title, props) }}
dangerouslySetInnerHTML={{ __html: compile(strapline || title || globals.titleStrapline, props) }}
/>
</span>

Expand Down

0 comments on commit a13f7d3

Please sign in to comment.