From a4b945d31d97644633f0e4980adc568696e2a259 Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 6 Jul 2020 14:04:29 -0700 Subject: [PATCH] cleaned up setting ui to make saving, publishing more accessible, turned on render on save functionality --- brain/api/v1/pages.js | 50 +++++++++++++++++++++++++++- brain/views/settings.pug | 33 +++++++++--------- src/com/actions/SettingsActions.js | 4 +-- src/com/controllers/SettingsIndex.js | 10 +++--- src/styles/main/_posts.styl | 2 -- src/styles/main/_settings.styl | 23 +++++++++++++ 6 files changed, 97 insertions(+), 25 deletions(-) diff --git a/brain/api/v1/pages.js b/brain/api/v1/pages.js index d9dcd12..d3b2b00 100644 --- a/brain/api/v1/pages.js +++ b/brain/api/v1/pages.js @@ -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); + }); + }); +} diff --git a/brain/views/settings.pug b/brain/views/settings.pug index 1765f73..69acc7f 100644 --- a/brain/views/settings.pug +++ b/brain/views/settings.pug @@ -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 @@ -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-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 - + =settings.global.descriptions #option-settings.columns #theme-settings.column label THEMES diff --git a/src/com/actions/SettingsActions.js b/src/com/actions/SettingsActions.js index eb81fdf..f68f5c4 100644 --- a/src/com/actions/SettingsActions.js +++ b/src/com/actions/SettingsActions.js @@ -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 }, diff --git a/src/com/controllers/SettingsIndex.js b/src/com/controllers/SettingsIndex.js index 6d07cb4..1e8e7fd 100644 --- a/src/com/controllers/SettingsIndex.js +++ b/src/com/controllers/SettingsIndex.js @@ -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() { diff --git a/src/styles/main/_posts.styl b/src/styles/main/_posts.styl index 5e164c9..852d723 100644 --- a/src/styles/main/_posts.styl +++ b/src/styles/main/_posts.styl @@ -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% diff --git a/src/styles/main/_settings.styl b/src/styles/main/_settings.styl index e833ccb..43d4952 100644 --- a/src/styles/main/_settings.styl +++ b/src/styles/main/_settings.styl @@ -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