cleaned up save settings payload, added render on save toggle
This commit is contained in:
parent
ab19d8027e
commit
03a96dfed1
6 changed files with 116 additions and 87 deletions
|
@ -1,17 +1,10 @@
|
||||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||||
import RightsManager, {
|
|
||||||
TASK_CREATE,
|
|
||||||
TASK_UPDATE,
|
|
||||||
OBJECT_POST,
|
|
||||||
OBJECT_SETTINGS
|
|
||||||
} from '../../../src/com/utils/RightsManager';
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const rightsManager = new RightsManager();
|
|
||||||
const settings = require('../../../site/settings.json');
|
const settings = require('../../../site/settings.json');
|
||||||
const folks = require('../../../site/folks.json');
|
const folks = require('../../../site/folks.json');
|
||||||
const uploadPath =
|
const uploadPath =
|
||||||
|
@ -38,51 +31,59 @@ var background_upload = multer({
|
||||||
//** SYNC POSTS */
|
//** SYNC POSTS */
|
||||||
router.post('/sync', (req, res) => {
|
router.post('/sync', (req, res) => {
|
||||||
let payload = req.body;
|
let payload = req.body;
|
||||||
if (req.handle.user) {
|
if (req.session.user) {
|
||||||
let user = req.session.user;
|
let user = req.session.user;
|
||||||
fs.readJson('site/settings.json')
|
let found = _.find(folks, { id: user.id });
|
||||||
.then(obj => {
|
let needToUpdate = false;
|
||||||
if (user.hande != payload.handle || user.email != payload.email) {
|
if (found) {
|
||||||
user.update({
|
let index = found.id - 1;
|
||||||
handle: payload.handle,
|
if (
|
||||||
email: payload.email
|
folks[index].handle != payload.member.handle ||
|
||||||
})
|
folks[index].email != payload.member.email
|
||||||
.then(() => {
|
) {
|
||||||
//console.log('UPDATED');
|
folks[index].handle = payload.member.handle;
|
||||||
})
|
folks[index].email = payload.member.email;
|
||||||
.catch(() => {
|
fs.writeJson('site/folks.json', folks);
|
||||||
//console.log('ERR', err);
|
} else {
|
||||||
});
|
//no need to save
|
||||||
} else {
|
}
|
||||||
//console.log('USER NOT UPDATED');
|
} else {
|
||||||
}
|
res.json({
|
||||||
obj.url = payload.url;
|
type: DataEvent.REQUEST_LAME,
|
||||||
obj.title = payload.title;
|
message: "You're not logged in, champ"
|
||||||
obj.description = payload.descriptions;
|
|
||||||
obj.private = payload.private;
|
|
||||||
obj.theme = payload.theme;
|
|
||||||
obj.background = payload.background; //TODO: make this url relative
|
|
||||||
//mail stuff
|
|
||||||
obj.email.active = payload.mailSettings.activeProtocol;
|
|
||||||
obj.email.smtp.domain = payload.mailSettings.smtp.domain;
|
|
||||||
obj.email.smtp.email = payload.mailSettings.smtp.email;
|
|
||||||
obj.email.smtp.password = payload.mailSettings.smtp.password;
|
|
||||||
obj.email.mailgun.domain = payload.mailSettings.mailgun.domain;
|
|
||||||
obj.email.mailgun['api-key'] = payload.mailSettings.mailgun.key;
|
|
||||||
fs.writeJson('site/settings.json', obj)
|
|
||||||
.then(() => {
|
|
||||||
res.json({
|
|
||||||
type: DataEvent.SETTINGS_UPDATED,
|
|
||||||
message: 'Settings Saved'
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
//console.error(err);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
//console.error(err);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_.isEqual(settings.global, payload.global)) {
|
||||||
|
let bg = payload.global.background;
|
||||||
|
payload.global.background = bg.substr(21, bg.length);
|
||||||
|
settings.global = payload.global;
|
||||||
|
needToUpdate = true;
|
||||||
|
} else {
|
||||||
|
//no need to save
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_.isEqual(settings.email, payload.email)) {
|
||||||
|
settings.email = payload.email;
|
||||||
|
needToUpdate = true;
|
||||||
|
} else {
|
||||||
|
//no need to save
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needToUpdate) {
|
||||||
|
fs.writeJson('site/settings.json', settings)
|
||||||
|
.then(() => {
|
||||||
|
res.json({
|
||||||
|
type: DataEvent.SETTINGS_UPDATED,
|
||||||
|
message: 'Settings Saved'
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
//console.error(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//no need to update
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ router.get('/nav', function(req, res) {
|
||||||
|
|
||||||
router.post('/nav-sync', (req, res) => {
|
router.post('/nav-sync', (req, res) => {
|
||||||
let payload = req.body;
|
let payload = req.body;
|
||||||
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
|
if (req.session.user) {
|
||||||
fs.readJson('config/site-settings.json')
|
fs.readJson('config/site-settings.json')
|
||||||
.then(obj => {
|
.then(obj => {
|
||||||
obj.menu = payload;
|
obj.menu = payload;
|
||||||
|
@ -121,10 +122,6 @@ router.post('/nav-sync', (req, res) => {
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
//console.error(err);
|
//console.error(err);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
res.json({
|
|
||||||
message: "Nah. You can't do that. Talk to the admin, sport."
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ function loadThemes() {
|
||||||
let themes = [];
|
let themes = [];
|
||||||
for (let index = 0; index < files.length; index++) {
|
for (let index = 0; index < files.length; index++) {
|
||||||
fs.readJSON(files[index], (err, theme) => {
|
fs.readJSON(files[index], (err, theme) => {
|
||||||
if (theme.name == settings.theme) {
|
if (theme.name == settings.global.theme) {
|
||||||
themes.push({
|
themes.push({
|
||||||
theme: theme,
|
theme: theme,
|
||||||
current: 'true'
|
current: 'true'
|
||||||
|
|
|
@ -2,7 +2,7 @@ extends frame
|
||||||
block main-content
|
block main-content
|
||||||
#site-background
|
#site-background
|
||||||
label FEATURE SITE IMAGE
|
label FEATURE SITE IMAGE
|
||||||
img#background(src=settings.background, alt="image for site background", for="background-upload")
|
img#background(src=settings.global.background, alt="image for site background", for="background-upload")
|
||||||
input(id="background-upload" type="file" name="backgrond-upload")
|
input(id="background-upload" type="file" name="backgrond-upload")
|
||||||
|
|
||||||
#settings-index
|
#settings-index
|
||||||
|
@ -12,22 +12,28 @@ block main-content
|
||||||
label AVATAR
|
label AVATAR
|
||||||
#member-avatar-drop
|
#member-avatar-drop
|
||||||
img#avatar(src=member.avi, for="avatar-upload")
|
img#avatar(src=member.avi, for="avatar-upload")
|
||||||
button#save-toggle SAVE SETTINGS
|
button#privacy-toggle(data-private=settings.global.private)
|
||||||
|
-if (settings.global.private == 'false')
|
||||||
|
| SITE IS PRIVATE
|
||||||
|
-else
|
||||||
|
| SITE IS PUBLIC
|
||||||
|
button#render-toggle(data-render=settings.global.renderOnSave)
|
||||||
|
-if (settings.global.renderOnSave == 'false')
|
||||||
|
| DON'T RENDER PAGES ON SAVE
|
||||||
|
-else
|
||||||
|
| RENDER PAGES ON SAVE
|
||||||
input(id="avatar-upload" type="file" name="avatar-upload")
|
input(id="avatar-upload" type="file" name="avatar-upload")
|
||||||
#member-settings-2.column
|
#member-settings-2.column
|
||||||
label INFO
|
label INFO
|
||||||
#member-info
|
#member-info
|
||||||
input(type='text', name='handle' id='settings-handle', placeholder='handle', value=member.handle, autofocus)
|
input(type='text', name='handle' id='settings-handle', placeholder='handle', value=member.handle, autofocus)
|
||||||
input(type='text', name='email' id='settings-email', placeholder='email', value=member.email, autofocus)
|
input(type='text', name='email' id='settings-email', placeholder='email', value=member.email, autofocus)
|
||||||
input(type='text', name='base-url' id='settings-url', placeholder='url', value=settings.base_url, autofocus)
|
input(type='text', name='base-url' id='settings-url', placeholder='url', value=settings.global.base_url, autofocus)
|
||||||
input(type='text', name='base-title' id='settings-title', placeholder='site title', value=settings.title, autofocus)
|
input(type='text', name='base-title' id='settings-title', placeholder='site title', value=settings.global.title, autofocus)
|
||||||
textarea(id="settings-desc" type='text', name='settings_desc' class='settings-dec', placeholder='description stuff', autofocus)
|
textarea(id="settings-desc" type='text', name='settings_desc' class='settings-dec', placeholder='description stuff', autofocus)
|
||||||
=settings.description
|
=settings.global.descriptions
|
||||||
button#privacy-toggle(data-private=settings.private)
|
button#save-toggle SAVE SETTINGS
|
||||||
-if (settings.private == 'false')
|
|
||||||
| SITE IS PRIVATE
|
|
||||||
-else
|
|
||||||
| SITE IS PUBLIC
|
|
||||||
#option-settings.columns
|
#option-settings.columns
|
||||||
#theme-settings.column
|
#theme-settings.column
|
||||||
label THEMES
|
label THEMES
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
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 SettingsActions {
|
export default class SettingsActions {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
//--------------------------
|
//--------------------------
|
||||||
constructor() {
|
constructor() {}
|
||||||
this.dataUtils = new DataUtils();
|
|
||||||
}
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
//--------------------------
|
//--------------------------
|
||||||
save() {
|
save() {
|
||||||
let self = this;
|
|
||||||
let handle = document.getElementById('settings-handle').value;
|
let handle = document.getElementById('settings-handle').value;
|
||||||
let email = document.getElementById('settings-email').value;
|
let email = document.getElementById('settings-email').value;
|
||||||
let url = document.getElementById('settings-url').value;
|
let url = document.getElementById('settings-url').value;
|
||||||
let title = document.getElementById('settings-title').value;
|
let title = document.getElementById('settings-title').value;
|
||||||
let desc = document.getElementById('settings-desc').innerHTML;
|
let desc = document.getElementById('settings-desc').value;
|
||||||
let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
|
let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
|
||||||
|
let render = document.getElementById('render-toggle').getAttribute('data-render');
|
||||||
let background = document.getElementById('background').src;
|
let background = document.getElementById('background').src;
|
||||||
let selected = '';
|
let selected = '';
|
||||||
let selects = document.querySelectorAll('.theme-select');
|
let selects = document.querySelectorAll('.theme-select');
|
||||||
|
@ -38,16 +37,18 @@ export default class SettingsActions {
|
||||||
mailActive = mailOptions[i].id;
|
mailActive = mailOptions[i].id;
|
||||||
}
|
}
|
||||||
let settingsData = {
|
let settingsData = {
|
||||||
handle: handle,
|
global: {
|
||||||
email: email,
|
base_url: url,
|
||||||
url: url,
|
title: title,
|
||||||
title: title,
|
descriptions: desc,
|
||||||
descriptions: desc,
|
background: background,
|
||||||
background: background,
|
private: privacy,
|
||||||
private: privacy,
|
renderOnSave: render,
|
||||||
theme: selected,
|
theme: selected
|
||||||
mailSettings: {
|
},
|
||||||
activeProtocol: mailActive,
|
member: { handle: handle, email: email },
|
||||||
|
email: {
|
||||||
|
active: mailActive,
|
||||||
smtp: {
|
smtp: {
|
||||||
domain: smtpDomain,
|
domain: smtpDomain,
|
||||||
email: smtpEmail,
|
email: smtpEmail,
|
||||||
|
@ -60,9 +61,9 @@ export default class SettingsActions {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
self.dataUtils
|
utils
|
||||||
.request(
|
.request(
|
||||||
'/api/settings/sync',
|
'/api/v1/settings/sync',
|
||||||
DataEvent.SETTINGS_UPDATED,
|
DataEvent.SETTINGS_UPDATED,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
|
|
@ -5,13 +5,13 @@ import Mailer from '../actions/Mailer';
|
||||||
import Notifications from '../ui/Notifications';
|
import Notifications from '../ui/Notifications';
|
||||||
const utils = new DataUtils();
|
const utils = new DataUtils();
|
||||||
const notify = new Notifications();
|
const notify = new Notifications();
|
||||||
|
const mailer = new Mailer();
|
||||||
export default class SettingsIndex {
|
export default class SettingsIndex {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
//--------------------------
|
//--------------------------
|
||||||
constructor() {
|
constructor() {
|
||||||
this.start();
|
this.start();
|
||||||
this.mailer = new Mailer();
|
|
||||||
}
|
}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
|
@ -22,8 +22,13 @@ export default class SettingsIndex {
|
||||||
document.getElementById('save-toggle').addEventListener('click', () =>
|
document.getElementById('save-toggle').addEventListener('click', () =>
|
||||||
new SettingsActions()
|
new SettingsActions()
|
||||||
.save()
|
.save()
|
||||||
.then(() => {
|
.then(response => {
|
||||||
//console.log(response);
|
let r = JSON.parse(response.request['response']);
|
||||||
|
if (r.type == DataEvent.SETTINGS_UPDATED) {
|
||||||
|
notify.alert(r.message, true);
|
||||||
|
} else {
|
||||||
|
notify.alert(r.message, true);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
//console.log(err);
|
//console.log(err);
|
||||||
|
@ -54,6 +59,9 @@ export default class SettingsIndex {
|
||||||
document
|
document
|
||||||
.getElementById('privacy-toggle')
|
.getElementById('privacy-toggle')
|
||||||
.addEventListener('click', e => this.togglePrivacy(e));
|
.addEventListener('click', e => this.togglePrivacy(e));
|
||||||
|
document
|
||||||
|
.getElementById('render-toggle')
|
||||||
|
.addEventListener('click', e => this.toggleRender(e));
|
||||||
document.getElementById('send-mail').addEventListener('click', e => this.handleMailer(e));
|
document.getElementById('send-mail').addEventListener('click', e => this.handleMailer(e));
|
||||||
//handle theme toggle
|
//handle theme toggle
|
||||||
let themeBtns = document.querySelectorAll('.theme-select');
|
let themeBtns = document.querySelectorAll('.theme-select');
|
||||||
|
@ -80,8 +88,19 @@ export default class SettingsIndex {
|
||||||
e.target.innerHTML = 'SITE IS PRIVATE';
|
e.target.innerHTML = 'SITE IS PRIVATE';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
toggleRender(e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.target.getAttribute('data-render') == 'false') {
|
||||||
|
e.target.setAttribute('data-render', 'true');
|
||||||
|
e.target.innerHTML = 'RENDER PAGES ON SAVE';
|
||||||
|
} else {
|
||||||
|
e.target.setAttribute('data-render', 'false');
|
||||||
|
e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
|
||||||
|
}
|
||||||
|
}
|
||||||
handleMailer() {
|
handleMailer() {
|
||||||
this.mailer.sendMail();
|
mailer.sendMail();
|
||||||
}
|
}
|
||||||
handleThemes(e) {
|
handleThemes(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
|
@ -61,10 +61,16 @@
|
||||||
border-radius 5px
|
border-radius 5px
|
||||||
overflow hidden
|
overflow hidden
|
||||||
cursor pointer
|
cursor pointer
|
||||||
|
display block
|
||||||
|
margin-bottom 2px
|
||||||
|
|
||||||
input
|
input
|
||||||
visibility hidden
|
visibility hidden
|
||||||
display none
|
display none
|
||||||
|
#privacy-toggle
|
||||||
|
width 50%
|
||||||
|
#render-toggle
|
||||||
|
width 50%
|
||||||
|
|
||||||
#member-info
|
#member-info
|
||||||
vertical-align top
|
vertical-align top
|
||||||
|
|
Loading…
Reference in a new issue