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 Book from '../../data/Book';
|
||||||
import Auth from '../../data/Auth';
|
import Auth from '../../data/Auth';
|
||||||
import Navigation from '../../data/Navigation';
|
import Settings from '../../data/Settings';
|
||||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
@ -8,8 +8,8 @@ const multer = require('multer');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const book = new Book();
|
const book = new Book();
|
||||||
const nav = new Navigation();
|
|
||||||
const auth = new Auth();
|
const auth = new Auth();
|
||||||
|
const settings = new Settings();
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const uploadPath =
|
const uploadPath =
|
||||||
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
|
'./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;
|
body.deleted = false;
|
||||||
book.editPage(body, body.page_uuid, task, req.session.user)
|
book.editPage(body, body.page_uuid, task, req.session.user)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.type === DataEvent.PAGE_CREATE) {
|
if (result.type === DataEvent.PAGE_ADDED) {
|
||||||
nav.updatePageStats();
|
settings.updatePageIndex();
|
||||||
}
|
}
|
||||||
res.json(result);
|
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
|
// event handlers
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
|
|
@ -11,7 +11,6 @@ export default class Settings {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
//--------------------------
|
//--------------------------
|
||||||
start() {}
|
|
||||||
saveTags(tags) {
|
saveTags(tags) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!_.isEqual(config.tags, tags)) {
|
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
|
// event handlers
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
|
Loading…
Reference in a new issue