Files
wekan/models/lib/domainTablePage.js
T
Lauri Ojansivu 7e1f9e89eb Docs: every feature topic in one folder under docs/Features, each with README.md as its main page.
- The General/ level is gone: its 109 files moved up into the folders of the
  same name, and its topic table is the "Shared topics" section of
  Features.md.
- Accessibility is one folder, docs/Features/Accessibility/, with the Admin
  Panel's accessibility page in it.
- Every folder's main page is README.md (110 X/X.md pages renamed with git mv,
  five merged with an existing README.md, 26 index pages added for folders
  that had none), so a folder opened on GitHub shows its page.
- The 73 "# Moved" forwarding pages are deleted, with the folders that held
  only them; every link that went to one goes to its final page.
- docs/Features/README.md has the website's "Features in WeKan" overview,
  each feature linking to its page here.

1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose,
snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when
General/ or a "# Moved" page comes back, a folder has no README.md, or a
relative link in the docs or README.md does not resolve.

Thanks to xet7 !
2026-11-24 20:02:06 +02:00

76 lines
2.8 KiB
JavaScript

'use strict';
// Pure filter + sort + paginate for the Admin Panel > People > Domains table.
// Extracted so the page logic is unit-testable without Meteor and shared by the
// server method that feeds the table.
//
// The Domains table used to load EVERY domain (aggregated from all users) into
// the browser at once, with a fixed order and no search. To behave like the
// Board Table view — send only one small page to the browser, let the user
// order by a column and search — the server aggregates all users into
// { domain, count } rows and then hands them to this helper, which applies the
// search filter, the requested column sort and the requested page, returning
// only that page plus the total so the client can render pagination controls.
// The app's one rows-per-page (TABLE_PAGE_ROWS_PER_PAGE in models/lib/tablePage.js,
// docs/Features/Table.md). Written out rather than imported because this module
// is loaded by a plain-node test with require(), which cannot parse ESM imports;
// tests/tablePage.test.cjs pins the two to the same number.
const PER_PAGE_DEFAULT = 10;
const PER_PAGE_MAX = 200;
function paginateDomains(rows, opts = {}) {
const all = Array.isArray(rows) ? rows : [];
const search =
typeof opts.search === 'string' ? opts.search.trim().toLowerCase() : '';
// Only two real columns; anything else falls back to the domain name.
const sortField = opts.sortField === 'count' ? 'count' : 'domain';
const sortDirection = opts.sortDirection === -1 ? -1 : 1;
const rawPerPage = Number(opts.perPage);
const perPage = Math.min(
PER_PAGE_MAX,
Number.isFinite(rawPerPage) && rawPerPage >= 1 ? rawPerPage : PER_PAGE_DEFAULT,
);
let filtered = all;
if (search) {
filtered = all.filter(
row => (row.domain || '').toLowerCase().indexOf(search) !== -1,
);
}
const byDomain = (a, b) =>
(a.domain || '').localeCompare(b.domain || '', undefined, {
sensitivity: 'base',
numeric: true,
});
filtered = filtered.slice().sort((a, b) => {
if (sortField === 'count') {
const cmp = ((a.count || 0) - (b.count || 0)) * sortDirection;
if (cmp !== 0) return cmp;
// Ties always break alphabetically (ascending), independent of direction.
return byDomain(a, b);
}
return byDomain(a, b) * sortDirection;
});
const total = filtered.length;
const totalPages = Math.max(1, Math.ceil(total / perPage));
// Clamp the requested page into range so a stale/too-large page never yields
// an empty table.
const page = Math.min(Math.max(1, Number(opts.page) || 1), totalPages);
const start = (page - 1) * perPage;
return {
rows: filtered.slice(start, start + perPage),
total,
page,
totalPages,
perPage,
};
}
module.exports = { paginateDomains, PER_PAGE_DEFAULT, PER_PAGE_MAX };