From 0fa1bebc8aedbd2fa9e9331921a900e0917f8406 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 27 Jun 2020 16:21:42 -0700 Subject: [PATCH] sets page menu status to false when corresponding menu item is removed from menu --- brain/api/v1/settings.js | 11 +++++++++-- brain/data/Book.js | 7 +++++-- brain/data/Navigation.js | 2 +- brain/views/navigation.pug | 2 +- src/com/actions/NavActions.js | 4 +++- src/com/controllers/NavIndex.js | 3 ++- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/brain/api/v1/settings.js b/brain/api/v1/settings.js index bf0a20d..789f08a 100644 --- a/brain/api/v1/settings.js +++ b/brain/api/v1/settings.js @@ -66,6 +66,13 @@ router.post('/sync', (req, res) => { router.post('/nav-sync', (req, res) => { auth.authCheck(req) .then(() => { + // find removoed menu item page and set menu to false + book.getPage(req.body.remove).then(page => { + let body = page.metadata; + body.content = page.content; + body.menu = false; + book.editPage(body, body.uuid, DataEvent.API_PAGE_WRITE, req.session.user); + }); nav.sync(req.body) .then(response => { res.json({ @@ -187,8 +194,8 @@ router.post('/add-feature-background', background_upload, (req, res) => { url: '/' + image }); }) - .catch(err => { - console.log('ERROR', err); + .catch(() => { + //console.log('ERROR', err); }); } else { res.json({ diff --git a/brain/data/Book.js b/brain/data/Book.js index 0d67bb3..709e342 100644 --- a/brain/data/Book.js +++ b/brain/data/Book.js @@ -49,6 +49,9 @@ export default class Book { } else { setTimeout(() => { //TODO: Duct tape solution until something better created + + //make check against menu to see if page should be marked as menu item + //if it doesnt' exist in menu change, edit page to let page = _.find(pages, list => { return list.metadata.uuid === id; }); @@ -89,9 +92,9 @@ export default class Book { moment(body.created).format('YYYY') + '/' + moment(body.created).format('MM'); - nav.editMenu(DataEvent.MENU_ADD_ITEM, body); + nav.editMenu(DataEvent.MENU_ADD_ITEM, body, user); } else { - nav.editMenu(DataEvent.MENU_DELETE_ITEM, body); + nav.editMenu(DataEvent.MENU_DELETE_ITEM, body, user); } if (body.layout !== 'page') layout = body.layout; if (body.layout === null || body.layout === 'null') layout = 'page'; diff --git a/brain/data/Navigation.js b/brain/data/Navigation.js index 1d1b55c..a30b8d9 100644 --- a/brain/data/Navigation.js +++ b/brain/data/Navigation.js @@ -19,7 +19,7 @@ export default class Navigation { .load(SETTINGS_FILE) .then(settings => { let payload = body; - settings.menu = payload; + settings.menu = payload.nav; fs.writeJson('site/settings.json', settings) .then(() => { response = { diff --git a/brain/views/navigation.pug b/brain/views/navigation.pug index 588510e..b843ad1 100644 --- a/brain/views/navigation.pug +++ b/brain/views/navigation.pug @@ -12,5 +12,5 @@ block main-content = menu[index].title #nav-btns button.nav-btn#edit-item(data-id=menu[index].uuid) EDIT - button.nav-btn#remove-item(data-id=menu[index].id) REMOVE + button.nav-btn#remove-item(data-id=menu[index].id, data-uuid=menu[index].uuid) REMOVE diff --git a/src/com/actions/NavActions.js b/src/com/actions/NavActions.js index c90ab3a..fe64e52 100644 --- a/src/com/actions/NavActions.js +++ b/src/com/actions/NavActions.js @@ -18,8 +18,10 @@ export default class NavActions { path: items[index].getAttribute('data-path') }); } + + let data = { nav: navData, remove: null }; return new Promise(function (resolve) { - resolve(navData); + resolve(data); }); } diff --git a/src/com/controllers/NavIndex.js b/src/com/controllers/NavIndex.js index 284a365..2364562 100644 --- a/src/com/controllers/NavIndex.js +++ b/src/com/controllers/NavIndex.js @@ -43,6 +43,7 @@ export default class NavIndex { id = e.target.getAttribute('data-id'); new NavActions().removeItem(id); new NavActions().syncMenu().then(data => { + data.remove = e.target.getAttribute('data-uuid'); api.syncNav(data).then(r => { if (r.type == DataEvent.MENU_UPDATED) { notify.alert(r.message, true); @@ -53,7 +54,7 @@ export default class NavIndex { }); break; case 'edit-item': - window.location = '/@/dashboard/pages/edit/' + e.target.getAttribute('data-id'); + window.location = '/@/dashboard/page/edit/' + e.target.getAttribute('data-id'); break; } }