44 lines
1,001 B
JavaScript
44 lines
1,001 B
JavaScript
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
|
|
//--------------------------
|
|
start() {}
|
|
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);
|
|
}
|
|
});
|
|
}
|
|
|
|
//--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
}
|