1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Partial fix for #1570

Stop the logger from creating alert tiddlers on the server. They
propagate to the client but are not deletable from the client because
they are in the `$:/temp` namespace.

cc @loleg
This commit is contained in:
Jermolene 2015-03-12 22:34:59 +00:00
parent 0e75a6f41c
commit 550ad4a1a9

View File

@ -36,37 +36,43 @@ Alert a message
Logger.prototype.alert = function(/* args */) { Logger.prototype.alert = function(/* args */) {
// Prepare the text of the alert // Prepare the text of the alert
var text = Array.prototype.join.call(arguments," "); var text = Array.prototype.join.call(arguments," ");
// Check if there is an existing alert with the same text and the same component // Create alert tiddlers in the browser
var existingAlerts = $tw.wiki.getTiddlersWithTag(ALERT_TAG), if($tw.browser) {
alertFields, // Check if there is an existing alert with the same text and the same component
existingCount, var existingAlerts = $tw.wiki.getTiddlersWithTag(ALERT_TAG),
self = this; alertFields,
$tw.utils.each(existingAlerts,function(title) { existingCount,
var tiddler = $tw.wiki.getTiddler(title); self = this;
if(tiddler.fields.text === text && tiddler.fields.component === self.componentName && tiddler.fields.modified && (!alertFields || tiddler.fields.modified < alertFields.modified)) { $tw.utils.each(existingAlerts,function(title) {
alertFields = $tw.utils.extend({},tiddler.fields); var tiddler = $tw.wiki.getTiddler(title);
if(tiddler.fields.text === text && tiddler.fields.component === self.componentName && tiddler.fields.modified && (!alertFields || tiddler.fields.modified < alertFields.modified)) {
alertFields = $tw.utils.extend({},tiddler.fields);
}
});
if(alertFields) {
existingCount = alertFields.count || 1;
} else {
alertFields = {
title: $tw.wiki.generateNewTitle("$:/temp/alerts/alert",{prefix: ""}),
text: text,
tags: [ALERT_TAG],
component: this.componentName
};
existingCount = 0;
} }
}); alertFields.modified = new Date();
if(alertFields) { if(++existingCount > 1) {
existingCount = alertFields.count || 1; alertFields.count = existingCount;
} else {
alertFields.count = undefined;
}
$tw.wiki.addTiddler(new $tw.Tiddler(alertFields));
// Log the alert as well
this.log.apply(this,Array.prototype.slice.call(arguments,0));
} else { } else {
alertFields = { // Print an orange message to the console if not in the browser
title: $tw.wiki.generateNewTitle("$:/temp/alerts/alert",{prefix: ""}), console.error("\x1b[1;33m" + text + "\x1b[0m");
text: text,
tags: [ALERT_TAG],
component: this.componentName
};
existingCount = 0;
} }
alertFields.modified = new Date();
if(++existingCount > 1) {
alertFields.count = existingCount;
} else {
alertFields.count = undefined;
}
$tw.wiki.addTiddler(new $tw.Tiddler(alertFields));
// Log it too
this.log.apply(this,Array.prototype.slice.call(arguments,0));
}; };
exports.Logger = Logger; exports.Logger = Logger;