Check for offline doc updates automatically

This commit is contained in:
Thibaut 2015-01-11 17:52:45 -05:00
parent 71f3387eeb
commit ebd00f5a72
5 changed files with 30 additions and 8 deletions

View file

@ -96,6 +96,11 @@
new app.views.Notif 'Share', autoHide: null if visitCount is 5
new app.views.Notif 'Thanks', autoHide: null if visitCount is 10
new app.views.News()
@checkForDocUpdates()
checkForDocUpdates: ->
@docs.checkForUpdates (i) ->
new app.views.Notif 'UpdateDocs', autoHide: null if i > 0
reload: ->
@docs.clearCache()

View file

@ -42,7 +42,9 @@ class app.collections.Docs extends app.Collection
@models[i++].uninstall(next, next)
else
callback()
return
next()
return
getInstallStatuses: (callback) ->
app.db.versions @models, (statuses) ->
@ -50,3 +52,14 @@ class app.collections.Docs extends app.Collection
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

View file

@ -36,3 +36,7 @@ app.templates.notifThanks = ->
<li><a href="http://devdocs.io/s/shopify" target="_blank">Shopify</a> is where I spend my weekdays. Interested in working on one of the biggest commerce platforms in the world, in a delightful work environment? We're hiring!
</ul>
<p class="_notif-text">Have a great day :) """
app.templates.notifUpdateDocs = ->
textNotif """ Documentation updates available. """,
""" <a href="/offline">Install them</a> as soon as possible to avoid broken pages. """

View file

@ -3,7 +3,7 @@ app.templates.offlinePage = (docs) -> """
<div class="_docs-tools">
<div class="_docs-links">
<a class="_docs-link" data-action-all="install">Install all</a><a class="_docs-link" data-action-all="update">Update all</a><a class="_docs-link" data-action-all="uninstall">Uninstall all</a>
<a class="_docs-link" data-action-all="install">Install all</a><a class="_docs-link" data-action-all="update"><strong>Update all</strong></a><a class="_docs-link" data-action-all="uninstall">Uninstall all</a>
</div>
</div>
@ -59,7 +59,7 @@ app.templates.offlineDoc = (doc, status) ->
"""
else if outdated
"""
<td>Outdated</td>
<td><strong>Outdated</strong></td>
<td><a data-action="update">Update</a> - <a data-action="uninstall">Uninstall</a></td>
"""
else

View file

@ -45,16 +45,16 @@ class app.views.OfflinePage extends app.View
return
onClick: (event) =>
target = event.target
if action = target.getAttribute('data-action')
return unless link = $.closestLink(event.target)
if action = link.getAttribute('data-action')
$.stopEvent(event)
doc = @docByEl(target)
doc = @docByEl(link)
action = 'install' if action is 'update'
doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc))
target.parentNode.innerHTML = "#{target.textContent.replace(/e$/, '')}ing…"
else if action = target.getAttribute('data-action-all')
link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…"
else if action = link.getAttribute('data-action-all')
$.stopEvent(event)
link.click() for link in @findAll("a[data-action='#{action}']")
el.click() for el in @findAll("a[data-action='#{action}']")
return
onInstallSuccess: (doc) ->