forked from projects/fipamo
added auth to nav update method, moved nav update method to nad data class
This commit is contained in:
parent
f3ae41cd2a
commit
21520b1d60
4 changed files with 60 additions and 44 deletions
|
@ -2,6 +2,7 @@ import * as DataEvent from '../../../src/com/events/DataEvent';
|
|||
import Auth from '../../data/Auth';
|
||||
import Render from '../../data/Render';
|
||||
import SettingsData from '../../data/Settings';
|
||||
import Navigation from '../../data/Navigation';
|
||||
import Book from '../../data/Book';
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
@ -15,6 +16,7 @@ const auth = new Auth();
|
|||
const render = new Render();
|
||||
const book = new Book();
|
||||
const settingsData = new SettingsData();
|
||||
const nav = new Navigation();
|
||||
const uploadPath =
|
||||
'./public/assets/images/user/' + moment().format('YYYY') + '/' + moment().format('MM');
|
||||
fs.ensureDir(uploadPath, () => {
|
||||
|
@ -63,23 +65,28 @@ router.post('/sync', (req, res) => {
|
|||
});
|
||||
|
||||
router.post('/nav-sync', (req, res) => {
|
||||
let payload = req.body;
|
||||
if (req.session.user) {
|
||||
settings.menu = payload;
|
||||
fs.writeJson('site/settings.json', settings)
|
||||
.then(() => {
|
||||
res.json({
|
||||
type: DataEvent.SETTINGS_UPDATED,
|
||||
message: 'Menu order saved, champ'
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.json({
|
||||
type: DataEvent.REQUEST_LAME,
|
||||
message: err
|
||||
auth.authCheck(req)
|
||||
.then(() => {
|
||||
nav.sync(req)
|
||||
.then(response => {
|
||||
res.json({
|
||||
type: response.type,
|
||||
message: response.message
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.json({
|
||||
type: DataEvent.REQUEST_LAME,
|
||||
message: err
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
res.json({
|
||||
type: err.type,
|
||||
message: err.message
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/publish-pages', (req, res) => {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
//import fh from 'filehound';
|
||||
import fs from 'fs-extra';
|
||||
//import metadataParser from 'markdown-yaml-metadata-parser';
|
||||
import _ from 'lodash';
|
||||
import * as DataEvent from '../../src/com/events/DataEvent';
|
||||
//const moment = require('moment');
|
||||
const settings = require('../../site/settings.json');
|
||||
|
||||
export default class Navigation {
|
||||
//--------------------------
|
||||
|
@ -13,7 +11,28 @@ export default class Navigation {
|
|||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
start() {}
|
||||
sync(req) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let payload = req.body;
|
||||
settings.menu = payload;
|
||||
let response = [];
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
editMenu(task, item) {
|
||||
switch (task) {
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import ApiUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/APIUtils';
|
||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||
const api = new ApiUtils();
|
||||
export default class NavActions {
|
||||
//--------------------------
|
||||
// constructor
|
||||
|
@ -9,7 +6,7 @@ export default class NavActions {
|
|||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
save() {
|
||||
syncMenu() {
|
||||
let navData = [];
|
||||
let items = document.getElementById('nav-pages').children;
|
||||
for (let index = 0; index < items.length; index++) {
|
||||
|
@ -20,20 +17,8 @@ export default class NavActions {
|
|||
uuid: items[index].getAttribute('data-uuid')
|
||||
});
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
api.request(
|
||||
'/api/v1/settings/nav-sync',
|
||||
DataEvent.API_SETTINGS_WRITE,
|
||||
REQUEST_TYPE_POST,
|
||||
CONTENT_TYPE_JSON,
|
||||
navData
|
||||
)
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
return new Promise(function (resolve) {
|
||||
resolve(navData);
|
||||
});
|
||||
}
|
||||
//--------------------------
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
import ApiUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/APIUtils';
|
||||
import NavActions from '../actions/NavActions';
|
||||
import * as DataEvent from '../events/DataEvent';
|
||||
import Notifications from '../ui/Notifications';
|
||||
const notify = new Notifications();
|
||||
const api = new ApiUtils();
|
||||
export default class NavIndex {
|
||||
//--------------------------
|
||||
// constructor
|
||||
//--------------------------
|
||||
constructor() {
|
||||
api.authStatus();
|
||||
this.start();
|
||||
//this.dataUtils = new DataUtils();
|
||||
}
|
||||
//--------------------------
|
||||
// methods
|
||||
|
@ -16,19 +18,22 @@ export default class NavIndex {
|
|||
start() {
|
||||
Sortable.create(document.getElementById('nav-pages'), {
|
||||
onUpdate: () => {
|
||||
new NavActions()
|
||||
.save()
|
||||
.then(response => {
|
||||
new NavActions().syncMenu().then(data => {
|
||||
api.request(
|
||||
'/api/v1/settings/nav-sync',
|
||||
DataEvent.API_SETTINGS_WRITE,
|
||||
REQUEST_TYPE_POST,
|
||||
CONTENT_TYPE_JSON,
|
||||
data
|
||||
).then(response => {
|
||||
let r = JSON.parse(response.request['response']);
|
||||
if (r.type == DataEvent.MENU_UPDATED) {
|
||||
notify.alert(r.message, true);
|
||||
} else {
|
||||
notify.alert(r.message, true);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
//console.log(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
var nav = document.querySelectorAll('.nav-btn');
|
||||
|
|
Loading…
Reference in a new issue