From f4509e24c66b16107694fd022717cc34743905c0 Mon Sep 17 00:00:00 2001 From: Johan Hammar Date: Tue, 28 Mar 2017 22:02:30 +0200 Subject: [PATCH 1/6] Added a week section to the clock module --- modules/default/clock/README.md | 1 + modules/default/clock/clock.js | 18 ++++++++++- tests/configs/modules/clock/clock_showWeek.js | 32 +++++++++++++++++++ tests/e2e/modules/clock_spec.js | 21 ++++++++++++ translations/en.json | 2 ++ translations/sv.json | 2 ++ 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/configs/modules/clock/clock_showWeek.js diff --git a/modules/default/clock/README.md b/modules/default/clock/README.md index f518a2b2..5c803316 100644 --- a/modules/default/clock/README.md +++ b/modules/default/clock/README.md @@ -30,6 +30,7 @@ The following properties can be configured: | `showPeriodUpper` | Show the period (AM/PM) with 12 hour format as uppercase.

**Possible values:** `true` or `false`
**Default value:** `false` | `clockBold` | Remove the colon and bold the minutes to make a more modern look.

**Possible values:** `true` or `false`
**Default value:** `false` | `showDate` | Turn off or on the Date section.

**Possible values:** `true` or `false`
**Default value:** `true` +| `showWeek` | Turn off or on the Week section.

**Possible values:** `true` or `false`
**Default value:** `false` | `dateFormat` | Configure the date format as you like.

**Possible values:** [Docs](http://momentjs.com/docs/#/displaying/format/)
**Default value:** `"dddd, LL"` | `displayType` | Display a digital clock, analog clock, or both together.

**Possible values:** `digital`, `analog`, or `both`
**Default value:** `digital` | `analogSize` | **Specific to the analog clock.** Defines how large the analog display is.

**Possible values:** A positive number of pixels`
**Default value:** `200px` diff --git a/modules/default/clock/clock.js b/modules/default/clock/clock.js index 21e665e7..761f3948 100644 --- a/modules/default/clock/clock.js +++ b/modules/default/clock/clock.js @@ -16,6 +16,7 @@ Module.register("clock",{ showPeriodUpper: false, clockBold: false, showDate: true, + showWeek: false, dateFormat: "dddd, LL", /* specific to the analog clock */ @@ -61,10 +62,12 @@ Module.register("clock",{ var timeWrapper = document.createElement("div"); var secondsWrapper = document.createElement("sup"); var periodWrapper = document.createElement("span"); + var weekWrapper = document.createElement("div") // Style Wrappers dateWrapper.className = "date normal medium"; timeWrapper.className = "time bright large light"; secondsWrapper.className = "dimmed"; + weekWrapper.className = "week dimmed medium" // Set content of wrappers. // The moment().format("h") method has a bug on the Raspberry Pi. @@ -90,6 +93,9 @@ Module.register("clock",{ if(this.config.showDate){ dateWrapper.innerHTML = now.format(this.config.dateFormat); } + if (this.config.showWeek) { + weekWrapper.innerHTML = this.translate("WEEK") + " " + now.week(); + } timeWrapper.innerHTML = timeString; secondsWrapper.innerHTML = now.format("ss"); if (this.config.showPeriodUpper) { @@ -172,16 +178,25 @@ Module.register("clock",{ // Display only a digital clock wrapper.appendChild(dateWrapper); wrapper.appendChild(timeWrapper); + wrapper.appendChild(weekWrapper); } else if (this.config.displayType === "analog") { // Display only an analog clock dateWrapper.style.textAlign = "center"; - dateWrapper.style.paddingBottom = "15px"; + + if (this.config.showWeek) { + weekWrapper.style.paddingBottom = "15px"; + } else { + dateWrapper.style.paddingBottom = "15px"; + } + if (this.config.analogShowDate === "top") { wrapper.appendChild(dateWrapper); + wrapper.appendChild(weekWrapper); wrapper.appendChild(clockCircle); } else if (this.config.analogShowDate === "bottom") { wrapper.appendChild(clockCircle); wrapper.appendChild(dateWrapper); + wrapper.appendChild(weekWrapper); } else { wrapper.appendChild(clockCircle); } @@ -198,6 +213,7 @@ Module.register("clock",{ digitalWrapper.style.cssFloat = "none"; digitalWrapper.appendChild(dateWrapper); digitalWrapper.appendChild(timeWrapper); + digitalWrapper.appendChild(weekWrapper); var appendClocks = function(condition, pos1, pos2) { var padding = [0,0,0,0]; diff --git a/tests/configs/modules/clock/clock_showWeek.js b/tests/configs/modules/clock/clock_showWeek.js new file mode 100644 index 00000000..8a5f305a --- /dev/null +++ b/tests/configs/modules/clock/clock_showWeek.js @@ -0,0 +1,32 @@ +/* Magic Mirror Test config for default clock module + * + * By Johan Hammar + * MIT Licensed. + */ + +var 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: "clock", + position: "middle_center", + config: { + showWeek: true + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") {module.exports = config;} diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index 8c6d9ff6..a24b38d6 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -100,4 +100,25 @@ describe("Clock module", function () { }); }); + describe("with showWeek config enabled", function() { + before(function() { + // Set config sample for use in test + process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showWeek.js"; + }); + + beforeEach(function (done) { + app.start().then(function() { done(); } ); + }); + + afterEach(function (done) { + app.stop().then(function() { done(); }); + }); + + it("shows week with correct format", function() { + const weekRegex = /^Week [0-9]{1,2}$/; + return app.client.waitUntilWindowLoaded() + .getText(".clock .week").should.eventually.match(weekRegex); + }); + }); + }); diff --git a/translations/en.json b/translations/en.json index 46061738..a1472cf1 100644 --- a/translations/en.json +++ b/translations/en.json @@ -7,6 +7,8 @@ "RUNNING": "Ends in", "EMPTY": "No upcoming events.", + "WEEK": "Week", + "N": "N", "NNE": "NNE", "NE": "NE", diff --git a/translations/sv.json b/translations/sv.json index 1fe3d48d..8025e51e 100644 --- a/translations/sv.json +++ b/translations/sv.json @@ -7,6 +7,8 @@ "RUNNING": "Slutar", "EMPTY": "Inga kommande händelser.", + "WEEK": "Vecka", + "N": "N", "NNE": "NNO", "NE": "NO", From 44f50eba5bbd0645becf94201b2f7c876a7897ee Mon Sep 17 00:00:00 2001 From: Johan Hammar Date: Tue, 28 Mar 2017 22:30:48 +0200 Subject: [PATCH 2/6] Updated changelog with information about the new week section of the clock module --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb328821..0801c54e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added multiple calendar icon support. - Added meta tags to support fullscreen mode on iOS (for server mode) - Added `ignoreOldItems` and `ignoreOlderThan` options to the News Feed module +- Added a configurable Week section to the clock module. ### Fixed - Update .gitignore to not ignore default modules folder. From cc9a4296896748fd3b7a95c8d65859ba1941ec8c Mon Sep 17 00:00:00 2001 From: Johan Hammar Date: Tue, 28 Mar 2017 22:44:47 +0200 Subject: [PATCH 3/6] Corrected minor typo --- js/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/server.js b/js/server.js index beb8b84c..c57b74f9 100644 --- a/js/server.js +++ b/js/server.js @@ -15,7 +15,7 @@ var fs = require("fs"); var helmet = require("helmet"); var Server = function(config, callback) { - console.log("Starting server op port " + config.port + " ... "); + console.log("Starting server on port " + config.port + " ... "); server.listen(config.port, config.address ? config.address : null); From 84046170901f81810d3fbc05fe4d4ffd1267e8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Tue, 28 Mar 2017 17:57:34 -0300 Subject: [PATCH 4/6] Add translations es for Week --- translations/es.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/translations/es.json b/translations/es.json index 914a72ce..adee4dfc 100644 --- a/translations/es.json +++ b/translations/es.json @@ -7,6 +7,8 @@ "RUNNING": "Termina en", "EMPTY": "No hay eventos programados.", + "WEEK": "Semana", + "N": "N", "NNE": "NNE", "NE": "NE", From 945cbdd3a754fc8a233e645ecd8310f994e1e6d8 Mon Sep 17 00:00:00 2001 From: Yuri Date: Thu, 30 Mar 2017 14:47:16 +0800 Subject: [PATCH 5/6] Update zh_cn.json Add Chinese support updated. --- translations/zh_cn.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/translations/zh_cn.json b/translations/zh_cn.json index e7f69616..18fe4534 100644 --- a/translations/zh_cn.json +++ b/translations/zh_cn.json @@ -3,6 +3,7 @@ "TODAY": "今天", "TOMORROW": "明天", + "DAYAFTERTOMORROW": "后天", "RUNNING": "结束日期", "EMPTY": "没有更多的活动。", @@ -22,4 +23,8 @@ "WNW": "西偏北风", "NW": "西北风", "NNW": "北偏西风" + + "UPDATE_NOTIFICATION": "MagicMirror² 有新的更新", + "UPDATE_NOTIFICATION_MODULE": "模块 MODULE_NAME 可更新", + "UPDATE_INFO": "当前已安装版本为 COMMIT_COUNT 落后于分支 BRANCH_NAME " } From 9e5a4189d70a9ddab3a0b2d8fb72c414bf4b7c51 Mon Sep 17 00:00:00 2001 From: Yuri Date: Thu, 30 Mar 2017 14:48:21 +0800 Subject: [PATCH 6/6] Update zh_cn.json --- translations/zh_cn.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translations/zh_cn.json b/translations/zh_cn.json index 18fe4534..5efbb691 100644 --- a/translations/zh_cn.json +++ b/translations/zh_cn.json @@ -22,7 +22,7 @@ "W": "西风", "WNW": "西偏北风", "NW": "西北风", - "NNW": "北偏西风" + "NNW": "北偏西风", "UPDATE_NOTIFICATION": "MagicMirror² 有新的更新", "UPDATE_NOTIFICATION_MODULE": "模块 MODULE_NAME 可更新",