sets page menu status to false when corresponding menu item is removed from menu

This commit is contained in:
Ro 2020-06-27 16:21:42 -07:00
parent 75b4cb9ac2
commit 0fa1bebc8a
6 changed files with 21 additions and 8 deletions

View file

@ -66,6 +66,13 @@ router.post('/sync', (req, res) => {
router.post('/nav-sync', (req, res) => { router.post('/nav-sync', (req, res) => {
auth.authCheck(req) auth.authCheck(req)
.then(() => { .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) nav.sync(req.body)
.then(response => { .then(response => {
res.json({ res.json({
@ -187,8 +194,8 @@ router.post('/add-feature-background', background_upload, (req, res) => {
url: '/' + image url: '/' + image
}); });
}) })
.catch(err => { .catch(() => {
console.log('ERROR', err); //console.log('ERROR', err);
}); });
} else { } else {
res.json({ res.json({

View file

@ -49,6 +49,9 @@ export default class Book {
} else { } else {
setTimeout(() => { setTimeout(() => {
//TODO: Duct tape solution until something better created //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 => { let page = _.find(pages, list => {
return list.metadata.uuid === id; return list.metadata.uuid === id;
}); });
@ -89,9 +92,9 @@ export default class Book {
moment(body.created).format('YYYY') + moment(body.created).format('YYYY') +
'/' + '/' +
moment(body.created).format('MM'); moment(body.created).format('MM');
nav.editMenu(DataEvent.MENU_ADD_ITEM, body); nav.editMenu(DataEvent.MENU_ADD_ITEM, body, user);
} else { } 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 !== 'page') layout = body.layout;
if (body.layout === null || body.layout === 'null') layout = 'page'; if (body.layout === null || body.layout === 'null') layout = 'page';

View file

@ -19,7 +19,7 @@ export default class Navigation {
.load(SETTINGS_FILE) .load(SETTINGS_FILE)
.then(settings => { .then(settings => {
let payload = body; let payload = body;
settings.menu = payload; settings.menu = payload.nav;
fs.writeJson('site/settings.json', settings) fs.writeJson('site/settings.json', settings)
.then(() => { .then(() => {
response = { response = {

View file

@ -12,5 +12,5 @@ block main-content
= menu[index].title = menu[index].title
#nav-btns #nav-btns
button.nav-btn#edit-item(data-id=menu[index].uuid) EDIT 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

View file

@ -18,8 +18,10 @@ export default class NavActions {
path: items[index].getAttribute('data-path') path: items[index].getAttribute('data-path')
}); });
} }
let data = { nav: navData, remove: null };
return new Promise(function (resolve) { return new Promise(function (resolve) {
resolve(navData); resolve(data);
}); });
} }

View file

@ -43,6 +43,7 @@ export default class NavIndex {
id = e.target.getAttribute('data-id'); id = e.target.getAttribute('data-id');
new NavActions().removeItem(id); new NavActions().removeItem(id);
new NavActions().syncMenu().then(data => { new NavActions().syncMenu().then(data => {
data.remove = e.target.getAttribute('data-uuid');
api.syncNav(data).then(r => { api.syncNav(data).then(r => {
if (r.type == DataEvent.MENU_UPDATED) { if (r.type == DataEvent.MENU_UPDATED) {
notify.alert(r.message, true); notify.alert(r.message, true);
@ -53,7 +54,7 @@ export default class NavIndex {
}); });
break; break;
case 'edit-item': case 'edit-item':
window.location = '/@/dashboard/pages/edit/' + e.target.getAttribute('data-id'); window.location = '/@/dashboard/page/edit/' + e.target.getAttribute('data-id');
break; break;
} }
} }