basic load progress bar, still not working correctly -- need to thread a visiting thacker through the loading system / rething how it's done...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-01-26 08:43:44 +04:00
parent 25af190b24
commit 1cc4e3fe0c
2 changed files with 41 additions and 3 deletions

View File

@ -72,6 +72,7 @@ function makeDiffFilePattern(base, diff, ext){
// //
// Will return the original deferred. // Will return the original deferred.
function statusNotify(prefix, loader, not_queued){ function statusNotify(prefix, loader, not_queued){
not_queued = not_queued == null ? true : not_queued
var report = not_queued == true ? showStatus : showStatusQ var report = not_queued == true ? showStatus : showStatusQ
if(loader == null){ if(loader == null){
loader = prefix loader = prefix
@ -88,7 +89,7 @@ function statusNotify(prefix, loader, not_queued){
report(args.join(': ')) report(args.join(': '))
}) })
.fail(function(){ .fail(function(){
// XXX showErrorStatus(args.join(': '))
}) })
return return
} }
@ -105,6 +106,39 @@ function statusNotify(prefix, loader, not_queued){
} }
// XXX
function statusProgress(msg, loader){
var progress = progressBar(msg)
var total = 0
var done = 0
return loader
.done(function(){
// XXX why does this close the progress bar right away???
closeProgressBar(progress)
})
.progress(function(){
var args = args2array(arguments)
var getter = args[args.length-1]
total += 1
// the getter is a deferred...
if(getter != null && getter.isResolved != null){
args.pop()
.always(function(){
done += 1
updateProgressBar(progress, done, total)
})
// no getter...
} else {
done += 1
updateProgressBar(progress, done, total)
}
})
}
// Bubble up actions in the deferred chain // Bubble up actions in the deferred chain
// //
// Will chain progress/notify and if only_progress is not set, also // Will chain progress/notify and if only_progress is not set, also
@ -204,7 +238,9 @@ function loadLatestFile(path, dfl, pattern, diff_pattern, default_data){
// keep the sort order... // keep the sort order...
diff_data[i+1] = data diff_data[i+1] = data
}) })
// XXX this is a hack... // XXX need to notify as early as possible but doing
// it outside this (see below) will notify BEFORE
// anyone's listening...
.always(function(){ .always(function(){
tracker.notify(e, getter) tracker.notify(e, getter)
}) })
@ -213,6 +249,7 @@ function loadLatestFile(path, dfl, pattern, diff_pattern, default_data){
// is no chance to get it back... // is no chance to get it back...
tracker.notify(e, getter) tracker.notify(e, getter)
*/ */
return getter return getter
})) }))
// merge the diffs... // merge the diffs...

View File

@ -167,7 +167,8 @@ $(function(){
BASE_URL = localStorage[data_attr + '_BASE_URL'] BASE_URL = localStorage[data_attr + '_BASE_URL']
var loading = statusNotify(loadDir(BASE_URL)) //var loading = statusNotify(loadDir(BASE_URL))
var loading = statusProgress('Loading', statusNotify(loadDir(BASE_URL)))
} else { } else {
// everything is in localStorage... // everything is in localStorage...