feat: Added orderPriority according to mentions in plan

pull/7619/head
Ruslan Semak 7 months ago
parent 9d132ca6e2
commit 395f39de90

@ -390,7 +390,6 @@ module.exports = class Page extends Model {
} }
// -> Ruslan: Check for title changes => Update all other links names to this page // -> Ruslan: Check for title changes => Update all other links names to this page
// На pageLinks опираться нельзя, т.r. авто-сгенерированные страницы не добавляются в pageLink
if (opts.title && ogPage.title !== opts.title) { if (opts.title && ogPage.title !== opts.title) {
const allPages = await WIKI.models.pages.query() const allPages = await WIKI.models.pages.query()
const mentionedInPages = allPages.filter(page => page.content.includes(`data-page-id="${ogPage.id}"`)) const mentionedInPages = allPages.filter(page => page.content.includes(`data-page-id="${ogPage.id}"`))
@ -443,6 +442,22 @@ module.exports = class Page extends Model {
} }
} }
const planPageId = 2
if (opts.id === planPageId) {
const pageIds = []
const regex = /data-page-id="(\d+)"/g
let match
while ((match = regex.exec(opts.content)) !== null) {
const id = Number(match[1])
if (!pageIds.includes(id)) {
pageIds.push(id)
}
}
await WIKI.models.pages.updatePriority({ pages: pageIds.map((id, idx) => ({ id, orderPriority: idx + 1 })) })
}
// -> Create version snapshot // -> Create version snapshot
await WIKI.models.pageHistory.addVersion({ await WIKI.models.pageHistory.addVersion({
...ogPage, ...ogPage,

Loading…
Cancel
Save