Fully implement offline docs table

pull/165/head
Thibaut 10 years ago
parent eb58c01ee5
commit f211124d14

@ -48,5 +48,5 @@ class app.collections.Docs extends app.Collection
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, version: value statuses[key] = downloaded: !!value, mtime: value
callback(statuses) callback(statuses)

@ -128,5 +128,5 @@ class app.models.Doc extends app.Model
getDownloadStatus: (callback) -> getDownloadStatus: (callback) ->
app.db.version @, (value) -> app.db.version @, (value) ->
callback downloaded: !!value, version: value callback downloaded: !!value, mtime: value
return return

@ -1,6 +1,14 @@
app.templates.offlinePage = (docs) -> """ app.templates.offlinePage = (docs) -> """
<h1 class="_lined-heading">Offline Documentation</h1> <h1 class="_lined-heading">Offline Documentation</h1>
<table class="_docs">#{docs}</table> <table class="_docs">
<tr>
<th>Documentation</th>
<th class="_docs-size">Size</th>
<th>Status</th>
<th>Action</th>
</tr>
#{docs}
</table>
<h1 class="_lined-heading">Questions & Answers</h1> <h1 class="_lined-heading">Questions & Answers</h1>
<dl> <dl>
<dt>How does this work? <dt>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). """ The current tab will continue to work, though (provided you downloaded all the documentations you want to use beforehand). """
app.templates.offlineDoc = (doc, status) -> app.templates.offlineDoc = (doc, status) ->
html = """<tr data-slug="#{doc.slug}">""" outdated = status.downloaded and status.mtime isnt doc.mtime
html += """<th class="_icon-#{doc.slug}">#{doc.name}</th>"""
html += if status.downloaded html = """
"""<td><a data-del>Delete</a></td>""" <tr data-slug="#{doc.slug}"#{if outdated then ' class="_highlight"' else ''}>
<td class="_docs-name _icon-#{doc.slug}">#{doc.name}</td>
<td class="_docs-size">#{Math.ceil(doc.db_size / 100000) / 10} MB</td>
"""
html += if !status.downloaded
"""
<td>-</td>
<td><a data-dl>Download</a></td>
"""
else if outdated
"""
<td>Outdated</td>
<td><a data-dl>Update</a> - <a data-del>Delete</a></td>
"""
else else
"""<td><a data-dl>Download</a></td>""" """
html += """</tr>""" <td>Up-to-date</td>
html <td><a data-del>Delete</a></td>
"""
html + '</tr>'

@ -39,25 +39,27 @@ class app.views.OfflinePage extends app.View
return return
onClick: (event) => onClick: (event) =>
if event.target.hasAttribute('data-dl') link = event.target
if link.hasAttribute('data-dl')
action = 'download' action = 'download'
else if event.target.hasAttribute('data-del') else if link.hasAttribute('data-del')
action = 'undownload' action = 'undownload'
if action if action
$.stopEvent(event) $.stopEvent(event)
doc = @docByEl(event.target) doc = @docByEl(link)
doc[action](@onDownloadSuccess.bind(@, doc), @onDownloadError.bind(@, doc)) doc[action](@onDownloadSuccess.bind(@, doc), @onDownloadError.bind(@, doc))
@docEl(doc).classList.add("#{action}ing") link.parentNode.innerHTML = "#{link.textContent.replace(/e$/, '')}ing…"
return return
onDownloadSuccess: (doc) -> onDownloadSuccess: (doc) ->
doc.getDownloadStatus (status) => doc.getDownloadStatus (status) =>
@docEl(doc).outerHTML = @renderDoc(doc, status) @docEl(doc).outerHTML = @renderDoc(doc, status)
$.highlight @docEl(doc), className: '_highlight'
return return
onDownloadError: (doc) -> onDownloadError: (doc) ->
el = @docEl(doc) el = @docEl(doc)
el.className = '' el.lastElementChild.textContent = 'Error'
el.classList.add('error')
return return

@ -250,43 +250,25 @@
width: 100%; width: 100%;
line-height: 1.5rem; line-height: 1.5rem;
th { th, td {
max-width: 0; width: 1%;
padding-left: .5rem;
padding-right: .5rem;
white-space: nowrap; white-space: nowrap;
font-weight: normal;
&:before { &:first-child { width: auto; }
float: left; &:last-child { width: 12rem; }
margin: .25rem .5rem .25rem 0;
@extend %icon;
}
} }
td:last-child { text-align: right; }
td > a { cursor: pointer; } td > a { cursor: pointer; }
}
tr.downloading > td:last-child { ._docs-name:before {
> a { display: none; } float: left;
&:before { content: 'Downloading…' } margin: .25rem .5rem .25rem 0;
} @extend %icon;
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-size { text-align: right; }
// //
// News // News
// //

Loading…
Cancel
Save