ajsfw
Version:
Ajs Framework
147 lines (146 loc) • 7.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils = require("ajsfw/utils");
var Tsx_1 = require("ajsfw/dbg/lib/tsx/Tsx");
var LogType_1 = require("./LogType");
var LogBody = (function () {
function LogBody(logger) {
this._logger = logger;
this._lastSelected = null;
this._lastMarked = null;
}
LogBody.prototype._selectRow = function (e) {
var row = e.currentTarget;
if (row !== this._lastSelected) {
if (this._lastSelected !== null && row !== this._lastSelected) {
var r1 = this._lastSelected.ajsdata;
var r2 = row.ajsdata;
this._logger.setInfo("Time to last selected record: " + Math.abs(r1.time.getTime() - r2.time.getTime()) + "ms");
}
if (this._lastSelected !== null) {
this._lastSelected.removeAttribute("ajsselected");
if (this._lastMarked !== null) {
this._lastMarked.removeAttribute("ajsmarked");
}
this._lastMarked = this._lastSelected;
this._lastMarked.setAttribute("ajsmarked", "true");
}
this._lastSelected = row;
this._lastSelected.setAttribute("ajsselected", "true");
}
else {
if (this._lastMarked !== null) {
this._lastMarked.removeAttribute("ajsmarked");
this._lastMarked = null;
}
}
this._logger.itemSelected(this._lastSelected.ajsdata);
};
LogBody.prototype._scroll = function (e) {
var doc = e.currentTarget.ownerDocument;
var hdr = (doc.getElementsByClassName("ajsDebugLogHeader")[0].parentElement);
var bdy = (doc.getElementsByClassName("ajsDebugLogBody")[0].parentElement);
hdr.scrollLeft = bdy.scrollLeft;
};
LogBody.prototype.setBreakpoint = function () {
this._lastSelected.setAttribute("ajsbreakpoint", "true");
};
LogBody.prototype.unsetBreakpoint = function () {
this._lastSelected.setAttribute("ajsbreakpoint", "false");
};
LogBody.prototype.clearBreakpoints = function () {
var tableElement = this._logElement.children[1].children[0];
for (var i = 0; i < tableElement.childElementCount; i++) {
if (tableElement.childNodes[i] instanceof HTMLTableRowElement &&
tableElement.childNodes[i].hasAttribute("ajsbreakpoint")) {
tableElement.childNodes[i].removeAttribute("ajsbreakpoint");
}
}
};
;
LogBody.prototype.render = function () {
var _this = this;
this._lastSelected = null;
var lines = [];
for (var i = 0; i < this._logger.records.length; i++) {
var className = "ajsDebugLog" + LogType_1.LogType[this._logger.records[i].type];
lines.push(Tsx_1.AjsDebugTsxFactory.createElement("tr", { class: className, ajsbreakpoint: this._logger.records[i].breakpoint, mousedown: function (e) { return (_this._selectRow(e)); }, ajsdata: this._logger.records[i] },
Tsx_1.AjsDebugTsxFactory.createElement("td", null, i),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].occurence),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].time.getTime() - this._logger.initTime),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, LogType_1.LogType[this._logger.records[i].type]),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].level),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].module),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._getType(this._logger.records[i].object)),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].function),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].caller),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].message),
Tsx_1.AjsDebugTsxFactory.createElement("td", null, this._logger.records[i].data)));
}
this._logElement = (Tsx_1.AjsDebugTsxFactory.createElement("div", null,
Tsx_1.AjsDebugTsxFactory.createElement("div", { class: "ajsDebugLogHeaderContainer" },
Tsx_1.AjsDebugTsxFactory.createElement("table", { cellpadding: "0", cellspacing: "0", class: "ajsDebugLogHeader" },
Tsx_1.AjsDebugTsxFactory.createElement("tr", null,
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "No."),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Occ"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Time"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Type"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Lvl"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Module"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Object class"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Function / Method"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Caller"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Message"),
Tsx_1.AjsDebugTsxFactory.createElement("th", null, "Data")))),
Tsx_1.AjsDebugTsxFactory.createElement("div", { class: "ajsDebugLogContainer", scroll: function (e) { return (_this._scroll(e)); } },
Tsx_1.AjsDebugTsxFactory.createElement("table", { cellpadding: "0", cellspacing: "0", class: "ajsDebugLogBody" }, lines))));
return this._logElement;
};
LogBody.prototype._getType = function (object) {
switch (typeof (object)) {
case "string":
return "string";
case "number":
return "number";
case "object":
if (object === null) {
return "null";
}
else {
if (object.constructor) {
return utils.getClassName(object);
}
}
return "object";
default:
return "";
}
};
LogBody.prototype.rendered = function (doc) {
if (this._logger.records.length === 0) {
return;
}
var hdr = doc.getElementsByClassName("ajsDebugLogHeader")[0];
var bdy = doc.getElementsByClassName("ajsDebugLogBody")[0];
for (var i = 0; i < hdr.firstChild.childNodes.length; i++) {
var hth = hdr.firstChild.childNodes[i];
var btd = bdy.firstChild.childNodes[i];
var hcs = window.getComputedStyle(hth);
var bcs = window.getComputedStyle(btd);
var hthSize = parseFloat(hcs.paddingLeft) + parseFloat(hcs.paddingRight) +
parseFloat(hcs.borderLeftWidth) + parseFloat(hcs.borderRightWidth) +
parseFloat(hcs.marginLeft) + parseFloat(hcs.marginRight) + parseFloat(hcs.width);
var bcsSize = parseFloat(bcs.paddingLeft) + parseFloat(bcs.paddingRight) +
parseFloat(bcs.borderLeftWidth) + parseFloat(bcs.borderRightWidth) +
parseFloat(bcs.marginLeft) + parseFloat(bcs.marginRight) + parseFloat(bcs.width);
if (hthSize > bcsSize) {
btd.style.width = hthSize + "px";
}
else {
hth.style.width = bcsSize + "px";
}
}
};
return LogBody;
}());
exports.LogBody = LogBody;