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 Book from '../../data/Book';
import Auth from '../../data/Auth'; 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 * as DataEvent from '../../../src/com/events/DataEvent';
import Render from '../../data/Render';
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const multer = require('multer'); const multer = require('multer');
@ -10,6 +11,7 @@ const moment = require('moment');
const book = new Book(); const book = new Book();
const auth = new Auth(); const auth = new Auth();
const settings = new Settings(); const settings = new Settings();
const render = new Render();
const _ = require('lodash'); const _ = require('lodash');
const uploadPath = const uploadPath =
'./public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM'); './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) { if (result.type === DataEvent.PAGE_ADDED) {
settings.updatePageIndex(); 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); res.json(result);
}) })
.catch(err => { .catch(err => {
@ -138,3 +170,19 @@ router.post('/add-post-image', post_upload, function (req, res) {
}); });
module.exports = router; 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 extends frame
block main-content 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 #site-background
label FEATURE SITE IMAGE label FEATURE SITE IMAGE
img#background(src=settings.global.background, alt="image for site background", for="background-upload") img#background(src=settings.global.background, alt="image for site background", for="background-upload")
@ -12,18 +29,6 @@ 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#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") input(id="avatar-upload" type="file" name="avatar-upload")
#member-settings-2.column #member-settings-2.column
label INFO label INFO
@ -33,9 +38,7 @@ block main-content
input(type='text', name='base-url' id='settings-url', placeholder='url', value=settings.global.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.global.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.global.descriptions =settings.global.descriptions
button#save-toggle SAVE SETTINGS
#option-settings.columns #option-settings.columns
#theme-settings.column #theme-settings.column
label THEMES label THEMES

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

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

@ -204,13 +204,11 @@
button[data-active='false'] button[data-active='false']
background $primary - 60% background $primary - 60%
svg svg
fill $white fill $white
button[data-active='true'] button[data-active='true']
background $tertiary + 50% background $tertiary + 50%
svg svg
fill $primary - 60% 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 #site-background
margin 0 0 10px 0 margin 0 0 10px 0

Loading…
Cancel
Save