cleaned up dependecies, initiated db-less post editing methodology

This commit is contained in:
Ro 2019-11-23 16:09:37 -08:00
parent d536871fd4
commit 7897a8bca9
20 changed files with 87 additions and 285 deletions

View file

@ -1,5 +1,4 @@
import DateUtils from '../../../src/com/utils/DateUtils';
import Pages from '../../data/Book';
import Book from '../../data/Book';
import StringUtils from '../../../src/com/utils/StringUtils';
import * as DataEvent from '../../../src/com/events/DataEvent';
import sanitize from 'sanitize-html';
@ -13,14 +12,11 @@ const router = express.Router();
const multer = require('multer');
const md = require('markdown-it')('commonmark');
const fs = require('fs-extra');
const dateUtils = new DateUtils();
const moment = require('moment');
const rightsManager = new RightsManager();
const pagesUtil = new Pages();
const uploadPath =
'./public/assets/images/blog/' +
dateUtils.getDate('year', new Date()) +
'/' +
dateUtils.getDate('month', new Date());
const book = new Book();
const uploadPath = './public/assets/images/blog/' + moment().format('YYYY');
'/' + moment().format('MM');
const _ = require('lodash');
fs.ensureDir(uploadPath, () => {
//console.log(err) // => null
@ -47,7 +43,7 @@ var post_upload = multer({
Retrieve Pages
*/
router.get('/', (req, res) => {
pagesUtil.grab().then(result => {
book.getPage().then(result => {
res.json(result);
});
});

View file

@ -1,11 +1,10 @@
import DateUtils from '../../../src/com/utils/DateUtils';
import Book from '../../data/Book';
var express = require('express');
var router = express.Router();
var hljs = require('highlight.js/lib/highlight');
var hljs_md = require('highlight.js/lib/languages/markdown');
const express = require('express');
const router = express.Router();
const hljs = require('highlight.js/lib/highlight');
const hljs_md = require('highlight.js/lib/languages/markdown');
hljs.registerLanguage('markdown', hljs_md);
const dateUtils = new DateUtils();
const moment = require('moment');
const book = new Book();
//--------------------------
// POSTS
@ -39,12 +38,7 @@ router.get('/add/new', function(req, res) {
user_status: true,
welcome: 'New Post',
mode: 'admin',
date:
dateUtils.getDate('year', new Date()) +
'-' +
dateUtils.getDate('month', new Date()) +
'-' +
dateUtils.getDate('day', new Date()),
date: '',
status: ['false', 'false', 'false'],
edit: false
});
@ -61,13 +55,6 @@ router.get('/edit/:id', function(req, res) {
book.getPage(id)
.then(page => {
let pretty = hljs.highlight('markdown', page.content).value;
let sexydate =
dateUtils.getDate('year', page.metadata.created) +
'-' +
dateUtils.getDate('month', page.metadata.created) +
'-' +
dateUtils.getDate('day', page.metadata.created);
res.render('page-edit', {
id: page.metadata.id,
title: 'Edit Page',
@ -75,7 +62,7 @@ router.get('/edit/:id', function(req, res) {
welcome: 'Edit Page',
mode: 'admin',
page: page.metadata,
date: sexydate,
date: moment(page.metadata.created).format('YYYY MMM DD'),
colored: pretty,
feature: page.metadata.feature,
status: [

27
package-lock.json generated
View file

@ -5063,9 +5063,9 @@
}
},
"moment": {
"version": "2.22.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
"integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y="
"version": "2.24.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
},
"moment-timezone": {
"version": "0.5.26",
@ -6029,6 +6029,27 @@
"uuid": "^3.3.2"
}
},
"request-promise": {
"version": "4.2.5",
"resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.5.tgz",
"integrity": "sha512-ZgnepCykFdmpq86fKGwqntyTiUrHycALuGggpyCZwMvGaZWgxW6yagT0FHkgo5LzYvOaCNvxYwWYIjevSH1EDg==",
"requires": {
"bluebird": "^3.5.0",
"request-promise-core": "1.1.3",
"stealthy-require": "^1.1.1",
"tough-cookie": "^2.3.3"
},
"dependencies": {
"request-promise-core": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.3.tgz",
"integrity": "sha512-QIs2+ArIGQVp5ZYbWD5ZLCY29D5CfWizP8eWnm8FoGD1TX61veauETVQbrV60662V0oFBkrDOuaBI8XgtuyYAQ==",
"requires": {
"lodash": "^4.17.15"
}
}
}
},
"request-promise-core": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz",

View file

@ -40,6 +40,7 @@
"markdown-it": "^8.4.1",
"markdown-yaml-metadata-parser": "^2.0.3",
"memorystore": "^1.6.1",
"moment": "^2.24.0",
"morgan": "latest",
"multer": "latest",
"nodemailer": "latest",
@ -49,6 +50,7 @@
"pug": "latest",
"reframe.js": "^2.2.5",
"request": "^2.88.0",
"request-promise": "^4.2.5",
"sanitize-html": "^1.20.1",
"sequelize": "^4.44.3",
"sequelize-cli": "^5.5.1",

View file

@ -1,9 +1,10 @@
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from './utils/DataUtils';
import * as DataEvent from './events/DataEvent';
//import DashManager from './controllers/DashManager';
import DataUtils from './utils/DataUtils';
import Manager from './controllers/DashManager';
import request from 'request-promise';
import * as DataEvent from '../com/events/DataEvent';
//import DBUtils from '../../../../../brain/utils/tools/DBUtils';
const dataUtils = new DataUtils();
const utils = new DataUtils();
const settings = require('../../site/settings.json');
export default class Base {
//--------------------------
@ -22,7 +23,7 @@ export default class Base {
.getElementById('login-btn')
.addEventListener('click', e => this.handleLogin(e));
} else {
//let dm = new DashManager();
let manager = new Manager();
}
}
//--------------------------
@ -31,33 +32,23 @@ export default class Base {
handleLogin(e) {
e.stopPropagation();
e.preventDefault();
let authForm = dataUtils.formDataToJSON(document.getElementById('login'));
dataUtils
.request(
'/api/v1/auth/login',
DataEvent.AUTH_STATUS,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
authForm
)
.then(r => {
let response = JSON.parse(r.request['response']);
if (response.type === DataEvent.REQUEST_LAME) {
e.target.innerHTML = response.message;
setTimeout(() => {
e.target.innerHTML = 'TRY IT AGAIN, HOMIE';
}, 1500);
//console.log('NOPE', response.message);
//self.dashManager = new DashManager();
let authForm = utils.formDataToJSON(document.getElementById('login'));
request({
method: 'POST',
uri: settings.base_url + '/api/v1/auth/login',
body: authForm,
json: true
})
.then(res => {
if (res.type === DataEvent.REQUEST_LAME) {
e.target.innerHTML = res.message;
} else {
e.target.innerHTML = response.message;
setTimeout(() => {
window.location = '/@/dashboard';
}, 500);
window.location = '/@/dashboard';
}
})
.catch(err => {
//console.log(err);
//console.log('ERROR', err);
});
}
}

View file

@ -1,8 +1,5 @@
import DataUtils, {
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON
} from '../../../brain/utils/tools/DataUtils';
import * as DataEvent from '../../../brain/utils/events/DataEvent';
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/DataUtils';
import * as DataEvent from '../../../src/com/events/DataEvent';
export default class Mailer {
//--------------------------
// constructor

View file

@ -1,17 +1,12 @@
import DataUtils, {
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON
} from '../../../brain/utils/tools/DataUtils';
import DateUtils from '../../../brain/utils/tools/DateUtils';
import * as DataEvent from '../../../brain/utils/events/DataEvent';
import DBUtils from '../../../brain/utils/tools/DBUtils';
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.dateUtils = new DateUtils();
this.dbutils = new DBUtils();
}
//--------------------------

View file

@ -1,12 +1,8 @@
import DataUtils, {
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON
} from '../../../brain/utils/tools/DataUtils';
import StringUtils from '../../../brain/utils/tools/StringUtils';
import DateUtils from '../../../brain/utils/tools/DateUtils';
import DBUtils from '../../../brain/utils/tools/DBUtils';
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 '../../../brain/utils/events/DataEvent';
import * as DataEvent from '../events/DataEvent';
export default class PostActions {
//--------------------------
// constructor

View file

@ -1,16 +1,11 @@
import DataUtils, {
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON
} from '../../../brain/utils/tools/DataUtils';
import DateUtils from '../../../brain/utils/tools/DateUtils';
import * as DataEvent from '../../../brain/utils/events/DataEvent';
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/DataUtils';
import * as DataEvent from '../../../src/com/events/DataEvent';
export default class SettingsActions {
//--------------------------
// constructor
//--------------------------
constructor() {
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
}
//--------------------------
// methods

View file

@ -19,7 +19,7 @@ export default class DashManager {
chooseDisplay(section, page) {
this.currentDisplay = '';
switch (section) {
case 'posts':
case 'page':
this.currentDisplay = new PostIndex(page);
break;
case 'settings':

View file

@ -1,5 +1,5 @@
import NavActions from '../actions/NavActions';
import DBUtils from '../../../brain/utils/tools/DBUtils';
import DBUtils from '../../../src/com/utils/DBUtils';
export default class NavIndex {
//--------------------------
// constructor

View file

@ -1,15 +1,11 @@
//TOOLS
import DataUtils, {
REQUEST_TYPE_POST,
CONTENT_TYPE_FORM
} from '../../../brain/utils/tools/DataUtils';
import * as DataEvent from '../../../brain/utils/events/DataEvent';
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_FORM } from '../../../src/com/utils/DataUtils';
import * as DataEvent from '../../../src/com/events/DataEvent';
import PostActions from '../actions/PostActions';
import * as EditorEvent from '../../../brain/utils/events/EditorEvent';
import * as EditorEvent from '../../../src/com/events/EditorEvent';
import TinyDatePicker from 'tiny-date-picker';
import DateUtils from '../../../brain/utils/tools/DateUtils';
import TextEditor from '../../../brain/utils/ui/TextEditor';
import DBUtils, { FINAL_KEY } from '../../../brain/utils/tools/DBUtils';
import TextEditor from '../../../src/com/ui/TextEditor';
import DBUtils, { FINAL_KEY } from '../../../src/com/utils/DBUtils';
export default class PostEditor {
//TODO - FIX POST FEATURE URLS IN DB
@ -19,7 +15,6 @@ export default class PostEditor {
constructor() {
let self = this;
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
this.urlPieces = document.URL.split('/');
this.dbUtils = new DBUtils();
this.post = [];

View file

@ -1,9 +1,6 @@
import SettingsActions from '../actions/SettingsActions';
import DataUtils, {
REQUEST_TYPE_POST,
CONTENT_TYPE_FORM
} from '../../../brain/utils/tools/DataUtils';
import * as DataEvent from '../../../brain/utils/events/DataEvent';
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_FORM } from '../../../src/com/utils/DataUtils';
import * as DataEvent from '../../../src/com/events/DataEvent';
import Mailer from '../actions/Mailer';
export default class SettingsIndex {
//--------------------------

View file

@ -1,8 +1,7 @@
import * as DataEvent from '../../../brain/tools/events/DataEvent';
import DateUtils from '../../../brain/tools/utils/DateUtils';
import * as DataEvent from '../events/DataEvent';
import { position } from 'caret-pos';
import EventEmitter from '../../../brain/tools/events/EventEmitter';
import * as EditorEvent from '../../../brain/tools/events/EditorEvent';
import EventEmitter from '../events/EventEmitter';
import * as EditorEvent from '../events/EditorEvent';
class TextEditor extends EventEmitter {
/**
* Text Editor UI Component

View file

@ -1,5 +1,5 @@
'use strict';
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../tools/DataUtils';
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from './DataUtils';
import Dexie from 'dexie';
import * as DataEvent from '../events/DataEvent';
export var COUNT;

View file

@ -1,27 +0,0 @@
class DOMUtils {
//--------------------------
// constructor
//--------------------------
constructor() {}
//--------------------------
// methods
//--------------------------
getWindowXY() {
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight || e.clientHeight || g.clientHeight;
var dimensions = {
windowHeight: y,
windowWidth: x
};
return dimensions;
}
//--------------------------
// event handlers
//--------------------------
}
export default DOMUtils;

View file

@ -5,7 +5,7 @@ export const REQUEST_TYPE_DELETE = 'DELETE';
export const CONTENT_TYPE_JSON = 'json';
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
import EventEmitter from '../events/EventEmitter';
class DataUtils extends EventEmitter {
export default class DataUtils extends EventEmitter {
//--------------------------
// constructor
//--------------------------
@ -15,46 +15,7 @@ class DataUtils extends EventEmitter {
//--------------------------
// methods
//--------------------------
request(
requestURL,
eventType,
requestType = REQUEST_TYPE_GET,
contentType = CONTENT_TYPE_JSON,
requestData = null
) {
var self = this;
return new Promise(function(resolve, reject) {
var request = new XMLHttpRequest();
request.upload.onprogress = self.handleLoadProgress;
request.open(requestType, requestURL, true);
request.onload = () => {
if (request.status == 200) {
resolve({
request,
eventType
});
} else {
reject({
request,
eventType
});
}
};
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
switch (contentType) {
case CONTENT_TYPE_JSON:
request.setRequestHeader('Content-type', 'application/' + contentType);
request.send(JSON.stringify(requestData));
break;
case CONTENT_TYPE_FORM:
request.send(requestData);
break;
}
} else {
request.send();
}
});
}
imgLoad(url) {
'use strict';
// Create new promise with the Promise() constructor;
@ -141,4 +102,3 @@ class DataUtils extends EventEmitter {
//console.log(percentComplete);
}
}
export default DataUtils;

View file

@ -1,102 +0,0 @@
class DateUtils {
//--------------------------
// constructor
//--------------------------
constructor() {}
//--------------------------
// methods
//--------------------------
getMKtime() {
var time =
new Date(
new Date().getFullYear(),
new Date().getMonth(),
new Date().getDate(),
new Date().getHours(),
new Date().getMinutes(),
new Date().getSeconds(),
0
).getTime() / 1000;
return time;
}
convertMKtime(seconds) {
var date = new Date(seconds * 1000);
return date;
}
getDate(type, rawdate) {
var day =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getUTCDate())
: String(new Date().getUTCDate());
var month =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getUTCMonth() + 1)
: String(new Date().getUTCMonth() + 1);
var year =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getUTCFullYear())
: String(new Date().getUTCFullYear());
var hour =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getUTCHours())
: String(new Date().getUTCHours());
var minute =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getUTCMinutes())
: String(new Date().getUTCMinutes());
var seconds =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getUTCSeconds())
: String(new Date().getUTCSeconds());
var millisecond =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getUTCMilliseconds())
: String(new Date().getUTCMilliseconds());
var offset =
rawdate != null || rawdate != ''
? String(new Date(rawdate).getTimezoneOffset())
: String(new Date().getTimezoneOffset());
if (day.length == 1) day = String('0' + day);
if (month.length == 1) month = String('0' + month);
offset = String(offset / 60);
if (offset.length == 1) offset = String('0' + offset);
switch (type) {
case 'day':
return day;
case 'month':
return month;
case 'year':
return year;
case 'stamp':
return String(
year +
'-' +
month +
'-' +
day +
' ' +
hour +
':' +
minute +
':' +
seconds +
'.' +
millisecond +
'-' +
offset
);
default:
return String(year + '-' + month + '-' + day);
}
}
//--------------------------
// event handlers
//--------------------------
}
export default DateUtils;

View file

@ -105,7 +105,7 @@
background $primary - 15%
border-radius 3px 0 0 3px
display inline-block
padding 2.9px
padding 5.2px
color $secondary
#post-options

View file

@ -13,7 +13,7 @@ a
color $secondary + 10%
svg.icons
width 30px
width 25px
fill $secondary
#loader