mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-19 12:18:25 +00:00
Compare commits
330 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b595cdd31e | ||
|
e64870ca58 | ||
|
a40f8d5b3a | ||
|
61b8871ead | ||
|
4b5a3ed44d | ||
|
7d6b7b2691 | ||
|
3dba46b74f | ||
|
2767e31a28 | ||
|
40886bcf08 | ||
|
04dde74572 | ||
|
29f3ac065f | ||
|
d2b30b4f9c | ||
|
3a42663dea | ||
|
905d0ca409 | ||
|
7e2c78666e | ||
|
6a5f0225fe | ||
|
ddb01fca31 | ||
|
684a3cd49e | ||
|
ad5e42115b | ||
|
2d6b8d0c47 | ||
|
61471e5449 | ||
|
b6f7ab7a9c | ||
|
2d061be98e | ||
|
d6e97b8c76 | ||
|
9e44660746 | ||
|
03e6ca58ab | ||
|
94c63b0554 | ||
|
c7c8c40a70 | ||
|
91c726c706 | ||
|
c9805e7ac9 | ||
|
a4db0e40e3 | ||
|
305b55cb2a | ||
|
272ca1ac4f | ||
|
bbc6a1b38f | ||
|
0e93713464 | ||
|
8f60e103f9 | ||
|
9cc702241d | ||
|
0d61c44232 | ||
|
9a8faac316 | ||
|
05f710cb5c | ||
|
c6184769e7 | ||
|
515d1bd920 | ||
|
b19cb17bba | ||
|
c1e808bce6 | ||
|
d8b7292d4b | ||
|
edd5e2f5bc | ||
|
efc6cb73b2 | ||
|
ecd79dc34b | ||
|
cdfc8b825d | ||
|
301344c96d | ||
|
5279995c3b | ||
|
5176b06b59 | ||
|
ed61ac624d | ||
|
4da6e3ecee | ||
|
9e5561936a | ||
|
843cd0eff6 | ||
|
6b6ee934a1 | ||
|
aea57ffaf4 | ||
|
87b48661fa | ||
|
556fa44858 | ||
|
1c3e196508 | ||
|
9b6812ad0c | ||
|
b7944c7fa4 | ||
|
2fbedca746 | ||
|
340d04a48c | ||
|
460a383ffc | ||
|
52c4e3a256 | ||
|
4338f11eb1 | ||
|
42bab052e0 | ||
|
0cb377618e | ||
|
5e4d25b957 | ||
|
153d1853fa | ||
|
22a3448461 | ||
|
2cad869680 | ||
|
bc912a8ea4 | ||
|
db9176c284 | ||
|
06308210c0 | ||
|
63d9904370 | ||
|
caaeff5cb7 | ||
|
d8c93d3455 | ||
|
cb28e5fddc | ||
|
7d7ec1a00b | ||
|
a5bc8dfa3f | ||
|
d74f055180 | ||
|
73be6c35a6 | ||
|
24f74e1400 | ||
|
8900e069f3 | ||
|
1dfec119bb | ||
|
9e23d35f01 | ||
|
cd2b240308 | ||
|
749f366a4a | ||
|
420aaa92fa | ||
|
985698bbc3 | ||
|
f9c9139f20 | ||
|
f308e7541f | ||
|
cb7ccd7854 | ||
|
a4953028d0 | ||
|
3d6485588d | ||
|
51bb9fede7 | ||
|
269c429959 | ||
|
fcdc84a12a | ||
|
ecdd9734eb | ||
|
84fc2c65af | ||
|
c8849a17b6 | ||
|
d8b49218e9 | ||
|
e95023e8cc | ||
|
878710e2cf | ||
|
0677d0a810 | ||
|
9c98fea8f4 | ||
|
e958f33450 | ||
|
937080b011 | ||
|
aee5803dd2 | ||
|
f1f394b871 | ||
|
81a32b56f0 | ||
|
a6aae70a55 | ||
|
823eb23773 | ||
|
1ff51822df | ||
|
500147e130 | ||
|
d90de18d99 | ||
|
ba4f48662f | ||
|
d208437c05 | ||
|
01faa2e1d7 | ||
|
c630c387d6 | ||
|
a774718607 | ||
|
9430c70d0d | ||
|
f3e893fddb | ||
|
11e144ca64 | ||
|
fbceab707e | ||
|
5b2efc43b9 | ||
|
8d85d1aa2d | ||
|
b469fc7577 | ||
|
9db54831c8 | ||
|
9b88bde09a | ||
|
aad03a74c5 | ||
|
55eb6e2e5c | ||
|
ca07355873 | ||
|
11a59e26b2 | ||
|
ec6d9e3521 | ||
|
230accd31e | ||
|
a24a4a747e | ||
|
1e97b5c27a | ||
|
a314ea1aa3 | ||
|
a77128d5f7 | ||
|
1b2673367e | ||
|
ce10e91a60 | ||
|
5244b37d2c | ||
|
1239c6716b | ||
|
67f6258ab0 | ||
|
9f63172b43 | ||
|
bd8bfeb525 | ||
|
4918c4ef4b | ||
|
00d9ea9344 | ||
|
33537cde76 | ||
|
3d5db5c9ca | ||
|
fdf339514d | ||
|
937c4e485a | ||
|
837c060e1f | ||
|
00bacd7dde | ||
|
781031775e | ||
|
97aee3d375 | ||
|
34698751f2 | ||
|
3c31460f2f | ||
|
d5cb60b19c | ||
|
3a7cfe3208 | ||
|
f079cdad64 | ||
|
2822303138 | ||
|
e38de75520 | ||
|
2723604d3e | ||
|
82ee051c1a | ||
|
7bdf49b7e0 | ||
|
32521aba6b | ||
|
819c4cde1c | ||
|
776c486b1a | ||
|
bcd97120a4 | ||
|
312bfb8509 | ||
|
11c9a50931 | ||
|
94c0656bcd | ||
|
13313d0b25 | ||
|
3a20db1d76 | ||
|
00148b4cc8 | ||
|
a31546b1ff | ||
|
361b62b8e2 | ||
|
37327b77a7 | ||
|
7ef8a5bb11 | ||
|
11cfb8af32 | ||
|
7315f7d283 | ||
|
7d58eb718e | ||
|
651be76776 | ||
|
4a5c6f1d39 | ||
|
5745d71d6a | ||
|
db62b7421a | ||
|
4084c57789 | ||
|
f90bec985a | ||
|
90f911c529 | ||
|
6c88b106db | ||
|
cef69d1b97 | ||
|
f76a7fb331 | ||
|
3e7b8b0663 | ||
|
a6eb3ad037 | ||
|
9468749384 | ||
|
37417fa1bb | ||
|
217146351e | ||
|
818ec33cef | ||
|
cd1671830a | ||
|
a5fca87dd0 | ||
|
f06ce55626 | ||
|
853085e755 | ||
|
2b7accaf68 | ||
|
5533d93172 | ||
|
f0e8c865fe | ||
|
36400c0a83 | ||
|
c5383557b5 | ||
|
b645007884 | ||
|
63ac137206 | ||
|
808cbf8e0b | ||
|
8ed77ba0c7 | ||
|
66c74c51e4 | ||
|
7a272ef0ab | ||
|
60b817ec8e | ||
|
a41ecaf7cc | ||
|
d41afa0e53 | ||
|
a6284e05e5 | ||
|
e56f61441d | ||
|
7b4b7dffa2 | ||
|
77a214ef9c | ||
|
cf2723aafb | ||
|
499e99cfc5 | ||
|
a7b83e9fe3 | ||
|
964504b9c3 | ||
|
ec65e66c58 | ||
|
e694b080be | ||
|
70894b3938 | ||
|
fb7115fc13 | ||
|
a619fc4fef | ||
|
7c6c5fd06f | ||
|
2970568eab | ||
|
62cb3a610e | ||
|
f600c163ca | ||
|
77cb68e5ac | ||
|
c6314576aa | ||
|
515c183070 | ||
|
63b9c0e6b8 | ||
|
84893b1664 | ||
|
835668d96d | ||
|
2bce15dc6e | ||
|
8f1a212b52 | ||
|
5c08bde0fa | ||
|
98a84c031e | ||
|
ea1715384e | ||
|
d9a4ee4f65 | ||
|
62017c4661 | ||
|
702b98f510 | ||
|
69aafd7d6a | ||
|
c1559dd8c8 | ||
|
4df1895560 | ||
|
cac92da6e4 | ||
|
5d39d85215 | ||
|
99b4c43fd5 | ||
|
b2f59d6813 | ||
|
c7d79bb893 | ||
|
aa80c468c4 | ||
|
6008cba2db | ||
|
caf56671dc | ||
|
44eccf5ee4 | ||
|
8f96e4847c | ||
|
ae3e307f33 | ||
|
3fe0c758ed | ||
|
7240fb32d2 | ||
|
e23a3461ba | ||
|
727eb0cfd7 | ||
|
3796076360 | ||
|
ef9576f8c4 | ||
|
94fc4cb8a2 | ||
|
ccb248db91 | ||
|
e7de447725 | ||
|
7ff5429cb7 | ||
|
17c581b4aa | ||
|
41e5c2939f | ||
|
7e2ab51298 | ||
|
03f917fd9c | ||
|
d24e10a728 | ||
|
a17ac1c16e | ||
|
dd6b972be4 | ||
|
7d0c9ba0d9 | ||
|
6fa211634f | ||
|
1ca24c7f38 | ||
|
bcfbccae59 | ||
|
20b75ce6ed | ||
|
2ea15d7bf5 | ||
|
18e14c597f | ||
|
06d75999d7 | ||
|
7047a7cae6 | ||
|
20d2124867 | ||
|
3c7a85361e | ||
|
1ffbbdac99 | ||
|
eeccca8842 | ||
|
e2d2dbd2ba | ||
|
c61f0409fb | ||
|
806be39a6d | ||
|
6170b0d059 | ||
|
bca838495e | ||
|
e31a747250 | ||
|
4cf430e146 | ||
|
ef554cf6ec | ||
|
fcd91daee6 | ||
|
396c78b46a | ||
|
4677a3fd89 | ||
|
834ab5c6b9 | ||
|
1599e8f7ff | ||
|
7430704002 | ||
|
4d7b19c8cb | ||
|
40f535cf3c | ||
|
17425dcaf7 | ||
|
6b87fc64af | ||
|
35174b0348 | ||
|
fd53541719 | ||
|
7c68bff9f5 | ||
|
6c64991951 | ||
|
ca04ff0f37 | ||
|
7742575cab | ||
|
cdcdce702d | ||
|
c80e04fe8d | ||
|
c3b3ea107a | ||
|
1dc530c549 | ||
|
8b0b70e757 | ||
|
a8bd196234 | ||
|
239d425940 | ||
|
baa3c1461c | ||
|
fa8e398e90 | ||
|
f34407fc43 |
@@ -3,4 +3,3 @@ vendor/*
|
||||
!/modules/default/**
|
||||
!/modules/node_helper
|
||||
!/modules/node_helper/**
|
||||
!/modules/default/defaultmodules.js
|
||||
|
@@ -2,9 +2,11 @@
|
||||
"rules": {
|
||||
"indent": ["error", "tab"],
|
||||
"quotes": ["error", "double"],
|
||||
"semi": ["error"],
|
||||
"max-len": ["error", 250],
|
||||
"curly": "error",
|
||||
"camelcase": ["error", {"properties": "never"}],
|
||||
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
|
||||
"no-trailing-spaces": ["error", {"ignoreComments": false }],
|
||||
"no-irregular-whitespace": ["error"]
|
||||
},
|
||||
@@ -15,6 +17,7 @@
|
||||
},
|
||||
"parserOptions": {
|
||||
"sourceType": "module",
|
||||
"ecmaVersion": 2017,
|
||||
"ecmaFeatures": {
|
||||
"globalReturn": true
|
||||
}
|
||||
|
19
.github/stale.yml
vendored
Normal file
19
.github/stale.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 60
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 7
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
- under investigation
|
||||
- pr welcome
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: wontfix
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
12
.gitignore
vendored
12
.gitignore
vendored
@@ -11,7 +11,9 @@ coverage
|
||||
.grunt
|
||||
.lock-wscript
|
||||
build/Release
|
||||
node_modules
|
||||
/node_modules/**/*
|
||||
fonts/node_modules/**/*
|
||||
vendor/node_modules/**/*
|
||||
jspm_modules
|
||||
.npm
|
||||
.node_repl_history
|
||||
@@ -57,12 +59,6 @@ Temporary Items
|
||||
.directory
|
||||
.Trash-*
|
||||
|
||||
# Various Magic Mirror ignoramuses and anti-ignoramuses.
|
||||
|
||||
# Don't ignore the node_helper core module.
|
||||
!/modules/node_helper
|
||||
!/modules/node_helper/**
|
||||
|
||||
# Ignore all modules except the default modules.
|
||||
/modules/**
|
||||
!/modules/default
|
||||
@@ -81,3 +77,5 @@ Temporary Items
|
||||
*.orig
|
||||
*.rej
|
||||
*.bak
|
||||
|
||||
!/tests/node_modules/**/*
|
14
.snyk
14
.snyk
@@ -1,14 +0,0 @@
|
||||
version: v1.5.2
|
||||
ignore: {}
|
||||
patch:
|
||||
'npm:minimatch:20160620':
|
||||
- snyk > recursive-readdir > minimatch:
|
||||
patched: '2016-07-30T14:02:31.280Z'
|
||||
'npm:negotiator:20160616':
|
||||
- socket.io > engine.io > accepts > negotiator:
|
||||
patched: '2016-07-30T14:02:31.280Z'
|
||||
'npm:ws:20160624':
|
||||
- socket.io > engine.io > ws:
|
||||
patched: '2016-07-30T14:02:31.280Z'
|
||||
- socket.io > socket.io-client > engine.io-client > ws:
|
||||
patched: '2016-07-30T14:02:31.280Z'
|
@@ -1,6 +1,9 @@
|
||||
dist: trusty
|
||||
language: node_js
|
||||
node_js:
|
||||
- "8"
|
||||
- "10"
|
||||
before_install:
|
||||
- npm i -g npm
|
||||
before_script:
|
||||
- yarn danger ci
|
||||
- npm install grunt-cli -g
|
||||
@@ -8,9 +11,9 @@ before_script:
|
||||
- "sh -e /etc/init.d/xvfb start"
|
||||
- sleep 5
|
||||
script:
|
||||
- grunt
|
||||
- npm run test:unit
|
||||
- npm run test:e2e
|
||||
- npm run test:unit
|
||||
- grunt
|
||||
after_script:
|
||||
- npm list
|
||||
cache:
|
||||
|
100
CHANGELOG.md
Normal file → Executable file
100
CHANGELOG.md
Normal file → Executable file
@@ -3,10 +3,106 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
---
|
||||
|
||||
❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² core.
|
||||
|
||||
## [2.10.0] - 2020-01-01
|
||||
|
||||
ℹ️ **Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`.
|
||||
|
||||
### Added
|
||||
- Timestamps in log output.
|
||||
- Padding in dateheader mode of the calendar module.
|
||||
- New upgrade script to help users consume regular updates installers/upgrade-script.sh.
|
||||
- New script to help setup pm2, without install installers/fixuppm2.sh.
|
||||
|
||||
### Updated
|
||||
- Updated lower bound of `lodash` and `helmet` dependencies for security patches.
|
||||
- Updated compliments.js to handle newline in text, as textfields to not interpolate contents.
|
||||
- Updated raspberry.sh installer script to handle new platform issues, split node/npm, pm2, and screen saver changes.
|
||||
- Improve handling for armv6l devices, where electron support has gone away, add optional serveronly config option.
|
||||
- Improved run-start.sh to handle for serveronly mode, by choice, or when electron not available.
|
||||
- Only check for xwindows running if not on macOS.
|
||||
|
||||
### Fixed
|
||||
- Fixed issue in weatherforecast module where predicted amount of rain was not using the decimal symbol specified in config.js.
|
||||
- Module header now updates correctly, if a module need to dynamically show/hide its header based on a condition.
|
||||
- Fix handling of config.js for serverOnly mode commented out.
|
||||
- Fixed issue in calendar module where the debug script didn't work correctly with authentication
|
||||
- Fixed issue that some full day events were not correctly recognized as such
|
||||
- Display full day events lasting multiple days as happening today instead of some days ago if they are still ongoing
|
||||
|
||||
## [2.9.0] - 2019-10-01
|
||||
|
||||
ℹ️ **Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`. If you are having issues running Electron, make sure your [Raspbian is up to date](https://www.raspberrypi.org/documentation/raspbian/updating.md).
|
||||
|
||||
### Added
|
||||
- Spanish translation for "PRECIP".
|
||||
- Adding a Malay (Malaysian) translation for MagicMirror².
|
||||
- Add test check URLs of vendors 200 and 404 HTTP CODE.
|
||||
- Add tests for new weather module and helper to stub ajax requests.
|
||||
|
||||
### Updated
|
||||
- Updatenotification module: Display update notification for a limited (configurable) time.
|
||||
- Enabled e2e/vendor_spec.js tests.
|
||||
- The css/custom.css will be rename after the next release. We've add into `run-start.sh` a instruction by GIT to ignore with `--skip-worktree` and `rm --cached`. [#1540](https://github.com/MichMich/MagicMirror/issues/1540)
|
||||
- Disable sending of notification CLOCK_SECOND when displaySeconds is false.
|
||||
|
||||
### Fixed
|
||||
- Updatenotification module: Properly handle race conditions, prevent crash.
|
||||
- Send `NEWS_FEED` notification also for the first news messages which are shown.
|
||||
- Fixed issue where weather module would not refresh data after a network or API outage. [#1722](https://github.com/MichMich/MagicMirror/issues/1722)
|
||||
- Fixed weatherforecast module not displaying rain amount on fallback endpoint.
|
||||
- Notifications CLOCK_SECOND & CLOCK_MINUTE being from startup instead of matched against the clock and avoid drifting.
|
||||
|
||||
## [2.8.0] - 2019-07-01
|
||||
|
||||
ℹ️ **Note:** This update uses new dependencies. Please update using the following command: `git pull && npm install`. If you are having issues running Electron, make sure your [Raspbian is up to date](https://www.raspberrypi.org/documentation/raspbian/updating.md).
|
||||
|
||||
### Added
|
||||
- Option to show event location in calendar
|
||||
- Finnish translation for "Feels" and "Weeks"
|
||||
- Russian translation for “Feels”
|
||||
- Calendar module: added `nextDaysRelative` config option
|
||||
- Add `broadcastPastEvents` config option for calendars to include events from the past `maximumNumberOfDays` in event broadcasts
|
||||
- Added feature to broadcast news feed items `NEWS_FEED` and updated news items `NEWS_FEED_UPDATED` in default [newsfeed](https://github.com/MichMich/MagicMirror/tree/develop/modules/default/newsfeed) module (when news is updated) with documented default and `config.js` options in [README.md](https://github.com/MichMich/MagicMirror/blob/develop/modules/default/newsfeed/README.md)
|
||||
- Added notifications to default `clock` module broadcasting `CLOCK_SECOND` and `CLOCK_MINUTE` for the respective time elapsed.
|
||||
- Added UK Met Office Datapoint feed as a provider in the default weather module.
|
||||
- Added new provider class
|
||||
- Added suncalc.js dependency to calculate sun times (not provided in UK Met Office feed)
|
||||
- Added "tempUnits" and "windUnits" to allow, for example, temp in metric (i.e. celsius) and wind in imperial (i.e. mph). These will override "units" if specified, otherwise the "units" value will be used.
|
||||
- Use Feels Like temp from feed if present
|
||||
- Optionally display probability of precipitation (PoP) in current weather (UK Met Office data)
|
||||
- Automatically try to fix eslint errors by passing `--fix` option to it
|
||||
- Added sunrise and sunset times to weathergov weather provider [#1705](https://github.com/MichMich/MagicMirror/issues/1705)
|
||||
- Added "useLocationAsHeader" to display "location" in `config.js` as header when location name is not returned
|
||||
- Added to `newsfeed.js`: in order to design the news article better with css, three more class-names were introduced: newsfeed-desc, newsfeed-desc, newsfeed-desc
|
||||
|
||||
### Updated
|
||||
- English translation for "Feels" to "Feels like"
|
||||
- Fixed the example calender url in `config.js.sample`
|
||||
- Update `ical.js` to solve various calendar issues.
|
||||
- Update weather city list url [#1676](https://github.com/MichMich/MagicMirror/issues/1676)
|
||||
- Only update clock once per minute when seconds aren't shown
|
||||
|
||||
### Fixed
|
||||
- Fixed uncaught exception, race condition on module update
|
||||
- Fixed issue [#1696](https://github.com/MichMich/MagicMirror/issues/1696), some ical files start date to not parse to date type
|
||||
- Allowance HTML5 autoplay-policy (policy is changed from Chrome 66 updates)
|
||||
- Handle SIGTERM messages
|
||||
- Fixes sliceMultiDayEvents so it respects maximumNumberOfDays
|
||||
- Minor types in default NewsFeed [README.md](https://github.com/MichMich/MagicMirror/blob/develop/modules/default/newsfeed/README.md)
|
||||
- Fix typos and small syntax errors, cleanup dependencies, remove multiple-empty-lines, add semi-rule
|
||||
- Fixed issues with calendar not displaying one-time changes to repeating events
|
||||
- Updated the fetchedLocationName variable in currentweather.js so that city shows up in the header
|
||||
|
||||
### Updated installer
|
||||
- give non-pi2+ users (pi0, odroid, jetson nano, mac, windows, ...) option to continue install
|
||||
- use current username vs hardcoded 'pi' to support non-pi install
|
||||
- check for npm installed. node install doesn't do npm anymore
|
||||
- check for mac as part of PM2 install, add install option string
|
||||
- update pm2 config with current username instead of hard coded 'pi'
|
||||
- check for screen saver config, "/etc/xdg/lxsession", bypass if not setup
|
||||
|
||||
## [2.7.1] - 2019-04-02
|
||||
|
||||
Fixed `package.json` version number.
|
||||
|
@@ -4,6 +4,7 @@ module.exports = function(grunt) {
|
||||
pkg: grunt.file.readJSON("package.json"),
|
||||
eslint: {
|
||||
options: {
|
||||
fix: "true",
|
||||
configFile: ".eslintrc.json"
|
||||
},
|
||||
target: [
|
||||
@@ -26,7 +27,7 @@ module.exports = function(grunt) {
|
||||
stylelint: {
|
||||
simple: {
|
||||
options: {
|
||||
configFile: ".stylelintrc"
|
||||
configFile: ".stylelintrc.json"
|
||||
},
|
||||
src: [
|
||||
"css/main.css",
|
||||
@@ -42,11 +43,11 @@ module.exports = function(grunt) {
|
||||
src: [
|
||||
"package.json",
|
||||
".eslintrc.json",
|
||||
".stylelintrc",
|
||||
".stylelintrc.json",
|
||||
"installers/pm2_MagicMirror.json",
|
||||
"translations/*.json",
|
||||
"modules/default/*/translations/*.json",
|
||||
"installers/pm2_MagicMirror.json",
|
||||
"vendor/package.js"
|
||||
"vendor/package.json"
|
||||
],
|
||||
options: {
|
||||
reporter: "jshint"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
The MIT License (MIT)
|
||||
=====================
|
||||
|
||||
Copyright © 2016-2017 Michael Teeuw
|
||||
Copyright © 2016-2019 Michael Teeuw
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
21
README.md
21
README.md
@@ -5,7 +5,7 @@
|
||||
<a href="https://david-dm.org/MichMich/MagicMirror#info=devDependencies"><img src="https://david-dm.org/MichMich/MagicMirror/dev-status.svg" alt="devDependency Status"></a>
|
||||
<a href="https://bestpractices.coreinfrastructure.org/projects/347"><img src="https://bestpractices.coreinfrastructure.org/projects/347/badge"></a>
|
||||
<a href="http://choosealicense.com/licenses/mit"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License"></a>
|
||||
<a href="https://travis-ci.org/MichMich/MagicMirror"><img src="https://travis-ci.org/MichMich/MagicMirror.svg" alt="Travis"></a>
|
||||
<a href="https://travis-ci.com/MichMich/MagicMirror"><img src="https://travis-ci.com/MichMich/MagicMirror.svg" alt="Travis"></a>
|
||||
<a href="https://snyk.io/test/github/MichMich/MagicMirror"><img src="https://snyk.io/test/github/MichMich/MagicMirror/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/MichMich/MagicMirror" style="max-width:100%;"></a>
|
||||
</p>
|
||||
|
||||
@@ -177,14 +177,19 @@ For more available modules, check out out the wiki page [MagicMirror² 3rd Party
|
||||
|
||||
If you want to update your MagicMirror² to the latest version, use your terminal to go to your Magic Mirror folder and type the following command:
|
||||
|
||||
```bash
|
||||
git pull && npm install
|
||||
```
|
||||
bash -c "$(curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/upgrade-script.sh)"
|
||||
```
|
||||
This will do a test run
|
||||
|
||||
If you changed nothing more than the config or the modules, this should work without any problems.
|
||||
Type `git status` to see your changes, if there are any, you can reset them with `git reset --hard`. After that, git pull should be possible.
|
||||
|
||||
If the test update looks good then run this command
|
||||
```
|
||||
bash -c "$(curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/upgrade-script.sh)" apply
|
||||
```
|
||||
If there are changes you have made, they will be listed, and u will have the opportunity to save your work
|
||||
|
||||
The script will also update the dependencies of any active modules
|
||||
If there are update issues, please come to the forums for help
|
||||
## Community
|
||||
|
||||
The community around the MagicMirror² is constantly growing. We even have a [forum](https://forum.magicmirror.builders) now where you can share your ideas, ask questions, help others and get inspired by other builders. We would love to see you there!
|
||||
@@ -208,7 +213,7 @@ Thanks for your help in making MagicMirror² better!
|
||||
MagicMirror² is opensource and free. That doesn't mean we don't need any money.
|
||||
|
||||
Please consider a donation to help us cover the ongoing costs like webservers and email services.
|
||||
If we recieve enough donations we might even be able to free up some working hours and spend some extra time improving the MagicMirror² core.
|
||||
If we receive enough donations we might even be able to free up some working hours and spend some extra time improving the MagicMirror² core.
|
||||
|
||||
To donate, please follow [this](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=G5D8E9MR5DTD2&source=url) link.
|
||||
|
||||
@@ -222,7 +227,7 @@ A real Manifesto is still to be written. Till then, Michael's response on [one o
|
||||
>
|
||||
>Of course, a bundled version can be complimentary to the regular un-bundled version. And I'm sure a lot of (new) users will opt for the bundled version. But this means those users won't be motivated to take a peek under the hood. They will just remain 'users'. They won't become contributors, and worse: they won't be motivated to take their first steps in software development.
|
||||
>
|
||||
>And to be honest: motivating curious users to step out of their comfort zone and take those first steps is what drives me in this project. Therefor my ultimate goal is this project is to keep it as accessible as possible."
|
||||
>And to be honest: motivating curious users to step out of their comfort zone and take those first steps is what drives me in this project. Therefore my ultimate goal is this project is to keep it as accessible as possible."
|
||||
>
|
||||
> ~ Michael Teeuw
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
// Use seperate scope to prevent global scope pollution
|
||||
// Use separate scope to prevent global scope pollution
|
||||
(function () {
|
||||
var config = {};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
// Prefer command line arguments over environment variables
|
||||
["address", "port"].forEach((key) => {
|
||||
config[key] = getCommandLineParameter(key, process.env[key.toUpperCase()]);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function getServerConfig(url) {
|
||||
@@ -30,7 +30,7 @@
|
||||
const request = lib.get(url, (response) => {
|
||||
var configData = "";
|
||||
|
||||
// Gather incomming data
|
||||
// Gather incoming data
|
||||
response.on("data", function(chunk) {
|
||||
configData += chunk;
|
||||
});
|
||||
@@ -43,8 +43,8 @@
|
||||
request.on("error", function(error) {
|
||||
reject(new Error(`Unable to read config from server (${url} (${error.message}`));
|
||||
});
|
||||
})
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function fail(message, code = 1) {
|
||||
if (message !== undefined && typeof message === "string") {
|
||||
@@ -89,7 +89,7 @@
|
||||
});
|
||||
|
||||
child.on("close", (code) => {
|
||||
if (code != 0) {
|
||||
if (code !== 0) {
|
||||
console.log(`There something wrong. The clientonly is not running code ${code}`);
|
||||
}
|
||||
});
|
||||
|
@@ -24,7 +24,12 @@ var config = {
|
||||
language: "en",
|
||||
timeFormat: 24,
|
||||
units: "metric",
|
||||
|
||||
// serverOnly: true/false/"local" ,
|
||||
// local for armv6l processors, default
|
||||
// starts serveronly and then starts chrome browser
|
||||
// false, default for all NON-armv6l devices
|
||||
// true, force serveronly mode, because you want to.. no UI on this device
|
||||
|
||||
modules: [
|
||||
{
|
||||
module: "alert",
|
||||
@@ -45,8 +50,7 @@ var config = {
|
||||
calendars: [
|
||||
{
|
||||
symbol: "calendar-check",
|
||||
url: "webcal://www.calendarlabs.com/templates/ical/US-Holidays.ics"
|
||||
}
|
||||
url: "webcal://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics" }
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -59,7 +63,7 @@ var config = {
|
||||
position: "top_right",
|
||||
config: {
|
||||
location: "New York",
|
||||
locationID: "", //ID from http://bulk.openweathermap.org/sample/; unzip the gz file and find your city
|
||||
locationID: "", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
|
||||
appid: "YOUR_OPENWEATHER_API_KEY"
|
||||
}
|
||||
},
|
||||
@@ -69,7 +73,7 @@ var config = {
|
||||
header: "Weather Forecast",
|
||||
config: {
|
||||
location: "New York",
|
||||
locationID: "5128581", //ID from https://openweathermap.org/city
|
||||
locationID: "5128581", //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
|
||||
appid: "YOUR_OPENWEATHER_API_KEY"
|
||||
}
|
||||
},
|
||||
@@ -84,7 +88,9 @@ var config = {
|
||||
}
|
||||
],
|
||||
showSourceTitle: true,
|
||||
showPublishDate: true
|
||||
showPublishDate: true,
|
||||
broadcastNewsFeeds: true,
|
||||
broadcastNewsUpdates: true
|
||||
}
|
||||
},
|
||||
]
|
||||
|
@@ -1,14 +0,0 @@
|
||||
/*****************************************************
|
||||
* Magic Mirror *
|
||||
* Custom CSS *
|
||||
* *
|
||||
* By Michael Teeuw http://michaelteeuw.nl *
|
||||
* MIT Licensed. *
|
||||
* *
|
||||
* Add any custom CSS below. *
|
||||
* Changes to this files will be ignored by GIT. *
|
||||
*****************************************************/
|
||||
|
||||
body {
|
||||
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
import { danger, fail, warn } from "danger"
|
||||
import { danger, fail, warn } from "danger";
|
||||
|
||||
// Check if the CHANGELOG.md file has been edited
|
||||
// Fail the build and post a comment reminding submitters to do so if it wasn't changed
|
||||
if (!danger.git.modified_files.includes("CHANGELOG.md")) {
|
||||
warn("Please include an updated `CHANGELOG.md` file.<br>This way we can keep track of all the contributions.")
|
||||
warn("Please include an updated `CHANGELOG.md` file.<br>This way we can keep track of all the contributions.");
|
||||
}
|
||||
|
||||
// Check if the PR request is send to the master branch.
|
||||
@@ -12,6 +12,6 @@ if (danger.github.pr.base.ref === "master" && danger.github.pr.user.login !== "M
|
||||
// Check if the PR body or title includes the text: #accepted.
|
||||
// If not, the PR will fail.
|
||||
if ((danger.github.pr.body + danger.github.pr.title).includes("#accepted")) {
|
||||
fail("Please send all your pull requests to the `develop` branch.<br>Pull requests on the `master` branch will not be accepted.")
|
||||
fail("Please send all your pull requests to the `develop` branch.<br>Pull requests on the `master` branch will not be accepted.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
installers/dumpactivemodules.js
Normal file
15
installers/dumpactivemodules.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const config = require('../config/config.js');const fs=require('fs');
|
||||
for(let m of config.modules){
|
||||
if(!(m.disabled || false)){
|
||||
try {
|
||||
let f=fs.statSync(m.module);
|
||||
if(f.isDirectory()){
|
||||
f1=fs.statSync(m.module+'/package.json');
|
||||
if (f1.isFile()){
|
||||
console.log(m.module);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ex) {}
|
||||
}
|
||||
}
|
183
installers/fixuppm2.sh
Executable file
183
installers/fixuppm2.sh
Executable file
@@ -0,0 +1,183 @@
|
||||
#!/bin/bash
|
||||
# Define the tested version of Node.js.
|
||||
NODE_TESTED="v10.1.0"
|
||||
NPM_TESTED="V6.0.0"
|
||||
USER=`whoami`
|
||||
PM2_FILE=pm2_MagicMirror.json
|
||||
mac=$(uname -s)
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
cmd=greadlink
|
||||
else
|
||||
cmd=readlink
|
||||
fi
|
||||
|
||||
if [ -d ~/MagicMirror ]; then
|
||||
# put the log where the script is located
|
||||
logdir=$(dirname $($cmd -f "$0"))
|
||||
# if the script was execute from the web
|
||||
if [[ $logdir != *"MagicMirror/installers"* ]]; then
|
||||
# use the MagicMirror/installers folder
|
||||
cd ~/MagicMirror/installers >/dev/null
|
||||
logdir=$(pwd)
|
||||
cd - >/dev/null
|
||||
fi
|
||||
logfile=$logdir/pm2_setup.log
|
||||
echo the log will be saved in $logfile
|
||||
date +"pm2 setup starting - %a %b %e %H:%M:%S %Z %Y" >>$logfile
|
||||
echo system is $(uname -a) >> $logfile
|
||||
if [ "$mac" == "Darwin" ]; then
|
||||
echo the os is macOS $(sw_vers -productVersion) >> $logfile
|
||||
else
|
||||
echo the os is $(lsb_release -a 2>/dev/null) >> $logfile
|
||||
fi
|
||||
node_installed=$(which node)
|
||||
if [ "$node_installed." == "." ]; then
|
||||
# node not installed
|
||||
echo Installing node >>$logfile
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
brew install node
|
||||
else
|
||||
NODE_STABLE_BRANCH="10.x"
|
||||
curl -sL https://deb.nodesource.com/setup_$NODE_STABLE_BRANCH | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
fi
|
||||
fi
|
||||
node_version=$(node -v)
|
||||
echo node version $node_version >>$logfile
|
||||
npm_installed=$(which npm)
|
||||
if [ "$npm_installed." == "." ]; then
|
||||
# npm not installed
|
||||
echo Installing npm >>$logfile
|
||||
if [ $mac != 'Darwin' ]; then
|
||||
sudo apt-get install -y npm
|
||||
fi
|
||||
fi
|
||||
# get latest
|
||||
echo force installing latest npm version via npm >>$logfile
|
||||
#sudo npm i -g npm
|
||||
npm_version=$(npm -v)
|
||||
echo npm version $npm_version >>$logfile
|
||||
# assume pm2 will be found on the path
|
||||
pm2cmd=pm2
|
||||
up=""
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
up="--unsafe-perm"
|
||||
launchctl=launchctl
|
||||
launchctl_path=$(which $launchctl)
|
||||
`export PATH=$PATH:${launchctl_path%/$launchctl}`
|
||||
fi
|
||||
# check to see if already installed
|
||||
pm2_installed=$(which $pm2cmd)
|
||||
if [ "$pm2_installed." != "." ]; then
|
||||
# does it work?
|
||||
echo pm2 installed >> $logfile
|
||||
pm2_fails=$(pm2 list | grep -i -m 1 "App Name" | wc -l )
|
||||
if [ $pm2_fails != 1 ]; then
|
||||
# uninstall it
|
||||
echo pm2 installed, but does not work, uninstalling >> $logfile
|
||||
sudo npm uninstall $up -g pm2
|
||||
# force reinstall
|
||||
pm2_installed=
|
||||
fi
|
||||
fi
|
||||
# in not installed
|
||||
if [ "$pm2_installed." == "." ]; then
|
||||
# install it.
|
||||
echo pm2 not installed, installing >>$logfile
|
||||
result=$(sudo npm install $up -g pm2)
|
||||
# if this is a mac
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
echo this is a mac, fixup for path >>$logfile
|
||||
# get the location of pm2 install
|
||||
# parse the npm install output to get the command
|
||||
pm2cmd=`echo $result | awk -F - '{print $1}' | tr -d '[:space:]'`
|
||||
c='/pm2'
|
||||
# get the path only
|
||||
echo ${pm2cmd%$c} >installers/pm2path
|
||||
fi
|
||||
fi
|
||||
# remove MagicMirror if defined
|
||||
$pm2cmd delete MagicMirror >/dev/null 2>&1
|
||||
cd ~/MagicMirror
|
||||
echo get the pm2 platform specific startup command >>$logfile
|
||||
# get the platform specific pm2 startup command
|
||||
v=$($pm2cmd startup | tail -n 1)
|
||||
if [ $mac != 'Darwin' ]; then
|
||||
# check to see if we can get the OS package name (Ubuntu)
|
||||
if [ $(which lsb_release| wc -l) >0 ]; then
|
||||
# fix command
|
||||
# if ubuntu 18.04, pm2 startup gets something wrong
|
||||
if [ $(lsb_release -r | grep -m1 18.04 | wc -l) > 0 ]; then
|
||||
v=$(echo $v | sed 's/\/bin/\/bin:\/bin/')
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo startup command = $v >>$logfile
|
||||
# execute the command returned
|
||||
$v 2>&1 >>$logfile
|
||||
echo pm2 startup command done >>$logfile
|
||||
# is this is mac
|
||||
# need to fix pm2 startup, only on catalina
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
if [ $(sw_vers -productVersion | head -c 6) == '10.15.' ]; then
|
||||
# only do if the faulty tag is present (pm2 may fix this, before the script is fixed)
|
||||
if [ $(grep -m 1 UserName /Users/$USER/Library/LaunchAgents/pm2.$USER.plist | wc -l) -eq 1 ]; then
|
||||
# copy the pm2 startup file config
|
||||
cp /Users/$USER/Library/LaunchAgents/pm2.$USER.plist .
|
||||
# edit out the UserName key/value strings
|
||||
sed -e '/UserName/{N;d;}' pm2.$USER.plist > pm2.$USER.plist.new
|
||||
# copy the file back
|
||||
sudo cp pm2.$USER.plist.new /Users/$USER/Library/LaunchAgents/pm2.$USER.plist
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# if the user is no pi, we have to fixup the pm2 json file
|
||||
echo configure the pm2 config file for MagicMirror >>$logfile
|
||||
if [ "$USER" != "pi" ]; then
|
||||
echo the user is not pi >>$logfile
|
||||
# go to the installers folder`
|
||||
cd installers
|
||||
# edit the startup script for the right user
|
||||
echo change mm.sh >>$logfile
|
||||
if [ ! -e mm_temp.sh ]; then
|
||||
echo save copy of mm.sh >> $logfile
|
||||
cp mm.sh mm_temp.sh
|
||||
fi
|
||||
if [ $(grep pi mm_temp.sh | wc -l) -gt 0 ]; then
|
||||
echo change hard coded pi username >> $logfile
|
||||
sed 's/pi/'$USER'/g' mm_temp.sh >mm.sh
|
||||
else
|
||||
echo change relative home path to hard coded path >> $logfile
|
||||
hf=$(echo $HOME |sed 's/\//\\\//g')
|
||||
sed 's/\~/'$hf'/g' mm_temp.sh >mm.sh
|
||||
fi
|
||||
# edit the pms config file for the right user
|
||||
echo change $PM2_FILE >>$logfile
|
||||
sed 's/pi/'$USER'/g' $PM2_FILE > pm2_MagicMirror_new.json
|
||||
# make sure to use the updated file
|
||||
PM2_FILE=pm2_MagicMirror_new.json
|
||||
# if this is a mac
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
# copy the path file to the system paths list
|
||||
sudo cp ./pm2path /etc/paths.d
|
||||
# change the name of the home path for mac
|
||||
sed 's/home/Users/g' $PM2_FILE > pm2_MagicMirror_new1.json
|
||||
# make sure to use the updated file
|
||||
PM2_FILE=pm2_MagicMirror_new1.json
|
||||
fi
|
||||
echo now using this config file $PM2_FILE >>$logfile
|
||||
# go back one cd level
|
||||
cd - >/dev/null
|
||||
fi
|
||||
echo start MagicMirror via pm2 now >>$logfile
|
||||
# tell pm2 to start the app defined in the config file
|
||||
$pm2cmd start $HOME/MagicMirror/installers/$PM2_FILE
|
||||
# tell pm2 to save that configuration, for start at boot
|
||||
echo save MagicMirror pm2 config now >>$logfile
|
||||
$pm2cmd save
|
||||
date +"pm2 setup completed - %a %b %e %H:%M:%S %Z %Y" >>$logfile
|
||||
else
|
||||
echo It appears MagicMirror has not been installed on this system
|
||||
echo please run the installer, "raspberry.sh" first
|
||||
fi
|
568
installers/raspberry.sh
Normal file → Executable file
568
installers/raspberry.sh
Normal file → Executable file
@@ -1,9 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#!/bin/bash
|
||||
# This is an installer script for MagicMirror2. It works well enough
|
||||
# that it can detect if you have Node installed, run a binary script
|
||||
# and then download and run MagicMirror2.
|
||||
|
||||
if [ $USER == 'root' ]; then
|
||||
echo Please logon as a user to execute the MagicMirror installation, not root
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "\e[0m"
|
||||
echo '$$\ $$\ $$\ $$\ $$\ $$\ $$$$$$\'
|
||||
echo '$$$\ $$$ | \__| $$$\ $$$ |\__| $$ __$$\'
|
||||
@@ -18,156 +22,548 @@ echo ' \$$$$$$ |'
|
||||
echo ' \______/'
|
||||
echo -e "\e[0m"
|
||||
|
||||
doInstall=1
|
||||
true=1
|
||||
false=0
|
||||
# Define the tested version of Node.js.
|
||||
NODE_TESTED="v5.1.0"
|
||||
NODE_TESTED="v10.1.0"
|
||||
NPM_TESTED="V6.0.0"
|
||||
USER=`whoami`
|
||||
PM2_FILE=pm2_MagicMirror.json
|
||||
force_arch=
|
||||
pm2setup=$false
|
||||
|
||||
trim() {
|
||||
local var="$*"
|
||||
# remove leading whitespace characters
|
||||
var="${var#"${var%%[![:space:]]*}"}"
|
||||
# remove trailing whitespace characters
|
||||
var="${var%"${var##*[![:space:]]}"}"
|
||||
echo -n "$var"
|
||||
}
|
||||
|
||||
|
||||
|
||||
mac=$(uname -s)
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
echo this is a mac | tee -a $logfile
|
||||
cmd=greadlink
|
||||
else
|
||||
cmd=readlink
|
||||
fi
|
||||
|
||||
|
||||
# put the log where the script is located
|
||||
logdir=$(dirname $($cmd -f "$0"))
|
||||
# if the script was execute from the web
|
||||
if [[ $logdir != *"MagicMirror/installers"* ]]; then
|
||||
# use the MagicMirror/installers folder, if setup
|
||||
if [ -d MagicMirror ]; then
|
||||
cd ~/MagicMirror/installers >/dev/null
|
||||
logdir=$(pwd)
|
||||
cd - >/dev/null
|
||||
else
|
||||
# use the users home folder if initial install
|
||||
logdir=$HOME
|
||||
fi
|
||||
fi
|
||||
logfile=$logdir/install.log
|
||||
echo install log being saved to $logfile
|
||||
|
||||
# Determine which Pi is running.
|
||||
ARM=$(uname -m)
|
||||
|
||||
date +"install starting - %a %b %e %H:%M:%S %Z %Y" >>$logfile
|
||||
ARM=$(uname -m)
|
||||
echo installing on $ARM processor system >>$logfile
|
||||
echo the os is $(lsb_release -a 2>/dev/null) >> $logfile
|
||||
# Check the Raspberry Pi version.
|
||||
if [ "$ARM" != "armv7l" ]; then
|
||||
echo -e "\e[91mSorry, your Raspberry Pi is not supported."
|
||||
echo -e "\e[91mPlease run MagicMirror on a Raspberry Pi 2 or 3."
|
||||
echo -e "\e[91mIf this is a Pi Zero, you are in the same boat as the original Raspberry Pi. You must run in server only mode."
|
||||
exit;
|
||||
read -p "this appears not to be a Raspberry Pi 2 or 3, do you want to continue installation (y/N)?" choice
|
||||
if [[ $choice =~ ^[Nn]$ ]]; then
|
||||
echo user stopped install on $ARM hardware >>$logfile
|
||||
echo -e "\e[91mSorry, your Raspberry Pi is not supported."
|
||||
echo -e "\e[91mPlease run MagicMirror on a Raspberry Pi 2 or 3."
|
||||
echo -e "\e[91mIf this is a Pi Zero, the setup will configure to run in server only mode wih a local browser."
|
||||
exit;
|
||||
fi
|
||||
#if [ "$ARM" == "armv6l" ]; then
|
||||
# echo forcing armv71 architecture for pi 0 >>$logfile
|
||||
# force_arch=-'--arch=armv7l'
|
||||
# fi
|
||||
fi
|
||||
|
||||
# Define helper methods.
|
||||
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
|
||||
function command_exists () { type "$1" &> /dev/null ;}
|
||||
function verlte() { [ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ];}
|
||||
function verlt() { [ "$1" = "$2" ] && return 1 || verlte $1 $2 ;}
|
||||
|
||||
# Update before first apt-get
|
||||
echo -e "\e[96mUpdating packages ...\e[90m"
|
||||
sudo apt-get update || echo -e "\e[91mUpdate failed, carrying on installation ...\e[90m"
|
||||
if [ $mac != 'Darwin' ]; then
|
||||
echo -e "\e[96mUpdating packages ...\e[90m" | tee -a $logfile
|
||||
upgrade=$false
|
||||
update=$(sudo apt-get update 2>&1)
|
||||
echo $update >> $logfile
|
||||
update_rc=$?
|
||||
if [ $update_rc -ne 0 ]; then
|
||||
echo -e "\e[91mUpdate failed, retrying installation ...\e[90m" | tee -a $logfile
|
||||
if [ $(echo $update | grep "apt-secure" | wc -l) -eq 1 ]; then
|
||||
update=$(sudo apt-get update --allow-releaseinfo-change 2>&1)
|
||||
update_rc=$?
|
||||
echo $update >> $logfile
|
||||
if [ $update_rc -ne 0 ]; then
|
||||
echo "second apt-get update failed" $update | tee -a $logfile
|
||||
exit 1
|
||||
else
|
||||
echo "second apt-get update completed ok" >> $logfile
|
||||
upgrade=$true
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "apt-get update completed ok" >> $logfile
|
||||
upgrade=$true
|
||||
fi
|
||||
if [ $upgrade -eq $true ]; then
|
||||
upgrade_result=$(sudo apt-get upgrade 2>&1)
|
||||
upgrade_rc=$?
|
||||
echo apt upgrade result ="rc=$upgrade_rc $upgrade_result" >> $logfile
|
||||
fi
|
||||
|
||||
# Installing helper tools
|
||||
echo -e "\e[96mInstalling helper tools ...\e[90m"
|
||||
sudo apt-get --assume-yes install curl wget git build-essential unzip || exit
|
||||
# Installing helper tools
|
||||
echo -e "\e[96mInstalling helper tools ...\e[90m" | tee -a $logfile
|
||||
sudo apt-get --assume-yes install curl wget git build-essential unzip || exit
|
||||
fi
|
||||
|
||||
# Check if we need to install or upgrade Node.js.
|
||||
echo -e "\e[96mCheck current Node installation ...\e[0m"
|
||||
echo -e "\e[96mCheck current Node installation ...\e[0m" | tee -a $logfile
|
||||
NODE_INSTALL=false
|
||||
if command_exists node && command_exists npm; then
|
||||
echo -e "\e[0mNode currently installed. Checking version number.";
|
||||
if command_exists node; then
|
||||
echo -e "\e[0mNode currently installed. Checking version number." | tee -a $logfile
|
||||
NODE_CURRENT=$(node -v)
|
||||
echo -e "\e[0mMinimum Node version: \e[1m$NODE_TESTED\e[0m"
|
||||
echo -e "\e[0mInstalled Node version: \e[1m$NODE_CURRENT\e[0m"
|
||||
if version_gt $NODE_TESTED $NODE_CURRENT; then
|
||||
echo -e "\e[96mNode should be upgraded.\e[0m"
|
||||
if [ "$NODE_CURRENT." == "." ]; then
|
||||
NODE_CURRENT="V1.0.0"
|
||||
echo forcing low Node version >> $logfile
|
||||
fi
|
||||
echo -e "\e[0mMinimum Node version: \e[1m$NODE_TESTED\e[0m" | tee -a $logfile
|
||||
echo -e "\e[0mInstalled Node version: \e[1m$NODE_CURRENT\e[0m" | tee -a $logfile
|
||||
if verlte $NODE_CURRENT $NODE_TESTED; then
|
||||
echo -e "\e[96mNode should be upgraded.\e[0m" | tee -a $logfile
|
||||
NODE_INSTALL=true
|
||||
|
||||
# Check if a node process is currenlty running.
|
||||
# If so abort installation.
|
||||
if pgrep "node" > /dev/null; then
|
||||
echo -e "\e[91mA Node process is currently running. Can't upgrade."
|
||||
echo "Please quit all Node processes and restart the installer."
|
||||
echo -e "\e[91mA Node process is currently running. Can't upgrade." | tee -a $logfile
|
||||
echo "Please quit all Node processes and restart the installer." | tee -a $logfile
|
||||
echo $(ps -ef | grep node | grep -v \-\-color) | tee -a $logfile
|
||||
exit;
|
||||
fi
|
||||
|
||||
else
|
||||
echo -e "\e[92mNo Node.js upgrade necessary.\e[0m"
|
||||
echo -e "\e[92mNo Node.js upgrade necessary.\e[0m" | tee -a $logfile
|
||||
fi
|
||||
|
||||
else
|
||||
echo -e "\e[93mNode.js is not installed.\e[0m";
|
||||
echo -e "\e[93mNode.js is not installed.\e[0m" | tee -a $logfile
|
||||
NODE_INSTALL=true
|
||||
fi
|
||||
|
||||
# Install or upgrade node if necessary.
|
||||
if $NODE_INSTALL; then
|
||||
|
||||
echo -e "\e[96mInstalling Node.js ...\e[90m"
|
||||
|
||||
echo -e "\e[96mInstalling Node.js ...\e[90m" | tee -a $logfile
|
||||
|
||||
# Fetch the latest version of Node.js from the selected branch
|
||||
# The NODE_STABLE_BRANCH variable will need to be manually adjusted when a new branch is released. (e.g. 7.x)
|
||||
# Only tested (stable) versions are recommended as newer versions could break MagicMirror.
|
||||
|
||||
NODE_STABLE_BRANCH="10.x"
|
||||
curl -sL https://deb.nodesource.com/setup_$NODE_STABLE_BRANCH | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
echo -e "\e[92mNode.js installation Done!\e[0m"
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
brew install node
|
||||
else
|
||||
NODE_STABLE_BRANCH="10.x"
|
||||
# sudo apt-get install --only-upgrade libstdc++6
|
||||
node_info=$(curl -sL https://deb.nodesource.com/setup_$NODE_STABLE_BRANCH | sudo -E bash - )
|
||||
echo Node release info = $node_info >> $logfile
|
||||
if [ "$(echo $node_info | grep "not currently supported")." == "." ]; then
|
||||
sudo apt-get install -y nodejs
|
||||
else
|
||||
echo node $NODE_STABLE_BRANCH version installer not available, doing manually >>$logfile
|
||||
# no longer supported install
|
||||
sudo apt-get install -y --only-upgrade libstdc++6 >> $logfile
|
||||
# have to do it manually
|
||||
node_vnum=$(echo $NODE_STABLE_BRANCH | awk -F. '{print $1}')
|
||||
# get the highest release number in the stable branch line for this processor architecture
|
||||
node_ver=$(curl -sL https://unofficial-builds.nodejs.org/download/release/index.tab | grep $ARM | grep -m 1 v$node_vnum | awk '{print $1}')
|
||||
echo latest release in the $NODE_STABLE_BRANCH family for $ARM is $node_ver >> $logfile
|
||||
curl -sL https://unofficial-builds.nodejs.org/download/release/$node_ver/node-$node_ver-linux-$ARM.tar.gz >node_release-$node_ver.tar.gz
|
||||
cd /usr/local
|
||||
echo using release tar file = node_release-$node_ver.tar.gz >> $logfile
|
||||
sudo tar --strip-components 1 -xzf $HOME/node_release-$node_ver.tar.gz
|
||||
cd - >/dev/null
|
||||
rm ./node_release-$node_ver.tar.gz
|
||||
fi
|
||||
# get the new node version number
|
||||
new_ver=$(node -v 2>&1)
|
||||
# if there is a failure to get it due to a missing library
|
||||
if [ $(echo $new_ver | grep "not found" | wc -l) -ne 0 ]; then
|
||||
#
|
||||
sudo apt-get install -y --only-upgrade libstdc++6 >> $logfile
|
||||
fi
|
||||
echo node version is $(node -v 2>&1 >>$logfile)
|
||||
fi
|
||||
echo -e "\e[92mNode.js installation Done! version=$(node -v)\e[0m" | tee -a $logfile
|
||||
fi
|
||||
# Check if we need to install or upgrade npm.
|
||||
echo -e "\e[96mCheck current NPM installation ...\e[0m" | tee -a $logfile
|
||||
NPM_INSTALL=false
|
||||
if command_exists npm; then
|
||||
echo -e "\e[0mNPM currently installed. Checking version number." | tee -a $logfile
|
||||
NPM_CURRENT='V'$(npm -v)
|
||||
echo -e "\e[0mMinimum npm version: \e[1m$NPM_TESTED\e[0m" | tee -a $logfile
|
||||
echo -e "\e[0mInstalled npm version: \e[1m$NPM_CURRENT\e[0m" | tee -a $logfile
|
||||
if verlte $NPM_CURRENT $NPM_TESTED; then
|
||||
echo -e "\e[96mnpm should be upgraded.\e[0m" | tee -a $logfile
|
||||
NPM_INSTALL=true
|
||||
|
||||
# Check if a node process is currently running.
|
||||
# If so abort installation.
|
||||
if pgrep "npm" > /dev/null; then
|
||||
echo -e "\e[91mA npm process is currently running. Can't upgrade." | tee -a $logfile
|
||||
echo "Please quit all npm processes and restart the installer." | tee -a $logfile
|
||||
exit;
|
||||
fi
|
||||
|
||||
else
|
||||
echo -e "\e[92mNo npm upgrade necessary.\e[0m" | tee -a $logfile
|
||||
fi
|
||||
|
||||
else
|
||||
echo -e "\e[93mnpm is not installed.\e[0m" | tee -a $logfile
|
||||
NPM_INSTALL=true
|
||||
fi
|
||||
|
||||
# Install or upgrade node if necessary.
|
||||
if $NPM_INSTALL; then
|
||||
|
||||
echo -e "\e[96mInstalling npm ...\e[90m" | tee -a $logfile
|
||||
|
||||
# Fetch the latest version of npm from the selected branch
|
||||
# The NODE_STABLE_BRANCH variable will need to be manually adjusted when a new branch is released. (e.g. 7.x)
|
||||
# Only tested (stable) versions are recommended as newer versions could break MagicMirror.
|
||||
|
||||
#NODE_STABLE_BRANCH="9.x"
|
||||
#curl -sL https://deb.nodesource.com/setup_$NODE_STABLE_BRANCH | sudo -E bash -
|
||||
#
|
||||
# if this is a mac, npm was installed with node
|
||||
if [ $mac != 'Darwin' ]; then
|
||||
sudo apt-get install -y npm >>$logfile
|
||||
fi
|
||||
# update to the latest.
|
||||
echo upgrading npm to latest >> $logfile
|
||||
sudo npm i -g npm >>$logfile
|
||||
echo -e "\e[92mnpm installation Done! version=V$(npm -v)\e[0m" | tee -a $logfile
|
||||
fi
|
||||
|
||||
# Install MagicMirror
|
||||
cd ~
|
||||
if [ -d "$HOME/MagicMirror" ] ; then
|
||||
echo -e "\e[93mIt seems like MagicMirror is already installed."
|
||||
echo -e "To prevent overwriting, the installer will be aborted."
|
||||
echo -e "Please rename the \e[1m~/MagicMirror\e[0m\e[93m folder and try again.\e[0m"
|
||||
echo ""
|
||||
echo -e "If you want to upgrade your installation run \e[1m\e[97mgit pull\e[0m from the ~/MagicMirror directory."
|
||||
echo ""
|
||||
exit;
|
||||
if [ $doInstall == 1 ]; then
|
||||
if [ -d "$HOME/MagicMirror" ] ; then
|
||||
echo -e "\e[93mIt seems like MagicMirror is already installed." | tee -a $logfile
|
||||
echo -e "To prevent overwriting, the installer will be aborted." | tee -a $logfile
|
||||
echo -e "Please rename the \e[1m~/MagicMirror\e[0m\e[93m folder and try again.\e[0m" | tee -a $logfile
|
||||
echo ""
|
||||
echo -e "If you want to upgrade your installation run \e[1m\e[97mupgrade-script\e[0m from the ~/MagicMirror/installers directory." | tee -a $logfile
|
||||
echo ""
|
||||
exit;
|
||||
fi
|
||||
|
||||
echo -e "\e[96mCloning MagicMirror ...\e[90m" | tee -a $logfile
|
||||
if git clone --depth=1 https://github.com/MichMich/MagicMirror.git; then
|
||||
echo -e "\e[92mCloning MagicMirror Done!\e[0m" | tee -a $logfile
|
||||
else
|
||||
echo -e "\e[91mUnable to clone MagicMirror." | tee -a $logfile
|
||||
exit;
|
||||
fi
|
||||
|
||||
cd ~/MagicMirror || exit
|
||||
if [ $(grep version package.json | awk -F: '{print $2}') == '"2.9.0",' -a $ARM == 'armv6l' ]; then
|
||||
git fetch https://github.com/MichMich/MagicMirror.git develop >/dev/null 2>&1
|
||||
git branch develop FETCH_HEAD > /dev/null 2>&1
|
||||
git checkout develop > /dev/null 2>&1
|
||||
fi
|
||||
echo -e "\e[96mInstalling dependencies ...\e[90m" | tee -a $logfile
|
||||
if npm install $force_arch; then
|
||||
echo -e "\e[92mDependencies installation Done!\e[0m" | tee -a $logfile
|
||||
else
|
||||
echo -e "\e[91mUnable to install dependencies!" | tee -a $logfile
|
||||
exit;
|
||||
fi
|
||||
|
||||
# Use sample config for start MagicMirror
|
||||
echo setting up initial config.js | tee -a $logfile
|
||||
cp config/config.js.sample config/config.js
|
||||
fi
|
||||
|
||||
echo -e "\e[96mCloning MagicMirror ...\e[90m"
|
||||
if git clone --depth=1 https://github.com/MichMich/MagicMirror.git; then
|
||||
echo -e "\e[92mCloning MagicMirror Done!\e[0m"
|
||||
else
|
||||
echo -e "\e[91mUnable to clone MagicMirror."
|
||||
exit;
|
||||
fi
|
||||
|
||||
cd ~/MagicMirror || exit
|
||||
echo -e "\e[96mInstalling dependencies ...\e[90m"
|
||||
if npm install; then
|
||||
echo -e "\e[92mDependencies installation Done!\e[0m"
|
||||
else
|
||||
echo -e "\e[91mUnable to install dependencies!"
|
||||
exit;
|
||||
fi
|
||||
|
||||
# Use sample config for start MagicMirror
|
||||
cp config/config.js.sample config/config.js
|
||||
|
||||
# Check if plymouth is installed (default with PIXEL desktop environment), then install custom splashscreen.
|
||||
echo -e "\e[96mCheck plymouth installation ...\e[0m"
|
||||
echo -e "\e[96mCheck plymouth installation ...\e[0m" | tee -a $logfile
|
||||
if command_exists plymouth; then
|
||||
THEME_DIR="/usr/share/plymouth/themes"
|
||||
echo -e "\e[90mSplashscreen: Checking themes directory.\e[0m"
|
||||
echo -e "\e[90mSplashscreen: Checking themes directory.\e[0m" | tee -a $logfile
|
||||
if [ -d $THEME_DIR ]; then
|
||||
echo -e "\e[90mSplashscreen: Create theme directory if not exists.\e[0m"
|
||||
echo -e "\e[90mSplashscreen: Create theme directory if not exists.\e[0m" | tee -a $logfile
|
||||
if [ ! -d $THEME_DIR/MagicMirror ]; then
|
||||
sudo mkdir $THEME_DIR/MagicMirror
|
||||
fi
|
||||
|
||||
if sudo cp ~/MagicMirror/splashscreen/splash.png $THEME_DIR/MagicMirror/splash.png && sudo cp ~/MagicMirror/splashscreen/MagicMirror.plymouth $THEME_DIR/MagicMirror/MagicMirror.plymouth && sudo cp ~/MagicMirror/splashscreen/MagicMirror.script $THEME_DIR/MagicMirror/MagicMirror.script; then
|
||||
echo -e "\e[90mSplashscreen: Theme copied successfully.\e[0m"
|
||||
if sudo plymouth-set-default-theme -R MagicMirror; then
|
||||
echo -e "\e[92mSplashscreen: Changed theme to MagicMirror successfully.\e[0m"
|
||||
else
|
||||
echo -e "\e[91mSplashscreen: Couldn't change theme to MagicMirror!\e[0m"
|
||||
echo
|
||||
if [ "$(which plymouth-set-default-theme)." != "." ]; then
|
||||
if sudo plymouth-set-default-theme -R MagicMirror; then
|
||||
echo -e "\e[92mSplashscreen: Changed theme to MagicMirror successfully.\e[0m" | tee -a $logfile
|
||||
else
|
||||
echo -e "\e[91mSplashscreen: Couldn't change theme to MagicMirror!\e[0m" | tee -a $logfile
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo -e "\e[91mSplashscreen: Copying theme failed!\e[0m"
|
||||
echo -e "\e[91mSplashscreen: Copying theme failed!\e[0m" | tee -a $logfile
|
||||
fi
|
||||
else
|
||||
echo -e "\e[91mSplashscreen: Themes folder doesn't exist!\e[0m"
|
||||
echo -e "\e[91mSplashscreen: Themes folder doesn't exist!\e[0m" | tee -a $logfile
|
||||
fi
|
||||
else
|
||||
echo -e "\e[93mplymouth is not installed.\e[0m";
|
||||
echo -e "\e[93mplymouth is not installed.\e[0m" | tee -a $logfile
|
||||
fi
|
||||
|
||||
# Use pm2 control like a service MagicMirror
|
||||
read -p "Do you want use pm2 for auto starting of your MagicMirror (y/N)?" choice
|
||||
if [[ $choice =~ ^[Yy]$ ]]; then
|
||||
sudo npm install -g pm2
|
||||
if [[ "$(ps --no-headers -o comm 1)" =~ systemd ]]; then #Checking for systemd
|
||||
sudo pm2 startup systemd -u pi --hp /home/pi
|
||||
else
|
||||
sudo su -c "env PATH=$PATH:/usr/bin pm2 startup linux -u pi --hp /home/pi"
|
||||
fi
|
||||
pm2 start ~/MagicMirror/installers/pm2_MagicMirror.json
|
||||
pm2 save
|
||||
echo install and setup pm2 | tee -a $logfile
|
||||
# assume pm2 will be found on the path
|
||||
pm2cmd=pm2
|
||||
# check to see if already installed
|
||||
pm2_installed=$(which $pm2cmd)
|
||||
up=""
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
up="--unsafe-perm"
|
||||
launchctl=launchctl
|
||||
launchctl_path=$(which $launchctl)
|
||||
`export PATH=$PATH:${launchctl_path%/$launchctl}`
|
||||
fi
|
||||
# check to see if already installed
|
||||
pm2_installed=$(which $pm2cmd)
|
||||
if [ "$pm2_installed." != "." ]; then
|
||||
# does it work?
|
||||
pm2_fails=$(pm2 list | grep -i -m 1 "App Name" | wc -l )
|
||||
if [ $pm2_fails != 1 ]; then
|
||||
# uninstall it
|
||||
echo pm2 installed, but does not work, uninstalling >> $logfile
|
||||
sudo npm uninstall $up -g pm2 >> $logfile
|
||||
# force reinstall
|
||||
pm2_installed=
|
||||
fi
|
||||
fi
|
||||
# if not installed
|
||||
if [ "$pm2_installed." == "." ]; then
|
||||
# install it.
|
||||
echo pm2 not installed, installing >>$logfile
|
||||
result=$(sudo npm install $up -g pm2 2>&1)
|
||||
echo pm2 install result $result >>$logfile
|
||||
# if this is a mac
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
echo this is a mac, fixup for path >>$logfile
|
||||
# get the location of pm2 install
|
||||
# parse the npm install output to get the command
|
||||
pm2cmd=`echo $result | awk -F - '{print $1}' | tr -d '[:space:]'`
|
||||
c='/pm2'
|
||||
# get the path only
|
||||
echo ${pm2cmd%$c} >installers/pm2path
|
||||
fi
|
||||
fi
|
||||
echo get the pm2 platform specific startup command >>$logfile
|
||||
# get the platform specific pm2 startup command
|
||||
v=$($pm2cmd startup | tail -n 1)
|
||||
if [ $mac != 'Darwin' ]; then
|
||||
# check to see if we can get the OS package name (Ubuntu)
|
||||
if [ $(which lsb_release| wc -l) >0 ]; then
|
||||
# fix command
|
||||
# if ubuntu 18.04, pm2 startup gets something wrong
|
||||
if [ $(lsb_release -r | grep -m1 18.04 | wc -l) > 0 ]; then
|
||||
v=$(echo $v | sed 's/\/bin/\/bin:\/bin/')
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo startup command = $v >>$logfile
|
||||
# execute the command returned
|
||||
$v 2>&1 >>$logfile
|
||||
echo pm2 startup command done >>$logfile
|
||||
# is this is mac
|
||||
# need to fix pm2 startup, only on catalina
|
||||
if [ $mac == 'Darwin' ];then
|
||||
if [ $(sw_vers -productVersion | head -c 6) == '10.15.' ]; then
|
||||
# only do if the faulty tag is present (pm2 may fix this, before the script is fixed)
|
||||
if [ $(grep -m 1 UserName /Users/$USER/Library/LaunchAgents/pm2.$USER.plist | wc -l) -eq 1 ]; then
|
||||
# copy the pm2 startup file config
|
||||
cp /Users/$USER/Library/LaunchAgents/pm2.$USER.plist .
|
||||
# edit out the UserName key/value strings
|
||||
sed -e '/UserName/{N;d;}' pm2.$USER.plist > pm2.$USER.plist.new
|
||||
# copy the file back
|
||||
sudo cp pm2.$USER.plist.new /Users/$USER/Library/LaunchAgents/pm2.$USER.plist
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# if the user is no pi, we have to fixup the pm2 json file
|
||||
echo configure the pm2 config file for MagicMirror >>$logfile
|
||||
if [ "$USER" != "pi" ]; then
|
||||
echo the user is not pi >>$logfile
|
||||
# go to the installers folder`
|
||||
cd installers
|
||||
# edit the startup script for the right user
|
||||
echo change mm.sh >>$logfile
|
||||
if [ ! -e mm_temp.sh ]; then
|
||||
echo save copy of mm.sh >> $logfile
|
||||
cp mm.sh mm_temp.sh
|
||||
fi
|
||||
if [ $(grep pi mm_temp.sh | wc -l) -gt 0 ]; then
|
||||
echo change hard coded pi username >> $logfile
|
||||
sed 's/pi/'$USER'/g' mm_temp.sh >mm.sh
|
||||
else
|
||||
echo change relative home path to hard coded path >> $logfile
|
||||
hf=$(echo $HOME |sed 's/\//\\\//g')
|
||||
sed 's/\~/'$hf'/g' mm_temp.sh >mm.sh
|
||||
fi
|
||||
# edit the pms config file for the right user
|
||||
echo change $PM2_FILE >>$logfile
|
||||
sed 's/pi/'$USER'/g' $PM2_FILE > pm2_MagicMirror_new.json
|
||||
# make sure to use the updated file
|
||||
PM2_FILE=pm2_MagicMirror_new.json
|
||||
# if this is a mac
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
# copy the path file to the system paths list
|
||||
sudo cp ./pm2path /etc/paths.d
|
||||
# change the name of the home path for mac
|
||||
sed 's/home/Users/g' $PM2_FILE > pm2_MagicMirror_new1.json
|
||||
# make sure to use the updated file
|
||||
PM2_FILE=pm2_MagicMirror_new1.json
|
||||
fi
|
||||
echo now using this config file $PM2_FILE >>$logfile
|
||||
# go back one cd level
|
||||
cd - >/dev/null
|
||||
fi
|
||||
echo start MagicMirror via pm2 now >>$logfile
|
||||
# tell pm2 to start the app defined in the config file
|
||||
$pm2cmd start $HOME/MagicMirror/installers/$PM2_FILE
|
||||
# tell pm2 to save that configuration, for start at boot
|
||||
echo save MagicMirror pm2 config now >>$logfile
|
||||
$pm2cmd save
|
||||
pm2setup=$true
|
||||
fi
|
||||
# Disable Screensaver
|
||||
choice=n
|
||||
read -p "Do you want to disable the screen saver? (y/N)?" choice
|
||||
if [[ $choice =~ ^[Yy]$ ]]; then
|
||||
sudo su -c "echo -e '@xset s noblank\n@xset s off\n@xset -dpms' >> /etc/xdg/lxsession/LXDE-pi/autostart"
|
||||
export DISPLAY=:0; xset s noblank;xset s off;xset -dpms
|
||||
# if this is a mac
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
# get the current setting
|
||||
setting=$(defaults -currentHost read com.apple.screensaver idleTime)
|
||||
# if its on
|
||||
if [ $setting != 0 ] ; then
|
||||
# turn it off
|
||||
echo disable screensaver via mac profile >> $logfile
|
||||
defaults -currentHost write com.apple.screensaver idleTime 0
|
||||
else
|
||||
echo mac profile screen saver already disabled >> $logfile
|
||||
fi
|
||||
else
|
||||
# find out if some screen saver running
|
||||
|
||||
# get just the running processes and args
|
||||
# just want the program name (1st token)
|
||||
# find the 1st with 'saver' in it (should only be one)
|
||||
# parse with path char, get the last field ( the actual pgm name)
|
||||
|
||||
screen_saver_running=$(ps -A -o args | awk '{print $1}' | grep -m1 [s]aver | awk -F\/ '{print $NF}');
|
||||
|
||||
# if we found something
|
||||
if [ "$screen_saver_running." != "." ]; then
|
||||
# some screensaver running
|
||||
case "$screen_saver_running" in
|
||||
mate-screensaver) echo 'mate screen saver' >>$logfile
|
||||
#killall mate-screensaver >/dev/null 2>&1
|
||||
#$ms -d >/dev/null 2>&1
|
||||
gsettings set org.mate.screensaver lock-enabled false 2>/dev/null
|
||||
gsettings set org.mate.screensaver idle-activation-enabled false 2>/dev/null
|
||||
gsettings set org.mate.screensaver lock_delay 0 2>/dev/null
|
||||
echo " $screen_saver_running disabled" >> $logfile
|
||||
DISPLAY=:0 mate-screensaver >/dev/null 2>&1 &
|
||||
;;
|
||||
gnome-screensaver) echo 'gnome screen saver' >>$logfile
|
||||
gnome_screensaver-command -d >/dev/null 2>&1
|
||||
echo " $screen_saver_running disabled" >> $logfile
|
||||
;;
|
||||
xscreensaver) echo 'xscreensaver running' | tee -a $logfile
|
||||
if [ $(grep -m1 'mode:' ~/.xscreensaver | awk '{print $2}') != 'off' ]; then
|
||||
sed -i 's/$xsetting/mode: off/' ~/.xscreensaver
|
||||
echo " xscreensaver set to off" >> $logfile
|
||||
else
|
||||
echo " xscreensaver already disabled" >> $logfile
|
||||
fi
|
||||
;;
|
||||
gsd-screensaver | gsd-screensaver-proxy)
|
||||
setting=$(gsettings get org.gnome.desktop.screensaver lock-enabled)
|
||||
setting1=$(gsettings get org.gnome.desktop.session idle-delay)
|
||||
if [ "$setting $setting1" != 'false uint32 0' ]; then
|
||||
echo disable screensaver via gsettings was $setting and $setting1>> $logfile
|
||||
gsettings set org.gnome.desktop.screensaver lock-enabled false
|
||||
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
|
||||
gsettings set org.gnome.desktop.session idle-delay 0
|
||||
else
|
||||
echo gsettings screen saver already disabled >> $logfile
|
||||
fi
|
||||
;;
|
||||
*) echo "some other screensaver $screen_saver_running" found | tee -a $logfile
|
||||
echo "please configure it manually" | tee -a $logfile
|
||||
;;
|
||||
esac
|
||||
elif [ -e "/etc/lightdm/lightdm.conf" ]; then
|
||||
# if screen saver NOT already disabled?
|
||||
if [ $(grep 'xserver-command=X -s 0 -dpms' /etc/lightdm/lightdm.conf | wc -l) == 0 ]; then
|
||||
echo install screensaver via lightdm.conf >> $logfile
|
||||
sudo sed -i '/^\[Seat:\*\]/a xserver-command=X -s 0 -dpms' /etc/lightdm/lightdm.conf
|
||||
else
|
||||
echo screensaver via lightdm already disabled >> $logfile
|
||||
fi
|
||||
elif [ $(which gsettings | wc -l) == 1 ]; then
|
||||
setting=$(gsettings get org.gnome.desktop.screensaver lock-enabled)
|
||||
setting1=$(gsettings get org.gnome.desktop.session idle-delay)
|
||||
if [ "$setting $setting1" != 'false uint32 0' ]; then
|
||||
echo disable screensaver via gsettings was $setting and $setting1>> $logfile
|
||||
gsettings set org.gnome.desktop.screensaver lock-enabled false
|
||||
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
|
||||
gsettings set org.gnome.desktop.session idle-delay 0
|
||||
else
|
||||
echo gsettings screen saver already disabled >> $logfile
|
||||
fi
|
||||
elif [ -d "/etc/xdg/lxsession" ]; then
|
||||
currently_set=$(grep -m1 '\-dpms' /etc/xdg/lxsession/LXDE-pi/autostart)
|
||||
if [ "$currently_set." == "." ]; then
|
||||
echo disable screensaver via lxsession >> $logfile
|
||||
# turn it off for the future
|
||||
sudo su -c "echo -e '@xset s noblank\n@xset s off\n@xset -dpms' >> /etc/xdg/lxsession/LXDE-pi/autostart"
|
||||
# turn it off now
|
||||
export DISPLAY=:0; xset s noblank;xset s off;xset -dpms
|
||||
else
|
||||
echo lxsession screen saver already disabled >> $logfile
|
||||
fi
|
||||
else
|
||||
echo " "
|
||||
echo -e "unable to disable screen saver, /etc/xdg/lxsession does not exist" | tee -a $logfile
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo " "
|
||||
if [ $pm2setup -eq $true ]; then
|
||||
rmessage="pm2 start MagicMirror"
|
||||
else
|
||||
rmessage="DISPLAY=:0 npm start"
|
||||
fi
|
||||
echo -e "\e[92mWe're ready! Run \e[1m\e[97m$rmessage\e[0m\e[92m from the ~/MagicMirror directory to start your MagicMirror.\e[0m" | tee -a $logfile
|
||||
|
||||
echo " "
|
||||
echo -e "\e[92mWe're ready! Run \e[1m\e[97mDISPLAY=:0 npm start\e[0m\e[92m from the ~/MagicMirror directory to start your MagicMirror.\e[0m"
|
||||
echo " "
|
||||
echo " "
|
||||
|
||||
date +"install completed - %a %b %e %H:%M:%S %Z %Y" >>$logfile
|
||||
|
101
installers/screensaveroff.sh
Executable file
101
installers/screensaveroff.sh
Executable file
@@ -0,0 +1,101 @@
|
||||
#/bin/bash
|
||||
logfile=~/screensaver.log
|
||||
mac=$(uname -s)
|
||||
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
setting=$(defaults -currentHost read com.apple.screensaver idleTime)
|
||||
if [ $setting != 0 ] ; then
|
||||
echo disable screensaver via mac profile >> $logfile
|
||||
defaults -currentHost write com.apple.screensaver idleTime 0
|
||||
else
|
||||
echo mac profile screen saver already disabled >> $logfile
|
||||
fi
|
||||
else
|
||||
# find out if some screen saver running
|
||||
|
||||
# get just the running processes and args
|
||||
# just want the program name
|
||||
# find the 1st with 'saver' in it (should only be one)
|
||||
# if the process name is a path, parse it and get the last field ( the actual pgm name)
|
||||
|
||||
screen_saver_running=$(ps -A -o args | awk '{print $1}' | grep -m1 [s]aver | awk -F\/ '{print $NF}');
|
||||
|
||||
# if we found something
|
||||
if [ "$screen_saver_running." != "." ]; then
|
||||
# some screensaver running
|
||||
case "$screen_saver_running" in
|
||||
mate-screensaver) echo 'mate screen saver' >>$logfile
|
||||
#killall mate-screensaver >/dev/null 2>&1
|
||||
#ms=$(which mate-screensaver-command)
|
||||
#$ms -d >/dev/null 2>&1
|
||||
gsettings set org.mate.screensaver lock-enabled false 2>/dev/null
|
||||
gsettings set org.mate.screensaver idle-activation-enabled false 2>/dev/null
|
||||
gsettings set org.mate.screensaver lock_delay 0 2>/dev/null
|
||||
echo " $screen_saver_running disabled" >> $logfile
|
||||
DISPLAY=:0 mate-screensaver >/dev/null 2>&1 &
|
||||
;;
|
||||
gnome-screensaver) echo 'gnome screen saver' >>$logfile
|
||||
gnome_screensaver-command -d >/dev/null 2>&1
|
||||
echo " $screen_saver_running disabled" >> $logfile
|
||||
;;
|
||||
xscreensaver) echo 'xscreensaver running' | tee -a $logfile
|
||||
if [ $(grep -m1 'mode:' ~/.xscreensaver | awk '{print $2}') != 'off' ]; then
|
||||
sed -i 's/$xsetting/mode: off/' ~/.xscreensaver
|
||||
echo " xscreensaver set to off" >> $logfile
|
||||
else
|
||||
echo " xscreensaver already disabled" >> $logfile
|
||||
fi
|
||||
;;
|
||||
gsd-screensaver | gsd-screensaver-proxy)
|
||||
setting=$(gsettings get org.gnome.desktop.screensaver lock-enabled)
|
||||
setting1=$(gsettings get org.gnome.desktop.session idle-delay)
|
||||
if [ "$setting $setting1" != 'false uint32 0' ]; then
|
||||
echo disable screensaver via gsettings was $setting and $setting1>> $logfile
|
||||
gsettings set org.gnome.desktop.screensaver lock-enabled false
|
||||
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
|
||||
gsettings set org.gnome.desktop.session idle-delay 0
|
||||
else
|
||||
echo gsettings screen saver already disabled >> $logfile
|
||||
fi
|
||||
;;
|
||||
*) echo "some other screensaver $screen_saver_running" found | tee -a $logfile
|
||||
echo "please configure it manually" | tee -a $logfile
|
||||
;;
|
||||
esac
|
||||
elif [ -e "/etc/lightdm/lightdm.conf" ]; then
|
||||
# if screen saver NOT already disabled?
|
||||
if [ $(grep 'xserver-command=X -s 0 -dpms' /etc/lightdm/lightdm.conf | wc -l) == 0 ]; then
|
||||
echo install screensaver via lightdm.conf >> $logfile
|
||||
sudo sed -i '/^\[Seat:\*\]/a xserver-command=X -s 0 -dpms' /etc/lightdm/lightdm.conf
|
||||
#sudo cp _myconf /etc/lightdm/lightdm.conf
|
||||
#rm _myconf >/dev/null
|
||||
else
|
||||
echo screensaver via lightdm already disabled >> $logfile
|
||||
fi
|
||||
elif [ $(which gsettings | wc -l) == 1 ]; then
|
||||
setting=$(gsettings get org.gnome.desktop.screensaver lock-enabled)
|
||||
setting1=$(gsettings get org.gnome.desktop.session idle-delay)
|
||||
if [ "$setting $setting1" != 'false uint32 0' ]; then
|
||||
echo disable screensaver via gsettings was $setting and $setting1>> $logfile
|
||||
gsettings set org.gnome.desktop.screensaver lock-enabled false
|
||||
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
|
||||
gsettings set org.gnome.desktop.session idle-delay 0
|
||||
else
|
||||
echo gsettings screen saver already disabled >> $logfile
|
||||
fi
|
||||
elif [ -d "/etc/xdg/lxsession" ]; then
|
||||
currently_set=$(grep -m1 '\-dpms' /etc/xdg/lxsession/LXDE-pi/autostart)
|
||||
if [ "$currently_set." == "." ]; then
|
||||
echo disable screensaver via lxsession >> $logfile
|
||||
# turn it off for the future
|
||||
sudo su -c "echo -e '@xset s noblank\n@xset s off\n@xset -dpms' >> /etc/xdg/lxsession/LXDE-pi/autostart"
|
||||
# turn it off now
|
||||
export DISPLAY=:0; xset s noblank;xset s off;xset -dpms
|
||||
else
|
||||
echo lxsession screen saver already disabled >> $logfile
|
||||
fi
|
||||
else
|
||||
echo " "
|
||||
echo -e "unable to disable screen saver, /etc/xdg/lxsession does not exist" | tee >>$logfile
|
||||
fi
|
||||
fi
|
361
installers/upgrade-script.sh
Executable file
361
installers/upgrade-script.sh
Executable file
@@ -0,0 +1,361 @@
|
||||
#!/bin/bash
|
||||
# only DO npm installs when flag is set to 1
|
||||
# test when set to 0
|
||||
true=1
|
||||
false=0
|
||||
doinstalls=$false
|
||||
force=$false
|
||||
justActive=$true
|
||||
test_run=$true
|
||||
stashed=$false
|
||||
keyFile=package.json
|
||||
forced_arch=
|
||||
git_active_lock='./.git/index.lock'
|
||||
lf=$'\n'
|
||||
git_user_name=
|
||||
git_user_email=
|
||||
|
||||
trim() {
|
||||
local var="$*"
|
||||
# remove leading whitespace characters
|
||||
var="${var#"${var%%[![:space:]]*}"}"
|
||||
# remove trailing whitespace characters
|
||||
var="${var%"${var##*[![:space:]]}"}"
|
||||
echo -n "$var"
|
||||
}
|
||||
# is this a mac
|
||||
mac=$(uname -s)
|
||||
# get the processor architecture
|
||||
arch=$(uname -m)
|
||||
if [ $mac == 'Darwin' ]; then
|
||||
cmd=greadlink
|
||||
else
|
||||
cmd=readlink
|
||||
fi
|
||||
if [ -d ~/MagicMirror ]; then
|
||||
|
||||
# put the log where the script is located
|
||||
logdir=$(dirname $($cmd -f "$0"))
|
||||
# if the script was execute from the web
|
||||
if [[ $logdir != *"MagicMirror/installers"* ]]; then
|
||||
# use the MagicMirror/installers folder
|
||||
cd ~/MagicMirror/installers >/dev/null
|
||||
logdir=$(pwd)
|
||||
cd - >/dev/null
|
||||
fi
|
||||
logfile=$logdir/upgrade.log
|
||||
echo the log will be $logfile
|
||||
echo >>$logfile
|
||||
date +"Upgrade started - %a %b %e %H:%M:%S %Z %Y" >>$logfile
|
||||
echo system is $(uname -a) >> $logfile
|
||||
echo the os is $(lsb_release -a) >> $logfile
|
||||
|
||||
# because of how its executed from the web, p0 gets overlayed with parm
|
||||
# check to see if a parm was passed .. easy apply without editing
|
||||
p0=$0
|
||||
# if not 'bash', and some parm specified
|
||||
if [ $0 != 'bash' -a "$1." != "." ]; then
|
||||
# then executed locally
|
||||
# get the parm
|
||||
p0=$1
|
||||
fi
|
||||
# lowercase it.. watch out, mac stuff doesn't work with tr, etc
|
||||
p0=$(echo $p0 | cut -c 1-5 | awk '{print tolower($0)}' )
|
||||
if [ $p0 == 'apply' ]; then
|
||||
echo user requested to apply changes >>$logfile
|
||||
doinstalls=$true
|
||||
test_run=$false
|
||||
elif [ $p0 == 'force' ]; then
|
||||
echo user requested to force apply changes >>$logfile
|
||||
doinstalls=$true
|
||||
force=$true
|
||||
test_run=$false
|
||||
fi
|
||||
|
||||
if [ $test_run == $true ]; then
|
||||
echo doing test run = true | tee -a $logfile
|
||||
else
|
||||
echo doing test run = false | tee -a $logfile
|
||||
fi
|
||||
|
||||
# if we want just the modules listed in config.js now
|
||||
if [ $justActive == $true ]; then
|
||||
if [ ! -f ~/MagicMirror/installers/dumpactivemodules.js ]; then
|
||||
echo downloading dumpactivemodules script >> $logfile
|
||||
curl -sL https://www.dropbox.com/s/wwe6bfg2lcjmj43/dumpactivemodules.js?dl=0 > ~/MagicMirror/installers/dumpactivemodules.js
|
||||
fi
|
||||
fi
|
||||
echo update log will be in $logfile
|
||||
# used for parsing the array of module names
|
||||
SAVEIFS=$IFS # Save current IFS
|
||||
IFS=$'\n'
|
||||
|
||||
echo | tee -a $logfile
|
||||
# if the git lock file exists and git is not running
|
||||
if [ -f git_active_lock ]; then
|
||||
# check to see if git is actually running
|
||||
git_running=`ps -ef | grep git | grep -v color | grep -v 'grep git' | wc -l`
|
||||
# if not running
|
||||
if [ git_running == $false ]; then
|
||||
# clean up the dangling lock file
|
||||
echo erasing abandonded git lock file >> $logfile
|
||||
rm git_active_lock >/dev/null 2>&1
|
||||
else
|
||||
# git IS running, we can't proceed
|
||||
echo it appears another instance of git is running | tee -a $logfile
|
||||
# if this is an actual run
|
||||
if [ $doinstalls == $true ]; then
|
||||
# force it back to test run
|
||||
doinstalls = $false
|
||||
test_run=$true
|
||||
echo forcing test run mode | tee -a $logfile
|
||||
echo please resolve git running already and start the update again | tee -a $logfile
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# change to MagicMirror folder
|
||||
cd ~/MagicMirror
|
||||
|
||||
# save custom.css
|
||||
cd css
|
||||
echo "saving custom.css" | tee -a $logfile
|
||||
cp -p custom.css save_custom.css
|
||||
cd - >/dev/null
|
||||
save_alias=$(alias git 2>/dev/null)
|
||||
lang=$(locale | grep LANGUAGE | awk -F= '{print $2}')
|
||||
# make sure git respones are in english, so code works
|
||||
if [ "$lang." != "en_US.UTF-8." ]; then
|
||||
echo not english or locale not set, set git alias >>$logfile
|
||||
if [ "$LC_ALL." == "." ]; then
|
||||
alias git='LANGUAGE=en_US.UTF-8 git' >>$logfile
|
||||
else
|
||||
alias git='LC_ALL=en_US.UTF-8 git' >>$logfile
|
||||
fi
|
||||
#alias >>$logfile
|
||||
fi
|
||||
# get the git remote name
|
||||
remote=$(git remote 2>/dev/null | awk '{print $1}')
|
||||
|
||||
# if remote name set
|
||||
if [ "$remote." != "." ]; then
|
||||
|
||||
echo remote name = $remote >>$logfile
|
||||
|
||||
# get the local and remote package.json versions
|
||||
local_version=$(grep -m1 version package.json | awk -F\" '{print $4}')
|
||||
remote_version=$(curl -s https://raw.githubusercontent.com/MichMich/MagicMirror/master/package.json | grep -m1 version | awk -F\" '{print $4}')
|
||||
|
||||
# only change if they are different
|
||||
if [ "$local_version." != "$remote_version." -o $force == $true -o $test_run == $true ]; then
|
||||
echo upgrading from version $local_version to $remote_version | tee -a $logfile
|
||||
|
||||
# get the latest upgrade
|
||||
echo fetching latest revisions | tee -a $logfile
|
||||
git fetch $remote >/dev/null
|
||||
rc=$?
|
||||
echo git fetch rc=$rc >>$logfile
|
||||
if [ $rc -eq 0 ]; then
|
||||
|
||||
# need to get the current branch
|
||||
current_branch=$(git branch | grep "*" | awk '{print $2}')
|
||||
echo current branch = $current_branch >>$logfile
|
||||
|
||||
git status 2>&1 >>$logfile
|
||||
|
||||
# get the names of the files that are different locally
|
||||
diffs=$(git status 2>&1 | grep modified | awk -F: '{print $2}')
|
||||
|
||||
# split names into an array
|
||||
diffs=($diffs) # split to array $diffs
|
||||
|
||||
# if there are different files (array size greater than zero)
|
||||
if [ ${#diffs[@]} -gt 0 ]; then
|
||||
package_lock=0
|
||||
echo there are "${#diffs[@]}" local files that are different than the master repo | tee -a $logfile
|
||||
echo | tee -a $logfile
|
||||
for file in "${diffs[@]}"
|
||||
do
|
||||
echo "$file" | tee -a $logfile
|
||||
if [ $(echo $file | grep '\-lock.json$' | wc -l) -eq 1 ]; then
|
||||
package_lock=$true
|
||||
fi
|
||||
done
|
||||
echo | tee -a $logfile
|
||||
if [ $package_lock -eq 1 ]; then
|
||||
echo "any *-lock.json files do not need to be saved"
|
||||
fi
|
||||
read -p "do you want to save these files for later (Y/n)?" choice
|
||||
echo save/restore files selection = $choice >> $logfile
|
||||
if [[ $choice =~ ^[Yy]$ ]]; then
|
||||
git_user=$(git config --global --get user.email)
|
||||
if [ "git_user." == "." ]; then
|
||||
git_user_name="-c user.name=upgrade_script"
|
||||
git_user_email="-c user.email=script@upgrade.com"
|
||||
fi
|
||||
git git_user_name git_user_email stash >>$logfile
|
||||
stashed=$true
|
||||
else
|
||||
for file in "${diffs[@]}"
|
||||
do
|
||||
f="$(trim "$file")"
|
||||
echo restoring $f from repo >> $logfile
|
||||
if [ $test_run == $false ]; then
|
||||
git checkout HEAD -- $f | tee -a $logfile
|
||||
else
|
||||
echo skipping restore for $f, doing test run | tee -a $logfile
|
||||
fi
|
||||
done
|
||||
fi
|
||||
else
|
||||
echo no files different from github version >> $logfile
|
||||
fi
|
||||
|
||||
# lets test merge, in memory, no changes to working directory or local repo
|
||||
test_merge_output=$(git merge-tree `git merge-base $current_branch HEAD` HEAD $current_branch | grep "^<<<<<<<\|changed in both")
|
||||
echo "test merge result rc='$test_merge_output' , if empty, no conflicts" >> $logfile
|
||||
|
||||
# if there were no conflicts reported
|
||||
if [ "$test_merge_output." == "." ]; then
|
||||
|
||||
if [ $test_run == $false ]; then
|
||||
# go ahead and merge now
|
||||
echo "executing merge, apply specified" >> $logfile
|
||||
# get the text output of merge
|
||||
merge_output=$(git merge $remote/$current_branch 2>&1)
|
||||
# and its return code
|
||||
merge_result=$?
|
||||
# make any long line readable
|
||||
merge_output=$(echo $merge_output | tr '|' '\n'| sed "s/create/\\${lf}create/g" | sed "s/mode\ change/\\${lf}mode\ change/g")
|
||||
echo -e "merge result rc= $merge_result\n $merge_output">> $logfile
|
||||
else
|
||||
echo "skipping merge, only test run" >> $logfile
|
||||
merge_output=''
|
||||
merge_result=0
|
||||
fi
|
||||
|
||||
# if no merge errors
|
||||
if [ $merge_result == 0 ]; then
|
||||
# some updates applied
|
||||
if [ "$merge_output." != 'Already up to date.' -o $test_run == $true ]; then
|
||||
# update any dependencies for base
|
||||
if [ $doinstalls == $true ]; then
|
||||
# if this is a pi zero
|
||||
echo processor architecture is $arch >> $logfile
|
||||
if [ "$arch" == "armv6l" ]; then
|
||||
# force to look like pi 2
|
||||
echo forcing architecture armv7l >>$logfile
|
||||
forced_arch='--arch=armv7l'
|
||||
fi
|
||||
echo "updating MagicMirror runtime, please wait" | tee -a $logfile
|
||||
npm install $forced_arch 2>&1 | tee -a $logfile
|
||||
done_update=`date +"completed - %a %b %e %H:%M:%S %Z %Y"`
|
||||
echo npm install $done_update on base >> $ logfile
|
||||
fi
|
||||
# process updates for modules after base changed
|
||||
cd modules
|
||||
if [ $justActive == $true ]; then
|
||||
# get the list of ACTIVE modules with package.json files
|
||||
mtype=active
|
||||
modules=$(node ../installers/dumpactivemodules.js)
|
||||
else
|
||||
# get the list of INSTALLED modules with package.json files
|
||||
mtype=installed
|
||||
modules=$(find -maxdepth 2 -name 'package.json' -printf "%h\n" | cut -d'/' -f2 )
|
||||
fi
|
||||
modules=($modules) # split to array $modules
|
||||
|
||||
# if the array has entries in it
|
||||
if [ ${#modules[@]} -gt 0 ]; then
|
||||
echo >> $logfile
|
||||
echo "processing dependency changes for $mtype modules with package.json files" | tee -a $logfile
|
||||
echo
|
||||
for module in "${modules[@]}"
|
||||
do
|
||||
echo "processing for module" $module please wait | tee -a $logfile
|
||||
echo '----------------------------------' | tee -a $logfile
|
||||
# change to that directory
|
||||
cd $module
|
||||
# process its dependencies
|
||||
if [ $doinstalls == $true ]; then
|
||||
npm install $forced_arch 2>&1| tee -a $logfile
|
||||
else
|
||||
echo skipped processing for $module, doing test run | tee -a $logfile
|
||||
fi
|
||||
# return to modules folder
|
||||
cd .. >/dev/null
|
||||
echo "processing complete for module" $module | tee -a $logfile
|
||||
echo
|
||||
done
|
||||
else
|
||||
echo "no modules found needing npm refresh" | tee -a $logfile
|
||||
fi
|
||||
# return to Magic Mirror folder
|
||||
cd .. >/dev/null
|
||||
else
|
||||
echo "no changes detected for modules, skipping " | tee -a $logfile
|
||||
fi
|
||||
else
|
||||
echo there were merge errors | tee -a $logfile
|
||||
echo $merge_output | tee -a %logfile
|
||||
echo you should examine and resolve them | tee -a $logfile
|
||||
echo using the command git log --oneline --decorate | tee -a $logfile
|
||||
git log --oneline --decorate | tee -a $logfile
|
||||
fi
|
||||
else
|
||||
echo "there are merge conflicts to be resolved, no changes have been applied" | tee -a $logfile
|
||||
echo $test_merge_output | tee -a $logfile
|
||||
fi
|
||||
else
|
||||
echo "MagicMirror git fetch failed" | tee -a $logfile
|
||||
fi
|
||||
else
|
||||
echo "local version $local_version already same as master $remote_version" | tee -a $logfile
|
||||
fi
|
||||
else
|
||||
echo "Unable to determine upstream git repository" | tee -a $logfile
|
||||
fi
|
||||
# should be in MagicMirror base
|
||||
cd css
|
||||
# restore custom.css
|
||||
echo "restoring custom.css" | tee -a $logfile
|
||||
cp -p save_custom.css custom.css
|
||||
rm save_custom.css
|
||||
cd - >/dev/null
|
||||
if [ "$lang." != "en_US.UTF-8." ]; then
|
||||
if [ "$save_alias." != "." ]; then
|
||||
echo restoring git alias >>$logfile
|
||||
$save_alias >/dev/null
|
||||
else
|
||||
echo removing git alias >>$logfile
|
||||
unalias git >/dev/null
|
||||
fi
|
||||
fi
|
||||
IFS=$SAVEIFS # Restore IFS
|
||||
|
||||
if [ $stashed == $true ]; then
|
||||
if [ $test_run == $true ]; then
|
||||
echo test run, restoring files stashed | tee -a $logfile
|
||||
git git_user_name git_user_email stash pop >> $logfile
|
||||
else
|
||||
echo we stashed a set of files that appear changed from the latest repo versions. you should review them | tee -a $logfile
|
||||
git stash show --name-only > installers/stashed_files
|
||||
echo see installers/stashed_files for the list
|
||||
echo
|
||||
echo you can use git checkout "stash@{0}" -- filename to extract one file from the stash
|
||||
echo
|
||||
echo or git stash pop to restore them all
|
||||
echo
|
||||
echo WARNING..
|
||||
echo WARNING.. either will overlay the file just installed by the update
|
||||
echo WARNING..
|
||||
fi
|
||||
fi
|
||||
# return to original folder
|
||||
cd - >/dev/null
|
||||
date +"Upgrade ended - %a %b %e %H:%M:%S %Z %Y" >>$logfile
|
||||
else
|
||||
echo It appears MagicMirror has not been installed on this system
|
||||
echo please run the installer, "raspberry.sh" first
|
||||
fi
|
||||
|
25
js/app.js
25
js/app.js
@@ -11,6 +11,12 @@ var Utils = require(__dirname + "/utils.js");
|
||||
var defaultModules = require(__dirname + "/../modules/default/defaultmodules.js");
|
||||
var path = require("path");
|
||||
|
||||
// Alias modules mentioned in package.js under _moduleAliases.
|
||||
require("module-alias/register");
|
||||
|
||||
// add timestamps in front of log messages
|
||||
require("console-stamp")(console, "HH:MM:ss.l");
|
||||
|
||||
// Get version number.
|
||||
global.version = JSON.parse(fs.readFileSync("package.json", "utf8")).version;
|
||||
console.log("Starting MagicMirror: v" + global.version);
|
||||
@@ -48,7 +54,6 @@ var App = function() {
|
||||
*
|
||||
* argument callback function - The callback function.
|
||||
*/
|
||||
|
||||
var loadConfig = function(callback) {
|
||||
console.log("Loading config ...");
|
||||
var defaults = require(__dirname + "/defaults.js");
|
||||
@@ -67,7 +72,7 @@ var App = function() {
|
||||
var config = Object.assign(defaults, c);
|
||||
callback(config);
|
||||
} catch (e) {
|
||||
if (e.code == "ENOENT") {
|
||||
if (e.code === "ENOENT") {
|
||||
console.error(Utils.colors.error("WARNING! Could not find config file. Please create one. Starting with default configuration."));
|
||||
} else if (e instanceof ReferenceError || e instanceof SyntaxError) {
|
||||
console.error(Utils.colors.error("WARNING! Could not validate config file. Starting with default configuration. Please correct syntax errors at or above this line: " + e.stack));
|
||||
@@ -96,7 +101,7 @@ var App = function() {
|
||||
". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.")
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* loadModule(module)
|
||||
* Loads a specific module.
|
||||
@@ -173,7 +178,7 @@ var App = function() {
|
||||
};
|
||||
|
||||
/* cmpVersions(a,b)
|
||||
* Compare two symantic version numbers and return the difference.
|
||||
* Compare two semantic version numbers and return the difference.
|
||||
*
|
||||
* argument a string - Version number a.
|
||||
* argument a string - Version number b.
|
||||
@@ -197,7 +202,7 @@ var App = function() {
|
||||
/* start(callback)
|
||||
* This methods starts the core app.
|
||||
* It loads the config, then it loads all modules.
|
||||
* When it"s done it executs the callback with the config as argument.
|
||||
* When it's done it executes the callback with the config as argument.
|
||||
*
|
||||
* argument callback function - The callback function.
|
||||
*/
|
||||
@@ -231,7 +236,6 @@ var App = function() {
|
||||
if (typeof callback === "function") {
|
||||
callback(config);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -263,6 +267,15 @@ var App = function() {
|
||||
this.stop();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
/* We also need to listen to SIGTERM signals so we stop everything when we are asked to stop by the OS.
|
||||
*/
|
||||
process.on("SIGTERM", () => {
|
||||
console.log("[SIGTERM] Received. Shutting down server...");
|
||||
setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds
|
||||
this.stop();
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = new App();
|
||||
|
@@ -21,7 +21,7 @@
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
|
||||
// Make a copy of all prototype properies, to prevent reference issues.
|
||||
// Make a copy of all prototype properties, to prevent reference issues.
|
||||
for (var name in prototype) {
|
||||
prototype[name] = cloneObject(prototype[name]);
|
||||
}
|
||||
@@ -29,8 +29,8 @@
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function (name, fn) {
|
||||
prototype[name] = typeof prop[name] === "function" &&
|
||||
typeof _super[name] === "function" && fnTest.test(prop[name]) ? (function (name, fn) {
|
||||
return function () {
|
||||
var tmp = this._super;
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) : prop[name];
|
||||
|
@@ -17,6 +17,7 @@ const BrowserWindow = electron.BrowserWindow;
|
||||
let mainWindow;
|
||||
|
||||
function createWindow() {
|
||||
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");
|
||||
var electronOptionsDefaults = {
|
||||
width: 800,
|
||||
height: 600,
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
var Loader = (function() {
|
||||
|
||||
/* Create helper valiables */
|
||||
/* Create helper variables */
|
||||
|
||||
var loadedModuleFiles = [];
|
||||
var loadedFiles = [];
|
||||
@@ -55,7 +55,7 @@ var Loader = (function() {
|
||||
module.start();
|
||||
}
|
||||
|
||||
// Notifiy core of loded modules.
|
||||
// Notify core of loaded modules.
|
||||
MM.modulesStarted(moduleObjects);
|
||||
};
|
||||
|
||||
@@ -104,7 +104,6 @@ var Loader = (function() {
|
||||
config: moduleData.config,
|
||||
classes: (typeof moduleData.classes !== "undefined") ? moduleData.classes + " " + module : module
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return moduleFiles;
|
||||
@@ -138,7 +137,6 @@ var Loader = (function() {
|
||||
afterLoad();
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* bootstrapModule(module, mObj)
|
||||
@@ -164,7 +162,6 @@ var Loader = (function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/* loadFile(fileName)
|
||||
@@ -210,7 +207,6 @@ var Loader = (function() {
|
||||
document.getElementsByTagName("head")[0].appendChild(stylesheet);
|
||||
break;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* Public Methods */
|
||||
@@ -261,5 +257,4 @@ var Loader = (function() {
|
||||
loadFile(module.file(fileName), callback);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
29
js/main.js
29
js/main.js
@@ -39,11 +39,13 @@ var MM = (function() {
|
||||
dom.opacity = 0;
|
||||
wrapper.appendChild(dom);
|
||||
|
||||
if (typeof module.getHeader() !== "undefined" && module.getHeader() !== "") {
|
||||
var moduleHeader = document.createElement("header");
|
||||
moduleHeader.innerHTML = module.getHeader();
|
||||
moduleHeader.className = "module-header";
|
||||
dom.appendChild(moduleHeader);
|
||||
var moduleHeader = document.createElement("header");
|
||||
moduleHeader.innerHTML = module.getHeader();
|
||||
moduleHeader.className = "module-header";
|
||||
dom.appendChild(moduleHeader);
|
||||
|
||||
if (typeof module.getHeader() === "undefined" || module.getHeader() !== "") {
|
||||
moduleHeader.style = "display: none;";
|
||||
}
|
||||
|
||||
var moduleContent = document.createElement("div");
|
||||
@@ -203,15 +205,15 @@ var MM = (function() {
|
||||
*/
|
||||
var updateModuleContent = function(module, newHeader, newContent) {
|
||||
var moduleWrapper = document.getElementById(module.identifier);
|
||||
if (moduleWrapper === null) {return;}
|
||||
var headerWrapper = moduleWrapper.getElementsByClassName("module-header");
|
||||
var contentWrapper = moduleWrapper.getElementsByClassName("module-content");
|
||||
|
||||
contentWrapper[0].innerHTML = "";
|
||||
contentWrapper[0].appendChild(newContent);
|
||||
|
||||
if( headerWrapper.length > 0 && newHeader) {
|
||||
headerWrapper[0].innerHTML = newHeader;
|
||||
}
|
||||
headerWrapper[0].innerHTML = newHeader;
|
||||
headerWrapper[0].style = headerWrapper.length > 0 && newHeader ? undefined : "display: none;";
|
||||
};
|
||||
|
||||
/* hideModule(module, speed, callback)
|
||||
@@ -291,7 +293,7 @@ var MM = (function() {
|
||||
var moduleWrapper = document.getElementById(module.identifier);
|
||||
if (moduleWrapper !== null) {
|
||||
moduleWrapper.style.transition = "opacity " + speed / 1000 + "s";
|
||||
// Restore the postition. See hideModule() for more info.
|
||||
// Restore the position. See hideModule() for more info.
|
||||
moduleWrapper.style.position = "static";
|
||||
|
||||
updateWrapperStates();
|
||||
@@ -311,7 +313,7 @@ var MM = (function() {
|
||||
/* updateWrapperStates()
|
||||
* Checks for all positions if it has visible content.
|
||||
* If not, if will hide the position to prevent unwanted margins.
|
||||
* This method schould be called by the show and hide methods.
|
||||
* This method should be called by the show and hide methods.
|
||||
*
|
||||
* Example:
|
||||
* If the top_bar only contains the update notification. And no update is available,
|
||||
@@ -319,7 +321,6 @@ var MM = (function() {
|
||||
* an ugly top margin. By using this function, the top bar will be hidden if the
|
||||
* update notification is not visible.
|
||||
*/
|
||||
|
||||
var updateWrapperStates = function() {
|
||||
var positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
|
||||
|
||||
@@ -329,7 +330,7 @@ var MM = (function() {
|
||||
|
||||
var showWrapper = false;
|
||||
Array.prototype.forEach.call(moduleWrappers, function(moduleWrapper) {
|
||||
if (moduleWrapper.style.position == "" || moduleWrapper.style.position == "static") {
|
||||
if (moduleWrapper.style.position === "" || moduleWrapper.style.position === "static") {
|
||||
showWrapper = true;
|
||||
}
|
||||
});
|
||||
@@ -478,7 +479,7 @@ var MM = (function() {
|
||||
/* sendNotification(notification, payload, sender)
|
||||
* Send a notification to all modules.
|
||||
*
|
||||
* argument notification string - The identifier of the noitication.
|
||||
* argument notification string - The identifier of the notification.
|
||||
* argument payload mixed - The payload of the notification.
|
||||
* argument sender Module - The module that sent the notification.
|
||||
*/
|
||||
@@ -558,7 +559,7 @@ var MM = (function() {
|
||||
})();
|
||||
|
||||
// Add polyfill for Object.assign.
|
||||
if (typeof Object.assign != "function") {
|
||||
if (typeof Object.assign !== "function") {
|
||||
(function() {
|
||||
Object.assign = function(target) {
|
||||
"use strict";
|
||||
|
17
js/module.js
17
js/module.js
@@ -76,7 +76,7 @@ var Module = Class.extend({
|
||||
/* getDom()
|
||||
* This method generates the dom which needs to be displayed. This method is called by the Magic Mirror core.
|
||||
* This method can to be subclassed if the module wants to display info on the mirror.
|
||||
* Alternatively, the getTemplete method could be subclassed.
|
||||
* Alternatively, the getTemplate method could be subclassed.
|
||||
*
|
||||
* return DomObject | Promise - The dom or a promise with the dom to display.
|
||||
*/
|
||||
@@ -92,7 +92,7 @@ var Module = Class.extend({
|
||||
// the template is a filename
|
||||
self.nunjucksEnvironment().render(template, templateData, function (err, res) {
|
||||
if (err) {
|
||||
Log.error(err)
|
||||
Log.error(err);
|
||||
}
|
||||
|
||||
div.innerHTML = res;
|
||||
@@ -121,7 +121,7 @@ var Module = Class.extend({
|
||||
|
||||
/* getTemplate()
|
||||
* This method returns the template for the module which is used by the default getDom implementation.
|
||||
* This method needs to be subclassed if the module wants to use a tempate.
|
||||
* This method needs to be subclassed if the module wants to use a template.
|
||||
* It can either return a template sting, or a template filename.
|
||||
* If the string ends with '.html' it's considered a file from within the module's folder.
|
||||
*
|
||||
@@ -138,7 +138,7 @@ var Module = Class.extend({
|
||||
* return Object
|
||||
*/
|
||||
getTemplateData: function () {
|
||||
return {}
|
||||
return {};
|
||||
},
|
||||
|
||||
/* notificationReceived(notification, payload, sender)
|
||||
@@ -164,7 +164,7 @@ var Module = Class.extend({
|
||||
* @returns Nunjucks Environment
|
||||
*/
|
||||
nunjucksEnvironment: function() {
|
||||
if (this._nunjucksEnvironment != null) {
|
||||
if (this._nunjucksEnvironment !== null) {
|
||||
return this._nunjucksEnvironment;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ var Module = Class.extend({
|
||||
lstripBlocks: true
|
||||
});
|
||||
this._nunjucksEnvironment.addFilter("translate", function(str) {
|
||||
return self.translate(str)
|
||||
return self.translate(str);
|
||||
});
|
||||
|
||||
return this._nunjucksEnvironment;
|
||||
@@ -233,7 +233,7 @@ var Module = Class.extend({
|
||||
},
|
||||
|
||||
/* socket()
|
||||
* Returns a socket object. If it doesn"t exist, it"s created.
|
||||
* Returns a socket object. If it doesn't exist, it"s created.
|
||||
* It also registers the notification callback.
|
||||
*/
|
||||
socket: function () {
|
||||
@@ -438,11 +438,10 @@ Module.create = function (name) {
|
||||
var ModuleClass = Module.extend(clonedDefinition);
|
||||
|
||||
return new ModuleClass();
|
||||
|
||||
};
|
||||
|
||||
/* cmpVersions(a,b)
|
||||
* Compare two symantic version numbers and return the difference.
|
||||
* Compare two semantic version numbers and return the difference.
|
||||
*
|
||||
* argument a string - Version number a.
|
||||
* argument a string - Version number b.
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
var Class = require("../../../js/class.js");
|
||||
var Class = require("./class.js");
|
||||
var express = require("express");
|
||||
var path = require("path");
|
||||
|
@@ -24,10 +24,10 @@ var Server = function(config, callback) {
|
||||
|
||||
console.log("Starting server on port " + port + " ... ");
|
||||
|
||||
server.listen(port, config.address ? config.address : null);
|
||||
server.listen(port, config.address ? config.address : "localhost");
|
||||
|
||||
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length == 0) {
|
||||
console.info(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs"))
|
||||
if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) {
|
||||
console.info(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs"));
|
||||
}
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
|
@@ -18,7 +18,7 @@ var Translator = (function() {
|
||||
xhr.overrideMimeType("application/json");
|
||||
xhr.open("GET", file, true);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == "200") {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
callback(JSON.parse(stripComments(xhr.responseText)));
|
||||
}
|
||||
};
|
||||
@@ -159,6 +159,7 @@ var Translator = (function() {
|
||||
|
||||
return key;
|
||||
},
|
||||
|
||||
/* load(module, file, isFallback, callback)
|
||||
* Load a translation file (json) and remember the data.
|
||||
*
|
||||
|
@@ -267,7 +267,7 @@ When using a node_helper, the node helper can send your module notifications. Wh
|
||||
- `payload` - AnyType - The payload of a notification.
|
||||
|
||||
**Note 1:** When a node helper sends a notification, all modules of that module type receive the same notifications. <br>
|
||||
**Note 2:** The socket connection is established as soon as the module sends its first message using [sendSocketNotification](thissendsocketnotificationnotification-payload).
|
||||
**Note 2:** The socket connection is established as soon as the module sends its first message using [sendSocketNotification](#thissendsocketnotificationnotification-payload).
|
||||
|
||||
**Example:**
|
||||
````javascript
|
||||
|
@@ -35,13 +35,13 @@ Module.register("alert",{
|
||||
};
|
||||
},
|
||||
show_notification: function(message) {
|
||||
if (this.config.effect == "slide") {this.config.effect = this.config.effect + "-" + this.config.position;}
|
||||
if (this.config.effect === "slide") {this.config.effect = this.config.effect + "-" + this.config.position;}
|
||||
msg = "";
|
||||
if (message.title) {
|
||||
msg += "<span class='thin dimmed medium'>" + message.title + "</span>";
|
||||
}
|
||||
if (message.message){
|
||||
if (msg != ""){
|
||||
if (msg !== ""){
|
||||
msg+= "<br />";
|
||||
}
|
||||
msg += "<span class='light bright small'>" + message.message + "</span>";
|
||||
@@ -132,7 +132,7 @@ Module.register("alert",{
|
||||
if (typeof payload.type === "undefined") { payload.type = "alert"; }
|
||||
if (payload.type === "alert") {
|
||||
this.show_alert(payload, sender);
|
||||
} else if (payload.type = "notification") {
|
||||
} else if (payload.type === "notification") {
|
||||
this.show_notification(payload);
|
||||
}
|
||||
} else if (notification === "HIDE_ALERT") {
|
||||
@@ -152,5 +152,4 @@ Module.register("alert",{
|
||||
}
|
||||
Log.info("Starting module: " + this.name);
|
||||
}
|
||||
|
||||
});
|
||||
|
@@ -30,6 +30,7 @@ The following properties can be configured:
|
||||
| `maximumNumberOfDays` | The maximum number of days in the future. <br><br> **Default value:** `365`
|
||||
| `displaySymbol` | Display a symbol in front of an entry. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||
| `defaultSymbol` | The default symbol. <br><br> **Possible values:** See [Font Awsome](http://fontawesome.io/icons/) website. <br> **Default value:** `calendar`
|
||||
| `showLocation` | Whether to show event locations. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `maxTitleLength` | The maximum title length. <br><br> **Possible values:** `10` - `50` <br> **Default value:** `25`
|
||||
| `wrapEvents` | Wrap event titles to multiple lines. Breaks lines at the length defined by `maxTitleLength`. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `maxTitleLines` | The maximum number of lines a title will wrap vertically before being cut (Only enabled if `wrapEvents` is also enabled). <br><br> **Possible values:** `0` - `10` <br> **Default value:** `3`
|
||||
@@ -53,8 +54,9 @@ The following properties can be configured:
|
||||
| `hidePrivate` | Hides private calendar events. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `hideOngoing` | Hides calendar events that have already started. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `excludedEvents` | An array of words / phrases from event titles that will be excluded from being shown. <br><br>Additionally advanced filter objects can be passed in. Below is the configuration for the advance filtering object.<br>**Required**<br>`filterBy` - string used to determine if filter is applied.<br>**Optional**<br>`until` - Time before an event to display it Ex: [`'3 days'`, `'2 months'`, `'1 week'`]<br>`caseSensitive` - By default, excludedEvents are case insensitive, set this to true to enforce case sensitivity<br>`regex` - set to `true` if filterBy is a regex. For those not familiar with regex it is used for pattern matching, please see [here](https://regexr.com/) for more info.<br><br> **Example:** `['Birthday', 'Hide This Event', {filterBy: 'Payment', until: '6 days', caseSensitive: true}, {filterBy: '^[0-9]{1,}.*', regex: true}]` <br> **Default value:** `[]`
|
||||
| `sliceMultiDayEvents` | If this is set to true, events exceeding at least one midnight will be sliced into separate events including a counter like (1/2). This is especially helpful in "dateheaders" mode. Events will be sliced at midnight, end time for all events but the last will be 23:59 **Default value:** `true`
|
||||
|
||||
| `broadcastPastEvents` | If this is set to true, events from the past `maximumNumberOfDays` will be included in event broadcasts <br> **Default value:** `false`
|
||||
| `sliceMultiDayEvents` | If this is set to true, events exceeding at least one midnight will be sliced into separate events including a counter like (1/2). This is especially helpful in "dateheaders" mode. Events will be sliced at midnight, end time for all events but the last will be 23:59 <br> **Default value:** `true`
|
||||
| `nextDaysRelative ` | If this is set to true, the appointments of today and tomorrow are displayed relatively, even if the timeformat is set to absolute. <br> **Default value:** `false`
|
||||
|
||||
### Calendar configuration
|
||||
|
||||
@@ -95,6 +97,7 @@ config: {
|
||||
| `symbolClass` | Add a class to the cell of symbol.
|
||||
| `titleClass` | Add a class to the title's cell.
|
||||
| `timeClass` | Add a class to the time's cell.
|
||||
| `broadcastPastEvents` | Whether to include past events from this calendar. Overrides global setting
|
||||
|
||||
|
||||
#### Calendar authentication options:
|
||||
|
@@ -15,6 +15,7 @@ Module.register("calendar", {
|
||||
maximumNumberOfDays: 365,
|
||||
displaySymbol: true,
|
||||
defaultSymbol: "calendar", // Fontawesome Symbol see http://fontawesome.io/cheatsheet/
|
||||
showLocation: false,
|
||||
displayRepeatingCountTitle: false,
|
||||
defaultRepeatingCountTitle: "",
|
||||
maxTitleLength: 25,
|
||||
@@ -48,7 +49,9 @@ Module.register("calendar", {
|
||||
},
|
||||
broadcastEvents: true,
|
||||
excludedEvents: [],
|
||||
sliceMultiDayEvents: false
|
||||
sliceMultiDayEvents: false,
|
||||
broadcastPastEvents: false,
|
||||
nextDaysRelative: false
|
||||
},
|
||||
|
||||
// Define required scripts.
|
||||
@@ -82,7 +85,8 @@ Module.register("calendar", {
|
||||
|
||||
var calendarConfig = {
|
||||
maximumEntries: calendar.maximumEntries,
|
||||
maximumNumberOfDays: calendar.maximumNumberOfDays
|
||||
maximumNumberOfDays: calendar.maximumNumberOfDays,
|
||||
broadcastPastEvents: calendar.broadcastPastEvents,
|
||||
};
|
||||
if (calendar.symbolClass === "undefined" || calendar.symbolClass === null) {
|
||||
calendarConfig.symbolClass = "";
|
||||
@@ -101,7 +105,7 @@ Module.register("calendar", {
|
||||
calendar.auth = {
|
||||
user: calendar.user,
|
||||
pass: calendar.pass
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.addCalendar(calendar.url, calendar.auth, calendarConfig);
|
||||
@@ -131,6 +135,7 @@ Module.register("calendar", {
|
||||
}
|
||||
} else if (notification === "FETCH_ERROR") {
|
||||
Log.error("Calendar Error. Could not fetch calendar: " + payload.url);
|
||||
this.loaded = true;
|
||||
} else if (notification === "INCORRECT_URL") {
|
||||
Log.error("Calendar Error. Incorrect url: " + payload.url);
|
||||
} else {
|
||||
@@ -175,6 +180,7 @@ Module.register("calendar", {
|
||||
|
||||
dateCell.colSpan = "3";
|
||||
dateCell.innerHTML = dateAsString;
|
||||
dateCell.style.paddingTop = "10px";
|
||||
dateRow.appendChild(dateCell);
|
||||
wrapper.appendChild(dateRow);
|
||||
|
||||
@@ -187,7 +193,6 @@ Module.register("calendar", {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var eventWrapper = document.createElement("tr");
|
||||
|
||||
if (this.config.colored && !this.config.coloredSymbolOnly) {
|
||||
@@ -220,7 +225,7 @@ Module.register("calendar", {
|
||||
symbolWrapper.appendChild(symbol);
|
||||
}
|
||||
eventWrapper.appendChild(symbolWrapper);
|
||||
}else if(this.config.timeFormat === "dateheaders"){
|
||||
} else if(this.config.timeFormat === "dateheaders"){
|
||||
var blankCell = document.createElement("td");
|
||||
blankCell.innerHTML = " ";
|
||||
eventWrapper.appendChild(blankCell);
|
||||
@@ -257,7 +262,7 @@ Module.register("calendar", {
|
||||
titleWrapper.colSpan = "2";
|
||||
titleWrapper.align = "left";
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
var timeClass = this.timeClassForUrl(event.url);
|
||||
var timeWrapper = document.createElement("td");
|
||||
@@ -270,7 +275,7 @@ Module.register("calendar", {
|
||||
}
|
||||
|
||||
eventWrapper.appendChild(titleWrapper);
|
||||
}else{
|
||||
} else {
|
||||
var timeWrapper = document.createElement("td");
|
||||
|
||||
eventWrapper.appendChild(titleWrapper);
|
||||
@@ -325,7 +330,7 @@ Module.register("calendar", {
|
||||
// If event is within 6 hour, display 'in xxx' time format or moment.fromNow()
|
||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").fromNow());
|
||||
} else {
|
||||
if(this.config.timeFormat === "absolute") {
|
||||
if(this.config.timeFormat === "absolute" && !this.config.nextDaysRelative) {
|
||||
timeWrapper.innerHTML = this.capFirst(moment(event.startDate, "x").format(this.config.dateFormat));
|
||||
} else {
|
||||
// Otherwise just say 'Today/Tomorrow at such-n-such time'
|
||||
@@ -379,6 +384,31 @@ Module.register("calendar", {
|
||||
currentFadeStep = e - startFade;
|
||||
eventWrapper.style.opacity = 1 - (1 / fadeSteps * currentFadeStep);
|
||||
}
|
||||
|
||||
if (this.config.showLocation) {
|
||||
if (event.location !== false) {
|
||||
var locationRow = document.createElement("tr");
|
||||
locationRow.className = "normal xsmall light";
|
||||
|
||||
if (this.config.displaySymbol) {
|
||||
var symbolCell = document.createElement("td");
|
||||
locationRow.appendChild(symbolCell);
|
||||
}
|
||||
|
||||
var descCell = document.createElement("td");
|
||||
descCell.className = "location";
|
||||
descCell.colSpan = "2";
|
||||
descCell.innerHTML = event.location;
|
||||
locationRow.appendChild(descCell);
|
||||
|
||||
wrapper.appendChild(locationRow);
|
||||
|
||||
if (e >= startFade) {
|
||||
currentFadeStep = e - startFade;
|
||||
locationRow.style.opacity = 1 - (1 / fadeSteps * currentFadeStep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
@@ -436,10 +466,14 @@ Module.register("calendar", {
|
||||
var events = [];
|
||||
var today = moment().startOf("day");
|
||||
var now = new Date();
|
||||
var future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
|
||||
for (var c in this.calendarData) {
|
||||
var calendar = this.calendarData[c];
|
||||
for (var e in calendar) {
|
||||
var event = calendar[e];
|
||||
var event = JSON.parse(JSON.stringify(calendar[e])); // clone object
|
||||
if(event.endDate < now) {
|
||||
continue;
|
||||
}
|
||||
if(this.config.hidePrivate) {
|
||||
if(event.class === "PRIVATE") {
|
||||
// do not add the current event, skip it
|
||||
@@ -460,24 +494,31 @@ Module.register("calendar", {
|
||||
/* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days,
|
||||
* otherwise, esp. in dateheaders mode it is not clear how long these events are.
|
||||
*/
|
||||
if (this.config.sliceMultiDayEvents) {
|
||||
var midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x"); //next midnight
|
||||
var maxCount = Math.ceil(((event.endDate - 1) - moment(event.startDate, "x").endOf("day").format("x"))/(1000*60*60*24)) + 1;
|
||||
if (this.config.sliceMultiDayEvents && maxCount > 1) {
|
||||
var splitEvents = [];
|
||||
var midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x");
|
||||
var count = 1;
|
||||
var maxCount = Math.ceil(((event.endDate - 1) - moment(event.startDate, "x").endOf("day").format("x"))/(1000*60*60*24)) + 1
|
||||
if (event.endDate > midnight) {
|
||||
while (event.endDate > midnight) {
|
||||
var nextEvent = JSON.parse(JSON.stringify(event)); //make a copy without reference to the original event
|
||||
nextEvent.startDate = midnight;
|
||||
event.endDate = midnight;
|
||||
event.title += " (" + count + "/" + maxCount + ")";
|
||||
events.push(event);
|
||||
event = nextEvent;
|
||||
count += 1;
|
||||
midnight = moment(midnight, "x").add(1, "day").format("x"); //move further one day for next split
|
||||
}
|
||||
event.title += " ("+count+"/"+maxCount+")";
|
||||
}
|
||||
events.push(event);
|
||||
while (event.endDate > midnight) {
|
||||
var thisEvent = JSON.parse(JSON.stringify(event)); // clone object
|
||||
thisEvent.today = thisEvent.startDate >= today && thisEvent.startDate < (today + 24 * 60 * 60 * 1000);
|
||||
thisEvent.endDate = midnight;
|
||||
thisEvent.title += " (" + count + "/" + maxCount + ")";
|
||||
splitEvents.push(thisEvent);
|
||||
|
||||
event.startDate = midnight;
|
||||
count += 1;
|
||||
midnight = moment(midnight, "x").add(1, "day").format("x"); // next day
|
||||
}
|
||||
// Last day
|
||||
event.title += " ("+count+"/"+maxCount+")";
|
||||
splitEvents.push(event);
|
||||
|
||||
for (event of splitEvents) {
|
||||
if ((event.endDate > now) && (event.endDate <= future)) {
|
||||
events.push(event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
events.push(event);
|
||||
}
|
||||
@@ -487,11 +528,9 @@ Module.register("calendar", {
|
||||
events.sort(function (a, b) {
|
||||
return a.startDate - b.startDate;
|
||||
});
|
||||
|
||||
return events.slice(0, this.config.maximumEntries);
|
||||
},
|
||||
|
||||
|
||||
listContainsEvent: function(eventList, event){
|
||||
for(var evt of eventList){
|
||||
if(evt.title === event.title && parseInt(evt.startDate) === parseInt(event.startDate)){
|
||||
@@ -499,7 +538,6 @@ Module.register("calendar", {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
},
|
||||
|
||||
/* createEventList(url)
|
||||
@@ -517,7 +555,8 @@ Module.register("calendar", {
|
||||
symbolClass: calendarConfig.symbolClass,
|
||||
titleClass: calendarConfig.titleClass,
|
||||
timeClass: calendarConfig.timeClass,
|
||||
auth: auth
|
||||
auth: auth,
|
||||
broadcastPastEvents: calendarConfig.broadcastPastEvents || this.config.broadcastPastEvents,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -678,7 +717,6 @@ Module.register("calendar", {
|
||||
* Capitalize the first letter of a string
|
||||
* Return capitalized string
|
||||
*/
|
||||
|
||||
capFirst: function (string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
},
|
||||
|
@@ -8,7 +8,7 @@
|
||||
var ical = require("./vendor/ical.js");
|
||||
var moment = require("moment");
|
||||
|
||||
var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth) {
|
||||
var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) {
|
||||
var self = this;
|
||||
|
||||
var reloadTimer = null;
|
||||
@@ -37,9 +37,9 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
if(auth.method === "bearer"){
|
||||
opts.auth = {
|
||||
bearer: auth.pass
|
||||
}
|
||||
};
|
||||
|
||||
}else{
|
||||
} else {
|
||||
opts.auth = {
|
||||
user: auth.user,
|
||||
pass: auth.pass
|
||||
@@ -47,7 +47,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
|
||||
if(auth.method === "digest"){
|
||||
opts.auth.sendImmediately = false;
|
||||
}else{
|
||||
} else {
|
||||
opts.auth.sendImmediately = true;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,8 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
// console.log(data);
|
||||
newEvents = [];
|
||||
|
||||
var limitFunction = function(date, i) {return i < maximumEntries;};
|
||||
// limitFunction doesn't do much limiting, see comment re: the dates array in rrule section below as to why we need to do the filtering ourselves
|
||||
var limitFunction = function(date, i) {return true;};
|
||||
|
||||
var eventDate = function(event, time) {
|
||||
return (event[time].length === 8) ? moment(event[time], "YYYYMMDD") : moment(new Date(event[time]));
|
||||
@@ -74,6 +75,11 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
var now = new Date();
|
||||
var today = moment().startOf("day").toDate();
|
||||
var future = moment().startOf("day").add(maximumNumberOfDays, "days").subtract(1,"seconds").toDate(); // Subtract 1 second so that events that start on the middle of the night will not repeat.
|
||||
var past = today;
|
||||
|
||||
if (includePastEvents) {
|
||||
past = moment().startOf("day").subtract(maximumNumberOfDays, "days").toDate();
|
||||
}
|
||||
|
||||
// FIXME:
|
||||
// Ugly fix to solve the facebook birthday issue.
|
||||
@@ -102,7 +108,6 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// calculate the duration f the event for use with recurring events.
|
||||
var duration = parseInt(endDate.format("x")) - parseInt(startDate.format("x"));
|
||||
|
||||
@@ -110,12 +115,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
startDate = startDate.startOf("day");
|
||||
}
|
||||
|
||||
var title = "Event";
|
||||
if (event.summary) {
|
||||
title = (typeof event.summary.val !== "undefined") ? event.summary.val : event.summary;
|
||||
} else if(event.description) {
|
||||
title = event.description;
|
||||
}
|
||||
var title = getTitleFromEvent(event);
|
||||
|
||||
var excluded = false,
|
||||
dateFilter = null;
|
||||
@@ -171,29 +171,98 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
var geo = event.geo || false;
|
||||
var description = event.description || false;
|
||||
|
||||
if (typeof event.rrule != "undefined" && event.rrule != null && !isFacebookBirthday) {
|
||||
if (typeof event.rrule !== "undefined" && event.rrule !== null && !isFacebookBirthday) {
|
||||
var rule = event.rrule;
|
||||
var addedEvents = 0;
|
||||
|
||||
// can cause problems with e.g. birthdays before 1900
|
||||
if(rule.origOptions && rule.origOptions.dtstart && rule.origOptions.dtstart.getFullYear() < 1900 ||
|
||||
if(rule.options && rule.origOptions && rule.origOptions.dtstart && rule.origOptions.dtstart.getFullYear() < 1900 ||
|
||||
rule.options && rule.options.dtstart && rule.options.dtstart.getFullYear() < 1900){
|
||||
rule.origOptions.dtstart.setYear(1900);
|
||||
rule.options.dtstart.setYear(1900);
|
||||
}
|
||||
|
||||
var dates = rule.between(today, future, true, limitFunction);
|
||||
// For recurring events, get the set of start dates that fall within the range
|
||||
// of dates we"re looking for.
|
||||
var dates = rule.between(past, future, true, limitFunction);
|
||||
|
||||
// The "dates" array contains the set of dates within our desired date range range that are valid
|
||||
// for the recurrence rule. *However*, it"s possible for us to have a specific recurrence that
|
||||
// had its date changed from outside the range to inside the range. For the time being,
|
||||
// we"ll handle this by adding *all* recurrence entries into the set of dates that we check,
|
||||
// because the logic below will filter out any recurrences that don"t actually belong within
|
||||
// our display range.
|
||||
// Would be great if there was a better way to handle this.
|
||||
if (event.recurrences != undefined)
|
||||
{
|
||||
var pastMoment = moment(past);
|
||||
var futureMoment = moment(future);
|
||||
|
||||
for (var r in event.recurrences)
|
||||
{
|
||||
// Only add dates that weren't already in the range we added from the rrule so that
|
||||
// we don"t double-add those events.
|
||||
if (moment(new Date(r)).isBetween(pastMoment, futureMoment) != true)
|
||||
{
|
||||
dates.push(new Date(r));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through the set of date entries to see which recurrences should be added to our event list.
|
||||
for (var d in dates) {
|
||||
startDate = moment(new Date(dates[d]));
|
||||
endDate = moment(parseInt(startDate.format("x")) + duration, "x");
|
||||
var date = dates[d];
|
||||
// ical.js started returning recurrences and exdates as ISOStrings without time information.
|
||||
// .toISOString().substring(0,10) is the method they use to calculate keys, so we'll do the same
|
||||
// (see https://github.com/peterbraden/ical.js/pull/84 )
|
||||
var dateKey = date.toISOString().substring(0,10);
|
||||
var curEvent = event;
|
||||
var showRecurrence = true;
|
||||
|
||||
if (timeFilterApplies(now, endDate, dateFilter)) {
|
||||
continue;
|
||||
// Stop parsing this event's recurrences if we've already found maximumEntries worth of recurrences.
|
||||
// (The logic below would still filter the extras, but the check is simple since we're already tracking the count)
|
||||
if (addedEvents >= maximumEntries) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (endDate.format("x") > now) {
|
||||
startDate = moment(date);
|
||||
|
||||
// For each date that we"re checking, it"s possible that there is a recurrence override for that one day.
|
||||
if ((curEvent.recurrences != undefined) && (curEvent.recurrences[dateKey] != undefined))
|
||||
{
|
||||
// We found an override, so for this recurrence, use a potentially different title, start date, and duration.
|
||||
curEvent = curEvent.recurrences[dateKey];
|
||||
startDate = moment(curEvent.start);
|
||||
duration = parseInt(moment(curEvent.end).format("x")) - parseInt(startDate.format("x"));
|
||||
}
|
||||
// If there"s no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
|
||||
else if ((curEvent.exdate != undefined) && (curEvent.exdate[dateKey] != undefined))
|
||||
{
|
||||
// This date is an exception date, which means we should skip it in the recurrence pattern.
|
||||
showRecurrence = false;
|
||||
}
|
||||
|
||||
endDate = moment(parseInt(startDate.format("x")) + duration, "x");
|
||||
if (startDate.format("x") == endDate.format("x")) {
|
||||
endDate = endDate.endOf("day");
|
||||
}
|
||||
|
||||
var recurrenceTitle = getTitleFromEvent(curEvent);
|
||||
|
||||
// If this recurrence ends before the start of the date range, or starts after the end of the date range, don"t add
|
||||
// it to the event list.
|
||||
if (endDate.isBefore(past) || startDate.isAfter(future)) {
|
||||
showRecurrence = false;
|
||||
}
|
||||
|
||||
if (timeFilterApplies(now, endDate, dateFilter)) {
|
||||
showRecurrence = false;
|
||||
}
|
||||
|
||||
if ((showRecurrence === true) && (addedEvents < maximumEntries)) {
|
||||
addedEvents++;
|
||||
newEvents.push({
|
||||
title: title,
|
||||
title: recurrenceTitle,
|
||||
startDate: startDate.format("x"),
|
||||
endDate: endDate.format("x"),
|
||||
fullDayEvent: isFullDayEvent(event),
|
||||
@@ -205,19 +274,27 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
});
|
||||
}
|
||||
}
|
||||
// end recurring event parsing
|
||||
} else {
|
||||
// console.log("Single event ...");
|
||||
// Single event.
|
||||
var fullDayEvent = (isFacebookBirthday) ? true : isFullDayEvent(event);
|
||||
|
||||
if (!fullDayEvent && endDate < new Date()) {
|
||||
//console.log("It's not a fullday event, and it is in the past. So skip: " + title);
|
||||
continue;
|
||||
}
|
||||
if (includePastEvents) {
|
||||
if (endDate < past) {
|
||||
//console.log("Past event is too far in the past. So skip: " + title);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!fullDayEvent && endDate < new Date()) {
|
||||
//console.log("It's not a fullday event, and it is in the past. So skip: " + title);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fullDayEvent && endDate <= today) {
|
||||
//console.log("It's a fullday event, and it is before today. So skip: " + title);
|
||||
continue;
|
||||
if (fullDayEvent && endDate <= today) {
|
||||
//console.log("It's a fullday event, and it is before today. So skip: " + title);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (startDate > future) {
|
||||
@@ -229,6 +306,11 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
continue;
|
||||
}
|
||||
|
||||
// adjust start date so multiple day events will be displayed as happening today even though they started some days ago already
|
||||
if (fullDayEvent && startDate <= today) {
|
||||
startDate = moment(today);
|
||||
}
|
||||
|
||||
// Every thing is good. Add it to the list.
|
||||
|
||||
newEvents.push({
|
||||
@@ -278,7 +360,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
* return bool - The event is a fullday event.
|
||||
*/
|
||||
var isFullDayEvent = function(event) {
|
||||
if (event.start.length === 8) {
|
||||
if (event.start.length === 8 || event.start.dateOnly) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -315,6 +397,24 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
return false;
|
||||
};
|
||||
|
||||
/* getTitleFromEvent(event)
|
||||
* Gets the title from the event.
|
||||
*
|
||||
* argument event object - The event object to check.
|
||||
*
|
||||
* return string - The title of the event, or "Event" if no title is found.
|
||||
*/
|
||||
var getTitleFromEvent = function (event) {
|
||||
var title = "Event";
|
||||
if (event.summary) {
|
||||
title = (typeof event.summary.val !== "undefined") ? event.summary.val : event.summary;
|
||||
} else if (event.description) {
|
||||
title = event.description;
|
||||
}
|
||||
|
||||
return title;
|
||||
};
|
||||
|
||||
var testTitleByFilter = function (title, filter, useRegex, regexFlags) {
|
||||
if (useRegex) {
|
||||
// Assume if leading slash, there is also trailing slash
|
||||
@@ -329,7 +429,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
} else {
|
||||
return title.includes(filter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* public methods */
|
||||
|
||||
@@ -383,8 +483,6 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
|
||||
this.events = function() {
|
||||
return events;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
module.exports = CalendarFetcher;
|
||||
|
@@ -15,6 +15,7 @@ var maximumEntries = 10;
|
||||
var maximumNumberOfDays = 365;
|
||||
var user = "magicmirror";
|
||||
var pass = "MyStrongPass";
|
||||
var broadcastPastEvents = false;
|
||||
|
||||
var auth = {
|
||||
user: user,
|
||||
@@ -23,7 +24,7 @@ var auth = {
|
||||
|
||||
console.log("Create fetcher ...");
|
||||
|
||||
fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays, auth);
|
||||
fetcher = new CalendarFetcher(url, fetchInterval, [], maximumEntries, maximumNumberOfDays, auth);
|
||||
|
||||
fetcher.onReceive(function(fetcher) {
|
||||
console.log(fetcher.events());
|
||||
@@ -37,4 +38,4 @@ fetcher.onError(function(fetcher, error) {
|
||||
|
||||
fetcher.startFetch();
|
||||
|
||||
console.log("Create fetcher done! ");
|
||||
console.log("Create fetcher done! ");
|
||||
|
@@ -24,7 +24,7 @@ module.exports = NodeHelper.create({
|
||||
socketNotificationReceived: function(notification, payload) {
|
||||
if (notification === "ADD_CALENDAR") {
|
||||
//console.log('ADD_CALENDAR: ');
|
||||
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth);
|
||||
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -36,7 +36,7 @@ module.exports = NodeHelper.create({
|
||||
* attribute reloadInterval number - Reload interval in milliseconds.
|
||||
*/
|
||||
|
||||
createFetcher: function(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth) {
|
||||
createFetcher: function(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents) {
|
||||
var self = this;
|
||||
|
||||
if (!validUrl.isUri(url)) {
|
||||
@@ -47,7 +47,7 @@ module.exports = NodeHelper.create({
|
||||
var fetcher;
|
||||
if (typeof self.fetchers[url] === "undefined") {
|
||||
console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval);
|
||||
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth);
|
||||
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents);
|
||||
|
||||
fetcher.onReceive(function(fetcher) {
|
||||
//console.log('Broadcast events.');
|
||||
@@ -60,6 +60,7 @@ module.exports = NodeHelper.create({
|
||||
});
|
||||
|
||||
fetcher.onError(function(fetcher, error) {
|
||||
console.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error);
|
||||
self.sendSocketNotification("FETCH_ERROR", {
|
||||
url: fetcher.url(),
|
||||
error: error
|
||||
|
@@ -1,6 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "4.2"
|
||||
- "8.9"
|
||||
install: npm install
|
||||
|
@@ -1,13 +1,16 @@
|
||||
var ical = require('ical')
|
||||
, months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
'use strict';
|
||||
|
||||
const ical = require('ical');
|
||||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function(err, data){
|
||||
for (var k in data){
|
||||
if (data.hasOwnProperty(k)){
|
||||
var ev = data[k]
|
||||
console.log("Conference", ev.summary, 'is in', ev.location, 'on the', ev.start.getDate(), 'of', months[ev.start.getMonth()] );
|
||||
}
|
||||
}
|
||||
})
|
||||
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function (err, data) {
|
||||
for (let k in data) {
|
||||
if (data.hasOwnProperty(k)) {
|
||||
var ev = data[k];
|
||||
if (data[k].type == 'VEVENT') {
|
||||
console.log(`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${months[ev.start.getMonth()]} at ${ev.start.toLocaleTimeString('en-GB')}`);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
118
modules/default/calendar/vendor/ical.js/example_rrule.js
vendored
Normal file
118
modules/default/calendar/vendor/ical.js/example_rrule.js
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
var ical = require('./node-ical')
|
||||
var moment = require('moment')
|
||||
|
||||
var data = ical.parseFile('./examples/example_rrule.ics');
|
||||
|
||||
// Complicated example demonstrating how to handle recurrence rules and exceptions.
|
||||
|
||||
for (var k in data) {
|
||||
|
||||
// When dealing with calendar recurrences, you need a range of dates to query against,
|
||||
// because otherwise you can get an infinite number of calendar events.
|
||||
var rangeStart = moment("2017-01-01");
|
||||
var rangeEnd = moment("2017-12-31");
|
||||
|
||||
|
||||
var event = data[k]
|
||||
if (event.type === 'VEVENT') {
|
||||
|
||||
var title = event.summary;
|
||||
var startDate = moment(event.start);
|
||||
var endDate = moment(event.end);
|
||||
|
||||
// Calculate the duration of the event for use with recurring events.
|
||||
var duration = parseInt(endDate.format("x")) - parseInt(startDate.format("x"));
|
||||
|
||||
// Simple case - no recurrences, just print out the calendar event.
|
||||
if (typeof event.rrule === 'undefined')
|
||||
{
|
||||
console.log('title:' + title);
|
||||
console.log('startDate:' + startDate.format('MMMM Do YYYY, h:mm:ss a'));
|
||||
console.log('endDate:' + endDate.format('MMMM Do YYYY, h:mm:ss a'));
|
||||
console.log('duration:' + moment.duration(duration).humanize());
|
||||
console.log();
|
||||
}
|
||||
|
||||
// Complicated case - if an RRULE exists, handle multiple recurrences of the event.
|
||||
else if (typeof event.rrule !== 'undefined')
|
||||
{
|
||||
// For recurring events, get the set of event start dates that fall within the range
|
||||
// of dates we're looking for.
|
||||
var dates = event.rrule.between(
|
||||
rangeStart.toDate(),
|
||||
rangeEnd.toDate(),
|
||||
true,
|
||||
function(date, i) {return true;}
|
||||
)
|
||||
|
||||
// The "dates" array contains the set of dates within our desired date range range that are valid
|
||||
// for the recurrence rule. *However*, it's possible for us to have a specific recurrence that
|
||||
// had its date changed from outside the range to inside the range. One way to handle this is
|
||||
// to add *all* recurrence override entries into the set of dates that we check, and then later
|
||||
// filter out any recurrences that don't actually belong within our range.
|
||||
if (event.recurrences != undefined)
|
||||
{
|
||||
for (var r in event.recurrences)
|
||||
{
|
||||
// Only add dates that weren't already in the range we added from the rrule so that
|
||||
// we don't double-add those events.
|
||||
if (moment(new Date(r)).isBetween(rangeStart, rangeEnd) != true)
|
||||
{
|
||||
dates.push(new Date(r));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through the set of date entries to see which recurrences should be printed.
|
||||
for(var i in dates) {
|
||||
|
||||
var date = dates[i];
|
||||
var curEvent = event;
|
||||
var showRecurrence = true;
|
||||
var curDuration = duration;
|
||||
|
||||
startDate = moment(date);
|
||||
|
||||
// Use just the date of the recurrence to look up overrides and exceptions (i.e. chop off time information)
|
||||
var dateLookupKey = date.toISOString().substring(0, 10);
|
||||
|
||||
// For each date that we're checking, it's possible that there is a recurrence override for that one day.
|
||||
if ((curEvent.recurrences != undefined) && (curEvent.recurrences[dateLookupKey] != undefined))
|
||||
{
|
||||
// We found an override, so for this recurrence, use a potentially different title, start date, and duration.
|
||||
curEvent = curEvent.recurrences[dateLookupKey];
|
||||
startDate = moment(curEvent.start);
|
||||
curDuration = parseInt(moment(curEvent.end).format("x")) - parseInt(startDate.format("x"));
|
||||
}
|
||||
// If there's no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
|
||||
else if ((curEvent.exdate != undefined) && (curEvent.exdate[dateLookupKey] != undefined))
|
||||
{
|
||||
// This date is an exception date, which means we should skip it in the recurrence pattern.
|
||||
showRecurrence = false;
|
||||
}
|
||||
|
||||
// Set the the title and the end date from either the regular event or the recurrence override.
|
||||
var recurrenceTitle = curEvent.summary;
|
||||
endDate = moment(parseInt(startDate.format("x")) + curDuration, 'x');
|
||||
|
||||
// If this recurrence ends before the start of the date range, or starts after the end of the date range,
|
||||
// don't process it.
|
||||
if (endDate.isBefore(rangeStart) || startDate.isAfter(rangeEnd)) {
|
||||
showRecurrence = false;
|
||||
}
|
||||
|
||||
if (showRecurrence === true) {
|
||||
|
||||
console.log('title:' + recurrenceTitle);
|
||||
console.log('startDate:' + startDate.format('MMMM Do YYYY, h:mm:ss a'));
|
||||
console.log('endDate:' + endDate.format('MMMM Do YYYY, h:mm:ss a'));
|
||||
console.log('duration:' + moment.duration(curDuration).humanize());
|
||||
console.log();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
40
modules/default/calendar/vendor/ical.js/examples/example_rrule.ics
vendored
Normal file
40
modules/default/calendar/vendor/ical.js/examples/example_rrule.ics
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:-//Google Inc//Google Calendar 70.9054//EN
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:PUBLISH
|
||||
X-WR-CALNAME:ical
|
||||
X-WR-TIMEZONE:US/Central
|
||||
X-WR-CALDESC:
|
||||
BEGIN:VEVENT
|
||||
UID:98765432-ABCD-DCBB-999A-987765432123
|
||||
DTSTART;TZID=US/Central:20170601T090000
|
||||
DTEND;TZID=US/Central:20170601T170000
|
||||
DTSTAMP:20170727T044436Z
|
||||
EXDATE;TZID=US/Central:20170706T090000,20170713T090000,20170720T090000,20
|
||||
170803T090000
|
||||
LAST-MODIFIED:20170727T044435Z
|
||||
RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20170814T045959Z;BYDAY=TH
|
||||
SEQUENCE:0
|
||||
SUMMARY:Recurring weekly meeting from June 1 - Aug 14 (except July 6, July 13, July 20, Aug 3)
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:98765432-ABCD-DCBB-999A-987765432123
|
||||
RECURRENCE-ID;TZID=US/Central:20170629T090000
|
||||
DTSTART;TZID=US/Central:20170703T090000
|
||||
DTEND;TZID=US/Central:20170703T120000
|
||||
DTSTAMP:20170727T044436Z
|
||||
LAST-MODIFIED:20170216T143445Z
|
||||
SEQUENCE:0
|
||||
SUMMARY:Last meeting in June moved to Monday July 3 and shortened to half day
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:12354454-ABCD-DCBB-999A-2349872354897
|
||||
DTSTART;TZID=US/Central:20171201T130000
|
||||
DTEND;TZID=US/Central:20171201T150000
|
||||
DTSTAMP:20170727T044436Z
|
||||
LAST-MODIFIED:20170727T044435Z
|
||||
SEQUENCE:0
|
||||
SUMMARY:Single event on Dec 1
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
295
modules/default/calendar/vendor/ical.js/ical.js
vendored
295
modules/default/calendar/vendor/ical.js/ical.js
vendored
@@ -33,9 +33,9 @@
|
||||
for (var i = 0; i<p.length; i++){
|
||||
if (p[i].indexOf('=') > -1){
|
||||
var segs = p[i].split('=');
|
||||
|
||||
|
||||
out[segs[0]] = parseValue(segs.slice(1).join('='));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return out || sp
|
||||
@@ -44,7 +44,7 @@
|
||||
var parseValue = function(val){
|
||||
if ('TRUE' === val)
|
||||
return true;
|
||||
|
||||
|
||||
if ('FALSE' === val)
|
||||
return false;
|
||||
|
||||
@@ -55,75 +55,52 @@
|
||||
return val;
|
||||
}
|
||||
|
||||
var storeParam = function(name){
|
||||
return function(val, params, curr){
|
||||
var data;
|
||||
if (params && params.length && !(params.length==1 && params[0]==='CHARSET=utf-8')){
|
||||
data = {params:parseParams(params), val:text(val)}
|
||||
}
|
||||
else
|
||||
data = text(val)
|
||||
var storeValParam = function (name) {
|
||||
return function (val, curr) {
|
||||
var current = curr[name];
|
||||
if (Array.isArray(current)) {
|
||||
current.push(val);
|
||||
return curr;
|
||||
}
|
||||
|
||||
var current = curr[name];
|
||||
if (Array.isArray(current)){
|
||||
current.push(data);
|
||||
return curr;
|
||||
}
|
||||
if (current != null) {
|
||||
curr[name] = [current, val];
|
||||
return curr;
|
||||
}
|
||||
|
||||
if (current != null){
|
||||
curr[name] = [current, data];
|
||||
return curr;
|
||||
curr[name] = val;
|
||||
return curr
|
||||
}
|
||||
|
||||
curr[name] = data;
|
||||
return curr
|
||||
}
|
||||
}
|
||||
|
||||
var addTZ = function(dt, params){
|
||||
var storeParam = function (name) {
|
||||
return function (val, params, curr) {
|
||||
var data;
|
||||
if (params && params.length && !(params.length == 1 && params[0] === 'CHARSET=utf-8')) {
|
||||
data = { params: parseParams(params), val: text(val) }
|
||||
}
|
||||
else
|
||||
data = text(val)
|
||||
|
||||
return storeValParam(name)(data, curr);
|
||||
}
|
||||
}
|
||||
|
||||
var addTZ = function (dt, params) {
|
||||
var p = parseParams(params);
|
||||
|
||||
if (params && p && dt){
|
||||
if (params && p){
|
||||
dt.tz = p.TZID
|
||||
}
|
||||
|
||||
return dt
|
||||
}
|
||||
|
||||
var parseTimestamp = function(val){
|
||||
//typical RFC date-time format
|
||||
var comps = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(Z)?$/.exec(val);
|
||||
if (comps !== null) {
|
||||
if (comps[7] == 'Z'){ // GMT
|
||||
return new Date(Date.UTC(
|
||||
parseInt(comps[1], 10),
|
||||
parseInt(comps[2], 10)-1,
|
||||
parseInt(comps[3], 10),
|
||||
parseInt(comps[4], 10),
|
||||
parseInt(comps[5], 10),
|
||||
parseInt(comps[6], 10 )
|
||||
));
|
||||
// TODO add tz
|
||||
} else {
|
||||
return new Date(
|
||||
parseInt(comps[1], 10),
|
||||
parseInt(comps[2], 10)-1,
|
||||
parseInt(comps[3], 10),
|
||||
parseInt(comps[4], 10),
|
||||
parseInt(comps[5], 10),
|
||||
parseInt(comps[6], 10)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var dateParam = function(name){
|
||||
return function(val, params, curr){
|
||||
return function (val, params, curr) {
|
||||
|
||||
var newDate = text(val);
|
||||
|
||||
// Store as string - worst case scenario
|
||||
storeParam(name)(val, undefined, curr)
|
||||
|
||||
if (params && params[0] === "VALUE=DATE") {
|
||||
// Just Date
|
||||
@@ -131,47 +108,54 @@
|
||||
var comps = /^(\d{4})(\d{2})(\d{2})$/.exec(val);
|
||||
if (comps !== null) {
|
||||
// No TZ info - assume same timezone as this computer
|
||||
curr[name] = new Date(
|
||||
newDate = new Date(
|
||||
comps[1],
|
||||
parseInt(comps[2], 10)-1,
|
||||
comps[3]
|
||||
);
|
||||
|
||||
curr[name] = addTZ(curr[name], params);
|
||||
return curr;
|
||||
newDate = addTZ(newDate, params);
|
||||
newDate.dateOnly = true;
|
||||
|
||||
// Store as string - worst case scenario
|
||||
return storeValParam(name)(newDate, curr)
|
||||
}
|
||||
}
|
||||
|
||||
curr[name] = []
|
||||
val.split(',').forEach(function(val){
|
||||
var newDate = parseTimestamp(val);
|
||||
curr[name].push(addTZ(newDate, params));
|
||||
});
|
||||
|
||||
if (curr[name].length === 0){
|
||||
delete curr[name];
|
||||
} else if (curr[name].length === 1){
|
||||
curr[name] = curr[name][0];
|
||||
}
|
||||
//typical RFC date-time format
|
||||
var comps = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(Z)?$/.exec(val);
|
||||
if (comps !== null) {
|
||||
if (comps[7] == 'Z'){ // GMT
|
||||
newDate = new Date(Date.UTC(
|
||||
parseInt(comps[1], 10),
|
||||
parseInt(comps[2], 10)-1,
|
||||
parseInt(comps[3], 10),
|
||||
parseInt(comps[4], 10),
|
||||
parseInt(comps[5], 10),
|
||||
parseInt(comps[6], 10 )
|
||||
));
|
||||
// TODO add tz
|
||||
} else {
|
||||
newDate = new Date(
|
||||
parseInt(comps[1], 10),
|
||||
parseInt(comps[2], 10)-1,
|
||||
parseInt(comps[3], 10),
|
||||
parseInt(comps[4], 10),
|
||||
parseInt(comps[5], 10),
|
||||
parseInt(comps[6], 10)
|
||||
);
|
||||
}
|
||||
|
||||
return curr;
|
||||
newDate = addTZ(newDate, params);
|
||||
}
|
||||
|
||||
|
||||
// Store as string - worst case scenario
|
||||
return storeValParam(name)(newDate, curr)
|
||||
}
|
||||
}
|
||||
|
||||
var exdateParam = function(name){
|
||||
return function(val, params, curr){
|
||||
var date = dateParam(name)(val, params, curr);
|
||||
if (date.exdates === undefined) {
|
||||
date.exdates = [];
|
||||
}
|
||||
if (Array.isArray(date.exdate)){
|
||||
date.exdates = date.exdates.concat(date.exdate);
|
||||
} else {
|
||||
date.exdates.push(date.exdate);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
var geoParam = function(name){
|
||||
return function(val, params, curr){
|
||||
@@ -195,7 +179,52 @@
|
||||
}
|
||||
}
|
||||
|
||||
var addFBType = function(fb, params){
|
||||
// EXDATE is an entry that represents exceptions to a recurrence rule (ex: "repeat every day except on 7/4").
|
||||
// The EXDATE entry itself can also contain a comma-separated list, so we make sure to parse each date out separately.
|
||||
// There can also be more than one EXDATE entries in a calendar record.
|
||||
// Since there can be multiple dates, we create an array of them. The index into the array is the ISO string of the date itself, for ease of use.
|
||||
// i.e. You can check if ((curr.exdate != undefined) && (curr.exdate[date iso string] != undefined)) to see if a date is an exception.
|
||||
// NOTE: This specifically uses date only, and not time. This is to avoid a few problems:
|
||||
// 1. The ISO string with time wouldn't work for "floating dates" (dates without timezones).
|
||||
// ex: "20171225T060000" - this is supposed to mean 6 AM in whatever timezone you're currently in
|
||||
// 2. Daylight savings time potentially affects the time you would need to look up
|
||||
// 3. Some EXDATE entries in the wild seem to have times different from the recurrence rule, but are still excluded by calendar programs. Not sure how or why.
|
||||
// These would fail any sort of sane time lookup, because the time literally doesn't match the event. So we'll ignore time and just use date.
|
||||
// ex: DTSTART:20170814T140000Z
|
||||
// RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=2;BYDAY=MO,TU
|
||||
// EXDATE:20171219T060000
|
||||
// Even though "T060000" doesn't match or overlap "T1400000Z", it's still supposed to be excluded? Odd. :(
|
||||
// TODO: See if this causes any problems with events that recur multiple times a day.
|
||||
var exdateParam = function (name) {
|
||||
return function (val, params, curr) {
|
||||
var separatorPattern = /\s*,\s*/g;
|
||||
curr[name] = curr[name] || [];
|
||||
var dates = val ? val.split(separatorPattern) : [];
|
||||
dates.forEach(function (entry) {
|
||||
var exdate = new Array();
|
||||
dateParam(name)(entry, params, exdate);
|
||||
|
||||
if (exdate[name])
|
||||
{
|
||||
if (typeof exdate[name].toISOString === 'function') {
|
||||
curr[name][exdate[name].toISOString().substring(0, 10)] = exdate[name];
|
||||
} else {
|
||||
console.error("No toISOString function in exdate[name]", exdate[name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
return curr;
|
||||
}
|
||||
}
|
||||
|
||||
// RECURRENCE-ID is the ID of a specific recurrence within a recurrence rule.
|
||||
// TODO: It's also possible for it to have a range, like "THISANDPRIOR", "THISANDFUTURE". This isn't currently handled.
|
||||
var recurrenceParam = function (name) {
|
||||
return dateParam(name);
|
||||
}
|
||||
|
||||
var addFBType = function (fb, params) {
|
||||
var p = parseParams(params);
|
||||
|
||||
if (params && p){
|
||||
@@ -239,7 +268,7 @@
|
||||
//scan all high level object in curr and drop all strings
|
||||
var key,
|
||||
obj;
|
||||
|
||||
|
||||
for (key in curr) {
|
||||
if(curr.hasOwnProperty(key)) {
|
||||
obj = curr[key];
|
||||
@@ -248,14 +277,93 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return curr
|
||||
}
|
||||
|
||||
|
||||
var par = stack.pop()
|
||||
|
||||
if (curr.uid)
|
||||
par[curr.uid] = curr
|
||||
{
|
||||
// If this is the first time we run into this UID, just save it.
|
||||
if (par[curr.uid] === undefined)
|
||||
{
|
||||
par[curr.uid] = curr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we have multiple ical entries with the same UID, it's either going to be a
|
||||
// modification to a recurrence (RECURRENCE-ID), and/or a significant modification
|
||||
// to the entry (SEQUENCE).
|
||||
|
||||
// TODO: Look into proper sequence logic.
|
||||
|
||||
if (curr.recurrenceid === undefined)
|
||||
{
|
||||
// If we have the same UID as an existing record, and it *isn't* a specific recurrence ID,
|
||||
// not quite sure what the correct behaviour should be. For now, just take the new information
|
||||
// and merge it with the old record by overwriting only the fields that appear in the new record.
|
||||
var key;
|
||||
for (key in curr) {
|
||||
par[curr.uid][key] = curr[key];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// If we have recurrence-id entries, list them as an array of recurrences keyed off of recurrence-id.
|
||||
// To use - as you're running through the dates of an rrule, you can try looking it up in the recurrences
|
||||
// array. If it exists, then use the data from the calendar object in the recurrence instead of the parent
|
||||
// for that day.
|
||||
|
||||
// NOTE: Sometimes the RECURRENCE-ID record will show up *before* the record with the RRULE entry. In that
|
||||
// case, what happens is that the RECURRENCE-ID record ends up becoming both the parent record and an entry
|
||||
// in the recurrences array, and then when we process the RRULE entry later it overwrites the appropriate
|
||||
// fields in the parent record.
|
||||
|
||||
if (curr.recurrenceid != null)
|
||||
{
|
||||
|
||||
// TODO: Is there ever a case where we have to worry about overwriting an existing entry here?
|
||||
|
||||
// Create a copy of the current object to save in our recurrences array. (We *could* just do par = curr,
|
||||
// except for the case that we get the RECURRENCE-ID record before the RRULE record. In that case, we
|
||||
// would end up with a shared reference that would cause us to overwrite *both* records at the point
|
||||
// that we try and fix up the parent record.)
|
||||
var recurrenceObj = new Object();
|
||||
var key;
|
||||
for (key in curr) {
|
||||
recurrenceObj[key] = curr[key];
|
||||
}
|
||||
|
||||
if (recurrenceObj.recurrences != undefined) {
|
||||
delete recurrenceObj.recurrences;
|
||||
}
|
||||
|
||||
|
||||
// If we don't have an array to store recurrences in yet, create it.
|
||||
if (par[curr.uid].recurrences === undefined) {
|
||||
par[curr.uid].recurrences = new Array();
|
||||
}
|
||||
|
||||
// Save off our cloned recurrence object into the array, keyed by date but not time.
|
||||
// We key by date only to avoid timezone and "floating time" problems (where the time isn't associated with a timezone).
|
||||
// TODO: See if this causes a problem with events that have multiple recurrences per day.
|
||||
if (typeof curr.recurrenceid.toISOString === 'function') {
|
||||
par[curr.uid].recurrences[curr.recurrenceid.toISOString().substring(0,10)] = recurrenceObj;
|
||||
} else {
|
||||
console.error("No toISOString function in curr.recurrenceid", curr.recurrenceid);
|
||||
}
|
||||
}
|
||||
|
||||
// One more specific fix - in the case that an RRULE entry shows up after a RECURRENCE-ID entry,
|
||||
// let's make sure to clear the recurrenceid off the parent field.
|
||||
if ((par[curr.uid].rrule != undefined) && (par[curr.uid].recurrenceid != undefined))
|
||||
{
|
||||
delete par[curr.uid].recurrenceid;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
par[Math.random()*100000] = curr // Randomly assign ID : TODO - use true GUID
|
||||
|
||||
@@ -277,6 +385,11 @@
|
||||
, 'COMPLETED': dateParam('completed')
|
||||
, 'CATEGORIES': categoriesParam('categories')
|
||||
, 'FREEBUSY': freebusyParam('freebusy')
|
||||
, 'DTSTAMP': dateParam('dtstamp')
|
||||
, 'CREATED': dateParam('created')
|
||||
, 'LAST-MODIFIED': dateParam('lastmodified')
|
||||
, 'RECURRENCE-ID': recurrenceParam('recurrenceid')
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -292,7 +405,7 @@
|
||||
name = name.substring(2);
|
||||
return (storeParam(name))(val, params, ctx, stack, line);
|
||||
}
|
||||
|
||||
|
||||
return storeParam(name.toLowerCase())(val, params, ctx);
|
||||
},
|
||||
|
||||
|
@@ -6,9 +6,16 @@ exports.fromURL = function(url, opts, cb){
|
||||
if (!cb)
|
||||
return;
|
||||
request(url, opts, function(err, r, data){
|
||||
if (err)
|
||||
return cb(err, null);
|
||||
cb(undefined, ical.parseICS(data));
|
||||
if (err)
|
||||
{
|
||||
return cb(err, null);
|
||||
}
|
||||
else if (r.statusCode != 200)
|
||||
{
|
||||
return cb(r.statusCode + ": " + r.statusMessage, null);
|
||||
}
|
||||
|
||||
cb(undefined, ical.parseICS(data));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,40 +24,43 @@ exports.parseFile = function(filename){
|
||||
}
|
||||
|
||||
|
||||
var rrule = require('rrule-alt').RRule
|
||||
var rrulestr = rrule.rrulestr
|
||||
var rrule = require('rrule').RRule
|
||||
|
||||
ical.objectHandlers['RRULE'] = function(val, params, curr, stack, line){
|
||||
curr.rrule = line;
|
||||
return curr
|
||||
}
|
||||
var originalEnd = ical.objectHandlers['END'];
|
||||
ical.objectHandlers['END'] = function(val, params, curr, stack){
|
||||
if (curr.rrule) {
|
||||
var rule = curr.rrule;
|
||||
if (rule.indexOf('DTSTART') === -1) {
|
||||
ical.objectHandlers['END'] = function (val, params, curr, stack) {
|
||||
// Recurrence rules are only valid for VEVENT, VTODO, and VJOURNAL.
|
||||
// More specifically, we need to filter the VCALENDAR type because we might end up with a defined rrule
|
||||
// due to the subtypes.
|
||||
if ((val === "VEVENT") || (val === "VTODO") || (val === "VJOURNAL")) {
|
||||
if (curr.rrule) {
|
||||
var rule = curr.rrule.replace('RRULE:', '');
|
||||
if (rule.indexOf('DTSTART') === -1) {
|
||||
|
||||
if (curr.start.length === 8) {
|
||||
var comps = /^(\d{4})(\d{2})(\d{2})$/.exec(curr.start);
|
||||
if (comps) {
|
||||
curr.start = new Date (comps[1], comps[2] - 1, comps[3]);
|
||||
}
|
||||
}
|
||||
if (curr.start.length === 8) {
|
||||
var comps = /^(\d{4})(\d{2})(\d{2})$/.exec(curr.start);
|
||||
if (comps) {
|
||||
curr.start = new Date(comps[1], comps[2] - 1, comps[3]);
|
||||
}
|
||||
}
|
||||
|
||||
rule += ' DTSTART:' + curr.start.toISOString().replace(/[-:]/g, '');
|
||||
rule = rule.replace(/\.[0-9]{3}/, '');
|
||||
}
|
||||
for (var i in curr.exdates) {
|
||||
rule += ' EXDATE:' + curr.exdates[i].toISOString().replace(/[-:]/g, '');
|
||||
rule = rule.replace(/\.[0-9]{3}/, '');
|
||||
}
|
||||
try {
|
||||
curr.rrule = rrulestr(rule);
|
||||
}
|
||||
catch(err) {
|
||||
console.log("Unrecognised element in calendar feed, ignoring: " + rule);
|
||||
curr.rrule = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof curr.start.toISOString === 'function') {
|
||||
try {
|
||||
rule += ';DTSTART=' + curr.start.toISOString().replace(/[-:]/g, '');
|
||||
rule = rule.replace(/\.[0-9]{3}/, '');
|
||||
} catch (error) {
|
||||
console.error("ERROR when trying to convert to ISOString", error);
|
||||
}
|
||||
} else {
|
||||
console.error("No toISOString function in curr.start", curr.start);
|
||||
}
|
||||
}
|
||||
curr.rrule = rrule.fromString(rule);
|
||||
}
|
||||
}
|
||||
return originalEnd.call(this, val, params, curr, stack);
|
||||
}
|
||||
|
@@ -10,17 +10,18 @@
|
||||
],
|
||||
"homepage": "https://github.com/peterbraden/ical.js",
|
||||
"author": "Peter Braden <peterbraden@peterbraden.co.uk> (peterbraden.co.uk)",
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/peterbraden/ical.js.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"request": "2.68.0",
|
||||
"rrule": "2.0.0"
|
||||
"request": "^2.88.0",
|
||||
"rrule": "2.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vows": "0.7.0",
|
||||
"underscore": "1.3.0"
|
||||
"vows": "0.8.2",
|
||||
"underscore": "1.9.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./node_modules/vows/bin/vows ./test/test.js"
|
||||
|
@@ -7,6 +7,7 @@ A tolerant, minimal icalendar parser for javascript/node
|
||||
(http://tools.ietf.org/html/rfc5545)
|
||||
|
||||
|
||||
|
||||
## Install - Node.js ##
|
||||
|
||||
ical.js is availble on npm:
|
||||
@@ -33,19 +34,29 @@ Use the request library to fetch the specified URL (```opts``` gets passed on to
|
||||
|
||||
## Example 1 - Print list of upcoming node conferences (see example.js)
|
||||
```javascript
|
||||
var ical = require('ical')
|
||||
, months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
'use strict';
|
||||
|
||||
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function(err, data) {
|
||||
for (var k in data){
|
||||
if (data.hasOwnProperty(k)) {
|
||||
var ev = data[k]
|
||||
console.log("Conference",
|
||||
ev.summary,
|
||||
'is in',
|
||||
ev.location,
|
||||
'on the', ev.start.getDate(), 'of', months[ev.start.getMonth()]);
|
||||
}
|
||||
}
|
||||
});
|
||||
const ical = require('ical');
|
||||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
ical.fromURL('http://lanyrd.com/topics/nodejs/nodejs.ics', {}, function (err, data) {
|
||||
for (let k in data) {
|
||||
if (data.hasOwnProperty(k)) {
|
||||
var ev = data[k];
|
||||
if (data[k].type == 'VEVENT') {
|
||||
console.log(`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${months[ev.start.getMonth()]} at ${ev.start.toLocaleTimeString('en-GB')}`);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Recurrences and Exceptions ##
|
||||
Calendar events with recurrence rules can be significantly more complicated to handle correctly. There are three parts to handling them:
|
||||
|
||||
1. rrule - the recurrence rule specifying the pattern of recurring dates and times for the event.
|
||||
2. recurrences - an optional array of event data that can override specific occurrences of the event.
|
||||
3. exdate - an optional array of dates that should be excluded from the recurrence pattern.
|
||||
|
||||
See example_rrule.js for an example of handling recurring calendar events.
|
||||
|
131
modules/default/calendar/vendor/ical.js/test/test.js
vendored
131
modules/default/calendar/vendor/ical.js/test/test.js
vendored
@@ -43,6 +43,12 @@ vows.describe('node-ical').addBatch({
|
||||
, 'has a summary (invalid colon handling tolerance)' : function(topic){
|
||||
assert.equal(topic.summary, '[Async]: Everything Express')
|
||||
}
|
||||
, 'has a date only start datetime' : function(topic){
|
||||
assert.equal(topic.start.dateOnly, true)
|
||||
}
|
||||
, 'has a date only end datetime' : function(topic){
|
||||
assert.equal(topic.end.dateOnly, true)
|
||||
}
|
||||
}
|
||||
, 'event d4c8' :{
|
||||
topic : function(events){
|
||||
@@ -108,7 +114,7 @@ vows.describe('node-ical').addBatch({
|
||||
assert.equal(topic.end.getFullYear(), 1998);
|
||||
assert.equal(topic.end.getUTCMonth(), 2);
|
||||
assert.equal(topic.end.getUTCDate(), 15);
|
||||
assert.equal(topic.end.getUTCHours(), 0);
|
||||
assert.equal(topic.end.getUTCHours(), 00);
|
||||
assert.equal(topic.end.getUTCMinutes(), 30);
|
||||
}
|
||||
}
|
||||
@@ -146,7 +152,7 @@ vows.describe('node-ical').addBatch({
|
||||
}
|
||||
, 'has a start datetime' : function(topic) {
|
||||
assert.equal(topic.start.getFullYear(), 2011);
|
||||
assert.equal(topic.start.getMonth(), 9);
|
||||
assert.equal(topic.start.getMonth(), 09);
|
||||
assert.equal(topic.start.getDate(), 11);
|
||||
}
|
||||
|
||||
@@ -192,12 +198,12 @@ vows.describe('node-ical').addBatch({
|
||||
}
|
||||
, 'has a start' : function(topic){
|
||||
assert.equal(topic.start.tz, 'America/Phoenix')
|
||||
assert.equal(topic.start.toISOString(), new Date(2011, 10, 9, 19, 0,0).toISOString())
|
||||
assert.equal(topic.start.toISOString(), new Date(2011, 10, 09, 19, 0,0).toISOString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
, 'with test6.ics (testing assembly.org)' : {
|
||||
, 'with test6.ics (testing assembly.org)': {
|
||||
topic: function () {
|
||||
return ical.parseFile('./test/test6.ics')
|
||||
}
|
||||
@@ -208,13 +214,13 @@ vows.describe('node-ical').addBatch({
|
||||
})[0];
|
||||
}
|
||||
, 'has a start' : function(topic){
|
||||
assert.equal(topic.start.toISOString(), new Date(2011, 7, 4, 12, 0,0).toISOString())
|
||||
assert.equal(topic.start.toISOString(), new Date(2011, 07, 04, 12, 0,0).toISOString())
|
||||
}
|
||||
}
|
||||
, 'event with rrule' :{
|
||||
topic: function(events){
|
||||
return _.select(_.values(events), function(x){
|
||||
return x.summary == "foobarTV broadcast starts"
|
||||
return x.summary === "foobarTV broadcast starts"
|
||||
})[0];
|
||||
}
|
||||
, "Has an RRULE": function(topic){
|
||||
@@ -249,7 +255,7 @@ vows.describe('node-ical').addBatch({
|
||||
},
|
||||
'task completed': function(task){
|
||||
assert.equal(task.completion, 100);
|
||||
assert.equal(task.completed.toISOString(), new Date(2013, 6, 16, 10, 57, 45).toISOString());
|
||||
assert.equal(task.completed.toISOString(), new Date(2013, 06, 16, 10, 57, 45).toISOString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +278,7 @@ vows.describe('node-ical').addBatch({
|
||||
},
|
||||
'grabbing custom properties': {
|
||||
topic: function(topic) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -367,14 +373,115 @@ vows.describe('node-ical').addBatch({
|
||||
assert.equal(topic.end.getFullYear(), 2014);
|
||||
assert.equal(topic.end.getMonth(), 3);
|
||||
assert.equal(topic.end.getUTCHours(), 19);
|
||||
assert.equal(topic.end.getUTCMinutes(), 0);
|
||||
assert.equal(topic.end.getUTCMinutes(), 00);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
'url request errors' : {
|
||||
, 'with test12.ics (testing recurrences and exdates)': {
|
||||
topic: function () {
|
||||
return ical.parseFile('./test/test12.ics')
|
||||
}
|
||||
, 'event with rrule': {
|
||||
topic: function (events) {
|
||||
return _.select(_.values(events), function (x) {
|
||||
return x.uid === '0000001';
|
||||
})[0];
|
||||
}
|
||||
, "Has an RRULE": function (topic) {
|
||||
assert.notEqual(topic.rrule, undefined);
|
||||
}
|
||||
, "Has summary Treasure Hunting": function (topic) {
|
||||
assert.equal(topic.summary, 'Treasure Hunting');
|
||||
}
|
||||
, "Has two EXDATES": function (topic) {
|
||||
assert.notEqual(topic.exdate, undefined);
|
||||
assert.notEqual(topic.exdate[new Date(2015, 06, 08, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
assert.notEqual(topic.exdate[new Date(2015, 06, 10, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
}
|
||||
, "Has a RECURRENCE-ID override": function (topic) {
|
||||
assert.notEqual(topic.recurrences, undefined);
|
||||
assert.notEqual(topic.recurrences[new Date(2015, 06, 07, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
assert.equal(topic.recurrences[new Date(2015, 06, 07, 12, 0, 0).toISOString().substring(0, 10)].summary, 'More Treasure Hunting');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
, 'with test13.ics (testing recurrence-id before rrule)': {
|
||||
topic: function () {
|
||||
return ical.parseFile('./test/test13.ics')
|
||||
}
|
||||
, 'event with rrule': {
|
||||
topic: function (events) {
|
||||
return _.select(_.values(events), function (x) {
|
||||
return x.uid === '6m2q7kb2l02798oagemrcgm6pk@google.com';
|
||||
})[0];
|
||||
}
|
||||
, "Has an RRULE": function (topic) {
|
||||
assert.notEqual(topic.rrule, undefined);
|
||||
}
|
||||
, "Has summary 'repeated'": function (topic) {
|
||||
assert.equal(topic.summary, 'repeated');
|
||||
}
|
||||
, "Has a RECURRENCE-ID override": function (topic) {
|
||||
assert.notEqual(topic.recurrences, undefined);
|
||||
assert.notEqual(topic.recurrences[new Date(2016, 7, 26, 14, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
assert.equal(topic.recurrences[new Date(2016, 7, 26, 14, 0, 0).toISOString().substring(0, 10)].summary, 'bla bla');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
, 'with test14.ics (testing comma-separated exdates)': {
|
||||
topic: function () {
|
||||
return ical.parseFile('./test/test14.ics')
|
||||
}
|
||||
, 'event with comma-separated exdate': {
|
||||
topic: function (events) {
|
||||
return _.select(_.values(events), function (x) {
|
||||
return x.uid === '98765432-ABCD-DCBB-999A-987765432123';
|
||||
})[0];
|
||||
}
|
||||
, "Has summary 'Example of comma-separated exdates'": function (topic) {
|
||||
assert.equal(topic.summary, 'Example of comma-separated exdates');
|
||||
}
|
||||
, "Has four comma-separated EXDATES": function (topic) {
|
||||
assert.notEqual(topic.exdate, undefined);
|
||||
// Verify the four comma-separated EXDATES are there
|
||||
assert.notEqual(topic.exdate[new Date(2017, 6, 6, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
assert.notEqual(topic.exdate[new Date(2017, 6, 17, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
assert.notEqual(topic.exdate[new Date(2017, 6, 20, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
assert.notEqual(topic.exdate[new Date(2017, 7, 3, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
// Verify an arbitrary date isn't there
|
||||
assert.equal(topic.exdate[new Date(2017, 4, 5, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
, 'with test14.ics (testing exdates with bad times)': {
|
||||
topic: function () {
|
||||
return ical.parseFile('./test/test14.ics')
|
||||
}
|
||||
, 'event with exdates with bad times': {
|
||||
topic: function (events) {
|
||||
return _.select(_.values(events), function (x) {
|
||||
return x.uid === '1234567-ABCD-ABCD-ABCD-123456789012';
|
||||
})[0];
|
||||
}
|
||||
, "Has summary 'Example of exdate with bad times'": function (topic) {
|
||||
assert.equal(topic.summary, 'Example of exdate with bad times');
|
||||
}
|
||||
, "Has two EXDATES even though they have bad times": function (topic) {
|
||||
assert.notEqual(topic.exdate, undefined);
|
||||
// Verify the two EXDATES are there, even though they have bad times
|
||||
assert.notEqual(topic.exdate[new Date(2017, 11, 18, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
assert.notEqual(topic.exdate[new Date(2017, 11, 19, 12, 0, 0).toISOString().substring(0, 10)], undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
, 'url request errors': {
|
||||
topic : function () {
|
||||
ical.fromURL('http://not.exist/', {}, this.callback);
|
||||
ical.fromURL('http://255.255.255.255/', {}, this.callback);
|
||||
}
|
||||
, 'are passed back to the callback' : function (err, result) {
|
||||
assert.instanceOf(err, Error);
|
||||
|
19
modules/default/calendar/vendor/ical.js/test/test12.ics
vendored
Normal file
19
modules/default/calendar/vendor/ical.js/test/test12.ics
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:0000001
|
||||
SUMMARY:Treasure Hunting
|
||||
DTSTART;TZID=America/Los_Angeles:20150706T120000
|
||||
DTEND;TZID=America/Los_Angeles:20150706T130000
|
||||
RRULE:FREQ=DAILY;COUNT=10
|
||||
EXDATE;TZID=America/Los_Angeles:20150708T120000
|
||||
EXDATE;TZID=America/Los_Angeles:20150710T120000
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:0000001
|
||||
SUMMARY:More Treasure Hunting
|
||||
LOCATION:The other island
|
||||
DTSTART;TZID=America/Los_Angeles:20150709T150000
|
||||
DTEND;TZID=America/Los_Angeles:20150707T160000
|
||||
RECURRENCE-ID;TZID=America/Los_Angeles:20150707T120000
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
57
modules/default/calendar/vendor/ical.js/test/test13.ics
vendored
Normal file
57
modules/default/calendar/vendor/ical.js/test/test13.ics
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:-//Google Inc//Google Calendar 70.9054//EN
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:PUBLISH
|
||||
X-WR-CALNAME:ical
|
||||
X-WR-TIMEZONE:Europe/Kiev
|
||||
X-WR-CALDESC:
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Kiev
|
||||
X-LIC-LOCATION:Europe/Kiev
|
||||
BEGIN:DAYLIGHT
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0300
|
||||
TZNAME:EEST
|
||||
DTSTART:19700329T030000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZOFFSETFROM:+0300
|
||||
TZOFFSETTO:+0200
|
||||
TZNAME:EET
|
||||
DTSTART:19701025T040000
|
||||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID=Europe/Kiev:20160826T140000
|
||||
DTEND;TZID=Europe/Kiev:20160826T150000
|
||||
DTSTAMP:20160825T061505Z
|
||||
UID:6m2q7kb2l02798oagemrcgm6pk@google.com
|
||||
RECURRENCE-ID;TZID=Europe/Kiev:20160826T140000
|
||||
CREATED:20160823T125221Z
|
||||
DESCRIPTION:
|
||||
LAST-MODIFIED:20160823T130320Z
|
||||
LOCATION:
|
||||
SEQUENCE:0
|
||||
STATUS:CONFIRMED
|
||||
SUMMARY:bla bla
|
||||
TRANSP:OPAQUE
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID=Europe/Kiev:20160825T140000
|
||||
DTEND;TZID=Europe/Kiev:20160825T150000
|
||||
RRULE:FREQ=DAILY;UNTIL=20160828T110000Z
|
||||
DTSTAMP:20160825T061505Z
|
||||
UID:6m2q7kb2l02798oagemrcgm6pk@google.com
|
||||
CREATED:20160823T125221Z
|
||||
DESCRIPTION:
|
||||
LAST-MODIFIED:20160823T125221Z
|
||||
LOCATION:
|
||||
SEQUENCE:0
|
||||
STATUS:CONFIRMED
|
||||
SUMMARY:repeated
|
||||
TRANSP:OPAQUE
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
33
modules/default/calendar/vendor/ical.js/test/test14.ics
vendored
Normal file
33
modules/default/calendar/vendor/ical.js/test/test14.ics
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:-//Google Inc//Google Calendar 70.9054//EN
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
METHOD:PUBLISH
|
||||
X-WR-CALNAME:ical
|
||||
X-WR-TIMEZONE:Europe/Kiev
|
||||
X-WR-CALDESC:
|
||||
BEGIN:VEVENT
|
||||
UID:98765432-ABCD-DCBB-999A-987765432123
|
||||
DTSTART;TZID=US/Central:20170216T090000
|
||||
DTEND;TZID=US/Central:20170216T190000
|
||||
DTSTAMP:20170727T044436Z
|
||||
EXDATE;TZID=US/Central:20170706T090000,20170717T090000,20170720T090000,20
|
||||
170803T090000
|
||||
LAST-MODIFIED:20170727T044435Z
|
||||
RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20170814T045959Z;INTERVAL=2;BYDAY=MO,TH
|
||||
SEQUENCE:0
|
||||
SUMMARY:Example of comma-separated exdates
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:1234567-ABCD-ABCD-ABCD-123456789012
|
||||
DTSTART:20170814T140000Z
|
||||
DTEND:20170815T000000Z
|
||||
DTSTAMP:20171204T134925Z
|
||||
EXDATE:20171219T060000
|
||||
EXDATE:20171218T060000
|
||||
LAST-MODIFIED:20171024T140004Z
|
||||
RRULE:FREQ=WEEKLY;WKST=SU;INTERVAL=2;BYDAY=MO,TU
|
||||
SEQUENCE:0
|
||||
SUMMARY:Example of exdate with bad times
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
@@ -44,3 +44,14 @@ The following properties can be configured:
|
||||
| `analogPlacement` | **Specific to the analog clock. _(requires displayType set to `'both'`)_** Specifies where the analog clock is in relation to the digital clock <br><br> **Possible values:** `top`, `right`, `bottom`, or `left` <br> **Default value:** `bottom`
|
||||
| `analogShowDate` | **Specific to the analog clock.** If the clock is used as a separate module and set to analog only, this configures whether a date is also displayed with the clock. <br><br> **Possible values:** `false`, `top`, or `bottom` <br> **Default value:** `top`
|
||||
| `timezone` | Specific a timezone to show clock. <br><br> **Possible examples values:** `America/New_York`, `America/Santiago`, `Etc/GMT+10` <br> **Default value:** `none`. See more informations about configuration value [here](https://momentjs.com/timezone/docs/#/data-formats/packed-format/)
|
||||
|
||||
## Notifications
|
||||
|
||||
The clock makes use of the built-in [Notification Mechanism](https://github.com/michMich/MagicMirror/wiki/notifications) to relay notifications to all modules.
|
||||
|
||||
Current notifications are:
|
||||
|
||||
| Notification | Description
|
||||
| ----------------- | -----------
|
||||
| `CLOCK_SECOND` | A second has elapsed. <br> *Parameter*: second value
|
||||
| `CLOCK_MINUTE` | A minute has elapsed <br> *Parameter*: minute value
|
||||
|
@@ -41,9 +41,40 @@ Module.register("clock",{
|
||||
|
||||
// Schedule update interval.
|
||||
var self = this;
|
||||
setInterval(function() {
|
||||
self.second = moment().second();
|
||||
self.minute = moment().minute();
|
||||
|
||||
//Calculate how many ms should pass until next update depending on if seconds is displayed or not
|
||||
var delayCalculator = function(reducedSeconds) {
|
||||
if (self.config.displaySeconds) {
|
||||
return 1000 - moment().milliseconds();
|
||||
} else {
|
||||
return ((60 - reducedSeconds) * 1000) - moment().milliseconds();
|
||||
}
|
||||
};
|
||||
|
||||
//A recursive timeout function instead of interval to avoid drifting
|
||||
var notificationTimer = function() {
|
||||
self.updateDom();
|
||||
}, 1000);
|
||||
|
||||
//If seconds is displayed CLOCK_SECOND-notification should be sent (but not when CLOCK_MINUTE-notification is sent)
|
||||
if (self.config.displaySeconds) {
|
||||
self.second = (self.second + 1) % 60;
|
||||
if (self.second !== 0) {
|
||||
self.sendNotification("CLOCK_SECOND", self.second);
|
||||
setTimeout(notificationTimer, delayCalculator(0));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//If minute changed or seconds isn't displayed send CLOCK_MINUTE-notification
|
||||
self.minute = (self.minute + 1) % 60;
|
||||
self.sendNotification("CLOCK_MINUTE", self.minute);
|
||||
setTimeout(notificationTimer, delayCalculator(0));
|
||||
};
|
||||
|
||||
//Set the initial timeout with the amount of seconds elapsed as reducedSeconds so it will trigger when the minute changes
|
||||
setTimeout(notificationTimer, delayCalculator(self.second));
|
||||
|
||||
// Set locale.
|
||||
moment.locale(config.language);
|
||||
@@ -62,12 +93,12 @@ Module.register("clock",{
|
||||
var timeWrapper = document.createElement("div");
|
||||
var secondsWrapper = document.createElement("sup");
|
||||
var periodWrapper = document.createElement("span");
|
||||
var weekWrapper = document.createElement("div")
|
||||
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"
|
||||
weekWrapper.className = "week dimmed medium";
|
||||
|
||||
// Set content of wrappers.
|
||||
// The moment().format("h") method has a bug on the Raspberry Pi.
|
||||
@@ -75,6 +106,7 @@ Module.register("clock",{
|
||||
// See issue: https://github.com/MichMich/MagicMirror/issues/181
|
||||
var timeString;
|
||||
var now = moment();
|
||||
this.lastDisplayedMinute = now.minute();
|
||||
if (this.config.timezone) {
|
||||
now.tz(this.config.timezone);
|
||||
}
|
||||
@@ -132,7 +164,7 @@ Module.register("clock",{
|
||||
clockCircle.style.width = this.config.analogSize;
|
||||
clockCircle.style.height = this.config.analogSize;
|
||||
|
||||
if (this.config.analogFace != "" && this.config.analogFace != "simple" && this.config.analogFace != "none") {
|
||||
if (this.config.analogFace !== "" && this.config.analogFace !== "simple" && this.config.analogFace !== "none") {
|
||||
clockCircle.style.background = "url("+ this.data.path + "faces/" + this.config.analogFace + ".svg)";
|
||||
clockCircle.style.backgroundSize = "100%";
|
||||
|
||||
@@ -140,7 +172,7 @@ Module.register("clock",{
|
||||
// clockCircle.style.border = "1px solid black";
|
||||
clockCircle.style.border = "rgba(0, 0, 0, 0.1)"; //Updated fix for Issue 611 where non-black backgrounds are used
|
||||
|
||||
} else if (this.config.analogFace != "none") {
|
||||
} else if (this.config.analogFace !== "none") {
|
||||
clockCircle.style.border = "2px solid white";
|
||||
}
|
||||
var clockFace = document.createElement("div");
|
||||
|
@@ -36,9 +36,10 @@ Module.register("compliments", {
|
||||
morningStartTime: 3,
|
||||
morningEndTime: 12,
|
||||
afternoonStartTime: 12,
|
||||
afternoonEndTime: 17
|
||||
afternoonEndTime: 17,
|
||||
random: true
|
||||
},
|
||||
|
||||
lastIndexUsed:-1,
|
||||
// Set currentweather from module
|
||||
currentWeatherType: "",
|
||||
|
||||
@@ -54,7 +55,7 @@ Module.register("compliments", {
|
||||
this.lastComplimentIndex = -1;
|
||||
|
||||
var self = this;
|
||||
if (this.config.remoteFile != null) {
|
||||
if (this.config.remoteFile !== null) {
|
||||
this.complimentFile(function(response) {
|
||||
self.config.compliments = JSON.parse(response);
|
||||
self.updateDom();
|
||||
@@ -134,7 +135,7 @@ Module.register("compliments", {
|
||||
xobj.overrideMimeType("application/json");
|
||||
xobj.open("GET", path, true);
|
||||
xobj.onreadystatechange = function() {
|
||||
if (xobj.readyState == 4 && xobj.status == "200") {
|
||||
if (xobj.readyState === 4 && xobj.status === 200) {
|
||||
callback(xobj.responseText);
|
||||
}
|
||||
};
|
||||
@@ -147,25 +148,48 @@ Module.register("compliments", {
|
||||
* return compliment string - A compliment.
|
||||
*/
|
||||
randomCompliment: function() {
|
||||
// get the current time of day compliments list
|
||||
var compliments = this.complimentArray();
|
||||
var index = this.randomIndex(compliments);
|
||||
// variable for index to next message to display
|
||||
let index=0
|
||||
// are we randomizing
|
||||
if(this.config.random){
|
||||
// yes
|
||||
index = this.randomIndex(compliments);
|
||||
}
|
||||
else{
|
||||
// no, sequetial
|
||||
// if doing sequential, don't fall off the end
|
||||
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed
|
||||
}
|
||||
|
||||
return compliments[index];
|
||||
},
|
||||
|
||||
// Override dom generator.
|
||||
// Override dom generator.
|
||||
getDom: function() {
|
||||
var complimentText = this.randomCompliment();
|
||||
|
||||
var compliment = document.createTextNode(complimentText);
|
||||
var wrapper = document.createElement("div");
|
||||
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
|
||||
// get the compliment text
|
||||
var complimentText = this.randomCompliment();
|
||||
// split it into parts on newline text
|
||||
var parts= complimentText.split('\n')
|
||||
// create a span to hold it all
|
||||
var compliment=document.createElement('span')
|
||||
// process all the parts of the compliment text
|
||||
for (part of parts){
|
||||
// create a text element for each part
|
||||
compliment.appendChild(document.createTextNode(part))
|
||||
// add a break `
|
||||
compliment.appendChild(document.createElement('BR'))
|
||||
}
|
||||
// remove the last break
|
||||
compliment.lastElementChild.remove();
|
||||
wrapper.appendChild(compliment);
|
||||
|
||||
return wrapper;
|
||||
},
|
||||
|
||||
|
||||
// From data currentweather set weather type
|
||||
setCurrentWeatherType: function(data) {
|
||||
var weatherIconTable = {
|
||||
@@ -191,10 +215,9 @@ Module.register("compliments", {
|
||||
this.currentWeatherType = weatherIconTable[data.weather[0].icon];
|
||||
},
|
||||
|
||||
|
||||
// Override notification handler.
|
||||
notificationReceived: function(notification, payload, sender) {
|
||||
if (notification == "CURRENTWEATHER_DATA") {
|
||||
if (notification === "CURRENTWEATHER_DATA") {
|
||||
this.setCurrentWeatherType(payload.data);
|
||||
}
|
||||
},
|
||||
|
@@ -19,7 +19,7 @@ modules: [
|
||||
config: {
|
||||
// See 'Configuration options' for more information.
|
||||
location: "Amsterdam,Netherlands",
|
||||
locationID: "", //Location ID from http://openweathermap.org/help/city_list.txt
|
||||
locationID: "", //Location ID from http://bulk.openweathermap.org/sample/city.list.json.gz
|
||||
appid: "abcde12345abcde12345abcde12345ab" //openweathermap.org API key.
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,7 @@ The following properties can be configured:
|
||||
| `apiBase` | The OpenWeatherMap base URL. <br><br> **Default value:** `'http://api.openweathermap.org/data/'`
|
||||
| `weatherEndpoint` | The OpenWeatherMap API endPoint. <br><br> **Default value:** `'weather'`
|
||||
| `appendLocationNameToHeader` | If set to `true`, the returned location name will be appended to the header of the module, if the header is enabled. This is mainly intresting when using calender based weather. <br><br> **Default value:** `true`
|
||||
| `useLocationAsHeader` | If set to `true` and location is given a value, the value of location will be used as the header. This is useful if `locationName` was not returned. <br><br> **Default value:** `false`
|
||||
| `calendarClass` | The class for the calender module to base the event based weather information on. <br><br> **Default value:** `'calendar'`
|
||||
| `iconTable` | The conversion table to convert the weather conditions to weather-icons. <br><br> **Default value:** view tabel below.
|
||||
|
||||
|
@@ -23,6 +23,7 @@ Module.register("currentweather",{
|
||||
showWindDirection: true,
|
||||
showWindDirectionAsArrow: false,
|
||||
useBeaufort: true,
|
||||
appendLocationNameToHeader: false,
|
||||
useKMPHwind: false,
|
||||
lang: config.language,
|
||||
decimalSymbol: ".",
|
||||
@@ -269,6 +270,10 @@ Module.register("currentweather",{
|
||||
return this.data.header + " " + this.fetchedLocationName;
|
||||
}
|
||||
|
||||
if (this.config.useLocationAsHeader && this.config.location !== false) {
|
||||
return this.config.location;
|
||||
}
|
||||
|
||||
return this.data.header;
|
||||
},
|
||||
|
||||
@@ -353,7 +358,7 @@ Module.register("currentweather",{
|
||||
} else if(this.config.location) {
|
||||
params += "q=" + this.config.location;
|
||||
} else if (this.firstEvent && this.firstEvent.geo) {
|
||||
params += "lat=" + this.firstEvent.geo.lat + "&lon=" + this.firstEvent.geo.lon
|
||||
params += "lat=" + this.firstEvent.geo.lat + "&lon=" + this.firstEvent.geo.lon;
|
||||
} else if (this.firstEvent && this.firstEvent.location) {
|
||||
params += "q=" + this.firstEvent.location;
|
||||
} else {
|
||||
@@ -383,6 +388,7 @@ Module.register("currentweather",{
|
||||
|
||||
this.humidity = parseFloat(data.main.humidity);
|
||||
this.temperature = this.roundValue(data.main.temp);
|
||||
this.fetchedLocationName = data.name;
|
||||
this.feelsLike = 0;
|
||||
|
||||
if (this.config.useBeaufort){
|
||||
|
@@ -15,10 +15,10 @@ Module.register("helloworld",{
|
||||
},
|
||||
|
||||
getTemplate: function () {
|
||||
return "helloworld.njk"
|
||||
return "helloworld.njk";
|
||||
},
|
||||
|
||||
getTemplateData: function () {
|
||||
return this.config
|
||||
return this.config;
|
||||
}
|
||||
});
|
||||
|
@@ -45,9 +45,17 @@ MagicMirror's [notification mechanism](https://github.com/MichMich/MagicMirror/t
|
||||
| `ARTICLE_PREVIOUS` | Shows the previous news title (hiding the summary or previously fully displayed article)
|
||||
| `ARTICLE_MORE_DETAILS` | When received the _first time_, shows the corresponding description of the currently displayed news title. <br> The module expects that the module's configuration option `showDescription` is set to `false` (default value). <br><br> When received a _second consecutive time_, shows the full news article in an IFRAME. <br> This requires that the news page can be embedded in an IFRAME, e.g. doesn't have the HTTP response header [X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options) set to e.g. `DENY`.<br><br>When received the _next consecutive times_, reloads the page and scrolls down by `scrollLength` pixels to paginate through the article.
|
||||
| `ARTICLE_LESS_DETAILS` | Hides the summary or full news article and only displays the news title of the currently viewed news item.
|
||||
| `ARTICLE_TOGGLE_FULL` | Toogles article in fullscreen.
|
||||
| `ARTICLE_TOGGLE_FULL` | Toggles article in fullscreen.
|
||||
| `ARTICLE_INFO_REQUEST` | Causes `newsfeed` to respond with the notification `ARTICLE_INFO_RESPONSE`, the payload of which provides the `title`, `source`, `date`, `desc` and `url` of the current news title.
|
||||
|
||||
#### Notifications sent by the module
|
||||
MagicMirror's [notification mechanism](https://github.com/MichMich/MagicMirror/tree/master/modules#thissendnotificationnotification-payload) can also be used to send notifications from the current module to all other modules. The following notifications are broadcasted from this module:
|
||||
|
||||
| Notification Identifier | Description
|
||||
| ----------------------- | -----------
|
||||
| `NEWS_FEED` | Broadcast the current list of news items.
|
||||
| `NEWS_FEED_UPDATE` | Broadcasts the list of updates news items.
|
||||
|
||||
Note the payload of the sent notification event is ignored.
|
||||
|
||||
#### Example
|
||||
@@ -68,6 +76,8 @@ The following properties can be configured:
|
||||
| `feeds` | An array of feed urls that will be used as source. <br> More info about this object can be found below. <br> **Default value:** `[{ title: "New York Times", url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml", encoding: "UTF-8" }]`<br>You can add `reloadInterval` option to set particular reloadInterval to a feed.
|
||||
| `showSourceTitle` | Display the title of the source. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||
| `showPublishDate` | Display the publish date of an headline. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||
| `broadcastNewsFeeds` | Gives the ability to broadcast news feeds to all modules, by using ```sendNotification()``` when set to `true`, rather than ```sendSocketNotification()``` when `false` <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||
| `broadcastNewsUpdates` | Gives the ability to broadcast news feed updates to all modules <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||
| `showDescription` | Display the description of an item. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `wrapTitle` | Wrap the title of the item to multiple lines. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||
| `wrapDescription` | Wrap the description of the item to multiple lines. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||
@@ -80,7 +90,7 @@ The following properties can be configured:
|
||||
| `maxNewsItems` | Total amount of news items to cycle through. (0 for unlimited) <br><br> **Possible values:**`0` - `...` <br> **Default value:** `0`
|
||||
| `ignoreOldItems` | Ignore news items that are outdated. <br><br> **Possible values:**`true` or `false` <br> **Default value:** `false`
|
||||
| `ignoreOlderThan` | How old should news items be before they are considered outdated? (Milliseconds) <br><br> **Possible values:**`1` - `...` <br> **Default value:** `86400000` (1 day)
|
||||
| `removeStartTags` | Some newsfeeds feature tags at the **beginning** of their titles or descriptions, such as _[VIDEO]_. This setting allows for the removal of specified tags from the beginning of an item's description and/or title. <br><br> **Possible values:**`'title'`, `'description'`, `'both'`
|
||||
| `removeStartTags` | Some news feeds feature tags at the **beginning** of their titles or descriptions, such as _[VIDEO]_. This setting allows for the removal of specified tags from the beginning of an item's description and/or title. <br><br> **Possible values:**`'title'`, `'description'`, `'both'`
|
||||
| `startTags` | List the tags you would like to have removed at the beginning of the feed item <br><br> **Possible values:** `['TAG']` or `['TAG1','TAG2',...]`
|
||||
| `removeEndTags` | Remove specified tags from the **end** of an item's description and/or title. <br><br> **Possible values:**`'title'`, `'description'`, `'both'`
|
||||
| `endTags` | List the tags you would like to have removed at the end of the feed item <br><br> **Possible values:** `['TAG']` or `['TAG1','TAG2',...]`
|
||||
|
@@ -81,11 +81,10 @@ var Fetcher = function(url, reloadInterval, encoding, logFeedWarnings) {
|
||||
scheduleTimer();
|
||||
});
|
||||
|
||||
|
||||
nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
|
||||
headers = {"User-Agent": "Mozilla/5.0 (Node.js "+ nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)",
|
||||
"Cache-Control": "max-age=0, no-cache, no-store, must-revalidate",
|
||||
"Pragma": "no-cache"}
|
||||
"Pragma": "no-cache"};
|
||||
|
||||
request({uri: url, encoding: null, headers: headers})
|
||||
.on("error", function(error) {
|
||||
|
@@ -20,6 +20,8 @@ Module.register("newsfeed",{
|
||||
],
|
||||
showSourceTitle: true,
|
||||
showPublishDate: true,
|
||||
broadcastNewsFeeds: true,
|
||||
broadcastNewsUpdates: true,
|
||||
showDescription: false,
|
||||
wrapTitle: true,
|
||||
wrapDescription: true,
|
||||
@@ -103,7 +105,7 @@ Module.register("newsfeed",{
|
||||
// this.config.showFullArticle is a run-time configuration, triggered by optional notifications
|
||||
if (!this.config.showFullArticle && (this.config.showSourceTitle || this.config.showPublishDate)) {
|
||||
var sourceAndTimestamp = document.createElement("div");
|
||||
sourceAndTimestamp.className = "light small dimmed";
|
||||
sourceAndTimestamp.className = "newsfeed-source light small dimmed";
|
||||
|
||||
if (this.config.showSourceTitle && this.newsItems[this.activeItem].sourceTitle !== "") {
|
||||
sourceAndTimestamp.innerHTML = this.newsItems[this.activeItem].sourceTitle;
|
||||
@@ -166,14 +168,14 @@ Module.register("newsfeed",{
|
||||
|
||||
if(!this.config.showFullArticle){
|
||||
var title = document.createElement("div");
|
||||
title.className = "bright medium light" + (!this.config.wrapTitle ? " no-wrap" : "");
|
||||
title.className = "newsfeed-title bright medium light" + (!this.config.wrapTitle ? " no-wrap" : "");
|
||||
title.innerHTML = this.newsItems[this.activeItem].title;
|
||||
wrapper.appendChild(title);
|
||||
}
|
||||
|
||||
if (this.isShowingDescription) {
|
||||
var description = document.createElement("div");
|
||||
description.className = "small light" + (!this.config.wrapDescription ? " no-wrap" : "");
|
||||
description.className = "newsfeed-desc small light" + (!this.config.wrapDescription ? " no-wrap" : "");
|
||||
var txtDesc = this.newsItems[this.activeItem].description;
|
||||
description.innerHTML = (this.config.truncDescription ? (txtDesc.length > this.config.lengthDescription ? txtDesc.substring(0, this.config.lengthDescription) + "..." : txtDesc) : txtDesc);
|
||||
wrapper.appendChild(description);
|
||||
@@ -189,7 +191,7 @@ Module.register("newsfeed",{
|
||||
fullArticle.style.top = "0";
|
||||
fullArticle.style.left = "0";
|
||||
fullArticle.style.border = "none";
|
||||
fullArticle.src = this.getActiveItemURL()
|
||||
fullArticle.src = this.getActiveItemURL();
|
||||
fullArticle.style.zIndex = 1;
|
||||
wrapper.appendChild(fullArticle);
|
||||
}
|
||||
@@ -266,6 +268,20 @@ Module.register("newsfeed",{
|
||||
}, this);
|
||||
}
|
||||
|
||||
// get updated news items and broadcast them
|
||||
var updatedItems = [];
|
||||
newsItems.forEach(value => {
|
||||
if (this.newsItems.findIndex(value1 => value1 === value) === -1) {
|
||||
// Add item to updated items list
|
||||
updatedItems.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
// check if updated items exist, if so and if we should broadcast these updates, then lets do so
|
||||
if (this.config.broadcastNewsUpdates && updatedItems.length > 0) {
|
||||
this.sendNotification("NEWS_FEED_UPDATE", {items: updatedItems});
|
||||
}
|
||||
|
||||
this.newsItems = newsItems;
|
||||
},
|
||||
|
||||
@@ -311,9 +327,19 @@ Module.register("newsfeed",{
|
||||
|
||||
self.updateDom(self.config.animationSpeed);
|
||||
|
||||
// Broadcast NewsFeed if needed
|
||||
if (self.config.broadcastNewsFeeds) {
|
||||
self.sendNotification("NEWS_FEED", {items: self.newsItems});
|
||||
}
|
||||
|
||||
timer = setInterval(function() {
|
||||
self.activeItem++;
|
||||
self.updateDom(self.config.animationSpeed);
|
||||
|
||||
// Broadcast NewsFeed if needed
|
||||
if (self.config.broadcastNewsFeeds) {
|
||||
self.sendNotification("NEWS_FEED", {items: self.newsItems});
|
||||
}
|
||||
}, this.config.updateInterval);
|
||||
},
|
||||
|
||||
@@ -398,7 +424,7 @@ Module.register("newsfeed",{
|
||||
date: this.newsItems[this.activeItem].pubdate,
|
||||
desc: this.newsItems[this.activeItem].description,
|
||||
url: this.getActiveItemURL()
|
||||
})
|
||||
});
|
||||
} else {
|
||||
Log.info(this.name + " - unknown notification, ignoring: " + notification);
|
||||
}
|
||||
|
@@ -10,11 +10,17 @@ module.exports = NodeHelper.create({
|
||||
config: {},
|
||||
|
||||
updateTimer: null,
|
||||
updateProcessStarted: false,
|
||||
|
||||
start: function () {
|
||||
},
|
||||
|
||||
configureModules: function(modules) {
|
||||
|
||||
// Push MagicMirror itself , biggest chance it'll show up last in UI and isn't overwritten
|
||||
// others will be added in front, asynchronously
|
||||
simpleGits.push({"module": "default", "git": SimpleGit(path.normalize(__dirname + "/../../../"))});
|
||||
|
||||
for (moduleName in modules) {
|
||||
if (defaultModules.indexOf(moduleName) < 0) {
|
||||
// Default modules are included in the main MagicMirror repo
|
||||
@@ -22,6 +28,7 @@ module.exports = NodeHelper.create({
|
||||
|
||||
var stat;
|
||||
try {
|
||||
//console.log("checking git for module="+moduleName)
|
||||
stat = fs.statSync(path.join(moduleFolder, ".git"));
|
||||
} catch(err) {
|
||||
// Error when directory .git doesn't exist
|
||||
@@ -36,30 +43,29 @@ module.exports = NodeHelper.create({
|
||||
// No valid remote for folder, skip
|
||||
return;
|
||||
}
|
||||
|
||||
// Folder has .git and has at least one git remote, watch this folder
|
||||
simpleGits.push({"module": mn, "git": git});
|
||||
simpleGits.unshift({"module": mn, "git": git});
|
||||
});
|
||||
}(moduleName, moduleFolder);
|
||||
}
|
||||
}
|
||||
|
||||
// Push MagicMirror itself last, biggest chance it'll show up last in UI and isn't overwritten
|
||||
simpleGits.push({"module": "default", "git": SimpleGit(path.normalize(__dirname + "/../../../"))});
|
||||
},
|
||||
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
if (notification === "CONFIG") {
|
||||
this.config = payload;
|
||||
} else if(notification === "MODULES") {
|
||||
this.configureModules(payload);
|
||||
this.preformFetch();
|
||||
// if this is the 1st time thru the update check process
|
||||
if(this.updateProcessStarted==false ){
|
||||
this.updateProcessStarted=true;
|
||||
this.configureModules(payload);
|
||||
this.preformFetch();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
preformFetch() {
|
||||
var self = this;
|
||||
|
||||
simpleGits.forEach(function(sg) {
|
||||
sg.git.fetch().status(function(err, data) {
|
||||
data.module = sg.module;
|
||||
@@ -79,7 +85,7 @@ module.exports = NodeHelper.create({
|
||||
|
||||
scheduleNextFetch: function(delay) {
|
||||
if (delay < 60 * 1000) {
|
||||
delay = 60 * 1000
|
||||
delay = 60 * 1000;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
@@ -2,41 +2,56 @@ Module.register("updatenotification", {
|
||||
|
||||
defaults: {
|
||||
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
||||
refreshInterval: 24 * 60 * 60 * 1000, // one day
|
||||
},
|
||||
|
||||
status: false,
|
||||
suspended: false,
|
||||
moduleList: {},
|
||||
|
||||
start: function () {
|
||||
var self = this;
|
||||
Log.log("Start updatenotification");
|
||||
|
||||
setInterval( () => { self.moduleList = {};self.updateDom(2); } , self.config.refreshInterval);
|
||||
},
|
||||
|
||||
notificationReceived: function (notification, payload, sender) {
|
||||
if (notification === "DOM_OBJECTS_CREATED") {
|
||||
this.sendSocketNotification("CONFIG", this.config);
|
||||
this.sendSocketNotification("MODULES", Module.definitions);
|
||||
this.hide(0, { lockString: self.identifier });
|
||||
//this.hide(0, { lockString: self.identifier });
|
||||
}
|
||||
},
|
||||
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
if (notification === "STATUS") {
|
||||
this.status = payload;
|
||||
this.updateUI();
|
||||
this.updateUI(payload);
|
||||
}
|
||||
},
|
||||
|
||||
updateUI: function () {
|
||||
updateUI: function (payload) {
|
||||
var self = this;
|
||||
if (this.status && this.status.behind > 0) {
|
||||
self.updateDom(0);
|
||||
self.show(1000, { lockString: self.identifier });
|
||||
if (payload && payload.behind > 0) {
|
||||
// if we haven't seen info for this module
|
||||
if(this.moduleList[payload.module] == undefined){
|
||||
// save it
|
||||
this.moduleList[payload.module]=payload;
|
||||
self.updateDom(2);
|
||||
}
|
||||
//self.show(1000, { lockString: self.identifier });
|
||||
|
||||
} else if (payload && payload.behind == 0){
|
||||
// if the module WAS in the list, but shouldn't be
|
||||
if(this.moduleList[payload.module] != undefined){
|
||||
// remove it
|
||||
delete this.moduleList[payload.module];
|
||||
self.updateDom(2);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
diffLink: function(text) {
|
||||
var localRef = this.status.hash;
|
||||
var remoteRef = this.status.tracking.replace(/.*\//, "");
|
||||
diffLink: function(module, text) {
|
||||
var localRef = module.hash;
|
||||
var remoteRef = module.tracking.replace(/.*\//, "");
|
||||
return "<a href=\"https://github.com/MichMich/MagicMirror/compare/"+localRef+"..."+remoteRef+"\" "+
|
||||
"class=\"xsmall dimmed\" "+
|
||||
"style=\"text-decoration: none;\" "+
|
||||
@@ -48,41 +63,53 @@ Module.register("updatenotification", {
|
||||
// Override dom generator.
|
||||
getDom: function () {
|
||||
var wrapper = document.createElement("div");
|
||||
if(this.suspended==false){
|
||||
// process the hash of module info found
|
||||
for(key of Object.keys(this.moduleList)){
|
||||
let m= this.moduleList[key];
|
||||
|
||||
if (this.status && this.status.behind > 0) {
|
||||
var message = document.createElement("div");
|
||||
message.className = "small bright";
|
||||
var message = document.createElement("div");
|
||||
message.className = "small bright";
|
||||
|
||||
var icon = document.createElement("i");
|
||||
icon.className = "fa fa-exclamation-circle";
|
||||
icon.innerHTML = " ";
|
||||
message.appendChild(icon);
|
||||
var icon = document.createElement("i");
|
||||
icon.className = "fa fa-exclamation-circle";
|
||||
icon.innerHTML = " ";
|
||||
message.appendChild(icon);
|
||||
|
||||
var updateInfoKeyName = this.status.behind == 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE";
|
||||
var subtextHtml = this.translate(updateInfoKeyName, {
|
||||
COMMIT_COUNT: this.status.behind,
|
||||
BRANCH_NAME: this.status.current
|
||||
});
|
||||
var updateInfoKeyName = m.behind == 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE";
|
||||
|
||||
var text = document.createElement("span");
|
||||
if (this.status.module == "default") {
|
||||
text.innerHTML = this.translate("UPDATE_NOTIFICATION");
|
||||
subtextHtml = this.diffLink(subtextHtml);
|
||||
} else {
|
||||
text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE", {
|
||||
MODULE_NAME: this.status.module
|
||||
var subtextHtml = this.translate(updateInfoKeyName, {
|
||||
COMMIT_COUNT: m.behind,
|
||||
BRANCH_NAME: m.current
|
||||
});
|
||||
|
||||
var text = document.createElement("span");
|
||||
if (m.module == "default") {
|
||||
text.innerHTML = this.translate("UPDATE_NOTIFICATION");
|
||||
subtextHtml = this.diffLink(m,subtextHtml);
|
||||
} else {
|
||||
text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE", {
|
||||
MODULE_NAME: m.module
|
||||
});
|
||||
}
|
||||
message.appendChild(text);
|
||||
|
||||
wrapper.appendChild(message);
|
||||
|
||||
var subtext = document.createElement("div");
|
||||
subtext.innerHTML = subtextHtml;
|
||||
subtext.className = "xsmall dimmed";
|
||||
wrapper.appendChild(subtext);
|
||||
}
|
||||
message.appendChild(text);
|
||||
|
||||
wrapper.appendChild(message);
|
||||
|
||||
var subtext = document.createElement("div");
|
||||
subtext.innerHTML = subtextHtml;
|
||||
subtext.className = "xsmall dimmed";
|
||||
wrapper.appendChild(subtext);
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
},
|
||||
|
||||
suspend: function() {
|
||||
this.suspended=true;
|
||||
},
|
||||
resume: function() {
|
||||
this.suspended=false;
|
||||
this.updateDom(2);
|
||||
}
|
||||
});
|
||||
|
14
modules/default/weather/README.md
Normal file → Executable file
14
modules/default/weather/README.md
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
# Weather Module
|
||||
|
||||
This module is aimed to be the replacement for the current `currentweather` and `weatherforcast` modules. The module will be configurable to be used as a current weather view, or to show the forecast. This way the module can be used twice to fullfil both purposes.
|
||||
This module is aimed to be the replacement for the current `currentweather` and `weatherforcast` modules. The module will be configurable to be used as a current weather view, or to show the forecast. This way the module can be used twice to fullfil both purposes.
|
||||
|
||||
The biggest change is the use of weather providers. This way we are not bound to one API source. And users can choose which API they want to use as their source.
|
||||
|
||||
@@ -35,9 +35,11 @@ The following properties can be configured:
|
||||
|
||||
| Option | Description
|
||||
| ---------------------------- | -----------
|
||||
| `weatherProvider` | Which weather provider should be used. <br><br> **Possible values:** `openweathermap` , `darksky` , or `weathergov` <br> **Default value:** `openweathermap`
|
||||
| `weatherProvider` | Which weather provider should be used. <br><br> **Possible values:** `openweathermap` , `darksky` , `weathergov` or `ukmetoffice`<br> **Default value:** `openweathermap`
|
||||
| `type` | Which type of weather data should be displayed. <br><br> **Possible values:** `current` or `forecast` <br> **Default value:** `current`
|
||||
| `units` | What units to use. Specified by config.js <br><br> **Possible values:** `config.units` = Specified by config.js, `default` = Kelvin, `metric` = Celsius, `imperial` = Fahrenheit <br> **Default value:** `config.units`
|
||||
| `tempUnits` | What units to use for temperature. If specified overrides `units` setting. Specified by config.js <br><br> **Possible values:** `config.units` = Specified by config.js, `default` = Kelvin, `metric` = Celsius, `imperial` = Fahrenheit <br> **Default value:** `units`
|
||||
| `windUnits` | What units to use for wind speed. If specified overrides `units` setting. Specified by config.js <br><br> **Possible values:** `config.units` = Specified by config.js, `default` = Kelvin, `metric` = Celsius, `imperial` = Fahrenheit <br> **Default value:** `units`
|
||||
| `roundTemp` | Round temperature value to nearest integer. <br><br> **Possible values:** `true` (round to integer) or `false` (display exact value with decimal point) <br> **Default value:** `false`
|
||||
| `degreeLabel` | Show the degree label for your chosen units (Metric = C, Imperial = F, Kelvin = K). <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||
| `updateInterval` | How often does the content needs to be fetched? (Milliseconds) <br><br> **Possible values:** `1000` - `86400000` <br> **Default value:** `600000` (10 minutes)
|
||||
@@ -105,6 +107,14 @@ The following properties can be configured:
|
||||
| `lat` | The geo coordinate latitude. <br><br> This value is **REQUIRED**
|
||||
| `lon` | The geo coordinate longitude. <br><br> This value is **REQUIRED**
|
||||
|
||||
### UK Met Office options
|
||||
|
||||
| Option | Description
|
||||
| ---------------------------- | -----------
|
||||
| `apiBase` | The UKMO base URL. <br><br> **Possible value:** `'http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/'` <br> This value is **REQUIRED**
|
||||
| `locationId` | The UKMO API location code. <br><br> **Possible values:** `322942` <br> This value is **REQUIRED**
|
||||
| `apiKey` | The [UK Met Office](https://www.metoffice.gov.uk/datapoint/getting-started) API key, which can be obtained by creating an UKMO Datapoint account. <br><br> This value is **REQUIRED**
|
||||
|
||||
## API Provider Development
|
||||
|
||||
If you want to add another API provider checkout the [Guide](providers).
|
||||
|
19
modules/default/weather/current.njk
Normal file → Executable file
19
modules/default/weather/current.njk
Normal file → Executable file
@@ -9,7 +9,7 @@
|
||||
{{ current.windSpeed | round }}
|
||||
{% endif %}
|
||||
{% if config.showWindDirection %}
|
||||
<sup>
|
||||
<sup>
|
||||
{% if config.showWindDirectionAsArrow %}
|
||||
<i class="fa fa-long-arrow-up" style="transform:rotate({{ current.windDirection }}deg);"></i>
|
||||
{% else %}
|
||||
@@ -24,7 +24,7 @@
|
||||
{% endif %}
|
||||
<span class="wi dimmed wi-{{ current.nextSunAction() }}"></span>
|
||||
<span>
|
||||
{% if current.nextSunAction() == "sunset" %}
|
||||
{% if current.nextSunAction() === "sunset" %}
|
||||
{{ current.sunset | formatTime }}
|
||||
{% else %}
|
||||
{{ current.sunrise | formatTime }}
|
||||
@@ -56,11 +56,18 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if config.showFeelsLike and not config.onlyTemp %}
|
||||
{% if (config.showFeelsLike or config.showPrecipitationAmount) and not config.onlyTemp %}
|
||||
<div class="normal medium">
|
||||
<span class="dimmed">
|
||||
{{ "FEELS" | translate }} {{ current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }}
|
||||
</span>
|
||||
{% if config.showFeelsLike %}
|
||||
<span class="dimmed">
|
||||
{{ "FEELS" | translate }} {{ current.feelsLike() | roundValue | unit("temperature") | decimalSymbol }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if config.showPrecipitationAmount %}
|
||||
<span class="dimmed">
|
||||
{{ "PRECIP" | translate }} {{ current.precipitation | unit("precip") }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
|
@@ -28,5 +28,5 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Uncomment the line below to see the contents of the `current` object. -->
|
||||
<!-- Uncomment the line below to see the contents of the `forecast` object. -->
|
||||
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{forecast | dump}}</div> -->
|
||||
|
10
modules/default/weather/providers/README.md
Normal file → Executable file
10
modules/default/weather/providers/README.md
Normal file → Executable file
@@ -18,9 +18,9 @@ This is the script in which the weather provider will be defined. In it's most s
|
||||
````javascript
|
||||
WeatherProvider.register("yourprovider", {
|
||||
providerName: "YourProvider",
|
||||
|
||||
|
||||
fetchCurrentWeather() {},
|
||||
|
||||
|
||||
fetchWeatherForecast() {}
|
||||
});
|
||||
````
|
||||
@@ -91,7 +91,9 @@ A convenience function to make requests. It returns a promise.
|
||||
|
||||
| Property | Type | Value/Unit |
|
||||
| --- | --- | --- |
|
||||
| units | `string` | Gets initialized with the constructor. <br> Possible values: `metric` and `imperial` |
|
||||
| units | `string` | Gets initialized with the constructor. <br> Possible values: `metric`, `imperial` |
|
||||
| tempUnits | `string` | Gets initialized with the constructor. <br> Possible values: `metric`, `imperial` |
|
||||
| windUnits | `string` | Gets initialized with the constructor. <br> Possible values: `metric`, `imperial` |
|
||||
| date | `object` | [Moment.js](https://momentjs.com/) object of the time/date. |
|
||||
| windSpeed |`number` | Metric: `meter/second` <br> Imperial: `miles/hour` |
|
||||
| windDirection |`number` | Direction of the wind in degrees. |
|
||||
@@ -104,7 +106,7 @@ A convenience function to make requests. It returns a promise.
|
||||
| humidity | `number` | Percentage of humidity |
|
||||
| rain | `number` | Metric: `millimeters` <br> Imperial: `inches` |
|
||||
| snow | `number` | Metric: `millimeters` <br> Imperial: `inches` |
|
||||
| precipitation | `number` | Metric: `millimeters` <br> Imperial: `inches` |
|
||||
| precipitation | `number` | Metric: `millimeters` <br> Imperial: `inches` <br> UK Met Office provider: `percent` |
|
||||
|
||||
#### Current weather
|
||||
|
||||
|
10
modules/default/weather/providers/darksky.js
Normal file → Executable file
10
modules/default/weather/providers/darksky.js
Normal file → Executable file
@@ -32,7 +32,8 @@ WeatherProvider.register("darksky", {
|
||||
this.setCurrentWeather(currentWeather);
|
||||
}).catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
});
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
fetchWeatherForecast() {
|
||||
@@ -47,7 +48,8 @@ WeatherProvider.register("darksky", {
|
||||
this.setWeatherForecast(forecast);
|
||||
}).catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
});
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
// Create a URL from the config and base URL.
|
||||
@@ -58,7 +60,7 @@ WeatherProvider.register("darksky", {
|
||||
|
||||
// Implement WeatherDay generator.
|
||||
generateWeatherDayFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units);
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
currentWeather.date = moment();
|
||||
currentWeather.humidity = parseFloat(currentWeatherData.currently.humidity);
|
||||
@@ -76,7 +78,7 @@ WeatherProvider.register("darksky", {
|
||||
const days = [];
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
const weather = new WeatherObject(this.config.units);
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
weather.date = moment(forecast.time, "X");
|
||||
weather.minTemperature = forecast.temperatureMin;
|
||||
|
18
modules/default/weather/providers/openweathermap.js
Normal file → Executable file
18
modules/default/weather/providers/openweathermap.js
Normal file → Executable file
@@ -34,6 +34,7 @@ WeatherProvider.register("openweathermap", {
|
||||
.catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
// Overwrite the fetchCurrentWeather method.
|
||||
@@ -54,6 +55,7 @@ WeatherProvider.register("openweathermap", {
|
||||
.catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
/** OpenWeatherMap Specific Methods - These are not part of the default provider methods */
|
||||
@@ -68,7 +70,7 @@ WeatherProvider.register("openweathermap", {
|
||||
* Generate a WeatherObject based on currentWeatherInformation
|
||||
*/
|
||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units);
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
currentWeather.humidity = currentWeatherData.main.humidity;
|
||||
currentWeather.temperature = currentWeatherData.main.temp;
|
||||
@@ -86,13 +88,13 @@ WeatherProvider.register("openweathermap", {
|
||||
*/
|
||||
generateWeatherObjectsFromForecast(forecasts) {
|
||||
|
||||
if (this.config.weatherEndpoint == "/forecast") {
|
||||
if (this.config.weatherEndpoint === "/forecast") {
|
||||
return this.fetchForecastHourly(forecasts);
|
||||
} else if (this.config.weatherEndpoint == "/forecast/daily") {
|
||||
} else if (this.config.weatherEndpoint === "/forecast/daily") {
|
||||
return this.fetchForecastDaily(forecasts);
|
||||
}
|
||||
// if weatherEndpoint does not match forecast or forecast/daily, what should be returned?
|
||||
const days = [new WeatherObject(this.config.units)];
|
||||
const days = [new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits)];
|
||||
return days;
|
||||
},
|
||||
|
||||
@@ -109,7 +111,7 @@ WeatherProvider.register("openweathermap", {
|
||||
let snow = 0;
|
||||
// variable for date
|
||||
let date = "";
|
||||
let weather = new WeatherObject(this.config.units);
|
||||
let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
|
||||
@@ -123,7 +125,7 @@ WeatherProvider.register("openweathermap", {
|
||||
// push weather information to days array
|
||||
days.push(weather);
|
||||
// create new weather-object
|
||||
weather = new WeatherObject(this.config.units);
|
||||
weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
minTemp = [];
|
||||
maxTemp = [];
|
||||
@@ -140,7 +142,7 @@ WeatherProvider.register("openweathermap", {
|
||||
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (moment(forecast.dt, "X").format("H") >= 8 && moment(forecast.dt, "X").format("H") <= 17) {
|
||||
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
||||
}
|
||||
@@ -187,7 +189,7 @@ WeatherProvider.register("openweathermap", {
|
||||
const days = [];
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
const weather = new WeatherObject(this.config.units);
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
weather.date = moment(forecast.dt, "X");
|
||||
weather.minTemperature = forecast.temp.min;
|
||||
|
264
modules/default/weather/providers/ukmetoffice.js
Executable file
264
modules/default/weather/providers/ukmetoffice.js
Executable file
@@ -0,0 +1,264 @@
|
||||
/* global WeatherProvider, WeatherObject */
|
||||
|
||||
/* Magic Mirror
|
||||
* Module: Weather
|
||||
*
|
||||
* By Malcolm Oakes https://github.com/maloakes
|
||||
* MIT Licensed.
|
||||
*
|
||||
* This class is a provider for UK Met Office Datapoint.
|
||||
*/
|
||||
|
||||
|
||||
WeatherProvider.register("ukmetoffice", {
|
||||
|
||||
// Set the name of the provider.
|
||||
// This isn't strictly necessary, since it will fallback to the provider identifier
|
||||
// But for debugging (and future alerts) it would be nice to have the real name.
|
||||
providerName: "UK Met Office",
|
||||
|
||||
units: {
|
||||
imperial: "us",
|
||||
metric: "si"
|
||||
},
|
||||
|
||||
// Overwrite the fetchCurrentWeather method.
|
||||
fetchCurrentWeather() {
|
||||
this.fetchData(this.getUrl("3hourly"))
|
||||
.then(data => {
|
||||
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location ||
|
||||
!data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length == 0) {
|
||||
// Did not receive usable new data.
|
||||
// Maybe this needs a better check?
|
||||
return;
|
||||
}
|
||||
|
||||
this.setFetchedLocation(`${data.SiteRep.DV.Location.name}, ${data.SiteRep.DV.Location.country}`);
|
||||
|
||||
const currentWeather = this.generateWeatherObjectFromCurrentWeather(data);
|
||||
this.setCurrentWeather(currentWeather);
|
||||
})
|
||||
.catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
// Overwrite the fetchCurrentWeather method.
|
||||
fetchWeatherForecast() {
|
||||
this.fetchData(this.getUrl("daily"))
|
||||
.then(data => {
|
||||
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location ||
|
||||
!data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length == 0) {
|
||||
// Did not receive usable new data.
|
||||
// Maybe this needs a better check?
|
||||
return;
|
||||
}
|
||||
|
||||
this.setFetchedLocation(`${data.SiteRep.DV.Location.name}, ${data.SiteRep.DV.Location.country}`);
|
||||
|
||||
const forecast = this.generateWeatherObjectsFromForecast(data);
|
||||
this.setWeatherForecast(forecast);
|
||||
})
|
||||
.catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
|
||||
|
||||
/** UK Met Office Specific Methods - These are not part of the default provider methods */
|
||||
/*
|
||||
* Gets the complete url for the request
|
||||
*/
|
||||
getUrl(forecastType) {
|
||||
return this.config.apiBase + this.config.locationID + this.getParams(forecastType);
|
||||
},
|
||||
|
||||
/*
|
||||
* Generate a WeatherObject based on currentWeatherInformation
|
||||
*/
|
||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
// data times are always UTC
|
||||
let nowUtc = moment.utc()
|
||||
let midnightUtc = nowUtc.clone().startOf("day")
|
||||
let timeInMins = nowUtc.diff(midnightUtc, "minutes");
|
||||
|
||||
// loop round each of the (5) periods, look for today (the first period may be yesterday)
|
||||
for (i in currentWeatherData.SiteRep.DV.Location.Period) {
|
||||
let periodDate = moment.utc(currentWeatherData.SiteRep.DV.Location.Period[i].value.substr(0,10), "YYYY-MM-DD")
|
||||
|
||||
// ignore if period is before today
|
||||
if (periodDate.isSameOrAfter(moment.utc().startOf("day"))) {
|
||||
|
||||
// check this is the period we want, after today the diff will be -ve
|
||||
if (moment().diff(periodDate, "minutes") > 0) {
|
||||
// loop round the reports looking for the one we are in
|
||||
// $ value specifies the time in minutes-of-the-day: 0, 180, 360,...1260
|
||||
for (j in currentWeatherData.SiteRep.DV.Location.Period[i].Rep){
|
||||
let p = currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].$;
|
||||
if (timeInMins >= p && timeInMins-180 < p) {
|
||||
// finally got the one we want, so populate weather object
|
||||
currentWeather.humidity = currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].H;
|
||||
currentWeather.temperature = this.convertTemp(currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].T);
|
||||
currentWeather.feelsLikeTemp = this.convertTemp(currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].F);
|
||||
currentWeather.precipitation = parseInt(currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].Pp);
|
||||
currentWeather.windSpeed = this.convertWindSpeed(currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].S);
|
||||
currentWeather.windDirection = this.convertWindDirection(currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].D);
|
||||
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.SiteRep.DV.Location.Period[i].Rep[j].W);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// determine the sunrise/sunset times - not supplied in UK Met Office data
|
||||
let times = this.calcAstroData(currentWeatherData.SiteRep.DV.Location)
|
||||
currentWeather.sunrise = times[0];
|
||||
currentWeather.sunset = times[1];
|
||||
|
||||
return currentWeather;
|
||||
},
|
||||
|
||||
/*
|
||||
* Generate WeatherObjects based on forecast information
|
||||
*/
|
||||
generateWeatherObjectsFromForecast(forecasts) {
|
||||
|
||||
const days = [];
|
||||
|
||||
// loop round the (5) periods getting the data
|
||||
// for each period array, Day is [0], Night is [1]
|
||||
for (j in forecasts.SiteRep.DV.Location.Period) {
|
||||
const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
// data times are always UTC
|
||||
dateStr = forecasts.SiteRep.DV.Location.Period[j].value
|
||||
let periodDate = moment.utc(dateStr.substr(0,10), "YYYY-MM-DD")
|
||||
|
||||
// ignore if period is before today
|
||||
if (periodDate.isSameOrAfter(moment.utc().startOf("day"))) {
|
||||
// populate the weather object
|
||||
weather.date = moment.utc(dateStr.substr(0,10), "YYYY-MM-DD");
|
||||
weather.minTemperature = this.convertTemp(forecasts.SiteRep.DV.Location.Period[j].Rep[1].Nm);
|
||||
weather.maxTemperature = this.convertTemp(forecasts.SiteRep.DV.Location.Period[j].Rep[0].Dm);
|
||||
weather.weatherType = this.convertWeatherType(forecasts.SiteRep.DV.Location.Period[j].Rep[0].W);
|
||||
weather.precipitation = parseInt(forecasts.SiteRep.DV.Location.Period[j].Rep[0].PPd);
|
||||
|
||||
days.push(weather);
|
||||
}
|
||||
}
|
||||
|
||||
return days;
|
||||
},
|
||||
|
||||
/*
|
||||
* calculate the astronomical data
|
||||
*/
|
||||
calcAstroData(location) {
|
||||
const sunTimes = [];
|
||||
|
||||
// determine the sunrise/sunset times
|
||||
let times = SunCalc.getTimes(new Date(), location.lat, location.lon);
|
||||
sunTimes.push(moment(times.sunrise, "X"));
|
||||
sunTimes.push(moment(times.sunset, "X"));
|
||||
|
||||
return sunTimes;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert the Met Office icons to a more usable name.
|
||||
*/
|
||||
convertWeatherType(weatherType) {
|
||||
const weatherTypes = {
|
||||
0: "night-clear",
|
||||
1: "day-sunny",
|
||||
2: "night-alt-cloudy",
|
||||
3: "day-cloudy",
|
||||
5: "fog",
|
||||
6: "fog",
|
||||
7: "cloudy",
|
||||
8: "cloud",
|
||||
9: "night-sprinkle",
|
||||
10: "day-sprinkle",
|
||||
11: "raindrops",
|
||||
12: "sprinkle",
|
||||
13: "night-alt-showers",
|
||||
14: "day-showers",
|
||||
15: "rain",
|
||||
16: "night-alt-sleet",
|
||||
17: "day-sleet",
|
||||
18: "sleet",
|
||||
19: "night-alt-hail",
|
||||
20: "day-hail",
|
||||
21: "hail",
|
||||
22: "night-alt-snow",
|
||||
23: "day-snow",
|
||||
24: "snow",
|
||||
25: "night-alt-snow",
|
||||
26: "day-snow",
|
||||
27: "snow",
|
||||
28: "night-alt-thunderstorm",
|
||||
29: "day-thunderstorm",
|
||||
30: "thunderstorm"
|
||||
};
|
||||
|
||||
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert temp (from degrees C) if required
|
||||
*/
|
||||
convertTemp(tempInC) {
|
||||
return this.tempUnits === "imperial" ? tempInC * 9 / 5 + 32 : tempInC;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert wind speed (from mph) if required
|
||||
*/
|
||||
convertWindSpeed(windInMph) {
|
||||
return this.windUnits === "metric" ? windInMph * 2.23694 : windInMph;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert the wind direction cardinal to value
|
||||
*/
|
||||
convertWindDirection(windDirection) {
|
||||
const windCardinals = {
|
||||
"N": 0,
|
||||
"NNE": 22,
|
||||
"NE": 45,
|
||||
"ENE": 67,
|
||||
"E": 90,
|
||||
"ESE": 112,
|
||||
"SE": 135,
|
||||
"SSE": 157,
|
||||
"S": 180,
|
||||
"SSW": 202,
|
||||
"SW": 225,
|
||||
"WSW": 247,
|
||||
"W": 270,
|
||||
"WNW": 292,
|
||||
"NW": 315,
|
||||
"NNW": 337
|
||||
};
|
||||
|
||||
return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
|
||||
},
|
||||
|
||||
/*
|
||||
* Generates an url with api parameters based on the config.
|
||||
*
|
||||
* return String - URL params.
|
||||
*/
|
||||
getParams(forecastType) {
|
||||
let params = "?";
|
||||
params += "res=" + forecastType;
|
||||
params += "&key=" + this.config.apiKey;
|
||||
|
||||
return params;
|
||||
}
|
||||
});
|
90
modules/default/weather/providers/weathergov.js
Normal file → Executable file
90
modules/default/weather/providers/weathergov.js
Normal file → Executable file
@@ -35,6 +35,7 @@ WeatherProvider.register("weathergov", {
|
||||
.catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
// Overwrite the fetchCurrentWeather method.
|
||||
@@ -53,6 +54,7 @@ WeatherProvider.register("weathergov", {
|
||||
.catch(function(request) {
|
||||
Log.error("Could not load data ... ", request);
|
||||
})
|
||||
.finally(() => this.updateAvailable())
|
||||
},
|
||||
|
||||
/** Weather.gov Specific Methods - These are not part of the default provider methods */
|
||||
@@ -67,13 +69,18 @@ WeatherProvider.register("weathergov", {
|
||||
* Generate a WeatherObject based on currentWeatherInformation
|
||||
*/
|
||||
generateWeatherObjectFromCurrentWeather(currentWeatherData) {
|
||||
const currentWeather = new WeatherObject(this.config.units);
|
||||
const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
currentWeather.temperature = currentWeatherData.temperature;
|
||||
currentWeather.windSpeed = currentWeatherData.windSpeed.split(" ", 1);
|
||||
currentWeather.windDirection = this.convertDirectiontoDegrees(currentWeatherData.windDirection);
|
||||
currentWeather.windDirection = this.convertWindDirection(currentWeatherData.windDirection);
|
||||
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.shortForecast, currentWeatherData.isDaytime);
|
||||
|
||||
// determine the sunrise/sunset times - not supplied in weather.gov data
|
||||
let times = this.calcAstroData(this.config.lat, this.config.lon)
|
||||
currentWeather.sunrise = times[0];
|
||||
currentWeather.sunset = times[1];
|
||||
|
||||
return currentWeather;
|
||||
},
|
||||
|
||||
@@ -95,7 +102,7 @@ WeatherProvider.register("weathergov", {
|
||||
let maxTemp = [];
|
||||
// variable for date
|
||||
let date = "";
|
||||
let weather = new WeatherObject(this.config.units);
|
||||
let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
weather.precipitation = 0;
|
||||
|
||||
for (const forecast of forecasts) {
|
||||
@@ -109,7 +116,7 @@ WeatherProvider.register("weathergov", {
|
||||
// push weather information to days array
|
||||
days.push(weather);
|
||||
// create new weather-object
|
||||
weather = new WeatherObject(this.config.units);
|
||||
weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||
|
||||
minTemp = [];
|
||||
maxTemp = [];
|
||||
@@ -134,9 +141,9 @@ WeatherProvider.register("weathergov", {
|
||||
minTemp.push(forecast.temperature);
|
||||
maxTemp.push(forecast.temperature);
|
||||
}
|
||||
|
||||
|
||||
// last day
|
||||
// calculate minimum/maximum temperature, specify rain amount
|
||||
// calculate minimum/maximum temperature
|
||||
weather.minTemperature = Math.min.apply(null, minTemp);
|
||||
weather.maxTemperature = Math.max.apply(null, maxTemp);
|
||||
|
||||
@@ -145,6 +152,20 @@ WeatherProvider.register("weathergov", {
|
||||
return days.slice(1);
|
||||
},
|
||||
|
||||
/*
|
||||
* Calculate the astronomical data
|
||||
*/
|
||||
calcAstroData(lat, lon) {
|
||||
const sunTimes = [];
|
||||
|
||||
// determine the sunrise/sunset times
|
||||
let times = SunCalc.getTimes(new Date(), lat, lon);
|
||||
sunTimes.push(moment(times.sunrise, "X"));
|
||||
sunTimes.push(moment(times.sunset, "X"));
|
||||
|
||||
return sunTimes;
|
||||
},
|
||||
|
||||
/*
|
||||
* Convert the icons to a more usable name.
|
||||
*/
|
||||
@@ -202,7 +223,7 @@ WeatherProvider.register("weathergov", {
|
||||
}
|
||||
|
||||
return "night-clear";
|
||||
} else if (weatherType.includes("Dust") || weatherType.includes("Sand")) {
|
||||
} else if (weatherType.includes("Dust") || weatherType.includes("Sand")) {
|
||||
return "dust";
|
||||
} else if (weatherType.includes("Fog")) {
|
||||
return "fog";
|
||||
@@ -218,39 +239,26 @@ WeatherProvider.register("weathergov", {
|
||||
/*
|
||||
Convert the direction into Degrees
|
||||
*/
|
||||
convertDirectiontoDegrees(direction) {
|
||||
if (direction === "NNE"){
|
||||
return 33.75;
|
||||
} else if (direction === "NE") {
|
||||
return 56.25;
|
||||
} else if (direction === "ENE") {
|
||||
return 78.75;
|
||||
} else if (direction === "E") {
|
||||
return 101.25;
|
||||
} else if (direction === "ESE") {
|
||||
return 123.75;
|
||||
} else if (direction === "SE") {
|
||||
return 146.25;
|
||||
} else if (direction === "SSE") {
|
||||
return 168.75;
|
||||
} else if (direction === "S") {
|
||||
return 191.25;
|
||||
} else if (direction === "SSW") {
|
||||
return 213.75;
|
||||
} else if (direction === "SW") {
|
||||
return 236.25;
|
||||
} else if (direction === "WSW") {
|
||||
return 258.75;
|
||||
} else if (direction === "W") {
|
||||
return 281.25;
|
||||
} else if (direction === "WNW") {
|
||||
return 303.75;
|
||||
} else if (direction === "NW") {
|
||||
return 326.25;
|
||||
} else if (direction === "NNW") {
|
||||
return 348.75;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
convertWindDirection(windDirection) {
|
||||
const windCardinals = {
|
||||
"N": 0,
|
||||
"NNE": 22,
|
||||
"NE": 45,
|
||||
"ENE": 67,
|
||||
"E": 90,
|
||||
"ESE": 112,
|
||||
"SE": 135,
|
||||
"SSE": 157,
|
||||
"S": 180,
|
||||
"SSW": 202,
|
||||
"SW": 225,
|
||||
"WSW": 247,
|
||||
"W": 270,
|
||||
"WNW": 292,
|
||||
"NW": 315,
|
||||
"NNW": 337
|
||||
};
|
||||
|
||||
return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
|
||||
}
|
||||
});
|
||||
|
@@ -19,6 +19,10 @@ Module.register("weather",{
|
||||
locationID: false,
|
||||
appid: "",
|
||||
units: config.units,
|
||||
|
||||
tempUnits: config.units,
|
||||
windUnits: config.units,
|
||||
|
||||
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
||||
animationSpeed: 1000,
|
||||
timeFormat: config.timeFormat,
|
||||
@@ -68,13 +72,14 @@ Module.register("weather",{
|
||||
"moment.js",
|
||||
"weatherprovider.js",
|
||||
"weatherobject.js",
|
||||
"suncalc.js",
|
||||
this.file("providers/" + this.config.weatherProvider.toLowerCase() + ".js")
|
||||
];
|
||||
},
|
||||
|
||||
// Override getHeader method.
|
||||
getHeader: function() {
|
||||
if (this.config.appendLocationNameToHeader && this.weatherProvider) {
|
||||
if (this.config.appendLocationNameToHeader && this.data.header !== undefined && this.weatherProvider) {
|
||||
return this.data.header + " " + this.weatherProvider.fetchedLocation();
|
||||
}
|
||||
|
||||
@@ -84,6 +89,7 @@ Module.register("weather",{
|
||||
// Start the weather module.
|
||||
start: function () {
|
||||
moment.locale(this.config.lang);
|
||||
|
||||
// Initialize the weather provider.
|
||||
this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this);
|
||||
|
||||
@@ -137,7 +143,7 @@ Module.register("weather",{
|
||||
humidity: this.indoorHumidity,
|
||||
temperature: this.indoorTemperature
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
// What to do when the weather provider has new information available?
|
||||
@@ -188,13 +194,13 @@ Module.register("weather",{
|
||||
|
||||
this.nunjucksEnvironment().addFilter("unit", function (value, type) {
|
||||
if (type === "temperature") {
|
||||
if (this.config.units === "metric" || this.config.units === "imperial") {
|
||||
if (this.config.tempUnits === "metric" || this.config.tempUnits === "imperial") {
|
||||
value += "°";
|
||||
}
|
||||
if (this.config.degreeLabel) {
|
||||
if (this.config.units === "metric") {
|
||||
if (this.config.tempUnits === "metric") {
|
||||
value += "C";
|
||||
} else if (this.config.units === "imperial") {
|
||||
} else if (this.config.tempUnits === "imperial") {
|
||||
value += "F";
|
||||
} else {
|
||||
value += "K";
|
||||
@@ -204,10 +210,14 @@ Module.register("weather",{
|
||||
if (isNaN(value) || value === 0 || value.toFixed(2) === "0.00") {
|
||||
value = "";
|
||||
} else {
|
||||
value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`;
|
||||
if (this.config.weatherProvider === "ukmetoffice") {
|
||||
value += "%";
|
||||
} else {
|
||||
value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`;
|
||||
}
|
||||
}
|
||||
} else if (type === "humidity") {
|
||||
value += "%"
|
||||
value += "%";
|
||||
}
|
||||
|
||||
return value;
|
||||
|
18
modules/default/weather/weatherobject.js
Normal file → Executable file
18
modules/default/weather/weatherobject.js
Normal file → Executable file
@@ -13,8 +13,11 @@
|
||||
// As soon as we start implementing the forecast, mode properties will be added.
|
||||
|
||||
class WeatherObject {
|
||||
constructor(units) {
|
||||
constructor(units, tempUnits, windUnits) {
|
||||
|
||||
this.units = units;
|
||||
this.tempUnits = tempUnits;
|
||||
this.windUnits = windUnits;
|
||||
this.date = null;
|
||||
this.windSpeed = null;
|
||||
this.windDirection = null;
|
||||
@@ -28,6 +31,8 @@ class WeatherObject {
|
||||
this.rain = null;
|
||||
this.snow = null;
|
||||
this.precipitation = null;
|
||||
this.feelsLikeTemp = null;
|
||||
|
||||
}
|
||||
|
||||
cardinalWindDirection() {
|
||||
@@ -67,7 +72,7 @@ class WeatherObject {
|
||||
}
|
||||
|
||||
beaufortWindSpeed() {
|
||||
const windInKmh = this.units === "imperial" ? this.windSpeed * 1.609344 : this.windSpeed * 60 * 60 / 1000;
|
||||
const windInKmh = (this.windUnits === "imperial") ? this.windSpeed * 1.609344 : this.windSpeed * 60 * 60 / 1000;
|
||||
const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000];
|
||||
for (const [index, speed] of speeds.entries()) {
|
||||
if (speed > windInKmh) {
|
||||
@@ -82,8 +87,11 @@ class WeatherObject {
|
||||
}
|
||||
|
||||
feelsLike() {
|
||||
const windInMph = this.units === "imperial" ? this.windSpeed : this.windSpeed * 2.23694;
|
||||
const tempInF = this.units === "imperial" ? this.temperature : this.temperature * 9 / 5 + 32;
|
||||
if (this.feelsLikeTemp) {
|
||||
return this.feelsLikeTemp;
|
||||
}
|
||||
const windInMph = (this.windUnits === "imperial") ? this.windSpeed : this.windSpeed * 2.23694;
|
||||
const tempInF = this.tempUnits === "imperial" ? this.temperature : this.temperature * 9 / 5 + 32;
|
||||
let feelsLike = tempInF;
|
||||
|
||||
if (windInMph > 3 && tempInF < 50) {
|
||||
@@ -97,6 +105,6 @@ class WeatherObject {
|
||||
- 1.99 * Math.pow(10, -6) * tempInF * tempInF * this.humidity * this.humidity;
|
||||
}
|
||||
|
||||
return this.units === "imperial" ? feelsLike : (feelsLike - 32) * 5 / 9;
|
||||
return this.tempUnits === "imperial" ? feelsLike : (feelsLike - 32) * 5 / 9;
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@
|
||||
* This class is the blueprint for a weather provider.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Base BluePrint for the WeatherProvider
|
||||
*/
|
||||
@@ -23,15 +22,14 @@ var WeatherProvider = Class.extend({
|
||||
weatherForecastArray: null,
|
||||
fetchedLocationName: null,
|
||||
|
||||
// The following properties will be set automaticly.
|
||||
// The following properties will be set automatically.
|
||||
// You do not need to overwrite these properties.
|
||||
config: null,
|
||||
delegate: null,
|
||||
providerIdentifier: null,
|
||||
|
||||
|
||||
// Weather Provider Methods
|
||||
// All the following methods can be overwrited, although most are good as they are.
|
||||
// All the following methods can be overwritten, although most are good as they are.
|
||||
|
||||
// Called when a weather provider is initialized.
|
||||
init: function(config) {
|
||||
@@ -51,13 +49,13 @@ var WeatherProvider = Class.extend({
|
||||
},
|
||||
|
||||
// This method should start the API request to fetch the current weather.
|
||||
// This method should definetly be overwritten in the provider.
|
||||
// This method should definitely be overwritten in the provider.
|
||||
fetchCurrentWeather: function() {
|
||||
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchCurrentWeather method.`);
|
||||
},
|
||||
|
||||
// This method should start the API request to fetch the weather forecast.
|
||||
// This method should definetly be overwritten in the provider.
|
||||
// This method should definitely be overwritten in the provider.
|
||||
fetchWeatherForecast: function() {
|
||||
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherForecast method.`);
|
||||
},
|
||||
@@ -81,16 +79,12 @@ var WeatherProvider = Class.extend({
|
||||
setCurrentWeather: function(currentWeatherObject) {
|
||||
// We should check here if we are passing a WeatherDay
|
||||
this.currentWeatherObject = currentWeatherObject;
|
||||
|
||||
this.updateAvailable();
|
||||
},
|
||||
|
||||
// Set the weatherForecastArray and notify the delegate that new information is available.
|
||||
setWeatherForecast: function(weatherForecastArray) {
|
||||
// We should check here if we are passing a WeatherDay
|
||||
this.weatherForecastArray = weatherForecastArray;
|
||||
|
||||
this.updateAvailable();
|
||||
},
|
||||
|
||||
// Set the fetched location name.
|
||||
@@ -103,7 +97,7 @@ var WeatherProvider = Class.extend({
|
||||
this.delegate.updateAvailable(this);
|
||||
},
|
||||
|
||||
// A convinience function to make requests. It returns a promise.
|
||||
// A convenience function to make requests. It returns a promise.
|
||||
fetchData: function(url, method = "GET", data = null) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var request = new XMLHttpRequest();
|
||||
@@ -113,12 +107,12 @@ var WeatherProvider = Class.extend({
|
||||
if (this.status === 200) {
|
||||
resolve(JSON.parse(this.response));
|
||||
} else {
|
||||
reject(request)
|
||||
reject(request);
|
||||
}
|
||||
}
|
||||
};
|
||||
request.send();
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -19,7 +19,7 @@ modules: [
|
||||
config: {
|
||||
// See 'Configuration options' for more information.
|
||||
location: "Amsterdam,Netherlands",
|
||||
locationID: "", //Location ID from http://openweathermap.org/help/city_list.txt
|
||||
locationID: "", //Location ID from http://bulk.openweathermap.org/sample/city.list.json.gz
|
||||
appid: "abcde12345abcde12345abcde12345ab" //openweathermap.org API key.
|
||||
}
|
||||
}
|
||||
|
@@ -19,9 +19,9 @@
|
||||
}
|
||||
|
||||
.weatherforecast tr.colored .min-temp {
|
||||
color: #BCDDFF;
|
||||
color: #BCDDFF;
|
||||
}
|
||||
|
||||
.weatherforecast tr.colored .max-temp {
|
||||
color: #FF8E99;
|
||||
color: #FF8E99;
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ Module.register("weatherforecast",{
|
||||
getTranslations: function() {
|
||||
// The translations for the default modules are defined in the core translation files.
|
||||
// Therefor we can just return false. Otherwise we should have returned a dictionary.
|
||||
// If you're trying to build yiur own module including translations, check out the documentation.
|
||||
// If you're trying to build your own module including translations, check out the documentation.
|
||||
return false;
|
||||
},
|
||||
|
||||
@@ -180,9 +180,9 @@ Module.register("weatherforecast",{
|
||||
rainCell.innerHTML = "";
|
||||
} else {
|
||||
if(config.units !== "imperial") {
|
||||
rainCell.innerHTML = parseFloat(forecast.rain).toFixed(1) + " mm";
|
||||
rainCell.innerHTML = parseFloat(forecast.rain).toFixed(1).replace(".", this.config.decimalSymbol) + " mm";
|
||||
} else {
|
||||
rainCell.innerHTML = (parseFloat(forecast.rain) / 25.4).toFixed(2) + " in";
|
||||
rainCell.innerHTML = (parseFloat(forecast.rain) / 25.4).toFixed(2).replace(".", this.config.decimalSymbol) + " in";
|
||||
}
|
||||
}
|
||||
rainCell.className = "align-right bright rain";
|
||||
@@ -240,7 +240,7 @@ Module.register("weatherforecast",{
|
||||
|
||||
/* updateWeather(compliments)
|
||||
* Requests new data from openweather.org.
|
||||
* Calls processWeather on succesfull response.
|
||||
* Calls processWeather on successful response.
|
||||
*/
|
||||
updateWeather: function() {
|
||||
if (this.config.appid === "") {
|
||||
@@ -261,7 +261,7 @@ Module.register("weatherforecast",{
|
||||
} else if (this.status === 401) {
|
||||
self.updateDom(self.config.animationSpeed);
|
||||
|
||||
if (self.config.forecastEndpoint == "forecast/daily") {
|
||||
if (self.config.forecastEndpoint === "forecast/daily") {
|
||||
self.config.forecastEndpoint = "forecast";
|
||||
Log.warn(self.name + ": Your AppID does not support long term forecasts. Switching to fallback endpoint.");
|
||||
}
|
||||
@@ -291,7 +291,7 @@ Module.register("weatherforecast",{
|
||||
} else if(this.config.location) {
|
||||
params += "q=" + this.config.location;
|
||||
} else if (this.firstEvent && this.firstEvent.geo) {
|
||||
params += "lat=" + this.firstEvent.geo.lat + "&lon=" + this.firstEvent.geo.lon
|
||||
params += "lat=" + this.firstEvent.geo.lat + "&lon=" + this.firstEvent.geo.lon;
|
||||
} else if (this.firstEvent && this.firstEvent.location) {
|
||||
params += "q=" + this.firstEvent.location;
|
||||
} else {
|
||||
@@ -315,7 +315,7 @@ Module.register("weatherforecast",{
|
||||
*/
|
||||
parserDataWeather: function(data) {
|
||||
if (data.hasOwnProperty("main")) {
|
||||
data["temp"] = {"min": data.main.temp_min, "max": data.main.temp_max}
|
||||
data["temp"] = {"min": data.main.temp_min, "max": data.main.temp_max};
|
||||
}
|
||||
return data;
|
||||
},
|
||||
@@ -330,7 +330,7 @@ Module.register("weatherforecast",{
|
||||
|
||||
this.forecast = [];
|
||||
var lastDay = null;
|
||||
var forecastData = {}
|
||||
var forecastData = {};
|
||||
|
||||
for (var i = 0, count = data.list.length; i < count; i++) {
|
||||
|
||||
@@ -353,7 +353,7 @@ Module.register("weatherforecast",{
|
||||
icon: this.config.iconTable[forecast.weather[0].icon],
|
||||
maxTemp: this.roundValue(forecast.temp.max),
|
||||
minTemp: this.roundValue(forecast.temp.min),
|
||||
rain: forecast.rain
|
||||
rain: this.processRain(forecast, data.list)
|
||||
};
|
||||
|
||||
this.forecast.push(forecastData);
|
||||
@@ -434,5 +434,38 @@ Module.register("weatherforecast",{
|
||||
roundValue: function(temperature) {
|
||||
var decimals = this.config.roundTemp ? 0 : 1;
|
||||
return parseFloat(temperature).toFixed(decimals);
|
||||
},
|
||||
|
||||
/* processRain(forecast, allForecasts)
|
||||
* Calculates the amount of rain for a whole day even if long term forecasts isn't available for the appid.
|
||||
*
|
||||
* When using the the fallback endpoint forecasts are provided in 3h intervals and the rain-property is an object instead of number.
|
||||
* That object has a property "3h" which contains the amount of rain since the previous forecast in the list.
|
||||
* This code finds all forecasts that is for the same day and sums the amount of rain and returns that.
|
||||
*/
|
||||
processRain: function(forecast, allForecasts) {
|
||||
//If the amount of rain actually is a number, return it
|
||||
if (!isNaN(forecast.rain)) {
|
||||
return forecast.rain;
|
||||
}
|
||||
|
||||
//Find all forecasts that is for the same day
|
||||
var checkDateTime = (!!forecast.dt_txt) ? moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(forecast.dt, "X");
|
||||
var daysForecasts = allForecasts.filter(function(item) {
|
||||
var itemDateTime = (!!item.dt_txt) ? moment(item.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(item.dt, "X");
|
||||
return itemDateTime.isSame(checkDateTime, "day") && item.rain instanceof Object;
|
||||
});
|
||||
|
||||
//If no rain this day return undefined so it wont be displayed for this day
|
||||
if (daysForecasts.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
//Summarize all the rain from the matching days
|
||||
return daysForecasts.map(function(item) {
|
||||
return Object.values(item.rain)[0];
|
||||
}).reduce(function(a, b) {
|
||||
return a + b;
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
|
7201
package-lock.json
generated
7201
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "magicmirror",
|
||||
"version": "2.7.1",
|
||||
"version": "2.10.0",
|
||||
"description": "The open source modular smart mirror platform.",
|
||||
"main": "js/electron.js",
|
||||
"scripts": {
|
||||
"start": "sh run-start.sh",
|
||||
"start": "./run-start.sh",
|
||||
"install": "cd vendor && npm install",
|
||||
"install-fonts": "cd fonts && npm install",
|
||||
"postinstall": "sh installers/postinstall/postinstall.sh && npm run install-fonts",
|
||||
"postinstall": "sh untrack-css.sh && sh installers/postinstall/postinstall.sh && npm run install-fonts",
|
||||
"test": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests --recursive",
|
||||
"test:unit": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests/unit --recursive",
|
||||
"test:e2e": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests/e2e --recursive",
|
||||
@@ -41,37 +41,42 @@
|
||||
"grunt": "latest",
|
||||
"grunt-eslint": "latest",
|
||||
"grunt-jsonlint": "latest",
|
||||
"grunt-markdownlint": "^1.0.43",
|
||||
"grunt-markdownlint": "latest",
|
||||
"grunt-stylelint": "latest",
|
||||
"grunt-yamllint": "latest",
|
||||
"http-auth": "^3.2.3",
|
||||
"jsdom": "^11.6.2",
|
||||
"jshint": "^2.9.5",
|
||||
"jshint": "^2.10.2",
|
||||
"mocha": "^4.1.0",
|
||||
"mocha-each": "^1.1.0",
|
||||
"mocha-logger": "^1.0.6",
|
||||
"spectron": "^3.8.0",
|
||||
"stylelint": "^8.4.0",
|
||||
"stylelint": "latest",
|
||||
"stylelint-config-standard": "latest",
|
||||
"time-grunt": "latest"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"electron": "^3.0.13"
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": "6.5.5",
|
||||
"body-parser": "^1.18.2",
|
||||
"colors": "^1.1.2",
|
||||
"electron": "^3.0.13",
|
||||
"console-stamp": "^0.2.9",
|
||||
"express": "^4.16.2",
|
||||
"express-ipfilter": "0.3.1",
|
||||
"express-ipfilter": "^1.0.1",
|
||||
"feedme": "latest",
|
||||
"helmet": "^3.9.0",
|
||||
"home-path": "^1.0.6",
|
||||
"helmet": "^3.21.2",
|
||||
"iconv-lite": "latest",
|
||||
"mocha-logger": "^1.0.6",
|
||||
"lodash": "^4.17.15",
|
||||
"module-alias": "^2.2.2",
|
||||
"moment": "latest",
|
||||
"request": "^2.87.0",
|
||||
"request": "^2.88.0",
|
||||
"rrule": "^2.6.2",
|
||||
"rrule-alt": "^2.2.8",
|
||||
"simple-git": "^1.85.0",
|
||||
"socket.io": "^2.1.1",
|
||||
"valid-url": "latest",
|
||||
"walk": "latest"
|
||||
"valid-url": "latest"
|
||||
},
|
||||
"_moduleAliases": {
|
||||
"node_helper": "js/node_helper.js"
|
||||
}
|
||||
}
|
||||
|
65
run-start.sh
Normal file → Executable file
65
run-start.sh
Normal file → Executable file
@@ -1,4 +1,67 @@
|
||||
#!/bin/bash
|
||||
# use bash instead of sh
|
||||
./untrack-css.sh
|
||||
|
||||
if [ -z "$DISPLAY" ]; then #If not set DISPLAY is SSH remote or tty
|
||||
export DISPLAY=:0 # Set by default display
|
||||
fi
|
||||
electron js/electron.js $1
|
||||
# get the processor architecture
|
||||
arch=$(uname -m)
|
||||
false='false'
|
||||
|
||||
# get the config option, if any
|
||||
# only check non comment lines
|
||||
serveronly=$(grep -v '^\s//' config/config.js | grep -i serveronly: | awk '{print tolower($2)}' | tr -d ,\"\')
|
||||
# set default if not defined in config
|
||||
serveronly=${serveronly:-false}
|
||||
# check for xwindows running
|
||||
xorg=$(pgrep Xorg)
|
||||
#check for macOS
|
||||
mac=$(uname)
|
||||
#
|
||||
# if the user requested serveronly OR
|
||||
# electron support for armv6l has been dropped OR
|
||||
# system is in text mode
|
||||
#
|
||||
if [ "$serveronly." != "false." -o "$arch" == "armv6l" ] || [ "$xorg." == "." -a $mac != 'Darwin' ]; then
|
||||
|
||||
# if user explicitly configured to run server only (no ui local)
|
||||
# OR there is no xwindows running, so no support for browser graphics
|
||||
if [ "$serveronly." == "true." -o "$xorg." == "." ]; then
|
||||
# start server mode,
|
||||
node serveronly
|
||||
else
|
||||
# start the server in the background
|
||||
# wait for server to be ready
|
||||
# need bash for this
|
||||
exec 3< <(node serveronly)
|
||||
|
||||
# Read the output of server line by line until one line 'point your browser'
|
||||
while read line; do
|
||||
case "$line" in
|
||||
*point\ your\ browser*)
|
||||
echo $line
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo $line
|
||||
#sleep .25
|
||||
;;
|
||||
esac
|
||||
done <&3
|
||||
|
||||
# Close the file descriptor
|
||||
exec 3<&-
|
||||
|
||||
# lets use chrome to display here now
|
||||
# get the server port address from the ready message
|
||||
port=$(echo $line | awk -F\: '{print $4}')
|
||||
# start chromium
|
||||
echo "Starting chromium browser now, have patience, it takes a minute"
|
||||
chromium-browser -noerrdialogs -kiosk -start_maximized --disable-infobars --app=http://localhost:$port --ignore-certificate-errors-spki-list --ignore-ssl-errors --ignore-certificate-errors 2>/dev/null
|
||||
exit
|
||||
fi
|
||||
else
|
||||
# we can use electron directly
|
||||
electron js/electron.js $1;
|
||||
fi
|
||||
|
@@ -16,7 +16,7 @@ var Utils = require(__dirname + "/../../js/utils.js");
|
||||
|
||||
/* getConfigFile()
|
||||
* Return string with path of configuration file
|
||||
* Check if set by enviroment variable MM_CONFIG_FILE
|
||||
* Check if set by environment variable MM_CONFIG_FILE
|
||||
*/
|
||||
function getConfigFile() {
|
||||
// FIXME: This function should be in core. Do you want refactor me ;) ?, be good!
|
||||
@@ -35,7 +35,7 @@ function checkConfigFile() {
|
||||
console.error(Utils.colors.error("File not found: "), configFileName);
|
||||
return;
|
||||
}
|
||||
// check permision
|
||||
// check permission
|
||||
try {
|
||||
fs.accessSync(configFileName, fs.F_OK);
|
||||
} catch (e) {
|
||||
@@ -52,12 +52,12 @@ function checkConfigFile() {
|
||||
if (err) { throw err; }
|
||||
v.JSHINT(data); // Parser by jshint
|
||||
|
||||
if (v.JSHINT.errors.length == 0) {
|
||||
if (v.JSHINT.errors.length === 0) {
|
||||
console.log("Your configuration file doesn't contain syntax errors :)");
|
||||
return true;
|
||||
} else {
|
||||
errors = v.JSHINT.data().errors;
|
||||
for (idx in errors) {
|
||||
for (var idx in errors) {
|
||||
error = errors[idx];
|
||||
console.log("Line", error.line, "col", error.character, error.reason);
|
||||
}
|
||||
@@ -67,4 +67,4 @@ function checkConfigFile() {
|
||||
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
checkConfigFile();
|
||||
};
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* Magic Mirror Test config sample enviroment
|
||||
/* Magic Mirror Test config sample environment
|
||||
*
|
||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
||||
* MIT Licensed.
|
||||
|
@@ -6,7 +6,6 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
|
||||
var config = {
|
||||
port: 8080,
|
||||
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
|
||||
|
35
tests/configs/modules/weather/currentweather_default.js
Normal file
35
tests/configs/modules/weather/currentweather_default.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Magic Mirror Test config default weather
|
||||
*
|
||||
* By fewieden https://github.com/fewieden
|
||||
*
|
||||
* 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: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
initialLoadDelay: 3000
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
40
tests/configs/modules/weather/currentweather_options.js
Normal file
40
tests/configs/modules/weather/currentweather_options.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/* Magic Mirror Test config default weather
|
||||
*
|
||||
* By fewieden https://github.com/fewieden
|
||||
*
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
let config = {
|
||||
port: 8080,
|
||||
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
|
||||
|
||||
language: "en",
|
||||
timeFormat: 24,
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
},
|
||||
},
|
||||
|
||||
modules: [
|
||||
{
|
||||
module: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
initialLoadDelay: 3000,
|
||||
useBeaufort: false,
|
||||
showWindDirectionAsArrow: true,
|
||||
showHumidity: true,
|
||||
roundTemp: true,
|
||||
degreeLabel: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
37
tests/configs/modules/weather/currentweather_units.js
Normal file
37
tests/configs/modules/weather/currentweather_units.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Magic Mirror Test config default weather
|
||||
*
|
||||
* By fewieden https://github.com/fewieden
|
||||
*
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
let config = {
|
||||
port: 8080,
|
||||
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
|
||||
|
||||
language: "en",
|
||||
timeFormat: 24,
|
||||
units: "imperial",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
},
|
||||
},
|
||||
|
||||
modules: [
|
||||
{
|
||||
module: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
initialLoadDelay: 3000,
|
||||
decimalSymbol: ",",
|
||||
showHumidity: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
37
tests/configs/modules/weather/forecastweather_default.js
Normal file
37
tests/configs/modules/weather/forecastweather_default.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Magic Mirror Test config default weather
|
||||
*
|
||||
* By fewieden https://github.com/fewieden
|
||||
*
|
||||
* 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: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
type: "forecast",
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
weatherEndpoint: "/forecast/daily",
|
||||
initialLoadDelay: 3000
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
40
tests/configs/modules/weather/forecastweather_options.js
Normal file
40
tests/configs/modules/weather/forecastweather_options.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/* Magic Mirror Test config default weather
|
||||
*
|
||||
* By fewieden https://github.com/fewieden
|
||||
*
|
||||
* 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: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
type: "forecast",
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
weatherEndpoint: "/forecast/daily",
|
||||
initialLoadDelay: 3000,
|
||||
showPrecipitationAmount: true,
|
||||
colored: true,
|
||||
tableClass: "myTableClass"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
@@ -1,4 +1,4 @@
|
||||
/* Magic Mirror Test config sample enviroment set por 8090
|
||||
/* Magic Mirror Test config sample environment set port 8090
|
||||
*
|
||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
||||
* MIT Licensed.
|
||||
|
@@ -1,13 +1,8 @@
|
||||
const helpers = require("./global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
const it = global.it;
|
||||
const beforeEach = global.beforeEach;
|
||||
const afterEach = global.afterEach;
|
||||
|
||||
describe("Development console tests", function() {
|
||||
// This tests fail and crash another tests
|
||||
|
@@ -1,7 +1,5 @@
|
||||
const helpers = require("./global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
|
@@ -1,14 +1,9 @@
|
||||
const helpers = require("./global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
const forEach = require("mocha-each");
|
||||
|
||||
const describe = global.describe;
|
||||
const it = global.it;
|
||||
const beforeEach = global.beforeEach;
|
||||
const afterEach = global.afterEach;
|
||||
const forEach = require("mocha-each");
|
||||
|
||||
describe("All font files from roboto.css should be downloadable", function() {
|
||||
helpers.setupTimeout(this);
|
||||
@@ -18,7 +13,7 @@ describe("All font files from roboto.css should be downloadable", function() {
|
||||
var fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");
|
||||
var regex = /\burl\(['"]([^'"]+)['"]\)/g;
|
||||
var match = regex.exec(fileContent);
|
||||
while (match != null) {
|
||||
while (match !== null) {
|
||||
// Push 1st match group onto fontFiles stack
|
||||
fontFiles.push(match[1]);
|
||||
// Find the next one
|
||||
|
@@ -12,7 +12,6 @@ const Application = require("spectron").Application;
|
||||
const assert = require("assert");
|
||||
const chai = require("chai");
|
||||
const chaiAsPromised = require("chai-as-promised");
|
||||
|
||||
const path = require("path");
|
||||
|
||||
global.before(function() {
|
||||
|
@@ -1,7 +1,5 @@
|
||||
const helpers = require("./global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
@@ -17,7 +15,7 @@ describe("ipWhitelist directive configuration", function () {
|
||||
beforeEach(function () {
|
||||
return helpers.startApplication({
|
||||
args: ["js/electron.js"]
|
||||
}).then(function (startedApp) { app = startedApp; })
|
||||
}).then(function (startedApp) { app = startedApp; });
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@@ -1,10 +1,6 @@
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
const serverBasicAuth = require("../../servers/basic-auth.js");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
const it = global.it;
|
||||
const beforeEach = global.beforeEach;
|
||||
@@ -72,7 +68,7 @@ describe("Calendar module", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Basic auth backward compatibilty configuration: DEPRECATED", function() {
|
||||
describe("Basic auth backward compatibility configuration: DEPRECATED", function() {
|
||||
before(function() {
|
||||
serverBasicAuth.listen(8012);
|
||||
// Set config sample for use in test
|
||||
|
@@ -1,8 +1,4 @@
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
const it = global.it;
|
||||
@@ -86,5 +82,4 @@ describe("Clock set to spanish language module", function() {
|
||||
.getText(".clock .week").should.eventually.match(weekRegex);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -1,8 +1,4 @@
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
const it = global.it;
|
||||
|
@@ -1,7 +1,4 @@
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
|
@@ -1,8 +1,4 @@
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
const it = global.it;
|
||||
@@ -24,7 +20,6 @@ describe("Test helloworld module", function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
afterEach(function() {
|
||||
return helpers.stopApplication(app);
|
||||
});
|
||||
@@ -52,5 +47,4 @@ describe("Test helloworld module", function() {
|
||||
.getText(".helloworld").should.eventually.equal("Hello World!");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
4
tests/e2e/modules/mocks/index.js
Normal file
4
tests/e2e/modules/mocks/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const generateWeather = require("./weather_current");
|
||||
const generateWeatherForecast = require("./weather_forecast");
|
||||
|
||||
module.exports = {generateWeather, generateWeatherForecast};
|
54
tests/e2e/modules/mocks/weather_current.js
Normal file
54
tests/e2e/modules/mocks/weather_current.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
function generateWeather(extendedData = {}) {
|
||||
return JSON.stringify(_.merge({}, {
|
||||
coord:{
|
||||
lon: 11.58,
|
||||
lat: 48.14
|
||||
},
|
||||
weather:[
|
||||
{
|
||||
id: 615,
|
||||
main: "Snow",
|
||||
description: "light rain and snow",
|
||||
icon: "13d"
|
||||
},
|
||||
{
|
||||
id: 500,
|
||||
main: "Rain",
|
||||
description: "light rain",
|
||||
icon: "10d"
|
||||
}
|
||||
],
|
||||
base: "stations",
|
||||
main:{
|
||||
temp: 1.49,
|
||||
pressure: 1005,
|
||||
humidity: 93.7,
|
||||
temp_min: 1,
|
||||
temp_max: 2
|
||||
},
|
||||
visibility: 7000,
|
||||
wind:{
|
||||
speed: 11.8,
|
||||
deg: 250
|
||||
},
|
||||
clouds:{
|
||||
all: 75
|
||||
},
|
||||
dt: 1547387400,
|
||||
sys:{
|
||||
type: 1,
|
||||
id: 1267,
|
||||
message: 0.0031,
|
||||
country: "DE",
|
||||
sunrise: 1547362817,
|
||||
sunset: 1547394301
|
||||
},
|
||||
id: 2867714,
|
||||
name: "Munich",
|
||||
cod: 200
|
||||
}, extendedData));
|
||||
}
|
||||
|
||||
module.exports = generateWeather;
|
97
tests/e2e/modules/mocks/weather_forecast.js
Normal file
97
tests/e2e/modules/mocks/weather_forecast.js
Normal file
@@ -0,0 +1,97 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
function generateWeatherForecast(extendedData = {}) {
|
||||
return JSON.stringify(_.merge({}, {
|
||||
"city": {
|
||||
"id": 2867714,
|
||||
"name": "Munich",
|
||||
"coord": {"lon": 11.5754, "lat": 48.1371},
|
||||
"country": "DE",
|
||||
"population": 1260391,
|
||||
"timezone": 7200
|
||||
},
|
||||
"cod": "200",
|
||||
"message": 0.9653487,
|
||||
"cnt": 7,
|
||||
"list": [{
|
||||
"dt": 1568372400,
|
||||
"sunrise": 1568350044,
|
||||
"sunset": 1568395948,
|
||||
"temp": {"day": 24.44, "min": 15.35, "max": 24.44, "night": 15.35, "eve": 18, "morn": 23.03},
|
||||
"pressure": 1031.65,
|
||||
"humidity": 70,
|
||||
"weather": [{"id": 801, "main": "Clouds", "description": "few clouds", "icon": "02d"}],
|
||||
"speed": 3.35,
|
||||
"deg": 314,
|
||||
"clouds": 21
|
||||
}, {
|
||||
"dt": 1568458800,
|
||||
"sunrise": 1568436525,
|
||||
"sunset": 1568482223,
|
||||
"temp": {"day": 20.81, "min": 13.56, "max": 21.02, "night": 13.56, "eve": 16.6, "morn": 15.88},
|
||||
"pressure": 1028.81,
|
||||
"humidity": 72,
|
||||
"weather": [{"id": 500, "main": "Rain", "description": "light rain", "icon": "10d"}],
|
||||
"speed": 2.21,
|
||||
"deg": 81,
|
||||
"clouds": 100
|
||||
}, {
|
||||
"dt": 1568545200,
|
||||
"sunrise": 1568523007,
|
||||
"sunset": 1568568497,
|
||||
"temp": {"day": 22.65, "min": 13.76, "max": 22.88, "night": 15.27, "eve": 17.45, "morn": 13.76},
|
||||
"pressure": 1023.75,
|
||||
"humidity": 64,
|
||||
"weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}],
|
||||
"speed": 1.15,
|
||||
"deg": 7,
|
||||
"clouds": 0
|
||||
}, {
|
||||
"dt": 1568631600,
|
||||
"sunrise": 1568609489,
|
||||
"sunset": 1568654771,
|
||||
"temp": {"day": 23.45, "min": 13.95, "max": 23.45, "night": 13.95, "eve": 17.75, "morn": 15.21},
|
||||
"pressure": 1020.41,
|
||||
"humidity": 64,
|
||||
"weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}],
|
||||
"speed": 3.07,
|
||||
"deg": 298,
|
||||
"clouds": 7
|
||||
}, {
|
||||
"dt": 1568718000,
|
||||
"sunrise": 1568695970,
|
||||
"sunset": 1568741045,
|
||||
"temp": {"day": 20.55, "min": 10.95, "max": 20.55, "night": 10.95, "eve": 14.82, "morn": 13.24},
|
||||
"pressure": 1019.4,
|
||||
"humidity": 66,
|
||||
"weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}],
|
||||
"speed": 2.8,
|
||||
"deg": 333,
|
||||
"clouds": 2
|
||||
}, {
|
||||
"dt": 1568804400,
|
||||
"sunrise": 1568782452,
|
||||
"sunset": 1568827319,
|
||||
"temp": {"day": 18.15, "min": 7.75, "max": 18.15, "night": 7.75, "eve": 12.45, "morn": 9.41},
|
||||
"pressure": 1017.56,
|
||||
"humidity": 52,
|
||||
"weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}],
|
||||
"speed": 2.92,
|
||||
"deg": 34,
|
||||
"clouds": 0
|
||||
}, {
|
||||
"dt": 1568890800,
|
||||
"sunrise": 1568868934,
|
||||
"sunset": 1568913593,
|
||||
"temp": {"day": 14.85, "min": 5.56, "max": 15.05, "night": 5.56, "eve": 9.56, "morn": 6.25},
|
||||
"pressure": 1022.7,
|
||||
"humidity": 59,
|
||||
"weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}],
|
||||
"speed": 2.89,
|
||||
"deg": 51,
|
||||
"clouds": 1
|
||||
}]
|
||||
}, extendedData));
|
||||
}
|
||||
|
||||
module.exports = generateWeatherForecast;
|
@@ -1,8 +1,4 @@
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const request = require("request");
|
||||
|
||||
const expect = require("chai").expect;
|
||||
|
||||
const describe = global.describe;
|
||||
const it = global.it;
|
||||
|
270
tests/e2e/modules/weather_spec.js
Normal file
270
tests/e2e/modules/weather_spec.js
Normal file
@@ -0,0 +1,270 @@
|
||||
const expect = require("chai").expect;
|
||||
const fs = require("fs");
|
||||
const moment = require("moment");
|
||||
const path = require("path");
|
||||
const wdajaxstub = require("webdriverajaxstub");
|
||||
|
||||
const helpers = require("../global-setup");
|
||||
|
||||
const {generateWeather, generateWeatherForecast} = require("./mocks");
|
||||
|
||||
const wait = () => new Promise(res => setTimeout(res, 3000));
|
||||
|
||||
describe("Weather module", function() {
|
||||
let app;
|
||||
|
||||
helpers.setupTimeout(this);
|
||||
|
||||
async function setup(responses) {
|
||||
app = await helpers.startApplication({
|
||||
args: ["js/electron.js"]
|
||||
});
|
||||
|
||||
wdajaxstub.init(app.client, responses);
|
||||
|
||||
app.client.setupStub();
|
||||
}
|
||||
|
||||
afterEach(function() {
|
||||
return helpers.stopApplication(app);
|
||||
});
|
||||
|
||||
describe("Current weather", function() {
|
||||
let template;
|
||||
|
||||
before(function() {
|
||||
template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "current.njk"), "utf8");
|
||||
});
|
||||
|
||||
describe("Default configuration", function() {
|
||||
before(function() {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_default.js";
|
||||
});
|
||||
|
||||
it("should render wind speed and wind direction", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
||||
});
|
||||
|
||||
it("should render sunrise", async function() {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().startOf("day").unix();
|
||||
|
||||
const weather = generateWeather({sys: {sunrise, sunset}});
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunrise", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "12:00 am", 10000);
|
||||
});
|
||||
|
||||
it("should render sunset", async function() {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().endOf("day").unix();
|
||||
|
||||
const weather = generateWeather({sys: {sunrise, sunset}});
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunset", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "11:59 pm", 10000);
|
||||
});
|
||||
|
||||
it("should render temperature with icon", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .large.light span.wi.weathericon.wi-snow", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .large.light span.bright", "1.5°", 10000);
|
||||
});
|
||||
|
||||
it("should render feels like temperature", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -5.6°", 10000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", function() {
|
||||
before(function() {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_options.js";
|
||||
});
|
||||
|
||||
it("should render useBeaufort = false", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "12", 10000);
|
||||
});
|
||||
|
||||
it("should render showWindDirectionAsArrow = true", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium sup i.fa-long-arrow-up", 10000);
|
||||
const element = await app.client.getHTML(".weather .normal.medium sup i.fa-long-arrow-up");
|
||||
|
||||
expect(element).to.include("transform:rotate(250deg);");
|
||||
});
|
||||
|
||||
it("should render showHumidity = true", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93", 10000);
|
||||
return app.client.waitForExist(".weather .normal.medium sup i.wi-humidity", 10000);
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .large.light span.bright", "1°C", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -6°C", 10000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather units", function() {
|
||||
before(function() {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_units.js";
|
||||
});
|
||||
|
||||
it("should render imperial units", async function() {
|
||||
const weather = generateWeather({
|
||||
main:{
|
||||
temp: 1.49 * 9 / 5 + 32,
|
||||
temp_min: 1 * 9 / 5 + 32,
|
||||
temp_max: 2 * 9 / 5 + 32
|
||||
},
|
||||
wind:{
|
||||
speed: 11.8 * 2.23694
|
||||
},
|
||||
});
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
||||
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
||||
});
|
||||
|
||||
it("should render decimalSymbol = ','", async function() {
|
||||
const weather = generateWeather({
|
||||
main:{
|
||||
temp: 1.49 * 9 / 5 + 32,
|
||||
temp_min: 1 * 9 / 5 + 32,
|
||||
temp_max: 2 * 9 / 5 + 32
|
||||
},
|
||||
wind:{
|
||||
speed: 11.8 * 2.23694
|
||||
},
|
||||
});
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93,7", 10000);
|
||||
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Weather Forecast", function() {
|
||||
let template;
|
||||
|
||||
before(function() {
|
||||
template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "forecast.njk"), "utf8");
|
||||
});
|
||||
|
||||
describe("Default configuration", function() {
|
||||
before(function() {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js";
|
||||
});
|
||||
|
||||
it("should render days", async function() {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup([weather, template]);
|
||||
|
||||
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
||||
|
||||
for (const [index, day] of days.entries()) {
|
||||
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
it("should render icons", async function() {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup([weather, template]);
|
||||
|
||||
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
||||
|
||||
for (const [index, icon] of icons.entries()) {
|
||||
await app.client.waitForExist(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
it("should render max temperatures", async function() {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup([weather, template]);
|
||||
|
||||
const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
||||
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
it("should render min temperatures", async function() {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup([weather, template]);
|
||||
|
||||
const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
||||
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
it("should render fading of rows", async function() {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup([weather, template]);
|
||||
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
|
||||
await app.client.waitForExist(".weather table.small", 10000);
|
||||
|
||||
for (const [index, opacity] of opacities.entries()) {
|
||||
const html = await app.client.getHTML(`.weather table.small tr:nth-child(${index + 1})`);
|
||||
expect(html).to.includes(`<tr style="opacity: ${opacity};">`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", function() {
|
||||
before(function() {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_options.js";
|
||||
});
|
||||
|
||||
it("should render custom table class", async function() {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather table.myTableClass", 10000);
|
||||
});
|
||||
|
||||
it("should render colored rows", async function() {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather table.myTableClass", 10000);
|
||||
|
||||
const rows = await app.client.$$(".weather table.myTableClass tr.colored");
|
||||
|
||||
expect(rows.length).to.be.equal(5);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user