History

Check for offline doc updates automatically

Thibaut committed 11 years ago

Commit ebd00f51 parent 71f33875 files · +30 −8Browse files

Unified · Split

5 files
  1. assets/javascripts/app/app.coffee +5 −0
  2. assets/javascripts/collections/docs.coffee +13 −0
  3. assets/javascripts/templates/notif_tmpl.coffee +4 −0
  4. assets/javascripts/templates/pages/offline_tmpl.coffee +2 −2
  5. assets/javascripts/views/content/offline_page.coffee +6 −6
assets/javascripts/app/app.coffee+5−0
@@ -96,6 +96,11 @@ · 95 unmodified lines
9696 new app.views.Notif 'Share', autoHide: null if visitCount is 5
9797 new app.views.Notif 'Thanks', autoHide: null if visitCount is 10
9898 new app.views.News()
99+ @checkForDocUpdates()
100+
101+ checkForDocUpdates: ->
102+ @docs.checkForUpdates (i) ->
103+ new app.views.Notif 'UpdateDocs', autoHide: null if i > 0
99104
100105 reload: ->
101106 @docs.clearCache()
assets/javascripts/collections/docs.coffee+13−0
@@ -42,7 +42,9 @@ class app.collections.Docs extends app.Collection · 41 unmodified lines
4242 @models[i++].uninstall(next, next)
4343 else
4444 callback()
45+ return
4546 next()
47+ return
4648
4749 getInstallStatuses: (callback) ->
4850 app.db.versions @models, (statuses) ->
@@ -50,3 +52,14 @@ class app.collections.Docs extends app.Collection · 1 unmodified line
5052 for key, value of statuses
5153 statuses[key] = installed: !!value, mtime: value
5254 callback(statuses)
55+ return
56+ return
57+
58+ checkForUpdates: (callback) ->
59+ @getInstallStatuses (statuses) =>
60+ i = 0
61+ if statuses
62+ i += 1 for slug, status of statuses when status.installed and @findBy('slug', slug).mtime isnt status.mtime
63+ callback(i)
64+ return
65+ return
assets/javascripts/templates/notif_tmpl.coffee+4−0
@@ -36,3 +36,7 @@ app.templates.notifThanks = -> · 35 unmodified lines
3636 <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!
3737 </ul>
3838 <p class="_notif-text">Have a great day :) """
39+
40+app.templates.notifUpdateDocs = ->
41+ textNotif """ Documentation updates available. """,
42+ """ <a href="/offline">Install them</a> as soon as possible to avoid broken pages. """
assets/javascripts/templates/pages/offline_tmpl.coffee+2−2
@@ -3,7 +3,7 @@ app.templates.offlinePage = (docs) -> """ · 2 unmodified lines
33
44 <div class="_docs-tools">
55 <div class="_docs-links">
6− <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>
6+ <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>
77 </div>
88 </div>
99
@@ -59,7 +59,7 @@ app.templates.offlineDoc = (doc, status) -> · 49 unmodified lines
5959 """
6060 else if outdated
6161 """
62− <td>Outdated</td>
62+ <td><strong>Outdated</strong></td>
6363 <td><a data-action="update">Update</a> - <a data-action="uninstall">Uninstall</a></td>
6464 """
6565 else
assets/javascripts/views/content/offline_page.coffee+6−6
@@ -45,16 +45,16 @@ class app.views.OfflinePage extends app.View · 44 unmodified lines
4545 return
4646
4747 onClick: (event) =>
48− target = event.target
49− if action = target.getAttribute('data-action')
48+ return unless link = $.closestLink(event.target)
49+ if action = link.getAttribute('data-action')
5050 $.stopEvent(event)
51− doc = @docByEl(target)
51+ doc = @docByEl(link)
5252 action = 'install' if action is 'update'
5353 doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc))
54− target.parentNode.innerHTML = "#{target.textContent.replace(/e$/, '')}ing…"
55− else if action = target.getAttribute('data-action-all')
54+ link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…"
55+ else if action = link.getAttribute('data-action-all')
5656 $.stopEvent(event)
57− link.click() for link in @findAll("a[data-action='#{action}']")
57+ el.click() for el in @findAll("a[data-action='#{action}']")
5858 return
5959
6060 onInstallSuccess: (doc) ->

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t