2020-11-14 13:00:00 +00:00
|
|
|
/*\
|
|
|
|
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();
|
2020-11-20 14:08:18 +00:00
|
|
|
this.execute();
|
2020-11-14 13:00:00 +00:00
|
|
|
};
|
|
|
|
|
2020-11-20 14:08:18 +00:00
|
|
|
LogWidget.prototype.execute = function(){
|
|
|
|
this.message = this.getAttribute("$$message","debug");
|
|
|
|
this.logAll = this.getAttribute("$$all","no") === "yes" ? true : false;
|
|
|
|
this.filter = this.getAttribute("$$filter");
|
|
|
|
}
|
|
|
|
|
2020-11-14 13:00:00 +00:00
|
|
|
/*
|
|
|
|
Refresh the widget by ensuring our attributes are up to date
|
|
|
|
*/
|
|
|
|
LogWidget.prototype.refresh = function(changedTiddlers) {
|
2020-11-20 14:08:18 +00:00
|
|
|
this.refreshSelf();
|
|
|
|
return true;
|
2020-11-14 13:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Invoke the action associated with this widget
|
|
|
|
*/
|
|
|
|
LogWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
2020-11-20 14:08:18 +00:00
|
|
|
this.log();
|
2020-11-14 13:00:00 +00:00
|
|
|
return true; // Action was invoked
|
|
|
|
};
|
|
|
|
|
2020-11-20 14:08:18 +00:00
|
|
|
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;
|
2021-05-30 18:20:17 +00:00
|
|
|
}
|
2020-11-20 14:08:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for(var v in this.variables) {
|
2024-06-08 16:12:51 +00:00
|
|
|
var variable = this.parentWidget && this.parentWidget.variables[v];
|
|
|
|
if(variable && variable.isFunctionDefinition) {
|
|
|
|
allVars[v] = variable.value;
|
|
|
|
} else {
|
|
|
|
allVars[v] = this.getVariable(v,{defaultValue:""});
|
|
|
|
}
|
2021-05-30 18:20:17 +00:00
|
|
|
}
|
2020-11-20 14:08:18 +00:00
|
|
|
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];
|
2021-05-30 18:20:17 +00:00
|
|
|
});
|
2020-11-20 14:08:18 +00:00
|
|
|
}
|
|
|
|
dataCount = $tw.utils.count(data);
|
|
|
|
|
|
|
|
console.group(this.message);
|
|
|
|
if(dataCount > 0) {
|
2020-12-07 15:53:49 +00:00
|
|
|
$tw.utils.logTable(data);
|
2020-11-20 14:08:18 +00:00
|
|
|
}
|
|
|
|
if(this.logAll || !dataCount) {
|
|
|
|
console.groupCollapsed("All variables");
|
2020-12-07 15:53:49 +00:00
|
|
|
$tw.utils.logTable(allVars);
|
2020-11-20 14:08:18 +00:00
|
|
|
console.groupEnd();
|
|
|
|
}
|
|
|
|
console.groupEnd();
|
|
|
|
}
|
|
|
|
|
2020-11-14 13:00:00 +00:00
|
|
|
exports["action-log"] = LogWidget;
|
|
|
|
|
|
|
|
})();
|