navigation updates correctly when pages are pinned to menu, menu items deleted when page is deleted
This commit is contained in:
parent
6ed3797b3a
commit
33f4765a87
5 changed files with 37 additions and 16 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -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/
|
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue