You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/collections/docs.coffee

66 lines
1.5 KiB

11 years ago
class app.collections.Docs extends app.Collection
@model: 'Doc'
sort: ->
@models.sort (a, b) ->
a = a.name.toLowerCase()
b = b.name.toLowerCase()
if a < b then -1 else if a > b then 1 else 0
11 years ago
# Load models concurrently.
# It's not pretty but I didn't want to import a promise library only for this.
CONCURRENCY = 3
load: (onComplete, onError, options) ->
i = 0
next = =>
if i < @models.length
@models[i].load(next, fail, options)
else if i is @models.length + CONCURRENCY - 1
onComplete()
i++
return
fail = (args...) ->
if onError
onError(args...)
onError = null
next()
return
next() for [0...CONCURRENCY]
return
clearCache: ->
doc.clearCache() for doc in @models
return
uninstall: (callback) ->
i = 0
next = =>
if i < @models.length
@models[i++].uninstall(next, next)
else
callback()
return
next()
return
getInstallStatuses: (callback) ->
app.db.versions @models, (statuses) ->
if statuses
for key, value of statuses
statuses[key] = installed: !!value, mtime: value
callback(statuses)
return
return
checkForUpdates: (callback) ->
@getInstallStatuses (statuses) =>
i = 0
if statuses
i += 1 for slug, status of statuses when status.installed and @findBy('slug', slug).mtime isnt status.mtime
callback(i)
return
return