Add home page notification and config value.

Fixes #43.
This commit is contained in:
Edward Shen 2020-08-31 21:24:56 -04:00
parent ec62411c17
commit 79e132b007
Signed by: edward
GPG key ID: F350507060ED6C90
2 changed files with 26 additions and 12 deletions

View file

@ -15,7 +15,8 @@ Module.register('MMM-pages', {
animationTime: 1000, animationTime: 1000,
rotationTime: 0, rotationTime: 0,
rotationFirstPage: 0, rotationFirstPage: 0,
rotationDelay: 10000 rotationDelay: 10000,
homePage: 0
}, },
/** /**
@ -41,7 +42,11 @@ Module.register('MMM-pages', {
* and sets the default current page to 0. * and sets the default current page to 0.
*/ */
start: function () { start: function () {
this.curPage = 0; // Clamp homePage value to [0, num pages).
if (this.config.homePage >= this.config.modules.length || this.config.homePage < 0) {
this.config.homePage = 0;
}
this.curPage = this.config.homePage;
this.rotationPaused = false; this.rotationPaused = false;
// Compatibility // Compatibility
@ -63,6 +68,9 @@ Module.register('MMM-pages', {
* 'PAGE_DECREMENT' - Move to the previous page. * 'PAGE_DECREMENT' - Move to the previous page.
* 'DOM_OBJECTS_CREATED' - Starts the module. * 'DOM_OBJECTS_CREATED' - Starts the module.
* 'QUERY_PAGE_NUMBER' - Requests the current page number * 'QUERY_PAGE_NUMBER' - Requests the current page number
* 'PAUSE_ROTATION' - Stops rotation
* 'RESUME_ROTATION' - Resumes rotation
* 'HOME_PAGE' - Calls PAGED_CHANGED with the default home page.
* *
* @param {string} notification the notification ID * @param {string} notification the notification ID
* @param {number} payload the page to change to/by * @param {number} payload the page to change to/by
@ -116,6 +124,9 @@ Module.register('MMM-pages', {
Log.warn('[Pages]: Was asked to resume but rotation was not paused!'); Log.warn('[Pages]: Was asked to resume but rotation was not paused!');
} }
break; break;
case 'HOME_PAGE':
this.notificationReceived('PAGE_CHANGED', this.config.homePage);
break;
default: // Do nothing default: // Do nothing
} }
}, },

View file

@ -51,7 +51,7 @@ modules: [
## Configuration options ## Configuration options
| Option | Type | Default Value | Description | | Option | Type | Default Value | Description |
| ------------------ | ------------------ | ------------------------ | --------- | | ------------------- | ------------------ | ------------------------ | ----------- |
| `modules` | `[[String...]...]` | `[]` | A 2D String array of what each module should be on which page. Note that all entries must take their class name (e.g. this module's class name is `MMM-pages`, while the default modules may just have `newsfeed`, without the `MMM-` prefix. | | `modules` | `[[String...]...]` | `[]` | A 2D String array of what each module should be on which page. Note that all entries must take their class name (e.g. this module's class name is `MMM-pages`, while the default modules may just have `newsfeed`, without the `MMM-` prefix. |
| `excludes` | *None* | *None* | **Deprecated** Use `fixed` instead. | | `excludes` | *None* | *None* | **Deprecated** Use `fixed` instead. |
| `fixed` | `[String...]` | `["MMM-page-indicator"]` | Which modules should show up all the time. | | `fixed` | `[String...]` | `["MMM-page-indicator"]` | Which modules should show up all the time. |
@ -59,6 +59,7 @@ modules: [
| `rotationTime` | `int` | `0` | Time, in milliseconds, between automatic page changes. | | `rotationTime` | `int` | `0` | Time, in milliseconds, between automatic page changes. |
| `rotationDelay` | `int` | `0` | Time, in milliseconds, of how long should a manual page change linger before returning to automatic page changing. In other words, how long should the timer wait for after you manually change a page. This does include the animation time, so you may wish to increase it by a few seconds or so to account for the animation time. | | `rotationDelay` | `int` | `0` | Time, in milliseconds, of how long should a manual page change linger before returning to automatic page changing. In other words, how long should the timer wait for after you manually change a page. This does include the animation time, so you may wish to increase it by a few seconds or so to account for the animation time. |
| `rotationFirstPage` | `int` | `0` | Time, in milliseconds, before automatically returning to the first page. | | `rotationFirstPage` | `int` | `0` | Time, in milliseconds, before automatically returning to the first page. |
| `homePage` | `int` | `0` | Which page index is the home page. |
For the `module` configuration option, the first element of the outer array For the `module` configuration option, the first element of the outer array
should consist of elements that should be on the first page. The second element should consist of elements that should be on the first page. The second element
@ -103,6 +104,8 @@ separate notification tag is used for compatibility reasons.
If you wish to pause the auto rotation, send a `PAUSE_ROTATION` event. Likewise, If you wish to pause the auto rotation, send a `PAUSE_ROTATION` event. Likewise,
you can send a `RESUME_ROTATION` event to resume it. you can send a `RESUME_ROTATION` event to resume it.
If you want to return to the home page, simply send a `HOME_PAGE` notification.
## FAQ ## FAQ
- Help! My module is (above/below) another module in the same region but I want - Help! My module is (above/below) another module in the same region but I want