mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-24 12:01:57 +00:00
added a propper tracker threading to loaders and now the loading progress bar mostly works (still some cleanup to do)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9892d26b0a
commit
84a869c2c8
@ -148,7 +148,7 @@ Roadmap
|
||||
| viewer (reloadViewer(true) or ctrl-alt-r)
|
||||
|
|
||||
| NOTE: appears to affect beginning of the ribbon too...
|
||||
[_] BUG: sorting mis-aligns ribbons in some cases...
|
||||
[X] BUG: sorting mis-aligns ribbons in some cases...
|
||||
| Example:
|
||||
| oooo... --[reverse]-> ...oooo
|
||||
| ...oooo[o]oooo... ...oooo[o]oooo...
|
||||
|
||||
90
ui/files.js
90
ui/files.js
@ -107,12 +107,14 @@ function statusNotify(prefix, loader, not_queued){
|
||||
|
||||
|
||||
// XXX
|
||||
function statusProgress(msg, loader){
|
||||
function statusProgress(msg, tracker){
|
||||
tracker = tracker == null ? $.Deferred() : null
|
||||
|
||||
var progress = progressBar(msg)
|
||||
var total = 0
|
||||
var done = 0
|
||||
|
||||
return loader
|
||||
return tracker
|
||||
.done(function(){
|
||||
// XXX why does this close the progress bar right away???
|
||||
closeProgressBar(progress)
|
||||
@ -133,8 +135,9 @@ function statusProgress(msg, loader){
|
||||
// no getter...
|
||||
} else {
|
||||
done += 1
|
||||
updateProgressBar(progress, done, total)
|
||||
}
|
||||
|
||||
updateProgressBar(progress, done, total)
|
||||
})
|
||||
}
|
||||
|
||||
@ -192,21 +195,21 @@ function bubbleProgress(prefix, from, to, only_progress){
|
||||
// NOTE: if neither of dfl, pattern or diff_pattern are given, then this
|
||||
// is essentially the same as $.getJSON(...)
|
||||
// NOTE: this needs listDir(...) to search for latest versions of files.
|
||||
function loadLatestJSONFile(path, dfl, pattern, diff_pattern, default_data){
|
||||
function loadLatestJSONFile(path, dfl, pattern, diff_pattern, default_data, tracker){
|
||||
var pparts = path.split(/[\/\\]/)
|
||||
dfl = dfl == null ? pparts.pop() : dfl
|
||||
//path = path == dfl ? '.' : path
|
||||
path = pparts.join('/')
|
||||
|
||||
var tracker = $.Deferred()
|
||||
var res = $.Deferred()
|
||||
|
||||
if(dfl == ''){
|
||||
return tracker.reject()
|
||||
return res.reject()
|
||||
}
|
||||
|
||||
// can't find diffs if can't list dirs...
|
||||
if(window.listDir == null && (pattern != null || diff_pattern != null)){
|
||||
return tracker.reject('listDir unsupported.')
|
||||
return res.reject('listDir unsupported.')
|
||||
}
|
||||
|
||||
var file_list = null
|
||||
@ -245,13 +248,11 @@ function loadLatestJSONFile(path, dfl, pattern, diff_pattern, default_data){
|
||||
// it outside this (see below) will notify BEFORE
|
||||
// anyone's listening...
|
||||
.always(function(){
|
||||
tracker.notify(e, getter)
|
||||
res.notify(e, getter)
|
||||
})
|
||||
/*
|
||||
// XXX the problem here is if we miss this, then there
|
||||
// is no chance to get it back...
|
||||
tracker.notify(e, getter)
|
||||
*/
|
||||
tracker != null && tracker.notify(e, getter)
|
||||
|
||||
return getter
|
||||
}))
|
||||
@ -267,7 +268,8 @@ function loadLatestJSONFile(path, dfl, pattern, diff_pattern, default_data){
|
||||
// load the main file and merge the diff with it...
|
||||
var getter = $.getJSON(path +'/'+ file)
|
||||
.always(function(){
|
||||
tracker.notify(file, getter)
|
||||
tracker != null && tracker.notify(file, getter)
|
||||
res.notify(file, getter)
|
||||
})
|
||||
$.when(diff, getter)
|
||||
.done(function(_, json){
|
||||
@ -278,23 +280,23 @@ function loadLatestJSONFile(path, dfl, pattern, diff_pattern, default_data){
|
||||
$.extend(json, diff_data)
|
||||
}
|
||||
|
||||
tracker.resolve(json)
|
||||
res.resolve(json)
|
||||
})
|
||||
.fail(function(){
|
||||
if(default_data != null){
|
||||
tracker.resolve(default_data)
|
||||
res.resolve(default_data)
|
||||
} else {
|
||||
tracker.reject()
|
||||
res.reject()
|
||||
}
|
||||
})
|
||||
|
||||
return tracker
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
// NOTE: config change to name will not affect this...
|
||||
function makeFileLoader(title, name, default_data, set_data, error, evt_name, skip_reg){
|
||||
var _loader = function(path){
|
||||
var _loader = function(path, tracker){
|
||||
var res = $.Deferred()
|
||||
|
||||
// NOTE: these are static!!
|
||||
@ -308,7 +310,8 @@ function makeFileLoader(title, name, default_data, set_data, error, evt_name, sk
|
||||
file_dfl,
|
||||
file_pattern,
|
||||
null,
|
||||
default_data)
|
||||
default_data,
|
||||
tracker)
|
||||
|
||||
// explicit path...
|
||||
// XXX need to account for paths without a CONFIG.cache_dir
|
||||
@ -323,7 +326,8 @@ function makeFileLoader(title, name, default_data, set_data, error, evt_name, sk
|
||||
path.split(base)[0],
|
||||
RegExp(path.split(base)[0]),
|
||||
null,
|
||||
default_data)
|
||||
default_data,
|
||||
tracker)
|
||||
}
|
||||
|
||||
res.done(set_data)
|
||||
@ -482,7 +486,7 @@ function ribbonsFromFavDirs(path, images, cmp, dir_name){
|
||||
// Load images from file
|
||||
//
|
||||
// This will also merge all diff files.
|
||||
function loadFileImages(path, no_load_diffs){
|
||||
function loadFileImages(path, tracker, no_load_diffs){
|
||||
no_load_diffs = window.listDir == null ? true : no_load_diffs
|
||||
|
||||
var res = $.Deferred()
|
||||
@ -493,7 +497,9 @@ function loadFileImages(path, no_load_diffs){
|
||||
var loader = loadLatestJSONFile(base,
|
||||
makeBaseFilename(CONFIG.images_file),
|
||||
makeFilenamePattern(CONFIG.images_file),
|
||||
makeDiffFilePattern(CONFIG.images_file))
|
||||
makeDiffFilePattern(CONFIG.images_file),
|
||||
null,
|
||||
tracker)
|
||||
|
||||
// explicit base dir...
|
||||
} else if(!/\.json$/i.test(path)) {
|
||||
@ -501,11 +507,13 @@ function loadFileImages(path, no_load_diffs){
|
||||
var loader = loadLatestJSONFile(base,
|
||||
makeBaseFilename(CONFIG.images_file),
|
||||
makeFilenamePattern(CONFIG.images_file),
|
||||
makeDiffFilePattern(CONFIG.images_file))
|
||||
makeDiffFilePattern(CONFIG.images_file),
|
||||
null,
|
||||
tracker)
|
||||
|
||||
// explicit path...
|
||||
} else {
|
||||
var loader = loadLatestJSONFile(normalizePath(path))
|
||||
var loader = loadLatestJSONFile(normalizePath(path), null, null, null, null, tracker)
|
||||
}
|
||||
|
||||
bubbleProgress('Images', loader, res)
|
||||
@ -576,7 +584,7 @@ function saveFileImagesDiff(name, date){
|
||||
// Load images, ribbons and run registered load callbacks...
|
||||
//
|
||||
// XXX add support for explicit filenames...
|
||||
function loadFileState(path, prefix){
|
||||
function loadFileState(path, prefix, tracker){
|
||||
prefix = prefix == null ? 'Data' : prefix
|
||||
prefix = prefix === false ? null : prefix
|
||||
|
||||
@ -595,7 +603,12 @@ function loadFileState(path, prefix){
|
||||
bubbleProgress(prefix,
|
||||
loadLatestJSONFile(path,
|
||||
makeBaseFilename(CONFIG.data_file),
|
||||
makeFilenamePattern(CONFIG.data_file)), res, true)
|
||||
makeFilenamePattern(CONFIG.data_file),
|
||||
null,
|
||||
null,
|
||||
tracker),
|
||||
res,
|
||||
true)
|
||||
.done(function(json){
|
||||
setBaseURL(base)
|
||||
|
||||
@ -621,13 +634,16 @@ function loadFileState(path, prefix){
|
||||
makeBaseFilename(CONFIG.current_file),
|
||||
null,
|
||||
null,
|
||||
DATA.current), res, true)
|
||||
DATA.current,
|
||||
tracker),
|
||||
res,
|
||||
true)
|
||||
.done(function(cur){
|
||||
DATA.current = cur
|
||||
}),
|
||||
// load images...
|
||||
bubbleProgress(prefix,
|
||||
loadFileImages(base), res, true),
|
||||
loadFileImages(base, tracker), res, true),
|
||||
//loadFileImages(DATA.image_file != null ?
|
||||
// normalizePath(DATA.image_file, base)
|
||||
// : null), res, true),
|
||||
@ -774,10 +790,24 @@ function loadRawDir(path, no_preview_processing, prefix){
|
||||
//
|
||||
// NOTE: this will create an images.json file in cache on opening an
|
||||
// un-cached dir (XXX is this correct???)
|
||||
function loadDir(path, no_preview_processing, prefix){
|
||||
// NOTE: if tracker === false no tracker will get created...
|
||||
function loadDir(path, no_preview_processing, prefix, tracker){
|
||||
prefix = prefix == null ? 'Data' : prefix
|
||||
prefix = prefix === false ? null : prefix
|
||||
|
||||
var res = $.Deferred()
|
||||
|
||||
if(tracker == null){
|
||||
var tracker = statusProgress('Loading')
|
||||
// XXX is this the right way to go???
|
||||
res.done(function(){
|
||||
tracker.resolve()
|
||||
})
|
||||
}
|
||||
if(tracker == false){
|
||||
tracker == null
|
||||
}
|
||||
|
||||
// stop all workers running on current image set before we
|
||||
// move to the next...
|
||||
// XXX is this the correct spot for this???
|
||||
@ -789,8 +819,6 @@ function loadDir(path, no_preview_processing, prefix){
|
||||
var orig_path = path
|
||||
var data
|
||||
|
||||
var res = $.Deferred()
|
||||
|
||||
res.notify(prefix, 'Loading', path)
|
||||
|
||||
var files = listDir(path)
|
||||
@ -807,7 +835,7 @@ function loadDir(path, no_preview_processing, prefix){
|
||||
}
|
||||
|
||||
bubbleProgress(prefix,
|
||||
loadFileState(path, false), res, true)
|
||||
loadFileState(path, false, tracker), res, true)
|
||||
.done(function(){
|
||||
res.resolve()
|
||||
})
|
||||
|
||||
@ -168,7 +168,10 @@ $(function(){
|
||||
BASE_URL = localStorage[data_attr + '_BASE_URL']
|
||||
|
||||
//var loading = statusNotify(loadDir(BASE_URL))
|
||||
var loading = statusProgress('Loading', statusNotify(loadDir(BASE_URL)))
|
||||
|
||||
//var loading = statusProgress('Loading', statusNotify(loadDir(BASE_URL)))
|
||||
|
||||
var loading = statusNotify(loadDir(BASE_URL))
|
||||
|
||||
} else {
|
||||
// everything is in localStorage...
|
||||
|
||||
@ -621,6 +621,12 @@ jQuery.fn.sortChildren = function(func){
|
||||
// Test if any workers are running in the pool.
|
||||
// NOTE: this will return false ONLY when the pool is empty.
|
||||
//
|
||||
// .isPaused() -> bool
|
||||
// Test if pool is in a paused state.
|
||||
// NOTE: some workers may sill be finishing up so if you want
|
||||
// to test whether any workers are still running use
|
||||
// .isRunning()
|
||||
//
|
||||
//
|
||||
// Event handler/callback registration:
|
||||
//
|
||||
@ -822,10 +828,6 @@ function makeDeferredPool(size, paused){
|
||||
return this
|
||||
}
|
||||
|
||||
Pool.isRunning = function(){
|
||||
return this.pool.len() > 0
|
||||
}
|
||||
|
||||
// NOTE: this will not directly cause .isRunning() to return false
|
||||
// as this will not directly spot all workers, it will just
|
||||
// pause the queue and the workers that have already started
|
||||
@ -854,6 +856,13 @@ function makeDeferredPool(size, paused){
|
||||
return this
|
||||
}
|
||||
|
||||
Pool.isPaused = function(){
|
||||
return this._paused
|
||||
}
|
||||
Pool.isRunning = function(){
|
||||
return this.pool.len() > 0
|
||||
}
|
||||
|
||||
|
||||
// Generic event handlers...
|
||||
Pool.on = function(evt, handler){
|
||||
|
||||
11
ui/marks.js
11
ui/marks.js
@ -285,18 +285,23 @@ function shiftGIDToOrderInList(gid, direction, list){
|
||||
//
|
||||
// returns true if list is updated....
|
||||
function shiftGIDInSparseList(gid, from, to, list){
|
||||
if(list[from] == null && list[to] == null){
|
||||
// XXX do we need this???
|
||||
if(list[from] == null
|
||||
&& list[to] == null
|
||||
// NOTE: if there is something between 'from' and 'to' it must
|
||||
// be shifted...
|
||||
&& compactSparceList(list.slice(from, to)).length == 0){
|
||||
return false
|
||||
}
|
||||
|
||||
// if gid was never in list, we must it and remove leave things as
|
||||
// we got them, and remove it again...
|
||||
var cleanup = list.indexOf(gid) < 0
|
||||
|
||||
// move the marked gid...
|
||||
list.splice(from, 1)
|
||||
list.splice(to, 0, gid)
|
||||
|
||||
// if gid was never in list, we must remove leave things as we got
|
||||
// them, and remove it again...
|
||||
// NOTE: essentially, we are using gid as a marker, as we can't
|
||||
// .splice(..) an undefined into a list...
|
||||
if(cleanup){
|
||||
|
||||
@ -113,7 +113,8 @@ function killAllWorkers(){
|
||||
.done(function(){
|
||||
console.log('Worker: All workers stopped.')
|
||||
res.resolve()
|
||||
$('.progress-bar').remove()
|
||||
// XXX do we need this???
|
||||
//$('.progress-bar').remove()
|
||||
})
|
||||
|
||||
return res
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user