diff --git a/brain/api/v1/pages.js b/brain/api/v1/pages.js index 7a50cbc..9a44930 100644 --- a/brain/api/v1/pages.js +++ b/brain/api/v1/pages.js @@ -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); }) diff --git a/brain/data/Navigation.js b/brain/data/Navigation.js index 4dce6c5..682929b 100644 --- a/brain/data/Navigation.js +++ b/brain/data/Navigation.js @@ -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 //-------------------------- diff --git a/brain/data/Settings.js b/brain/data/Settings.js index 407937d..0a4be6e 100644 --- a/brain/data/Settings.js +++ b/brain/data/Settings.js @@ -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 //--------------------------