smooted out settings update after new post, activated page listing and sorting
This commit is contained in:
parent
532748f688
commit
477533ceb5
4 changed files with 129 additions and 80 deletions
|
@ -101,6 +101,12 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
|||
|
||||
// success case, the file was saved
|
||||
if (req.params.task === 'new') {
|
||||
// if new file, update settings index and page count
|
||||
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);
|
||||
});
|
||||
res.json({
|
||||
type: DataEvent.PAGE_ADDED,
|
||||
message: 'New Page Created',
|
||||
|
|
|
@ -6,7 +6,7 @@ const hljs_md = require('highlight.js/lib/languages/markdown');
|
|||
const moment = require('moment');
|
||||
const book = new Book();
|
||||
const uuidv4 = require('uuid/v4');
|
||||
const fs = require('fs-extra');
|
||||
const settings = require('../../../site/settings.json');
|
||||
hljs.registerLanguage('markdown', hljs_md);
|
||||
//--------------------------
|
||||
// POSTS
|
||||
|
@ -16,9 +16,68 @@ router.get('/list/:filter?/:page?', function(req, res) {
|
|||
var filter = req.params.filter;
|
||||
if (pageNum == '' || pageNum == null) pageNum = 1;
|
||||
if (filter == '' || filter == null) filter = 'all';
|
||||
/*
|
||||
if (req.session.user) {
|
||||
|
||||
book.getPage()
|
||||
.then(function(pages) {
|
||||
pages.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id));
|
||||
let all = [];
|
||||
let deleted = [];
|
||||
let published = [];
|
||||
let menu = [];
|
||||
let featured = [];
|
||||
for (let index = 0; index < pages.length; index++) {
|
||||
let item = pages[index].metadata;
|
||||
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);
|
||||
if (item.featured == true) featured.push(pages[index].metadata);
|
||||
} else {
|
||||
deleted.push(pages[index].metadata);
|
||||
}
|
||||
}
|
||||
var filtered;
|
||||
switch (filter) {
|
||||
case 'published':
|
||||
filtered = published;
|
||||
break;
|
||||
case 'deleted':
|
||||
filtered = deleted;
|
||||
break;
|
||||
default:
|
||||
filtered = all;
|
||||
break;
|
||||
}
|
||||
var count = Math.round(filtered.length / 6);
|
||||
var pageItems = [];
|
||||
var itemLimit = 6;
|
||||
var rangeStart = pageNum * itemLimit - itemLimit;
|
||||
for (var i = 0; i < itemLimit; i++) {
|
||||
try {
|
||||
if (filtered[i + rangeStart].id != null) {
|
||||
pageItems.push(filtered[i + rangeStart]);
|
||||
}
|
||||
} catch (e) {
|
||||
//console.log("NO POST", e)
|
||||
}
|
||||
}
|
||||
res.render('book-index', {
|
||||
title: 'Dashbord | Book',
|
||||
welcome: 'Your pages',
|
||||
items: pageItems,
|
||||
page_info: {
|
||||
all: all.length,
|
||||
deleted: deleted.length,
|
||||
published: published.length,
|
||||
pages: pages.length,
|
||||
featured: featured.length
|
||||
},
|
||||
page_index: pageNum,
|
||||
page_count: count,
|
||||
postFilter: filter,
|
||||
status: true
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
//console.log(value);
|
||||
})
|
||||
|
@ -28,41 +87,25 @@ router.get('/list/:filter?/:page?', function(req, res) {
|
|||
} else {
|
||||
res.redirect('/@/dashboard');
|
||||
}
|
||||
*/
|
||||
});
|
||||
|
||||
//--------------------------
|
||||
// BLOG POST ADD DISPLAY
|
||||
//--------------------------
|
||||
router.get('/add/new', function(req, res) {
|
||||
if (req.session.user) {
|
||||
fs.readJSON('site/settings.json')
|
||||
.then(settings => {
|
||||
//use current index as id, then updated current index and page count
|
||||
let pageID = settings.library_stats.current_index;
|
||||
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')
|
||||
.then(() => {
|
||||
res.render('page-edit', {
|
||||
id: pageID,
|
||||
uuid: uuidv4(),
|
||||
title: 'Add New Page',
|
||||
user_status: true,
|
||||
welcome: 'Add New Page',
|
||||
date: moment(Date.now()).format('YYYY MMM DD'),
|
||||
page: [],
|
||||
rawDate: Date.now(),
|
||||
status: ['false', 'false', 'false'],
|
||||
edit: false
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.render('error', { error: err });
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.render('error', { error: err });
|
||||
});
|
||||
res.render('page-edit', {
|
||||
id: settings.library_stats.current_index,
|
||||
uuid: uuidv4(),
|
||||
title: 'Add New Page',
|
||||
user_status: true,
|
||||
welcome: 'Add New Page',
|
||||
date: moment(Date.now()).format('YYYY MMM DD'),
|
||||
page: [],
|
||||
rawDate: moment(Date.now()).format(),
|
||||
status: ['false', 'false', 'false'],
|
||||
edit: false
|
||||
});
|
||||
} else {
|
||||
res.redirect('/@/dashboard');
|
||||
}
|
||||
|
|
48
brain/views/book-index.pug
Normal file
48
brain/views/book-index.pug
Normal file
|
@ -0,0 +1,48 @@
|
|||
extends frame
|
||||
block main-content
|
||||
#post-index
|
||||
#post-index-wrapper
|
||||
#post-index-menu
|
||||
- if(postFilter=='all')
|
||||
a.current-filter(href="/@/dashboard/page/list/all")= "All Pages ("+page_info.all+")"
|
||||
- else
|
||||
a(href="/@/dashboard/page/list/all")= "All Pages ("+page_info.all+")"
|
||||
| .
|
||||
- if(postFilter=='published')
|
||||
a.current-filter(href="/@/dashboard/page/list/published")= "Published ("+page_info.published+")"
|
||||
- else
|
||||
a(href="/@/dashboard/page/list/published")= "Published ("+page_info.published+")"
|
||||
| .
|
||||
- if(postFilter=='deleted')
|
||||
a.current-filter(href="/@/dashboard/page/list/deleted")= "Deleted ("+page_info.deleted+")"
|
||||
- else
|
||||
a(href="/@/dashboard/page/list/deleted")= "Deleted ("+page_info.deleted+")"
|
||||
|
||||
a.add-new-post(href="/@/dashboard/page/add/new") +
|
||||
label Create New Post
|
||||
#posts-list
|
||||
- var index = 0;
|
||||
- for ( index; index < items.length; index++)
|
||||
a.post-link(href="/@/dashboard/page/edit/"+items[index].uuid id=items[index].uuid)
|
||||
|
||||
div.post-bg(style="background: #fc6399 url("+items[index].feature+") no-repeat center center / cover")
|
||||
label= items[index].title
|
||||
span= items[index].created
|
||||
//p= items[index].plaintext.substr(0, 200)+"..."
|
||||
|
||||
- var next = parseInt(page_index, 10) + 1
|
||||
- var prev = parseInt(page_index, 10) - 1
|
||||
- if(next > page_count) next = 1
|
||||
- if(prev <= 0) prev = page_count
|
||||
|
||||
br
|
||||
a.page-btns(href="/@/dashboard/page/list/"+postFilter+"/"+prev)
|
||||
svg(viewBox="0 0 20 20" class="icons")
|
||||
use(xlink:href='/assets/images/global/sprite.svg#entypo-chevron-left')
|
||||
|
||||
span.paginate= "PAGE "+page_index+" OF "+page_count
|
||||
|
||||
a.page-btns(href="/@/dashboard/page/list/"+postFilter+"/"+next)
|
||||
svg(viewBox="0 0 20 20" class="icons")
|
||||
use(xlink:href='/assets/images/global/sprite.svg#entypo-chevron-right')
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
extends frame
|
||||
block main-content
|
||||
#post-index
|
||||
#post-index-wrapper
|
||||
#post-index-menu
|
||||
- if(postFilter=='all')
|
||||
a.current-filter(href="/@/dashboard/posts/list/all")= "All Posts ("+page_info.all+")"
|
||||
- else
|
||||
a(href="/@/dashboard/posts/list/all")= "All Posts ("+page_info.all+")"
|
||||
| .
|
||||
- if(postFilter=='published')
|
||||
a.current-filter(href="/@/dashboard/posts/list/published")= "Published ("+page_info.published+")"
|
||||
- else
|
||||
a(href="/@/dashboard/posts/list/published")= "Published ("+page_info.published+")"
|
||||
| .
|
||||
- if(postFilter=='deleted')
|
||||
a.current-filter(href="/@/dashboard/posts/list/deleted")= "Deleted ("+page_info.deleted+")"
|
||||
- else
|
||||
a(href="/@/dashboard/posts/list/deleted")= "Deleted ("+page_info.deleted+")"
|
||||
|
||||
a.add-new-post(href="/@/dashboard/posts/add/new") +
|
||||
label Create New Post
|
||||
#posts-list
|
||||
- var index = 0;
|
||||
- for ( index; index < items.length; index++)
|
||||
a.post-link(href="/@/dashboard/posts/edit/"+items[index].post.uuid id=items[index].post.uuid)
|
||||
|
||||
div.post-bg(style="background: #fc6399 url("+items[index].post.feature.substr(8)+") no-repeat center center / cover")
|
||||
label= items[index].post.title
|
||||
span= items[index].post.created
|
||||
p= items[index].post.plaintext.substr(0, 200)+"..."
|
||||
|
||||
- var next = parseInt(page_index, 10) + 1
|
||||
- var prev = parseInt(page_index, 10) - 1
|
||||
- if(next > page_count) next = 1
|
||||
- if(prev <= 0) prev = page_count
|
||||
|
||||
br
|
||||
a.page-btns(href="/@/dashboard/posts/list/"+postFilter+"/"+prev)
|
||||
svg(viewBox="0 0 20 20" class="icons")
|
||||
use(xlink:href='/dash/assets/images/sprite.svg#entypo-chevron-left')
|
||||
|
||||
span.paginate= "PAGE "+page_index+" OF "+page_count
|
||||
|
||||
a.page-btns(href="/@/dashboard/posts/list/"+postFilter+"/"+next)
|
||||
svg(viewBox="0 0 20 20" class="icons")
|
||||
use(xlink:href='/dash/assets/images/sprite.svg#entypo-chevron-right')
|
||||
|
Loading…
Reference in a new issue