forked from projects/fipamo
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/
|
node_modules/
|
||||||
.sass-cache/
|
.sass-cache/
|
||||||
.cache/
|
.cache/
|
||||||
|
.nova/
|
||||||
public/*
|
public/*
|
||||||
|
public/assets/images/*
|
||||||
!public/assets/images/global
|
!public/assets/images/global
|
||||||
content/
|
content/
|
||||||
.ftpconfig
|
.ftpconfig
|
||||||
|
@ -19,4 +21,3 @@ brain/models/_backup/
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
/forfipamo
|
/forfipamo
|
||||||
site-settings.json
|
site-settings.json
|
||||||
.nova/
|
|
|
@ -66,7 +66,7 @@ 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(() => {
|
||||||
nav.sync(req)
|
nav.sync(req.body)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
res.json({
|
res.json({
|
||||||
type: response.type,
|
type: response.type,
|
||||||
|
|
|
@ -84,6 +84,15 @@ export default class Book {
|
||||||
moment(body.created).format('MM') +
|
moment(body.created).format('MM') +
|
||||||
'/'
|
'/'
|
||||||
).then(() => {
|
).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 !== 'page') layout = body.layout;
|
||||||
if (body.layout === null || body.layout === 'null') layout = 'page';
|
if (body.layout === null || body.layout === 'null') layout = 'page';
|
||||||
var pageWrite =
|
var pageWrite =
|
||||||
|
@ -181,6 +190,7 @@ export default class Book {
|
||||||
let body = _.mapValues(page.metadata);
|
let body = _.mapValues(page.metadata);
|
||||||
body.content = page.content;
|
body.content = page.content;
|
||||||
body.deleted = moment(Date.now()).format();
|
body.deleted = moment(Date.now()).format();
|
||||||
|
body.menu = false;
|
||||||
self.editPage(body, body.uuid, DataEvent.API_PAGE_WRITE, user)
|
self.editPage(body, body.uuid, DataEvent.API_PAGE_WRITE, user)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
let item = {
|
let item = {
|
||||||
|
@ -190,6 +200,7 @@ export default class Book {
|
||||||
uuid: body.uuid
|
uuid: body.uuid
|
||||||
};
|
};
|
||||||
nav.editMenu(DataEvent.MENU_DELETE_ITEM, item);
|
nav.editMenu(DataEvent.MENU_DELETE_ITEM, item);
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
type: DataEvent.PAGE_DELETED,
|
type: DataEvent.PAGE_DELETED,
|
||||||
message: 'Page deleted, sport',
|
message: 'Page deleted, sport',
|
||||||
|
|
|
@ -3,7 +3,6 @@ import _ from 'lodash';
|
||||||
import * as DataEvent from '../../src/com/events/DataEvent';
|
import * as DataEvent from '../../src/com/events/DataEvent';
|
||||||
import Settings, { SETTINGS_FILE } from './Settings';
|
import Settings, { SETTINGS_FILE } from './Settings';
|
||||||
const settings = new Settings();
|
const settings = new Settings();
|
||||||
//const settings = require('../../site/settings.json');
|
|
||||||
|
|
||||||
export default class Navigation {
|
export default class Navigation {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
@ -13,9 +12,9 @@ export default class Navigation {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
//--------------------------
|
//--------------------------
|
||||||
sync(req) {
|
sync(body) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let payload = req.body;
|
let payload = body;
|
||||||
settings.menu = payload;
|
settings.menu = payload;
|
||||||
let response = [];
|
let response = [];
|
||||||
fs.writeJson('site/settings.json', settings)
|
fs.writeJson('site/settings.json', settings)
|
||||||
|
@ -37,18 +36,26 @@ export default class Navigation {
|
||||||
}
|
}
|
||||||
|
|
||||||
editMenu(task, item) {
|
editMenu(task, item) {
|
||||||
switch (task) {
|
settings.load(SETTINGS_FILE).then(settings => {
|
||||||
case DataEvent.MENU_ADD_ITEM:
|
switch (task) {
|
||||||
break;
|
case DataEvent.MENU_ADD_ITEM:
|
||||||
case DataEvent.MENU_DELETE_ITEM:
|
settings.menu.push({
|
||||||
settings.load(SETTINGS_FILE).then(settings => {
|
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 => {
|
settings.menu = _.remove(settings.menu, m => {
|
||||||
return m.uuid != item.uuid;
|
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,
|
title: item.tag,
|
||||||
default_bg: result.settings.global.background,
|
default_bg: result.settings.global.background,
|
||||||
content_tags: 'THESE ARE TAGS',
|
content_tags: 'THESE ARE TAGS',
|
||||||
tag_list: item.tag_list
|
tag_list: item.tag_list,
|
||||||
|
menu: result.settings.menu
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
fs.ensureDir('public/tags', () => {
|
fs.ensureDir('public/tags', () => {
|
||||||
|
@ -182,7 +183,8 @@ export default class Render {
|
||||||
title: 'ARCHIVES',
|
title: 'ARCHIVES',
|
||||||
default_bg: settings.global.background,
|
default_bg: settings.global.background,
|
||||||
content_tags: 'COLD STORAGE',
|
content_tags: 'COLD STORAGE',
|
||||||
archives: archive
|
archives: archive,
|
||||||
|
menu: settings.menu
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue