From 849c5e2ac0b08666ff344adffb79706beea190d9 Mon Sep 17 00:00:00 2001 From: Ro Date: Sun, 24 Nov 2019 12:23:01 -0800 Subject: [PATCH] switched to web safe fonts for now, streamline file uploads, now tracking upload progress. --- brain/api/v1/auth.js | 6 +++++- brain/api/v1/pages.js | 12 +++++++++--- brain/views/page-edit.pug | 1 + src/com/Base.js | 2 +- src/com/actions/NavActions.js | 2 -- src/com/actions/PostActions.js | 5 +---- src/com/controllers/NavIndex.js | 2 -- src/com/controllers/PostEditor.js | 28 +++++++++++++++++++++++++-- src/com/events/DataEvent.js | 32 ++++++++++--------------------- src/com/utils/DataUtils.js | 3 +-- src/styles/main/_forms.styl | 16 ++++++++-------- src/styles/main/_index.styl | 2 +- src/styles/main/_posts.styl | 12 ++++++------ src/styles/main/_typography.styl | 3 ++- 14 files changed, 71 insertions(+), 55 deletions(-) diff --git a/brain/api/v1/auth.js b/brain/api/v1/auth.js index 1d2f336..466f7d0 100644 --- a/brain/api/v1/auth.js +++ b/brain/api/v1/auth.js @@ -40,7 +40,11 @@ router.post('/login', function(req, res) { let session = req.session; session.user = found; session.token = token; - res.json({ type: DataEvent.REQUEST_GOOD, message: 'Yes', token: session.token }); + res.json({ + type: DataEvent.REQUEST_GOOD, + message: 'Welcome Back', + token: session.token + }); } else { res.json({ type: DataEvent.REQUEST_LAME, diff --git a/brain/api/v1/pages.js b/brain/api/v1/pages.js index 87c7448..0089f88 100644 --- a/brain/api/v1/pages.js +++ b/brain/api/v1/pages.js @@ -15,11 +15,10 @@ const fs = require('fs-extra'); const moment = require('moment'); const rightsManager = new RightsManager(); const book = new Book(); -const uploadPath = './public/assets/images/blog/' + moment().format('YYYY'); -'/' + moment().format('MM'); +const uploadPath = + './public/assets/images/blog/' + moment().format('YYYY') + '/' + moment().format('MM'); const _ = require('lodash'); fs.ensureDir(uploadPath, () => { - //console.log(err) // => null // dir has now been created, including the directory it is to be placed in }); var storage = multer.diskStorage({ @@ -48,4 +47,11 @@ router.get('/', (req, res) => { }); }); +/*** + Update Page +*/ +router.post('/write', feature_upload, (req, res) => { + console.log('FILEZ BRAH', req.files); +}); + module.exports = router; diff --git a/brain/views/page-edit.pug b/brain/views/page-edit.pug index 83e959e..9743c9e 100644 --- a/brain/views/page-edit.pug +++ b/brain/views/page-edit.pug @@ -17,6 +17,7 @@ block main-content -post_date = date -post_status = status + form#test-form #post-edit-index(data-index=id) #post-edit-index-wrapper //h2 EDIT diff --git a/src/com/Base.js b/src/com/Base.js index fb10426..1a87de7 100644 --- a/src/com/Base.js +++ b/src/com/Base.js @@ -21,7 +21,7 @@ export default class Base { .getElementById('login-btn') .addEventListener('click', e => this.handleLogin(e)); } else { - //let dm = new DashManager(); + let manager = new DashManager(); } } //-------------------------- diff --git a/src/com/actions/NavActions.js b/src/com/actions/NavActions.js index 3743388..c5e1734 100644 --- a/src/com/actions/NavActions.js +++ b/src/com/actions/NavActions.js @@ -1,13 +1,11 @@ import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/DataUtils'; import * as DataEvent from '../../../src/com/events/DataEvent'; -import DBUtils from '../../../src/com/utils/DBUtils'; export default class NavActions { //-------------------------- // constructor //-------------------------- constructor() { this.dataUtils = new DataUtils(); - this.dbutils = new DBUtils(); } //-------------------------- // methods diff --git a/src/com/actions/PostActions.js b/src/com/actions/PostActions.js index 33a8d31..dcc4b97 100644 --- a/src/com/actions/PostActions.js +++ b/src/com/actions/PostActions.js @@ -1,16 +1,13 @@ import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../utils/DataUtils'; import StringUtils from '../utils/StringUtils'; -import DBUtils from '../utils/DBUtils'; -var uuidv4 = require('uuid/v4'); import * as DataEvent from '../events/DataEvent'; +var uuidv4 = require('uuid/v4'); export default class PostActions { //-------------------------- // constructor //-------------------------- constructor() { this.dataUtils = new DataUtils(); - this.dateUtils = new DateUtils(); - this.dbUtils = new DBUtils(); } //-------------------------- // methods diff --git a/src/com/controllers/NavIndex.js b/src/com/controllers/NavIndex.js index 8d9f65c..8783c09 100644 --- a/src/com/controllers/NavIndex.js +++ b/src/com/controllers/NavIndex.js @@ -1,5 +1,4 @@ import NavActions from '../actions/NavActions'; -import DBUtils from '../../../src/com/utils/DBUtils'; export default class NavIndex { //-------------------------- // constructor @@ -7,7 +6,6 @@ export default class NavIndex { constructor() { this.start(); //this.dataUtils = new DataUtils(); - this.dbutils = new DBUtils(); } //-------------------------- // methods diff --git a/src/com/controllers/PostEditor.js b/src/com/controllers/PostEditor.js index 9898afc..ef12da3 100644 --- a/src/com/controllers/PostEditor.js +++ b/src/com/controllers/PostEditor.js @@ -5,6 +5,7 @@ import PostActions from '../actions/PostActions'; import * as EditorEvent from '../../../src/com/events/EditorEvent'; import TinyDatePicker from 'tiny-date-picker'; import TextEditor from '../../../src/com/ui/TextEditor'; +const data = new DataUtils(); export default class PostEditor { //TODO - FIX POST FEATURE URLS IN DB @@ -130,6 +131,27 @@ export default class PostEditor { }); break; case EditorEvent.EDITOR_UPDATE: + var pageData = new FormData(); + pageData.append('name', 'HAMMOCK LANSING'); + var image = document.getElementById('featured-image-upload').files[0]; + if (image != null || image != undefined) { + pageData.append('feature_image', image, image.name); + } + + data.request( + '/api/v1/page/write', + DataEvent.API_PAGE_WRITE, + REQUEST_TYPE_POST, + CONTENT_TYPE_FORM, + pageData + ) + .then(r => { + console.log('RESPONSE', r); + }) + .catch(err => { + console.log('ERROR', err); + }); + /** new PostActions() .update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY) .then(() => { @@ -138,6 +160,7 @@ export default class PostEditor { .catch(() => { //console.log("ERRORZ", err) }); + */ break; case EditorEvent.EDITOR_DELETE: if (confirm("Aye! You know you're deleting this post, right?")) { @@ -198,9 +221,11 @@ 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) { @@ -224,8 +249,7 @@ export default class PostEditor { ? imageData.append('feature_image', file, file.name) : imageData.append('post_image', file, file.name); } - this.dataUtils - .request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData) + 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) diff --git a/src/com/events/DataEvent.js b/src/com/events/DataEvent.js index 5dbebde..f7c88fe 100644 --- a/src/com/events/DataEvent.js +++ b/src/com/events/DataEvent.js @@ -2,14 +2,7 @@ export const REQUEST_GOOD = 'requestGood'; export const REQUEST_LAME = 'requestLame'; export const IMG_REQUEST_GOOD = 'imgRequestGood'; export const IMG_REQUEST_LAME = 'imgRequestLame'; -export const SETTINGS_LOADED = 'dataLoaded'; -export const HTML_LOADED = 'htmlLoaded'; -export const ARCHIVES_JSON_LOADED = 'archivesJSONLoaded'; -export const ARCHIVES_PAGE_LOADED = 'archivesPAGELoaded'; -export const ARCHIVES_ENTRY_LOADED = 'archivesEntryLoaded'; -export const PROJECT_UPDATED = 'projectUpdated'; -export const PROJECT_ADDED = 'projectAdded'; -export const PROJECTS_SORTED = 'projectsSorted'; +export const SETTINGS_LOADED = 'settingsLoaded'; export const POST_IMAGE_ADDED = 'postImageAdded'; export const FEATURE_IMAGE_ADDED = 'featureImageAdded'; export const POST_ERROR = 'postError'; @@ -17,21 +10,16 @@ export const POST_ADDED = 'postAdded'; export const POST_UPDATED = 'postUpdated'; export const POST_DELETED = 'postImageAdded'; export const POSTS_SYNCED = 'postsSynced'; -export const LOCAL_DB_READY = 'localDBReady'; export const SETTINGS_UPDATED = 'settingsUpdated'; export const AVATAR_UPLOADED = 'avatarUploaded'; export const SITE_BACKGROUND_UPLOADED = 'siteBackgroundUploaded'; -class DataEvent -{ - - //-------------------------- - // methods - //-------------------------- - - - - //-------------------------- - // event handlers - //-------------------------- +export const API_PAGE_WRITE = 'writingItDown'; +class DataEvent { + //-------------------------- + // methods + //-------------------------- + //-------------------------- + // event handlers + //-------------------------- } -export default new DataEvent +export default new DataEvent(); diff --git a/src/com/utils/DataUtils.js b/src/com/utils/DataUtils.js index 2d49f79..1461902 100644 --- a/src/com/utils/DataUtils.js +++ b/src/com/utils/DataUtils.js @@ -137,8 +137,7 @@ export default class DataUtils extends EventEmitter { //-------------------------- // event handlers //-------------------------- - handleLoadProgress() { + handleLoadProgress(e) { //var percentComplete = Math.ceil((e.loaded / e.total) * 100); - //console.log(percentComplete); } } diff --git a/src/styles/main/_forms.styl b/src/styles/main/_forms.styl index c9181fc..a7218a4 100644 --- a/src/styles/main/_forms.styl +++ b/src/styles/main/_forms.styl @@ -5,7 +5,7 @@ input[type=email], input[type=password], input[type=text] border 0 border-radius 3px padding 5px - font 1em 'Apercu-Mono' + font 1em $monoType display inline-block background-color $primary - 60% color $secondary @@ -14,19 +14,19 @@ textarea border 0 border-radius 3px color $type02 - font 15px 'Apercu-Mono' + font 15px $monoType button, input[type=submit] background $highlight color $primary - 60% - font 1em 'Apercu-Mono' + font 1em $monoType border-radius 3px position relative cursor pointer border 0 select - font 1em 'Apercu-Mono' + font 1em $monoType border 1px solid $secondary -webkit-appearance none -moz-appearance none @@ -35,19 +35,19 @@ select color $primary ::-webkit-input-placeholder - font 1em 'Apercu-Mono' + font 1em $monoType color $secondary :-moz-placeholder /* Firefox 18- */ - font 1em 'Apercu-Mono' + font 1em $monoType color $secondary ::-moz-placeholder /* Firefox 19+ */ - font 1em 'Apercu-Mono' + font 1em $monoType color $secondary :-ms-input-placeholder - font 1em 'Apercu-Mono' + font 1em $monoType color $secondary diff --git a/src/styles/main/_index.styl b/src/styles/main/_index.styl index 8be08e3..cc00271 100644 --- a/src/styles/main/_index.styl +++ b/src/styles/main/_index.styl @@ -117,7 +117,7 @@ float right vertical-align top display inline-block - font-family 'Apercu-mono' + font-family $monoType font-size 0.5em padding 7px color $primary - 60% diff --git a/src/styles/main/_posts.styl b/src/styles/main/_posts.styl index 996ad24..14d83d5 100644 --- a/src/styles/main/_posts.styl +++ b/src/styles/main/_posts.styl @@ -53,7 +53,7 @@ display inline-block vertical-align top font-size 0.8em - font-family 'Apercu-Mono' + font-family $monoType width 50% padding 0 0 0 10px @@ -83,7 +83,7 @@ #post-title #post_title background $primary - 4% - font-family 'Apercu' + font-family $baseType width 97.6% height 140px font-size 1.5em @@ -95,7 +95,7 @@ background $primary - 10% border-radius 0 3px 3px 0 width 39.5% - font-family 'Apercu' + font-family $baseType color $highlight height 30px vertical-align top @@ -145,7 +145,7 @@ #post-meta #post_tags background $primary - 4% - font-family 'Apercu' + font-family $baseType width 97.6% height 140px color $secondary @@ -167,7 +167,7 @@ background $primary - 50% color $primary vertical-align middle - font-family 'Apercu-Mono' + font-family $monoType label cursor pointer @@ -202,7 +202,7 @@ pre code - font-family 'Apercu-Mono' + font-family $monoType padding 5px border-radius 5px line-height 1.6em diff --git a/src/styles/main/_typography.styl b/src/styles/main/_typography.styl index 3788c75..d06b037 100644 --- a/src/styles/main/_typography.styl +++ b/src/styles/main/_typography.styl @@ -99,7 +99,8 @@ url('fonts/Apercu-Mono.ttf') format('truetype'), url('fonts/Apercu-Mono.svg?#Apercu') format('svg') -$baseType = 'Apercu', Helvetica, Arial, sans-serif; +$baseType = Helvetica, Arial, sans-serif; +$monoType = 'Andale Mono' h1, h2, h3 color $white