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
96 new app.views.Notif 'Share', autoHide: null if visitCount is 596 new app.views.Notif 'Share', autoHide: null if visitCount is 5
97 new app.views.Notif 'Thanks', autoHide: null if visitCount is 1097 new app.views.Notif 'Thanks', autoHide: null if visitCount is 10
98 new app.views.News()98 new app.views.News()
99 @checkForDocUpdates()
100
101 checkForDocUpdates: ->
102 @docs.checkForUpdates (i) ->
103 new app.views.Notif 'UpdateDocs', autoHide: null if i > 0
99 104
100 reload: ->105 reload: ->
101 @docs.clearCache()106 @docs.clearCache()
assets/javascripts/collections/docs.coffee+13−0
@@ -42,7 +42,9 @@ class app.collections.Docs extends app.Collection · 41 unmodified lines
42 @models[i++].uninstall(next, next)42 @models[i++].uninstall(next, next)
43 else43 else
44 callback()44 callback()
45 return
45 next()46 next()
47 return
46 48
47 getInstallStatuses: (callback) ->49 getInstallStatuses: (callback) ->
48 app.db.versions @models, (statuses) ->50 app.db.versions @models, (statuses) ->
@@ -50,3 +52,14 @@ class app.collections.Docs extends app.Collection · 1 unmodified line
50 for key, value of statuses52 for key, value of statuses
51 statuses[key] = installed: !!value, mtime: value53 statuses[key] = installed: !!value, mtime: value
52 callback(statuses)54 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
36 <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!36 <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!
37 </ul>37 </ul>
38 <p class="_notif-text">Have a great day :) """38 <p class="_notif-text">Have a great day :) """
39
40app.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
3 3
4 <div class="_docs-tools">4 <div class="_docs-tools">
5 <div class="_docs-links">5 <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>
7 </div>7 </div>
8 </div>8 </div>
9 9
@@ -59,7 +59,7 @@ app.templates.offlineDoc = (doc, status) -> · 49 unmodified lines
59 """59 """
60 else if outdated60 else if outdated
61 """61 """
62 <td>Outdated</td>62 <td><strong>Outdated</strong></td>
63 <td><a data-action="update">Update</a> - <a data-action="uninstall">Uninstall</a></td>63 <td><a data-action="update">Update</a> - <a data-action="uninstall">Uninstall</a></td>
64 """64 """
65 else65 else
assets/javascripts/views/content/offline_page.coffee+6−6
@@ -45,16 +45,16 @@ class app.views.OfflinePage extends app.View · 44 unmodified lines
45 return45 return
46 46
47 onClick: (event) =>47 onClick: (event) =>
48 target = event.target48 return unless link = $.closestLink(event.target)
49 if action = target.getAttribute('data-action')49 if action = link.getAttribute('data-action')
50 $.stopEvent(event)50 $.stopEvent(event)
51 doc = @docByEl(target)51 doc = @docByEl(link)
52 action = 'install' if action is 'update'52 action = 'install' if action is 'update'
53 doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc))53 doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc))
54 target.parentNode.innerHTML = "#{target.textContent.replace(/e$/, '')}ing…"54 link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…"
55 else if action = target.getAttribute('data-action-all')55 else if action = link.getAttribute('data-action-all')
56 $.stopEvent(event)56 $.stopEvent(event)
57 link.click() for link in @findAll("a[data-action='#{action}']")57 el.click() for el in @findAll("a[data-action='#{action}']")
58 return58 return
59 59
60 onInstallSuccess: (doc) ->60 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