From 33f4765a8765aa02243d4b9c67d89ef6b2b2ceab Mon Sep 17 00:00:00 2001 From: Ro Date: Sun, 21 Jun 2020 19:01:22 -0700 Subject: [PATCH] navigation updates correctly when pages are pinned to menu, menu items deleted when page is deleted --- .gitignore | 3 ++- brain/api/v1/settings.js | 2 +- brain/data/Book.js | 11 +++++++++++ brain/data/Navigation.js | 31 +++++++++++++++++++------------ brain/data/Render.js | 6 ++++-- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index ea2c159..c03c85c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ node_modules/ .sass-cache/ .cache/ +.nova/ public/* +public/assets/images/* !public/assets/images/global content/ .ftpconfig @@ -19,4 +21,3 @@ brain/models/_backup/ *.DS_Store /forfipamo site-settings.json -.nova/ \ No newline at end of file diff --git a/brain/api/v1/settings.js b/brain/api/v1/settings.js index 37aee4a..cfd436f 100644 --- a/brain/api/v1/settings.js +++ b/brain/api/v1/settings.js @@ -66,7 +66,7 @@ router.post('/sync', (req, res) => { router.post('/nav-sync', (req, res) => { auth.authCheck(req) .then(() => { - nav.sync(req) + nav.sync(req.body) .then(response => { res.json({ type: response.type, diff --git a/brain/data/Book.js b/brain/data/Book.js index cd1ab93..4f390b6 100644 --- a/brain/data/Book.js +++ b/brain/data/Book.js @@ -84,6 +84,15 @@ export default class Book { moment(body.created).format('MM') + '/' ).then(() => { + if (body.menu === 'true') { + body.path = + moment(body.created).format('YYYY') + + '/' + + moment(body.created).format('MM'); + nav.editMenu(DataEvent.MENU_ADD_ITEM, body); + } else { + nav.editMenu(DataEvent.MENU_DELETE_ITEM, body); + } if (body.layout !== 'page') layout = body.layout; if (body.layout === null || body.layout === 'null') layout = 'page'; var pageWrite = @@ -181,6 +190,7 @@ export default class Book { let body = _.mapValues(page.metadata); body.content = page.content; body.deleted = moment(Date.now()).format(); + body.menu = false; self.editPage(body, body.uuid, DataEvent.API_PAGE_WRITE, user) .then(() => { let item = { @@ -190,6 +200,7 @@ export default class Book { uuid: body.uuid }; nav.editMenu(DataEvent.MENU_DELETE_ITEM, item); + response = { type: DataEvent.PAGE_DELETED, message: 'Page deleted, sport', diff --git a/brain/data/Navigation.js b/brain/data/Navigation.js index df15b4c..995429d 100644 --- a/brain/data/Navigation.js +++ b/brain/data/Navigation.js @@ -3,7 +3,6 @@ import _ from 'lodash'; import * as DataEvent from '../../src/com/events/DataEvent'; import Settings, { SETTINGS_FILE } from './Settings'; const settings = new Settings(); -//const settings = require('../../site/settings.json'); export default class Navigation { //-------------------------- @@ -13,9 +12,9 @@ export default class Navigation { //-------------------------- // methods //-------------------------- - sync(req) { + sync(body) { return new Promise((resolve, reject) => { - let payload = req.body; + let payload = body; settings.menu = payload; let response = []; fs.writeJson('site/settings.json', settings) @@ -37,18 +36,26 @@ export default class Navigation { } editMenu(task, item) { - switch (task) { - case DataEvent.MENU_ADD_ITEM: - break; - case DataEvent.MENU_DELETE_ITEM: - settings.load(SETTINGS_FILE).then(settings => { + settings.load(SETTINGS_FILE).then(settings => { + switch (task) { + case DataEvent.MENU_ADD_ITEM: + settings.menu.push({ + title: item.title, + id: item.id, + slug: item.slug, + uuid: item.uuid, + path: item.path + }); + break; + case DataEvent.MENU_DELETE_ITEM: settings.menu = _.remove(settings.menu, m => { return m.uuid != item.uuid; }); - fs.writeJSON(SETTINGS_FILE, settings); - }); - break; - } + + break; + } + fs.writeJSON(SETTINGS_FILE, settings); + }); } //-------------------------- diff --git a/brain/data/Render.js b/brain/data/Render.js index d39a882..2529dee 100644 --- a/brain/data/Render.js +++ b/brain/data/Render.js @@ -144,7 +144,8 @@ export default class Render { title: item.tag, default_bg: result.settings.global.background, content_tags: 'THESE ARE TAGS', - tag_list: item.tag_list + tag_list: item.tag_list, + menu: result.settings.menu } ); fs.ensureDir('public/tags', () => { @@ -182,7 +183,8 @@ export default class Render { title: 'ARCHIVES', default_bg: settings.global.background, content_tags: 'COLD STORAGE', - archives: archive + archives: archive, + menu: settings.menu } );