fixed a bug in progress + working on .linked...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-26 19:04:47 +03:00
parent d74486f95c
commit e04e050f18
3 changed files with 113 additions and 52 deletions

View File

@ -1989,6 +1989,7 @@ progress:not(value)::-webkit-progress-bar {
display: none; display: none;
} }
.progress-bar { .progress-bar {
position: relative;
color: silver; color: silver;
font-size: 10px; font-size: 10px;
margin: 10px; margin: 10px;
@ -1996,8 +1997,8 @@ progress:not(value)::-webkit-progress-bar {
.progress-bar .close { .progress-bar .close {
display: none; display: none;
position: absolute; position: absolute;
top: 0px; top: -10px;
right: 7px; right: 0px;
width: 20px; width: 20px;
font-size: 20px; font-size: 20px;
text-align: center; text-align: center;

View File

@ -2978,8 +2978,102 @@ var TaskActions = actions.Actions({
// XXX is context manager a special case of task manager??? // XXX is context manager a special case of task manager???
// XXX move to a separate feature... // XXX move to a separate feature...
__contexts: null,
get contexts(){}, get contexts(){},
// Links...
//
__links: null,
get links(){
var links = this.__linked = this.__linked || {}
// remove 'current' if it does not match the current index...
// XXX revise the test...
var c = links.current
if(c && (c.data !== this.data || c.images !== this.images)){
links.previous = c
delete links.current }
return links },
get linked(){
return this.link() },
link: ['- System/',
doc`Get/create links...
Get/create link to current state...
.link()
.link('current')
-> current-link
Get link to previous state if present...
.link('previous')
-> previous-link
-> undefined
Get/create a titled link...
.link(title)
-> link
A link is a separate ImageGrid instance that links to the parent's
state and explicitly disabled ui features.
A link will reflect the data changes but when the main index is
cleared or reloaded it will retain the old data.
Care must be taken as this is true in both directions and changes
to link state are reflected on the link .parent, this is useful
when updating state in the background but can bite the user if not
used carefully.
This effectively enables us to isolate a context for long running
actions/tasks and make them independent of the main state.
Example:
ig.linked.readAllMetadata()
NOTE: links are relatively cheap as almost no data is copied but
they can be a source of a memory "leak" if not cleaned out
as they prevent data from being garbage collected...
NOTE: 'current' and 'previous' links are reserved.
NOTE: 'previous' are a special case as they can not be created
via .link(..).
`,
function(title='current'){
var that = this
var links = this.links
// get link already created...
// NOTE: 'current' and 'previous' links are handled by the
// .links prop...
var link = links[title]
if(link){
return link }
// prevent creating previous links...
if(title == 'previous'){
return actions.UNDEFINED }
// create a link...
// NOTE: we intentionally disable ui here and do not trigger .start()...
return (links[title] =
Object.assign(
// XXX add a 'link' feature...
ImageGridFeatures.setup([
...this.features.input,
'-ui',
]),
this,
{
// link metadata...
parent: this,
title: title,
// XXX change this when data/images changes...
// ...a prop in the link feature...
type: 'link',
// link configuration...
logger: that.logger
.push(`Linked ${ Object.keys(links).length }`),
})) }],
// XXX this should delete the clone when done...
LinkedTask: ['- System/',
function(){}],
// XXX would be nice to have an ability to partially clone the instance... // XXX would be nice to have an ability to partially clone the instance...
// ...currently we can do a full clone and remove things we do // ...currently we can do a full clone and remove things we do
// not want but that still takes time and memory... // not want but that still takes time and memory...
@ -3024,52 +3118,6 @@ var TaskActions = actions.Actions({
undefined undefined
: res }], : res }],
// Create a new ig instance with the same data...
//
// This will reflect the data changes while when the main index is
// cleared or reloaded this will retain the old data...
//
// XXX should this be a prop -- .linked???
// XXX would be a good idea to store all the links in once place...
__linked: null,
get linked(){
return (this.__linked = this.__linked || []) },
link: ['- System/',
function(title){
var that = this
var links = this.linked
// get link already created...
var link = this.linked
.filter(function(l){
return title ?
l.title == title
: (l.data === that.data
&& l.images === that.images) })
.last()
if(link){
return link }
// create a link...
// NOTE: we intentionally disable ui here and do not trigger .start()...
link = ImageGridFeatures.setup([...this.features.input, '-ui'])
return Object.assign(
link,
this,
{
// XXX revise...
parent: this,
title: title,
// XXX change this when data/images changes...
type: 'link',
})
.run(function(){
this.logger = that.logger.push(['Task', links.length].join(' '))
this.context_id = links.push(this) }) }],
// XXX this should delete the clone when done...
LinkedTask: ['- System/',
function(){}],
}) })
var Tasks = var Tasks =

View File

@ -141,8 +141,15 @@ var ProgressActions = actions.Actions({
var forceShow = !!(attrs || {}).forceShow var forceShow = !!(attrs || {}).forceShow
;[text, value, max] = args ;[text, value, max] = args
var msg = text instanceof Array ? text.slice(1).join(': ') : null // XXX revise...
text = text instanceof Array ? text[0] : text var msg =
(text instanceof Array
&& text.length > 1) ?
text.slice(1).join(': ')
: null
text = text instanceof Array ?
text[0]
: text
// reset -- clear cache and set everything to 0... // reset -- clear cache and set everything to 0...
// NOTE: we will later draw the progress bar full... // NOTE: we will later draw the progress bar full...
@ -157,8 +164,11 @@ var ProgressActions = actions.Actions({
var cache = (this.__progress_cache = this.__progress_cache || {}) var cache = (this.__progress_cache = this.__progress_cache || {})
cache = cache[text] = cache = cache[text] =
Object.assign( Object.assign(
cache[text] || {}, {msg},
cache[text] || {msg},
attrs || {}) attrs || {})
// restore cached message if none given...
msg = cache.msg = msg || cache.msg
var updateValue = function(name, value){ var updateValue = function(name, value){
var v = cache[name] || 0 var v = cache[name] || 0
@ -284,7 +294,9 @@ var ProgressActions = actions.Actions({
.replace(/^00:(00:)?/, '') }s` .replace(/^00:(00:)?/, '') }s`
: '' : ''
// format the message... // format the message...
msg = msg ? ': '+msg : '' msg = msg ?
': '+msg
: ''
msg = ' '+ msg msg = ' '+ msg
+ (value && value >= (max || 0) ? + (value && value >= (max || 0) ?
' (done)' ' (done)'