From 532748f6882bc11da044dfa0811c423bb078d759 Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 25 Nov 2019 16:51:35 -0800 Subject: [PATCH] fixed post image uploading, cleaned up text editor styles (FINALLY), plugged in error page renderererer --- brain/api/v1/pages.js | 12 +++++++++++- brain/routes/dash/pages.js | 7 +++---- brain/views/error.pug | 8 ++++++++ brain/views/frame.pug | 3 +++ src/com/controllers/PageEditor.js | 27 ++++++--------------------- src/styles/dash.styl | 6 ++++++ src/styles/main/_error.styl | 22 ++++++++++++++++++++++ src/styles/main/_posts.styl | 9 ++++++--- src/styles/main/_structure.styl | 1 + 9 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 brain/views/error.pug create mode 100644 src/styles/main/_error.styl diff --git a/brain/api/v1/pages.js b/brain/api/v1/pages.js index fac1782..74201b5 100644 --- a/brain/api/v1/pages.js +++ b/brain/api/v1/pages.js @@ -107,9 +107,19 @@ router.post('/write/:task?', feature_upload, (req, res) => { id: req.body.page_uuid }); } else { - res.json({ type: DataEvent.PAGE_UPDATED, message: 'Page Has been saved' }); + res.json({ type: DataEvent.PAGE_UPDATED, message: 'Page saved, boss' }); } }); }); +router.post('/add-post-image', post_upload, function(req, res) { + //console.log(req.body); + var image = req.files[0].path; + return res.json({ + type: DataEvent.POST_IMAGE_ADDED, + message: 'Added Image', + url: '/' + image.substr(7, image.length) + }); +}); + module.exports = router; diff --git a/brain/routes/dash/pages.js b/brain/routes/dash/pages.js index b82b1f2..e1c7d36 100644 --- a/brain/routes/dash/pages.js +++ b/brain/routes/dash/pages.js @@ -38,11 +38,10 @@ router.get('/add/new', function(req, res) { fs.readJSON('site/settings.json') .then(settings => { //use current index as id, then updated current index and page count - let pageID = settings.library_stats.current_index; settings.library_stats.current_index = ++settings.library_stats.current_index; settings.library_stats.total_pages = ++settings.library_stats.total_pages; - fs.writeJson('site/settings.json', settings) + fs.writeJson('site/settings.json') .then(() => { res.render('page-edit', { id: pageID, @@ -58,11 +57,11 @@ router.get('/add/new', function(req, res) { }); }) .catch(err => { - console.error('SAVING', err); + res.render('error', { error: err }); }); }) .catch(err => { - console.log('READING', err); + res.render('error', { error: err }); }); } else { res.redirect('/@/dashboard'); diff --git a/brain/views/error.pug b/brain/views/error.pug new file mode 100644 index 0000000..b3cb2b1 --- /dev/null +++ b/brain/views/error.pug @@ -0,0 +1,8 @@ +extends frame +block main-content + #error-index + br + label#message Ok, so this is... awkward + br + label#error= error + diff --git a/brain/views/frame.pug b/brain/views/frame.pug index 4b57069..19dd78d 100644 --- a/brain/views/frame.pug +++ b/brain/views/frame.pug @@ -22,6 +22,9 @@ html(xmlns='http://www.w3.org/1999/xhtml', lang='en', xml:lang="en") #left a(href="/@/dashboard") img#the-logo(src="/assets/images/global/the-logo.svg") + #right + -if(status) + include partials/dash-nav block main-content script(src='/assets/scripts/dashkit.min.js' type="text/javascript") script(src='/assets/scripts/dash.min.js' type="text/javascript") diff --git a/src/com/controllers/PageEditor.js b/src/com/controllers/PageEditor.js index b92b979..f12476e 100644 --- a/src/com/controllers/PageEditor.js +++ b/src/com/controllers/PageEditor.js @@ -56,9 +56,8 @@ export default class PostEditor { ); TinyDatePicker(document.getElementById('post-date'), { mode: 'dp-below', - format(date) { - console.log('RAW DATE', date); - return self.dateUtils.getDate('origin', date); + format() { + //return self.dateUtils.getDate('origin', date); } }); @@ -115,7 +114,6 @@ export default class PostEditor { : currentOption.setAttribute('data-active', 'false'); } handleEditorOptions(e) { - let self = this; switch (e) { case EditorEvent.EDITOR_SAVE: case EditorEvent.EDITOR_UPDATE: @@ -211,23 +209,12 @@ export default class PostEditor { // Read in the image file as a data URL. reader.readAsDataURL(f); } - /** - if (e.target.id == 'featured-image-upload') - this.handleImageUpload(e.target.id, PostEditor.uploadFiles); - break; - */ } } handleImageUpload(type, files) { - let url = ''; - let eventType = ''; + let url = '/api/v1/page/add-post-image'; + let eventType = DataEvent.POST_IMAGE_ADDED; let self = this; - type == 'featured-image-upload' - ? (url = '/api/post/add-feature-image') - : (url = '/api/post/add-post-image'); - type == 'featured-image-upload' - ? (eventType = DataEvent.FEATURE_IMAGE_ADDED) - : (eventType = DataEvent.POST_IMAGE_ADDED); var imageData = new FormData(); for (var i = 0; i < files.length; i++) { var file = files[i]; @@ -235,14 +222,12 @@ export default class PostEditor { if (!file.type.match('image.*')) { continue; } - type == 'featured-image-upload' - ? imageData.append('feature_image', file, file.name) - : imageData.append('post_image', file, file.name); + imageData.append('post_image', file, file.name); } data.request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData) .then(response => { let r = JSON.parse(response.request['response']); - if (r.message == DataEvent.POST_IMAGE_ADDED) + if (r.type == DataEvent.POST_IMAGE_ADDED) self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url); }) .catch(() => { diff --git a/src/styles/dash.styl b/src/styles/dash.styl index ba92805..2aac8b4 100644 --- a/src/styles/dash.styl +++ b/src/styles/dash.styl @@ -47,6 +47,12 @@ ------------------------------- * */ @import 'main/_settings' + /** +------------------------------- +-- Error +------------------------------- +* */ +@import 'main/_error' /** ------------------------------- -- Navigation diff --git a/src/styles/main/_error.styl b/src/styles/main/_error.styl new file mode 100644 index 0000000..25dbf64 --- /dev/null +++ b/src/styles/main/_error.styl @@ -0,0 +1,22 @@ + #error-index + width 100% + max-width 900px + margin 0 auto; + padding: 10px + height 100% + z-index 10 + position relative + label#title + font-size 100px + color $highlight + font-weight: 500 + + label#message + font-size 50px + color $tertiary + font-weight: 500 + + label#error + font-size 25px + color $eventLame + font-weight: 500 \ No newline at end of file diff --git a/src/styles/main/_posts.styl b/src/styles/main/_posts.styl index 14d83d5..1efc8d1 100644 --- a/src/styles/main/_posts.styl +++ b/src/styles/main/_posts.styl @@ -190,17 +190,19 @@ #edit-post width 100% - max-width 900px + max-width 880px margin 0 auto #edit-post-wrapper - width 98% + //width 98.7% max-width 900px - margin 0 auto border-radius 5px background $primary - 10% + margin-bottom: 40px + overflow hidden pre + margin 0 code font-family $monoType padding 5px @@ -217,6 +219,7 @@ display inline-block width 100% max-width 900px + min-height 200px /** ------------------------------- diff --git a/src/styles/main/_structure.styl b/src/styles/main/_structure.styl index 91467e6..012f9d5 100644 --- a/src/styles/main/_structure.styl +++ b/src/styles/main/_structure.styl @@ -70,6 +70,7 @@ svg.icons a text-decoration-color $highlight + font-weight: 400 label#the-title font-size 1.2em