diff --git a/assets/javascripts/app/app.coffee b/assets/javascripts/app/app.coffee index ad0772f6..ec56e021 100644 --- a/assets/javascripts/app/app.coffee +++ b/assets/javascripts/app/app.coffee @@ -99,8 +99,11 @@ @checkForDocUpdates() checkForDocUpdates: -> - @docs.checkForUpdates (i) -> - new app.views.Notif 'UpdateDocs', autoHide: null if i > 0 + if @settings.get('autoUpdate') + @docs.updateInBackground() + else + @docs.checkForUpdates (i) -> + new app.views.Notif 'UpdateDocs', autoHide: null if i > 0 reload: -> @docs.clearCache() diff --git a/assets/javascripts/app/settings.coffee b/assets/javascripts/app/settings.coffee index e1552de5..46061040 100644 --- a/assets/javascripts/app/settings.coffee +++ b/assets/javascripts/app/settings.coffee @@ -7,6 +7,7 @@ class app.Settings hideDisabled: false hideIntro: false news: 0 + autoUpdate: true constructor: (@store) -> @create() unless @settings = @store.get(SETTINGS_KEY) diff --git a/assets/javascripts/collections/docs.coffee b/assets/javascripts/collections/docs.coffee index 1a69ac85..30001566 100644 --- a/assets/javascripts/collections/docs.coffee +++ b/assets/javascripts/collections/docs.coffee @@ -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 diff --git a/assets/javascripts/models/doc.coffee b/assets/javascripts/models/doc.coffee index 44ce1ff2..13995a5a 100644 --- a/assets/javascripts/models/doc.coffee +++ b/assets/javascripts/models/doc.coffee @@ -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 diff --git a/assets/javascripts/templates/pages/offline_tmpl.coffee b/assets/javascripts/templates/pages/offline_tmpl.coffee index c8bfb376..4b993a76 100644 --- a/assets/javascripts/templates/pages/offline_tmpl.coffee +++ b/assets/javascripts/templates/pages/offline_tmpl.coffee @@ -5,6 +5,10 @@ app.templates.offlinePage = (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 = """ diff --git a/assets/javascripts/views/content/offline_page.coffee b/assets/javascripts/views/content/offline_page.coffee index 6acc446a..df1ea9d4 100644 --- a/assets/javascripts/views/content/offline_page.coffee +++ b/assets/javascripts/views/content/offline_page.coffee @@ -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 diff --git a/assets/stylesheets/components/_content.scss b/assets/stylesheets/components/_content.scss index 4b9fd2e9..16c4f3f1 100644 --- a/assets/stylesheets/components/_content.scss +++ b/assets/stylesheets/components/_content.scss @@ -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 //