From 1d8285fb6abef3afb9fa45a3c66ea5656b64bd90 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Mon, 17 Apr 2017 22:44:04 -0400 Subject: [PATCH] Work on All Pages section --- .vscode/launch.json | 28 +++++++++++++ client/js/pages/all.js | 32 ++++++++++++++- controllers/pages.js | 12 +----- controllers/ws.js | 13 ++++++ fuse.js | 9 ++++- libs/entries.js | 7 ++-- models/entry.js | 15 +++---- views/pages/all.pug | 89 +++--------------------------------------- wiki.js | 43 +++++++++++--------- 9 files changed, 122 insertions(+), 126 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..b9ef82e5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to learn about possible Node.js debug attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "attach", + "name": "Attach (Inspector Protocol)", + "port": 9229, + "protocol": "inspector" + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceRoot}\\server.js" + }, + { + "type": "node", + "request": "attach", + "name": "Attach to Port", + "address": "localhost", + "port": 9222 + } + ] +} diff --git a/client/js/pages/all.js b/client/js/pages/all.js index 4bf4587d..2f0dd344 100644 --- a/client/js/pages/all.js +++ b/client/js/pages/all.js @@ -1,9 +1,39 @@ 'use strict' import $ from 'jquery' +import Vue from 'vue' +import _ from 'lodash' module.exports = (alerts, socket) => { if ($('#page-type-all').length) { - + let vueAllPages = new Vue({ // eslint-disable-line no-unused-vars + el: '#page-type-all', + data: { + tree: [] + }, + methods: { + fetch: function (basePath) { + let self = this + $('#notifload').addClass('active') + Vue.nextTick(() => { + socket.emit('treeFetch', { basePath }, (data) => { + if (self.tree.length > 0) { + let curTree = _.last(self.tree) + curTree.hasChildren = true + _.find(curTree.pages, { _id: basePath }).isActive = true + } + self.tree.push({ + hasChildren: false, + pages: data + }) + $('#notifload').removeClass('active') + }) + }) + } + }, + mounted: function () { + this.fetch('') + } + }) } } diff --git a/controllers/pages.js b/controllers/pages.js index 39f6de59..986030a6 100644 --- a/controllers/pages.js +++ b/controllers/pages.js @@ -135,18 +135,10 @@ router.put('/create/*', (req, res, next) => { // ========================================== /** - * View list view of all pages + * View tree view of all pages */ router.get('/all', (req, res, next) => { - entries.getFromTree('/').then((pageData) => { - res.render('pages/all', { pageData }) - return true - }).catch((err) => { - res.render('error', { - message: err.message, - error: {} - }) - }) + res.render('pages/all') }) // ========================================== diff --git a/controllers/ws.js b/controllers/ws.js index 7ce016fc..a5894019 100644 --- a/controllers/ws.js +++ b/controllers/ws.js @@ -18,6 +18,19 @@ module.exports = (socket) => { }) } + // ----------------------------------------- + // TREE VIEW (LIST ALL PAGES) + // ----------------------------------------- + + if (socket.request.user.logged_in) { + socket.on('treeFetch', (data, cb) => { + cb = cb || _.noop + entries.getFromTree(data.basePath).then((f) => { + return cb(f) || true + }) + }) + } + // ----------------------------------------- // UPLOADS // ----------------------------------------- diff --git a/fuse.js b/fuse.js index 70c3e87b..798e2098 100644 --- a/fuse.js +++ b/fuse.js @@ -30,6 +30,12 @@ const args = require('yargs') describe: 'Start in Configure Developer mode', type: 'boolean' }) + .option('i', { + alias: 'inspect', + describe: 'Enable Inspector for debugging', + type: 'boolean', + implies: 'd' + }) .help('h') .alias('h', 'help') .argv @@ -204,8 +210,7 @@ globalTasks.then(() => { _.delay(() => { nodemon({ - script: './server.js', - args: [], + exec: (args.i) ? 'node --inspect server' : 'node server', ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'], ext: 'js json', watch: [ diff --git a/libs/entries.js b/libs/entries.js index 8a409224..25cf6b18 100644 --- a/libs/entries.js +++ b/libs/entries.js @@ -272,7 +272,7 @@ module.exports = { }, /** - * Update local cache and search index + * Update local cache * * @param {String} entryPath The entry path * @return {Promise} Promise of the operation @@ -301,13 +301,14 @@ module.exports = { winston.error(err) return err }).then((content) => { + // let entryPaths = _.split(content.entryPath, '/') return db.Entry.findOneAndUpdate({ _id: content.entryPath }, { _id: content.entryPath, title: content.meta.title || content.entryPath, subtitle: content.meta.subtitle || '', - parent: content.parent.title || '', + parentTitle: content.parent.title || '', parentPath: content.parent.path || '' }, { new: true, @@ -416,6 +417,6 @@ module.exports = { * @return {Promise} List of entries */ getFromTree (basePath) { - return Promise.resolve([]) + return db.Entry.find({ parentPath: basePath }) } } diff --git a/models/entry.js b/models/entry.js index cbdc3048..80edcab2 100644 --- a/models/entry.js +++ b/models/entry.js @@ -6,7 +6,6 @@ * @type {} */ var entrySchema = Mongoose.Schema({ - _id: String, title: { @@ -18,18 +17,20 @@ var entrySchema = Mongoose.Schema({ type: String, default: '' }, - parent: { + parentTitle: { type: String, default: '' }, parentPath: { type: String, default: '' + }, + isDirectory: { + type: Boolean, + default: false } - -}, - { - timestamps: {} - }) +}, { + timestamps: {} +}) module.exports = Mongoose.model('Entry', entrySchema) diff --git a/views/pages/all.pug b/views/pages/all.pug index 1ef0bc23..543b8efa 100644 --- a/views/pages/all.pug +++ b/views/pages/all.pug @@ -26,87 +26,8 @@ block content a(href='/login') i.icon-unlock span Login - ul.collapsable-nav.has-children - li: a - i.icon-file - span Page 1 - li: a - i.icon-file - span Page 2 - li: a - i.icon-file - span Page 3 - li.is-active: a - i.icon-folder2 - span Page 4 - li: a - i.icon-file - span Page 5 - ul.collapsable-nav.has-children - li.is-title page-4 - li: a - i.icon-file - span Page 1 - li.is-active: a - i.icon-file - span Page 2 - li: a - i.icon-file - span Page 3 - li: a - i.icon-file - span Page 4 - li: a - i.icon-file - span Page 5 - ul.collapsable-nav.has-children - li.is-title page-4 - li: a - i.icon-file - span Page 1 - li.is-active: a - i.icon-file - span Page 2 - li: a - i.icon-file - span Page 3 - li: a - i.icon-file - span Page 4 - li: a - i.icon-file - span Page 5 - ul.collapsable-nav.has-children - li.is-title page-4 - li: a - i.icon-file - span Page 1 - li.is-active: a - i.icon-file - span Page 2 - li: a - i.icon-file - span Page 3 - li: a - i.icon-file - span Page 4 - li: a - i.icon-file - span Page 5 - ul.collapsable-nav - li.is-title Sub-Pages - li: a - i.icon-file - span Page 1 - li: a - i.icon-file - span Page 2 - li: a - i.icon-file - span Page 3 - li: a - i.icon-file - span Page 4 - li: a - i.icon-file - span Page 5 + 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 }} diff --git a/wiki.js b/wiki.js index 4e63f8b5..b128d48f 100644 --- a/wiki.js +++ b/wiki.js @@ -21,27 +21,32 @@ cmdr.version(packageObj.version) cmdr.command('start') .description('Start Wiki.js process') .action(() => { - let spinner = ora('Initializing...').start() - fs.emptyDirAsync(path.join(__dirname, './logs')).then(() => { - return pm2.connectAsync().then(() => { - return pm2.startAsync({ - name: 'wiki', - script: 'server.js', - cwd: __dirname, - output: path.join(__dirname, './logs/wiki-output.log'), - error: path.join(__dirname, './logs/wiki-error.log'), - minUptime: 5000, - maxRestarts: 5 - }).then(() => { - spinner.succeed('Wiki.js has started successfully.') - }).finally(() => { - pm2.disconnect() + if (process.env.HEROKU) { + console.info('Initializing Wiki.js for Heroku...') + // todo + } else { + let spinner = ora('Initializing...').start() + fs.emptyDirAsync(path.join(__dirname, './logs')).then(() => { + return pm2.connectAsync().then(() => { + return pm2.startAsync({ + name: 'wiki', + script: 'server.js', + cwd: __dirname, + output: path.join(__dirname, './logs/wiki-output.log'), + error: path.join(__dirname, './logs/wiki-error.log'), + minUptime: 5000, + maxRestarts: 5 + }).then(() => { + spinner.succeed('Wiki.js has started successfully.') + }).finally(() => { + pm2.disconnect() + }) }) + }).catch(err => { + spinner.fail(err) + process.exit(1) }) - }).catch(err => { - spinner.fail(err) - process.exit(1) - }) + } }) cmdr.command('stop')