Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanKingdon committed May 13, 2019
1 parent 61fa541 commit dd472b9
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"rules": {
"indent": ["error", "tab"],
"quotes": ["error", "double"],
"max-len": ["error", 250],
"curly": "error",
"camelcase": ["error", {"properties": "never"}],
"no-trailing-spaces": ["error"],
"no-irregular-whitespace": ["error"]
},
"env": {
"browser": true,
"node": true,
"es6": true
}
}
5 changes: 5 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "stylelint-config-standard",
"font-family-name-quotes": "double-where-recommended",
"block-no-empty": false
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# MMM-MoonPhase Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [1.0.0] - Unreleased

First public release
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019 Nolan Kingdon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions MMM-MoonPhase.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
*
* MMM-MoonPhase
*
* Nolan Kingdon
* MIT Licensed.
*
* Custom here your css module
*
*/
155 changes: 155 additions & 0 deletions MMM-MoonPhase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/* global Module */

/* Magic Mirror
* Module: MMM-MoonPhase
*
* By Nolan Kingdon
* MIT Licensed.
*/

Module.register("MMM-MoonPhase", {
defaults: { //TODOs - Commented out
updateInterval: 43200000,
// hemisphere: "North",
// resolution: "detailed",
// language: "en",
title: true, //Whether or not the Moon Phase Title is displayed
phase: true, //Label for what moon phase it is
},

requiresVersion: "2.1.0", // Required version of MagicMirror

start: function() {
var self = this;
var dataRequest = null;
var dataNotification = null;

//Flag for check if module is loaded
this.loaded = false;

// Schedule update timer.

setInterval(function() {
self.updateDom();
}, this.config.updateInterval);
},

getDom: function() {
var self = this;

// create element wrapper for show into the module
let wrapper = document.createElement("div");
let title = document.createElement("p");
title.id = "moonphase-title";
if(this.config.title) {title.innerHTML = this.translate("TITLE");}
let moonImg = document.createElement("img");
moonImg.id = "moonphase-img";
let phase = document.createElement("p");
phase.id = "moonphase-phase";
if(!this.config.phase){phase.style.display = "none";}

let moonPhase = this.calculatePhase();
moonPhase = Math.round(moonPhase);
let timestamp = new Date();
//TODO - reduce this to numeric file names to condense this
if(moonPhase === 0 || moonPhase === 29) {
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/new.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("NEW");
} else if (moonPhase === 1){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-cresc-1.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_CRESC");
} else if (moonPhase === 2){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-cresc-2.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_CRESC");
}else if (moonPhase === 3){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-cresc-3.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_CRESC");
}else if (moonPhase === 4){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-cresc-4.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_CRESC");
}else if (moonPhase === 5){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-cresc-5.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_CRESC");
}else if (moonPhase === 6){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-cresc-6.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_CRESC");
}else if (moonPhase === 7){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/first.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("FIRST");
}else if (moonPhase === 8 || moonPhase === 9){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-gibbous-1.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_GIB");
}else if (moonPhase === 10){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-gibbous-2.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_GIB");
}else if (moonPhase === 11 || moonPhase === 12){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-gibbous-3.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_GIB");
}else if (moonPhase === 13){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-gibbous-4.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_GIB");
}else if (moonPhase === 14){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/waxing-gibbous-5.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("WAX_GIB");
}else if(moonPhase === 15){
moonImg.src = 'modules/MMM-MoonPhase/images/Phases/full.png' + '?seed=' + timestamp;
phase.innerHTML = this.translate("FULL");
}

wrapper.appendChild(title);
wrapper.appendChild(moonImg);
wrapper.appendChild(phase);

return wrapper;
},

getStyles: function () {
return [
"MMM-MoonPhase.css",
];
},

// Load translations files
getTranslations: function() {
//FIXME: This can be load a one file javascript definition
return {
en: "translations/en.json",
es: "translations/es.json"
};
},

calculatePhase: function(){
//Formula from here: https://www.subsystems.us/uploads/9/8/9/4/98948044/moonphase.pdf
//Getting Current Date
const currDate = new Date();
let d = currDate.getDate();
let m = currDate.getMonth()+1;
let y = currDate.getFullYear();

//Adjusting as per our formula found above
if(m === 1 || m === 2){
y = y-1;
m = m + 12;
}

//Formula to determine number of new moons Julian dates
let a = y/100;
let b = a/4;
let c = 2-a+b;
let e = 365.25 * (y+4716);
let f = 30.6001 * (m+1);
let jd = c + d + e + f - 1524.5;
let daysSinceNew = jd - 2451549.5;
let newMoons = daysSinceNew / 29.53;
let moonFraction = "0." + newMoons.toString().split(".")[1];
//Our final Digit - 29.53 days a moon cycle. 15 is full moon. 0/29.5 is new
let dayOfCycle = parseFloat(moonFraction * 29.53);
return dayOfCycle;
},
// socketNotificationReceived from helper
socketNotificationReceived: function (notification, payload) {
if(notification === "MMM-MoonPhase-PHASE-RECIEVED") {
this.updateDom();
}
},
});
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# MMM-MoonPhase

This is a module for the [MagicMirror²](https://github.com/MichMich/MagicMirror/).

Todo: Insert description here!

## Using the module

To use this module, add the following configuration block to the modules array in the `config/config.js` file:
```js
var config = {
modules: [
{
module: 'MMM-MoonPhase',
config: {
// See below for configurable options
}
}
]
}
```

## Configuration options

| Option | Description
|----------------- |-----------
| `option1` | *Required* DESCRIPTION HERE
| `option2` | *Optional* DESCRIPTION HERE TOO <br><br>**Type:** `int`(milliseconds) <br>Default 60000 milliseconds (1 minute)
51 changes: 51 additions & 0 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Magic Mirror
* Node Helper: MMM-MoonPhase
*
* By Nolan Kingdon
* MIT Licensed.
*/

var NodeHelper = require("node_helper");

module.exports = NodeHelper.create({

// Override socketNotificationReceived method.

/* socketNotificationReceived(notification, payload)
* This method is called when a socket notification arrives.
*
* argument notification string - The identifier of the noitication.
* argument payload mixed - The payload of the notification.
*/
socketNotificationReceived: function(notification, payload) {
console.log("Moon recieved notification");
console.log(notification);
if (notification === "MMM-MoonPhase-GET-PHASE") {
console.log("Calculating Moon Phase");
let phase = this.calculatePhase();
console.log("Phase is: " + phase);
}
},


/*
// Example function send notification test
sendNotificationTest: function(payload) {
this.sendSocketNotification("MMM-MoonPhase-NOTIFICATION_TEST", payload);
},
// this you can create extra routes for your module
extraRoutes: function() {
var self = this;
this.expressApp.get("/MMM-MoonPhase/extra_route", function(req, res) {
// call another function
values = self.anotherFunction();
res.send(values);
});
},
// Test another function
anotherFunction: function() {
return {date: new Date()};
}*/
});
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "MMM-MoonPhase",
"version": "1.0.0",
"description": "Todo: Insert description here!",
"main": "MMM-MoonPhase.js",
"author": "Nolan Kingdon",
"license": "MIT",
"devDependencies": {
"grunt": "latest",
"grunt-eslint": "latest",
"grunt-jsonlint": "latest",
"grunt-markdownlint": "^1.0.13",
"grunt-stylelint": "latest",
"grunt-yamllint": "latest",
"stylelint-config-standard": "latest",
"time-grunt": "latest"
}
}
12 changes: 12 additions & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"TITLE": "Moon Phase",
"UPDATE": "Update",
"NEW": "New Moon",
"WAX_CRESC": "Waxing Crescent",
"FIRST": "First Quarter",
"WAX_GIB": "Waxing Gibbous",
"FULL": "Full Moon",
"WAN_GIB": "Waning Gibbous",
"THIRD": "Third Quarter",
"WAN_CRESC": "Waning Crescent"
}
12 changes: 12 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"TITLE": "Moon Phase",
"UPDATE": "Update",
"NEW": "New Moon",
"WAX_CRESC": "Waxing Crescent",
"FIRST": "First Quarter",
"WAX_GIB": "Waxing Gibbous",
"FULL": "Full Moon",
"WAN_GIB": "Waning Gibbous",
"THIRD": "Third Quarter",
"WAN_CRESC": "Waning Crescent"
}
25 changes: 25 additions & 0 deletions translations/en.json.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"TITLE": "Moon Phase",
"UPDATE": "Update",
"NEW":"New Moon",
"WAX_CRESC": "Waxing Crescent",
"FIRST": "First Quarter",
"WAX_GIBB": "Waxing Gibbous",
"FULL": "Full Moon",
"WAN_GIBB": "Waning Gibbous",
"THIRD": "Third Quarter",
"WAN_CRESC": "Waning Crescent",
"NEW": "New Moon"
"TITLE": "Moon Phase",
"UPDATE": "Update",
"NEW":"New Moon",
"WAX_CRESC": "Waxing Crescent",
"FIRST": "First Quarter",
"WAX_GIBB": "Waxing Gibbous",
"FULL": "Full Moon",
"WAN_GIBB": "Waning Gibbous",
"THIRD": "Third Quarter",
"WAN_CRESC": "Waning Crescent",
"NEW": "New Moon"

}
5 changes: 5 additions & 0 deletions translations/en.json.save.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{




12 changes: 12 additions & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"TITLE": "Moon Phase",
"UPDATE": "Update",
"NEW": "New Moon",
"WAX_CRESC": "Waxing Crescent",
"FIRST": "First Quarter",
"WAX_GIB": "Waxing Gibbous",
"FULL": "Full Moon",
"WAN_GIB": "Waning Gibbous",
"THIRD": "Third Quarter",
"WAN_CRESC": "Waning Crescent"
}
Loading

0 comments on commit dd472b9

Please sign in to comment.