fixed post image uploading, cleaned up text editor styles (FINALLY), plugged in error page renderererer

This commit is contained in:
Ro 2019-11-25 16:51:35 -08:00
parent 84542228a3
commit 532748f688
9 changed files with 66 additions and 29 deletions

View file

@ -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;

View file

@ -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');

8
brain/views/error.pug Normal file
View file

@ -0,0 +1,8 @@
extends frame
block main-content
#error-index
br
label#message Ok, so this is... awkward
br
label#error= error

View file

@ -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")

View file

@ -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(() => {

View file

@ -47,6 +47,12 @@
-------------------------------
* */
@import 'main/_settings'
/**
-------------------------------
-- Error
-------------------------------
* */
@import 'main/_error'
/**
-------------------------------
-- Navigation

View file

@ -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

View file

@ -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
/**
-------------------------------

View file

@ -70,6 +70,7 @@ svg.icons
a
text-decoration-color $highlight
font-weight: 400
label#the-title
font-size 1.2em