updated post editing and creation for new data syncing methodology. finally.

sql-version-freeze
Ro 6 years ago
parent b057c50ad4
commit a7239a3027

@ -50,12 +50,11 @@ var post_upload = multer(
{
storage: storage
}).array('post_image');
//** SYNC POSTS */
router.post("/sync", (req, res, next) =>
{
let payload = req.body;
console.log("***PAYLOAD***", payload)
Models.User.findById(req.session.user.id).then((user) =>
{
if (rightsManager.check(user.role, OBJECT_POST, TASK_UPDATE))
@ -77,13 +76,18 @@ router.post("/sync", (req, res, next) =>
}
}).then(found =>
{
if (!_.isEqual(item.post, found.post)){
found.update(item).then(updated=>{
if (!_.isEqual(item.post, found.post))
{
found.update(item).then(updated =>
{
console.log("UPDATED", updated);
}).catch(err=>{
}).catch(err =>
{
//console.log("***ERROR***", err);
})
} else{
}
else
{
//chilld
}
}).catch(err =>
@ -123,7 +127,6 @@ router.get('/json', function(req, res, next)
//next(err);
})
})
/***
POST IMAGE
*/
@ -169,4 +172,47 @@ router.post('/add-post-image', function(req, res, next)
}
});
});
router.post('/add-feature-image', function(req, res, next)
{
//console.log(req.body);
if (!req.session.user) return res.json(
{
message: "You need to be logged in, champ."
});
Models.User.findById(req.session.user.id).then((user) =>
{
if (rightsManager.check(user.role, OBJECT_POST, TASK_CREATE))
{
feature_upload(req, res, function(err)
{
if (err)
{
//console.log('Error in Saving Entry: ' + err);
res.json(
{
message: err
});
throw err;
}
else
{
var postImage = req.files[0].path;
return res.json(
{
message: "post image added",
url: postImage.substr(7, postImage.length)
});
}
});
}
else
{
res.json(
{
message: "Nah. You can't do that. Talk to the admin, sport."
});
}
});
});
module.exports = router;

@ -108,9 +108,10 @@ router.get('/edit/:id', function(req, res)
}
}).then(item =>
{
let featured_img = JSON.parse(item.post.feature);
console.log("**ITEM***", item);
let featured = 'null';
if (featured_img.length != 0) featured = featured_img[0].substr(7, featured_img[0].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 sexydate = dateUtils.getDate('year', item.post.created) + "-" + dateUtils.getDate('month', item.post.created) + "-" + dateUtils.getDate('day', item.post.created)
res.render('dash/post-edit',

@ -13,14 +13,14 @@ router.get('/', function(req, res)
{
var loggedIn = false
if (req.session.user) loggedIn = true;
Models.Post.sync().then(f =>
Models.FreshPost.sync().then(f =>
{
Models.Post.findAll(
Models.FreshPost.findAll(
{
order: [
['id', 'DESC']
],
limit: 10
limit: 5
}).then(function(posts)
{
res.render('dash/index',

@ -11,6 +11,7 @@ export const PROJECT_UPDATED = 'projectUpdated';
export const PROJECT_ADDED = 'projectAdded';
export const PROJECTS_SORTED = 'projectsSorted';
export const POST_IMAGE_ADDED = 'postImageAdded';
export const FEATURE_IMAGE_ADDED = 'featureImageAdded';
export const POST_ERROR = 'postError';
export const POST_ADDED = 'postAdded';
export const POST_UPDATED = 'postUpdated';

@ -197,7 +197,7 @@ exports.default = _default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.POSTS_SYNCED = exports.POST_DELETED = exports.POST_UPDATED = exports.POST_ADDED = exports.POST_ERROR = exports.POST_IMAGE_ADDED = exports.PROJECTS_SORTED = exports.PROJECT_ADDED = exports.PROJECT_UPDATED = exports.ARCHIVES_ENTRY_LOADED = exports.ARCHIVES_PAGE_LOADED = exports.ARCHIVES_JSON_LOADED = exports.HTML_LOADED = exports.SETTINGS_LOADED = exports.IMG_REQUEST_LAME = exports.IMG_REQUEST_GOOD = exports.REQUEST_LAME = exports.REQUEST_GOOD = void 0;
exports.default = exports.POSTS_SYNCED = exports.POST_DELETED = exports.POST_UPDATED = exports.POST_ADDED = exports.POST_ERROR = exports.FEATURE_IMAGE_ADDED = exports.POST_IMAGE_ADDED = exports.PROJECTS_SORTED = exports.PROJECT_ADDED = exports.PROJECT_UPDATED = exports.ARCHIVES_ENTRY_LOADED = exports.ARCHIVES_PAGE_LOADED = exports.ARCHIVES_JSON_LOADED = exports.HTML_LOADED = exports.SETTINGS_LOADED = exports.IMG_REQUEST_LAME = exports.IMG_REQUEST_GOOD = exports.REQUEST_LAME = exports.REQUEST_GOOD = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@ -227,6 +227,8 @@ var PROJECTS_SORTED = 'projectsSorted';
exports.PROJECTS_SORTED = PROJECTS_SORTED;
var POST_IMAGE_ADDED = 'postImageAdded';
exports.POST_IMAGE_ADDED = POST_IMAGE_ADDED;
var FEATURE_IMAGE_ADDED = 'featureImageAdded';
exports.FEATURE_IMAGE_ADDED = FEATURE_IMAGE_ADDED;
var POST_ERROR = 'postError';
exports.POST_ERROR = POST_ERROR;
var POST_ADDED = 'postAdded';
@ -27361,7 +27363,94 @@ sanitizeHtml.simpleTransform = function (newTagName, newAttribs, merge) {
};
};
};
},{"htmlparser2":"../../../../node_modules/htmlparser2/lib/index.js","xtend":"../../../../node_modules/xtend/immutable.js","lodash.escaperegexp":"../../../../node_modules/lodash.escaperegexp/index.js","lodash.clonedeep":"../../../../node_modules/lodash.clonedeep/index.js","lodash.mergewith":"../../../../node_modules/lodash.mergewith/index.js","lodash.isstring":"../../../../node_modules/lodash.isstring/index.js","lodash.isplainobject":"../../../../node_modules/lodash.isplainobject/index.js","srcset":"../../../../node_modules/srcset/index.js","postcss":"../../../../node_modules/postcss/lib/postcss.js","url":"../../../../../../.nvm/versions/node/v8.12.0/lib/node_modules/parcel-bundler/node_modules/url/url.js"}],"../../../../node_modules/markdown-it/lib/common/entities.js":[function(require,module,exports) {
},{"htmlparser2":"../../../../node_modules/htmlparser2/lib/index.js","xtend":"../../../../node_modules/xtend/immutable.js","lodash.escaperegexp":"../../../../node_modules/lodash.escaperegexp/index.js","lodash.clonedeep":"../../../../node_modules/lodash.clonedeep/index.js","lodash.mergewith":"../../../../node_modules/lodash.mergewith/index.js","lodash.isstring":"../../../../node_modules/lodash.isstring/index.js","lodash.isplainobject":"../../../../node_modules/lodash.isplainobject/index.js","srcset":"../../../../node_modules/srcset/index.js","postcss":"../../../../node_modules/postcss/lib/postcss.js","url":"../../../../../../.nvm/versions/node/v8.12.0/lib/node_modules/parcel-bundler/node_modules/url/url.js"}],"../../../../brain/tools/utilities/DateUtils.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var DateUtils =
/*#__PURE__*/
function () {
//--------------------------
// constructor
//--------------------------
function DateUtils() {
_classCallCheck(this, DateUtils);
} //--------------------------
// methods
//--------------------------
_createClass(DateUtils, [{
key: "getMKtime",
value: function getMKtime() {
var time = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), new Date().getHours(), new Date().getMinutes(), new Date().getSeconds(), 0).getTime() / 1000;
return time;
}
}, {
key: "convertMKtime",
value: function convertMKtime(seconds) {
var date = new Date(seconds * 1000);
return date;
}
}, {
key: "getDate",
value: function getDate(type, rawdate) {
var day = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCDate()) : String(new Date().getUTCDate());
var month = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMonth() + 1) : String(new Date().getUTCMonth() + 1);
var year = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCFullYear()) : String(new Date().getUTCFullYear());
var hour = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCHours()) : String(new Date().getUTCHours());
var minute = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMinutes()) : String(new Date().getUTCMinutes());
var seconds = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCSeconds()) : String(new Date().getUTCSeconds());
var millisecond = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMilliseconds()) : String(new Date().getUTCMilliseconds());
var offset = rawdate != null || rawdate != '' ? String(new Date(rawdate).getTimezoneOffset()) : String(new Date().getTimezoneOffset());
if (day.length == 1) day = String("0" + day);
if (month.length == 1) month = String("0" + month);
offset = String(offset / 60);
if (offset.length == 1) offset = String("0" + offset);
switch (type) {
case "day":
return day;
break;
case "month":
return month;
break;
case "year":
return year;
break;
case "stamp":
return String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds + "." + millisecond + "-" + offset);
break;
default:
return String(year + "-" + month + "-" + day);
break;
}
} //--------------------------
// event handlers
//--------------------------
}]);
return DateUtils;
}();
var _default = DateUtils;
exports.default = _default;
},{}],"../../../../node_modules/markdown-it/lib/common/entities.js":[function(require,module,exports) {
// HTML5 entities map: { name -> utf16string }
//
'use strict';
@ -34785,7 +34874,100 @@ module.exports = MarkdownIt;
module.exports = require('./lib/');
},{"./lib/":"../../../../node_modules/markdown-it/lib/index.js"}],"actions/PostActions.js":[function(require,module,exports) {
},{"./lib/":"../../../../node_modules/markdown-it/lib/index.js"}],"../../../../node_modules/uuid/lib/rng-browser.js":[function(require,module,exports) {
// Unique ID creation requires a high quality random # generator. In the
// browser this is a little complicated due to unknown quality of Math.random()
// and inconsistent support for the `crypto` API. We do the best we can via
// feature-detection
// getRandomValues needs to be invoked in a context where "this" is a Crypto
// implementation. Also, find the complete implementation of crypto on IE11.
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
(typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));
if (getRandomValues) {
// WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
module.exports = function whatwgRNG() {
getRandomValues(rnds8);
return rnds8;
};
} else {
// Math.random()-based (RNG)
//
// If all else fails, use Math.random(). It's fast, but is of unspecified
// quality.
var rnds = new Array(16);
module.exports = function mathRNG() {
for (var i = 0, r; i < 16; i++) {
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
}
return rnds;
};
}
},{}],"../../../../node_modules/uuid/lib/bytesToUuid.js":[function(require,module,exports) {
/**
* Convert array of 16 byte values to UUID string format of the form:
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
*/
var byteToHex = [];
for (var i = 0; i < 256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substr(1);
}
function bytesToUuid(buf, offset) {
var i = offset || 0;
var bth = byteToHex;
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
return ([bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]]]).join('');
}
module.exports = bytesToUuid;
},{}],"../../../../node_modules/uuid/v4.js":[function(require,module,exports) {
var rng = require('./lib/rng');
var bytesToUuid = require('./lib/bytesToUuid');
function v4(options, buf, offset) {
var i = buf && offset || 0;
if (typeof(options) == 'string') {
buf = options === 'binary' ? new Array(16) : null;
options = null;
}
options = options || {};
var rnds = options.random || (options.rng || rng)();
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
rnds[6] = (rnds[6] & 0x0f) | 0x40;
rnds[8] = (rnds[8] & 0x3f) | 0x80;
// Copy bytes to buffer, if provided
if (buf) {
for (var ii = 0; ii < 16; ++ii) {
buf[i + ii] = rnds[ii];
}
}
return buf || bytesToUuid(rnds);
}
module.exports = v4;
},{"./lib/rng":"../../../../node_modules/uuid/lib/rng-browser.js","./lib/bytesToUuid":"../../../../node_modules/uuid/lib/bytesToUuid.js"}],"actions/PostActions.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
@ -34803,6 +34985,8 @@ var _dexie = _interopRequireDefault(require("dexie"));
var _sanitizeHtml = _interopRequireDefault(require("sanitize-html"));
var _DateUtils = _interopRequireDefault(require("../../../../../brain/tools/utilities/DateUtils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
@ -34815,6 +34999,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
var md = require('markdown-it')('commonmark');
var uuidv4 = require('uuid/v4');
var PostActions =
/*#__PURE__*/
function () {
@ -34825,6 +35011,7 @@ function () {
_classCallCheck(this, PostActions);
this.dataUtils = new _DataUtils.default();
this.dateUtils = new _DateUtils.default();
this.db = new _dexie.default("fipamo_posts");
this.db.version(1).stores({
postList: 'id,post'
@ -34836,7 +35023,7 @@ function () {
_createClass(PostActions, [{
key: "update",
value: function update(id, data, files) {
value: function update(id, data, files, lastKey) {
var _this = this;
var self = this;
@ -34868,21 +35055,70 @@ function () {
data.featured = document.getElementById('option-feature').getAttribute('data-active');
data.published = document.getElementById('option-published').getAttribute('data-active');
_this.db.postList.update(Number(id), {
post: data
}).then(function (updated) {
self.db.postList.toArray(function (array) {
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_JSON, array).then(function (response) {
resolve({
response: response
if (files.length != 0) {
for (var i = 0; i < files.length; i++) {
var file = files[i]; // Check the file type.
if (!file.type.match('image.*')) {
continue;
}
data.feature = "/content/blog-images/" + _this.dateUtils.getDate('year', new Date()) + "/" + _this.dateUtils.getDate('month', new Date()) + "/" + file.name;
}
} else {//data.feature = "";
}
if (id == null) {
_this.db.postList.put({
id: lastKey + 1,
post: {
uuid: uuidv4(),
title: data.title,
slug: data.slug,
plaintext: data.plaintext,
html: data.html,
feature: data.feature,
created: data.created,
tags: data.tags,
page: data.page,
featured: data.featured,
published: data.published,
author: "user"
}
}).then(function (fresh) {
self.db.postList.toArray(function (array) {
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_JSON, array).then(function (response) {
var bounce = {
message: response,
newPost: fresh
};
resolve({
bounce: bounce
});
}).catch(function (err) {
reject({
err: err
});
});
}).catch(function (err) {
reject({
err: err
}); //(updated) ? resolve("UPDATED") : reject("NOT UPDATED");
});
} else {
_this.db.postList.update(Number(id), {
post: data
}).then(function (updated) {
self.db.postList.toArray(function (array) {
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_JSON, array).then(function (response) {
resolve({
response: response
});
}).catch(function (err) {
reject({
err: err
});
});
});
}); //(updated) ? resolve("UPDATED") : reject("NOT UPDATED");
});
}); //(updated) ? resolve("UPDATED") : reject("NOT UPDATED");
});
}
});
}
}, {
@ -35005,7 +35241,7 @@ function () {
}();
exports.default = PostActions;
},{"../../../../../brain//tools/utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","../../../../../brain//tools/events/DataEvent":"../../../../brain/tools/events/DataEvent.js","../../../../../brain//tools/utilities/StringUtils":"../../../../brain/tools/utilities/StringUtils.js","dexie":"../../../../node_modules/dexie/dist/dexie.es.js","sanitize-html":"../../../../node_modules/sanitize-html/dist/index.js","markdown-it":"../../../../node_modules/markdown-it/index.js"}],"../../../../brain/tools/events/EditorEvent.js":[function(require,module,exports) {
},{"../../../../../brain//tools/utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","../../../../../brain//tools/events/DataEvent":"../../../../brain/tools/events/DataEvent.js","../../../../../brain//tools/utilities/StringUtils":"../../../../brain/tools/utilities/StringUtils.js","dexie":"../../../../node_modules/dexie/dist/dexie.es.js","sanitize-html":"../../../../node_modules/sanitize-html/dist/index.js","../../../../../brain/tools/utilities/DateUtils":"../../../../brain/tools/utilities/DateUtils.js","markdown-it":"../../../../node_modules/markdown-it/index.js","uuid/v4":"../../../../node_modules/uuid/v4.js"}],"../../../../brain/tools/events/EditorEvent.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
@ -36236,93 +36472,6 @@ var global = arguments[3];
})));
},{}],"../../../../brain/tools/utilities/DateUtils.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var DateUtils =
/*#__PURE__*/
function () {
//--------------------------
// constructor
//--------------------------
function DateUtils() {
_classCallCheck(this, DateUtils);
} //--------------------------
// methods
//--------------------------
_createClass(DateUtils, [{
key: "getMKtime",
value: function getMKtime() {
var time = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), new Date().getHours(), new Date().getMinutes(), new Date().getSeconds(), 0).getTime() / 1000;
return time;
}
}, {
key: "convertMKtime",
value: function convertMKtime(seconds) {
var date = new Date(seconds * 1000);
return date;
}
}, {
key: "getDate",
value: function getDate(type, rawdate) {
var day = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCDate()) : String(new Date().getUTCDate());
var month = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMonth() + 1) : String(new Date().getUTCMonth() + 1);
var year = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCFullYear()) : String(new Date().getUTCFullYear());
var hour = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCHours()) : String(new Date().getUTCHours());
var minute = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMinutes()) : String(new Date().getUTCMinutes());
var seconds = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCSeconds()) : String(new Date().getUTCSeconds());
var millisecond = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMilliseconds()) : String(new Date().getUTCMilliseconds());
var offset = rawdate != null || rawdate != '' ? String(new Date(rawdate).getTimezoneOffset()) : String(new Date().getTimezoneOffset());
if (day.length == 1) day = String("0" + day);
if (month.length == 1) month = String("0" + month);
offset = String(offset / 60);
if (offset.length == 1) offset = String("0" + offset);
switch (type) {
case "day":
return day;
break;
case "month":
return month;
break;
case "year":
return year;
break;
case "stamp":
return String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds + "." + millisecond + "-" + offset);
break;
default:
return String(year + "-" + month + "-" + day);
break;
}
} //--------------------------
// event handlers
//--------------------------
}]);
return DateUtils;
}();
var _default = DateUtils;
exports.default = _default;
},{}],"../../../../node_modules/caret-pos/lib/esm2015/main.js":[function(require,module,exports) {
"use strict";
@ -37109,14 +37258,20 @@ function () {
this.dateUtils = new _DateUtils.default();
this.urlPieces = document.URL.split("/");
this.post = [];
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
this.postID = null;
this.postCount = null;
this.postFinalKey = null;
if (document.getElementById('post-edit-index').getAttribute('data-index')) this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
var fipamoPosts = new _dexie.default("fipamo_posts");
fipamoPosts.version(1).stores({
postList: 'id, post'
});
fipamoPosts.postList.get(Number(this.postID)).then(function (obj) {
return _this.setPost(obj.post);
fipamoPosts.postList.toArray(function (array) {
self.setListVars(array);
});
if (this.postID != null) fipamoPosts.postList.get(Number(this.postID)).then(function (obj) {
return _this.setPost(obj.post);
});else this.start();
if (document.getElementById('edit-post-text')) {
this.editor = new _TextEditor.default(document.getElementById('edit-post-text'), document.getElementById('header').offsetHeight + document.getElementById('post-header').offsetHeight + document.getElementById('post-feature').offsetHeight);
@ -37154,6 +37309,12 @@ function () {
this.post = array;
this.start();
}
}, {
key: "setListVars",
value: function setListVars(array) {
this.postCount = array.length;
this.postFinalKey = array[this.postCount - 1].id;
}
}, {
key: "start",
value: function start() {
@ -37164,7 +37325,9 @@ function () {
if (document.getElementById('featured-image-drop')) {
document.getElementById('featured-image-drop').addEventListener('dragover', this.handleDragOver, false);
document.getElementById('featured-image-drop').addEventListener('drop', this.handleDrop, false);
document.getElementById('featured-click').addEventListener('change', this.handleClicked, false);
document.getElementById('featured-click').addEventListener('change', function (e) {
return _this2.handleFeatureImageAdd(e);
}, false);
if (document.getElementById('new-upload-link')) {
document.getElementById('new-upload-link').addEventListener('click', function (e) {
@ -37216,38 +37379,28 @@ function () {
switch (e) {
case EditorEvent.EDITOR_SAVE:
case EditorEvent.EDITOR_UPDATE:
var edit = false; //if (e == EditorEvent.EDITOR_UPDATE) edit = true;
new _PostActions.default().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(function (response) {
//console.log(response.bounce.newPost);
var freshDB = new _dexie.default("fipamo_posts");
freshDB.version(1).stores({
postList: 'id, post'
});
setTimeout(function (f) {
freshDB.postList.get(Number(response.bounce.newPost)).then(function (obj) {
window.location = "/@/dashboard/posts/edit/" + obj.post.slug;
});
}, 200); //this.editor.notify(DataEvent.POST_UPDATED, this.postID);
}).catch(function (err) {
console.log("ERROR", err);
});
break;
new _PostActions.default().update(this.postID, this.post, PostEditor.uploadFiles).then(function (response) {
case EditorEvent.EDITOR_UPDATE:
new _PostActions.default().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(function (response) {
_this3.editor.notify(DataEvent.POST_UPDATED, _this3.postID);
}).catch(function (err) {
console.log("ERROR", err);
});
/**
new PostActions().sync(PostEditor.uploadFiles).then((response) =>
{
let note = JSON.parse(response['response']['request'].response);
//this.editor.notify(note.message, note.postID);
//if (note.message == DataEvent.POST_ADDED) window.location = "/@/dashboard/posts/edit/" + note.postID;
}).catch((err) =>
{
console.log(err)
});
*/
/*
new PostActions().submitPost(edit, PostEditor.uploadFiles).then((response) =>
{
let note = JSON.parse(response['response']['request'].response);
this.editor.notify(note.message, note.postID);
if (note.message == DataEvent.POST_ADDED) window.location = "/@/dashboard/posts/edit/" + note.postID;
}).catch((err) =>
{
console.log(err)
});
*/
break;
case EditorEvent.EDITOR_DELETE:
@ -37276,12 +37429,11 @@ function () {
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
}, {
key: "handleClicked",
value: function handleClicked(e) {
key: "handleDrop",
value: function handleDrop(e) {
e.stopPropagation();
e.preventDefault(); //console.log("IMAGES " + e.target.files);
PostEditor.uploadFiles = e.target.files;
e.preventDefault();
PostEditor.uploadFiles = e.dataTransfer.files; //console.log(MemberArea.uploadFiles.length);
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) {
// Only process image files.
@ -37294,14 +37446,11 @@ function () {
reader.onload = function (theFile) {
return function (f) {
// Render thumbnail.
var image = document.createElement('img');
image.src = f.target.result;
image.title = escape(theFile.name);
var span = document.createElement('div');
var span = document.createElement('span');
span.innerHTML = ['<img src="', f.target.result, '" title="', escape(theFile.name), '"/>'].join(''); //document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById('featured-image-drop').innerHTML = '';
document.getElementById('featured-image-drop').appendChild(image);
document.getElementById('featured-image-drop').appendChild(span);
};
}(f); // Read in the image file as a data URL.
@ -37310,11 +37459,29 @@ function () {
}
}
}, {
key: "handleDrop",
value: function handleDrop(e) {
key: "handleFeatureImageAdd",
value: function handleFeatureImageAdd(e) {
e.stopPropagation();
e.preventDefault();
PostEditor.uploadFiles = e.dataTransfer.files; //console.log(MemberArea.uploadFiles.length);
var self = this;
var postData = new FormData();
var files = e.target.files;
for (var i = 0; i < files.length; i++) {
var file = files[i]; // Check the file type.
if (!file.type.match('image.*')) {
continue;
}
postData.append('feature_image', file, file.name);
}
this.dataUtils.request("/api/post/add-feature-image", DataEvent.FEATURE_IMAGE_ADDED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM, postData).then(function (response) {//self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, JSON.parse(response.request['response']).url);
}).catch(function (err) {
console.log(err);
});
PostEditor.uploadFiles = e.target.files;
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) {
// Only process image files.
@ -37327,11 +37494,14 @@ function () {
reader.onload = function (theFile) {
return function (f) {
// Render thumbnail.
var span = document.createElement('span');
var image = document.createElement('img');
image.src = f.target.result;
image.title = escape(theFile.name);
var span = document.createElement('div');
span.innerHTML = ['<img src="', f.target.result, '" title="', escape(theFile.name), '"/>'].join(''); //document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById('featured-image-drop').innerHTML = '';
document.getElementById('featured-image-drop').appendChild(span);
document.getElementById('featured-image-drop').appendChild(image);
};
}(f); // Read in the image file as a data URL.
@ -37358,7 +37528,7 @@ function () {
postData.append('post_image', file, file.name);
}
this.dataUtils.request("/api/blog/add-post-image", DataEvent.POST_IMAGE_ADDED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM, postData).then(function (response) {
this.dataUtils.request("/api/post/add-post-image", DataEvent.POST_IMAGE_ADDED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM, postData).then(function (response) {
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, JSON.parse(response.request['response']).url);
}).catch(function (err) {
console.log(err);
@ -37650,7 +37820,7 @@ var parent = module.bundle.parent;
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
var hostname = "" || location.hostname;
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
var ws = new WebSocket(protocol + '://' + hostname + ':' + "61971" + '/');
var ws = new WebSocket(protocol + '://' + hostname + ':' + "64227" + '/');
ws.onmessage = function (event) {
var data = JSON.parse(event.data);

File diff suppressed because one or more lines are too long

@ -25,8 +25,8 @@
br
- var index = 0;
- for ( index; index < items.length; index++)
a(href="/@/dashboard/posts/edit/"+items[index].slug id=items[index].uuid)
= items[index].title
a(href="/@/dashboard/posts/edit/"+items[index].post.slug id=items[index].post.uuid)
= items[index].post.title
br
br

@ -11,7 +11,7 @@ block main-content
- var index = 0;
- for ( index; index < items.length; index++)
- var date = new Date(items[index].post.created)
a.post-list-link(href="/@/dashboard/posts/edit/"+items[index].slug id=items[index].uuid)
a.post-list-link(href="/@/dashboard/posts/edit/"+items[index].post.slug id=items[index].post.uuid)
= items[index].post.title
br
span= date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()

@ -12,7 +12,9 @@ import * as DataEvent from '../../../../../brain//tools/events/DataEvent';
import StringUtils from '../../../../../brain//tools/utilities/StringUtils';
import Dexie from 'dexie';
import sanitize from 'sanitize-html'
import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
var md = require('markdown-it')('commonmark');
var uuidv4 = require('uuid/v4');
class PostActions
{
//--------------------------
@ -21,6 +23,7 @@ class PostActions
constructor()
{
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
this.db = new Dexie("fipamo_posts");
this.db.version(1).stores(
{
@ -30,7 +33,7 @@ class PostActions
//--------------------------
// methods
//--------------------------
update(id, data, files)
update(id, data, files, lastKey)
{
let self = this;
return new Promise((resolve, reject) =>
@ -63,29 +66,96 @@ class PostActions
data.page = document.getElementById('option-page').getAttribute('data-active')
data.featured = document.getElementById('option-feature').getAttribute('data-active')
data.published = document.getElementById('option-published').getAttribute('data-active')
this.db.postList.update(Number(id), {post:data}).then(updated =>
if (files.length != 0)
{
self.db.postList.toArray(array =>
for (var i = 0; i < files.length; i++)
{
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, array).then((response) =>
var file = files[i];
// Check the file type.
if (!file.type.match('image.*'))
{
resolve(
continue;
}
data.feature = "/content/blog-images/" + this.dateUtils.getDate('year', new Date()) + "/" + this.dateUtils.getDate('month', new Date()) + "/" + file.name;
}
}
else
{
//data.feature = "";
}
if (id == null)
{
this.db.postList.put(
{
id: lastKey + 1,
post:
{
uuid: uuidv4(),
title: data.title,
slug: data.slug,
plaintext: data.plaintext,
html: data.html,
feature:data.feature,
created: data.created,
tags: data.tags,
page: data.page,
featured: data.featured,
published: data.published,
author: "user"
}
}).then(fresh =>
{
self.db.postList.toArray(array =>
{
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, array).then((response) =>
{
let bounce = {
message: response,
newPost: fresh
}
resolve(
{
bounce
})
}).catch((err) =>
{
response
reject(
{
err
});
})
}).catch((err) =>
})
//(updated) ? resolve("UPDATED") : reject("NOT UPDATED");
});
}
else
{
this.db.postList.update(Number(id),
{
post: data
}).then(updated =>
{
self.db.postList.toArray(array =>
{
reject(
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, array).then((response) =>
{
err
});
resolve(
{
response
})
}).catch((err) =>
{
reject(
{
err
});
})
})
})
//(updated) ? resolve("UPDATED") : reject("NOT UPDATED");
});
//(updated) ? resolve("UPDATED") : reject("NOT UPDATED");
});
}
})
}
sync(files)

@ -28,17 +28,25 @@ export default class PostEditor
let self = this;
this.uploadFiles;
this.anim = new Animate();
this.dataUtils = new DataUtils
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
this.urlPieces = document.URL.split("/");
this.post = [];
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
this.postID = null;
this.postCount = null;
this.postFinalKey = null;
if (document.getElementById('post-edit-index').getAttribute('data-index')) this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
var fipamoPosts = new Dexie("fipamo_posts");
fipamoPosts.version(1).stores(
{
postList: 'id, post'
});
fipamoPosts.postList.get(Number(this.postID)).then(obj => this.setPost(obj.post));
fipamoPosts.postList.toArray(array =>
{
self.setListVars(array);
})
if (this.postID != null) fipamoPosts.postList.get(Number(this.postID)).then(obj => this.setPost(obj.post));
else this.start();
if (document.getElementById('edit-post-text'))
{
this.editor = new TextEditor(document.getElementById('edit-post-text'), document.getElementById('header').offsetHeight + document.getElementById('post-header').offsetHeight + document.getElementById('post-feature').offsetHeight);
@ -66,6 +74,11 @@ export default class PostEditor
this.post = array;
this.start();
}
setListVars(array)
{
this.postCount = array.length;
this.postFinalKey = array[this.postCount - 1].id;
}
start()
{
let self = this;
@ -73,7 +86,7 @@ export default class PostEditor
{
document.getElementById('featured-image-drop').addEventListener('dragover', this.handleDragOver, false);
document.getElementById('featured-image-drop').addEventListener('drop', this.handleDrop, false);
document.getElementById('featured-click').addEventListener('change', this.handleClicked, false);
document.getElementById('featured-click').addEventListener('change', e => this.handleFeatureImageAdd(e), false);
if (document.getElementById('new-upload-link'))
{
document.getElementById('new-upload-link').addEventListener('click', e =>
@ -117,38 +130,35 @@ export default class PostEditor
switch (e)
{
case EditorEvent.EDITOR_SAVE:
case EditorEvent.EDITOR_UPDATE:
let edit = false;
//if (e == EditorEvent.EDITOR_UPDATE) edit = true;
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles).then(response=>{
this.editor.notify(DataEvent.POST_UPDATED, this.postID);
}).catch(err=>{
console.log("ERROR", err)
})
/**
new PostActions().sync(PostEditor.uploadFiles).then((response) =>
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(response =>
{
let note = JSON.parse(response['response']['request'].response);
//this.editor.notify(note.message, note.postID);
//if (note.message == DataEvent.POST_ADDED) window.location = "/@/dashboard/posts/edit/" + note.postID;
}).catch((err) =>
//console.log(response.bounce.newPost);
let freshDB = new Dexie("fipamo_posts");
freshDB.version(1).stores(
{
postList: 'id, post'
});
setTimeout(f =>
{
freshDB.postList.get(Number(response.bounce.newPost)).then(obj =>
{
window.location = "/@/dashboard/posts/edit/" + obj.post.slug;
});
}, 200);
//this.editor.notify(DataEvent.POST_UPDATED, this.postID);
}).catch(err =>
{
console.log(err)
});
*/
/*
new PostActions().submitPost(edit, PostEditor.uploadFiles).then((response) =>
console.log("ERROR", err)
})
break
case EditorEvent.EDITOR_UPDATE:
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(response =>
{
let note = JSON.parse(response['response']['request'].response);
this.editor.notify(note.message, note.postID);
if (note.message == DataEvent.POST_ADDED) window.location = "/@/dashboard/posts/edit/" + note.postID;
}).catch((err) =>
this.editor.notify(DataEvent.POST_UPDATED, this.postID);
}).catch(err =>
{
console.log(err)
});
*/
console.log("ERROR", err)
})
break;
case EditorEvent.EDITOR_DELETE:
if (confirm('Aye! You know you\'re deleting this post, right?'))
@ -179,12 +189,12 @@ export default class PostEditor
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
handleClicked(e)
handleDrop(e)
{
e.stopPropagation();
e.preventDefault();
//console.log("IMAGES " + e.target.files);
PostEditor.uploadFiles = e.target.files;
PostEditor.uploadFiles = e.dataTransfer.files;
//console.log(MemberArea.uploadFiles.length);
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++)
{
// Only process image files.
@ -199,29 +209,45 @@ export default class PostEditor
return function(f)
{
// Render thumbnail.
var image = document.createElement('img');
image.src = f.target.result;
image.title = escape(theFile.name);
var span = document.createElement('div');
var span = document.createElement('span');
span.innerHTML = ['<img src="',
f.target.result, '" title="',
escape(theFile.name), '"/>'
].join('');
//document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById('featured-image-drop').innerHTML = '';
document.getElementById('featured-image-drop').appendChild(image);
document.getElementById('featured-image-drop').appendChild(span);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
handleDrop(e)
handleFeatureImageAdd(e)
{
e.stopPropagation();
e.preventDefault();
PostEditor.uploadFiles = e.dataTransfer.files;
//console.log(MemberArea.uploadFiles.length);
let self = this;
var postData = new FormData();
var files = e.target.files;
for (var i = 0; i < files.length; i++)
{
var file = files[i];
// Check the file type.
if (!file.type.match('image.*'))
{
continue;
}
postData.append('feature_image', file, file.name);
}
this.dataUtils.request("/api/post/add-feature-image", DataEvent.FEATURE_IMAGE_ADDED, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, postData).then((response) =>
{
//self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, JSON.parse(response.request['response']).url);
}).catch((err) =>
{
console.log(err)
})
PostEditor.uploadFiles = e.target.files;
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++)
{
// Only process image files.
@ -236,14 +262,17 @@ export default class PostEditor
return function(f)
{
// Render thumbnail.
var span = document.createElement('span');
var image = document.createElement('img');
image.src = f.target.result;
image.title = escape(theFile.name);
var span = document.createElement('div');
span.innerHTML = ['<img src="',
f.target.result, '" title="',
escape(theFile.name), '"/>'
].join('');
//document.getElementById('featured-image-drop').insertBefore(span, null);
document.getElementById('featured-image-drop').innerHTML = '';
document.getElementById('featured-image-drop').appendChild(span);
document.getElementById('featured-image-drop').appendChild(image);
};
})(f);
// Read in the image file as a data URL.
@ -267,7 +296,7 @@ export default class PostEditor
}
postData.append('post_image', file, file.name);
}
this.dataUtils.request("/api/blog/add-post-image", DataEvent.POST_IMAGE_ADDED, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, postData).then((response) =>
this.dataUtils.request("/api/post/add-post-image", DataEvent.POST_IMAGE_ADDED, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, postData).then((response) =>
{
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, JSON.parse(response.request['response']).url);
}).catch((err) =>

Loading…
Cancel
Save