Skip to content

Commit

Permalink
Merge pull request #3 from fewieden/develop
Browse files Browse the repository at this point in the history
add linter
  • Loading branch information
fewieden authored Feb 17, 2017
2 parents 6d7d1db + 1900946 commit 5145d68
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 69 deletions.
23 changes: 23 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
engines:
stylelint:
enabled: true
duplication:
enabled: true
config:
languages:
- javascript
eslint:
enabled: true
channel: "eslint-3"
fixme:
enabled: true
markdownlint:
enabled: true
ratings:
paths:
- "**.css"
- "**.js"
- "**.md"
exclude_paths: [
"node_modules/**/*"
]
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[{*.json, *.yml}]
indent_style = space
indent_size = 2
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "airbnb-base",
"rules": {
"comma-dangle": 0,
"indent": [2, 4],
"max-len": [2, 120, { "ignoreStrings": true }],
"radix": [2, "as-needed"]
},
"env": {
"browser": true,
"es6": true
}
}
2 changes: 2 additions & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all
rules "~MD013", "~MD026", "~MD033"
6 changes: 6 additions & 0 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "stylelint-config-standard",
"rules": {
"indentation": 4
}
}
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: node_js
node_js:
- "stable"
- "7"
- "6"
- "5"
script:
- npm run lint
cache:
directories:
- node_modules
4 changes: 2 additions & 2 deletions MMM-AlarmClock.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

.MMM-AlarmClock .button {
padding: 10px 40px;
border: 2px solid #FFFFFF;
border: 2px solid #fff;
border-radius: 10px;
text-align: center;
}
}
122 changes: 61 additions & 61 deletions MMM-AlarmClock.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* global Module Log config moment MM */

/* Magic Mirror
* Module: MMM-AlarmClock
*
* By fewieden https://github.com/fewieden/MMM-AlarmClock
* MIT Licensed.
*/

Module.register("MMM-AlarmClock", {
Module.register('MMM-AlarmClock', {

next: null,
alarmFired: false,
Expand All @@ -14,54 +16,54 @@ Module.register("MMM-AlarmClock", {
sound: 'alarm.mp3',
touch: false,
volume: 1.0,
format: "ddd, h:mmA",
format: 'ddd, h:mmA',
timer: 60 * 1000 // one minute
},

getStyles: function () {
return ["font-awesome.css", "MMM-AlarmClock.css"];
getStyles() {
return ['font-awesome.css', 'MMM-AlarmClock.css'];
},

getScripts: function() {
return ["moment.js"];
getScripts() {
return ['moment.js'];
},

getTranslations: function () {
getTranslations() {
return {
en: "translations/en.json",
de: "translations/de.json"
en: 'translations/en.json',
de: 'translations/de.json'
};
},

start: function () {
Log.info("Starting module: " + this.name);
start() {
Log.info(`Starting module: ${this.name}`);
this.setNextAlarm();
setInterval(() => {
this.checkAlarm();
}, 1000);
moment.locale(config.language);
},

checkAlarm: function(){
if(!this.alarmFired && this.next && moment().diff(this.next.moment) >= 0){
var alert = {
checkAlarm() {
if (!this.alarmFired && this.next && moment().diff(this.next.moment) >= 0) {
const alert = {
imageFA: 'bell-o',
title: this.next.sender || this.next.title,
message: this.next.message
};
if(!this.config.touch){
if (!this.config.touch) {
alert.timer = this.config.timer;
}
this.sendNotification("SHOW_ALERT", alert);
this.sendNotification('SHOW_ALERT', alert);
this.alarmFired = true;
this.updateDom(300);
this.timer = setTimeout(() => {
this.resetAlarmClock();
}, this.config.timer);
if(this.config.touch){
if (this.config.touch) {
MM.getModules().enumerate((module) => {
if(module.name === "alert"){
module.alerts["MMM-AlarmClock"].ntf.addEventListener("click", () => {
if (module.name === 'alert') {
module.alerts['MMM-AlarmClock'].ntf.addEventListener('click', () => {
clearTimeout(this.timer);
this.resetAlarmClock();
});
Expand All @@ -71,89 +73,87 @@ Module.register("MMM-AlarmClock", {
}
},

setNextAlarm: function(){
setNextAlarm() {
this.next = null;
for(var i = 0; i < this.config.alarms.length; i++){
var temp = this.getMoment(this.config.alarms[i]);
if(!this.next || temp.diff(this.next.moment) < 0){
for (let i = 0; i < this.config.alarms.length; i += 1) {
const temp = this.getMoment(this.config.alarms[i]);
if (!this.next || temp.diff(this.next.moment) < 0) {
this.next = this.config.alarms[i];
this.next.moment = temp;
}
}
},

resetAlarmClock: function(){
resetAlarmClock() {
this.alarmFired = false;
if(this.config.touch){
this.sendNotification("HIDE_ALERT");
if (this.config.touch) {
this.sendNotification('HIDE_ALERT');
}
this.setNextAlarm();
this.updateDom(300);
},

getMoment: function(alarm){
var now = moment();
var difference = Math.min();
var hour = parseInt(alarm.time.split(":")[0]);
var minute = parseInt(alarm.time.split(":")[1]);
getMoment(alarm) {
const now = moment();
let difference = Math.min();
const hour = parseInt(alarm.time.split(':')[0]);
const minute = parseInt(alarm.time.split(':')[1]);

for(var i = 0; i < alarm.days.length; i++){
if(now.day() < alarm.days[i]){
for (let i = 0; i < alarm.days.length; i += 1) {
if (now.day() < alarm.days[i]) {
difference = Math.min(alarm.days[i] - now.day(), difference);
} else if(now.day() === alarm.days[i] && (parseInt(now.hour()) < hour || parseInt(now.hour()) === hour && parseInt(now.minute()) < minute)){
} else if (now.day() === alarm.days[i] && (parseInt(now.hour()) < hour ||
(parseInt(now.hour()) === hour && parseInt(now.minute()) < minute))) {
difference = Math.min(0, difference);
} else if(now.day() === alarm.days[i]){
} else if (now.day() === alarm.days[i]) {
difference = Math.min(7, difference);
} else {
difference = Math.min(7 - now.day() + alarm.days[i], difference);
difference = Math.min((7 - now.day()) + alarm.days[i], difference);
}
}

return moment().add(difference, 'days').set({
hour: hour,
minute: minute,
hour,
minute,
second: 0,
millisecond: 0
});
},

getDom() {
const wrapper = document.createElement('div');
const header = document.createElement('header');
header.classList.add('align-left');


getDom: function () {

var wrapper = document.createElement("div");
var header = document.createElement("header");
header.classList.add("align-left");

var logo = document.createElement("i");
logo.classList.add("fa", "fa-bell-o", "logo");
const logo = document.createElement('i');
logo.classList.add('fa', 'fa-bell-o', 'logo');
header.appendChild(logo);

var name = document.createElement("span");
name.innerHTML = this.translate("ALARM_CLOCK");
const name = document.createElement('span');
name.innerHTML = this.translate('ALARM_CLOCK');
header.appendChild(name);
wrapper.appendChild(header);

if (!this.next) {
var text = document.createElement("div");
text.innerHTML = this.translate("LOADING");
text.classList.add("dimmed", "light");
const text = document.createElement('div');
text.innerHTML = this.translate('LOADING');
text.classList.add('dimmed', 'light');
wrapper.appendChild(text);
} else if(this.alarmFired) {
var sound = document.createElement("audio");
} else if (this.alarmFired) {
const sound = document.createElement('audio');
if (this.config.sound.match(/^https?:\/\//)) {
sound.src = this.config.sound;
}else{
sound.src = this.file("sounds/" + this.config.sound);
} else {
sound.src = this.file(`sounds/${this.config.sound}`);
}
sound.volume = this.config.volume;
sound.setAttribute("autoplay", true);
sound.setAttribute("loop", true);
sound.setAttribute('autoplay', true);
sound.setAttribute('loop', true);
wrapper.appendChild(sound);
} else {
var alarm = document.createElement("div");
alarm.classList.add("small");
alarm.innerHTML = this.next.title + ": " + this.next.moment.format(this.config.format);
const alarm = document.createElement('div');
alarm.classList.add('small');
alarm.innerHTML = `${this.next.title}: ${this.next.moment.format(this.config.format)}`;
wrapper.appendChild(alarm);
}

Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# MMM-AlarmClock
# MMM-AlarmClock [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/fewieden/MMM-AlarmClock/master/LICENSE) [![Build Status](https://travis-ci.org/fewieden/MMM-AlarmClock.svg?branch=master)](https://travis-ci.org/fewieden/MMM-AlarmClock) [![Code Climate](https://codeclimate.com/github/fewieden/MMM-AlarmClock/badges/gpa.svg?style=flat)](https://codeclimate.com/github/fewieden/MMM-AlarmClock) [![Known Vulnerabilities](https://snyk.io/test/github/fewieden/mmm-alarmclock/badge.svg)](https://snyk.io/test/github/fewieden/mmm-alarmclock)

Alarm Clock Module for MagicMirror<sup>2</sup>

## Example

![](.github/example.jpg) ![](.github/example2.jpg)

## Dependencies
* An installation of [MagicMirror<sup>2</sup>](https://github.com/MichMich/MagicMirror)

* An installation of [MagicMirror<sup>2</sup>](https://github.com/MichMich/MagicMirror)

## Installation
1. Clone this repo into `~/MagicMirror/modules` directory.
2. Configure your `~/MagicMirror/config/config.js`:

1. Clone this repo into `~/MagicMirror/modules` directory.
1. Configure your `~/MagicMirror/config/config.js`:

```
{
Expand All @@ -27,6 +30,7 @@ Alarm Clock Module for MagicMirror<sup>2</sup>
```
## Config Options
| **Option** | **Default** | **Description** |
| --- | --- | --- |
| `alarm` | `REQUIRED` | An Array with all your alarms as objects. Those objects need to have the properties -> time: 24h format, days: Array of all days the alarm should be fired (0 = Sunday, 6 = Saturday), title and message. |
Expand All @@ -37,6 +41,8 @@ Alarm Clock Module for MagicMirror<sup>2</sup>
| `timer` | `60000` (1 min) | How long the alarm should ring for non touch screen or without interaction on touch screen devices. |
## Alarm Sounds
There are already two alarm sounds:
* [alarm.mp3](http://www.orangefreesounds.com/mp3-alarm-clock/) | From Alexander licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)
* [blackforest.mp3](http://www.orangefreesounds.com/coo-coo-clock-sound/) | From Alexander licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)
* [alarm.mp3](http://www.orangefreesounds.com/mp3-alarm-clock/) | From Alexander licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)
* [blackforest.mp3](http://www.orangefreesounds.com/coo-coo-clock-sound/) | From Alexander licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "mmm-alarmclock",
"version": "1.0.0",
"description": "Alarm Clock Module for MagicMirror2",
"scripts": {
"lint": "./node_modules/.bin/eslint . && ./node_modules/.bin/stylelint ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/fewieden/MMM-AlarmClock.git"
},
"keywords": [
"MagicMirror",
"alarm clock"
],
"author": "fewieden",
"license": "MIT",
"bugs": {
"url": "https://github.com/fewieden/MMM-AlarmClock/issues"
},
"homepage": "https://github.com/fewieden/MMM-AlarmClock#readme",
"devDependencies": {
"eslint": "^3.14.1",
"eslint-config-airbnb-base": "^11.0.1",
"eslint-plugin-import": "^2.2.0",
"stylelint": "^7.8.0",
"stylelint-config-standard": "^16.0.0"
}
}

0 comments on commit 5145d68

Please sign in to comment.