mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
reworked logging and progress...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e1ccbb6e72
commit
be163d3a12
@ -14,6 +14,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Features:
|
* Features:
|
||||||
|
* - logger
|
||||||
* - introspection
|
* - introspection
|
||||||
* - lifecycle
|
* - lifecycle
|
||||||
* base life-cycle events (start/stop/..)
|
* base life-cycle events (start/stop/..)
|
||||||
@ -214,6 +215,130 @@ if(typeof(window) != 'undefined'){
|
|||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
// Logger...
|
||||||
|
|
||||||
|
// XXX add log filtering...
|
||||||
|
var LoggerActions = actions.Actions({
|
||||||
|
Logger: object.Constructor('BaseLogger', {
|
||||||
|
__context: null,
|
||||||
|
get context(){
|
||||||
|
return this.__context || this.root.__context },
|
||||||
|
|
||||||
|
root: null,
|
||||||
|
get isRoot(){
|
||||||
|
return this === this.root },
|
||||||
|
|
||||||
|
// NOTE: to disable log retention in .log set this to false...
|
||||||
|
__log: null,
|
||||||
|
get log(){
|
||||||
|
return this.__log === false ?
|
||||||
|
false
|
||||||
|
: this.__log ?
|
||||||
|
this.__log
|
||||||
|
: this.isRoot ?
|
||||||
|
(this.__log = this.__log || [])
|
||||||
|
: this.root.log },
|
||||||
|
|
||||||
|
__path: null,
|
||||||
|
get path(){
|
||||||
|
return (this.__path =
|
||||||
|
this.__path == null ?
|
||||||
|
[]
|
||||||
|
: this.__path) },
|
||||||
|
set path(value){
|
||||||
|
this.__path = value },
|
||||||
|
|
||||||
|
|
||||||
|
// log management...
|
||||||
|
clear: function(){
|
||||||
|
this.log
|
||||||
|
&& this.log.splice(0, this.log.length)
|
||||||
|
return this },
|
||||||
|
print: function(){
|
||||||
|
return this.log ?
|
||||||
|
this.log
|
||||||
|
.map(function([path, status, rest]){
|
||||||
|
return path.join(': ') + (path.length > 0 ? ': ' : '')
|
||||||
|
+ status
|
||||||
|
+ (rest.length > 1 ?
|
||||||
|
':\n\t'
|
||||||
|
: rest.length == 1 ?
|
||||||
|
': '
|
||||||
|
: '')
|
||||||
|
+ rest.join(': ') })
|
||||||
|
.join('\n')
|
||||||
|
: '' },
|
||||||
|
|
||||||
|
|
||||||
|
// main API...
|
||||||
|
push: function(...msg){
|
||||||
|
return msg.length == 0 ?
|
||||||
|
this
|
||||||
|
: Object.assign(
|
||||||
|
this.constructor(),
|
||||||
|
{
|
||||||
|
root: this.root,
|
||||||
|
path: this.path.concat(msg),
|
||||||
|
}) },
|
||||||
|
pop: function(){
|
||||||
|
return (this.root === this || this.path.length == 1) ?
|
||||||
|
this
|
||||||
|
: Object.assign(
|
||||||
|
this.constructor(),
|
||||||
|
{
|
||||||
|
root: this.root,
|
||||||
|
path: this.path.slice(0, -1),
|
||||||
|
}) },
|
||||||
|
|
||||||
|
emit: function(status, ...rest){
|
||||||
|
this.log !== false
|
||||||
|
&& this.log.push([this.path, status, rest])
|
||||||
|
this.context
|
||||||
|
&& this.context.handleLogItem
|
||||||
|
&& this.context.handleLogItem(this.path, status, ...rest)
|
||||||
|
return this },
|
||||||
|
|
||||||
|
|
||||||
|
__call__: function(_, status, ...rest){
|
||||||
|
return this.emit(status, ...rest) },
|
||||||
|
__init__: function(context){
|
||||||
|
this.__context = context
|
||||||
|
this.root = this
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
__logger: null,
|
||||||
|
get logger(){
|
||||||
|
return (this.__logger =
|
||||||
|
this.__logger
|
||||||
|
|| this.Logger(this)) },
|
||||||
|
|
||||||
|
// XXX move this to console-logger... (???)
|
||||||
|
handleLogItem: ['- System/',
|
||||||
|
function(path, status, ...rest){
|
||||||
|
console.log(
|
||||||
|
path.join(': ') + (path.length > 0 ? ': ' : '')
|
||||||
|
+ status
|
||||||
|
+ (rest.length > 1 ?
|
||||||
|
':\n\t'
|
||||||
|
: rest.length == 1 ?
|
||||||
|
': '
|
||||||
|
: ''), ...rest) }],
|
||||||
|
})
|
||||||
|
|
||||||
|
var Logger =
|
||||||
|
module.Logger = ImageGridFeatures.Feature({
|
||||||
|
title: '',
|
||||||
|
|
||||||
|
tag: 'logger',
|
||||||
|
depends: [],
|
||||||
|
|
||||||
|
actions: LoggerActions,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
// Introspection...
|
// Introspection...
|
||||||
|
|
||||||
// Normalize doc strings...
|
// Normalize doc strings...
|
||||||
|
|||||||
@ -25,6 +25,7 @@ core.ImageGridFeatures.Feature('imagegrid-commandline', [
|
|||||||
|
|
||||||
core.ImageGridFeatures.Feature('imagegrid-minimal', [
|
core.ImageGridFeatures.Feature('imagegrid-minimal', [
|
||||||
'lifecycle',
|
'lifecycle',
|
||||||
|
'logger', // XXX
|
||||||
'alias',
|
'alias',
|
||||||
'peer',
|
'peer',
|
||||||
'fs',
|
'fs',
|
||||||
|
|||||||
@ -142,6 +142,37 @@ var ProgressActions = actions.Actions({
|
|||||||
|
|
||||||
// XXX what should we return??? (state, self, controller?)
|
// XXX what should we return??? (state, self, controller?)
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
// handle logger progress...
|
||||||
|
// XXX revise...
|
||||||
|
handleLogItem: ['- System/',
|
||||||
|
function(path, status, ...rest){
|
||||||
|
var msg = this.message
|
||||||
|
|
||||||
|
// report progress...
|
||||||
|
// XXX HACK -- need meaningful status...
|
||||||
|
if(status == 'queued'
|
||||||
|
|| status == 'found'){
|
||||||
|
this.showProgress(msg || ['Progress', status], '+0', '+'+rest.length)
|
||||||
|
|
||||||
|
} else if(status == 'loaded' || status == 'done' || status == 'written'
|
||||||
|
|| status == 'index'){
|
||||||
|
this.showProgress(msg || ['Progress', status], '+'+rest.length)
|
||||||
|
|
||||||
|
} else if(status == 'skipping' || status == 'skipped'){
|
||||||
|
// XXX if everything is skipped the indicator does not
|
||||||
|
// get hidden...
|
||||||
|
//this.showProgress(msg || ['Progress', status], '+0', '-1')
|
||||||
|
this.showProgress(msg || ['Progress', status], '+'+rest.length)
|
||||||
|
|
||||||
|
// XXX STUB...
|
||||||
|
} else if(status == 'error' ){
|
||||||
|
this.showProgress(['Error'].concat(msg), '+0', '+'+rest.length)
|
||||||
|
//console.log(msg ?
|
||||||
|
// ' '+ msg.join(': ') + ':'
|
||||||
|
// : '', ...arguments)
|
||||||
|
}
|
||||||
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
var Progress =
|
var Progress =
|
||||||
|
|||||||
6
ui (gen4)/package-lock.json
generated
6
ui (gen4)/package-lock.json
generated
@ -956,9 +956,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ig-object": {
|
"ig-object": {
|
||||||
"version": "2.0.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/ig-object/-/ig-object-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ig-object/-/ig-object-2.1.0.tgz",
|
||||||
"integrity": "sha512-vYt/WKiBhE5jH7R3RtEXLh8lvY+0aH+WUvW0eB2/KkOKPZgkLqE8XkwIDwdWkvHsSpEqNGybU1kVlSwd+omung=="
|
"integrity": "sha512-8xqHyRmxavh3MRK6UlGKuBGST7dfvUR8sw8nfLyI9BLptp0v+cnZ5OUBXY/C4vwvSEAYrcIwToYwAaHsA2b1MQ=="
|
||||||
},
|
},
|
||||||
"image-size": {
|
"image-size": {
|
||||||
"version": "0.5.5",
|
"version": "0.5.5",
|
||||||
|
|||||||
@ -29,7 +29,7 @@
|
|||||||
"guarantee-events": "^1.0.0",
|
"guarantee-events": "^1.0.0",
|
||||||
"ig-actions": "^3.24.2",
|
"ig-actions": "^3.24.2",
|
||||||
"ig-features": "^3.4.0",
|
"ig-features": "^3.4.0",
|
||||||
"ig-object": "^2.0.0",
|
"ig-object": "^2.1.0",
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"requirejs": "^2.3.6",
|
"requirejs": "^2.3.6",
|
||||||
"requirejs-plugins": "^1.0.2",
|
"requirejs-plugins": "^1.0.2",
|
||||||
|
|||||||
@ -108,72 +108,6 @@ $(function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// setup logger...
|
|
||||||
// XXX STUB...
|
|
||||||
ig.logger = ig.logger || {
|
|
||||||
root: true,
|
|
||||||
message: null,
|
|
||||||
log: null,
|
|
||||||
|
|
||||||
emit: function(e, v){
|
|
||||||
var msg = this.message
|
|
||||||
var log = this.log = this.log || []
|
|
||||||
|
|
||||||
var i = v instanceof Array ? v.length : 1
|
|
||||||
|
|
||||||
// report progress...
|
|
||||||
// XXX HACK -- need meaningful status...
|
|
||||||
if(e == 'queued'
|
|
||||||
|| e == 'found'){
|
|
||||||
ig.showProgress(msg || ['Progress', e], '+0', '+'+i)
|
|
||||||
|
|
||||||
} else if(e == 'loaded' || e == 'done' || e == 'written'
|
|
||||||
|| e == 'index'){
|
|
||||||
ig.showProgress(msg || ['Progress', e], '+'+i)
|
|
||||||
|
|
||||||
} else if(e == 'skipping' || e == 'skipped'){
|
|
||||||
// XXX if everything is skipped the indicator does not
|
|
||||||
// get hidden...
|
|
||||||
//ig.showProgress(msg || ['Progress', e], '+0', '-1')
|
|
||||||
ig.showProgress(msg || ['Progress', e], '+'+i)
|
|
||||||
|
|
||||||
// XXX STUB...
|
|
||||||
} else if(e == 'error' ){
|
|
||||||
ig.showProgress(['Error'].concat(msg), '+0', '+'+i)
|
|
||||||
console.log(msg ?
|
|
||||||
' '+ msg.join(': ') + ':'
|
|
||||||
: '', ...arguments)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// console...
|
|
||||||
console.log(msg ?
|
|
||||||
' '+ msg.join(': ') + ':'
|
|
||||||
: '', ...arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX
|
|
||||||
//log.push([msg, e, v])
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
|
|
||||||
push: function(msg){
|
|
||||||
if(msg == null){
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
var logger = Object.create(this)
|
|
||||||
logger.root = false
|
|
||||||
logger.message = logger.message == null ? [msg] : logger.message.concat([msg])
|
|
||||||
logger.log = this.log = this.log || []
|
|
||||||
|
|
||||||
return logger
|
|
||||||
},
|
|
||||||
pop: function(){
|
|
||||||
return !this.__proto__.root ? this.__proto__ : this
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// setup the viewer...
|
// setup the viewer...
|
||||||
ig
|
ig
|
||||||
.load({ viewer: $('.viewer') })
|
.load({ viewer: $('.viewer') })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user