added support for changing by a certain amount of pages

This commit is contained in:
Edward Shen 2018-05-07 13:05:52 -04:00
parent 2d0eb22a6d
commit f4fc53fa19
No known key found for this signature in database
GPG key ID: 4E887A42793D0433
2 changed files with 14 additions and 6 deletions

View file

@ -55,11 +55,12 @@ Module.register('MMM-pages', {
* @param {number} payload the page to change to
*/
notificationReceived: function(notification, payload) {
const isValidPayload = typeof payload === 'number';
switch (notification) {
case 'PAGE_CHANGED':
Log.log(`${this.name} recieved a notification`
+ `to change to page ${payload} of type ${typeof payload}`);
if (typeof payload === 'number') {
if (isValidPayload) {
this.curPage = payload;
} else {
Log.error('Was asked to change to an invalid number!');
@ -70,12 +71,18 @@ Module.register('MMM-pages', {
break;
case 'PAGE_INCREMENT':
Log.log(`${this.name} recieved a notification to increment pages!`);
this.curPage = this.mod(this.curPage + 1, this.config.modules.length);
this.curPage = this.mod(
this.curPage + (isValidPayload) ? payload : 1,
this.config.modules.length
);
this.updatePages(true);
break;
case 'PAGE_DECREMENT':
Log.log(`${this.name} recieved a notification to decrement pages!`);
this.curPage = this.mod(this.curPage - 1, this.config.modules.length);
this.curPage = this.mod(
this.curPage - (isValidPayload) ? payload : 1,
this.config.modules.length
);
this.updatePages(true);
break;
case 'DOM_OBJECTS_CREATED':

View file

@ -76,9 +76,10 @@ this.sendNotification("PAGE_CHANGED", 2);
```
This would cause the module to change show that you are on page 3.
You can also just send `PAGE_INCREMENT` or `PAGE_DECREMENT` without any payloads
(or with, but it will be ignored) to have the module change the displayed page
by one.
Sending a `PAGE_INCREMENT` or `PAGE_DECREMENT` without any parameters will
increase or decrease the page by one. Attaching a valid payload to the
aforementioned notifications will increase or decrease the pages by that amount.
Remember that this module **strictly checks** for a number.
This module keeps internal track of how many pages you have, defined by your
config in the config file. There is no way to dynamically change the pages you