Add setting for updating offline docs automatically

pull/165/head
Thibaut 10 years ago
parent ebd00f5a72
commit 6a82830ab4

@ -99,6 +99,9 @@
@checkForDocUpdates()
checkForDocUpdates: ->
if @settings.get('autoUpdate')
@docs.updateInBackground()
else
@docs.checkForUpdates (i) ->
new app.views.Notif 'UpdateDocs', autoHide: null if i > 0

@ -7,6 +7,7 @@ class app.Settings
hideDisabled: false
hideIntro: false
news: 0
autoUpdate: true
constructor: (@store) ->
@create() unless @settings = @store.get(SETTINGS_KEY)

@ -59,7 +59,16 @@ class app.collections.Docs extends app.Collection
@getInstallStatuses (statuses) =>
i = 0
if statuses
i += 1 for slug, status of statuses when status.installed and @findBy('slug', slug).mtime isnt status.mtime
i += 1 for slug, status of statuses when @findBy('slug', slug).isOutdated(status)
callback(i)
return
return
updateInBackground: ->
@getInstallStatuses (statuses) =>
return unless statuses
for slug, status of statuses
doc = @findBy 'slug', slug
doc.install($.noop, $.noop) if doc.isOutdated(status)
return
return

@ -130,3 +130,6 @@ class app.models.Doc extends app.Model
app.db.version @, (value) ->
callback installed: !!value, mtime: value
return
isOutdated: (status) ->
status.installed and @mtime isnt status.mtime

@ -5,6 +5,10 @@ app.templates.offlinePage = (docs) -> """
<div class="_docs-links">
<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>
<label class="_docs-label">
<input type="checkbox" name="autoUpdate" value="1" #{if app.settings.get('autoUpdate') then 'checked' else ''}>
Check for and install updates automatically
</label>
</div>
<table class="_docs">
@ -44,7 +48,7 @@ canICloseTheTab = ->
The current tab will continue to work, though (provided you installed all the documentations you want to use beforehand). """
app.templates.offlineDoc = (doc, status) ->
outdated = status.installed and status.mtime isnt doc.mtime
outdated = doc.isOutdated(status)
html = """
<tr data-slug="#{doc.slug}"#{if outdated then ' class="_highlight"' else ''}>

@ -3,6 +3,7 @@ class app.views.OfflinePage extends app.View
@events:
click: 'onClick'
change: 'onChange'
deactivate: ->
if super
@ -68,3 +69,8 @@ class app.views.OfflinePage extends app.View
el = @docEl(doc)
el.lastElementChild.textContent = 'Error'
return
onChange: (event) ->
if event.target.name is 'autoUpdate'
app.settings.set 'autoUpdate', !!event.target.checked
return

@ -248,6 +248,7 @@
._docs {
width: 100%;
margin-top: .75rem;
line-height: 1.5rem;
th, td {
@ -269,7 +270,10 @@
._docs-size { text-align: right; }
._docs-tools { overflow: hidden; }
._docs-tools {
overflow: hidden;
line-height: 1.5rem;
}
._docs-links {
float: right;
@ -287,6 +291,21 @@
&._show ~ &._show { border-left: 1px solid $boxBorder; }
}
._docs-label {
display: block;
overflow: hidden;
margin: 1px 0;
padding: .375rem .5rem;
> input {
display: inline-block;
vertical-align: top;
margin: .25rem;
width: 1rem;
height: 1rem;
}
}
//
// News
//

Loading…
Cancel
Save