plugged in prettier and eslint, deep cleaned code base

This commit is contained in:
Ro 2019-02-27 11:17:51 -05:00
parent cc19e14a25
commit 5decfa92e2
34 changed files with 2597 additions and 2886 deletions

69
.eslintrc Normal file
View file

@ -0,0 +1,69 @@
{
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {}
},
"rules": {
"constructor-super": 2,
"for-direction": 2,
"getter-return": 2,
"no-case-declarations": 2,
"no-class-assign": 2,
"no-compare-neg-zero": 2,
"no-cond-assign": 2,
"no-console": 2,
"no-const-assign": 2,
"no-constant-condition": 2,
"no-control-regex": 1,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty": 2,
"no-empty-character-class": 2,
"no-empty-pattern": 2,
"no-ex-assign": 2,
"no-extra-boolean-cast": 2,
"no-extra-semi": 2,
"no-fallthrough": 2,
"no-func-assign": 2,
"no-global-assign": 2,
"no-inner-declarations": 2,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-mixed-spaces-and-tabs": 2,
"no-new-symbol": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-self-assign": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-undef": 2,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"no-unsafe-finally": 2,
"no-unsafe-negation": 2,
"no-unused-labels": 2,
"no-unused-vars": 2,
"no-useless-escape": 1,
"require-yield": 2,
"use-isnan": 2,
"valid-typeof": 2,
"no-duplicate-imports": 2
},
"env": {
"node": true,
"browser": true,
"es6": true
},
"globals": {
"_": false,
"hljs": false,
"Sortable": false
}
}

5
.prettierignore Normal file
View file

@ -0,0 +1,5 @@
.babelrc
README.md
*.pug
*.styl

17
.prettierrc Normal file
View file

@ -0,0 +1,17 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": true,
"parser": "babel",
"proseWrap": "preserve",
"requirePragma": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"useTabs": true,
"tabWidth": 4,
"printWidth": 100
}

View file

@ -2,20 +2,11 @@ import DateUtils from '../../tools/utilities/DateUtils';
import StringUtils from '../../tools/utilities/StringUtils'; import StringUtils from '../../tools/utilities/StringUtils';
import * as DataEvent from '../../tools/events/DataEvent'; import * as DataEvent from '../../tools/events/DataEvent';
import sanitize from 'sanitize-html'; import sanitize from 'sanitize-html';
import RightsManager, import RightsManager, {
{
TASK_CREATE, TASK_CREATE,
TASK_UPDATE, TASK_UPDATE,
TASK_READ,
TASK_DELETE,
OBJECT_CLIENT_ADMIN,
OBJECT_CLIENT_USER,
OBJECT_PROJECT_CLIENT,
OBJECT_PROJECT_FOLIO,
OBJECT_BOOKMARK,
OBJECT_POST OBJECT_POST
} } from '../../tools/utilities/RightsManager';
from '../../tools/utilities/RightsManager';
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const multer = require('multer'); const multer = require('multer');
@ -24,224 +15,179 @@ const fs = require('fs-extra');
const Models = require('../../models'); const Models = require('../../models');
const dateUtils = new DateUtils(); const dateUtils = new DateUtils();
const rightsManager = new RightsManager(); const rightsManager = new RightsManager();
const uploadPath = "./content/blog-images/" + dateUtils.getDate('year', new Date()) + "/" + dateUtils.getDate('month', new Date()); const uploadPath =
'./content/blog-images/' +
dateUtils.getDate('year', new Date()) +
'/' +
dateUtils.getDate('month', new Date());
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const Op = Sequelize.Op; const Op = Sequelize.Op;
const _ = require('lodash'); const _ = require('lodash');
fs.ensureDir(uploadPath, function(err) fs.ensureDir(uploadPath, () => {
{
//console.log(err) // => null //console.log(err) // => null
// dir has now been created, including the directory it is to be placed in // dir has now been created, including the directory it is to be placed in
}) });
var storage = multer.diskStorage( var storage = multer.diskStorage({
{ destination: function(req, file, cb) {
destination: function(req, file, cb) cb(null, uploadPath);
{
cb(null, uploadPath)
}, },
filename: function(req, file, cb) filename: function(req, file, cb) {
{
var splice = file.originalname.split(':'); var splice = file.originalname.split(':');
cb(null, splice[0]); cb(null, splice[0]);
} }
}); });
var feature_upload = multer( var feature_upload = multer({
{
storage: storage storage: storage
}).array('feature_image'); }).array('feature_image');
var post_upload = multer( var post_upload = multer({
{
storage: storage storage: storage
}).array('post_image'); }).array('post_image');
//** SYNC POSTS */ //** SYNC POSTS */
router.post("/sync", (req, res, next) => router.post('/sync', (req, res) => {
{
let payload = req.body; let payload = req.body;
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ if (rightsManager.check(user.role, OBJECT_POST, TASK_UPDATE)) {
if (rightsManager.check(user.role, OBJECT_POST, TASK_UPDATE)) for (let index = 0; index < payload.length; index++) {
{
for (let index = 0; index < payload.length; index++)
{
const item = payload[index]; const item = payload[index];
Models.FreshPost.findOne( Models.FreshPost.findOne({
{ where: {
where: post: {
{ [Op.contains]: {
"post":
{
[Op.contains]:
{
uuid: item.post.uuid uuid: item.post.uuid
} }
} }
} }
}).then(found => })
{ .then(found => {
let buffed = sanitize(item.post.plaintext, let buffed = sanitize(item.post.plaintext, {
{ allowedTags: ['del', 'a', 'iframe', 'img'],
allowedTags: ['del', 'a', 'iframe', 'img', ], allowedAttributes: {
allowedAttributes:
{
a: ['href', 'name', 'target'], a: ['href', 'name', 'target'],
img: ['src'], img: ['src'],
iframe: ['height', 'width', 'src', 'frameborder', 'allow', 'allowfullscreen'] iframe: [
'height',
'width',
'src',
'frameborder',
'allow',
'allowfullscreen'
]
} }
}) });
buffed = new StringUtils().decodeHTML(buffed); buffed = new StringUtils().decodeHTML(buffed);
item.post.plaintext = buffed; item.post.plaintext = buffed;
item.post.html = md.render(buffed, item.post.html = md.render(buffed, {
{
html: true, html: true,
xhtmlOut: true, xhtmlOut: true
}); });
if (!_.isEqual(item.post, found.post)) if (!_.isEqual(item.post, found.post)) {
{ found
found.update(item).then(updated => .update(item)
{ .then(() => {
console.log("UPDATED", updated); //console.log('UPDATED', updated);
}).catch(err =>
{
//console.log("***ERROR***", err);
}) })
} .catch(() => {
else //console.log("***ERROR***", err);
{ });
} else {
//chilld //chilld
} }
}).catch(err => })
{ .catch(() => {
//console.log("***ERRRORZ****", err); //console.log("***ERRRORZ****", err);
Models.FreshPost.create(item).then(fresh => Models.FreshPost.create(item).then(() => {
{
//console.log(fresh) //console.log(fresh)
}) });
})
}
res.json(
{
message: "postsSynced"
}); });
} }
else res.json({
{ message: 'postsSynced'
res.json( });
{ } else {
res.json({
message: "Nah. You can't do that. Talk to the admin, sport." message: "Nah. You can't do that. Talk to the admin, sport."
}); });
} }
}); });
});
router.get('/json', function(req, res) {
Models.FreshPost.findAll({
order: [['id', 'DESC']]
}) })
router.get('/json', function(req, res, next) .then(function(posts) {
{
Models.FreshPost.findAll(
{
order: [
['id', 'DESC']
]
}).then(function(posts)
{
let newlist = []; let newlist = [];
for (let index = 0; index < posts.length; index++) for (let index = 0; index < posts.length; index++) {
{
let item = posts[index].post; let item = posts[index].post;
if (typeof item.deleted == 'undefined' || item.deleted == false) if (typeof item.deleted == 'undefined' || item.deleted == false) {
{ newlist.push(posts[index]);
newlist.push(posts[index]) } else {
} continue;
else
{
continue
} }
} }
res.json(newlist) res.json(newlist);
}).catch(function(err) })
{ .catch(() => {
//next(err); //next(err);
}) });
}) });
/*** /***
POST IMAGE POST IMAGE
*/ */
router.post('/add-post-image', function(req, res, next) router.post('/add-post-image', function(req, res) {
{
//console.log(req.body); //console.log(req.body);
if (!req.session.user) return res.json( if (!req.session.user)
{ return res.json({
message: "You need to be logged in, champ." message: 'You need to be logged in, champ.'
}); });
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) post_upload(req, res, function(err) {
{ if (err) {
post_upload(req, res, function(err)
{
if (err)
{
//console.log('Error in Saving Entry: ' + err); //console.log('Error in Saving Entry: ' + err);
res.json( res.json({
{
message: err message: err
}); });
throw err; throw err;
} } else {
else
{
var postImage = req.files[0].path; var postImage = req.files[0].path;
return res.json( return res.json({
{
message: DataEvent.POST_IMAGE_ADDED, message: DataEvent.POST_IMAGE_ADDED,
url: postImage.substr(7, postImage.length) url: postImage.substr(7, postImage.length)
}); });
} }
}); });
} } else {
else res.json({
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport." message: "Nah. You can't do that. Talk to the admin, sport."
}); });
} }
}); });
}); });
router.post('/add-feature-image', function(req, res, next) router.post('/add-feature-image', function(req, res) {
{
//console.log(req.body); //console.log(req.body);
if (!req.session.user) return res.json( if (!req.session.user)
{ return res.json({
message: "You need to be logged in, champ." message: 'You need to be logged in, champ.'
}); });
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) feature_upload(req, res, function(err) {
{ if (err) {
feature_upload(req, res, function(err)
{
if (err)
{
//console.log('Error in Saving Entry: ' + err); //console.log('Error in Saving Entry: ' + err);
res.json( res.json({
{
message: err message: err
}); });
throw err; throw err;
} } else {
else
{
var postImage = req.files[0].path; var postImage = req.files[0].path;
return res.json( return res.json({
{
message: DataEvent.FEATURE_IMAGE_ADDED, message: DataEvent.FEATURE_IMAGE_ADDED,
url: postImage.substr(7, postImage.length) url: postImage.substr(7, postImage.length)
}); });
} }
}); });
} } else {
else res.json({
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport." message: "Nah. You can't do that. Talk to the admin, sport."
}); });
} }

View file

@ -1,21 +1,11 @@
import DateUtils from '../../tools/utilities/DateUtils'; import DateUtils from '../../tools/utilities/DateUtils';
import StringUtils from '../../tools/utilities/StringUtils';
import * as DataEvent from '../../tools/events/DataEvent'; import * as DataEvent from '../../tools/events/DataEvent';
import RightsManager, import RightsManager, {
{
TASK_CREATE, TASK_CREATE,
TASK_UPDATE, TASK_UPDATE,
TASK_READ,
TASK_DELETE,
OBJECT_CLIENT_ADMIN,
OBJECT_CLIENT_USER,
OBJECT_PROJECT_CLIENT,
OBJECT_PROJECT_FOLIO,
OBJECT_BOOKMARK,
OBJECT_POST, OBJECT_POST,
OBJECT_SETTINGS OBJECT_SETTINGS
} } from '../../tools/utilities/RightsManager';
from '../../tools/utilities/RightsManager';
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const multer = require('multer'); const multer = require('multer');
@ -23,62 +13,50 @@ const fs = require('fs-extra');
const Models = require('../../models'); const Models = require('../../models');
const dateUtils = new DateUtils(); const dateUtils = new DateUtils();
const rightsManager = new RightsManager(); const rightsManager = new RightsManager();
const uploadPath = "./content/user-images/" + dateUtils.getDate('year', new Date()) + "/" + dateUtils.getDate('month', new Date()); const uploadPath =
const Sequelize = require('sequelize'); './content/user-images/' +
const Op = Sequelize.Op; dateUtils.getDate('year', new Date()) +
const _ = require('lodash'); '/' +
fs.ensureDir(uploadPath, function(err) dateUtils.getDate('month', new Date());
{ fs.ensureDir(uploadPath, () => {
//console.log(err) // => null //console.log(err) // => null
// dir has now been created, including the directory it is to be placed in // dir has now been created, including the directory it is to be placed in
}) });
var storage = multer.diskStorage( var storage = multer.diskStorage({
{ destination: function(req, file, cb) {
destination: function(req, file, cb) cb(null, uploadPath);
{
cb(null, uploadPath)
}, },
filename: function(req, file, cb) filename: function(req, file, cb) {
{
var splice = file.originalname.split(':'); var splice = file.originalname.split(':');
cb(null, splice[0]); cb(null, splice[0]);
} }
}); });
var avatar_upload = multer( var avatar_upload = multer({
{
storage: storage storage: storage
}).array('avatar_upload'); }).array('avatar_upload');
var background_upload = multer( var background_upload = multer({
{
storage: storage storage: storage
}).array('background_upload'); }).array('background_upload');
//** SYNC POSTS */ //** SYNC POSTS */
router.post("/sync", (req, res, next) => router.post('/sync', (req, res) => {
{
let payload = req.body; let payload = req.body;
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) fs.readJson('config/site-settings.json')
{ .then(obj => {
fs.readJson('config/site-settings.json').then(obj => if (user.hande != payload.handle || user.email != payload.email) {
{ user.update({
if (user.hande != payload.handle || user.email != payload.email)
{
user.update(
{
handle: payload.handle, handle: payload.handle,
email: payload.email email: payload.email
}).then(updated =>
{
console.log("UPDATED")
}).catch(err =>
{
console.log("ERR", err);
}) })
} .then(() => {
else //console.log('UPDATED');
{ })
console.log("USER NOT UPDATED") .catch(() => {
//console.log('ERR', err);
});
} else {
//console.log('USER NOT UPDATED');
} }
obj.url = payload.url; obj.url = payload.url;
obj.title = payload.title; obj.title = payload.title;
@ -93,135 +71,107 @@ router.post("/sync", (req, res, next) =>
obj.email.smtp.password = payload.mailSettings.smtp.password; obj.email.smtp.password = payload.mailSettings.smtp.password;
obj.email.mailgun.domain = payload.mailSettings.mailgun.domain; obj.email.mailgun.domain = payload.mailSettings.mailgun.domain;
obj.email.mailgun['api-key'] = payload.mailSettings.mailgun.key; obj.email.mailgun['api-key'] = payload.mailSettings.mailgun.key;
fs.writeJson('config/site-settings.json', obj).then(() => fs.writeJson('config/site-settings.json', obj)
{ .then(() => {
res.json( res.json({
{
message: DataEvent.SETTINGS_UPDATED message: DataEvent.SETTINGS_UPDATED
}); });
}).catch(err =>
{
console.error(err)
}) })
}).catch(err => .catch(() => {
{ //console.error(err);
console.error(err) });
}) })
} .catch(() => {
else //console.error(err);
{ });
res.json( } else {
{ res.json({
message: "Nah. You can't do that. Talk to the admin, sport." message: "Nah. You can't do that. Talk to the admin, sport."
}); });
} }
}); });
}) });
router.get('/nav', function(req, res, next) router.get('/nav', function(req, res) {
{ fs.readJson('config/site-settings.json')
fs.readJson('config/site-settings.json').then(obj => .then(obj => {
{ fs.writeJson('config/site-settings.json', obj)
fs.writeJson('config/site-settings.json', obj).then(() => .then(() => {
{
res.json(obj.menu); res.json(obj.menu);
}).catch(err =>
{
console.error(err)
})
}).catch(err =>
{
console.error(err)
}) })
.catch(() => {
//console.error(err);
});
}) })
.catch(() => {
//console.error(err);
});
});
router.post("/nav-sync", (req, res, next) => router.post('/nav-sync', (req, res) => {
{
let payload = req.body; let payload = req.body;
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) {
if (rightsManager.check(user.role, OBJECT_SETTINGS, TASK_UPDATE)) fs.readJson('config/site-settings.json')
{ .then(obj => {
fs.readJson('config/site-settings.json').then(obj =>
{
obj.menu = payload; obj.menu = payload;
fs.writeJson('config/site-settings.json', obj).then(() => fs.writeJson('config/site-settings.json', obj)
{ .then(() => {
res.json( res.json({
{
message: DataEvent.SETTINGS_UPDATED message: DataEvent.SETTINGS_UPDATED
}); });
}).catch(err =>
{
console.error(err)
}) })
}).catch(err => .catch(() => {
{ //console.error(err);
console.error(err) });
}) })
} .catch(() => {
else //console.error(err);
{ });
res.json( } else {
{ res.json({
message: "Nah. You can't do that. Talk to the admin, sport." message: "Nah. You can't do that. Talk to the admin, sport."
}); });
} }
}); });
}) });
/*** /***
UPLOAD AVATAR UPLOAD AVATAR
*/ */
router.post('/add-avatar', function(req, res, next) router.post('/add-avatar', function(req, res) {
{
//console.log(req.body); //console.log(req.body);
if (!req.session.user) return res.json( if (!req.session.user)
{ return res.json({
message: "You need to be logged in, champ." message: 'You need to be logged in, champ.'
}); });
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) avatar_upload(req, res, function(err) {
{ if (err) {
avatar_upload(req, res, function(err) res.json({
{
if (err)
{
res.json(
{
message: err message: err
}); });
throw err; throw err;
} } else {
else
{
var avatar = req.files[0].path; var avatar = req.files[0].path;
user.update( user.update({
{
avatar: avatar.substr(7, avatar.length) avatar: avatar.substr(7, avatar.length)
}).then(updated =>
{
req.session.user = updated;
}).catch(err =>
{
console.log("ERR", err);
}) })
return res.json( .then(updated => {
{ req.session.user = updated;
})
.catch(() => {
//console.log('ERR', err);
});
return res.json({
message: DataEvent.AVATAR_UPLOADED, message: DataEvent.AVATAR_UPLOADED,
url: avatar.substr(7, avatar.length) url: avatar.substr(7, avatar.length)
}); });
} }
}); });
} } else {
else res.json({
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport." message: "Nah. You can't do that. Talk to the admin, sport."
}); });
} }
@ -230,42 +180,30 @@ router.post('/add-avatar', function(req, res, next)
/*** /***
UPLOAD FEATURE BACKGROUND UPLOAD FEATURE BACKGROUND
*/ */
router.post('/add-feature-background', function(req, res, next) router.post('/add-feature-background', function(req, res) {
{
//console.log(req.body); //console.log(req.body);
if (!req.session.user) return res.json( if (!req.session.user)
{ return res.json({
message: "You need to be logged in, champ." message: 'You need to be logged in, champ.'
}); });
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) {
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE)) background_upload(req, res, function(err) {
{ if (err) {
background_upload(req, res, function(err) res.json({
{
if (err)
{
res.json(
{
message: err message: err
}); });
throw err; throw err;
} } else {
else
{
var bgImage = req.files[0].path; var bgImage = req.files[0].path;
return res.json( return res.json({
{
message: DataEvent.SITE_BACKGROUND_UPLOADED, message: DataEvent.SITE_BACKGROUND_UPLOADED,
url: bgImage.substr(7, bgImage.length) url: bgImage.substr(7, bgImage.length)
}); });
} }
}); });
} } else {
else res.json({
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport." message: "Nah. You can't do that. Talk to the admin, sport."
}); });
} }

View file

@ -4,46 +4,42 @@ var nodemailer = require('nodemailer');
var mg = require('nodemailer-mailgun-transport'); var mg = require('nodemailer-mailgun-transport');
const fs = require('fs-extra'); const fs = require('fs-extra');
const pug = require('pug'); const pug = require('pug');
router.post('/', function(req, res, next) router.post('/', function(req, res) {
{ fs.readJson('config/site-settings.json')
fs.readJson('config/site-settings.json').then(settings => .then(settings => {
{ let transport = '';
let transport = '' var auth = '';
switch (settings.email.active) switch (settings.email.active) {
{ case 'option-smtp':
case "option-smtp": auth = {
var auth = {
host: settings.email.smtp.domain, host: settings.email.smtp.domain,
port: 587, port: 587,
secure: false, secure: false,
auth: auth: {
{ type: 'login',
type:"login",
email: settings.email.smtp, email: settings.email.smtp,
password: settings.email.smtp.password password: settings.email.smtp.password
} }
} };
transport = nodemailer.createTransport((auth)); transport = nodemailer.createTransport(auth);
break; break;
case "option-mg": case 'option-mg':
var auth = { auth = {
auth: auth: {
{
api_key: settings.email.mailgun['api-key'], api_key: settings.email.mailgun['api-key'],
domain: settings.email.mailgun.domain domain: settings.email.mailgun.domain
} }
} };
transport = nodemailer.createTransport(mg(auth)); transport = nodemailer.createTransport(mg(auth));
break break;
} }
let render = pug.compileFile('themes/dash/email/base.pug'); let render = pug.compileFile('themes/dash/email/base.pug');
let html = render( let html = render({
{
title: settings.title, title: settings.title,
header: "a note from " + settings.title, header: 'a note from ' + settings.title,
content: req.body.content, content: req.body.content,
footer: "powered by fipamo" footer: 'powered by fipamo'
}) });
transport.sendMail( transport.sendMail(
{ {
from: 'control@playvico.us', from: 'control@playvico.us',
@ -53,30 +49,26 @@ router.post('/', function(req, res, next)
html: html html: html
//You can use "text:" to send plain-text content. It's oldschool! //You can use "text:" to send plain-text content. It's oldschool!
//text: 'Mailgun rocks, pow pow!' //text: 'Mailgun rocks, pow pow!'
}, function(err, info) },
{ function(err, info) {
if (err) if (err) {
{ //console.log(err);
console.log(err) res.json({
res.json( message: 'MAIL ERROR',
{
message: "MAIL ERROR",
desc: err desc: err
}); });
} } else {
else //console.log(info);
{ res.json({
console.log(info) message: 'MAIL SENT',
res.json(
{
message: "MAIL SENT",
desc: info desc: info
}); });
} }
}); }
}).catch(err => );
{
console.error(err)
}) })
.catch(() => {
//console.error(err);
});
}); });
module.exports = router; module.exports = router;

View file

@ -1,9 +1,12 @@
module.exports = function(sequelize, DataTypes) { module.exports = function(sequelize, DataTypes) {
var FreshPost = sequelize.define('FreshPost', { var FreshPost = sequelize.define(
'FreshPost',
{
post: { post: {
type: DataTypes.JSONB type: DataTypes.JSONB
} }
}, { },
{
timestamps: false, timestamps: false,
// don't delete database entries but set the newly added attribute deletedAt // don't delete database entries but set the newly added attribute deletedAt
@ -27,7 +30,8 @@ module.exports = function (sequelize, DataTypes) {
// to the model and throw an OptimisticLockingError error when stale instances are saved. // to the model and throw an OptimisticLockingError error when stale instances are saved.
// Set to true or a string with the attribute name you want to use to enable. // Set to true or a string with the attribute name you want to use to enable.
version: false version: false
}); }
);
return FreshPost; return FreshPost;
}; };

View file

@ -15,10 +15,9 @@ if (config.use_env_variable) {
sequelize = new Sequelize(config.database, config.username, config.password, config); sequelize = new Sequelize(config.database, config.username, config.password, config);
} }
fs fs.readdirSync(__dirname)
.readdirSync(__dirname)
.filter(file => { .filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js'); return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js';
}) })
.forEach(file => { .forEach(file => {
const model = sequelize['import'](path.join(__dirname, file)); const model = sequelize['import'](path.join(__dirname, file));

View file

@ -1,76 +1,61 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const Models = require('../../models'); const Models = require('../../models');
const fs = require("fs-extra"); const fs = require('fs-extra');
const _ = require('lodash'); const _ = require('lodash');
var settings = []; var settings = [];
//-------------------------- //--------------------------
// SETTINGS // SETTINGS
//-------------------------- //--------------------------
router.get('/', function(req, res) router.get('/', function(req, res) {
{ fs.readJson('config/site-settings.json')
fs.readJson('config/site-settings.json').then(obj => .then(obj => {
{ settings = [];
settings = []
settings = obj; settings = obj;
}).catch(err =>
{
//console.error(err)
}) })
if (req.session.user) .catch(() => {
{ //console.error(err)
Models.User.findById(req.session.user.id).then((user) => });
{ if (req.session.user) {
Models.FreshPost.findAll( Models.User.findById(req.session.user.id).then(() => {
{ Models.FreshPost.findAll({
order: [ order: [['id', 'DESC']]
['id', 'DESC'] })
] .then(posts => {
}).then(posts => let pages = [];
{ if (settings.menu.length == 0) {
let pages = [] for (let index = 0; index < posts.length; index++) {
if (settings.menu.length == 0)
{
for (let index = 0; index < posts.length; index++)
{
let item = posts[index].post; let item = posts[index].post;
if (item.page == true || item.page == "true") pages.push( if (item.page == true || item.page == 'true')
{ pages.push({
id: posts[index].id, id: posts[index].id,
uuid: posts[index].post.uuid, uuid: posts[index].post.uuid,
title: posts[index].post.title, title: posts[index].post.title,
slug: posts[index].post.slug slug: posts[index].post.slug
}); });
} }
} } else {
else let newpages = [];
{
let newpages = []
pages = settings.menu; pages = settings.menu;
for (let index = 0; index < posts.length; index++) for (let index = 0; index < posts.length; index++) {
{
let item = posts[index].post; let item = posts[index].post;
if (item.page == true || item.page == "true") newpages.push( if (item.page == true || item.page == 'true')
{ newpages.push({
id: posts[index].id, id: posts[index].id,
uuid: posts[index].post.uuid, uuid: posts[index].post.uuid,
title: posts[index].post.title, title: posts[index].post.title,
slug: posts[index].post.slug slug: posts[index].post.slug
}); });
} }
for (let i = 0; i < newpages.length; i++) for (let i = 0; i < newpages.length; i++) {
{ if (
if (_.findIndex(pages, function(o) _.findIndex(pages, function(o) {
{
return o.id == newpages[i].id; return o.id == newpages[i].id;
}) != -1) }) != -1
{ ) {
//console.log("FOUND") //console.log("FOUND")
} } else {
else pages.push({
{
pages.push(
{
id: newpages[i].id, id: newpages[i].id,
uuid: newpages[i].uuid, uuid: newpages[i].uuid,
title: newpages[i].title, title: newpages[i].title,
@ -79,19 +64,16 @@ router.get('/', function(req, res)
} }
} }
} }
res.render('dash/navigation', res.render('dash/navigation', {
{
pages: pages, pages: pages,
title: 'Dashboard | Global Nav' title: 'Dashboard | Global Nav'
}); });
}).catch(err =>
{
console.log("ERROR", err)
}) })
}) .catch(() => {
} //console.log('ERROR', err);
else });
{ });
} else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
}); });

View file

@ -13,14 +13,12 @@ const dateUtils = new DateUtils();
//-------------------------- //--------------------------
router.get('/:page?', function(req, res) { router.get('/:page?', function(req, res) {
var pageNum = req.params.page; var pageNum = req.params.page;
if (pageNum == "" || pageNum == null) pageNum = 1; if (pageNum == '' || pageNum == null) pageNum = 1;
var offset = ((pageNum * 5) - 5);
if (req.session.user) { if (req.session.user) {
Models.FreshPost.findAll({ Models.FreshPost.findAll({
order: [ order: [['id', 'DESC']]
['id', 'DESC'] })
] .then(function(posts) {
}).then(function (posts) {
let all = []; let all = [];
let deleted = []; let deleted = [];
let published = []; let published = [];
@ -34,13 +32,13 @@ router.get('/:page?', function (req, res) {
if (item.page == 'true') pages.push(posts[index]); if (item.page == 'true') pages.push(posts[index]);
if (item.featured == 'true') featured.push(posts[index]); if (item.featured == 'true') featured.push(posts[index]);
} else { } else {
deleted.push(posts[index]) deleted.push(posts[index]);
} }
} }
var count = Math.round(all.length / 6); var count = Math.round(all.length / 6);
var pageItems = []; var pageItems = [];
var itemLimit = 6; var itemLimit = 6;
var rangeStart = (pageNum * itemLimit) - itemLimit; var rangeStart = pageNum * itemLimit - itemLimit;
for (var i = 0; i < itemLimit; i++) { for (var i = 0; i < itemLimit; i++) {
try { try {
if (all[i + rangeStart].id != null) { if (all[i + rangeStart].id != null) {
@ -53,7 +51,7 @@ router.get('/:page?', function (req, res) {
res.render('dash/posts-index', { res.render('dash/posts-index', {
title: 'Dashbord | Posts', title: 'Dashbord | Posts',
mode: 'admin', mode: 'admin',
welcome: "Your Posts", welcome: 'Your Posts',
items: pageItems, items: pageItems,
page_info: { page_info: {
all: all.length, all: all.length,
@ -66,11 +64,13 @@ router.get('/:page?', function (req, res) {
page_count: count, page_count: count,
user_status: true user_status: true
}); });
}).then(function (value) {
//console.log(value);
}).catch(function (err) {
//next(err);
}) })
.then(() => {
//console.log(value);
})
.catch(() => {
//next(err);
});
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
@ -83,7 +83,12 @@ router.get('/add/new', function (req, res) {
res.render('dash/post-edit', { res.render('dash/post-edit', {
title: 'Make New Post', title: 'Make New Post',
mode: 'admin', mode: 'admin',
date: dateUtils.getDate('year', new Date()) + "-" + dateUtils.getDate('month', new Date()) + "-" + dateUtils.getDate('day', new Date()), date:
dateUtils.getDate('year', new Date()) +
'-' +
dateUtils.getDate('month', new Date()) +
'-' +
dateUtils.getDate('day', new Date()),
status: ['false', 'false', 'false'], status: ['false', 'false', 'false'],
edit: false edit: false
}); });
@ -98,17 +103,24 @@ router.get('/edit/:id', function (req, res) {
if (req.session.user) { if (req.session.user) {
Models.FreshPost.findOne({ Models.FreshPost.findOne({
where: { where: {
"post": { post: {
[Op.contains]: { [Op.contains]: {
uuid: req.params.id uuid: req.params.id
} }
} }
} }
}).then(item => { })
.then(item => {
let featured = 'null'; let featured = 'null';
if (item.post.feature != null || item.post.feature != '') featured = item.post.feature.substr(8, item.post.feature.length); if (item.post.feature != null || item.post.feature != '')
featured = item.post.feature.substr(8, item.post.feature.length);
let pretty = hljs.highlight('markdown', item.post.plaintext).value; let pretty = hljs.highlight('markdown', item.post.plaintext).value;
let sexydate = dateUtils.getDate('year', item.post.created) + "-" + dateUtils.getDate('month', item.post.created) + "-" + dateUtils.getDate('day', item.post.created) let sexydate =
dateUtils.getDate('year', item.post.created) +
'-' +
dateUtils.getDate('month', item.post.created) +
'-' +
dateUtils.getDate('day', item.post.created);
res.render('dash/post-edit', { res.render('dash/post-edit', {
id: item.id, id: item.id,
title: 'Edit Post', title: 'Edit Post',
@ -118,14 +130,20 @@ router.get('/edit/:id', function (req, res) {
colored: pretty, colored: pretty,
html: item.post.plaintext, html: item.post.plaintext,
feature: featured, feature: featured,
status: [String(item.post.page), String(item.post.featured), String(item.post.published)], status: [
String(item.post.page),
String(item.post.featured),
String(item.post.published)
],
edit: true edit: true
}); });
}).then(function (value) {
//console.log("VALUE: " + value);
}).catch(function (err) {
//console.log(err);
}) })
.then(() => {
//console.log("VALUE: " + value);
})
.catch(() => {
//console.log(err);
});
} else { } else {
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }

View file

@ -2,55 +2,48 @@ const express = require('express');
const router = express.Router(); const router = express.Router();
const FileHound = require('filehound'); const FileHound = require('filehound');
const Models = require('../../models'); const Models = require('../../models');
const fs = require("fs-extra"); const fs = require('fs-extra');
var settings = []; var settings = [];
//-------------------------- //--------------------------
// SETTINGS // SETTINGS
//-------------------------- //--------------------------
router.get('/', function(req, res) router.get('/', function(req, res) {
{ fs.readJson('config/site-settings.json')
fs.readJson('config/site-settings.json').then(obj => .then(obj => {
{
settings = obj; settings = obj;
}).catch(err => })
{ .catch(() => {
//console.error(err) //console.error(err)
})
let themes = [];
FileHound.create().paths('themes').ext('json').find().then(files =>
{
files.forEach(file =>
{
fs.readJson(file).then(theme =>
{
if (theme.name == settings.theme)
{
themes.push(
{
theme: theme,
current: "true"
})
}
else
{
themes.push(
{
theme: theme,
current: "false"
})
}
}).catch(err =>
{
//console.error(err)
})
}); });
if (req.session.user) let themes = [];
{ FileHound.create()
.paths('themes')
.ext('json')
.find()
.then(files => {
files.forEach(file => {
fs.readJson(file)
.then(theme => {
if (theme.name == settings.theme) {
themes.push({
theme: theme,
current: 'true'
});
} else {
themes.push({
theme: theme,
current: 'false'
});
}
})
.catch(() => {
//console.error(err)
});
});
if (req.session.user) {
let memberInfo = []; let memberInfo = [];
Models.User.findById(req.session.user.id).then((user) => Models.User.findById(req.session.user.id).then(user => {
{ memberInfo.push({
memberInfo.push(
{
handle: user.handle, handle: user.handle,
email: user.email, email: user.email,
avi: user.avatar avi: user.avatar
@ -58,19 +51,16 @@ router.get('/', function(req, res)
themes.sort(function(a, b) { themes.sort(function(a, b) {
var textA = a.theme.name.toUpperCase(); var textA = a.theme.name.toUpperCase();
var textB = b.theme.name.toUpperCase(); var textB = b.theme.name.toUpperCase();
return (textA < textB) ? -1 : (textA > textB) ? 1 : 0; return textA < textB ? -1 : textA > textB ? 1 : 0;
}); });
res.render('dash/settings', res.render('dash/settings', {
{
title: 'Dashboard | Settings', title: 'Dashboard | Settings',
themes: themes, themes: themes,
settings: settings, settings: settings,
member: memberInfo[0] member: memberInfo[0]
}); });
}) });
} } else {
else
{
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
} }
}); });

View file

@ -5,92 +5,76 @@ const bCrypt = require('bcrypt-nodejs');
//-------------------------- //--------------------------
// Index // Index
//-------------------------- //--------------------------
router.get('/', function(req, res) router.get('/', function(req, res) {
{ var loggedIn = false;
var loggedIn = false
if (req.session.user) loggedIn = true; if (req.session.user) loggedIn = true;
Models.FreshPost.findAll( Models.FreshPost.findAll({
{ order: [['id', 'DESC']]
order: [ })
['id', 'DESC'] .then(function(posts) {
]
}).then(function(posts)
{
let title = 'Fipamo Admin'; let title = 'Fipamo Admin';
(!loggedIn) ? welcome = "Hello." : welcome = "Welcome back, "+req.session.user.handle let welcome = ''(!loggedIn)
? (welcome = 'Hello.')
: (welcome = 'Welcome back, ' + req.session.user.handle);
let filtered = []; let filtered = [];
for (let index = 0; index < posts.length; index++) for (let index = 0; index < posts.length; index++) {
{
let item = posts[index].post; let item = posts[index].post;
if (typeof item.deleted == 'undefined' || item.deleted == false) if (typeof item.deleted == 'undefined' || item.deleted == false) {
{ filtered.push(posts[index]);
filtered.push(posts[index]) } else {
} continue;
else
{
continue
} }
} }
res.render('dash/index', res.render('dash/index', {
{
title: title, title: title,
welcome: welcome, welcome: welcome,
user_status: loggedIn, user_status: loggedIn,
items: filtered items: filtered
}); });
}).then(function(value)
{
//console.log(value);
}).catch(function(err)
{
//next(err);
}) })
.then(() => {
//console.log(value);
})
.catch(() => {
//next(err);
});
}); });
//-------------------------- //--------------------------
// Login // Login
//-------------------------- //--------------------------
/* Handle Login POST */ /* Handle Login POST */
router.post('/login', function(req, res, next) router.post('/login', function(req, res) {
{ Models.User.findOne({
Models.User.findOne( where: {
{
where:
{
handle: req.body.handle handle: req.body.handle
} }
}).then(user => })
{ .then(user => {
if (!isValidPassword(user, req.body.password)) if (!isValidPassword(user, req.body.password)) {
{ return res.json({
return res.json(
{
message: 'CHECK YOUR PASSWORD' message: 'CHECK YOUR PASSWORD'
}); });
} }
let session = req.session; let session = req.session;
session.user = user; session.user = user;
res.redirect('/@/dashboard'); res.redirect('/@/dashboard');
}).catch(err => })
{ .catch(() => {
return res.json( return res.json({
{
message: 'NOT FOUND, HAWS' message: 'NOT FOUND, HAWS'
}); });
}) });
}); });
//-------------------------- //--------------------------
// Logout // Logout
//-------------------------- //--------------------------
router.post('/logout', function(req, res, next) router.post('/logout', function(req, res) {
{
req.logout(); req.logout();
return res.json( return res.json({
{
message: 'LOGGED OUT' message: 'LOGGED OUT'
}); });
}); });
module.exports = router; module.exports = router;
var isValidPassword = function(user, password) var isValidPassword = function(user, password) {
{
return bCrypt.compareSync(password, user.password); return bCrypt.compareSync(password, user.password);
} };

View file

@ -1,23 +0,0 @@
import EventEmitter from '../events/EventEmitter';
class Animate extends EventEmitter {
//--------------------------
// constructor
//--------------------------
constructor() {
super();
}
//--------------------------
// methods
//--------------------------
object(properties) {
var animation = anime(
properties
);
//animation.start(properties);
}
//--------------------------
// event handlers
//--------------------------
}
export default Animate

View file

@ -1,70 +0,0 @@
class TexEffects {
//--------------------------
// constructor
//--------------------------
constructor() {}
//--------------------------
// methods
//--------------------------
scramble(obj, offset, complete)
{
var scrambleText = new ScrambleText(obj, {
timeOffset: offset,
chars: [
'安',
'以',
'宇',
'衣',
'於',
'加',
'幾',
'久',
'計',
'己',
'左',
'之',
'寸',
'世',
'曽',
'太',
'知',
'川',
'天',
'止',
'奈',
'仁',
'奴',
'称',
'乃',
'波',
'比',
'不',
'部',
'保',
'末',
'美',
'武',
'女',
'毛',
'也',
'為',
'由',
'恵',
'与',
'良',
'利',
'留',
'礼',
'呂',
'和',
'遠',
'无'
],
callback: complete
}).start();
}
//--------------------------
// event handlers
//--------------------------
}
export default TexEffects

View file

@ -3,17 +3,12 @@ export const EDITOR_UPLOAD_POST_IMAGE = 'editorUploadImage';
export const EDITOR_SAVE = 'editorSave'; export const EDITOR_SAVE = 'editorSave';
export const EDITOR_UPDATE = 'editorUpdate'; export const EDITOR_UPDATE = 'editorUpdate';
class EditorEvent class EditorEvent {
{
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
} }
export default new EditorEvent export default new EditorEvent();

View file

@ -1,11 +1,8 @@
class EventEmitter class EventEmitter {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
this.listeners = new Map(); this.listeners = new Map();
} }
//-------------------------- //--------------------------
@ -26,9 +23,7 @@ class EventEmitter
if (listeners && listeners.length) { if (listeners && listeners.length) {
index = listeners.reduce((i, listener, index) => { index = listeners.reduce((i, listener, index) => {
return (isFunction(listener) && listener === callback) return isFunction(listener) && listener === callback ? (i = index) : i;
? i = index
: i;
}, -1); }, -1);
if (index > -1) { if (index > -1) {
@ -43,7 +38,7 @@ class EventEmitter
emitEvent(label, ...args) { emitEvent(label, ...args) {
var listeners = this.listeners.get(label); var listeners = this.listeners.get(label);
if (listeners && listeners.length) { if (listeners && listeners.length) {
listeners.forEach((listener) => { listeners.forEach(listener => {
listener(...args); listener(...args);
}); });
return true; return true;
@ -54,4 +49,4 @@ class EventEmitter
// event handlers // event handlers
//-------------------------- //--------------------------
} }
export default EventEmitter export default EventEmitter;

View file

@ -1,10 +1,6 @@
import * as DataEvent from '../events/DataEvent'; import * as DataEvent from '../events/DataEvent';
import DateUtils from '../utilities/DateUtils'; import DateUtils from '../utilities/DateUtils';
import { import { position } from 'caret-pos';
position,
offset
}
from 'caret-pos';
import EventEmitter from '../events/EventEmitter'; import EventEmitter from '../events/EventEmitter';
import * as EditorEvent from '../events/EditorEvent'; import * as EditorEvent from '../events/EditorEvent';
class TextEditor extends EventEmitter { class TextEditor extends EventEmitter {
@ -25,14 +21,13 @@ class TextEditor extends EventEmitter {
this.fixLimit = scrollLimit; this.fixLimit = scrollLimit;
this.caretPos = null; this.caretPos = null;
this.url = ''; this.url = '';
let self = this;
this.setInputs(); this.setInputs();
window.addEventListener("scroll", f => { window.addEventListener('scroll', () => {
var fixLimit = this.fixLimit; var fixLimit = this.fixLimit;
if (window.pageYOffset >= fixLimit) { if (window.pageYOffset >= fixLimit) {
document.getElementById('edit-control').style.position = "fixed" document.getElementById('edit-control').style.position = 'fixed';
} else { } else {
document.getElementById('edit-control').style.position = "relative" document.getElementById('edit-control').style.position = 'relative';
} }
}); });
this.refresh(); this.refresh();
@ -50,19 +45,19 @@ class TextEditor extends EventEmitter {
this.textEditor.addEventListener('input', e => { this.textEditor.addEventListener('input', e => {
let htmlTagRe = /<[a-z][\s\S]*>/g; let htmlTagRe = /<[a-z][\s\S]*>/g;
let text = this.textEditor.innerText; let text = this.textEditor.innerText;
if (e.inputType == "insertParagraph") return //cursor setting gets weird on return, so just back out if (e.inputType == 'insertParagraph') return; //cursor setting gets weird on return, so just back out
if (text.search(htmlTagRe) > -1) { if (text.search(htmlTagRe) > -1) {
let caret = position(this.textEditor).pos; let caret = position(this.textEditor).pos;
self.refresh() self.refresh();
position(this.textEditor, caret); position(this.textEditor, caret);
} }
}) });
} }
refresh() { refresh() {
var spiffed = hljs.highlight('markdown', this.textEditor.innerText).value; var spiffed = hljs.highlight('markdown', this.textEditor.innerText).value;
spiffed = spiffed.replace(new RegExp('\r?\n', 'g'), '<br>'); spiffed = spiffed.replace(new RegExp('\r?\n', 'g'), '<br>');
var temp = document.createElement("div"); var temp = document.createElement('div');
temp.innerText = spiffed; temp.innerText = spiffed;
this.textEditor.innerHTML = temp.innerText; this.textEditor.innerHTML = temp.innerText;
this.textEditor.style.maxWidth = '900px'; this.textEditor.style.maxWidth = '900px';
@ -74,7 +69,7 @@ class TextEditor extends EventEmitter {
document.getElementById('submit-good').classList.remove('icon-hide'); document.getElementById('submit-good').classList.remove('icon-hide');
document.getElementById('edit-update').classList.remove('submit-start'); document.getElementById('edit-update').classList.remove('submit-start');
document.getElementById('edit-update').classList.add('submit-cool'); document.getElementById('edit-update').classList.add('submit-cool');
setTimeout(f => { setTimeout(() => {
document.getElementById('submit-update').classList.remove('icon-hide'); document.getElementById('submit-update').classList.remove('icon-hide');
document.getElementById('submit-good').classList.add('icon-hide'); document.getElementById('submit-good').classList.add('icon-hide');
document.getElementById('edit-update').classList.add('submit-start'); document.getElementById('edit-update').classList.add('submit-start');
@ -86,26 +81,27 @@ class TextEditor extends EventEmitter {
break; break;
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE: case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
position(this.textEditor, this.caretPos); position(this.textEditor, this.caretPos);
var sel, range, pulled; var sel, range;
//var pulled;
sel = window.getSelection(); //console.log(sel) sel = window.getSelection(); //console.log(sel)
//console.log(note.message) //console.log(note.message)
if (sel.rangeCount) { if (sel.rangeCount) {
range = sel.getRangeAt(0); range = sel.getRangeAt(0);
pulled = sel.getRangeAt(0).toString(); //pulled = sel.getRangeAt(0).toString();
range.deleteContents(); range.deleteContents();
range.insertNode(document.createTextNode("![image alt text](" + data + " 'image title')")); range.insertNode(
document.createTextNode('![image alt text](' + data + " 'image title')")
);
} }
this.refresh(); this.refresh();
break; break;
} }
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
handleEditorOption(e) { handleEditorOption(e) {
e.preventDefault(); e.preventDefault();
var self = this;
var sel, range, pulled; var sel, range, pulled;
sel = window.getSelection(); //console.log(sel) sel = window.getSelection(); //console.log(sel)
if (sel.rangeCount) { if (sel.rangeCount) {
@ -113,48 +109,48 @@ class TextEditor extends EventEmitter {
pulled = sel.getRangeAt(0).toString(); pulled = sel.getRangeAt(0).toString();
range.deleteContents(); range.deleteContents();
switch (e.target.id) { switch (e.target.id) {
case "edit-bold": case 'edit-bold':
range.insertNode(document.createTextNode("**" + pulled + "**")); range.insertNode(document.createTextNode('**' + pulled + '**'));
break; break;
case "edit-italic": case 'edit-italic':
range.insertNode(document.createTextNode("*" + pulled + "*")); range.insertNode(document.createTextNode('*' + pulled + '*'));
break; break;
case "edit-strikethrough": case 'edit-strikethrough':
range.insertNode(document.createTextNode("<del>" + pulled + "</del>")); range.insertNode(document.createTextNode('<del>' + pulled + '</del>'));
break; break;
case "edit-header1": case 'edit-header1':
range.insertNode(document.createTextNode("# " + pulled)); range.insertNode(document.createTextNode('# ' + pulled));
break; break;
case "edit-header2": case 'edit-header2':
range.insertNode(document.createTextNode("## " + pulled)); range.insertNode(document.createTextNode('## ' + pulled));
break; break;
case "edit-header3": case 'edit-header3':
range.insertNode(document.createTextNode("### " + pulled)); range.insertNode(document.createTextNode('### ' + pulled));
break; break;
case "edit-image": case 'edit-image':
this.caretPos = position(this.textEditor).pos; this.caretPos = position(this.textEditor).pos;
this.emitEvent(EditorEvent.EDITOR_UPLOAD_POST_IMAGE); this.emitEvent(EditorEvent.EDITOR_UPLOAD_POST_IMAGE);
break; break;
case "submit-save": case 'submit-save':
case "edit-save": case 'edit-save':
this.emitEvent(EditorEvent.EDITOR_SAVE); this.emitEvent(EditorEvent.EDITOR_SAVE);
break; break;
case "submit-update": case 'submit-update':
case "edit-update": case 'edit-update':
this.emitEvent(EditorEvent.EDITOR_UPDATE); this.emitEvent(EditorEvent.EDITOR_UPDATE);
break
case "edit-link":
range.insertNode(document.createTextNode("[" + pulled + "](PASTE URL HERE)"));
break; break;
case "edit-delete": case 'edit-link':
range.insertNode(document.createTextNode('[' + pulled + '](PASTE URL HERE)'));
break;
case 'edit-delete':
this.emitEvent(EditorEvent.EDITOR_DELETE); this.emitEvent(EditorEvent.EDITOR_DELETE);
break break;
default: default:
//range.insertNode(document.createTextNode("[" + self.url + "](PASTE URL HERE)")); //range.insertNode(document.createTextNode("[" + self.url + "](PASTE URL HERE)"));
break; break;
} }
} }
this.refresh() this.refresh();
} }
} }
export default TextEditor export default TextEditor;

View file

@ -1,202 +1,175 @@
"use strict"; 'use strict';
import DataUtils, import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../utilities/DataUtils';
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM
}
from '../utilities/DataUtils';
import Dexie from 'dexie'; import Dexie from 'dexie';
import * as DataEvent from '../events/DataEvent'; import * as DataEvent from '../events/DataEvent';
export var COUNT; export var COUNT;
export var FINAL_KEY; export var FINAL_KEY;
export default class DBUtils export default class DBUtils {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
/** /**
* NOTE: DB ERRORS REPLICATE. * NOTE: DB ERRORS REPLICATE.
* WHEN FIXING A BUG, FIX DATA WITH JSON BACKUP * WHEN FIXING A BUG, FIX DATA WITH JSON BACKUP
*/ */
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.db = new Dexie("fipamo_posts"); this.db = new Dexie('fipamo_posts');
this.db.version(1).stores( this.db.version(1).stores({
{
postList: 'id,post' postList: 'id,post'
}); });
this.db.postList.toArray(array => this.db.postList.toArray(array => {
{
COUNT = array.length; COUNT = array.length;
FINAL_KEY = array[COUNT - 1].id; FINAL_KEY = array[COUNT - 1].id;
}) });
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
modify(id, postData) modify(id, postData) {
{
let self = this; let self = this;
let freshID; let freshID;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ if (id == null) {
if (id == null) self.db.postList
{ .put(postData)
self.db.postList.put(postData).then(fresh => .then(fresh => {
{
freshID = fresh; freshID = fresh;
}).catch(e =>
{
let err = {
message: "PUT ERROR",
error: e
}
});
}
else
{
//console.log("UPDATED", postData);
self.db.postList.update(Number(id),
{
post: postData
}).then(updated =>
{}).catch(e =>
{
let err = {
message: "UPDATE ERROR",
error: e
}
});
}
self.db.postList.toArray(array =>
{
self.syncRemote(array, freshID).then(response =>
{
resolve(
{
response
}) })
}).catch(err => .catch(e => {
{ let err = {
reject( message: 'PUT ERROR',
{ error: e
};
return err;
});
} else {
//console.log("UPDATED", postData);
self.db.postList
.update(Number(id), {
post: postData
})
.then(() => {})
.catch(e => {
let err = {
message: 'UPDATE ERROR',
error: e
};
return err;
});
}
self.db.postList.toArray(array => {
self.syncRemote(array, freshID)
.then(response => {
resolve({
response
});
})
.catch(err => {
reject({
err err
}); });
}); });
}) });
}) });
} }
syncLocal(array) syncLocal(array) {
{
let self = this; let self = this;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ self.db.postList.clear().then(() => {
self.db.postList.clear().then(result => self.db.postList
{ .bulkAdd(array)
self.db.postList.bulkAdd(array).then(key => .then(() => {
{ self.db.postList.toArray(() => {
self.db.postList.toArray(array => let event = DataEvent.LOCAL_DB_READY;
{ resolve({
let event = DataEvent.LOCAL_DB_READY
resolve(
{
event event
});
});
}) })
}) .catch(Dexie.BulkError, e => {
}).catch(Dexie.BulkError, e => reject({
{
reject(
{
e e
}) });
}) });
}) });
}) });
} }
syncRemote(db, newPostId) syncRemote(db, newPostId) {
{
let self = this; let self = this;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ self.dataUtils
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, db).then((response) => .request(
{ '/api/post/sync',
DataEvent.POSTS_SYNCED,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
db
)
.then(response => {
let bounce = { let bounce = {
message: response, message: response,
newPost: newPostId newPost: newPostId
} };
resolve(bounce) resolve(bounce);
}).catch((err) => })
{ .catch(err => {
reject(err); reject(err);
}) });
}) });
} }
getPost(id) getPost(id) {
{
let self = this; let self = this;
if (id == null) if (id == null) {
{ return new Promise(function(resolve, reject) {
return new Promise(function(resolve, reject) self.db.postList
{ .toArray(array => {
self.db.postList.toArray(array => resolve(array);
{
resolve(array)
}).catch(err =>
{
reject(err)
})
})
}
else
{
return new Promise(function(resolve, reject)
{
self.db.postList.get(Number(id)).then(obj =>
{
resolve(obj)
}).catch(err =>
{
reject(err)
}) })
.catch(err => {
reject(err);
});
});
} else {
return new Promise(function(resolve, reject) {
self.db.postList
.get(Number(id))
.then(obj => {
resolve(obj);
}) })
.catch(err => {
reject(err);
});
});
} }
} }
archivePost(id, archive) archivePost(id, archive) {
{
let self = this; let self = this;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ self.db.postList
self.db.postList.update(Number(id), .update(Number(id), {
{
post: archive post: archive
}).then(deleted =>
{
self.db.postList.toArray(array =>
{
self.syncRemote(array, null).then(response =>
{
resolve(
{
response
}) })
}).catch(err => .then(() => {
{ self.db.postList.toArray(array => {
reject( self.syncRemote(array, null)
{ .then(response => {
resolve({
response
});
})
.catch(err => {
reject({
err err
}); });
}); });
})
}).catch(e =>
{
console.log("ERROR", e)
}); });
}) })
.catch(() => {
//console.log('ERROR', e);
});
});
} }
//-------------------------- //--------------------------
// event handlers // event handlers

View file

@ -1,16 +1,12 @@
class DOMUtils class DOMUtils {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {}
{}
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
getWindowXY() getWindowXY() {
{
var w = window, var w = window,
d = document, d = document,
e = d.documentElement, e = d.documentElement,
@ -21,11 +17,11 @@ class DOMUtils
var dimensions = { var dimensions = {
windowHeight: y, windowHeight: y,
windowWidth: x windowWidth: x
} };
return dimensions; return dimensions;
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
} }
export default DOMUtils export default DOMUtils;

View file

@ -1,97 +1,84 @@
export const REQUEST_TYPE_POST = "POST"; export const REQUEST_TYPE_POST = 'POST';
export const REQUEST_TYPE_GET = "GET"; export const REQUEST_TYPE_GET = 'GET';
export const REQUEST_TYPE_PUT = "PUT"; export const REQUEST_TYPE_PUT = 'PUT';
export const REQUEST_TYPE_DELETE = "DELETE"; export const REQUEST_TYPE_DELETE = 'DELETE';
export const CONTENT_TYPE_JSON = 'json'; export const CONTENT_TYPE_JSON = 'json';
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded'; export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
import EventEmitter from '../events/EventEmitter'; import EventEmitter from '../events/EventEmitter';
import * as DataEvent from '../events/DataEvent'; class DataUtils extends EventEmitter {
class DataUtils extends EventEmitter
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
super(); super();
var self = this;
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
request(requestURL, eventType, requestType = REQUEST_TYPE_GET, contentType = CONTENT_TYPE_JSON, requestData = null) request(
{ requestURL,
eventType,
requestType = REQUEST_TYPE_GET,
contentType = CONTENT_TYPE_JSON,
requestData = null
) {
var self = this; var self = this;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.upload.onprogress = self.handleLoadProgress; request.upload.onprogress = self.handleLoadProgress;
request.open(requestType, requestURL, true); request.open(requestType, requestURL, true);
request.onload = function(e) request.onload = () => {
{ if (request.status == 200) {
if (request.status == 200) resolve({
{ request,
resolve( eventType
{ });
} else {
reject({
request, request,
eventType eventType
}); });
} }
else
{
reject(
{
request,
eventType
});
}; };
}; if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) switch (contentType) {
{
switch (contentType)
{
case CONTENT_TYPE_JSON: case CONTENT_TYPE_JSON:
request.setRequestHeader("Content-type", "application/" + contentType); request.setRequestHeader('Content-type', 'application/' + contentType);
request.send(JSON.stringify(requestData)); request.send(JSON.stringify(requestData));
break; break;
case CONTENT_TYPE_FORM: case CONTENT_TYPE_FORM:
request.send(requestData); request.send(requestData);
break; break;
} }
} } else {
else
{
request.send(); request.send();
} }
}) });
} }
imgLoad(url) imgLoad(url) {
{
'use strict'; 'use strict';
// Create new promise with the Promise() constructor; // Create new promise with the Promise() constructor;
// This has as its argument a function with two parameters, resolve and reject // This has as its argument a function with two parameters, resolve and reject
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{
// Standard XHR to load an image // Standard XHR to load an image
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
request.open('GET', url); request.open('GET', url);
request.responseType = 'blob'; request.responseType = 'blob';
// When the request loads, check whether it was successful // When the request loads, check whether it was successful
request.onload = function() request.onload = function() {
{ if (request.status === 200) {
if (request.status === 200)
{
// If successful, resolve the promise by passing back the request response // If successful, resolve the promise by passing back the request response
resolve(request.response); resolve(request.response);
} } else {
else
{
// If it fails, reject the promise with a error message // If it fails, reject the promise with a error message
reject(new Error('Image didn\'t load successfully; error code:' + request.statusText)); reject(
new Error(
"Image didn't load successfully; error code:" + request.statusText
)
);
} }
}; };
request.onerror = function() request.onerror = function() {
{
// Also deal with the case when the entire request fails to begin with // Also deal with the case when the entire request fails to begin with
// This is probably a network error, so reject the promise with an appropriate message // This is probably a network error, so reject the promise with an appropriate message
reject(new Error('There was a network error.')); reject(new Error('There was a network error.'));
@ -100,20 +87,17 @@ class DataUtils extends EventEmitter
request.send(); request.send();
}); });
} }
loadImage(src) loadImage(src) {
{
'use strict'; 'use strict';
let self = this; let self = this;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{
// Get a reference to the body element, and create a new image object // Get a reference to the body element, and create a new image object
var body = document.querySelector('body'), var myImage = new Image();
myImage = new Image(); myImage.crossOrigin = ''; // or "anonymous"
myImage.crossOrigin = ""; // or "anonymous"
// Call the function with the URL we want to load, but then chain the // Call the function with the URL we want to load, but then chain the
// promise then() method on to the end of it. This contains two callbacks // promise then() method on to the end of it. This contains two callbacks
self.imgLoad(src).then(function(response) self.imgLoad(src).then(
{ function(response) {
// The first runs when the promise resolves, with the request.reponse specified within the resolve() method. // The first runs when the promise resolves, with the request.reponse specified within the resolve() method.
var imageURL = window.URL.createObjectURL(response); var imageURL = window.URL.createObjectURL(response);
resolve(imageURL); resolve(imageURL);
@ -121,18 +105,18 @@ class DataUtils extends EventEmitter
//console.log(imageURL); //console.log(imageURL);
//body.appendChild(myImage); //body.appendChild(myImage);
// The second runs when the promise is rejected, and logs the Error specified with the reject() method. // The second runs when the promise is rejected, and logs the Error specified with the reject() method.
}, function(Error) },
{ function(Error) {
reject(Error) reject(Error);
}); }
);
}); });
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
handleLoadProgress(e) handleLoadProgress() {
{ //var percentComplete = Math.ceil((e.loaded / e.total) * 100);
var percentComplete = Math.ceil((e.loaded / e.total) * 100);
//console.log(percentComplete); //console.log(percentComplete);
} }
} }

View file

@ -1,5 +1,4 @@
class DateUtils { class DateUtils {
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
@ -9,7 +8,16 @@ class DateUtils {
// methods // methods
//-------------------------- //--------------------------
getMKtime() { 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; 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; return time;
} }
@ -19,37 +27,70 @@ class DateUtils {
} }
getDate(type, rawdate) { getDate(type, rawdate) {
var day = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCDate()) : String(new Date().getUTCDate())); var day =
var month = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMonth() + 1) : String(new Date().getUTCMonth() + 1)); rawdate != null || rawdate != ''
var year = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCFullYear()) : String(new Date().getUTCFullYear())); ? String(new Date(rawdate).getUTCDate())
var hour = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCHours()) : String(new Date().getUTCHours())); : String(new Date().getUTCDate());
var minute = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMinutes()) : String(new Date().getUTCMinutes())); var month =
var seconds = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCSeconds()) : String(new Date().getUTCSeconds())); rawdate != null || rawdate != ''
var millisecond = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getUTCMilliseconds()) : String(new Date().getUTCMilliseconds())); ? String(new Date(rawdate).getUTCMonth() + 1)
var offset = ((rawdate != null || rawdate != '') ? String(new Date(rawdate).getTimezoneOffset()) : String(new Date().getTimezoneOffset())); : String(new Date().getUTCMonth() + 1);
if (day.length == 1) var year =
day = String("0" + day); rawdate != null || rawdate != ''
if (month.length == 1) ? String(new Date(rawdate).getUTCFullYear())
month = String("0" + month); : 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); offset = String(offset / 60);
if (offset.length == 1) if (offset.length == 1) offset = String('0' + offset);
offset = String("0" + offset);
switch (type) { switch (type) {
case "day": case 'day':
return day; return day;
break;
case "month": case 'month':
return month; return month;
break; case 'year':
case "year":
return year; return year;
break; case 'stamp':
case "stamp": return String(
return String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds + "." + millisecond + "-" + (offset)); year +
break '-' +
month +
'-' +
day +
' ' +
hour +
':' +
minute +
':' +
seconds +
'.' +
millisecond +
'-' +
offset
);
default: default:
return String(year + "-" + month + "-" + day); return String(year + '-' + month + '-' + day);
break;
} }
} }
@ -58,4 +99,4 @@ class DateUtils {
//-------------------------- //--------------------------
} }
export default DateUtils export default DateUtils;

View file

@ -1,158 +1,133 @@
export const roles = { export const roles = {
hnic: hnic: {
{ client_admin: {
"client_admin": create: true,
{ read: true,
"create": true, update: true,
"read": true, delete: true
"update": true,
"delete": true
}, },
"client_user": client_user: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
}, },
"client_project": client_project: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
}, },
"folio_project": folio_project: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
}, },
"bookmark": bookmark: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
}, },
"post": post: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
}, },
"settings": settings: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
} }
}, },
client: client: {
{ client_admin: {
"client_admin": create: false,
{ read: true,
"create": false, update: false,
"read": true, delete: false
"update": false,
"delete": false
}, },
"client_user": client_user: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
}, },
"client_project": client_project: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: false
"delete": false
}, },
"folio_project": folio_project: {
{ create: false,
"create": false, read: false,
"read": false, update: false,
"update": false, delete: false
"delete": false
} }
}, },
user: user: {
{ client_admin: {
"client_admin": create: false,
{ read: false,
"create": false, update: false,
"read": false, delete: false
"update": false,
"delete": false
}, },
"client_user": client_user: {
{ create: false,
"create": false, read: true,
"read": true, update: false,
"update": false, delete: false
"delete": false
}, },
"client_project": client_project: {
{ create: false,
"create": false, read: true,
"read": true, update: true,
"update": true, delete: false
"delete": false
}, },
"folio_project": folio_project: {
{ create: false,
"create": false, read: false,
"read": false, update: false,
"update": false, delete: false
"delete": false
}, },
"bookmark": bookmark: {
{ create: true,
"create": true, read: true,
"read": true, update: true,
"update": true, delete: true
"delete": true
}, },
"post": post: {
{ create: false,
"create": false, read: false,
"read": false, update: false,
"update": false, delete: false
"delete": false
} }
} }
}; };
export const TASK_CREATE = 'create' export const TASK_CREATE = 'create';
export const TASK_UPDATE = 'update' export const TASK_UPDATE = 'update';
export const TASK_READ = 'read' export const TASK_READ = 'read';
export const TASK_DELETE = 'delete' export const TASK_DELETE = 'delete';
export const OBJECT_CLIENT_ADMIN = 'client_admin' export const OBJECT_CLIENT_ADMIN = 'client_admin';
export const OBJECT_CLIENT_USER = 'client_user' export const OBJECT_CLIENT_USER = 'client_user';
export const OBJECT_PROJECT_CLIENT = 'client_project' export const OBJECT_PROJECT_CLIENT = 'client_project';
export const OBJECT_PROJECT_FOLIO = 'folio_project' export const OBJECT_PROJECT_FOLIO = 'folio_project';
export const OBJECT_BOOKMARK = 'bookmark' export const OBJECT_BOOKMARK = 'bookmark';
export const OBJECT_POST = 'post' export const OBJECT_POST = 'post';
export const OBJECT_SETTINGS = 'settings' export const OBJECT_SETTINGS = 'settings';
export default class RightsManager export default class RightsManager {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {}
{
var self = this;
}
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
check(role, object, task) check(role, object, task) {
{
//console.log(role + " *** " + object + " *** " + task); //console.log(role + " *** " + object + " *** " + task);
return roles[role][object][task]; return roles[role][object][task];
} }

View file

@ -1,17 +1,16 @@
class StringUtils class StringUtils {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {}
{}
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
cleanString(string) cleanString(string) {
{ var clean = string
var clean = string.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g, '').toLowerCase().replace(/[\/_| -]+/g, '-'); .replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g, '')
.toLowerCase()
.replace(/[\/_| -]+/g, '-');
return clean; return clean;
} }
@ -22,19 +21,23 @@ class StringUtils
if (typeof quote_style === 'undefined') { if (typeof quote_style === 'undefined') {
quote_style = 2; quote_style = 2;
} }
string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>'); string = string
.toString()
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>');
var OPTS = { var OPTS = {
'ENT_NOQUOTES': 0, ENT_NOQUOTES: 0,
'ENT_HTML_QUOTE_SINGLE': 1, ENT_HTML_QUOTE_SINGLE: 1,
'ENT_HTML_QUOTE_DOUBLE': 2, ENT_HTML_QUOTE_DOUBLE: 2,
'ENT_COMPAT': 2, ENT_COMPAT: 2,
'ENT_QUOTES': 3, ENT_QUOTES: 3,
'ENT_IGNORE': 4 ENT_IGNORE: 4
}; };
if (quote_style === 0) { if (quote_style === 0) {
noquotes = true; noquotes = true;
} }
if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags if (typeof quote_style !== 'number') {
// Allow for a single string or an array of string flags
quote_style = [].concat(quote_style); quote_style = [].concat(quote_style);
for (i = 0; i < quote_style.length; i++) { for (i = 0; i < quote_style.length; i++) {
// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
@ -62,4 +65,4 @@ class StringUtils
// event handlers // event handlers
//-------------------------- //--------------------------
} }
export default StringUtils export default StringUtils;

12
init.js
View file

@ -5,7 +5,7 @@
*/ */
var app = require('./brain/app'); var app = require('./brain/app');
var debug = require('debug')('thetwelfthhouse:server'); var debug = require('debug')('fipamo:server');
var http = require('http'); var http = require('http');
var models = require('./brain/models'); var models = require('./brain/models');
@ -30,7 +30,6 @@ server.listen(port);
server.on('error', onError); server.on('error', onError);
server.on('listening', onListening); server.on('listening', onListening);
models.sequelize.sync().then(function() { models.sequelize.sync().then(function() {
/** /**
* Listen on provided port, on all network interfaces. * Listen on provided port, on all network interfaces.
@ -42,7 +41,6 @@ models.sequelize.sync().then(function() {
server.on('listening', onListening); server.on('listening', onListening);
}); });
/** /**
* Normalize a port into a number, string, or false. * Normalize a port into a number, string, or false.
*/ */
@ -72,9 +70,7 @@ function onError(error) {
throw error; throw error;
} }
var bind = typeof port === 'string' ? var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
'Pipe ' + port :
'Port ' + port
// handle specific listen errors with friendly messages // handle specific listen errors with friendly messages
switch (error.code) { switch (error.code) {
@ -97,8 +93,6 @@ function onError(error) {
function onListening() { function onListening() {
var addr = server.address(); var addr = server.address();
var bind = typeof addr === 'string' ? var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
'pipe ' + addr :
'port ' + addr.port;
debug('Listening on ' + bind); debug('Listening on ' + bind);
} }

View file

@ -1,39 +1,37 @@
import DataUtils, import DataUtils, {
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE, CONTENT_TYPE_JSON
CONTENT_TYPE_JSON, } from '../../../../../brain//tools/utilities/DataUtils';
CONTENT_TYPE_FORM
}
from '../../../../../brain//tools/utilities/DataUtils';
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
export default class Mailer export default class Mailer {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
sendMail() sendMail() {
{
var self = this; var self = this;
let mailData = { let mailData = {
content: "This is a test email" content: 'This is a test email'
} };
self.dataUtils.request('/api/mail', DataEvent.SETTINGS_UPDATED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, mailData).then((response) => self.dataUtils
{ .request(
console.log(response) '/api/mail',
}).catch((err) => DataEvent.SETTINGS_UPDATED,
{ REQUEST_TYPE_POST,
console.log(err) CONTENT_TYPE_JSON,
mailData
)
.then(() => {
//console.log(response);
}) })
.catch(() => {
//console.log(err);
});
} }
//-------------------------- //--------------------------
// event handlers // event handlers

View file

@ -1,24 +1,15 @@
import DataUtils, import DataUtils, {
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE, CONTENT_TYPE_JSON
CONTENT_TYPE_JSON, } from '../../../../../brain//tools/utilities/DataUtils';
CONTENT_TYPE_FORM
}
from '../../../../../brain//tools/utilities/DataUtils';
import StringUtils from '../../../../../brain//tools/utilities/StringUtils';
import DateUtils from '../../../../../brain/tools/utilities/DateUtils'; import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
import DBUtils from '../../../../../brain/tools/utilities/DBUtils'; import DBUtils from '../../../../../brain/tools/utilities/DBUtils';
export default class NavActions export default class NavActions {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils(); this.dateUtils = new DateUtils();
this.dbutils = new DBUtils(); this.dbutils = new DBUtils();
@ -26,44 +17,44 @@ export default class NavActions
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
save() save() {
{
let self = this; let self = this;
let navData = []; let navData = [];
let items = document.getElementById('nav-pages').children; let items = document.getElementById('nav-pages').children;
for (let index = 0; index < items.length; index++) for (let index = 0; index < items.length; index++) {
{ navData.push({
navData.push(
{
title: items[index].getElementsByTagName('label')[0].innerHTML, title: items[index].getElementsByTagName('label')[0].innerHTML,
id: items[index].id, id: items[index].id,
slug: items[index].getAttribute('data-slug'), slug: items[index].getAttribute('data-slug'),
uuid: items[index].getAttribute('data-uuid') uuid: items[index].getAttribute('data-uuid')
}) });
} }
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ self.dataUtils
self.dataUtils.request('/api/settings/nav-sync', DataEvent.SETTINGS_UPDATED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, navData).then((response) => .request(
{ '/api/settings/nav-sync',
resolve(response) DataEvent.SETTINGS_UPDATED,
}).catch((err) => REQUEST_TYPE_POST,
{ CONTENT_TYPE_JSON,
navData
)
.then(response => {
resolve(response);
})
.catch(err => {
reject(err); reject(err);
}) });
}) });
} }
removeItem(id) removeItem(id) {
{
let self = this; let self = this;
this.dbutils.getPost(id).then(post => this.dbutils.getPost(id).then(post => {
{ post.post.page = 'false';
post.post.page = "false"; self.dbutils.modify(id, post.post).then(() => {
self.dbutils.modify(id, post.post).then(r =>
{
document.getElementById('nav-pages').removeChild(document.getElementById(id)); document.getElementById('nav-pages').removeChild(document.getElementById(id));
self.save() self.save();
}) });
}) });
} }
//-------------------------- //--------------------------
// event handlers // event handlers

View file

@ -1,25 +1,17 @@
import DataUtils, import DataUtils, {
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE, CONTENT_TYPE_JSON
CONTENT_TYPE_JSON, } from '../../../../../brain//tools/utilities/DataUtils';
CONTENT_TYPE_FORM
}
from '../../../../../brain//tools/utilities/DataUtils';
import StringUtils from '../../../../../brain//tools/utilities/StringUtils'; import StringUtils from '../../../../../brain//tools/utilities/StringUtils';
import DateUtils from '../../../../../brain/tools/utilities/DateUtils'; import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import DBUtils from '../../../../../brain/tools/utilities/DBUtils'; import DBUtils from '../../../../../brain/tools/utilities/DBUtils';
var uuidv4 = require('uuid/v4'); var uuidv4 = require('uuid/v4');
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
export default class PostActions export default class PostActions {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils(); this.dateUtils = new DateUtils();
this.dbUtils = new DBUtils(); this.dbUtils = new DBUtils();
@ -27,49 +19,48 @@ export default class PostActions
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
update(id, data, files, lastKey) update(id, data, files, lastKey) {
{
let self = this; let self = this;
let freshData; let freshData;
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ let txt = document.createElement('textarea');
let txt = document.createElement("textarea");
txt.innerHTML = document.getElementById('edit-post-text').innerHTML; txt.innerHTML = document.getElementById('edit-post-text').innerHTML;
let html = txt.value; let html = txt.value;
html = html.replace(/<\/?span[^>]*>/g, ""); //removes highightjs styling html = html.replace(/<\/?span[^>]*>/g, ''); //removes highightjs styling
html = html.replace(/<\/?br[^>]*>/g, "\n"); //convert back to encoded line break for storage html = html.replace(/<\/?br[^>]*>/g, '\n'); //convert back to encoded line break for storage
data.title = document.getElementById('post_title').value; data.title = document.getElementById('post_title').value;
data.slug = new StringUtils().cleanString(document.getElementById('post_title').value) data.slug = new StringUtils().cleanString(document.getElementById('post_title').value);
data.plaintext = html; data.plaintext = html;
data.html = html; data.html = html;
data.created = document.getElementById('post-date').value; data.created = document.getElementById('post-date').value;
data.tags = document.getElementById('post_tags').value; data.tags = document.getElementById('post_tags').value;
data.page = document.getElementById('option-page').getAttribute('data-active') data.page = document.getElementById('option-page').getAttribute('data-active');
data.featured = document.getElementById('option-feature').getAttribute('data-active') data.featured = document.getElementById('option-feature').getAttribute('data-active');
data.published = document.getElementById('option-published').getAttribute('data-active') data.published = document
if (files.length != 0) .getElementById('option-published')
{ .getAttribute('data-active');
for (var i = 0; i < files.length; i++) if (files.length != 0) {
{ for (var i = 0; i < files.length; i++) {
var file = files[i]; var file = files[i];
// Check the file type. // Check the file type.
if (!file.type.match('image.*')) if (!file.type.match('image.*')) {
{
continue; continue;
} }
data.feature = "/content/blog-images/" + self.dateUtils.getDate('year', new Date()) + "/" + self.dateUtils.getDate('month', new Date()) + "/" + file.name; data.feature =
'/content/blog-images/' +
self.dateUtils.getDate('year', new Date()) +
'/' +
self.dateUtils.getDate('month', new Date()) +
'/' +
file.name;
} }
} else {
if (typeof data.feature == 'undefined') data.feature = '';
} }
else if (id == null) {
{
if (typeof data.feature == 'undefined') data.feature = ""
}
if (id == null)
{
freshData = { freshData = {
id: lastKey + 1, id: lastKey + 1,
post: post: {
{
uuid: uuidv4(), uuid: uuidv4(),
title: data.title, title: data.title,
slug: data.slug, slug: data.slug,
@ -81,79 +72,81 @@ export default class PostActions
page: data.page, page: data.page,
featured: data.featured, featured: data.featured,
published: data.published, published: data.published,
deleted: "", deleted: '',
author: "user" author: 'user'
} }
} };
} } else {
else
{
freshData = data; freshData = data;
} }
self.dbUtils.modify(id, freshData).then((response) => self.dbUtils
{ .modify(id, freshData)
resolve(response) .then(response => {
if(id != null) (freshData.page == 'true') ? self.updateNav(true, id, freshData) : self.updateNav(false, id, freshData) resolve(response);
if (id != null)
}).catch((err) => freshData.page == 'true'
{ ? self.updateNav(true, id, freshData)
reject(err) : self.updateNav(false, id, freshData);
})
}) })
.catch(err => {
reject(err);
});
});
} }
deletePost(id, body) deletePost(id, body) {
{
let self = this; let self = this;
body.deleted = new Date().toString(); body.deleted = new Date().toString();
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ self.dbUtils
self.dbUtils.archivePost(id, body).then(response => .archivePost(id, body)
{ .then(response => {
console.log(response) //console.log(response);
resolve(response) resolve(response);
}).catch(err =>
{
console.log(err)
reject(error)
})
}) })
.catch(err => {
//console.log(err);
reject(err);
});
});
} }
updateNav(add, id, post) updateNav(add, id, post) {
{
var self = this; var self = this;
this.dataUtils.request('/api/settings/nav', DataEvent.SETTINGS_LOADED).then((response) => this.dataUtils
{ .request('/api/settings/nav', DataEvent.SETTINGS_LOADED)
.then(response => {
let menu = JSON.parse(response.request['response']); let menu = JSON.parse(response.request['response']);
let item = { let item = {
id: id, id: id,
uuid: post.uuid, uuid: post.uuid,
title: post.title, title: post.title,
slug: post.slug slug: post.slug
} };
if (add) if (add) {
{ menu.push(item);
menu.push(item) } else {
} for (let index = 0; index < menu.length; index++) {
else if (menu[index].id == id) {
{ menu.splice(index, 1);
for (let index = 0; index < menu.length; index++)
{
if (menu[index].id == id)
{
menu.splice(index, 1)
} }
} }
} }
self.dataUtils.request('/api/settings/nav-sync', DataEvent.SETTINGS_UPDATED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, menu).then((response) => self.dataUtils
{ .request(
console.log(response) '/api/settings/nav-sync',
}).catch((err) => DataEvent.SETTINGS_UPDATED,
{ REQUEST_TYPE_POST,
console.log(err) CONTENT_TYPE_JSON,
menu
)
.then(() => {
//console.log(response);
}) })
}).catch((err) => .catch(() => {
{ //console.log(err);
console.log(err); });
})
.catch(() => {
//console.log(err);
}); });
} }
//-------------------------- //--------------------------

View file

@ -1,31 +1,21 @@
import DataUtils, import DataUtils, {
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE, CONTENT_TYPE_JSON
CONTENT_TYPE_JSON, } from '../../../../../brain//tools/utilities/DataUtils';
CONTENT_TYPE_FORM
}
from '../../../../../brain//tools/utilities/DataUtils';
import StringUtils from '../../../../../brain//tools/utilities/StringUtils';
import DateUtils from '../../../../../brain/tools/utilities/DateUtils'; import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
export default class SettingsActions export default class SettingsActions {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils(); this.dateUtils = new DateUtils();
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
save() save() {
{
let self = this; let self = this;
let handle = document.getElementById('settings-handle').value; let handle = document.getElementById('settings-handle').value;
let email = document.getElementById('settings-email').value; let email = document.getElementById('settings-email').value;
@ -34,23 +24,23 @@ export default class SettingsActions
let desc = document.getElementById('settings-desc').innerHTML; let desc = document.getElementById('settings-desc').innerHTML;
let privacy = document.getElementById('privacy-toggle').getAttribute('data-private'); let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
let background = document.getElementById('background').src; let background = document.getElementById('background').src;
let selected = ""; let selected = '';
let selects = document.querySelectorAll('.theme-select'); let selects = document.querySelectorAll('.theme-select');
let smtpDomain = document.getElementById('smtp-domain').value; let smtpDomain = document.getElementById('smtp-domain').value;
let smtpEmail = document.getElementById('smtp-email').value; let smtpEmail = document.getElementById('smtp-email').value;
let smtpPass = document.getElementById('smtp-pass').value; let smtpPass = document.getElementById('smtp-pass').value;
let mgDomain = document.getElementById('mg-domain').value; let mgDomain = document.getElementById('mg-domain').value;
let mgKey = document.getElementById('mg-key').value; let mgKey = document.getElementById('mg-key').value;
let mailActive = ""; let mailActive = '';
let mailOptions = document.querySelectorAll('.mail-option'); let mailOptions = document.querySelectorAll('.mail-option');
for (var i = 0, length = selects.length; i < length; i++) var i, count;
{ for (i = 0, count = selects.length; i < count; i++) {
if (selects[i].getAttribute('data-enabled') == "true") selected = selects[i].id; if (selects[i].getAttribute('data-enabled') == 'true') selected = selects[i].id;
} }
for (var i = 0, length = mailOptions.length; i < length; i++) for (i = 0, count = mailOptions.length; i < count; i++) {
{ if (mailOptions[i].getAttribute('data-enabled') == 'true')
if (mailOptions[i].getAttribute('data-enabled') == "true") mailActive = mailOptions[i].id; mailActive = mailOptions[i].id;
} }
let settingsData = { let settingsData = {
handle: handle, handle: handle,
@ -73,18 +63,24 @@ export default class SettingsActions
key: mgKey key: mgKey
} }
} }
} };
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject) {
{ self.dataUtils
self.dataUtils.request('/api/settings/sync', DataEvent.SETTINGS_UPDATED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, settingsData).then((response) => .request(
{ '/api/settings/sync',
DataEvent.SETTINGS_UPDATED,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
settingsData
)
.then(response => {
//console.log("RESPONSE", response) //console.log("RESPONSE", response)
resolve(response) resolve(response);
}).catch((err) => })
{ .catch(err => {
reject(err); reject(err);
}) });
}) });
} }
//-------------------------- //--------------------------
// event handlers // event handlers

View file

@ -8,16 +8,13 @@ export default class DashManager {
//-------------------------- //--------------------------
constructor() { constructor() {
this.currentDisplay = ''; this.currentDisplay = '';
this.urlPieces = document.URL.split("/"); this.urlPieces = document.URL.split('/');
this.chooseDisplay(this.urlPieces[5], this.urlPieces[6]); this.chooseDisplay(this.urlPieces[5], this.urlPieces[6]);
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() { start() {}
let self = this;
}
chooseDisplay(section, page) { chooseDisplay(section, page) {
this.currentDisplay = ''; this.currentDisplay = '';
@ -30,16 +27,15 @@ export default class DashManager {
break; break;
case 'navigation': case 'navigation':
this.currentDisplay = new NaviIndex(); this.currentDisplay = new NaviIndex();
break;
default: default:
// just chill // just chill
break; break;
} }
this.start(); this.start();
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
} }

View file

@ -1,66 +1,48 @@
import NavActions from "../actions/NavActions"; import NavActions from '../actions/NavActions';
import DataUtils, import DBUtils from '../../../../../brain/tools/utilities/DBUtils';
{ export default class NavIndex {
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM
}
from "../../../../../brain/tools/utilities/DataUtils";
import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
import DBUtils from "../../../../../brain/tools/utilities/DBUtils";
export default class NavIndex
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
this.start(); this.start();
this.dataUtils = new DataUtils(); //this.dataUtils = new DataUtils();
this.dbutils = new DBUtils(); this.dbutils = new DBUtils();
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() start() {
{ Sortable.create(document.getElementById('nav-pages'), {
let self = this; onUpdate: () => {
let menu = Sortable.create(document.getElementById("nav-pages"), new NavActions()
{ .save()
onUpdate: e => .then(() => {
{ //console.log(r);
new NavActions().save().then(r=>{
console.log(r);
}).catch(err=>{
console.log(err)
}) })
.catch(() => {
//console.log(err);
});
} }
}); });
var nav = document.querySelectorAll('.nav-btn'); var nav = document.querySelectorAll('.nav-btn');
for (var i = 0, length = nav.length; i < length; i++) for (var i = 0, length = nav.length; i < length; i++) {
{
nav[i].addEventListener('click', e => this.handleNavButton(e), false); nav[i].addEventListener('click', e => this.handleNavButton(e), false);
} }
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
handleNavButton(e) handleNavButton(e) {
{ let id = '';
let self = this; switch (e.target.id) {
switch (e.target.id) case 'remove-item':
{ id = e.target.getAttribute('data-id');
case "remove-item":
let id = e.target.getAttribute('data-id');
new NavActions().removeItem(id); new NavActions().removeItem(id);
break break;
case "edit-item": case 'edit-item':
window.location = "/@/dashboard/posts/edit/" + e.target.getAttribute('data-id'); window.location = '/@/dashboard/posts/edit/' + e.target.getAttribute('data-id');
break break;
} }
} }
} }

View file

@ -1,74 +1,78 @@
//TOOLS //TOOLS
import DataUtils, import DataUtils, {
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM CONTENT_TYPE_FORM
} } from '../../../../../brain/tools/utilities/DataUtils';
from '../../../../../brain/tools/utilities/DataUtils';
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
import PostActions from '../actions/PostActions'; import PostActions from '../actions/PostActions';
import * as EditorEvent from '../../../../../brain/tools/events/EditorEvent'; import * as EditorEvent from '../../../../../brain/tools/events/EditorEvent';
import TinyDatePicker from 'tiny-date-picker'; import TinyDatePicker from 'tiny-date-picker';
import DateUtils from '../../../../../brain/tools/utilities/DateUtils'; import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import TextEditor from '../../../../../brain/tools/ui/TextEditor'; import TextEditor from '../../../../../brain/tools/ui/TextEditor';
import DBUtils, import DBUtils, { FINAL_KEY } from '../../../../../brain/tools/utilities/DBUtils';
{ export default class PostEditor {
FINAL_KEY
}
from '../../../../../brain/tools/utilities/DBUtils';
export default class PostEditor
{
//TODO - FIX POST FEATURE URLS IN DB //TODO - FIX POST FEATURE URLS IN DB
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
let self = this; let self = this;
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils(); this.dateUtils = new DateUtils();
this.urlPieces = document.URL.split("/"); this.urlPieces = document.URL.split('/');
this.dbUtils = new DBUtils(); this.dbUtils = new DBUtils();
this.post = []; this.post = [];
this.postID = null; this.postID = null;
if (document.getElementById('post-edit-index').getAttribute('data-index')) if (document.getElementById('post-edit-index').getAttribute('data-index')) {
{
this.postID = document.getElementById('post-edit-index').getAttribute('data-index'); this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
this.dbUtils.getPost(this.postID).then(body => this.dbUtils
{ .getPost(this.postID)
.then(body => {
self.post = body.post; self.post = body.post;
this.start() this.start();
}).catch(err =>
{
//console.log(err)
}) })
.catch();
} else {
this.start();
} }
else if (document.getElementById('edit-post-text')) {
{ this.editor = new TextEditor(
this.start() document.getElementById('edit-post-text'),
} document.getElementById('header').offsetHeight +
if (document.getElementById('edit-post-text')) document.getElementById('post-header').offsetHeight +
{ document.getElementById('post-feature').offsetHeight
this.editor = new TextEditor(document.getElementById('edit-post-text'), document.getElementById('header').offsetHeight + document.getElementById('post-header').offsetHeight + document.getElementById('post-feature').offsetHeight); );
this.editor.addListener(EditorEvent.EDITOR_DELETE, f => this.handleEditorOptions(EditorEvent.EDITOR_DELETE), false) this.editor.addListener(
this.editor.addListener(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, f => this.handleEditorOptions(EditorEvent.EDITOR_UPLOAD_POST_IMAGE), false) EditorEvent.EDITOR_DELETE,
this.editor.addListener(EditorEvent.EDITOR_UPDATE, f => this.handleEditorOptions(EditorEvent.EDITOR_UPDATE), false) () => this.handleEditorOptions(EditorEvent.EDITOR_DELETE),
this.editor.addListener(EditorEvent.EDITOR_SAVE, f => this.handleEditorOptions(EditorEvent.EDITOR_SAVE), false) false
document.getElementById('post-image-upload').addEventListener('change', e => );
{ this.editor.addListener(
EditorEvent.EDITOR_UPLOAD_POST_IMAGE,
() => this.handleEditorOptions(EditorEvent.EDITOR_UPLOAD_POST_IMAGE),
false
);
this.editor.addListener(
EditorEvent.EDITOR_UPDATE,
() => this.handleEditorOptions(EditorEvent.EDITOR_UPDATE),
false
);
this.editor.addListener(
EditorEvent.EDITOR_SAVE,
() => this.handleEditorOptions(EditorEvent.EDITOR_SAVE),
false
);
document.getElementById('post-image-upload').addEventListener(
'change',
e => {
self.handleImageUpload(e.target.id, e.target.files); self.handleImageUpload(e.target.id, e.target.files);
}, false); },
TinyDatePicker(document.getElementById('post-date'), false
{ );
TinyDatePicker(document.getElementById('post-date'), {
mode: 'dp-below', mode: 'dp-below',
format(date) format(date) {
{
return self.dateUtils.getDate('origin', date); return self.dateUtils.getDate('origin', date);
} }
}); });
@ -77,24 +81,24 @@ export default class PostEditor
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() start() {
{ if (document.getElementById('featured-image-drop')) {
let self = this; document
if (document.getElementById('featured-image-drop')) .getElementById('featured-image-drop')
{ .addEventListener('dragover', this.handleImageActions, false);
document.getElementById('featured-image-drop').addEventListener('dragover', this.handleImageActions, false); document
document.getElementById('featured-image-drop').addEventListener('drop', this.handleImageActions, false); .getElementById('featured-image-drop')
document.getElementById('featured-image-upload').addEventListener('change', e => this.handleImageActions(e), false); .addEventListener('drop', this.handleImageActions, false);
if (document.getElementById('new-feature-upload')) document
{ .getElementById('featured-image-upload')
document.getElementById('new-feature-upload').addEventListener('click', e => .addEventListener('change', e => this.handleImageActions(e), false);
{ if (document.getElementById('new-feature-upload')) {
document.getElementById('new-feature-upload').addEventListener('click', () => {
document.getElementById('featured-image-upload').click(); document.getElementById('featured-image-upload').click();
}) });
} }
var optionButtons = document.querySelectorAll('.post-option-btn'); var optionButtons = document.querySelectorAll('.post-option-btn');
for (var i = 0, length = optionButtons.length; i < length; i++) for (var i = 0, length = optionButtons.length; i < length; i++) {
{
optionButtons[i].addEventListener('click', e => this.handlePostOptions(e), false); optionButtons[i].addEventListener('click', e => this.handlePostOptions(e), false);
} }
} }
@ -102,72 +106,65 @@ export default class PostEditor
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
handlePostOptions(e) handlePostOptions(e) {
{
let currentOption; let currentOption;
switch (e.target.id) switch (e.target.id) {
{ case 'option-page-icon':
case "option-page-icon": case 'option-page':
case "option-page":
currentOption = document.getElementById('option-page'); currentOption = document.getElementById('option-page');
break; break;
case "option-feature-icon": case 'option-feature-icon':
case "option-feature": case 'option-feature':
currentOption = document.getElementById('option-feature'); currentOption = document.getElementById('option-feature');
break; break;
case "option-published-icon": case 'option-published-icon':
case "option-published": case 'option-published':
currentOption = document.getElementById('option-published'); currentOption = document.getElementById('option-published');
break; break;
} }
let active = currentOption.getAttribute('data-active'); let active = currentOption.getAttribute('data-active');
(active == 'false') ? currentOption.setAttribute('data-active', 'true'): currentOption.setAttribute('data-active', 'false') active == 'false'
? currentOption.setAttribute('data-active', 'true')
: currentOption.setAttribute('data-active', 'false');
} }
handleEditorOptions(e) handleEditorOptions(e) {
{
let self = this; let self = this;
switch (e) switch (e) {
{
case EditorEvent.EDITOR_SAVE: case EditorEvent.EDITOR_SAVE:
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY).then(response => new PostActions()
{ .update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY)
setTimeout(f => .then(response => {
{ setTimeout(() => {
self.dbUtils.getPost(Number(response.response.newPost)).then(r => self.dbUtils.getPost(Number(response.response.newPost)).then(r => {
{ window.location = '/@/dashboard/posts/edit/' + r.post.uuid;
window.location = "/@/dashboard/posts/edit/" + r.post.uuid; });
})
}, 100); }, 100);
}).catch(err => })
{ .catch(() => {
//console.log("ERROR", err) //console.log("ERROR", err)
}) });
break break;
case EditorEvent.EDITOR_UPDATE: case EditorEvent.EDITOR_UPDATE:
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY).then(response => new PostActions()
{ .update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY)
.then(() => {
this.editor.notify(DataEvent.POST_UPDATED, this.postID); this.editor.notify(DataEvent.POST_UPDATED, this.postID);
}).catch(err =>
{
//console.log("ERRORZ", err)
}) })
.catch(() => {
//console.log("ERRORZ", err)
});
break; break;
case EditorEvent.EDITOR_DELETE: case EditorEvent.EDITOR_DELETE:
if (confirm('Aye! You know you\'re deleting this post, right?')) if (confirm("Aye! You know you're deleting this post, right?")) {
{ new PostActions()
new PostActions().deletePost(this.postID, this.post).then((response) => .deletePost(this.postID, this.post)
{ .then(() => {
setTimeout(f => setTimeout(() => {
{ window.location = '/@/dashboard/posts/';
window.location = "/@/dashboard/posts/"
}, 100); }, 100);
}).catch((err) => })
{ .catch(() => {});
console.log(err) } else {
});
}
else
{
// Do nothing! // Do nothing!
} }
break; break;
@ -176,40 +173,38 @@ export default class PostEditor
break; break;
} }
} }
handleImageActions(e) handleImageActions(e) {
{
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
var self = this; switch (e.type) {
switch (e.type) case 'dragover':
{
case "dragover":
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
break; break;
case "change": case 'change':
case "drop": case 'drop':
(e.type == "drop") ? PostEditor.uploadFiles = e.dataTransfer.files: PostEditor.uploadFiles = e.target.files; e.type == 'drop'
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) ? (PostEditor.uploadFiles = e.dataTransfer.files)
{ : (PostEditor.uploadFiles = e.target.files);
for (var i = 0, f; (f = PostEditor.uploadFiles[i]); i++) {
// Only process image files. // Only process image files.
if (!f.type.match('image.*')) if (!f.type.match('image.*')) {
{
continue; continue;
} }
var reader = new FileReader(); var reader = new FileReader();
// Closure to capture the file information. // Closure to capture the file information.
reader.onload = (function(theFile) reader.onload = (function(theFile) {
{ return function(f) {
return function(f)
{
// Render thumbnail. // Render thumbnail.
var image = document.createElement('img'); var image = document.createElement('img');
image.src = f.target.result; image.src = f.target.result;
image.title = escape(theFile.name); image.title = escape(theFile.name);
var span = document.createElement('div'); var span = document.createElement('div');
span.innerHTML = ['<img src="', span.innerHTML = [
f.target.result, '" title="', '<img src="',
escape(theFile.name), '"/>' f.target.result,
'" title="',
escape(theFile.name),
'"/>'
].join(''); ].join('');
document.getElementById('featured-image-drop').innerHTML = ''; document.getElementById('featured-image-drop').innerHTML = '';
document.getElementById('featured-image-drop').appendChild(image); document.getElementById('featured-image-drop').appendChild(image);
@ -218,36 +213,42 @@ export default class PostEditor
// Read in the image file as a data URL. // Read in the image file as a data URL.
reader.readAsDataURL(f); reader.readAsDataURL(f);
} }
if (e.target.id == "featured-image-upload") this.handleImageUpload(e.target.id, PostEditor.uploadFiles); if (e.target.id == 'featured-image-upload')
this.handleImageUpload(e.target.id, PostEditor.uploadFiles);
break; break;
} }
} }
handleImageUpload(type, files) handleImageUpload(type, files) {
{ let url = '';
let url = "" let eventType = '';
let eventType = "";
let self = this; let self = this;
(type == "featured-image-upload") ? url = "/api/post/add-feature-image": url = "/api/post/add-post-image"; type == 'featured-image-upload'
(type == "featured-image-upload") ? eventType = DataEvent.FEATURE_IMAGE_ADDED: eventType = DataEvent.POST_IMAGE_ADDED ? (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(); var imageData = new FormData();
for (var i = 0; i < files.length; i++) for (var i = 0; i < files.length; i++) {
{
var file = files[i]; var file = files[i];
// Check the file type. // Check the file type.
if (!file.type.match('image.*')) if (!file.type.match('image.*')) {
{
continue; continue;
} }
(type == "featured-image-upload") ? imageData.append('feature_image', file, file.name): imageData.append('post_image', file, file.name); type == 'featured-image-upload'
? 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).then((response) => this.dataUtils
{ .request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
.then(response => {
let r = JSON.parse(response.request['response']); let r = JSON.parse(response.request['response']);
if (r.message == DataEvent.POST_IMAGE_ADDED) self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url); if (r.message == DataEvent.POST_IMAGE_ADDED)
}).catch((err) => self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
{
//console.log(err)
}) })
.catch(() => {
//console.log(err)
});
} }
} }
PostEditor.uploadFiles = []; PostEditor.uploadFiles = [];

View file

@ -1,11 +1,9 @@
import PostEditor from './PostEditor'; import PostEditor from './PostEditor';
export default class PostIndex export default class PostIndex {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor(page) constructor(page) {
{
this.currentPage = null; this.currentPage = null;
this.choosePage(page); this.choosePage(page);
this.start(); this.start();
@ -13,17 +11,12 @@ export default class PostIndex
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() start() {}
{ choosePage(page) {
let self = this;
}
choosePage(page)
{
this.currentPage = ''; this.currentPage = '';
switch (page) switch (page) {
{ case 'edit':
case "edit": case 'add':
case "add":
this.currentPage = new PostEditor(); this.currentPage = new PostEditor();
break; break;
default: default:

View file

@ -1,23 +1,15 @@
import SettingsActions from "../actions/SettingsActions"; import SettingsActions from '../actions/SettingsActions';
import DataUtils, import DataUtils, {
{
REQUEST_TYPE_GET,
REQUEST_TYPE_PUT,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
REQUEST_TYPE_DELETE,
CONTENT_TYPE_JSON,
CONTENT_TYPE_FORM CONTENT_TYPE_FORM
} } from '../../../../../brain/tools/utilities/DataUtils';
from "../../../../../brain/tools/utilities/DataUtils";
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
import Mailer from '../actions/Mailer'; import Mailer from '../actions/Mailer';
export default class SettingsIndex export default class SettingsIndex {
{
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() constructor() {
{
this.start(); this.start();
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.mailer = new Mailer(); this.mailer = new Mailer();
@ -25,147 +17,136 @@ export default class SettingsIndex
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() start() {
{
let self = this; let self = this;
//handle save button //handle save button
document.getElementById('save-toggle').addEventListener('click', f => new SettingsActions().save().then(response => document.getElementById('save-toggle').addEventListener('click', () =>
{ new SettingsActions()
console.log(response); .save()
}).catch(err => .then(() => {
{ //console.log(response);
console.log(err); })
})); .catch(() => {
//console.log(err);
})
);
//handle set up image uploads //handle set up image uploads
document.getElementById('avatar').addEventListener('click', e => document.getElementById('avatar').addEventListener('click', () => {
{
document.getElementById('avatar-upload').click(); document.getElementById('avatar-upload').click();
}) });
document.getElementById('background').addEventListener('click', e => document.getElementById('background').addEventListener('click', () => {
{
document.getElementById('background-upload').click(); document.getElementById('background-upload').click();
}) });
document.getElementById('avatar-upload').addEventListener('change', e => document.getElementById('avatar-upload').addEventListener(
{ 'change',
e => {
self.handleImageUpload(e.target.id, e.target.files); self.handleImageUpload(e.target.id, e.target.files);
}, false); },
document.getElementById('background-upload').addEventListener('change', e => false
{ );
document.getElementById('background-upload').addEventListener(
'change',
e => {
self.handleImageUpload(e.target.id, e.target.files); self.handleImageUpload(e.target.id, e.target.files);
}, false); },
false
);
//handle privacy toggle //handle privacy toggle
document.getElementById("privacy-toggle").addEventListener("click", e => this.togglePrivacy(e)); document
document.getElementById("send-mail").addEventListener("click", e => this.handleMailer(e)); .getElementById('privacy-toggle')
.addEventListener('click', e => this.togglePrivacy(e));
document.getElementById('send-mail').addEventListener('click', e => this.handleMailer(e));
//handle theme toggle //handle theme toggle
let themeBtns = document.querySelectorAll('.theme-select'); let themeBtns = document.querySelectorAll('.theme-select');
for (var i = 0, length = themeBtns.length; i < length; i++) for (var i = 0, length = themeBtns.length; i < length; i++) {
{
themeBtns[i].addEventListener('click', e => this.handleThemes(e)); themeBtns[i].addEventListener('click', e => this.handleThemes(e));
} }
//handle mail options //handle mail options
let mailBtn = document.querySelectorAll('.mail-option'); let mailBtn = document.querySelectorAll('.mail-option');
for (var i = 0, length = mailBtn.length; i < length; i++) for (i = 0, length = mailBtn.length; i < length; i++) {
{
mailBtn[i].addEventListener('click', e => this.handleMailOptions(e)); mailBtn[i].addEventListener('click', e => this.handleMailOptions(e));
} }
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
togglePrivacy(e) togglePrivacy(e) {
{
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
if (e.target.getAttribute('data-private') == "false") if (e.target.getAttribute('data-private') == 'false') {
{
e.target.setAttribute('data-private', 'true'); e.target.setAttribute('data-private', 'true');
e.target.innerHTML = "SITE IS PUBLIC" e.target.innerHTML = 'SITE IS PUBLIC';
} } else {
else
{
e.target.setAttribute('data-private', 'false'); e.target.setAttribute('data-private', 'false');
e.target.innerHTML = "SITE IS PRIVATE" e.target.innerHTML = 'SITE IS PRIVATE';
} }
} }
handleMailer() handleMailer() {
{
this.mailer.sendMail(); this.mailer.sendMail();
} }
handleThemes(e) handleThemes(e) {
{
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
let themes = document.querySelectorAll('.theme-select'); let themes = document.querySelectorAll('.theme-select');
for (var i = 0, length = themes.length; i < length; i++) for (var i = 0, length = themes.length; i < length; i++) {
{ e.target.id == themes[i].id
(e.target.id == themes[i].id) ? themes[i].setAttribute('data-enabled', 'true'): themes[i].setAttribute('data-enabled', 'false') ? themes[i].setAttribute('data-enabled', 'true')
: themes[i].setAttribute('data-enabled', 'false');
} }
} }
handleMailOptions(e) handleMailOptions(e) {
{
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
let smtp = document.getElementById('mail-smtp'); let smtp = document.getElementById('mail-smtp');
let mailgun = document.getElementById('mail-mg') let mailgun = document.getElementById('mail-mg');
let mail = document.querySelectorAll('.mail-option'); let mail = document.querySelectorAll('.mail-option');
for (var i = 0, length = mail.length; i < length; i++) for (var i = 0, length = mail.length; i < length; i++) {
{ if (e.target.id == mail[i].id) {
if (e.target.id == mail[i].id) mail[i].setAttribute('data-enabled', 'true');
{ if (e.target.id == 'option-smtp') {
mail[i].setAttribute('data-enabled', 'true') smtp.setAttribute('data-enabled', 'true');
if (e.target.id == "option-smtp") mailgun.setAttribute('data-enabled', 'false');
{ } else if (e.target.id == 'option-none') {
smtp.setAttribute('data-enabled', 'true') smtp.setAttribute('data-enabled', 'false');
mailgun.setAttribute('data-enabled', 'false') mailgun.setAttribute('data-enabled', 'false');
} else {
smtp.setAttribute('data-enabled', 'false');
mailgun.setAttribute('data-enabled', 'true');
} }
else if (e.target.id == "option-none") } else {
{ mail[i].setAttribute('data-enabled', 'false');
smtp.setAttribute('data-enabled', 'false')
mailgun.setAttribute('data-enabled', 'false')
}
else
{
smtp.setAttribute('data-enabled', 'false')
mailgun.setAttribute('data-enabled', 'true')
}
}
else
{
mail[i].setAttribute('data-enabled', 'false')
} }
} }
} }
handleImageUpload(type, files) handleImageUpload(type, files) {
{ let url = '';
let url = "" let eventType = '';
let eventType = ""; type == 'avatar-upload'
let self = this; ? (url = '/api/settings/add-avatar')
(type == "avatar-upload") ? url = "/api/settings/add-avatar": url = "/api/settings/add-feature-background"; : (url = '/api/settings/add-feature-background');
var imageData = new FormData(); var imageData = new FormData();
for (var i = 0; i < files.length; i++) for (var i = 0; i < files.length; i++) {
{
var file = files[i]; var file = files[i];
// Check the file type. // Check the file type.
if (!file.type.match('image.*')) if (!file.type.match('image.*')) {
{
continue; continue;
} }
(type == "avatar-upload") ? imageData.append('avatar_upload', file, file.name): imageData.append('background_upload', file, file.name); type == 'avatar-upload'
? imageData.append('avatar_upload', file, file.name)
: imageData.append('background_upload', file, file.name);
} }
this.dataUtils.request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData).then((response) => this.dataUtils
{ .request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
.then(response => {
let r = JSON.parse(response.request['response']); let r = JSON.parse(response.request['response']);
if (r.message == DataEvent.AVATAR_UPLOADED) if (r.message == DataEvent.AVATAR_UPLOADED) {
{
document.getElementById('avatar').src = r.url; document.getElementById('avatar').src = r.url;
} } else {
else
{
document.getElementById('background').src = r.url; document.getElementById('background').src = r.url;
} }
}).catch((err) =>
{
//console.log(err)
}) })
.catch(() => {
//console.log(err)
});
} }
} }

View file

@ -3,95 +3,72 @@
-- Bulma -- Bulma
------------------------------- -------------------------------
* */ * */
//@import '/../../node_modules/bulma.styl/bulma.styl' @import '../../../../node_modules/bulma.styl/stylus/utilities/_all';
@import "../../../../node_modules/bulma.styl/stylus/utilities/_all" @import '../../../../node_modules/bulma.styl/stylus/grid/columns';
@import "../../../../node_modules/bulma.styl/stylus/grid/columns"
/** /**
------------------------------- -------------------------------
-- Colors -- Colors
------------------------------- -------------------------------
* */ * */
@import 'main/_colors';
@import "main/_colors"
/** /**
------------------------------- -------------------------------
-- Mixins -- Mixins
------------------------------- -------------------------------
* */ * */
@import 'main/_mixins';
@import 'main/_mixins'
/** /**
------------------------------- -------------------------------
-- Normalize -- Normalize
------------------------------- -------------------------------
* */ * */
@import 'main/_normalize' @import 'main/_normalize';
/** /**
------------------------------- -------------------------------
-- Typography -- Typography
------------------------------- -------------------------------
* */ * */
@import 'main/_typography';
@import "main/_typography"
/** /**
------------------------------- -------------------------------
-- Main Structure -- Main Structure
------------------------------- -------------------------------
* */ * */
@import 'main/_structure';
@import "main/_structure"
/** /**
------------------------------- -------------------------------
-- Index -- Index
------------------------------- -------------------------------
* */ * */
@import 'main/_index';
@import "main/_index"
/** /**
------------------------------- -------------------------------
-- Settings -- Settings
------------------------------- -------------------------------
* */ * */
@import 'main/_settings';
@import "main/_settings"
/** /**
------------------------------- -------------------------------
-- Navigation -- Navigation
------------------------------- -------------------------------
* */ * */
@import 'main/_navigation';
@import "main/_navigation"
/** /**
------------------------------- -------------------------------
-- Forms -- Forms
------------------------------- -------------------------------
* */ * */
@import 'main/_forms';
@import 'main/_forms'
/** /**
------------------------------- -------------------------------
-- Blog -- Blog
------------------------------- -------------------------------
* */ * */
@import 'main/_posts';
@import 'main/_posts'
/** /**
------------------------------- -------------------------------
-- Editor -- Editor
------------------------------- -------------------------------
* */ * */
@import 'main/_editor';
@import 'main/_editor' @import 'main/_editor-highlight';
@import 'main/_editor-highlight'