From 0d3e10eddaa1d4d7c0a8e4d32cd5f3e44474a1ab Mon Sep 17 00:00:00 2001 From: NGPixel Date: Sun, 23 Apr 2017 15:54:35 -0400 Subject: [PATCH] feat: All Pages directory handling --- client/js/pages/all.js | 5 +++++ libs/entries.js | 15 +++++++++++++-- views/pages/all.pug | 10 +++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/client/js/pages/all.js b/client/js/pages/all.js index 88e13997..4819f5c2 100644 --- a/client/js/pages/all.js +++ b/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 () { diff --git a/libs/entries.js b/libs/entries.js index 25cf6b18..daf23229 100644 --- a/libs/entries.js +++ b/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 diff --git a/views/pages/all.pug b/views/pages/all.pug index 543b8efa..220ef911 100644 --- a/views/pages/all.pug +++ b/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