From f211124d140f80cc2fc4837c1877412792e8499c Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sat, 3 Jan 2015 18:56:37 -0500 Subject: [PATCH] Fully implement offline docs table --- assets/javascripts/collections/docs.coffee | 2 +- assets/javascripts/models/doc.coffee | 2 +- .../templates/pages/offline_tmpl.coffee | 41 +++++++++++++++---- .../views/content/offline_page.coffee | 14 ++++--- assets/stylesheets/components/_content.scss | 40 +++++------------- 5 files changed, 54 insertions(+), 45 deletions(-) diff --git a/assets/javascripts/collections/docs.coffee b/assets/javascripts/collections/docs.coffee index 721f96cd..feded625 100644 --- a/assets/javascripts/collections/docs.coffee +++ b/assets/javascripts/collections/docs.coffee @@ -48,5 +48,5 @@ class app.collections.Docs extends app.Collection app.db.versions @models, (statuses) -> if statuses for key, value of statuses - statuses[key] = downloaded: !!value, version: value + statuses[key] = downloaded: !!value, mtime: value callback(statuses) diff --git a/assets/javascripts/models/doc.coffee b/assets/javascripts/models/doc.coffee index bb67a672..3144fcb9 100644 --- a/assets/javascripts/models/doc.coffee +++ b/assets/javascripts/models/doc.coffee @@ -128,5 +128,5 @@ class app.models.Doc extends app.Model getDownloadStatus: (callback) -> app.db.version @, (value) -> - callback downloaded: !!value, version: value + callback downloaded: !!value, mtime: value return diff --git a/assets/javascripts/templates/pages/offline_tmpl.coffee b/assets/javascripts/templates/pages/offline_tmpl.coffee index 500190fb..2d3a5720 100644 --- a/assets/javascripts/templates/pages/offline_tmpl.coffee +++ b/assets/javascripts/templates/pages/offline_tmpl.coffee @@ -1,6 +1,14 @@ app.templates.offlinePage = (docs) -> """

Offline Documentation

- #{docs}
+ + + + + + + + #{docs} +
DocumentationSizeStatusAction

Questions & Answers

How does this work? @@ -29,11 +37,28 @@ canICloseTheTab = -> The current tab will continue to work, though (provided you downloaded all the documentations you want to use beforehand). """ app.templates.offlineDoc = (doc, status) -> - html = """""" - html += """#{doc.name}""" - html += if status.downloaded - """Delete""" + outdated = status.downloaded and status.mtime isnt doc.mtime + + html = """ + + #{doc.name} + #{Math.ceil(doc.db_size / 100000) / 10} MB + """ + + html += if !status.downloaded + """ + - + Download + """ + else if outdated + """ + Outdated + Update - Delete + """ else - """Download""" - html += """""" - html + """ + Up-to-date + Delete + """ + + html + '' diff --git a/assets/javascripts/views/content/offline_page.coffee b/assets/javascripts/views/content/offline_page.coffee index 5ec1b322..124215d7 100644 --- a/assets/javascripts/views/content/offline_page.coffee +++ b/assets/javascripts/views/content/offline_page.coffee @@ -39,25 +39,27 @@ class app.views.OfflinePage extends app.View return onClick: (event) => - if event.target.hasAttribute('data-dl') + link = event.target + + if link.hasAttribute('data-dl') action = 'download' - else if event.target.hasAttribute('data-del') + else if link.hasAttribute('data-del') action = 'undownload' if action $.stopEvent(event) - doc = @docByEl(event.target) + doc = @docByEl(link) doc[action](@onDownloadSuccess.bind(@, doc), @onDownloadError.bind(@, doc)) - @docEl(doc).classList.add("#{action}ing") + link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…" return onDownloadSuccess: (doc) -> doc.getDownloadStatus (status) => @docEl(doc).outerHTML = @renderDoc(doc, status) + $.highlight @docEl(doc), className: '_highlight' return onDownloadError: (doc) -> el = @docEl(doc) - el.className = '' - el.classList.add('error') + el.lastElementChild.textContent = 'Error' return diff --git a/assets/stylesheets/components/_content.scss b/assets/stylesheets/components/_content.scss index 48d6d0fc..beb94238 100644 --- a/assets/stylesheets/components/_content.scss +++ b/assets/stylesheets/components/_content.scss @@ -250,43 +250,25 @@ width: 100%; line-height: 1.5rem; - th { - max-width: 0; - padding-left: .5rem; - padding-right: .5rem; + th, td { + width: 1%; white-space: nowrap; - font-weight: normal; - &:before { - float: left; - margin: .25rem .5rem .25rem 0; - @extend %icon; - } + &:first-child { width: auto; } + &:last-child { width: 12rem; } } - td:last-child { text-align: right; } td > a { cursor: pointer; } +} - tr.downloading > td:last-child { - > a { display: none; } - &:before { content: 'Downloading…' } - } - - tr.undownloading > td:last-child { - > a { display: none; } - &:before { content: 'Deleting…' } - } - - tr.error > td:last-child { - > a { display: none; } - - &:before { - content: 'Error'; - color: red; - } - } +._docs-name:before { + float: left; + margin: .25rem .5rem .25rem 0; + @extend %icon; } +._docs-size { text-align: right; } + // // News //