added page removal and poste page status update from navigation area

This commit is contained in:
Ro 2019-01-13 13:57:03 -05:00
parent 27a1e670e3
commit 0021782037
11 changed files with 161 additions and 14 deletions

View file

@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router(); const router = express.Router();
const Models = require('../../models'); const Models = require('../../models');
const fs = require("fs-extra"); const fs = require("fs-extra");
const _ = require('lodash');
var settings = []; var settings = [];
//-------------------------- //--------------------------
// SETTINGS // SETTINGS
@ -35,6 +36,8 @@ router.get('/', function(req, res)
let item = posts[index].post; let item = posts[index].post;
if (item.page == true || item.page == "true") pages.push( if (item.page == true || item.page == "true") pages.push(
{ {
id: posts[index].id,
uuid: posts[index].post.uuid,
title: posts[index].post.title, title: posts[index].post.title,
slug: posts[index].post.slug slug: posts[index].post.slug
}); });
@ -42,7 +45,39 @@ router.get('/', function(req, res)
} }
else else
{ {
pages = settings.menu let newpages = []
pages = settings.menu;
for (let index = 0; index < posts.length; index++)
{
let item = posts[index].post;
if (item.page == true || item.page == "true") newpages.push(
{
id: posts[index].id,
uuid: posts[index].post.uuid,
title: posts[index].post.title,
slug: posts[index].post.slug
});
}
for (let i = 0; i < newpages.length; i++)
{
if (_.findIndex(pages, function(o)
{
return o.id == newpages[i].id;
}) != -1)
{
//console.log("FOUND")
}
else
{
pages.push(
{
id: newpages[i].id,
uuid: newpages[i].uuid,
title: newpages[i].title,
slug: newpages[i].slug
});
}
}
} }
res.render('dash/navigation', res.render('dash/navigation',
{ {

View file

@ -20,6 +20,10 @@ export default class DBUtils
//-------------------------- //--------------------------
constructor() constructor()
{ {
/**
* NOTE: DB ERRORS REPLICATE.
* WHEN FIXING A BUG, FIX DATA WITH JSON BACKUP
*/
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.db = new Dexie("fipamo_posts"); this.db = new Dexie("fipamo_posts");
this.db.version(1).stores( this.db.version(1).stores(
@ -56,6 +60,7 @@ export default class DBUtils
} }
else else
{ {
//console.log("UPDATED", postData);
self.db.postList.update(Number(id), self.db.postList.update(Number(id),
{ {
post: postData post: postData

View file

@ -6,8 +6,8 @@
"repository": "https://code.playvicio.us/Are0h/Fipamo", "repository": "https://code.playvicio.us/Are0h/Fipamo",
"theme": "default-light", "theme": "default-light",
"scripts": { "scripts": {
"start": "forever start -r esm init.js", "start": "pm2 --node-args='-r esm --inspect' start init.js",
"stop": "forever stop -r esm init.js", "stop": "pm2 stop init.js",
"dev": "nodemon -r esm init.js", "dev": "nodemon -r esm init.js",
"watch-front-scripts": "parcel watch themes/$npm_package_theme/src/com/Start.jsx --out-dir themes/$npm_package_theme/assets/js --out-file start.min.js --public-url /$npm_package_theme/assets/js", "watch-front-scripts": "parcel watch themes/$npm_package_theme/src/com/Start.jsx --out-dir themes/$npm_package_theme/assets/js --out-file start.min.js --public-url /$npm_package_theme/assets/js",
"watch-front-styles": "stylus -w -m -o themes/$npm_package_theme/assets/css themes/$npm_package_theme/src/styles/base.styl", "watch-front-styles": "stylus -w -m -o themes/$npm_package_theme/assets/css themes/$npm_package_theme/src/styles/base.styl",

View file

@ -2051,7 +2051,7 @@ svg.icons {
#nav-index #nav-index-wrapper { #nav-index #nav-index-wrapper {
padding: 0.75rem; padding: 0.75rem;
} }
#nav-index #nav-index-wrapper #nav-pages div { #nav-index #nav-index-wrapper #nav-pages div.nav-item {
display: block; display: block;
width: 100%; width: 100%;
background: #161d23; background: #161d23;
@ -2070,6 +2070,13 @@ svg.icons {
margin: -15px 0 0 10px; margin: -15px 0 0 10px;
cursor: move; cursor: move;
} }
#nav-index #nav-index-wrapper #nav-pages #nav-btns {
float: right;
}
#nav-index #nav-index-wrapper #nav-pages #nav-btns button {
font-size: 0.8em;
margin: 0 0 0 10px;
}
/** /**
------------------------------- -------------------------------
-- Forms -- Forms

File diff suppressed because one or more lines are too long

View file

@ -5615,6 +5615,10 @@ function () {
function DBUtils() { function DBUtils() {
_classCallCheck(this, DBUtils); _classCallCheck(this, DBUtils);
/**
* NOTE: DB ERRORS REPLICATE.
* WHEN FIXING A BUG, FIX DATA WITH JSON BACKUP
*/
this.dataUtils = new _DataUtils.default(); this.dataUtils = new _DataUtils.default();
this.db = new _dexie.default("fipamo_posts"); this.db = new _dexie.default("fipamo_posts");
this.db.version(1).stores({ this.db.version(1).stores({
@ -5645,6 +5649,7 @@ function () {
}; };
}); });
} else { } else {
//console.log("UPDATED", postData);
self.db.postList.update(Number(id), { self.db.postList.update(Number(id), {
post: postData post: postData
}).then(function (updated) {}).catch(function (e) { }).then(function (updated) {}).catch(function (e) {
@ -8604,6 +8609,8 @@ var _DateUtils = _interopRequireDefault(require("../../../../../brain/tools/util
var DataEvent = _interopRequireWildcard(require("../../../../../brain/tools/events/DataEvent")); var DataEvent = _interopRequireWildcard(require("../../../../../brain/tools/events/DataEvent"));
var _DBUtils = _interopRequireDefault(require("../../../../../brain/tools/utilities/DBUtils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _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; } }
@ -8625,6 +8632,7 @@ function () {
this.dataUtils = new _DataUtils.default(); this.dataUtils = new _DataUtils.default();
this.dateUtils = new _DateUtils.default(); this.dateUtils = new _DateUtils.default();
this.dbutils = new _DBUtils.default();
} //-------------------------- } //--------------------------
// methods // methods
//-------------------------- //--------------------------
@ -8640,7 +8648,9 @@ function () {
for (var index = 0; index < items.length; index++) { for (var index = 0; index < items.length; index++) {
navData.push({ navData.push({
title: items[index].getElementsByTagName('label')[0].innerHTML, title: items[index].getElementsByTagName('label')[0].innerHTML,
slug: items[index].id id: items[index].id,
slug: items[index].getAttribute('data-slug'),
uuid: items[index].getAttribute('data-uuid')
}); });
} }
@ -8652,6 +8662,18 @@ function () {
reject(err); reject(err);
}); });
}); });
}
}, {
key: "removeItem",
value: function removeItem(id) {
var self = this;
this.dbutils.getPost(id).then(function (post) {
post.post.page = "false";
self.dbutils.modify(id, post.post).then(function (r) {
document.getElementById('nav-pages').removeChild(document.getElementById(id));
self.save();
});
});
} //-------------------------- } //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
@ -8662,7 +8684,7 @@ function () {
}(); }();
exports.default = NavActions; exports.default = NavActions;
},{"../../../../../brain//tools/utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","../../../../../brain//tools/utilities/StringUtils":"../../../../brain/tools/utilities/StringUtils.js","../../../../../brain/tools/utilities/DateUtils":"../../../../brain/tools/utilities/DateUtils.js","../../../../../brain/tools/events/DataEvent":"../../../../brain/tools/events/DataEvent.js"}],"controllers/NavIndex.js":[function(require,module,exports) { },{"../../../../../brain//tools/utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","../../../../../brain//tools/utilities/StringUtils":"../../../../brain/tools/utilities/StringUtils.js","../../../../../brain/tools/utilities/DateUtils":"../../../../brain/tools/utilities/DateUtils.js","../../../../../brain/tools/events/DataEvent":"../../../../brain/tools/events/DataEvent.js","../../../../../brain/tools/utilities/DBUtils":"../../../../brain/tools/utilities/DBUtils.js"}],"controllers/NavIndex.js":[function(require,module,exports) {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
@ -8676,6 +8698,8 @@ var _DataUtils = _interopRequireWildcard(require("../../../../../brain/tools/uti
var DataEvent = _interopRequireWildcard(require("../../../../../brain/tools/events/DataEvent")); var DataEvent = _interopRequireWildcard(require("../../../../../brain/tools/events/DataEvent"));
var _DBUtils = _interopRequireDefault(require("../../../../../brain/tools/utilities/DBUtils"));
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 _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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@ -8697,6 +8721,7 @@ function () {
this.start(); this.start();
this.dataUtils = new _DataUtils.default(); this.dataUtils = new _DataUtils.default();
this.dbutils = new _DBUtils.default();
} //-------------------------- } //--------------------------
// methods // methods
//-------------------------- //--------------------------
@ -8705,6 +8730,8 @@ function () {
_createClass(NavIndex, [{ _createClass(NavIndex, [{
key: "start", key: "start",
value: function start() { value: function start() {
var _this = this;
var self = this; var self = this;
var menu = Sortable.create(document.getElementById("nav-pages"), { var menu = Sortable.create(document.getElementById("nav-pages"), {
onUpdate: function onUpdate(e) { onUpdate: function onUpdate(e) {
@ -8715,17 +8742,40 @@ function () {
}); });
} }
}); });
var nav = document.querySelectorAll('.nav-btn');
for (var i = 0, length = nav.length; i < length; i++) {
nav[i].addEventListener('click', function (e) {
return _this.handleNavButton(e);
}, false);
}
} //-------------------------- } //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
}, {
key: "handleNavButton",
value: function handleNavButton(e) {
var self = this;
switch (e.target.id) {
case "remove-item":
var id = e.target.getAttribute('data-id');
new _NavActions.default().removeItem(id);
break;
case "edit-item":
console.log("EDIT STUFF");
break;
}
}
}]); }]);
return NavIndex; return NavIndex;
}(); }();
exports.default = NavIndex; exports.default = NavIndex;
},{"../actions/NavActions":"actions/NavActions.js","../../../../../brain/tools/utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","../../../../../brain/tools/events/DataEvent":"../../../../brain/tools/events/DataEvent.js"}],"controllers/DashManager.js":[function(require,module,exports) { },{"../actions/NavActions":"actions/NavActions.js","../../../../../brain/tools/utilities/DataUtils":"../../../../brain/tools/utilities/DataUtils.js","../../../../../brain/tools/events/DataEvent":"../../../../brain/tools/events/DataEvent.js","../../../../../brain/tools/utilities/DBUtils":"../../../../brain/tools/utilities/DBUtils.js"}],"controllers/DashManager.js":[function(require,module,exports) {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {

File diff suppressed because one or more lines are too long

View file

@ -5,9 +5,12 @@ block main-content
#nav-pages #nav-pages
- var index = 0; - var index = 0;
- for ( index; index < pages.length; index++) - for ( index; index < pages.length; index++)
.nav-item(id=pages[index].slug) .nav-item(id=pages[index].id, data-slug=pages[index].slug, data-uuid=pages[index].uuid)
svg#item-arrows(viewBox="0 0 20 20" class="icons") svg#item-arrows(viewBox="0 0 20 20" class="icons")
use(xlink:href='/dash/assets/images/sprite.svg#entypo-select-arrows') use(xlink:href='/dash/assets/images/sprite.svg#entypo-select-arrows')
label label
= pages[index].title = pages[index].title
#nav-btns
button.nav-btn#edit-item(data-id=pages[index].uuid) EDIT
button.nav-btn#remove-item(data-id=pages[index].id) REMOVE

View file

@ -11,6 +11,7 @@ from '../../../../../brain//tools/utilities/DataUtils';
import StringUtils from '../../../../../brain//tools/utilities/StringUtils'; import StringUtils from '../../../../../brain//tools/utilities/StringUtils';
import DateUtils from '../../../../../brain/tools/utilities/DateUtils'; import DateUtils from '../../../../../brain/tools/utilities/DateUtils';
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
import DBUtils from '../../../../../brain/tools/utilities/DBUtils';
export default class NavActions export default class NavActions
{ {
//-------------------------- //--------------------------
@ -20,6 +21,7 @@ export default class NavActions
{ {
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.dateUtils = new DateUtils(); this.dateUtils = new DateUtils();
this.dbutils = new DBUtils();
} }
//-------------------------- //--------------------------
// methods // methods
@ -29,10 +31,16 @@ export default class NavActions
let self = this; let self = this;
let navData = []; let navData = [];
let items = document.getElementById('nav-pages').children; let items = document.getElementById('nav-pages').children;
for (let index = 0; index < items.length; index++) { for (let index = 0; index < items.length; index++)
navData.push({title:items[index].getElementsByTagName('label')[0].innerHTML, slug:items[index].id}) {
navData.push(
{
title: items[index].getElementsByTagName('label')[0].innerHTML,
id: items[index].id,
slug: items[index].getAttribute('data-slug'),
uuid: items[index].getAttribute('data-uuid')
})
} }
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
self.dataUtils.request('/api/settings/nav-sync', DataEvent.SETTINGS_UPDATED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, navData).then((response) => self.dataUtils.request('/api/settings/nav-sync', DataEvent.SETTINGS_UPDATED, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, navData).then((response) =>
@ -45,6 +53,19 @@ export default class NavActions
}) })
}) })
} }
removeItem(id)
{
let self = this;
this.dbutils.getPost(id).then(post =>
{
post.post.page = "false";
self.dbutils.modify(id, post.post).then(r =>
{
document.getElementById('nav-pages').removeChild(document.getElementById(id));
self.save()
})
})
}
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------

View file

@ -10,6 +10,7 @@ import DataUtils,
} }
from "../../../../../brain/tools/utilities/DataUtils"; from "../../../../../brain/tools/utilities/DataUtils";
import * as DataEvent from '../../../../../brain/tools/events/DataEvent'; import * as DataEvent from '../../../../../brain/tools/events/DataEvent';
import DBUtils from "../../../../../brain/tools/utilities/DBUtils";
export default class NavIndex export default class NavIndex
{ {
//-------------------------- //--------------------------
@ -19,6 +20,7 @@ export default class NavIndex
{ {
this.start(); this.start();
this.dataUtils = new DataUtils(); this.dataUtils = new DataUtils();
this.dbutils = new DBUtils();
} }
//-------------------------- //--------------------------
// methods // methods
@ -38,8 +40,27 @@ export default class NavIndex
}) })
} }
}); });
var nav = document.querySelectorAll('.nav-btn');
for (var i = 0, length = nav.length; i < length; i++)
{
nav[i].addEventListener('click', e => this.handleNavButton(e), false);
}
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
handleNavButton(e)
{
let self = this;
switch (e.target.id)
{
case "remove-item":
let id = e.target.getAttribute('data-id');
new NavActions().removeItem(id);
break
case "edit-item":
console.log("EDIT STUFF");
break
}
}
} }

View file

@ -6,7 +6,7 @@
#nav-index-wrapper #nav-index-wrapper
padding 0.75rem padding 0.75rem
#nav-pages #nav-pages
div div.nav-item
display: block display: block
width: 100% width: 100%
background: $primary - 60% background: $primary - 60%
@ -23,3 +23,8 @@
padding: 0 padding: 0
margin: -15px 0 0 10px margin: -15px 0 0 10px
cursor move cursor move
#nav-btns
float right
button
font-size: .8em
margin: 0 0 0 10px