From 950fa84d1ce44fc50270aeba19f3864964542b32 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 30 Nov 2016 10:30:49 -0500 Subject: [PATCH 1/2] Added capability to load compliments from the host file system. --- modules/default/compliments/compliments.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/default/compliments/compliments.js b/modules/default/compliments/compliments.js index f05cd9c1..3bfdc8be 100644 --- a/modules/default/compliments/compliments.js +++ b/modules/default/compliments/compliments.js @@ -29,6 +29,7 @@ Module.register("compliments",{ ] }, updateInterval: 30000, + remoteFile: null, fadeSpeed: 4000 }, @@ -46,6 +47,12 @@ Module.register("compliments",{ this.lastComplimentIndex = -1; + if (this.config.remoteFile != null) { + this.complimentFile((response) => { + this.config.compliments = JSON.parse(response); + }); + } + // Schedule update timer. var self = this; setInterval(function() { @@ -104,6 +111,21 @@ Module.register("compliments",{ }, + /* complimentFile(callback) + * Retrieve a file from the local filesystem + */ + complimentFile: function(callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open('GET', this.file(this.config.remoteFile), true); + xobj.onreadystatechange = function () { + if (xobj.readyState == 4 && xobj.status == "200") { + callback(xobj.responseText); + } + }; + xobj.send(null); + }, + /* complimentArray() * Retrieve a random compliment. * From 829ccfca88364aa79d94b94e614bb55b5e647e0b Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 30 Nov 2016 10:31:19 -0500 Subject: [PATCH 2/2] Updated changelog and compliments documentation. --- CHANGELOG.md | 1 + modules/default/compliments/README.md | 38 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5b5d31e..d3acbcc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added option `disabled` for modules. - Added option `address` to set bind address. - Added option `onlyTemp` for currentweather module to show show only current temperature and weather icon. +- Added option `remoteFile` to compliments module to load compliment array from filesystem. ### Updated - Modified translations for Frysk. diff --git a/modules/default/compliments/README.md b/modules/default/compliments/README.md index 911de4b0..1dab242a 100644 --- a/modules/default/compliments/README.md +++ b/modules/default/compliments/README.md @@ -56,6 +56,15 @@ The following properties can be configured:
Default value: See compliment configuration below. + + remoteFile + External file from which to load the compliments
+
Possible values:Path to a JSON file containing compliments, configured + as per the value of the compliments configuration (see below). An object with three arrays: + morning, afternoon and evening. - compliments.json +
Default value: null (Do not load from file) + + @@ -123,3 +132,32 @@ config: { } } ```` + +### External Compliment File +You may specify an external file that contains the three compliment arrays. This is particularly useful if you have a +large number of compliments and do not wish to crowd your `config.js` file with a large array of compliments. +Adding the `remoteFile` variable will override an array you specify in the configuration file. + +This file must be straight JSON. Note that the array names need quotes +around them ("morning", "afternoon", "evening", "snow", "rain", etc.). +#### Example compliments.json file: +````json +{ + "morning" : [ + "Good morning, sunshine!", + "Who needs coffee when you have your smile?", + "Go get 'em, Tiger!" + ], + "afternoon" : [ + "Hitting your stride!", + "You are making a difference!", + "You're more fun than bubble wrap!" + ], + "evening" : [ + "You made someone smile today, I know it.", + "You are making a difference.", + "The day was better for your efforts." + ] +} +```` +