1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00
TiddlyWiki5/core/modules/widgets/action-log.js
saqimtiaz 483fd941f5
Extend action-log and subclass it as log widget (#5078)
* Extended action-log and subclassed it as log widget

* Do not rename LogWidget class

* Removed unneeded variable declaration
2020-11-20 14:08:18 +00:00

94 lines
2.0 KiB
JavaScript

/*\
title: $:/core/modules/widgets/action-log.js
type: application/javascript
module-type: widget
Action widget to log debug messages
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var LogWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
LogWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
LogWidget.prototype.render = function(parent,nextSibling) {
this.computeAttributes();
this.execute();
};
LogWidget.prototype.execute = function(){
this.message = this.getAttribute("$$message","debug");
this.logAll = this.getAttribute("$$all","no") === "yes" ? true : false;
this.filter = this.getAttribute("$$filter");
}
/*
Refresh the widget by ensuring our attributes are up to date
*/
LogWidget.prototype.refresh = function(changedTiddlers) {
this.refreshSelf();
return true;
};
/*
Invoke the action associated with this widget
*/
LogWidget.prototype.invokeAction = function(triggeringWidget,event) {
this.log();
return true; // Action was invoked
};
LogWidget.prototype.log = function() {
var data = {},
dataCount,
allVars = {},
filteredVars;
$tw.utils.each(this.attributes,function(attribute,name) {
if(name.substring(0,2) !== "$$") {
data[name] = attribute;
}
});
for(var v in this.variables) {
allVars[v] = this.getVariable(v,{defaultValue:""});
}
if(this.filter) {
filteredVars = this.wiki.compileFilter(this.filter).call(this.wiki,this.wiki.makeTiddlerIterator(allVars));
$tw.utils.each(filteredVars,function(name) {
data[name] = allVars[name];
});
}
dataCount = $tw.utils.count(data);
console.group(this.message);
if(dataCount > 0) {
$tw.utils.logTable(data,["name","value"]);
}
if(this.logAll || !dataCount) {
console.groupCollapsed("All variables");
$tw.utils.logTable(allVars,["name","value"]);
console.groupEnd();
}
console.groupEnd();
}
exports["action-log"] = LogWidget;
})();