First round of undef fixes

This commit is contained in:
rejas 2020-05-02 10:39:09 +02:00
parent d8f093b226
commit b9d19cfcb4
22 changed files with 56 additions and 50 deletions

View File

@ -9,6 +9,7 @@
"globals": {
"config": true,
"Log": true,
"MM": true,
"moment": true
},
"parserOptions": {

View File

@ -3,6 +3,7 @@
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function () {
var initializing = false;

View File

@ -6,9 +6,8 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var port = 8080;
var address = "localhost";
var port = 8080;
if (typeof(mmPort) !== "undefined") {
port = mmPort;
}

View File

@ -1,4 +1,4 @@
/* global vendor, MM, Module */
/* global Module, vendor */
/* Magic Mirror
* Module and File loaders.

View File

@ -1,4 +1,4 @@
/* global Loader, Module, defaults */
/* global Loader, Module, defaults, Translator */
/* Magic Mirror
* Main System

View File

@ -1,4 +1,4 @@
/* exported Module */
/* global Class, Loader, MMSocket, nunjucks, Translator */
/* Magic Mirror
* Module Blueprint.
@ -6,7 +6,6 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var Module = Class.extend({
/*********************************************************
@ -237,7 +236,7 @@ var Module = Class.extend({
*/
socket: function () {
if (typeof this._socket === "undefined") {
this._socket = this._socket = new MMSocket(this.name);
this._socket = new MMSocket(this.name);
}
var self = this;
@ -467,8 +466,8 @@ function cmpVersions(a, b) {
Module.register = function (name, moduleDefinition) {
if (moduleDefinition.requiresVersion) {
Log.log("Check MagicMirror version for module '" + name + "' - Minimum version: " + moduleDefinition.requiresVersion + " - Current version: " + version);
if (cmpVersions(version, moduleDefinition.requiresVersion) >= 0) {
Log.log("Check MagicMirror version for module '" + name + "' - Minimum version: " + moduleDefinition.requiresVersion + " - Current version: " + global.version);
if (cmpVersions(global.version, moduleDefinition.requiresVersion) >= 0) {
Log.log("Version is ok!");
} else {
Log.log("Version is incorrect. Skip module: '" + name + "'");

View File

@ -4,12 +4,10 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
const Class = require("./class.js");
const express = require("express");
var Class = require("./class.js");
var express = require("express");
var path = require("path");
NodeHelper = Class.extend({
var NodeHelper = Class.extend({
init: function() {
console.log("Initializing new module helper ...");
},
@ -114,7 +112,6 @@ NodeHelper = Class.extend({
}
});
});
}
});
@ -122,4 +119,5 @@ NodeHelper.create = function(moduleDefinition) {
return NodeHelper.extend(moduleDefinition);
};
module.exports = NodeHelper;
/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = NodeHelper;}

View File

@ -71,7 +71,7 @@ var Server = function(config, callback) {
var html = fs.readFileSync(path.resolve(global.root_path + "/index.html"), {encoding: "utf8"});
html = html.replace("#VERSION#", global.version);
configFile = "config/config.js";
var configFile = "config/config.js";
if (typeof(global.configuration_file) !== "undefined") {
configFile = global.configuration_file;
}

View File

@ -1,10 +1,11 @@
/* global io */
/* Magic Mirror
* Socket Connection
*
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var MMSocket = function(moduleName) {
var self = this;

View File

@ -1,3 +1,11 @@
/* global io */
/* Magic Mirror
* TODO add description
*
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
var MMSocket = function(moduleName) {
var self = this;

View File

@ -5,8 +5,8 @@
* MIT Licensed.
*/
var ical = require("./vendor/ical.js");
var moment = require("moment");
const ical = require("./vendor/ical.js");
const moment = require("moment");
var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) {
var self = this;
@ -25,7 +25,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
clearTimeout(reloadTimer);
reloadTimer = null;
nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
var nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
var opts = {
headers: {
"User-Agent": "Mozilla/5.0 (Node.js "+ nodeVersion + ") MagicMirror/" + global.version + " (https://github.com/MichMich/MagicMirror/)"
@ -61,7 +61,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
}
// console.log(data);
newEvents = [];
var newEvents = [];
// 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;};
@ -97,7 +97,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
if (typeof event.end !== "undefined") {
endDate = eventDate(event, "end");
} else if(typeof event.duration !== "undefined") {
dur=moment.duration(event.duration);
var dur=moment.duration(event.duration);
endDate = startDate.clone().add(dur);
} else {
if (!isFacebookBirthday) {

View File

@ -15,8 +15,6 @@ var maximumEntries = 10;
var maximumNumberOfDays = 365;
var user = "magicmirror";
var pass = "MyStrongPass";
var broadcastPastEvents = false;
var auth = {
user: user,
pass: pass
@ -24,7 +22,7 @@ var auth = {
console.log("Create fetcher ...");
fetcher = new CalendarFetcher(url, fetchInterval, [], maximumEntries, maximumNumberOfDays, auth);
var fetcher = new CalendarFetcher(url, fetchInterval, [], maximumEntries, maximumNumberOfDays, auth);
fetcher.onReceive(function(fetcher) {
console.log(fetcher.events());

View File

@ -1,4 +1,4 @@
/* global Module */
/* global Module, SunCalc */
/* Magic Mirror
* Module: Clock
@ -289,11 +289,12 @@ Module.register("clock",{
// Both clocks have been configured, check position
var placement = this.config.analogPlacement;
analogWrapper = document.createElement("div");
var analogWrapper = document.createElement("div");
analogWrapper.id = "analog";
analogWrapper.style.cssFloat = "none";
analogWrapper.appendChild(clockCircle);
digitalWrapper = document.createElement("div");
var digitalWrapper = document.createElement("div");
digitalWrapper.id = "digital";
digitalWrapper.style.cssFloat = "none";
digitalWrapper.appendChild(dateWrapper);

View File

@ -127,7 +127,7 @@ Module.register("compliments", {
compliments.push.apply(compliments, this.config.compliments.anytime);
for (entry in this.config.compliments) {
for (var entry in this.config.compliments) {
if (new RegExp(entry).test(date)) {
compliments.push.apply(compliments, this.config.compliments[entry]);
}
@ -188,7 +188,7 @@ Module.register("compliments", {
// create a span to hold it all
var compliment = document.createElement("span");
// process all the parts of the compliment text
for (part of parts){
for (var part of parts){
// create a text element for each part
compliment.appendChild(document.createTextNode(part));
// add a break `

View File

@ -81,8 +81,8 @@ 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/)",
var nodeVersion = Number(process.version.match(/^v(\d+\.\d+)/)[1]);
var 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"};

View File

@ -126,7 +126,7 @@ Module.register("newsfeed",{
if (this.config.removeStartTags === "title" || this.config.removeStartTags === "both") {
for (f=0; f<this.config.startTags.length;f++) {
for (let f=0; f<this.config.startTags.length;f++) {
if (this.newsItems[this.activeItem].title.slice(0,this.config.startTags[f].length) === this.config.startTags[f]) {
this.newsItems[this.activeItem].title = this.newsItems[this.activeItem].title.slice(this.config.startTags[f].length,this.newsItems[this.activeItem].title.length);
}
@ -137,7 +137,7 @@ Module.register("newsfeed",{
if (this.config.removeStartTags === "description" || this.config.removeStartTags === "both") {
if (this.isShowingDescription) {
for (f=0; f<this.config.startTags.length;f++) {
for (let f=0; f<this.config.startTags.length;f++) {
if (this.newsItems[this.activeItem].description.slice(0,this.config.startTags[f].length) === this.config.startTags[f]) {
this.newsItems[this.activeItem].description = this.newsItems[this.activeItem].description.slice(this.config.startTags[f].length,this.newsItems[this.activeItem].description.length);
}
@ -149,14 +149,14 @@ Module.register("newsfeed",{
//Remove selected tags from the end of rss feed items (title or description)
if (this.config.removeEndTags) {
for (f=0; f<this.config.endTags.length;f++) {
for (let f=0; f<this.config.endTags.length;f++) {
if (this.newsItems[this.activeItem].title.slice(-this.config.endTags[f].length)===this.config.endTags[f]) {
this.newsItems[this.activeItem].title = this.newsItems[this.activeItem].title.slice(0,-this.config.endTags[f].length);
}
}
if (this.isShowingDescription) {
for (f=0; f<this.config.endTags.length;f++) {
for (let f=0; f<this.config.endTags.length;f++) {
if (this.newsItems[this.activeItem].description.slice(-this.config.endTags[f].length)===this.config.endTags[f]) {
this.newsItems[this.activeItem].description = this.newsItems[this.activeItem].description.slice(0,-this.config.endTags[f].length);
}
@ -331,7 +331,7 @@ Module.register("newsfeed",{
self.sendNotification("NEWS_FEED", {items: self.newsItems});
}
timer = setInterval(function() {
this.timer = setInterval(function() {
self.activeItem++;
self.updateDom(self.config.animationSpeed);
@ -360,7 +360,7 @@ Module.register("newsfeed",{
// reset bottom bar alignment
document.getElementsByClassName("region bottom bar")[0].style.bottom = "0";
document.getElementsByClassName("region bottom bar")[0].style.top = "inherit";
if(!timer){
if(!this.timer){
this.scheduleUpdateInterval();
}
},
@ -433,10 +433,9 @@ Module.register("newsfeed",{
document.getElementsByClassName("region bottom bar")[0].style.bottom = "inherit";
document.getElementsByClassName("region bottom bar")[0].style.top = "-90px";
}
clearInterval(timer);
timer = null;
clearInterval(this.timer);
this.timer = null;
Log.info(this.name + " - showing " + this.isShowingDescription ? "article description" : "full article");
this.updateDom(100);
}
});

View File

@ -24,7 +24,7 @@ module.exports = NodeHelper.create({
var promises = [];
for (moduleName in modules) {
for (var moduleName in modules) {
if (!this.ignoreUpdateChecking(moduleName)) {
// Default modules are included in the main MagicMirror repo
var moduleFolder = path.normalize(__dirname + "/../../" + moduleName);

View File

@ -74,7 +74,7 @@ Module.register("updatenotification", {
var wrapper = document.createElement("div");
if(this.suspended === false){
// process the hash of module info found
for(key of Object.keys(this.moduleList)){
for(var key of Object.keys(this.moduleList)){
let m = this.moduleList[key];
var message = document.createElement("div");

View File

@ -8,6 +8,7 @@ const describe = global.describe;
describe("All font files from roboto.css should be downloadable", function() {
helpers.setupTimeout(this);
var app;
var fontFiles = [];
// Statements below filters out all 'url' lines in the CSS file
var fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");

View File

@ -28,7 +28,7 @@ describe("Position of modules", function () {
var position;
var className;
for (idx in positions) {
for (var idx in positions) {
position = positions[idx];
className = position.replace("_", ".");
it("show text in " + position, function () {

View File

@ -6,7 +6,6 @@ const describe = global.describe;
const it = global.it;
const before = global.before;
const after = global.after;
const mlog = require("mocha-logger");
describe("Vendors", function () {
@ -30,7 +29,7 @@ describe("Vendors", function () {
var vendors = require(__dirname + "/../../vendor/vendor.js");
Object.keys(vendors).forEach(vendor => {
it(`should return 200 HTTP code for vendor "${vendor}"`, function () {
urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
var urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
request.get(urlVendor, function (err, res, body) {
expect(res.statusCode).to.equal(200);
});
@ -39,7 +38,7 @@ describe("Vendors", function () {
Object.keys(vendors).forEach(vendor => {
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, function() {
urlVendor = "http://localhost:8080/" + vendors[vendor];
var urlVendor = "http://localhost:8080/" + vendors[vendor];
request.get(urlVendor, function (err, res, body) {
expect(res.statusCode).to.equal(404);
});

View File

@ -19,7 +19,8 @@ app.use(auth.connect(basic));
// Set available directories
var directories = ["/tests/configs"];
var directory;
rootPath = path.resolve(__dirname + "/../../");
var rootPath = path.resolve(__dirname + "/../../");
for (var i in directories) {
directory = directories[i];
app.use(directory, express.static(path.resolve(rootPath + directory)));