completed CRUD functionality for new data syncing methodology. fuck. yes.

sql-version-freeze
Ro 6 years ago
parent 22af04f59a
commit b0cb4d9229

@ -55,7 +55,6 @@ var post_upload = multer(
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))
@ -122,7 +121,19 @@ router.get('/json', function(req, res, next)
]
}).then(function(posts)
{
res.json(posts)
let newlist = [];
for (let index = 0; index < posts.length; index++) {
let item = posts[index].post;
if(typeof item.deleted == 'undefined' || item.deleted == false)
{
newlist.push(posts[index])
}else{
continue
}
}
res.json(newlist)
}).catch(function(err)
{
//next(err);

@ -25,7 +25,21 @@ router.get('/:page?', function(req, res)
]
}).then(function(posts)
{
var count = Math.round(posts.length / 6);
let filtered = [];
for (let index = 0; index < posts.length; index++)
{
let item = posts[index].post;
if (typeof item.deleted == 'undefined' || item.deleted == false)
{
filtered.push(posts[index])
}
else
{
continue
}
}
var count = Math.round(filtered.length / 6);
//console.log("COUNT: "+count);
var pageItems = [];
var itemLimit = 6;
@ -36,7 +50,7 @@ router.get('/:page?', function(req, res)
{
if (posts[i + rangeStart].id != null)
{
pageItems.push(posts[i + rangeStart]);
pageItems.push(filtered[i + rangeStart]);
}
}
catch (e)
@ -109,8 +123,7 @@ router.get('/edit/:id', function(req, res)
}).then(item =>
{
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 sexydate = dateUtils.getDate('year', item.post.created) + "-" + dateUtils.getDate('month', item.post.created) + "-" + dateUtils.getDate('day', item.post.created)
res.render('dash/post-edit',

@ -23,11 +23,24 @@ router.get('/', function(req, res)
limit: 5
}).then(function(posts)
{
let filtered = [];
for (let index = 0; index < posts.length; index++)
{
let item = posts[index].post;
if (typeof item.deleted == 'undefined' || item.deleted == false)
{
filtered.push(posts[index])
}
else
{
continue
}
}
res.render('dash/index',
{
title: 'Dashboard',
user_status: loggedIn,
items: posts
items: filtered
});
}).then(function(value)
{

@ -1,7 +1,18 @@
"use strict";
import DataUtils from '../../../themes/default/src/com/tools/utilities/DataUtils';
import 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 * as DataEvent from '../events/DataEvent';
export var COUNT;
export var FINAL_KEY;
export default class DBUtils
{
//--------------------------
@ -15,11 +26,68 @@ export default class DBUtils
{
postList: 'id,post'
});
this.db.postList.toArray(array =>
{
COUNT = array.length;
FINAL_KEY = array[COUNT - 1].id;
})
}
//--------------------------
// methods
//--------------------------
resetLocal(array)
modify(id, postData)
{
let self = this;
let freshID;
return new Promise(function(resolve, reject)
{
if (id == null)
{
self.db.postList.put(postData).then(fresh =>
{
freshID = fresh;
}).catch(e =>
{
let err = {
message: "PUT ERROR",
error: e
}
});
}
else
{
self.db.postList.update(Number(id),
{
post: postData
}).then(updated =>
{}).catch(e =>
{
consol.log("ERROR", e)
let err = {
message: "UPDATE ERROR",
error: e
}
});
}
self.db.postList.toArray(array =>
{
self.syncRemote(array, freshID).then(response =>
{
resolve(
{
response
})
}).catch(err =>
{
reject(
{
err
});
});
})
})
}
syncLocal(array)
{
let self = this;
return new Promise(function(resolve, reject)
@ -46,6 +114,86 @@ export default class DBUtils
})
})
}
syncRemote(db, newPostId)
{
let self = this;
return new Promise(function(resolve, reject)
{
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, db).then((response) =>
{
let bounce = {
message: response,
newPost: newPostId
}
resolve(bounce)
}).catch((err) =>
{
reject(err);
})
})
}
getPost(id)
{
let self = this;
if (id == null)
{
return new Promise(function(resolve, reject)
{
self.db.postList.toArray(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)
})
})
}
}
archivePost(id, archive)
{
let self = this;
return new Promise(function(resolve, reject)
{
self.db.postList.update(Number(id),
{
post: archive
}).then(deleted =>
{
self.db.postList.toArray(array =>
{
self.syncRemote(array, null).then(response =>
{
resolve(
{
response
})
}).catch(err =>
{
reject(
{
err
});
});
})
}).catch(e =>
{
console.log("ERROR", e)
});
})
}
//--------------------------
// event handlers
//--------------------------

@ -6,109 +6,134 @@ export const CONTENT_TYPE_JSON = 'json';
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
import EventEmitter from '../events/EventEmitter';
import * as DataEvent from '../events/DataEvent';
class DataUtils extends EventEmitter {
//--------------------------
// constructor
//--------------------------
constructor() {
super();
var self = this;
}
//--------------------------
// methods
//--------------------------
request(requestURL, eventType, requestType = REQUEST_TYPE_GET, contentType = CONTENT_TYPE_JSON, requestData = null) {
var self = this;
return new Promise(function(resolve, reject) {
var request = new XMLHttpRequest();
request.upload.onprogress = self.handleLoadProgress;
request.open(requestType, requestURL, true);
request.onload = function(e) {
if (request.status == 200) {
resolve({
request,
eventType
});
} else {
reject({
request,
eventType
});
}
;
};
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
switch (contentType) {
case CONTENT_TYPE_JSON:
request.setRequestHeader("Content-type", "application/" + contentType);
request.send(JSON.stringify(requestData));
break;
case CONTENT_TYPE_FORM:
request.send(requestData);
break;
}
} else {
request.send();
}
})
}
imgLoad(url) {
'use strict';
// Create new promise with the Promise() constructor;
// This has as its argument a function with two parameters, resolve and reject
return new Promise(function(resolve, reject) {
// Standard XHR to load an image
var request = new XMLHttpRequest();
request.open('GET', url);
request.responseType = 'blob';
// When the request loads, check whether it was successful
request.onload = function() {
if (request.status === 200) {
// If successful, resolve the promise by passing back the request response
resolve(request.response);
} else {
// If it fails, reject the promise with a error message
reject(new Error('Image didn\'t load successfully; error code:' + request.statusText));
}
};
request.onerror = function() {
// 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
reject(new Error('There was a network error.'));
};
// Send the request
request.send();
});
}
loadImage(src) {
'use strict';
let self = this;
return new Promise(function(resolve, reject) {
// Get a reference to the body element, and create a new image object
var body = document.querySelector('body'),
myImage = new Image();
myImage.crossOrigin = ""; // or "anonymous"
// 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
self.imgLoad(src).then(function(response) {
// The first runs when the promise resolves, with the request.reponse specified within the resolve() method.
var imageURL = window.URL.createObjectURL(response);
resolve(imageURL);
//$('background-content').setStyle('background-image', 'url('+imageURL+')') //myImage.src = imageURL;
//console.log(imageURL);
//body.appendChild(myImage);
// The second runs when the promise is rejected, and logs the Error specified with the reject() method.
}, function(Error) {
reject(Error)
});
});
}
//--------------------------
// event handlers
//--------------------------
handleLoadProgress(e) {
var percentComplete = Math.ceil((e.loaded / e.total) * 100);
//console.log(percentComplete);
}
class DataUtils extends EventEmitter
{
//--------------------------
// constructor
//--------------------------
constructor()
{
super();
var self = this;
}
//--------------------------
// methods
//--------------------------
request(requestURL, eventType, requestType = REQUEST_TYPE_GET, contentType = CONTENT_TYPE_JSON, requestData = null)
{
var self = this;
return new Promise(function(resolve, reject)
{
var request = new XMLHttpRequest();
request.upload.onprogress = self.handleLoadProgress;
request.open(requestType, requestURL, true);
request.onload = function(e)
{
if (request.status == 200)
{
resolve(
{
request,
eventType
});
}
else
{
reject(
{
request,
eventType
});
};
};
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST)
{
switch (contentType)
{
case CONTENT_TYPE_JSON:
request.setRequestHeader("Content-type", "application/" + contentType);
request.send(JSON.stringify(requestData));
break;
case CONTENT_TYPE_FORM:
request.send(requestData);
break;
}
}
else
{
request.send();
}
})
}
imgLoad(url)
{
'use strict';
// Create new promise with the Promise() constructor;
// This has as its argument a function with two parameters, resolve and reject
return new Promise(function(resolve, reject)
{
// Standard XHR to load an image
var request = new XMLHttpRequest();
request.open('GET', url);
request.responseType = 'blob';
// When the request loads, check whether it was successful
request.onload = function()
{
if (request.status === 200)
{
// If successful, resolve the promise by passing back the request response
resolve(request.response);
}
else
{
// If it fails, reject the promise with a error message
reject(new Error('Image didn\'t load successfully; error code:' + request.statusText));
}
};
request.onerror = function()
{
// 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
reject(new Error('There was a network error.'));
};
// Send the request
request.send();
});
}
loadImage(src)
{
'use strict';
let self = this;
return new Promise(function(resolve, reject)
{
// Get a reference to the body element, and create a new image object
var body = document.querySelector('body'),
myImage = new Image();
myImage.crossOrigin = ""; // or "anonymous"
// 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
self.imgLoad(src).then(function(response)
{
// The first runs when the promise resolves, with the request.reponse specified within the resolve() method.
var imageURL = window.URL.createObjectURL(response);
resolve(imageURL);
//$('background-content').setStyle('background-image', 'url('+imageURL+')') //myImage.src = imageURL;
//console.log(imageURL);
//body.appendChild(myImage);
// The second runs when the promise is rejected, and logs the Error specified with the reject() method.
}, function(Error)
{
reject(Error)
});
});
}
//--------------------------
// event handlers
//--------------------------
handleLoadProgress(e)
{
var percentComplete = Math.ceil((e.loaded / e.total) * 100);
//console.log(percentComplete);
}
}
export default DataUtils;
export default DataUtils;

@ -27452,7 +27452,192 @@ function () {
var _default = DateUtils;
exports.default = _default;
},{}],"../../../../node_modules/markdown-it/lib/common/entities.js":[function(require,module,exports) {
},{}],"../../../../brain/tools/utilities/DBUtils.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.FINAL_KEY = exports.COUNT = void 0;
var _DataUtils = _interopRequireWildcard(require("../utilities/DataUtils"));
var _dexie = _interopRequireDefault(require("dexie"));
var DataEvent = _interopRequireWildcard(require("../events/DataEvent"));
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; } }
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 COUNT;
exports.COUNT = COUNT;
var FINAL_KEY;
exports.FINAL_KEY = FINAL_KEY;
var DBUtils =
/*#__PURE__*/
function () {
//--------------------------
// constructor
//--------------------------
function DBUtils() {
_classCallCheck(this, DBUtils);
this.dataUtils = new _DataUtils.default();
this.db = new _dexie.default("fipamo_posts");
this.db.version(1).stores({
postList: 'id,post'
});
this.db.postList.toArray(function (array) {
exports.COUNT = COUNT = array.length;
exports.FINAL_KEY = FINAL_KEY = array[COUNT - 1].id;
});
} //--------------------------
// methods
//--------------------------
_createClass(DBUtils, [{
key: "modify",
value: function modify(id, postData) {
var self = this;
var freshID;
return new Promise(function (resolve, reject) {
if (id == null) {
self.db.postList.put(postData).then(function (fresh) {
freshID = fresh;
}).catch(function (e) {
var err = {
message: "PUT ERROR",
error: e
};
});
} else {
self.db.postList.update(Number(id), {
post: postData
}).then(function (updated) {}).catch(function (e) {
consol.log("ERROR", e);
var err = {
message: "UPDATE ERROR",
error: e
};
});
}
self.db.postList.toArray(function (array) {
self.syncRemote(array, freshID).then(function (response) {
resolve({
response: response
});
}).catch(function (err) {
reject({
err: err
});
});
});
});
}
}, {
key: "syncLocal",
value: function syncLocal(array) {
var self = this;
return new Promise(function (resolve, reject) {
self.db.postList.clear().then(function (result) {
self.db.postList.bulkAdd(array).then(function (key) {
self.db.postList.toArray(function (array) {
var event = DataEvent.LOCAL_DB_READY;
resolve({
event: event
});
});
}).catch(_dexie.default.BulkError, function (e) {
reject({
e: e
});
});
});
});
}
}, {
key: "syncRemote",
value: function syncRemote(db, newPostId) {
var self = this;
return new Promise(function (resolve, reject) {
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_JSON, db).then(function (response) {
var bounce = {
message: response,
newPost: newPostId
};
resolve(bounce);
}).catch(function (err) {
reject(err);
});
});
}
}, {
key: "getPost",
value: function getPost(id) {
var self = this;
if (id == null) {
return new Promise(function (resolve, reject) {
self.db.postList.toArray(function (array) {
resolve(array);
}).catch(function (err) {
reject(err);
});
});
} else {
return new Promise(function (resolve, reject) {
self.db.postList.get(Number(id)).then(function (obj) {
resolve(obj);
}).catch(function (err) {
reject(err);
});
});
}
}
}, {
key: "archivePost",
value: function archivePost(id, archive) {
var self = this;
return new Promise(function (resolve, reject) {
self.db.postList.update(Number(id), {
post: archive
}).then(function (deleted) {
self.db.postList.toArray(function (array) {
self.syncRemote(array, null).then(function (response) {
resolve({
response: response
});
}).catch(function (err) {
reject({
err: err
});
});
});
}).catch(function (e) {
console.log("ERROR", e);
});
});
} //--------------------------
// event handlers
//--------------------------
}]);
return DBUtils;
}();
exports.default = DBUtils;
},{"../utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","dexie":"../../../../node_modules/dexie/dist/dexie.es.js","../events/DataEvent":"../../../../brain/tools/events/DataEvent.js"}],"../../../../node_modules/markdown-it/lib/common/entities.js":[function(require,module,exports) {
// HTML5 entities map: { name -> utf16string }
//
'use strict';
@ -34989,6 +35174,8 @@ var _sanitizeHtml = _interopRequireDefault(require("sanitize-html"));
var _DateUtils = _interopRequireDefault(require("../../../../../brain/tools/utilities/DateUtils"));
var _DBUtils = _interopRequireDefault(require("../../../../../brain/tools/utilities/DBUtils"));
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; } }
@ -35014,10 +35201,7 @@ function () {
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'
});
this.dbUtils = new _DBUtils.default();
} //--------------------------
// methods
//--------------------------
@ -35027,7 +35211,7 @@ function () {
key: "update",
value: function update(id, data, files, lastKey) {
var self = this;
var newID = null;
var freshData;
return new Promise(function (resolve, reject) {
var txt = document.createElement("textarea");
txt.innerHTML = document.getElementById('edit-post-text').innerHTML;
@ -35066,11 +35250,12 @@ function () {
data.feature = "/content/blog-images/" + self.dateUtils.getDate('year', new Date()) + "/" + self.dateUtils.getDate('month', new Date()) + "/" + file.name;
}
} else {//data.feature = "";
} else {
if (typeof data.feature == 'undefined') data.feature = "";
}
if (id == null) {
self.db.postList.put({
freshData = {
id: lastKey + 1,
post: {
uuid: uuidv4(),
@ -35084,63 +35269,33 @@ function () {
page: data.page,
featured: data.featured,
published: data.published,
deleted: "",
author: "user"
}
}).then(function (fresh) {
newID = fresh;
});
};
} else {
self.db.postList.update(Number(id), {
post: data
}).then(function (updated) {});
freshData = data;
}
self.db.postList.toArray(function (array) {
self.sync(array, newID).then(function (response) {
resolve({
response: response
});
}).catch(function (err) {
reject({
err: err
});
});
});
});
}
}, {
key: "sync",
value: function sync(db, newPostId) {
var self = this;
return new Promise(function (resolve, reject) {
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_JSON, db).then(function (response) {
var bounce = {
message: response,
newPost: newPostId
};
resolve({
bounce: bounce
});
self.dbUtils.modify(id, freshData).then(function (response) {
resolve(response);
}).catch(function (err) {
reject({
err: err
});
reject(err);
});
});
}
}, {
key: "deletePost",
value: function deletePost() {
value: function deletePost(id, body) {
var self = this;
body.deleted = new Date().toString();
return new Promise(function (resolve, reject) {
self.dataUtils.request("/api/post/delete/" + postID, DataEvent.POST_DELETED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM).then(function (response) {
resolve({
response: response
});
self.dbUtils.archivePost(id, body).then(function (response) {
console.log(response);
resolve(response);
}).catch(function (err) {
reject({
err: err
});
console.log(err);
reject(error);
});
});
} //--------------------------
@ -35153,7 +35308,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","../../../../../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) {
},{"../../../../../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","../../../../../brain/tools/utilities/DBUtils":"../../../../brain/tools/utilities/DBUtils.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", {
@ -37141,6 +37296,8 @@ var _TextEditor = _interopRequireDefault(require("../../../../../brain/tools/ui/
var _dexie = _interopRequireDefault(require("dexie"));
var _DBUtils = _interopRequireWildcard(require("../../../../../brain/tools/utilities/DBUtils"));
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; } }
@ -37167,21 +37324,21 @@ function () {
this.dataUtils = new _DataUtils.default();
this.dateUtils = new _DateUtils.default();
this.urlPieces = document.URL.split("/");
this.dbUtils = new _DBUtils.default();
this.post = [];
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.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('post-edit-index').getAttribute('data-index')) {
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
this.dbUtils.getPost(this.postID).then(function (body) {
self.post = body.post;
_this.start();
}).catch(function (err) {//console.log(err)
});
} 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);
@ -37214,18 +37371,6 @@ function () {
_createClass(PostEditor, [{
key: "setPost",
value: function setPost(array) {
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() {
var _this2 = this;
@ -37287,37 +37432,33 @@ function () {
value: function handleEditorOptions(e) {
var _this3 = this;
var self = this;
switch (e) {
case EditorEvent.EDITOR_SAVE:
new _PostActions.default().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(function (response) {
var freshDB = new _dexie.default("fipamo_posts");
freshDB.version(1).stores({
postList: 'id, post'
});
new _PostActions.default().update(this.postID, this.post, PostEditor.uploadFiles, _DBUtils.FINAL_KEY).then(function (response) {
setTimeout(function (f) {
freshDB.postList.get(Number(response.response.bounce.newPost)).then(function (obj) {
window.location = "/@/dashboard/posts/edit/" + obj.post.slug;
self.dbUtils.getPost(Number(response.response.newPost)).then(function (r) {
window.location = "/@/dashboard/posts/edit/" + r.post.slug;
});
}, 200);
}).catch(function (err) {
console.log("ERROR", err);
}, 100);
}).catch(function (err) {//console.log("ERROR", err)
});
break;
case EditorEvent.EDITOR_UPDATE:
new _PostActions.default().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(function (response) {
//console.log(response.response.bounce.newPost);
new _PostActions.default().update(this.postID, this.post, PostEditor.uploadFiles, _DBUtils.FINAL_KEY).then(function (response) {
_this3.editor.notify(DataEvent.POST_UPDATED, _this3.postID);
}).catch(function (err) {
console.log("ERROR", err);
}).catch(function (err) {//console.log("ERRORZ", err)
});
break;
case EditorEvent.EDITOR_DELETE:
if (confirm('Aye! You know you\'re deleting this post, right?')) {
new _PostActions.default().deletePost().then(function (response) {
var note = JSON.parse(response['response']['request'].response);
window.location = "/@/dashboard/posts/";
new _PostActions.default().deletePost(this.postID, this.post).then(function (response) {
setTimeout(function (f) {
window.location = "/@/dashboard/posts/";
}, 100);
}).catch(function (err) {
console.log(err);
});
@ -37401,8 +37542,7 @@ function () {
this.dataUtils.request(url, eventType, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM, imageData).then(function (response) {
var r = JSON.parse(response.request['response']);
if (r.message == DataEvent.POST_IMAGE_ADDED) self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
}).catch(function (err) {
console.log(err);
}).catch(function (err) {//console.log(err)
});
}
}]);
@ -37412,7 +37552,7 @@ function () {
exports.default = PostEditor;
PostEditor.uploadFiles = [];
},{"../../../../../brain/tools/utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","../../../../../brain/tools/events/DataEvent":"../../../../brain/tools/events/DataEvent.js","../../../../../brain/tools/effects/Animate":"../../../../brain/tools/effects/Animate.js","../actions/PostActions":"actions/PostActions.js","../../../../../brain/tools/events/EditorEvent":"../../../../brain/tools/events/EditorEvent.js","tiny-date-picker":"../../../../node_modules/tiny-date-picker/dist/tiny-date-picker.js","../../../../../brain/tools/utilities/DateUtils":"../../../../brain/tools/utilities/DateUtils.js","../../../../../brain/tools/ui/TextEditor":"../../../../brain/tools/ui/TextEditor.js","dexie":"../../../../node_modules/dexie/dist/dexie.es.js"}],"controllers/PostIndex.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/effects/Animate":"../../../../brain/tools/effects/Animate.js","../actions/PostActions":"actions/PostActions.js","../../../../../brain/tools/events/EditorEvent":"../../../../brain/tools/events/EditorEvent.js","tiny-date-picker":"../../../../node_modules/tiny-date-picker/dist/tiny-date-picker.js","../../../../../brain/tools/utilities/DateUtils":"../../../../brain/tools/utilities/DateUtils.js","../../../../../brain/tools/ui/TextEditor":"../../../../brain/tools/ui/TextEditor.js","dexie":"../../../../node_modules/dexie/dist/dexie.es.js","../../../../../brain/tools/utilities/DBUtils":"../../../../brain/tools/utilities/DBUtils.js"}],"controllers/PostIndex.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
@ -37549,396 +37689,7 @@ function () {
}();
exports.default = DashManager;
},{"./PostEditor":"controllers/PostEditor.js","../../../../../brain/tools/effects/Animate":"../../../../brain/tools/effects/Animate.js","./PostIndex":"controllers/PostIndex.js"}],"../../../default/src/com/tools/events/EventEmitter.jsx":[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 EventEmitter =
/*#__PURE__*/
function () {
//--------------------------
// constructor
//--------------------------
function EventEmitter() {
_classCallCheck(this, EventEmitter);
this.listeners = new Map();
} //--------------------------
// methods
//--------------------------
_createClass(EventEmitter, [{
key: "addListener",
value: function addListener(label, callback) {
this.listeners.has(label) || this.listeners.set(label, []);
this.listeners.get(label).push(callback);
}
}, {
key: "removeListener",
value: function removeListener(label, callback) {
var isFunction = function isFunction(obj) {
return typeof obj == 'function' || false;
};
var listeners = this.listeners.get(label),
index;
if (listeners && listeners.length) {
index = listeners.reduce(function (i, listener, index) {
return isFunction(listener) && listener === callback ? i = index : i;
}, -1);
if (index > -1) {
listeners.splice(index, 1);
this.listeners.set(label, listeners);
return true;
}
}
return false;
}
}, {
key: "emitEvent",
value: function emitEvent(label) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var listeners = this.listeners.get(label);
if (listeners && listeners.length) {
listeners.forEach(function (listener) {
listener.apply(void 0, args);
});
return true;
}
return false;
} //--------------------------
// event handlers
//--------------------------
}]);
return EventEmitter;
}();
var _default = EventEmitter;
exports.default = _default;
},{}],"../../../default/src/com/tools/events/DataEvent.jsx":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = 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"); } }
var REQUEST_GOOD = 'requestGood';
exports.REQUEST_GOOD = REQUEST_GOOD;
var REQUEST_LAME = 'requestLame';
exports.REQUEST_LAME = REQUEST_LAME;
var IMG_REQUEST_GOOD = 'imgRequestGood';
exports.IMG_REQUEST_GOOD = IMG_REQUEST_GOOD;
var IMG_REQUEST_LAME = 'imgRequestLame';
exports.IMG_REQUEST_LAME = IMG_REQUEST_LAME;
var SETTINGS_LOADED = 'dataLoaded';
exports.SETTINGS_LOADED = SETTINGS_LOADED;
var HTML_LOADED = 'htmlLoaded';
exports.HTML_LOADED = HTML_LOADED;
var ARCHIVES_JSON_LOADED = 'archivesJSONLoaded';
exports.ARCHIVES_JSON_LOADED = ARCHIVES_JSON_LOADED;
var ARCHIVES_PAGE_LOADED = 'archivesPAGELoaded';
exports.ARCHIVES_PAGE_LOADED = ARCHIVES_PAGE_LOADED;
var ARCHIVES_ENTRY_LOADED = 'archivesEntryLoaded';
exports.ARCHIVES_ENTRY_LOADED = ARCHIVES_ENTRY_LOADED;
var PROJECT_UPDATED = 'projectUpdated';
exports.PROJECT_UPDATED = PROJECT_UPDATED;
var PROJECT_ADDED = 'projectAdded';
exports.PROJECT_ADDED = PROJECT_ADDED;
var PROJECTS_SORTED = 'projectsSorted';
exports.PROJECTS_SORTED = PROJECTS_SORTED;
var DataEvent = function DataEvent() {
_classCallCheck(this, DataEvent);
};
var _default = new DataEvent();
exports.default = _default;
},{}],"../../../default/src/com/tools/utilities/DataUtils.jsx":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.CONTENT_TYPE_FORM = exports.CONTENT_TYPE_JSON = exports.REQUEST_TYPE_DELETE = exports.REQUEST_TYPE_PUT = exports.REQUEST_TYPE_GET = exports.REQUEST_TYPE_POST = void 0;
var _EventEmitter2 = _interopRequireDefault(require("../events/EventEmitter.jsx"));
var DataEvent = _interopRequireWildcard(require("../events/DataEvent.jsx"));
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; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
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; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
var REQUEST_TYPE_POST = "POST";
exports.REQUEST_TYPE_POST = REQUEST_TYPE_POST;
var REQUEST_TYPE_GET = "GET";
exports.REQUEST_TYPE_GET = REQUEST_TYPE_GET;
var REQUEST_TYPE_PUT = "PUT";
exports.REQUEST_TYPE_PUT = REQUEST_TYPE_PUT;
var REQUEST_TYPE_DELETE = "DELETE";
exports.REQUEST_TYPE_DELETE = REQUEST_TYPE_DELETE;
var CONTENT_TYPE_JSON = 'json';
exports.CONTENT_TYPE_JSON = CONTENT_TYPE_JSON;
var CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
exports.CONTENT_TYPE_FORM = CONTENT_TYPE_FORM;
var DataUtils =
/*#__PURE__*/
function (_EventEmitter) {
_inherits(DataUtils, _EventEmitter);
//--------------------------
// constructor
//--------------------------
function DataUtils() {
var _this;
_classCallCheck(this, DataUtils);
_this = _possibleConstructorReturn(this, _getPrototypeOf(DataUtils).call(this));
var self = _assertThisInitialized(_assertThisInitialized(_this));
return _this;
} //--------------------------
// methods
//--------------------------
_createClass(DataUtils, [{
key: "request",
value: function request(requestURL, eventType) {
var requestType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : REQUEST_TYPE_GET;
var contentType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CONTENT_TYPE_JSON;
var requestData = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
var self = this;
return new Promise(function (resolve, reject) {
var request = new XMLHttpRequest();
request.upload.onprogress = self.handleLoadProgress;
request.open(requestType, requestURL, true);
request.onload = function (e) {
if (request.status == 200) {
resolve({
request: request,
eventType: eventType
});
} else {
reject({
request: request,
eventType: eventType
});
}
;
};
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
switch (contentType) {
case CONTENT_TYPE_JSON:
request.setRequestHeader("Content-type", "application/" + contentType);
request.send(JSON.stringify(requestData));
break;
case CONTENT_TYPE_FORM:
request.send(requestData);
break;
}
} else {
request.send();
}
});
}
}, {
key: "imgLoad",
value: function imgLoad(url) {
'use strict'; // Create new promise with the Promise() constructor;
// This has as its argument a function with two parameters, resolve and reject
return new Promise(function (resolve, reject) {
// Standard XHR to load an image
var request = new XMLHttpRequest();
request.open('GET', url);
request.responseType = 'blob'; // When the request loads, check whether it was successful
request.onload = function () {
if (request.status === 200) {
// If successful, resolve the promise by passing back the request response
resolve(request.response);
} else {
// If it fails, reject the promise with a error message
reject(new Error('Image didn\'t load successfully; error code:' + request.statusText));
}
};
request.onerror = function () {
// 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
reject(new Error('There was a network error.'));
}; // Send the request
request.send();
});
}
}, {
key: "loadImage",
value: function loadImage(src) {
'use strict';
var self = this;
return new Promise(function (resolve, reject) {
// Get a reference to the body element, and create a new image object
var body = document.querySelector('body'),
myImage = new Image();
myImage.crossOrigin = ""; // or "anonymous"
// 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
self.imgLoad(src).then(function (response) {
// The first runs when the promise resolves, with the request.reponse specified within the resolve() method.
var imageURL = window.URL.createObjectURL(response);
resolve(imageURL); //$('background-content').setStyle('background-image', 'url('+imageURL+')') //myImage.src = imageURL;
//console.log(imageURL);
//body.appendChild(myImage);
// The second runs when the promise is rejected, and logs the Error specified with the reject() method.
}, function (Error) {
reject(Error);
});
});
} //--------------------------
// event handlers
//--------------------------
}, {
key: "handleLoadProgress",
value: function handleLoadProgress(e) {
var percentComplete = Math.ceil(e.loaded / e.total * 100); //console.log(percentComplete);
}
}]);
return DataUtils;
}(_EventEmitter2.default);
var _default = DataUtils;
exports.default = _default;
},{"../events/EventEmitter.jsx":"../../../default/src/com/tools/events/EventEmitter.jsx","../events/DataEvent.jsx":"../../../default/src/com/tools/events/DataEvent.jsx"}],"../../../../brain/tools/utilities/DBUtils.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _DataUtils = _interopRequireDefault(require("../../../themes/default/src/com/tools/utilities/DataUtils"));
var _dexie = _interopRequireDefault(require("dexie"));
var DataEvent = _interopRequireWildcard(require("../events/DataEvent"));
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; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 DBUtils =
/*#__PURE__*/
function () {
//--------------------------
// constructor
//--------------------------
function DBUtils() {
_classCallCheck(this, DBUtils);
this.dataUtils = new _DataUtils.default();
this.db = new _dexie.default("fipamo_posts");
this.db.version(1).stores({
postList: 'id,post'
});
} //--------------------------
// methods
//--------------------------
_createClass(DBUtils, [{
key: "resetLocal",
value: function resetLocal(array) {
var self = this;
return new Promise(function (resolve, reject) {
self.db.postList.clear().then(function (result) {
self.db.postList.bulkAdd(array).then(function (key) {
self.db.postList.toArray(function (array) {
var event = DataEvent.LOCAL_DB_READY;
resolve({
event: event
});
});
}).catch(_dexie.default.BulkError, function (e) {
reject({
e: e
});
});
});
});
} //--------------------------
// event handlers
//--------------------------
}]);
return DBUtils;
}();
exports.default = DBUtils;
},{"../../../themes/default/src/com/tools/utilities/DataUtils":"../../../default/src/com/tools/utilities/DataUtils.jsx","dexie":"../../../../node_modules/dexie/dist/dexie.es.js","../events/DataEvent":"../../../../brain/tools/events/DataEvent.js"}],"Base.js":[function(require,module,exports) {
},{"./PostEditor":"controllers/PostEditor.js","../../../../../brain/tools/effects/Animate":"../../../../brain/tools/effects/Animate.js","./PostIndex":"controllers/PostIndex.js"}],"Base.js":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
@ -38005,7 +37756,7 @@ function () {
});
}
self.dbUtils.resetLocal(list).then(function (r) {
self.dbUtils.syncLocal(list).then(function (r) {
self.start();
}).catch(function (err) {
console.log(err);

File diff suppressed because one or more lines are too long

@ -44,7 +44,7 @@ export default class Base
for (let index = 0; index < posts.length; index++) {
list.push({id:posts[index].id ,post:posts[index].post});
}
self.dbUtils.resetLocal(list).then(r=>{
self.dbUtils.syncLocal(list).then(r=>{
self.start();
}).catch(err=>{
console.log(err);

@ -13,6 +13,7 @@ import StringUtils from '../../../../../brain//tools/utilities/StringUtils';
import Dexie from 'dexie';
import sanitize from 'sanitize-html' //NOTE: Santize is a really big add - explore ways to reduce this
import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import DBUtils from '../../../../../brain/tools/utilities/DBUtils';
var md = require('markdown-it')('commonmark');
var uuidv4 = require('uuid/v4');
export default class PostActions
@ -24,11 +25,7 @@ export default class PostActions
{
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
this.db = new Dexie("fipamo_posts");
this.db.version(1).stores(
{
postList: 'id,post'
});
this.dbUtils = new DBUtils();
}
//--------------------------
// methods
@ -36,7 +33,7 @@ export default class PostActions
update(id, data, files, lastKey)
{
let self = this;
let newID = null;
let freshData;
return new Promise(function(resolve, reject)
{
let txt = document.createElement("textarea");
@ -53,7 +50,7 @@ export default class PostActions
iframe: ['height', 'width', 'src', 'frameborder', 'allow', 'allowfullscreen']
}
})
buffed = new StringUtils().decodeHTML(buffed)
buffed = new StringUtils().decodeHTML(buffed);
data.title = document.getElementById('post_title').value;
data.slug = new StringUtils().cleanString(document.getElementById('post_title').value)
data.plaintext = buffed;
@ -82,12 +79,12 @@ export default class PostActions
}
else
{
//data.feature = "";
if (typeof data.feature == 'undefined')
data.feature = ""
}
if (id == null)
{
self.db.postList.put(
{
freshData = {
id: lastKey + 1,
post:
{
@ -102,80 +99,36 @@ export default class PostActions
page: data.page,
featured: data.featured,
published: data.published,
deleted: "",
author: "user"
}
}).then(fresh =>
{
newID = fresh;
});
}
}
else
{
self.db.postList.update(Number(id),
{
post: data
}).then(updated =>
{});
freshData = data;
}
self.db.postList.toArray(array =>
self.dbUtils.modify(id, freshData).then((response) =>
{
self.sync(array, newID).then(response =>
{
resolve(
{
response
})
}).catch(err =>
{
reject(
{
err
});
});
})
})
}
sync(db, newPostId)
{
let self = this;
return new Promise(function(resolve, reject)
{
self.dataUtils.request('/api/post/sync', DataEvent.POSTS_SYNCED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, db).then((response) =>
{
let bounce = {
message: response,
newPost: newPostId
}
resolve(
{
bounce
})
resolve(response)
}).catch((err) =>
{
reject(
{
err
});
reject(err)
})
})
}
deletePost()
deletePost(id, body)
{
let self = this;
return new Promise(function(resolve, reject)
{
self.dataUtils.request("/api/post/delete/" + postID, DataEvent.POST_DELETED, REQUEST_TYPE_POST, CONTENT_TYPE_FORM).then((response) =>
{
resolve(
{
response
})
}).catch((err) =>
{
reject(
{
err
});
body.deleted = new Date().toString();
return new Promise(function(resolve, reject){
self.dbUtils.archivePost(id, body).then(response=>{
console.log(response)
resolve(response)
}).catch(err=>{
console.log(err)
reject(error)
})
})
}

@ -17,6 +17,7 @@ import TinyDatePicker from 'tiny-date-picker';
import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import TextEditor from '../../../../../brain/tools/ui/TextEditor';
import Dexie from 'dexie';
import DBUtils , {COUNT, FINAL_KEY} from '../../../../../brain/tools/utilities/DBUtils';
export default class PostEditor
{
//--------------------------
@ -29,22 +30,22 @@ export default class PostEditor
this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils();
this.urlPieces = document.URL.split("/");
this.dbUtils = new DBUtils();
this.post = [];
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(
if (document.getElementById('post-edit-index').getAttribute('data-index'))
{
postList: 'id, 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();
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
this.dbUtils.getPost(this.postID).then(body=>{
self.post = body.post;
this.start()
}).catch(err=>{
//console.log(err)
})
}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);
@ -70,16 +71,6 @@ export default class PostEditor
//--------------------------
// methods
//--------------------------
setPost(array)
{
this.post = array;
this.start();
}
setListVars(array)
{
this.postCount = array.length;
this.postFinalKey = array[this.postCount - 1].id;
}
start()
{
let self = this;
@ -128,45 +119,43 @@ export default class PostEditor
}
handleEditorOptions(e)
{
let self = this;
switch (e)
{
case EditorEvent.EDITOR_SAVE:
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(response =>
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY).then(response =>
{
let freshDB = new Dexie("fipamo_posts");
freshDB.version(1).stores(
{
postList: 'id, post'
});
setTimeout(f =>
{
freshDB.postList.get(Number(response.response.bounce.newPost)).then(obj =>
{
window.location = "/@/dashboard/posts/edit/" + obj.post.slug;
});
}, 200);
self.dbUtils.getPost(Number(response.response.newPost)).then(r=>{
window.location = "/@/dashboard/posts/edit/" + r.post.slug;
})
}, 100);
}).catch(err =>
{
console.log("ERROR", err)
//console.log("ERROR", err)
})
break
case EditorEvent.EDITOR_UPDATE:
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, this.postFinalKey).then(response =>
new PostActions().update(this.postID, this.post, PostEditor.uploadFiles, FINAL_KEY).then(response =>
{
//console.log(response.response.bounce.newPost);
this.editor.notify(DataEvent.POST_UPDATED, this.postID);
}).catch(err =>
{
console.log("ERROR", err)
//console.log("ERRORZ", err)
})
break;
case EditorEvent.EDITOR_DELETE:
if (confirm('Aye! You know you\'re deleting this post, right?'))
{
new PostActions().deletePost().then((response) =>
new PostActions().deletePost(this.postID, this.post).then((response) =>
{
let note = JSON.parse(response['response']['request'].response);
window.location = "/@/dashboard/posts/";
setTimeout(f =>
{
window.location = "/@/dashboard/posts/"
}, 100);
}).catch((err) =>
{
console.log(err)
@ -253,7 +242,7 @@ export default class PostEditor
if (r.message == DataEvent.POST_IMAGE_ADDED) self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
}).catch((err) =>
{
console.log(err)
//console.log(err)
})
}
}

Loading…
Cancel
Save