cleaned up setting ui to make saving, publishing more accessible, turned on render on save functionality

pull/20/head
Ro 4 years ago
parent ef9665f12b
commit a4b945d31d

@ -1,7 +1,8 @@
import Book from '../../data/Book';
import Auth from '../../data/Auth';
import Settings from '../../data/Settings';
import Settings, { SETTINGS_FILE } from '../../data/Settings';
import * as DataEvent from '../../../src/com/events/DataEvent';
import Render from '../../data/Render';
const express = require('express');
const router = express.Router();
const multer = require('multer');
@ -10,6 +11,7 @@ const moment = require('moment');
const book = new Book();
const auth = new Auth();
const settings = new Settings();
const render = new Render();
const _ = require('lodash');
const uploadPath =
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM');
@ -91,6 +93,36 @@ router.post('/write/:task?', feature_upload, (req, res) => {
if (result.type === DataEvent.PAGE_ADDED) {
settings.updatePageIndex();
}
//load all page data and render if render on save flag is set in settings file
getBookData()
.then(result => {
if (result.settings.global.renderOnSave === 'true') {
render
.publishAll(
result.pages,
result.settings.global.theme,
req.session.user.handle
)
.then(response => {
res.json({
type: response.type,
message: response.message
});
})
.catch(err => {
res.json({
type: DataEvent.PAGES_NOT_RENDERED,
message: 'Uh oh. Pages not rendered, sport',
error: err
});
});
} else {
//console.log('DONT RENDER PAGES');
}
})
.catch(() => {
console.log();
});
res.json(result);
})
.catch(err => {
@ -138,3 +170,19 @@ router.post('/add-post-image', post_upload, function (req, res) {
});
module.exports = router;
function getBookData() {
return new Promise((resolve, reject) => {
let getSettings = settings.load(SETTINGS_FILE);
let getBook = book.getPage();
Promise.all([getSettings, getBook])
.then(result => {
const [settings, pages] = result;
let data = { settings: settings, pages: pages };
resolve(data);
})
.catch(err => {
reject(err);
});
});
}

@ -1,5 +1,22 @@
extends frame
block main-content
#settings-actions
#buttons
button#save-toggle
svg#submit-update(viewBox="0 0 20 20" class="icons")
use#submit-update(xlink:href='/assets/images/global/sprite.svg#entypo-save')
//button#privacy-toggle(data-private=settings.global.private)
-if (settings.global.private == 'false')
| SITE IS PRIVATE
-else
| SITE IS PUBLIC
button#publish-pages
svg#submit-update(viewBox="0 0 20 20" class="icons")
use#submit-update(xlink:href='/assets/images/global/sprite.svg#entypo-publish')
button#render-toggle(data-render=settings.global.renderOnSave)
svg#submit-update(viewBox="0 0 20 20" class="icons")
use#submit-update(xlink:href='/assets/images/global/sprite.svg#entypo-ccw')
#site-background
label FEATURE SITE IMAGE
img#background(src=settings.global.background, alt="image for site background", for="background-upload")
@ -12,18 +29,6 @@ block main-content
label AVATAR
#member-avatar-drop
img#avatar(src=member.avi, for="avatar-upload")
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
button#publish-pages
| Publish Site
input(id="avatar-upload" type="file" name="avatar-upload")
#member-settings-2.column
label INFO
@ -34,8 +39,6 @@ block main-content
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)
=settings.global.descriptions
button#save-toggle SAVE SETTINGS
#option-settings.columns
#theme-settings.column
label THEMES

@ -12,7 +12,7 @@ export default class SettingsActions {
let url = document.getElementById('settings-url').value;
let title = document.getElementById('settings-title').value;
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 selected = '';
@ -39,7 +39,7 @@ export default class SettingsActions {
title: title,
descriptions: desc,
background: background,
private: privacy,
private: false,
renderOnSave: render,
theme: selected
},

@ -57,9 +57,9 @@ export default class SettingsIndex {
false
);
//handle privacy toggle
document
.getElementById('privacy-toggle')
.addEventListener('click', e => this.togglePrivacy(e));
//document
//.getElementById('privacy-toggle')
//.addEventListener('click', e => this.togglePrivacy(e));
document
.getElementById('render-toggle')
.addEventListener('click', e => this.toggleRender(e));
@ -97,10 +97,10 @@ export default class SettingsIndex {
e.preventDefault();
if (e.target.getAttribute('data-render') == 'false') {
e.target.setAttribute('data-render', 'true');
e.target.innerHTML = 'RENDER PAGES ON SAVE';
//e.target.innerHTML = 'RENDER PAGES ON SAVE';
} else {
e.target.setAttribute('data-render', 'false');
e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
//e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
}
}
handleMailer() {

@ -204,13 +204,11 @@
button[data-active='false']
background $primary - 60%
svg
fill $white
button[data-active='true']
background $tertiary + 50%
svg
fill $primary - 60%

@ -1,3 +1,26 @@
#settings-actions
position fixed
width 100%
margin-top -85px
#buttons
width 155px
margin 0 auto
button
//width 30%
margin 5px
svg
fill $white
button[data-render='false']
background $primary - 60%
svg
fill $white
button[data-render='true']
background $tertiary + 50%
svg
fill $primary - 60%
#site-background
margin 0 0 10px 0

Loading…
Cancel
Save