fipamo/brain/data/Settings.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

import * as DataEvent from '../../src/com/events/DataEvent';
import fs from 'fs-extra';
const config = require('../../site/settings.json');
const _ = require('lodash');
export default class Settings {
//--------------------------
// constructor
//--------------------------
constructor() {}
//--------------------------
// methods
//--------------------------
saveTags(tags) {
return new Promise((resolve, reject) => {
if (!_.isEqual(config.tags, tags)) {
config.tags = tags;
fs.writeJson('site/settings.json', config)
.then(() => {
let response = {
type: DataEvent.SETTINGS_UPDATED,
message: 'Settings Saved'
};
resolve(response);
})
.catch(err => {
reject(err);
});
} else {
let response = {
type: DataEvent.SETTINGS_NOT_UPDATED,
message: 'Settings Already Saved'
};
resolve(response);
}
});
}
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
//--------------------------
}