moved indexing to setting file, simplified updating index count
This commit is contained in:
parent
c4f6ed7357
commit
0f26dcb62a
3 changed files with 12 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
|||
import Book from '../../data/Book';
|
||||
import Auth from '../../data/Auth';
|
||||
import Navigation from '../../data/Navigation';
|
||||
import Settings from '../../data/Settings';
|
||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
@ -8,8 +8,8 @@ const multer = require('multer');
|
|||
const fs = require('fs-extra');
|
||||
const moment = require('moment');
|
||||
const book = new Book();
|
||||
const nav = new Navigation();
|
||||
const auth = new Auth();
|
||||
const settings = new Settings();
|
||||
const _ = require('lodash');
|
||||
const uploadPath =
|
||||
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
||||
|
@ -68,8 +68,8 @@ router.post('/write/:task?', feature_upload, (req, res) => {
|
|||
body.deleted = false;
|
||||
book.editPage(body, body.page_uuid, task, req.session.user)
|
||||
.then(result => {
|
||||
if (result.type === DataEvent.PAGE_CREATE) {
|
||||
nav.updatePageStats();
|
||||
if (result.type === DataEvent.PAGE_ADDED) {
|
||||
settings.updatePageIndex();
|
||||
}
|
||||
res.json(result);
|
||||
})
|
||||
|
|
|
@ -30,14 +30,6 @@ export default class Navigation {
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
//--------------------------
|
||||
|
|
|
@ -11,7 +11,6 @@ export default class Settings {
|
|||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
start() {}
|
||||
saveTags(tags) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!_.isEqual(config.tags, tags)) {
|
||||
|
@ -37,6 +36,14 @@ export default class Settings {
|
|||
});
|
||||
}
|
||||
|
||||
updatePageIndex() {
|
||||
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
|
||||
//--------------------------
|
||||
|
|
Loading…
Reference in a new issue