mirror of
https://bitbucket.org/bellord13/kit.git
synced 2026-11-13 19:06:11 +03:00
fix
This commit is contained in:
@@ -22,27 +22,26 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
return new Collection([]);
|
return new Collection([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLastIndex(key){
|
|
||||||
var n = Number(key);
|
|
||||||
if (support.arr.isKey(key) && n > this.__lastIndex) {
|
|
||||||
this.__lastIndex = n;
|
|
||||||
}
|
|
||||||
return this.__lastIndex;
|
|
||||||
}
|
|
||||||
function actualParams() {
|
|
||||||
var index;
|
|
||||||
this.length = this.__keys.length;
|
|
||||||
this.__lastIndex = 0;
|
|
||||||
for(index in this.__keys) {
|
|
||||||
setLastIndex.call(this, this.__keys[index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @class Collection
|
* @class Collection
|
||||||
|
* @property length
|
||||||
* @memberOf kit
|
* @memberOf kit
|
||||||
*/
|
*/
|
||||||
var Collection = function (data = []) {
|
var Collection = function (data = []) {
|
||||||
|
var self = this;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
|
||||||
|
support.definePropertyGet(this, 'length', function () {
|
||||||
|
return self.__keys.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
if(data instanceof Collection) {
|
||||||
|
this.__type = data.__type;
|
||||||
|
this.__keys = data.__keys;
|
||||||
|
this.__values = data.__values;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(Array.isArray(data)) {
|
if(Array.isArray(data)) {
|
||||||
this.__type = 'array';
|
this.__type = 'array';
|
||||||
}
|
}
|
||||||
@@ -58,18 +57,28 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
console.warn('collection: not support data' + typeof data);
|
console.warn('collection: not support data' + typeof data);
|
||||||
}
|
}
|
||||||
var key;
|
var key;
|
||||||
this.__lastIndex = 0;
|
|
||||||
this.length = 0;
|
|
||||||
this.__keys = [];
|
this.__keys = [];
|
||||||
this.__values = [];
|
this.__values = [];
|
||||||
for(key in this.data) {
|
for(key in this.data) {
|
||||||
if(!this.data.hasOwnProperty(key)) continue;
|
if(!this.data.hasOwnProperty(key)) continue;
|
||||||
setLastIndex.call(this, key);
|
this.__keys.push(safeArrayKey(key));
|
||||||
this.length = this.__keys.push(safeArrayKey(key));
|
|
||||||
this.__values.push(this.data[key]);
|
this.__values.push(this.data[key]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
Collection.prototype.__getLastIndex = function () {
|
||||||
|
var lastIndex = -1, n = 0, index;
|
||||||
|
for(index in this.__keys) {
|
||||||
|
n = this.__keys[index];
|
||||||
|
if (support.isNumber(n) && n > lastIndex) {
|
||||||
|
lastIndex = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastIndex;
|
||||||
|
};
|
||||||
Collection.prototype.all = function () {
|
Collection.prototype.all = function () {
|
||||||
if(this.__type === 'array' || this.__type === 'arrayObject') {
|
if(this.__type === 'array' || this.__type === 'arrayObject') {
|
||||||
return this.toArray();
|
return this.toArray();
|
||||||
@@ -115,7 +124,6 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
}
|
}
|
||||||
this.length = this.__keys.push(safeArrayKey(key));
|
this.length = this.__keys.push(safeArrayKey(key));
|
||||||
this.data[key] = this.__values[this.length-1] = value;
|
this.data[key] = this.__values[this.length-1] = value;
|
||||||
setLastIndex.call(this, key);
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -123,7 +131,7 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
* @return {kit.Collection}
|
* @return {kit.Collection}
|
||||||
*/
|
*/
|
||||||
Collection.prototype.push = function (value) {
|
Collection.prototype.push = function (value) {
|
||||||
this.set(this.__lastIndex + 1, value);
|
this.set(this.__getLastIndex() + 1, value);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Collection.prototype.get = function (key, defValue = undefined) {
|
Collection.prototype.get = function (key, defValue = undefined) {
|
||||||
@@ -296,7 +304,6 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
var index = this.indexKey(key);
|
var index = this.indexKey(key);
|
||||||
this.__keys.splice(index, 1);
|
this.__keys.splice(index, 1);
|
||||||
this.__values.splice(index, 1);
|
this.__values.splice(index, 1);
|
||||||
actualParams.call(this);
|
|
||||||
delete this.data[key];
|
delete this.data[key];
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@@ -315,7 +322,6 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
var value = this.__values[index];
|
var value = this.__values[index];
|
||||||
this.__keys.splice(index, 1);
|
this.__keys.splice(index, 1);
|
||||||
this.__values.splice(index, 1);
|
this.__values.splice(index, 1);
|
||||||
actualParams.call(this);
|
|
||||||
delete this.data[key];
|
delete this.data[key];
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
@@ -331,7 +337,6 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
var value = this.__values[index];
|
var value = this.__values[index];
|
||||||
this.__keys.splice(index, 1);
|
this.__keys.splice(index, 1);
|
||||||
this.__values.splice(index, 1);
|
this.__values.splice(index, 1);
|
||||||
actualParams.call(this);
|
|
||||||
delete this.data[key];
|
delete this.data[key];
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
@@ -347,7 +352,6 @@ kit.PluginManager.register('Collection', function(module, exports, require, glob
|
|||||||
var value = this.__values[index];
|
var value = this.__values[index];
|
||||||
this.__keys.splice(index, 1);
|
this.__keys.splice(index, 1);
|
||||||
this.__values.splice(index, 1);
|
this.__values.splice(index, 1);
|
||||||
actualParams.call(this);
|
|
||||||
delete this.data[key];
|
delete this.data[key];
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -212,14 +212,20 @@ __PluginManager__.registerPlugins({
|
|||||||
path: __pmConfig__.assetsPath + '/testing',
|
path: __pmConfig__.assetsPath + '/testing',
|
||||||
module: '/testing.js',
|
module: '/testing.js',
|
||||||
type: 'loader',
|
type: 'loader',
|
||||||
deps: ['Logger'],
|
deps: ['loggerService'],
|
||||||
},
|
},
|
||||||
Logger: {
|
Logger: {
|
||||||
path: __pmConfig__.assetsPath + '/logger',
|
path: __pmConfig__.assetsPath + '/logger',
|
||||||
module: '/logger.js',
|
module: '/logger.js',
|
||||||
css: '/logger.css',
|
|
||||||
type: 'loader',
|
type: 'loader',
|
||||||
deps: ['support']
|
deps: ['support', 'Collection']
|
||||||
|
},
|
||||||
|
loggerService: {
|
||||||
|
path: __pmConfig__.assetsPath + '/loggerService',
|
||||||
|
module: '/loggerService.js',
|
||||||
|
css: '/loggerService.css',
|
||||||
|
type: 'loader',
|
||||||
|
deps: ['Logger', 'support']
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
+25
-126
@@ -1,162 +1,61 @@
|
|||||||
/** @module logger */
|
/** @module Logger */
|
||||||
__PluginManager__.register('Logger', function(module, exports, require, global){
|
__PluginManager__.register('Logger', function(module, exports, require, global){
|
||||||
|
|
||||||
var support = require('support');
|
var support = require('support');
|
||||||
|
var Collection = require('Collection');
|
||||||
var lightMap = [
|
|
||||||
{class: '', keys: []},
|
|
||||||
{class: 'text-danger', keys: []},
|
|
||||||
{class: 'text-secondary', keys: []},
|
|
||||||
];
|
|
||||||
var getLightClass = function(key) {
|
|
||||||
key = ''+key;
|
|
||||||
var addClass = '', ar;
|
|
||||||
for(var i=0; i < lightMap.length; i++){
|
|
||||||
ar = lightMap[i]['keys'];
|
|
||||||
addClass = ar.includes(key)?lightMap[i]['class']:addClass;
|
|
||||||
}
|
|
||||||
return addClass;
|
|
||||||
};
|
|
||||||
var collectionTemplater = '<div class="kit-logger kit-logger--fixed"></div>';
|
|
||||||
// function dump(value) {
|
|
||||||
// var rArray = [];
|
|
||||||
// if(value === null) {
|
|
||||||
// rArray[0] = 'null';
|
|
||||||
// } else {
|
|
||||||
// rArray[0] = String(typeof value);
|
|
||||||
// rArray[1] = emptyPHP(value)?'empty':'';
|
|
||||||
// }
|
|
||||||
// return rArray.join(' ');
|
|
||||||
// };
|
|
||||||
function getRowNode(level, key, value, opClass = ''){
|
|
||||||
if(opClass) {
|
|
||||||
opClass = ' kit-logger-row--'+opClass;
|
|
||||||
}
|
|
||||||
var i = 0, lvlTemplate = '';
|
|
||||||
key = String(key);
|
|
||||||
value = String(value);
|
|
||||||
lvlTemplate = level?'style="--logger-lvl:'+level+';" ':'';
|
|
||||||
var result = '<logger-item '+lvlTemplate+'class="'+getLightClass(key)+opClass+'"><logger-item__key>'+key+'</logger-item__key><logger-item__value>'+value+'</logger-item__value></logger-item>';
|
|
||||||
|
|
||||||
return support.makeNode(result);
|
|
||||||
}
|
|
||||||
function getItemObjectNode(id = ''){
|
|
||||||
var entity = '', css = '', style = '';
|
|
||||||
if(id) {
|
|
||||||
css = '<style>input#'+id+':checked ~ [data-entity-id="'+id+'"] {display: block !important;}</style>';
|
|
||||||
entity = ' data-entity-id="'+id+'"';
|
|
||||||
style = ' style="display: none"'
|
|
||||||
}
|
|
||||||
return support.makeNode('<logger-item-object'+entity+style+'>'+css+'</logger-item-object>');
|
|
||||||
}
|
|
||||||
|
|
||||||
function args2array(arguments) {
|
|
||||||
var args = [];
|
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
|
||||||
args.push(arguments[i]);
|
|
||||||
}
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Logger
|
* @class Logger
|
||||||
* @memberOf kit
|
* @memberOf kit
|
||||||
*/
|
*/
|
||||||
var Logger = function() {
|
var Logger = function() {
|
||||||
this.collection = undefined;
|
this.collection = new Collection();
|
||||||
|
this.onLog = new Collection();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param node {HTMLElement}
|
* @param collection {kit.Collection}
|
||||||
*/
|
*/
|
||||||
Logger.prototype.setCollection = function (node) {
|
Logger.prototype.setCollection = function (collection) {
|
||||||
/**
|
this.collection = collection;
|
||||||
* @type {HTMLElement}
|
|
||||||
*/
|
|
||||||
this.collection = node || document.getElementById('kit-logger') || document.querySelector('.kit-logger') || support.makeNode(collectionTemplater);
|
|
||||||
|
|
||||||
if((this.collection instanceof HTMLElement) && !this.collection.parentElement) {
|
|
||||||
document.body.appendChild(this.collection)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Logger.prototype.__row = function(message, lvl = 0, opClass = '') {
|
|
||||||
if (!this.collection) {
|
|
||||||
this.setCollection();
|
|
||||||
}
|
|
||||||
var log = this.collection;
|
|
||||||
|
|
||||||
function setObjectValue(log, lvl, key, value, opClass, depth = 3, openDepth = 1, isRoot = true) {
|
|
||||||
var rowChild, isObj = support.isObject(value), id = isObj?support.uniqueId():'',
|
|
||||||
val = (isObj&&depth)?'<label for="'+id+'">'+value+'</label>':value, inp, j,
|
|
||||||
len = isObj?Object.keys(value).length:0;
|
|
||||||
|
|
||||||
if(!isRoot || (isRoot && !isObj)) {
|
|
||||||
log.appendChild(getRowNode(lvl, key, '' + val + (isObj?(' ['+len+']'):''), opClass));
|
|
||||||
}
|
|
||||||
if(isObj&&depth) {
|
|
||||||
!isRoot && ++lvl;
|
|
||||||
depth = Math.max(0, depth - 1);
|
|
||||||
log.appendChild(inp = support.makeNode('<input id="'+id+'" type="checkbox" style="display: none;">'));
|
|
||||||
inp.checked = !!openDepth;
|
|
||||||
openDepth = Math.max(0, openDepth - 1);
|
|
||||||
log.appendChild(rowChild = getItemObjectNode(id));
|
|
||||||
for(j in value) {
|
|
||||||
if(value.hasOwnProperty(j))
|
|
||||||
setObjectValue(rowChild, lvl, j, value[j], opClass, depth, openDepth, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setObjectValue(log, lvl, '', message, opClass, 6, 3);
|
|
||||||
|
|
||||||
log.scrollTop = log.scrollHeight;
|
|
||||||
};
|
|
||||||
|
|
||||||
Logger.prototype.__log = function(lvl, type, message, context){
|
|
||||||
lvl = Number(lvl);
|
|
||||||
var opClass = '';
|
|
||||||
if(arguments.length >= 2) opClass = type;
|
|
||||||
if(arguments.length >= 3)
|
|
||||||
this.__row(message, lvl, opClass);
|
|
||||||
if(arguments.length >= 4)
|
|
||||||
this.__row(context, lvl+1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.emergency = function (message, context) {
|
Logger.prototype.emergency = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'emergency'].concat(args2array(arguments)));
|
this.log(0, message, context, 'emergency');
|
||||||
};
|
};
|
||||||
Logger.prototype.alert = function (message, context) {
|
Logger.prototype.alert = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'alert'].concat(args2array(arguments)));
|
this.log(0, message, context, 'alert');
|
||||||
};
|
};
|
||||||
Logger.prototype.critical = function (message, context) {
|
Logger.prototype.critical = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'critical'].concat(args2array(arguments)));
|
this.log(0, message, context, 'critical');
|
||||||
};
|
};
|
||||||
Logger.prototype.error = function (message, context) {
|
Logger.prototype.error = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'error'].concat(args2array(arguments)));
|
this.log(0, message, context, 'error');
|
||||||
};
|
};
|
||||||
Logger.prototype.warning = function (message, context) {
|
Logger.prototype.warning = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'warning'].concat(args2array(arguments)));
|
this.log(0, message, context, 'warning');
|
||||||
};
|
};
|
||||||
Logger.prototype.notice = function (message, context) {
|
Logger.prototype.notice = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'notice'].concat(args2array(arguments)));
|
this.log(0, message, context, 'notice');
|
||||||
};
|
};
|
||||||
Logger.prototype.info = function (message, context) {
|
Logger.prototype.info = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'info'].concat(args2array(arguments)));
|
this.log(0, message, context, 'info');
|
||||||
};
|
};
|
||||||
Logger.prototype.debug = function (message, context) {
|
Logger.prototype.debug = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'debug'].concat(args2array(arguments)));
|
this.log(0, message, context, 'debug');
|
||||||
};
|
};
|
||||||
Logger.prototype.success = function (message, context) {
|
Logger.prototype.success = function (message, context) {
|
||||||
this.__log.apply(this, [0, 'success'].concat(args2array(arguments)));
|
this.log(0, message, context, 'success');
|
||||||
};
|
};
|
||||||
Logger.prototype.log = function (lvl = 0, message = '', context, type) {
|
Logger.prototype.log = function (lvl = 0, message = '', context, type) {
|
||||||
lvl = Number(lvl);
|
var data = {
|
||||||
var opClass = '';
|
lvl: lvl,
|
||||||
if(arguments.length >= 4) opClass = type;
|
type: type,
|
||||||
if(arguments.length >= 2)
|
message: message,
|
||||||
this.__row(message, lvl, opClass);
|
context: context,
|
||||||
if(arguments.length >= 3)
|
};
|
||||||
this.__row(context, lvl+1, opClass);
|
this.collection.push(data);
|
||||||
|
this.onLog.eachCall(this, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
return module.exports = Logger;
|
return module.exports = Logger;
|
||||||
|
|||||||
@@ -16,11 +16,13 @@
|
|||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
background: hsla(0, 0%, 11%, 1);
|
background: hsla(0, 0%, 11%, 1);
|
||||||
color: #909090;
|
color: #909090;
|
||||||
height: 100%;
|
|
||||||
overflow-y: scroll !important;
|
overflow-y: scroll !important;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
.kit-logger:empty, #kit-logger:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
.kit-logger--fixed {
|
.kit-logger--fixed {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
/** @module loggerService */
|
||||||
|
__PluginManager__.register('loggerService', function(module, exports, require, global){
|
||||||
|
|
||||||
|
var support = require('support');
|
||||||
|
var Logger = require('Logger');
|
||||||
|
|
||||||
|
var lightMap = [
|
||||||
|
{class: '', keys: []},
|
||||||
|
{class: 'text-danger', keys: []},
|
||||||
|
{class: 'text-secondary', keys: []},
|
||||||
|
];
|
||||||
|
var getLightClass = function(key) {
|
||||||
|
key = ''+key;
|
||||||
|
var addClass = '', ar;
|
||||||
|
for(var i=0; i < lightMap.length; i++){
|
||||||
|
ar = lightMap[i]['keys'];
|
||||||
|
addClass = ar.includes(key)?lightMap[i]['class']:addClass;
|
||||||
|
}
|
||||||
|
return addClass;
|
||||||
|
};
|
||||||
|
var htmlCollectionTemplater = '<div class="kit-logger kit-logger--fixed"></div>';
|
||||||
|
// function dump(value) {
|
||||||
|
// var rArray = [];
|
||||||
|
// if(value === null) {
|
||||||
|
// rArray[0] = 'null';
|
||||||
|
// } else {
|
||||||
|
// rArray[0] = String(typeof value);
|
||||||
|
// rArray[1] = emptyPHP(value)?'empty':'';
|
||||||
|
// }
|
||||||
|
// return rArray.join(' ');
|
||||||
|
// };
|
||||||
|
function getRowNode(level, key, value, opClass = ''){
|
||||||
|
if(opClass) {
|
||||||
|
opClass = ' kit-logger-row--'+opClass;
|
||||||
|
}
|
||||||
|
var lvlTemplate;
|
||||||
|
key = String(key);
|
||||||
|
value = String(value);
|
||||||
|
lvlTemplate = level?'style="--logger-lvl:'+level+';" ':'';
|
||||||
|
var result = '<logger-item '+lvlTemplate+'class="'+getLightClass(key)+opClass+'"><logger-item__key>'+key+'</logger-item__key><logger-item__value>'+value+'</logger-item__value></logger-item>';
|
||||||
|
|
||||||
|
return support.makeNode(result);
|
||||||
|
}
|
||||||
|
function getItemObjectNode(id = ''){
|
||||||
|
var entity = '', css = '', style = '';
|
||||||
|
if(id) {
|
||||||
|
css = '<style>input#'+id+':checked ~ [data-entity-id="'+id+'"] {display: block !important;}</style>';
|
||||||
|
entity = ' data-entity-id="'+id+'"';
|
||||||
|
style = ' style="display: none"'
|
||||||
|
}
|
||||||
|
return support.makeNode('<logger-item-object'+entity+style+'>'+css+'</logger-item-object>');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends kit.Logger
|
||||||
|
* @class LoggerService
|
||||||
|
* @memberOf kit
|
||||||
|
*/
|
||||||
|
var LoggerService = function() {
|
||||||
|
Logger.prototype.constructor.apply(this, arguments);
|
||||||
|
this.onLog.push(this.__log);
|
||||||
|
};
|
||||||
|
|
||||||
|
support.extend(LoggerService.prototype, Logger.prototype);
|
||||||
|
|
||||||
|
LoggerService.prototype.setHtmlCollection = function (node) {
|
||||||
|
/**
|
||||||
|
* @type {HTMLElement}
|
||||||
|
*/
|
||||||
|
this.__htmlCollection = node || document.getElementById('kit-logger') || document.querySelector('.kit-logger') || support.makeNode(__htmlCollectionTemplater);
|
||||||
|
|
||||||
|
if((this.__htmlCollection instanceof HTMLElement) && !this.__htmlCollection.parentElement) {
|
||||||
|
document.body.appendChild(this.__htmlCollection)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
LoggerService.prototype.__row = function(message, lvl = 0, opClass = '') {
|
||||||
|
if (!this.__htmlCollection) {
|
||||||
|
this.setHtmlCollection();
|
||||||
|
}
|
||||||
|
var log = this.__htmlCollection;
|
||||||
|
|
||||||
|
function setObjectValue(log, lvl, key, value, opClass, depth = 3, openDepth = 1, isRoot = true) {
|
||||||
|
var rowChild, isObj = support.isObject(value), id = isObj?support.uniqueId():'',
|
||||||
|
val = (isObj&&depth)?'<label for="'+id+'">'+value+'</label>':value, inp, j,
|
||||||
|
len = isObj?Object.keys(value).length:0;
|
||||||
|
|
||||||
|
if(!isRoot || (isRoot && !isObj)) {
|
||||||
|
log.appendChild(getRowNode(lvl, key, '' + val + (isObj?(' ['+len+']'):''), opClass));
|
||||||
|
}
|
||||||
|
if(isObj&&depth) {
|
||||||
|
!isRoot && ++lvl;
|
||||||
|
depth = Math.max(0, depth - 1);
|
||||||
|
log.appendChild(inp = support.makeNode('<input id="'+id+'" type="checkbox" style="display: none;">'));
|
||||||
|
inp.checked = !!openDepth;
|
||||||
|
openDepth = Math.max(0, openDepth - 1);
|
||||||
|
log.appendChild(rowChild = getItemObjectNode(id));
|
||||||
|
for(j in value) {
|
||||||
|
if(value.hasOwnProperty(j))
|
||||||
|
setObjectValue(rowChild, lvl, j, value[j], opClass, depth, openDepth, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setObjectValue(log, lvl, '', message, opClass, 6, 3);
|
||||||
|
|
||||||
|
log.scrollTop = log.scrollHeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
LoggerService.prototype.__log = function(data = {
|
||||||
|
lvl: 0,
|
||||||
|
message: '',
|
||||||
|
context: [],
|
||||||
|
type: ''
|
||||||
|
}){
|
||||||
|
lvl = support.toNumber(data.lvl);
|
||||||
|
var opClass = String(data.type);
|
||||||
|
this.__row(data.message, lvl, opClass);
|
||||||
|
if(support.isObject(data.context))
|
||||||
|
this.__row(data.context, lvl+1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @memberOf kit.service
|
||||||
|
* @class logger
|
||||||
|
**/
|
||||||
|
var logger = new LoggerService();
|
||||||
|
|
||||||
|
global.service.logger = logger;
|
||||||
|
|
||||||
|
module.exports = logger;
|
||||||
|
});
|
||||||
@@ -68,6 +68,13 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
|||||||
function isNumber(value) {
|
function isNumber(value) {
|
||||||
return !Number.isNaN(value) && isFinite(value) && typeof value === 'number';
|
return !Number.isNaN(value) && isFinite(value) && typeof value === 'number';
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
function toNumber(value, def = 0) {
|
||||||
|
var n = Number(value);
|
||||||
|
return isNumber(n)?n:def;
|
||||||
|
}
|
||||||
function isInteger(value) {
|
function isInteger(value) {
|
||||||
return isNumber(value) && (value % 1) === 0;
|
return isNumber(value) && (value % 1) === 0;
|
||||||
}
|
}
|
||||||
@@ -134,7 +141,20 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
function definePropertyGet(obj, key, val) {
|
||||||
|
Object.defineProperty(obj, key, {
|
||||||
|
get: function () {
|
||||||
|
return valueEx(val);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function args2array(arguments) {
|
||||||
|
var args = [];
|
||||||
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
|
args.push(arguments[i]);
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @memberOf kit
|
* @memberOf kit
|
||||||
*/
|
*/
|
||||||
@@ -158,7 +178,10 @@ __PluginManager__.register('support', function(module, exports, require, global)
|
|||||||
isA,
|
isA,
|
||||||
makeNode,
|
makeNode,
|
||||||
setKit,
|
setKit,
|
||||||
getKit
|
getKit,
|
||||||
|
toNumber,
|
||||||
|
definePropertyGet,
|
||||||
|
args2array
|
||||||
};
|
};
|
||||||
|
|
||||||
return module.exports = support;
|
return module.exports = support;
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
/** @module testing */
|
/** @module testing */
|
||||||
__PluginManager__.register('testing', function(module, exports, require, global){
|
__PluginManager__.register('testing', function(module, exports, require, global){
|
||||||
|
|
||||||
|
var loggerService = require('loggerService');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Unit() {
|
function Unit() {
|
||||||
this.logger = new kit.Logger();
|
this.logger = loggerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param logger {kit.Logger}
|
||||||
|
*/
|
||||||
|
Unit.prototype.setLogger = function (logger) {
|
||||||
|
this.logger = logger;
|
||||||
|
};
|
||||||
|
|
||||||
Unit.prototype.assertSame = function (expected, actual, message) {
|
Unit.prototype.assertSame = function (expected, actual, message) {
|
||||||
if(expected === actual) {
|
if(expected === actual) {
|
||||||
this.logger.success({pass: message});
|
this.logger.success({pass: message});
|
||||||
|
|||||||
+73
-6
@@ -1,17 +1,84 @@
|
|||||||
|
<script src="../assets/config/config.js"></script>
|
||||||
|
<script src="../assets/core/core.js"></script>
|
||||||
|
<script src="../assets/core/core.register.js"></script>
|
||||||
|
|
||||||
<div style="display: flex; flex-direction: column; align-items: center;">
|
<div style="display: flex; flex-direction: column; align-items: center;">
|
||||||
|
<script>
|
||||||
|
var iframeList = [], iframe, i;
|
||||||
|
</script>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$arFilesItems = glob(__DIR__ . '/*Test.php');
|
$arFilesItems = glob(__DIR__ . '/*Test.php');
|
||||||
|
|
||||||
|
|
||||||
foreach ($arFilesItems as $file) {
|
foreach ($arFilesItems as $file) {
|
||||||
$file = basename($file);
|
$file = basename($file);
|
||||||
$clName = substr($file, 0, -8);
|
$clName = substr($file, 0, -8);
|
||||||
echo "<a href=\"$file\"><b>$clName</b></a>";
|
//echo "<a href=\"$file\"><b>$clName</b></a>";
|
||||||
}
|
?>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
iframe = document.createElement("frame");
|
||||||
|
iframe.src = '<?=$file?>';
|
||||||
|
i = iframeList.push({
|
||||||
|
fileName: '<?=$file?>',
|
||||||
|
clName: '<?=$clName?>',
|
||||||
|
iframe: iframe,
|
||||||
|
// contentWindow: iframe.contentWindow,
|
||||||
|
//document: iframe.contentWindow.document
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// if (iframeDoc.readyState == 'complete') {
|
||||||
|
// iframeDoc.body.style.backgroundColor = 'green';
|
||||||
|
// }
|
||||||
|
// iframe.onload = function() {
|
||||||
|
// var iframeDoc2 = iframe.contentWindow.document;
|
||||||
|
// iframeDoc2.body.style.backgroundColor = 'orange';
|
||||||
|
// }
|
||||||
|
</script>
|
||||||
|
<?
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
kit.ready(['Collection', 'flexKit', 'loggerService'], function () {
|
||||||
|
|
||||||
|
window.frameList = new kit.Collection(iframeList);
|
||||||
|
|
||||||
|
frameList.map(function (frameData) {
|
||||||
|
kit.service.logger.notice('<a href="'+frameData.fileName+'">'+frameData.clName+'</a>');
|
||||||
|
});
|
||||||
|
|
||||||
|
kit.service.logger.notice(' ');
|
||||||
|
kit.service.logger.warning('FRAME LIST ...');
|
||||||
|
kit.service.logger.notice(' ');
|
||||||
|
|
||||||
|
console.log(frameList);
|
||||||
|
frameList.map(function (data) {
|
||||||
|
data.iframe.onload = function() {
|
||||||
|
data.kit = data.iframe.contentWindow.kit;
|
||||||
|
//console.log('kit',kit);
|
||||||
|
data.kit.ready([], function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
var log = [];
|
||||||
|
kit.service.logger.info(data.clName);
|
||||||
|
if(data.kit.service.logger){
|
||||||
|
log = data.kit.service.logger.collection.map(function (log) {
|
||||||
|
log.lvl++;
|
||||||
|
kit.service.logger.__log(log);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
document.body.appendChild(data.iframe);
|
||||||
|
data.window = data.iframe.contentWindow;
|
||||||
|
data.document = data.iframe.contentWindow.document;
|
||||||
|
data.kit = data.window.kit;
|
||||||
|
})
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<div class="kit-wrapper">
|
||||||
|
<div class="kit-logger"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -28,6 +28,7 @@ kit.ready(['collection', 'testing', 'flexKit'], function () {
|
|||||||
unit.logger.info('Коллекции by php collection: Array ( [10] => 10 [1] => 1 )');
|
unit.logger.info('Коллекции by php collection: Array ( [10] => 10 [1] => 1 )');
|
||||||
unit.logger.notice(' ');
|
unit.logger.notice(' ');
|
||||||
unit.logger.info('ARRAY');
|
unit.logger.info('ARRAY');
|
||||||
|
unit.logger.notice(' ');
|
||||||
var assertSame = unit.assertSame.bind(unit);
|
var assertSame = unit.assertSame.bind(unit);
|
||||||
|
|
||||||
|
|
||||||
@@ -231,6 +232,8 @@ kit.ready(['collection', 'testing', 'flexKit'], function () {
|
|||||||
y = x.pluck('age');
|
y = x.pluck('age');
|
||||||
assertSame('20-19-18', y.toArray().join('-'), 'pluck с проверкой сохранения порядка');
|
assertSame('20-19-18', y.toArray().join('-'), 'pluck с проверкой сохранения порядка');
|
||||||
|
|
||||||
|
|
||||||
|
assertSame('10', 20, 'Спец ошибка');
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user