2020-05-19 22:51:04 +02:00
|
|
|
import * as DataEvent from '../../src/com/events/DataEvent';
|
|
|
|
import fs from 'fs-extra';
|
2020-05-21 03:14:19 +02:00
|
|
|
const config = require('../../site/settings.json');
|
2020-05-19 22:51:04 +02:00
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
export default class Settings {
|
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {}
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
|
|
|
start() {}
|
|
|
|
saveTags(tags) {
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-05-21 03:14:19 +02:00
|
|
|
if (!_.isEqual(config.tags, tags)) {
|
|
|
|
config.tags = tags;
|
|
|
|
fs.writeJson('site/settings.json', config)
|
2020-05-19 22:51:04 +02:00
|
|
|
.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
|
|
|
|
//--------------------------
|
|
|
|
}
|