forked from projects/fipamo
44 lines
1,009 B
JavaScript
44 lines
1,009 B
JavaScript
|
import * as DataEvent from '../../src/com/events/DataEvent';
|
||
|
import fs from 'fs-extra';
|
||
|
const settings = require('../../site/settings.json');
|
||
|
const _ = require('lodash');
|
||
|
|
||
|
export default class Settings {
|
||
|
//--------------------------
|
||
|
// constructor
|
||
|
//--------------------------
|
||
|
constructor() {}
|
||
|
//--------------------------
|
||
|
// methods
|
||
|
//--------------------------
|
||
|
start() {}
|
||
|
saveTags(tags) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
if (!_.isEqual(settings.tags, tags)) {
|
||
|
settings.tags = tags;
|
||
|
fs.writeJson('site/settings.json', settings)
|
||
|
.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
|
||
|
//--------------------------
|
||
|
}
|