88 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-10-15 13:08:46 +02:00
Module.register("updatenotification", {
defaults: {
updateInterval: 10 * 60 * 1000, // every 10 minutes
},
status: false,
start: function () {
Log.log("Start updatenotification");
2016-10-15 13:08:46 +02:00
},
notificationReceived: function (notification, payload, sender) {
2016-10-15 13:08:46 +02:00
if (notification === "DOM_OBJECTS_CREATED") {
this.sendSocketNotification("CONFIG", this.config);
this.sendSocketNotification("MODULES", Module.definitions);
this.hide(0, { lockString: self.identifier });
2016-10-15 13:08:46 +02:00
}
},
socketNotificationReceived: function (notification, payload) {
if (notification === "STATUS") {
this.status = payload;
2016-10-15 17:06:52 +02:00
this.updateUI();
}
},
updateUI: function () {
2016-10-15 17:06:52 +02:00
var self = this;
if (this.status && this.status.behind > 0) {
self.updateDom(0);
self.show(1000, { lockString: self.identifier });
2016-10-15 13:08:46 +02:00
}
},
2017-10-16 09:35:25 +02:00
diffLink: function(text) {
var localRef = this.status.hash;
var remoteRef = this.status.tracking.replace(/.*\//, "");
return "<a href=\"https://github.com/MichMich/MagicMirror/compare/"+localRef+"..."+remoteRef+"\" "+
"class=\"xsmall dimmed\" "+
"style=\"text-decoration: none;\" "+
"target=\"_blank\" >" +
text +
"</a>";
},
2016-10-15 13:08:46 +02:00
// Override dom generator.
getDom: function () {
var wrapper = document.createElement("div");
if (this.status && this.status.behind > 0) {
var message = document.createElement("div");
message.className = "small bright";
var icon = document.createElement("i");
icon.className = "fa fa-exclamation-circle";
icon.innerHTML = "&nbsp;";
message.appendChild(icon);
var subtextHtml = this.translate("UPDATE_INFO", {
2018-02-17 10:17:59 +01:00
COMMIT_COUNT: this.status.behind + " " + ((this.status.behind == 1) ? "commit" : "commits"),
BRANCH_NAME: this.status.current
});
2017-10-16 09:35:25 +02:00
2016-10-15 13:08:46 +02:00
var text = document.createElement("span");
2016-11-16 18:19:44 +01:00
if (this.status.module == "default") {
text.innerHTML = this.translate("UPDATE_NOTIFICATION");
2017-10-16 09:35:25 +02:00
subtextHtml = this.diffLink(subtextHtml);
2016-11-16 18:19:44 +01:00
} else {
text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE", {
2018-02-17 10:17:59 +01:00
MODULE_NAME: this.status.module
});
2016-11-16 18:19:44 +01:00
}
2016-10-15 13:08:46 +02:00
message.appendChild(text);
wrapper.appendChild(message);
var subtext = document.createElement("div");
2017-10-16 09:35:25 +02:00
subtext.innerHTML = subtextHtml;
2016-10-15 13:08:46 +02:00
subtext.className = "xsmall dimmed";
wrapper.appendChild(subtext);
}
return wrapper;
}
});