forked from projects/fipamo
navigation sorting working again
This commit is contained in:
parent
03a96dfed1
commit
d329522091
7 changed files with 94 additions and 60 deletions
|
@ -87,40 +87,22 @@ router.post('/sync', (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/nav', function(req, res) {
|
|
||||||
fs.readJson('config/site-settings.json')
|
|
||||||
.then(obj => {
|
|
||||||
fs.writeJson('config/site-settings.json', obj)
|
|
||||||
.then(() => {
|
|
||||||
res.json(obj.menu);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
//console.error(err);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
//console.error(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/nav-sync', (req, res) => {
|
router.post('/nav-sync', (req, res) => {
|
||||||
let payload = req.body;
|
let payload = req.body;
|
||||||
if (req.session.user) {
|
if (req.session.user) {
|
||||||
fs.readJson('config/site-settings.json')
|
settings.menu = payload;
|
||||||
.then(obj => {
|
fs.writeJson('site/settings.json', settings)
|
||||||
obj.menu = payload;
|
.then(() => {
|
||||||
fs.writeJson('config/site-settings.json', obj)
|
res.json({
|
||||||
.then(() => {
|
type: DataEvent.SETTINGS_UPDATED,
|
||||||
res.json({
|
message: 'Menu order saved, champ'
|
||||||
message: DataEvent.SETTINGS_UPDATED
|
});
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
//console.error(err);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(err => {
|
||||||
//console.error(err);
|
res.json({
|
||||||
|
type: DataEvent.REQUEST_LAME,
|
||||||
|
message: err
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,7 +45,7 @@ app.use(flash());
|
||||||
var dash = require('./routes/dash/index');
|
var dash = require('./routes/dash/index');
|
||||||
var page = require('./routes/dash/pages');
|
var page = require('./routes/dash/pages');
|
||||||
var settings = require('./routes/dash/settings');
|
var settings = require('./routes/dash/settings');
|
||||||
//var navDashboard = require('./routes/dash/nav');
|
var nav = require('./routes/dash/nav');
|
||||||
//api
|
//api
|
||||||
var pages = require('./api/v1/pages');
|
var pages = require('./api/v1/pages');
|
||||||
var setting = require('./api/v1/settings');
|
var setting = require('./api/v1/settings');
|
||||||
|
@ -58,11 +58,10 @@ app.use('/api/v1/settings', setting);
|
||||||
//app.use('/api/mail', mailer);
|
//app.use('/api/mail', mailer);
|
||||||
app.use('/api/v1/auth', auth);
|
app.use('/api/v1/auth', auth);
|
||||||
// PAGES
|
// PAGES
|
||||||
//app.use('/', front);
|
|
||||||
app.use('/@/dashboard', dash);
|
app.use('/@/dashboard', dash);
|
||||||
app.use('/@/dashboard/page', page);
|
app.use('/@/dashboard/page', page);
|
||||||
app.use('/@/dashboard/settings', settings);
|
app.use('/@/dashboard/settings', settings);
|
||||||
//app.use('/@/dashboard/navigation', navDashboard);
|
app.use('/@/dashboard/navigation', nav);
|
||||||
//app.use('/mailer', mailer);
|
//app.use('/mailer', mailer);
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
|
@ -76,7 +75,7 @@ app.use(function(req, res, next) {
|
||||||
if (app.get('env') === 'development') {
|
if (app.get('env') === 'development') {
|
||||||
app.use(function(err, req, res) {
|
app.use(function(err, req, res) {
|
||||||
res.status(err.status || 500);
|
res.status(err.status || 500);
|
||||||
res.render(theme + '/error', {
|
res.render('error', {
|
||||||
message: err.message,
|
message: err.message,
|
||||||
error: err
|
error: err
|
||||||
});
|
});
|
||||||
|
@ -86,7 +85,7 @@ if (app.get('env') === 'development') {
|
||||||
// no stacktraces leaked to user
|
// no stacktraces leaked to user
|
||||||
app.use(function(err, req, res) {
|
app.use(function(err, req, res) {
|
||||||
res.status(err.status || 500);
|
res.status(err.status || 500);
|
||||||
res.render(theme + '/error', {
|
res.render('error', {
|
||||||
message: err.message,
|
message: err.message,
|
||||||
error: {}
|
error: {}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,21 +1,65 @@
|
||||||
|
import Book from '../../../brain/data/Book';
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const fs = require('fs-extra');
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
var settings = [];
|
const settings = require('../../../site/settings.json');
|
||||||
|
const book = new Book();
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// SETTINGS
|
// SETTINGS
|
||||||
//--------------------------
|
//--------------------------
|
||||||
router.get('/', function(req, res) {
|
router.get('/', function(req, res) {
|
||||||
fs.readJson('config/site-settings.json')
|
|
||||||
.then(obj => {
|
|
||||||
settings = [];
|
|
||||||
settings = obj;
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
//console.error(err)
|
|
||||||
});
|
|
||||||
if (req.session.user) {
|
if (req.session.user) {
|
||||||
|
var nav = [];
|
||||||
|
book.getPage()
|
||||||
|
.then(pages => {
|
||||||
|
if (settings.menu.length === 0) {
|
||||||
|
for (let index = 0; index < pages.length; index++) {
|
||||||
|
let item = pages[index].metadata;
|
||||||
|
if (item.menu) {
|
||||||
|
nav.push({
|
||||||
|
id: item.id,
|
||||||
|
uuid: item.uuid,
|
||||||
|
title: item.title,
|
||||||
|
slug: item.slug
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let newpages = [];
|
||||||
|
nav = settings.menu;
|
||||||
|
for (let index = 0; index < pages.length; index++) {
|
||||||
|
let item = pages[index].metadata;
|
||||||
|
if (item.menu)
|
||||||
|
newpages.push({
|
||||||
|
id: item.id,
|
||||||
|
uuid: item.uuid,
|
||||||
|
title: item.title,
|
||||||
|
slug: item.slug
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let i = 0; i < newpages.length; i++) {
|
||||||
|
if (_.find(nav, { uuid: newpages[i].uuid })) {
|
||||||
|
//menu item already exists
|
||||||
|
} else {
|
||||||
|
nav.push({
|
||||||
|
id: newpages[i].id,
|
||||||
|
uuid: newpages[i].uuid,
|
||||||
|
title: newpages[i].title,
|
||||||
|
slug: newpages[i].slug
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.render('navigation', {
|
||||||
|
menu: nav,
|
||||||
|
welcome: 'Edit Navigation',
|
||||||
|
status: true,
|
||||||
|
title: 'Dashboard | Navigation'
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
//console.log('ERROR', err);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
res.redirect('/@/dashboard');
|
res.redirect('/@/dashboard');
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,13 @@ block main-content
|
||||||
#nav-index-wrapper
|
#nav-index-wrapper
|
||||||
#nav-pages
|
#nav-pages
|
||||||
- var index = 0;
|
- var index = 0;
|
||||||
- for ( index; index < pages.length; index++)
|
- for ( index; index < menu.length; index++)
|
||||||
.nav-item(id=pages[index].id, data-slug=pages[index].slug, data-uuid=pages[index].uuid)
|
.nav-item(id=menu[index].id, data-slug=menu[index].slug, data-uuid=menu[index].uuid)
|
||||||
svg#item-arrows(viewBox="0 0 20 20" class="icons")
|
svg#item-arrows(viewBox="0 0 20 20" class="icons")
|
||||||
use(xlink:href='/dash/assets/images/sprite.svg#entypo-select-arrows')
|
use(xlink:href='/assets/images/global/sprite.svg#entypo-select-arrows')
|
||||||
label
|
label
|
||||||
= pages[index].title
|
= menu[index].title
|
||||||
#nav-btns
|
#nav-btns
|
||||||
button.nav-btn#edit-item(data-id=pages[index].uuid) EDIT
|
button.nav-btn#edit-item(data-id=menu[index].uuid) EDIT
|
||||||
button.nav-btn#remove-item(data-id=pages[index].id) REMOVE
|
button.nav-btn#remove-item(data-id=menu[index].id) REMOVE
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/DataUtils';
|
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/DataUtils';
|
||||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||||
|
const utils = new DataUtils();
|
||||||
export default class NavActions {
|
export default class NavActions {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
//--------------------------
|
//--------------------------
|
||||||
constructor() {
|
constructor() {}
|
||||||
this.dataUtils = new DataUtils();
|
|
||||||
}
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
//--------------------------
|
//--------------------------
|
||||||
save() {
|
save() {
|
||||||
let self = this;
|
|
||||||
let navData = [];
|
let navData = [];
|
||||||
let items = document.getElementById('nav-pages').children;
|
let items = document.getElementById('nav-pages').children;
|
||||||
for (let index = 0; index < items.length; index++) {
|
for (let index = 0; index < items.length; index++) {
|
||||||
|
@ -23,9 +21,9 @@ export default class NavActions {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
self.dataUtils
|
utils
|
||||||
.request(
|
.request(
|
||||||
'/api/settings/nav-sync',
|
'/api/v1/settings/nav-sync',
|
||||||
DataEvent.SETTINGS_UPDATED,
|
DataEvent.SETTINGS_UPDATED,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
@ -40,6 +38,7 @@ export default class NavActions {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
removeItem(id) {
|
removeItem(id) {
|
||||||
|
/**
|
||||||
let self = this;
|
let self = this;
|
||||||
this.dbutils.getPost(id).then(post => {
|
this.dbutils.getPost(id).then(post => {
|
||||||
post.post.page = 'false';
|
post.post.page = 'false';
|
||||||
|
@ -48,6 +47,7 @@ export default class NavActions {
|
||||||
self.save();
|
self.save();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// event handlers
|
// event handlers
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import NavActions from '../actions/NavActions';
|
import NavActions from '../actions/NavActions';
|
||||||
|
import * as DataEvent from '../events/DataEvent';
|
||||||
|
import Notifications from '../ui/Notifications';
|
||||||
|
const notify = new Notifications();
|
||||||
export default class NavIndex {
|
export default class NavIndex {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
|
@ -15,8 +18,13 @@ export default class NavIndex {
|
||||||
onUpdate: () => {
|
onUpdate: () => {
|
||||||
new NavActions()
|
new NavActions()
|
||||||
.save()
|
.save()
|
||||||
.then(() => {
|
.then(response => {
|
||||||
//console.log(r);
|
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(() => {
|
.catch(() => {
|
||||||
//console.log(err);
|
//console.log(err);
|
||||||
|
@ -39,7 +47,7 @@ export default class NavIndex {
|
||||||
new NavActions().removeItem(id);
|
new NavActions().removeItem(id);
|
||||||
break;
|
break;
|
||||||
case 'edit-item':
|
case 'edit-item':
|
||||||
window.location = '/@/dashboard/posts/edit/' + e.target.getAttribute('data-id');
|
window.location = '/@/dashboard/pages/edit/' + e.target.getAttribute('data-id');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ export const PAGE_ADDED = 'postAdded';
|
||||||
export const PAGE_UPDATED = 'postUpdated';
|
export const PAGE_UPDATED = 'postUpdated';
|
||||||
export const PAGE_DELETED = 'postImageAdded';
|
export const PAGE_DELETED = 'postImageAdded';
|
||||||
export const SETTINGS_UPDATED = 'settingsUpdated';
|
export const SETTINGS_UPDATED = 'settingsUpdated';
|
||||||
|
export const MENU_UPDATED = 'menuUpdated';
|
||||||
export const AVATAR_UPLOADED = 'avatarUploaded';
|
export const AVATAR_UPLOADED = 'avatarUploaded';
|
||||||
export const SITE_BACKGROUND_UPLOADED = 'siteBackgroundUploaded';
|
export const SITE_BACKGROUND_UPLOADED = 'siteBackgroundUploaded';
|
||||||
export const API_PAGE_WRITE = 'writingItDown';
|
export const API_PAGE_WRITE = 'writingItDown';
|
||||||
|
|
Loading…
Reference in a new issue