mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-08 06:55:26 +02:00
requested changes
This commit is contained in:
parent
0fc44a6e65
commit
8f63a269a8
3 changed files with 14 additions and 14 deletions
|
@ -41,28 +41,28 @@ class PagesOrder {
|
|||
*
|
||||
* @param {string} oldParentId - old parent page's id
|
||||
* @param {string} newParentId - new parent page's id
|
||||
* @param {string} childId - page's id which is changing the parent page
|
||||
* @param {string} targetPageId - page's id which is changing the parent page
|
||||
*/
|
||||
static async renew(oldParentId, newParentId, childId) {
|
||||
static async move(oldParentId, newParentId, targetPageId) {
|
||||
const oldParentOrder = await Model.get(oldParentId);
|
||||
|
||||
oldParentOrder.remove(childId);
|
||||
oldParentOrder.remove(targetPageId);
|
||||
oldParentOrder.save();
|
||||
|
||||
const newParentOrder = await Model.get(newParentId);
|
||||
|
||||
newParentOrder.push(childId);
|
||||
newParentOrder.push(targetPageId);
|
||||
await newParentOrder.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new array with ordered pages
|
||||
*
|
||||
* @param {Array<Page>} pages - list of all available pages
|
||||
* @param {Page[]} pages - list of all available pages
|
||||
* @param {string} currentPageId - page's id around which we are ordering
|
||||
* @param {string} parentPageId - parent page's id that contains page above
|
||||
* @param {Boolean} ignoreSelf - should we ignore current page in list or not
|
||||
* @return Array<Page>
|
||||
* @return {Page[]}
|
||||
*/
|
||||
static async getOrderedChildren(pages, currentPageId, parentPageId, ignoreSelf = false) {
|
||||
const children = await PagesOrder.get(parentPageId);
|
||||
|
|
|
@ -17,15 +17,15 @@ class PageOrder {
|
|||
/**
|
||||
* Returns current Page's children order
|
||||
*
|
||||
* @param page
|
||||
* @param {string} pageId - page's id
|
||||
*/
|
||||
static async get(page) {
|
||||
const order = await db.findOne({page});
|
||||
static async get(pageId) {
|
||||
const order = await db.findOne({page: pageId});
|
||||
|
||||
let data = {};
|
||||
|
||||
if (!order) {
|
||||
data.page = page;
|
||||
data.page = pageId;
|
||||
} else {
|
||||
data = order;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class PageOrder {
|
|||
/**
|
||||
* Pushes page id to the orders array
|
||||
*
|
||||
* @param {string} pageId
|
||||
* @param {string} pageId - page's id
|
||||
*/
|
||||
push(pageId) {
|
||||
this._order.push(pageId);
|
||||
|
@ -83,7 +83,7 @@ class PageOrder {
|
|||
/**
|
||||
* Removes page id from orders array
|
||||
*
|
||||
* @param {string} pageId
|
||||
* @param {string} pageId - page's id
|
||||
*/
|
||||
remove(pageId) {
|
||||
const found = this._order.indexOf(pageId);
|
||||
|
@ -96,7 +96,7 @@ class PageOrder {
|
|||
/**
|
||||
* Returns ordered list
|
||||
*
|
||||
* @return {Array<string>}
|
||||
* @return {string[]}
|
||||
*/
|
||||
get order() {
|
||||
return this._order;
|
||||
|
|
|
@ -84,7 +84,7 @@ router.post('/page/:id', multer.any(), async (req, res) => {
|
|||
let page = await Pages.get(id);
|
||||
|
||||
if (page._parent !== parent) {
|
||||
await PagesOrder.renew(page._parent, parent, id);
|
||||
await PagesOrder.move(page._parent, parent, id);
|
||||
} else {
|
||||
await PagesOrder.update(page._id, page._parent, putAbovePageId);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue