Add Github link to update info

This commit is contained in:
Chris van Marle 2017-10-16 09:35:25 +02:00
parent 08aa9790f3
commit e7b9100f1c
2 changed files with 21 additions and 4 deletions

View File

@ -64,7 +64,10 @@ module.exports = NodeHelper.create({
sg.git.fetch().status(function(err, data) { sg.git.fetch().status(function(err, data) {
data.module = sg.module; data.module = sg.module;
if (!err) { if (!err) {
self.sendSocketNotification("STATUS", data); sg.git.log({"-1": null}, function(err, data2) {
data.hash = data2.latest.hash;
self.sendSocketNotification("STATUS", data);
});
} }
}); });
}); });

View File

@ -34,6 +34,17 @@ Module.register("updatenotification", {
} }
}, },
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>";
},
// Override dom generator. // Override dom generator.
getDom: function () { getDom: function () {
var wrapper = document.createElement("div"); var wrapper = document.createElement("div");
@ -47,9 +58,14 @@ Module.register("updatenotification", {
icon.innerHTML = "&nbsp;"; icon.innerHTML = "&nbsp;";
message.appendChild(icon); message.appendChild(icon);
var subtextHtml = this.translate("UPDATE_INFO")
.replace("COMMIT_COUNT", this.status.behind + " " + ((this.status.behind == 1) ? "commit" : "commits"))
.replace("BRANCH_NAME", this.status.current);
var text = document.createElement("span"); var text = document.createElement("span");
if (this.status.module == "default") { if (this.status.module == "default") {
text.innerHTML = this.translate("UPDATE_NOTIFICATION"); text.innerHTML = this.translate("UPDATE_NOTIFICATION");
subtextHtml = this.diffLink(subtextHtml);
} else { } else {
text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE").replace("MODULE_NAME", this.status.module); text.innerHTML = this.translate("UPDATE_NOTIFICATION_MODULE").replace("MODULE_NAME", this.status.module);
} }
@ -58,9 +74,7 @@ Module.register("updatenotification", {
wrapper.appendChild(message); wrapper.appendChild(message);
var subtext = document.createElement("div"); var subtext = document.createElement("div");
subtext.innerHTML = this.translate("UPDATE_INFO") subtext.innerHTML = subtextHtml;
.replace("COMMIT_COUNT", this.status.behind + " " + ((this.status.behind == 1) ? "commit" : "commits"))
.replace("BRANCH_NAME", this.status.current);
subtext.className = "xsmall dimmed"; subtext.className = "xsmall dimmed";
wrapper.appendChild(subtext); wrapper.appendChild(subtext);
} }