Skip to content

Instantly share code, notes, and snippets.

@flippyhead
Created February 23, 2016 18:14
Show Gist options
  • Select an option

  • Save flippyhead/eb6459d48801d6c22ad0 to your computer and use it in GitHub Desktop.

Select an option

Save flippyhead/eb6459d48801d6c22ad0 to your computer and use it in GitHub Desktop.
dates = {}
Template.documentsTable.rendered = ->
@autorun ->
Session.get 'query'
dates = {}
@autorun =>
page = (Session.get('limit') / 10) - 1
@$('#documents-table--table tbody tr:last')
.addClass('pageRow')
.removeClass('hidden')
.find('td.page')
.text(page)
Template.documentsTable.helpers
hasDocuments: ->
@?.count() > 0
hasAnyDocuments: ->
return unless count = Count.find().fetch()[0]
{total, query, tags} = count
!!query or tags?.length or total > 0
isReady: ->
!!Count.find().fetch()[0]
heading: ->
return false unless Session.get('sort') is 'updatedAt'
date = @updatedAtAgo()
if not dates[date]? or dates[date] is @_id
dates[date] = @_id
date
else
false
<template name="documentsTable">
{{#if hasAnyDocuments }}
{{#if hasDocuments }}
<table id="documents-table--table" class="table documents-index--table">
<tbody>
{{#each this}}
{{#if heading}}
<tr class="documents-table--row-heading">
<td></td>
<td>{{heading}}</td>
</tr>
{{/if}}
{{> documentsRow}}
<tr class="hidden pageRow">
<td class="page documents-row--controls"></td>
<td><hr /></td>
</tr>
{{/each}}
</tbody>
</table>
{{else}}
<div class="no-results">
No documents matching your search could be found.
</div>
{{/if}}
{{else}}
{{#if isReady }}
{{> documentsHelp}}
{{/if}}
{{/if}}
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment