forked from projects/fipamo
added Navigation data class, menu updates on page soft delete
This commit is contained in:
parent
7b6af21c77
commit
ea1795e0fa
9 changed files with 83 additions and 31 deletions
|
@ -1,4 +1,5 @@
|
|||
import Book from '../../data/Book';
|
||||
import Navigation from '../../data/Navigation';
|
||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
@ -8,6 +9,7 @@ const moment = require('moment');
|
|||
const jwt = require('jsonwebtoken');
|
||||
const bCrypt = require('bcrypt-nodejs');
|
||||
const book = new Book();
|
||||
const nav = new Navigation();
|
||||
const _ = require('lodash');
|
||||
const uploadPath =
|
||||
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
||||
|
@ -68,13 +70,7 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
|||
book.editPage(body, body.page_uuid, task, req.session.user)
|
||||
.then(result => {
|
||||
if (result.type === DataEvent.PAGE_CREATE) {
|
||||
fs.readJSON('site/settings.json').then(settings => {
|
||||
settings.library_stats.current_index = ++settings.library_stats
|
||||
.current_index;
|
||||
settings.library_stats.total_pages = ++settings.library_stats
|
||||
.total_pages;
|
||||
fs.writeJSON('site/settings.json', settings);
|
||||
});
|
||||
nav.updatePageStats();
|
||||
}
|
||||
res.json(result);
|
||||
})
|
||||
|
@ -98,6 +94,7 @@ router.post('/delete', (req, res) => {
|
|||
.then(() => {
|
||||
book.editPage([], req.body.id, DataEvent.API_PAGE_DELETE, req.session.user)
|
||||
.then(result => {
|
||||
//remove item from menu in settings
|
||||
res.json(result);
|
||||
})
|
||||
.catch(err => {
|
||||
|
@ -126,10 +123,21 @@ router.post('/add-post-image', post_upload, function(req, res) {
|
|||
|
||||
module.exports = router;
|
||||
|
||||
/**
|
||||
* Checks to make sure received token matches
|
||||
* @parameter token: created token
|
||||
* @parameter hashedToken: encrypted token
|
||||
*/
|
||||
|
||||
function isTokenValid(token, hashedToken) {
|
||||
return bCrypt.compareSync(token, hashedToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure access token is legit
|
||||
* @parameter req
|
||||
*/
|
||||
|
||||
function authCheck(req) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let hash = req.headers['x-access-token'];
|
||||
|
|
|
@ -3,6 +3,8 @@ import fs from 'fs-extra';
|
|||
import metadataParser from 'markdown-yaml-metadata-parser';
|
||||
import _ from 'lodash';
|
||||
import * as DataEvent from '../../src/com/events/DataEvent';
|
||||
import Navigation from './Navigation';
|
||||
const nav = new Navigation();
|
||||
const moment = require('moment');
|
||||
|
||||
export default class Pages {
|
||||
|
@ -130,7 +132,7 @@ export default class Pages {
|
|||
} else {
|
||||
response = {
|
||||
type: DataEvent.PAGE_UPDATED,
|
||||
message: 'Page saved, boss'
|
||||
message: 'Page saved. Nice Work'
|
||||
};
|
||||
resolve(response);
|
||||
}
|
||||
|
@ -144,9 +146,17 @@ export default class Pages {
|
|||
body.deleted = moment(Date.now()).format();
|
||||
self.editPage(body, body.uuid, DataEvent.API_PAGE_WRITE, user)
|
||||
.then(() => {
|
||||
let item = {
|
||||
title: body.title,
|
||||
id: body.id,
|
||||
slug: body.slug,
|
||||
uuid: body.uuid
|
||||
};
|
||||
nav.editMenu(DataEvent.MENU_DELETE_ITEM, item);
|
||||
response = {
|
||||
type: DataEvent.PAGE_DELETED,
|
||||
message: 'Page deleted, sport'
|
||||
message: 'Page deleted, sport',
|
||||
data: { uuid: body.uuid }
|
||||
};
|
||||
resolve(response);
|
||||
})
|
||||
|
|
44
brain/data/Navigation.js
Normal file
44
brain/data/Navigation.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
//import fh from 'filehound';
|
||||
import fs from 'fs-extra';
|
||||
//import metadataParser from 'markdown-yaml-metadata-parser';
|
||||
import _ from 'lodash';
|
||||
import * as DataEvent from '../../src/com/events/DataEvent';
|
||||
//const moment = require('moment');
|
||||
|
||||
export default class Navigation {
|
||||
//--------------------------
|
||||
// constructor
|
||||
//--------------------------
|
||||
constructor() {}
|
||||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
start() {}
|
||||
|
||||
editMenu(task, item) {
|
||||
switch (task) {
|
||||
case DataEvent.MENU_ADD_ITEM:
|
||||
break;
|
||||
case DataEvent.MENU_DELETE_ITEM:
|
||||
fs.readJSON('site/settings.json').then(settings => {
|
||||
settings.menu = _.remove(settings.menu, m => {
|
||||
return m.uuid != item.uuid;
|
||||
});
|
||||
fs.writeJSON('site/settings.json', settings);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
updatePageStats() {
|
||||
fs.readJSON('site/settings.json').then(settings => {
|
||||
settings.library_stats.current_index = ++settings.library_stats.current_index;
|
||||
settings.library_stats.total_pages = ++settings.library_stats.total_pages;
|
||||
fs.writeJSON('site/settings.json', settings);
|
||||
});
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
// event handlers
|
||||
//--------------------------
|
||||
}
|
|
@ -10,11 +10,17 @@ router.get('/', function(req, res) {
|
|||
let book = new Book();
|
||||
book.getPage().then(result => {
|
||||
result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id));
|
||||
let indexPages = [];
|
||||
result.forEach(page => {
|
||||
if (typeof page.metadata.deleted === 'undefined' || page.metadata.deleted === false) {
|
||||
indexPages.push(page);
|
||||
}
|
||||
});
|
||||
let pageData = [];
|
||||
if (req.session.user) {
|
||||
pageData = { title: settings.global.title, status: true, pages: result };
|
||||
pageData = { title: settings.global.title, status: true, pages: indexPages };
|
||||
} else {
|
||||
pageData = { title: settings.global.title, status: false, pages: result };
|
||||
pageData = { title: settings.global.title, status: false, pages: indexPages };
|
||||
}
|
||||
|
||||
res.render('index', pageData);
|
||||
|
|
|
@ -27,10 +27,7 @@ router.get('/list/:filter?/:page?', function(req, res) {
|
|||
let featured = [];
|
||||
for (let index = 0; index < pages.length; index++) {
|
||||
let item = pages[index].metadata;
|
||||
if (
|
||||
typeof item.deleted === 'undefined' ||
|
||||
(item.deleted === false && item.layout === 'page')
|
||||
) {
|
||||
if (typeof item.deleted === 'undefined' || item.deleted === false) {
|
||||
all.push(pages[index].metadata);
|
||||
if (item.published == true) published.push(pages[index].metadata);
|
||||
if (item.menu == true) menu.push(pages[index].metadata);
|
||||
|
|
|
@ -36,18 +36,6 @@ export default class NavActions {
|
|||
});
|
||||
});
|
||||
}
|
||||
removeItem(id) {
|
||||
/**
|
||||
let self = this;
|
||||
this.dbutils.getPost(id).then(post => {
|
||||
post.post.page = 'false';
|
||||
self.dbutils.modify(id, post.post).then(() => {
|
||||
document.getElementById('nav-pages').removeChild(document.getElementById(id));
|
||||
self.save();
|
||||
});
|
||||
});
|
||||
*/
|
||||
}
|
||||
//--------------------------
|
||||
// event handlers
|
||||
//--------------------------
|
||||
|
|
|
@ -66,9 +66,7 @@ export default class PostActions {
|
|||
resolve(pageInfo);
|
||||
});
|
||||
}
|
||||
deletePost(id, body) {
|
||||
let self = this;
|
||||
}
|
||||
|
||||
updateNav(add, id, post) {
|
||||
api.request('/api/settings/nav', DataEvent.SETTINGS_LOADED)
|
||||
.then(response => {
|
||||
|
|
|
@ -171,7 +171,6 @@ export default class PostEditor {
|
|||
id
|
||||
)
|
||||
.then(() => {
|
||||
console.log('DELETED');
|
||||
window.location = '/@/dashboard/page/list/';
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
|
@ -12,6 +12,8 @@ export const PAGE_ADDED = 'postAdded';
|
|||
export const PAGE_UPDATED = 'postUpdated';
|
||||
export const PAGE_DELETED = 'postImageAdded';
|
||||
export const SETTINGS_UPDATED = 'settingsUpdated';
|
||||
export const MENU_ADD_ITEM = 'menuAddItem';
|
||||
export const MENU_DELETE_ITEM = 'menuDeleteItem';
|
||||
export const MENU_UPDATED = 'menuUpdated';
|
||||
export const AVATAR_UPLOADED = 'avatarUploaded';
|
||||
export const SITE_BACKGROUND_UPLOADED = 'siteBackgroundUploaded';
|
||||
|
|
Loading…
Reference in a new issue