Add setting for updating offline docs automatically

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

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

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

@ -59,7 +59,16 @@ class app.collections.Docs extends app.Collection
@getInstallStatuses (statuses) => @getInstallStatuses (statuses) =>
i = 0 i = 0
if statuses 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) callback(i)
return return
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) -> app.db.version @, (value) ->
callback installed: !!value, mtime: value callback installed: !!value, mtime: value
return return
isOutdated: (status) ->
status.installed and @mtime isnt status.mtime

@ -5,6 +5,10 @@ app.templates.offlinePage = (docs) -> """
<div class="_docs-links"> <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> <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>
<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> </div>
<table class="_docs"> <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). """ 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.installed and status.mtime isnt doc.mtime outdated = doc.isOutdated(status)
html = """ html = """
<tr data-slug="#{doc.slug}"#{if outdated then ' class="_highlight"' else ''}> <tr data-slug="#{doc.slug}"#{if outdated then ' class="_highlight"' else ''}>

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

@ -248,6 +248,7 @@
._docs { ._docs {
width: 100%; width: 100%;
margin-top: .75rem;
line-height: 1.5rem; line-height: 1.5rem;
th, td { th, td {
@ -269,7 +270,10 @@
._docs-size { text-align: right; } ._docs-size { text-align: right; }
._docs-tools { overflow: hidden; } ._docs-tools {
overflow: hidden;
line-height: 1.5rem;
}
._docs-links { ._docs-links {
float: right; float: right;
@ -287,6 +291,21 @@
&._show ~ &._show { border-left: 1px solid $boxBorder; } &._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 // News
// //

Loading…
Cancel
Save