Pārlūkot izejas kodu

feat: All Pages directory handling

NGPixel 8 gadi atpakaļ
vecāks
revīzija
0d3e10edda
3 mainītis faili ar 25 papildinājumiem un 5 dzēšanām
  1. 5 0
      client/js/pages/all.js
  2. 13 2
      libs/entries.js
  3. 7 3
      views/pages/all.pug

+ 5 - 0
client/js/pages/all.js

@@ -4,6 +4,8 @@ import $ from 'jquery'
 import Vue from 'vue'
 import _ from 'lodash'
 
+const rootUrl = '/'
+
 module.exports = (alerts, socket) => {
   if ($('#page-type-all').length) {
     let vueAllPages = new Vue({ // eslint-disable-line no-unused-vars
@@ -29,6 +31,9 @@ module.exports = (alerts, socket) => {
               $('#notifload').removeClass('active')
             })
           })
+        },
+        goto: function (entryPath) {
+          window.location.assign(rootUrl + entryPath)
         }
       },
       mounted: function () {

+ 13 - 2
libs/entries.js

@@ -301,7 +301,7 @@ module.exports = {
       winston.error(err)
       return err
     }).then((content) => {
-      // let entryPaths = _.split(content.entryPath, '/')
+      let parentPath = _.chain(content.entryPath).split('/').initial().join('/').value()
       return db.Entry.findOneAndUpdate({
         _id: content.entryPath
       }, {
@@ -309,11 +309,22 @@ module.exports = {
         title: content.meta.title || content.entryPath,
         subtitle: content.meta.subtitle || '',
         parentTitle: content.parent.title || '',
-        parentPath: content.parent.path || ''
+        parentPath: parentPath,
+        isDirectory: false
       }, {
         new: true,
         upsert: true
       })
+    }).then(result => {
+      return db.Entry.distinct('parentPath', { parentPath: { $ne: '' } }).then(allPaths => {
+        if (allPaths.length > 0) {
+          return db.Entry.updateMany({ _id: { $in: allPaths } }, { $set: { isDirectory: true } }).then(() => {
+            return result
+          })
+        } else {
+          return result
+        }
+      })
     }).catch(err => {
       winston.error(err)
       return err

+ 7 - 3
views/pages/all.pug

@@ -28,6 +28,10 @@ block content
                   span Login
       ul.collapsable-nav(v-for='treeItem in tree', :class='{ "has-children": treeItem.hasChildren }', v-cloak)
         li(v-for='page in treeItem.pages', :class='{ "is-active": page.isActive }')
-          a(v-on:click='fetch(page._id)')
-            i(:class='{ "icon-folder2": page.isFolder, "icon-file": !page.isFolder }')
-            span {{ page.title }}
+          a(v-on:click='(page.isDirectory) ? fetch(page._id) : goto(page._id)')
+            template(v-if='page._id !== "home"')
+              i(:class='{ "icon-folder2": page.isDirectory, "icon-file-text-o": !page.isDirectory }')
+              span {{ page.title }}
+            template(v-else)
+              i.icon-home
+              span Home