Переглянути джерело

Populated the Collection nav on Essay page

Markus Ochel 13 роки тому
батько
коміт
71ccc7314a

+ 1 - 1
admin/controllers/index.coffee

@@ -58,7 +58,7 @@ class App extends Spine.Controller
 
     @append @mainNav, @mainStack, @helpUI
 
-    Spine.Route.setup(history: true)
+    Spine.Route.setup()
 
     @doOtherStuff()
 

+ 1 - 1
admin/controllers/ui/multi-select.coffee

@@ -48,7 +48,7 @@ class MultiSelectUI extends Spine.Controller
       # add the created option to the list
       @el.append $option
 
-    setTimeout(@scrollToSelected, 2000) if @jumpToFirst
+    setTimeout(@scrollToSelected, 1000) if @jumpToFirst
     @
 
   selected: =>

+ 1 - 1
admin/templates/help.html

@@ -67,7 +67,7 @@
     <tr>
       <td><a href="http://daringfireball.net/projects/markdown/dingus" target="_blank">Online reference</a></td>
       <td></td>
-      <td>Use this site to practice writing Markdwon style.</td>
+      <td>Use this site to practice writing Markdown styles.</td>
     </tr>
   </tbody>
 </table>

+ 15 - 4
site/lib/app.coffee

@@ -54,10 +54,21 @@ exports.initialize = (config) ->
 
   # Setup the Collection menu
   if $collectionNav
-    $collectionNavId = $collectionNav.attr('data-id')
-    if $collectionNavId
-      for c in [1...5]
-        $collectionNavList.append "<li><a href=\"#\">Essay Number #{c}</a></li>"
+    collectionId = $collectionNav.attr('data-id')
+    collectionSlug = $collectionNav.attr('data-slug')
+    if collectionSlug
+      $.ajax
+        type: 'GET'
+        url: "/json/collection/#{collectionSlug}"
+        contentType: 'json'
+        success: (data) ->
+          if data
+            data = JSON.parse(data)
+            for row in data.rows
+              doc = row.doc
+              url = "/#{doc.type}/#{doc.slug}"
+              selectedClass = if window.location.pathname is url then 'active' else ''
+              $collectionNavList.append "<li><a href=\"#{url}\" class=\"#{selectedClass}\">#{doc.title}</a></li>"
 
     $collectionNavIcon.on 'click', (e) ->
       e.stopPropagation()

+ 1 - 0
site/server/lists.coffee

@@ -218,6 +218,7 @@ exports.essay = (head, req) ->
       content: templates.render 'essay.html', req,
         essay: essay
         collections: collections
+        collection: collections?[0] # primary one
         author: author
         sponsor: sponsor
         blocks: blocks

+ 13 - 0
site/server/rewrites.coffee

@@ -47,6 +47,19 @@ module.exports = [
     }
   }
 
+# Collection's JSON view - list of essays ONLY
+  # `:slug` is the collection's slug
+  {
+    from: '/render/:site/json/collection/:slug',
+    to: '_view/essays_by_collection',
+    query: {
+      startkey: [':site', ':slug', 'essay', {}],
+      endkey: [':site', ':slug', 'essay'],
+      descending: 'true',
+      include_docs: 'true'
+    }
+  }
+
   # Essay's content page
   # `:slug` is the essay's slug
   {

+ 14 - 14
site/server/views.coffee

@@ -6,12 +6,12 @@ exports.docs_for_home =
     if doc.site and doc.type is 'collection' and doc.updated_at
       pinned = if doc.pinned then 1 else 0
       timestamp = new Date(doc.updated_at).getTime()
-      emit [doc.site, pinned, timestamp], doc
+      emit [doc.site, 'collection', pinned, timestamp], doc
     else if doc.type is 'block' and doc.code in ['site_intro','site_promo']
-      emit [doc.site], doc
+      emit [doc.site, 'block'], doc
     else if doc.type is 'site'
       # Also add the site doc
-      emit [doc._id], doc
+      emit [doc._id, 'site'], doc
 
 
 exports.essays_by_collection =
@@ -19,17 +19,17 @@ exports.essays_by_collection =
     if doc.site and doc.type is 'essay' and doc.collections and doc.updated_at and doc.published
       timestamp = new Date(doc.updated_at).getTime()
       for c, i in doc.collections
-        emit [doc.site, c.slug, timestamp], null
+        emit [doc.site, c.slug, 'essay', timestamp], null
     else if doc.site and doc.type is 'collection'
-      emit [doc.site, doc.slug, {}], null
+      emit [doc.site, doc.slug, 'collection', {}], null
       # Also add the collection's sponsor doc
-      emit [doc.site, doc.slug, {}], { _id: doc.sponsor_id } if doc.sponsor_id
+      emit [doc.site, doc.slug, 'sponsor', {}], { _id: doc.sponsor_id } if doc.sponsor_id
       # Also add the collection's associated blocks
       if doc.blocks
         for block_id, i in doc.blocks
-          emit [doc.site, doc.slug, {}], { _id: block_id }
+          emit [doc.site, doc.slug, 'block', {}], { _id: block_id }
       # Also add the site doc
-      emit [doc.site, doc.slug, {}], { _id: doc.site }
+      emit [doc.site, doc.slug, 'site', {}], { _id: doc.site }
 
 
 exports.essays_by_date =
@@ -50,17 +50,17 @@ exports.essays_by_slug =
   map: (doc) ->
     # Essay key by slug followed with it's collection references
     if doc.site and doc.type is 'essay' and doc.slug
-      emit [doc.site, doc.slug, 0], null
+      emit [doc.site, doc.slug, 'essay', 0], null
       for c, i in doc.collections
         # To get each collection's doc
-        emit [doc.site, doc.slug, i+1], {_id: c.id}
+        emit [doc.site, doc.slug, 'collection', i+1], {_id: c.id}
       # Also add the essay's author doc
-      emit [doc.site, doc.slug, {}], { _id: doc.author_id } if doc.author_id
+      emit [doc.site, doc.slug, 'author', {}], { _id: doc.author_id } if doc.author_id
       # Also add the essay's sponsor doc
-      emit [doc.site, doc.slug, {}], { _id: doc.sponsor_id } if doc.sponsor_id
+      emit [doc.site, doc.slug, 'sponsor', {}], { _id: doc.sponsor_id } if doc.sponsor_id
       # Also add the essay's associated blocks
       if doc.blocks
         for block_id, i in doc.blocks
-          emit [doc.site, doc.slug, {}], { _id: block_id }
+          emit [doc.site, doc.slug, 'block', {}], { _id: block_id }
       # Also add the site doc
-      emit [doc.site, doc.slug, {}], { _id: doc.site }
+      emit [doc.site, doc.slug, 'site', {}], { _id: doc.site }

+ 2 - 2
site/templates/essay.html

@@ -88,12 +88,12 @@
   </ul>
 </nav>
 
-<nav class="collection-nav" data-id="{{collections.[0]._id}}">
+<nav class="collection-nav" data-id="{{collection._id}}" data-slug="{{collection.slug}}">
   <div class="icon"><div>Collection</div><i></i></div>
   <ul>
     <li class="heading">
       <small>5 Essays in Collection:</small><br>
-      {{collections.[0].name}}
+      {{collection.name}}
     </li>
   </ul>
 </nav>