mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A feature's guide now sits under the menu it is used from, read from the templates rather than from where somebody once put it: Header-Bar, All-Boards, Pages, Board-Header (search and every Board View), Board-Sidebar (Board Settings, Filter, Members, Labels, Archive), Rules, Swimlanes, Lists, Cards, Member-Settings, Admin-Panel and Login-Page. Topics used from several menus (editor, history, theme, translations, email, troubleshooting) are in General. - Each area has a README mapping its menu entries to their guides and to the template or server module that implements them. Board-Header/README.md lists all 40 Board View entries with the template boardBody.jade renders; five views (Table, Calendar Mode, Time, Timeline, Map) have no guide of their own yet and say so. - Board-View.md listed 25 views while BOARD_VIEWS has 40; it now lists all of them with their English labels. - Pages keep their file names. Where a released changelog links an old path, a "# Moved" page stays there and points to the new one; test-menu.sh skips folders holding only those. - Undo was filed under Login; it is General/Undo now. - Every link in docs, code comments, scripts and tests follows the move; docsLinksResolve checks them all. Tests that read a doc follow it to its new place. boardViewSettings now fails when Board-View.md or Board-Header/README.md differs from BOARD_VIEWS, or names a template boardBody.jade does not render. Thanks to xet7 !
76 lines
2.8 KiB
JavaScript
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/General/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 };
|