mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-07-24 21:02:50 +00:00
Enhance alerting to coalesce repeated alerts with the same text
This commit is contained in:
parent
44678b2ea2
commit
4836cf83e2
@ -12,6 +12,8 @@ A basic logging implementation
|
|||||||
/*global $tw: false */
|
/*global $tw: false */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var ALERT_TAG = "$:/tags/Alert";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Make a new logger
|
Make a new logger
|
||||||
*/
|
*/
|
||||||
@ -32,15 +34,37 @@ Logger.prototype.log = function(/* args */) {
|
|||||||
Alert a message
|
Alert a message
|
||||||
*/
|
*/
|
||||||
Logger.prototype.alert = function(/* args */) {
|
Logger.prototype.alert = function(/* args */) {
|
||||||
var text = Array.prototype.join.call(arguments," "),
|
// Prepare the text of the alert
|
||||||
fields = {
|
var text = Array.prototype.join.call(arguments," ");
|
||||||
|
// Check if there is an existing alert with the same text and the same component
|
||||||
|
var existingAlerts = $tw.wiki.getTiddlersWithTag(ALERT_TAG),
|
||||||
|
alertFields,
|
||||||
|
existingCount,
|
||||||
|
self = this;
|
||||||
|
$tw.utils.each(existingAlerts,function(title) {
|
||||||
|
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: ""}),
|
title: $tw.wiki.generateNewTitle("$:/temp/alerts/alert",{prefix: ""}),
|
||||||
text: text,
|
text: text,
|
||||||
tags: ["$:/tags/Alert"],
|
tags: [ALERT_TAG],
|
||||||
component: this.componentName,
|
component: this.componentName
|
||||||
modified: new Date()
|
|
||||||
};
|
};
|
||||||
$tw.wiki.addTiddler(new $tw.Tiddler(fields));
|
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
|
// Log it too
|
||||||
this.log.apply(this,Array.prototype.slice.call(arguments,0));
|
this.log.apply(this,Array.prototype.slice.call(arguments,0));
|
||||||
};
|
};
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
title: $:/core/ui/AlertTemplate
|
title: $:/core/ui/AlertTemplate
|
||||||
|
|
||||||
<div class="tw-alert"><div class="tw-alert-toolbar"><$button message="tw-delete-tiddler" class="btn-invisible">{{$:/core/images/delete-button}}</$button></div><div class="tw-alert-subtitle"><$view field="component"/> - <$view field="modified" format="date" template="0hh:0mm:0ss DD MM YYYY"/></div><div class="tw-alert-body"><$view field="text"/></div></div>
|
<div class="tw-alert"><div class="tw-alert-toolbar"><$button message="tw-delete-tiddler" class="btn-invisible">{{$:/core/images/delete-button}}</$button></div><div class="tw-alert-subtitle"><$view field="component"/> - <$view field="modified" format="date" template="0hh:0mm:0ss DD MM YYYY"/> <$reveal type="nomatch" state="!!count" text=""><span class="tw-alert-highlight">(count: <$view field="count"/>)</span></$reveal></div><div class="tw-alert-body"><$view field="text"/></div></div>
|
||||||
|
|
||||||
|
@ -950,6 +950,9 @@ canvas.tw-edit-bitmapeditor {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tw-alert-highlight {
|
||||||
|
color: #812;
|
||||||
|
}
|
||||||
|
|
||||||
.tw-static-alert {
|
.tw-static-alert {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user