Download/Delete -> Install/Uninstall

pull/165/head
Thibaut 10 years ago
parent 6e54d92f18
commit e9fc1d3c68

@ -35,18 +35,18 @@ class app.collections.Docs extends app.Collection
doc.clearCache() for doc in @models doc.clearCache() for doc in @models
return return
undownload: (callback) -> uninstall: (callback) ->
i = 0 i = 0
next = => next = =>
if i < @models.length if i < @models.length
@models[i++].undownload(next, next) @models[i++].uninstall(next, next)
else else
callback() callback()
next() next()
getDownloadStatuses: (callback) -> getInstallStatuses: (callback) ->
app.db.versions @models, (statuses) -> app.db.versions @models, (statuses) ->
if statuses if statuses
for key, value of statuses for key, value of statuses
statuses[key] = downloaded: !!value, mtime: value statuses[key] = installed: !!value, mtime: value
callback(statuses) callback(statuses)

@ -89,17 +89,17 @@ class app.models.Doc extends app.Model
app.store.set @slug, [@mtime, data] app.store.set @slug, [@mtime, data]
return return
download: (onSuccess, onError) -> install: (onSuccess, onError) ->
return if @downloading return if @installing
@downloading = true @installing = true
error = => error = =>
@downloading = null @installing = null
onError() onError()
return return
success = (data) => success = (data) =>
@downloading = null @installing = null
app.db.store @, data, onSuccess, error app.db.store @, data, onSuccess, error
return return
@ -109,24 +109,24 @@ class app.models.Doc extends app.Model
error: error error: error
return return
undownload: (onSuccess, onError) -> uninstall: (onSuccess, onError) ->
return if @downloading return if @installing
@downloading = true @installing = true
success = => success = =>
@downloading = null @installing = null
onSuccess() onSuccess()
return return
error = => error = =>
@downloading = null @installing = null
onError() onError()
return return
app.db.unstore @, success, error app.db.unstore @, success, error
return return
getDownloadStatus: (callback) -> getInstallStatus: (callback) ->
app.db.version @, (value) -> app.db.version @, (value) ->
callback downloaded: !!value, mtime: value callback installed: !!value, mtime: value
return return

@ -30,14 +30,14 @@ app.templates.offlinePage = (docs) -> """
canICloseTheTab = -> canICloseTheTab = ->
if app.AppCache.isEnabled() if app.AppCache.isEnabled()
""" Yes! Even offline, you can open a new tab, go to <a href="http://devdocs.io">devdocs.io</a>, and everything will work as if you were online (provided you downloaded all the documentations you want to use beforehand).<br> """ Yes! Even offline, you can open a new tab, go to <a href="http://devdocs.io">devdocs.io</a>, and everything will work as if you were online (provided you installed all the documentations you want to use beforehand).<br>
Note that loading any page other than <a href="http://devdocs.io">devdocs.io</a> directly won't work (due to limitations in AppCache). """ Note that loading any page other than <a href="http://devdocs.io">devdocs.io</a> directly won't work (due to limitations in AppCache). """
else else
""" No. Because AppCache is unavailable in your browser (or has been disabled), loading <a href="http://devdocs.io">devdocs.io</a> offline won't work.<br> """ No. Because AppCache is unavailable in your browser (or has been disabled), loading <a href="http://devdocs.io">devdocs.io</a> offline won't work.<br>
The current tab will continue to work, though (provided you downloaded all the documentations you want to use beforehand). """ The current tab will continue to work, though (provided you installed all the documentations you want to use beforehand). """
app.templates.offlineDoc = (doc, status) -> app.templates.offlineDoc = (doc, status) ->
outdated = status.downloaded and status.mtime isnt doc.mtime outdated = status.installed and status.mtime isnt doc.mtime
html = """ html = """
<tr data-slug="#{doc.slug}"#{if outdated then ' class="_highlight"' else ''}> <tr data-slug="#{doc.slug}"#{if outdated then ' class="_highlight"' else ''}>
@ -45,20 +45,20 @@ app.templates.offlineDoc = (doc, status) ->
<td class="_docs-size">#{Math.ceil(doc.db_size / 100000) / 10} MB</td> <td class="_docs-size">#{Math.ceil(doc.db_size / 100000) / 10} MB</td>
""" """
html += if !status.downloaded html += if !status.installed
""" """
<td>-</td> <td>-</td>
<td><a data-dl>Download</a></td> <td><a data-dl>Install</a></td>
""" """
else if outdated else if outdated
""" """
<td>Outdated</td> <td>Outdated</td>
<td><a data-dl>Update</a> - <a data-del>Delete</a></td> <td><a data-dl>Update</a> - <a data-del>Uninstall</a></td>
""" """
else else
""" """
<td>Up-to-date</td> <td>Up-to-date</td>
<td><a data-del>Delete</a></td> <td><a data-del>Uninstall</a></td>
""" """
html + '</tr>' html + '</tr>'

@ -10,7 +10,7 @@ class app.views.OfflinePage extends app.View
return return
render: -> render: ->
app.docs.getDownloadStatuses (statuses) => app.docs.getInstallStatuses (statuses) =>
return unless @activated return unless @activated
if statuses is false if statuses is false
@html @tmpl('offlineError') @html @tmpl('offlineError')
@ -42,24 +42,24 @@ class app.views.OfflinePage extends app.View
link = event.target link = event.target
if link.hasAttribute('data-dl') if link.hasAttribute('data-dl')
action = 'download' action = 'install'
else if link.hasAttribute('data-del') else if link.hasAttribute('data-del')
action = 'undownload' action = 'uninstall'
if action if action
$.stopEvent(event) $.stopEvent(event)
doc = @docByEl(link) doc = @docByEl(link)
doc[action](@onDownloadSuccess.bind(@, doc), @onDownloadError.bind(@, doc)) doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc))
link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…" link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…"
return return
onDownloadSuccess: (doc) -> onInstallSuccess: (doc) ->
doc.getDownloadStatus (status) => doc.getInstallStatus (status) =>
@docEl(doc).outerHTML = @renderDoc(doc, status) @docEl(doc).outerHTML = @renderDoc(doc, status)
$.highlight @docEl(doc), className: '_highlight' $.highlight @docEl(doc), className: '_highlight'
return return
onDownloadError: (doc) -> onInstallError: (doc) ->
el = @docEl(doc) el = @docEl(doc)
el.lastElementChild.textContent = 'Error' el.lastElementChild.textContent = 'Error'
return return

@ -50,7 +50,7 @@ class app.views.DocPicker extends app.View
app.settings.setDocs(docs) app.settings.setDocs(docs)
@saveLink.textContent = if app.appCache then 'Downloading\u2026' else 'Saving\u2026' @saveLink.textContent = if app.appCache then 'Downloading\u2026' else 'Saving\u2026'
disabledDocs = new app.collections.Docs(doc for doc in app.docs.all() when docs.indexOf(doc.slug) is -1) disabledDocs = new app.collections.Docs(doc for doc in app.docs.all() when docs.indexOf(doc.slug) is -1)
disabledDocs.undownload -> app.reload() disabledDocs.uninstall -> app.reload()
return return
getSelectedDocs: -> getSelectedDocs: ->

Loading…
Cancel
Save