mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 12:12:20 +00:00
commit
8c85e240b7
@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Run tests on long term support and latest stable version of nodejs
|
- Run tests on long term support and latest stable version of nodejs
|
||||||
- Added the ability to configure a list of modules that shouldn't be update checked.
|
- Added the ability to configure a list of modules that shouldn't be update checked.
|
||||||
- Run linters on git commits
|
- Run linters on git commits
|
||||||
|
- Added date functionality to compliments: display birthday wishes or celebrate an anniversary
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Force declaration of public ip address in config file (ISSUE #1852)
|
- Force declaration of public ip address in config file (ISSUE #1852)
|
||||||
|
@ -28,6 +28,9 @@ Module.register("compliments", {
|
|||||||
"Wow, you look hot!",
|
"Wow, you look hot!",
|
||||||
"You look nice!",
|
"You look nice!",
|
||||||
"Hi, sexy!"
|
"Hi, sexy!"
|
||||||
|
],
|
||||||
|
"....-01-01": [
|
||||||
|
"Happy new year!"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
updateInterval: 30000,
|
updateInterval: 30000,
|
||||||
@ -37,7 +40,8 @@ Module.register("compliments", {
|
|||||||
morningEndTime: 12,
|
morningEndTime: 12,
|
||||||
afternoonStartTime: 12,
|
afternoonStartTime: 12,
|
||||||
afternoonEndTime: 17,
|
afternoonEndTime: 17,
|
||||||
random: true
|
random: true,
|
||||||
|
mockDate: null
|
||||||
},
|
},
|
||||||
lastIndexUsed:-1,
|
lastIndexUsed:-1,
|
||||||
// Set currentweather from module
|
// Set currentweather from module
|
||||||
@ -102,6 +106,7 @@ Module.register("compliments", {
|
|||||||
*/
|
*/
|
||||||
complimentArray: function() {
|
complimentArray: function() {
|
||||||
var hour = moment().hour();
|
var hour = moment().hour();
|
||||||
|
var date = this.config.mockDate ? this.config.mockDate : moment().format("YYYY-MM-DD");
|
||||||
var compliments;
|
var compliments;
|
||||||
|
|
||||||
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
|
if (hour >= this.config.morningStartTime && hour < this.config.morningEndTime && this.config.compliments.hasOwnProperty("morning")) {
|
||||||
@ -122,6 +127,12 @@ Module.register("compliments", {
|
|||||||
|
|
||||||
compliments.push.apply(compliments, this.config.compliments.anytime);
|
compliments.push.apply(compliments, this.config.compliments.anytime);
|
||||||
|
|
||||||
|
for (entry in this.config.compliments) {
|
||||||
|
if (new RegExp(entry).test(date)) {
|
||||||
|
compliments.push.apply(compliments, this.config.compliments[entry]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return compliments;
|
return compliments;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -151,19 +162,19 @@ Module.register("compliments", {
|
|||||||
// get the current time of day compliments list
|
// get the current time of day compliments list
|
||||||
var compliments = this.complimentArray();
|
var compliments = this.complimentArray();
|
||||||
// variable for index to next message to display
|
// variable for index to next message to display
|
||||||
let index=0;
|
let index = 0;
|
||||||
// are we randomizing
|
// are we randomizing
|
||||||
if(this.config.random){
|
if(this.config.random){
|
||||||
// yes
|
// yes
|
||||||
index = this.randomIndex(compliments);
|
index = this.randomIndex(compliments);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// no, sequetial
|
// no, sequential
|
||||||
// if doing sequential, don't fall off the end
|
// if doing sequential, don't fall off the end
|
||||||
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed;
|
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
return compliments[index];
|
return compliments[index] || "";
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override dom generator.
|
// Override dom generator.
|
||||||
@ -173,9 +184,9 @@ Module.register("compliments", {
|
|||||||
// get the compliment text
|
// get the compliment text
|
||||||
var complimentText = this.randomCompliment();
|
var complimentText = this.randomCompliment();
|
||||||
// split it into parts on newline text
|
// split it into parts on newline text
|
||||||
var parts= complimentText.split("\n");
|
var parts = complimentText.split("\n");
|
||||||
// create a span to hold it all
|
// create a span to hold it all
|
||||||
var compliment=document.createElement("span");
|
var compliment = document.createElement("span");
|
||||||
// process all the parts of the compliment text
|
// process all the parts of the compliment text
|
||||||
for (part of parts){
|
for (part of parts){
|
||||||
// create a text element for each part
|
// create a text element for each part
|
||||||
|
41
tests/configs/modules/compliments/compliments_date.js
Normal file
41
tests/configs/modules/compliments/compliments_date.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* Magic Mirror Test config compliments with date type
|
||||||
|
*
|
||||||
|
* By Rejas
|
||||||
|
*
|
||||||
|
* MIT Licensed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
port: 8080,
|
||||||
|
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
|
||||||
|
|
||||||
|
language: "en",
|
||||||
|
timeFormat: 12,
|
||||||
|
units: "metric",
|
||||||
|
electronOptions: {
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
modules: [
|
||||||
|
{
|
||||||
|
module: "compliments",
|
||||||
|
position: "middle_center",
|
||||||
|
config: {
|
||||||
|
mockDate: "2020-01-01",
|
||||||
|
compliments: {
|
||||||
|
morning: [],
|
||||||
|
afternoon: [],
|
||||||
|
evening: [],
|
||||||
|
"....-01-01": [
|
||||||
|
"Happy new year!"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||||
|
if (typeof module !== "undefined") {module.exports = config;}
|
@ -89,4 +89,19 @@ describe("Compliments module", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Feature date in compliments module", function() {
|
||||||
|
describe("Set date and empty compliments for anytime, morning, evening and afternoon", function() {
|
||||||
|
before(function() {
|
||||||
|
// Set config sample for use in test
|
||||||
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js";
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Show happy new year compliment on new years day", function() {
|
||||||
|
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
|
||||||
|
expect(text).to.be.oneOf(["Happy new year!"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user