2020-03-01 22:13:18 +01:00
|
|
|
import fs from 'fs-extra';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import * as DataEvent from '../../src/com/events/DataEvent';
|
2020-06-19 01:21:33 +02:00
|
|
|
import Settings, { SETTINGS_FILE } from './Settings';
|
|
|
|
const settings = new Settings();
|
2020-03-01 22:13:18 +01:00
|
|
|
|
|
|
|
export default class Navigation {
|
|
|
|
//--------------------------
|
|
|
|
// constructor
|
|
|
|
//--------------------------
|
|
|
|
constructor() {}
|
|
|
|
//--------------------------
|
|
|
|
// methods
|
|
|
|
//--------------------------
|
2020-06-22 04:01:22 +02:00
|
|
|
sync(body) {
|
2020-05-23 22:55:25 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let response = [];
|
2020-06-25 00:19:54 +02:00
|
|
|
settings
|
|
|
|
.load(SETTINGS_FILE)
|
|
|
|
.then(settings => {
|
|
|
|
let payload = body;
|
|
|
|
settings.menu = payload;
|
|
|
|
fs.writeJson('site/settings.json', settings)
|
|
|
|
.then(() => {
|
|
|
|
response = {
|
|
|
|
type: DataEvent.SETTINGS_UPDATED,
|
|
|
|
message: 'Menu order saved, champ'
|
|
|
|
};
|
|
|
|
resolve(response);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
response = {
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
message: err
|
|
|
|
};
|
|
|
|
reject(response);
|
|
|
|
});
|
2020-05-23 22:55:25 +02:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
response = {
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
message: err
|
|
|
|
};
|
|
|
|
reject(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-03-01 22:13:18 +01:00
|
|
|
|
|
|
|
editMenu(task, item) {
|
2020-06-22 04:01:22 +02:00
|
|
|
settings.load(SETTINGS_FILE).then(settings => {
|
|
|
|
switch (task) {
|
|
|
|
case DataEvent.MENU_ADD_ITEM:
|
|
|
|
settings.menu.push({
|
|
|
|
title: item.title,
|
|
|
|
id: item.id,
|
|
|
|
slug: item.slug,
|
|
|
|
uuid: item.uuid,
|
|
|
|
path: item.path
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case DataEvent.MENU_DELETE_ITEM:
|
2020-03-01 22:13:18 +01:00
|
|
|
settings.menu = _.remove(settings.menu, m => {
|
|
|
|
return m.uuid != item.uuid;
|
|
|
|
});
|
2020-06-22 04:01:22 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fs.writeJSON(SETTINGS_FILE, settings);
|
|
|
|
});
|
2020-03-01 22:13:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// event handlers
|
|
|
|
//--------------------------
|
|
|
|
}
|