Skip to content
This repository has been archived by the owner on Mar 6, 2022. It is now read-only.

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneCL committed May 11, 2018
1 parent e299f3d commit 3ea09a8
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 380 deletions.
255 changes: 125 additions & 130 deletions MMM-Wunderlist.js
@@ -1,4 +1,4 @@
"use strict"
"use strict";
/* global Module */

/* Magic Mirror
Expand All @@ -9,133 +9,128 @@
*/

Module.register("MMM-Wunderlist", {

defaults: {
maximumEntries: 10,
order: "normal",
lists: ["inbox"],
interval: 60,
fade: true,
fadePoint: 0.25,
showDeadline: false,
showAssignee: false,
deadlineFormat: 'L',

},

notificationReceived: function(notification, payload, sender) {
if (notification === "ALL_MODULES_STARTED") {
console.log("ALL_MODULES_STATED"+ this.identifier)
}
},

// Override socket notification handler.
socketNotificationReceived: function (notification, payload) {
if (notification === "TASKS") {
this.tasks = payload
this.updateDom(3000);
}
else if (notification === "RETRIEVED_LISTS") {
this.sendSocketNotification("addLists", this.identifier)
}
else if (notification === "users") {
this.users = payload;
if (this.tasks && this.tasks.length > 0) {
this.updateDom(3000);
}
}
},

start: function () {
this.tasks = [];

// Use global language per default
if (this.config.language == null) {
this.config.language = config.language;
}

var payload = {
id: this.identifier,
config: this.config
}
this.sendSocketNotification("CONNECT", {id: this.identifier , config: this.config});
this.sendSocketNotification("CONFIG", {id: this.identifier, config: this.config});
this.sendSocketNotification("CONNECTED");
Log.info("Starting module: " + this.name + this.identifier);
},

getTodos: function () {
var tasksShown = [];
for (var i = 0; i < this.config.lists.length; i++) {
if (typeof this.tasks[this.config.lists[i]] != "undefined") {
var list = this.tasks[this.config.lists[i]];

for (var todo in list) {
if (this.config.order == "reversed") {
tasksShown.push(list[todo]);
}
else {
tasksShown.unshift(list[todo]);
}
}
}
}
return tasksShown.slice(0, this.config.maximumEntries);
},

getScripts: function () {
return [
'String.format.js'
];
},
getStyles: function () {
return ["font-awesome.css"];
},

html: {
table: '<thead>{0}</thead><tbody>{1}</tbody>',
row: '<tr><td>{0}</td><td>{1}</td><td class="title bright">{2}</td><td>{3}</td></tr>',
star: '<i class="fa fa-star" aria-hidden="true"></i>',
assignee: '<div style="display: inline-flex; align-items: center; justify-content: center; background-color: #aaa; color: #666; min-width: 1em; border-radius: 50%; vertical-align: middle; padding: 2px; text-transform: uppercase;">{0}</div>',
},

getDom: function () {
if (this.config.showAssignee && this.started && !this.users) {
this.sendSocketNotification("getUsers");
}
var self = this;
var wrapper = document.createElement("table");
wrapper.className = "normal small light";

var todos = this.getTodos();

var rows = []
todos.forEach(function (todo, i) {
rows[i] = self.html.row.format(
self.config.showDeadline && todo.due_date ? todo.due_date : '',
todo.starred ? self.html.star : '',
todo.title,
self.config.showAssignee && todo.assignee_id && self.users ? self.html.assignee.format(self.users[todo.assignee_id]) : ''
)

// Create fade effect
if (self.config.fade && self.config.fadePoint < 1) {
if (self.config.fadePoint < 0) {
self.config.fadePoint = 0;
}
var startingPoint = todos.length * self.config.fadePoint;
if (i >= startingPoint) {
wrapper.style.opacity = 1 - (1 / todos.length - startingPoint * (i - startingPoint));
}
}
});

wrapper.innerHTML = this.html.table.format(
this.html.row.format('', '', '', ''),
rows.join('')
)

return wrapper;
},

defaults: {
maximumEntries: 10,
order: "normal",
lists: ["inbox"],
interval: 60,
fade: true,
fadePoint: 0.25,
showDeadline: false,
showAssignee: false,
deadlineFormat: "L"
},

notificationReceived: function(notification, payload, sender) {
if (notification === "ALL_MODULES_STARTED") {
console.log("ALL_MODULES_STATED" + this.identifier);
}
},

// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification === "TASKS") {
this.tasks = payload;
this.updateDom(3000);
} else if (notification === "RETRIEVED_LISTS") {
this.sendSocketNotification("addLists", this.identifier);
} else if (notification === "users") {
this.users = payload;
if (this.tasks && this.tasks.length > 0) {
this.updateDom(3000);
}
}
},

start: function() {
this.tasks = [];

// Use global language per default
if (this.config.language == null) {
this.config.language = config.language;
}

var payload = {
id: this.identifier,
config: this.config
};
this.sendSocketNotification("CONNECT", {id: this.identifier , config: this.config});
this.sendSocketNotification("CONFIG", {id: this.identifier, config: this.config});
this.sendSocketNotification("CONNECTED");
Log.info("Starting module: " + this.name + this.identifier);
},

getTodos: function() {
var tasksShown = [];
for (var i = 0; i < this.config.lists.length; i++) {
if (typeof this.tasks[this.config.lists[i]] != "undefined") {
var list = this.tasks[this.config.lists[i]];

for (var todo in list) {
if (this.config.order == "reversed") {
tasksShown.push(list[todo]);
} else {
tasksShown.unshift(list[todo]);
}
}
}
}
return tasksShown.slice(0, this.config.maximumEntries);
},

getScripts: function() {
return ["String.format.js"];
},
getStyles: function() {
return ["font-awesome.css"];
},

html: {
table: "<thead>{0}</thead><tbody>{1}</tbody>",
row: "<tr><td>{0}</td><td>{1}</td><td class=\"title bright\">{2}</td><td>{3}</td></tr>",
star: "<i class=\"fa fa-star\" aria-hidden=\"true\"></i>",
assignee: "<div style=\"display: inline-flex; align-items: center; justify-content: center; background-color: #aaa; color: #666; min-width: 1em; border-radius: 50%; vertical-align: middle; padding: 2px; text-transform: uppercase;\">{0}</div>"
},

getDom: function() {
if (this.config.showAssignee && this.started && !this.users) {
this.sendSocketNotification("getUsers");
}
var self = this;
var wrapper = document.createElement("table");
wrapper.className = "normal small light";

var todos = this.getTodos();

var rows = [];
todos.forEach(function(todo, i) {
rows[i] = self.html.row.format(
self.config.showDeadline && todo.due_date ? todo.due_date : "",
todo.starred ? self.html.star : "",
todo.title,
self.config.showAssignee && todo.assignee_id && self.users
? self.html.assignee.format(self.users[todo.assignee_id])
: ""
);

// Create fade effect
if (self.config.fade && self.config.fadePoint < 1) {
if (self.config.fadePoint < 0) {
self.config.fadePoint = 0;
}
var startingPoint = todos.length * self.config.fadePoint;
if (i >= startingPoint) {
wrapper.style.opacity =
1 - (1 / todos.length - startingPoint * (i - startingPoint));
}
}
});

wrapper.innerHTML = this.html.table.format(
this.html.row.format("", "", "", ""),
rows.join("")
);

return wrapper;
}
});
16 changes: 8 additions & 8 deletions String.format.js
@@ -1,11 +1,11 @@
"use strict"
"use strict";

// add string format method
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
};
}
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != "undefined" ? args[number] : match;
});
};
}

0 comments on commit 3ea09a8

Please sign in to comment.