mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-07 14:35:26 +02:00
fix bugs
This commit is contained in:
parent
462d1b26f1
commit
432edd6167
4 changed files with 14 additions and 5 deletions
|
@ -2,7 +2,7 @@ import PageOrder from '../models/pageOrder.js';
|
|||
import Page from '../models/page.js';
|
||||
import PagesFlatArray from '../models/pagesFlatArray.js';
|
||||
import { EntityId } from '../database/types.js';
|
||||
import { isEqualIds } from '../database/index.js';
|
||||
import { isEqualIds, toEntityId } from '../database/index.js';
|
||||
|
||||
/**
|
||||
* @class PagesOrder
|
||||
|
@ -103,13 +103,15 @@ class PagesOrder {
|
|||
const unordered = pages.filter(page => isEqualIds(page._parent, parentPageId)).map(page => page._id);
|
||||
|
||||
// Create unique array with ordered and unordered pages id
|
||||
const ordered = Array.from(new Set([...children.order, ...unordered]));
|
||||
const ordered = Array.from(new Set([...children.order, ...unordered].map(id => id?.toString())));
|
||||
|
||||
const result: Page[] = [];
|
||||
|
||||
ordered.forEach(pageId => {
|
||||
const id = pageId ? toEntityId(pageId): undefined;
|
||||
|
||||
pages.forEach(page => {
|
||||
if (isEqualIds(page._id, pageId) && (!isEqualIds(pageId, currentPageId) || !ignoreSelf)) {
|
||||
if (isEqualIds(page._id, id) && (!isEqualIds(id, currentPageId) || !ignoreSelf)) {
|
||||
result.push(page);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -15,6 +15,8 @@ router.get('/page/new', verifyToken, allowEdit, async (req: Request, res: Respon
|
|||
try {
|
||||
const pagesAvailableGrouped = await Pages.groupByParent();
|
||||
|
||||
console.log(pagesAvailableGrouped);
|
||||
|
||||
res.render('pages/form', {
|
||||
pagesAvailableGrouped,
|
||||
page: null,
|
||||
|
|
|
@ -62,11 +62,16 @@ export default (function () {
|
|||
* @returns {string} stringified object
|
||||
*/
|
||||
twig.extendFunction('toString', function (object: object): string {
|
||||
if (!object) {
|
||||
return object;
|
||||
}
|
||||
|
||||
return object.toString();
|
||||
});
|
||||
|
||||
/**
|
||||
* Converts JSON to string
|
||||
*
|
||||
* @param {string} data - data to be converted
|
||||
* @returns {string} - converted data
|
||||
*/
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<option value="0">Root</option>
|
||||
{% for _page in pagesAvailableGrouped %}
|
||||
{% if toString(_page._id) != toString(currentPageId) %}
|
||||
<option value="{{ _page._id }}" {{ page is not empty and toString(page._parent) == toString(_page._id) ? 'selected' : ''}}>
|
||||
<option value="{{ toString(_page._id) }}" {{ page is not empty and toString(page._parent) == toString(_page._id) ? 'selected' : ''}}>
|
||||
{% if _page._parent != "0" %}
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
|||
<select id="above" name="above">
|
||||
<option value="0">—</option>
|
||||
{% for _page in parentsChildrenOrdered %}
|
||||
<option value="{{ _page._id }}">{{ _page.title }}</option>
|
||||
<option value="{{ toString(_page._id) }}">{{ _page.title }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue