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 !
157 lines
6.3 KiB
JavaScript
157 lines
6.3 KiB
JavaScript
'use strict';
|
|
|
|
// Starred PAGES: the same star, on a page that is not a board.
|
|
//
|
|
// A board could be starred and reached from the dropdown in the first header
|
|
// bar. Every other page - All Boards / Remaining, a workspace, Admin Panel /
|
|
// Settings / Version - could not, so the one control for "keep this where I can
|
|
// get at it" worked on one kind of destination and was simply absent on the
|
|
// rest, even though those pages have had their own addresses since the All
|
|
// Boards and Admin Panel URLs landed.
|
|
//
|
|
// A starred page is its URL and its TITLE - the same words the browser tab
|
|
// shows, "Product name - All Boards / Remaining" - because the title is what
|
|
// the dropdown lists, and a row saying `/allboards/remaining` would make the
|
|
// reader parse a path to find out where it goes.
|
|
//
|
|
// The URL is RELATIVE. What is stored has to survive the site moving to another
|
|
// host, and an absolute URL pins a bookmark to the hostname it was made on.
|
|
//
|
|
// Pure: an array in, an array out. No Meteor, no collections, no router, so the
|
|
// same rules run on the client, on the server and in a unit test.
|
|
// docs/Features/Pages/Starred.md
|
|
|
|
// A cap, because this is a dropdown. Starring is one click and unstarring is
|
|
// one click, so a list that grows without limit is a list that quietly stops
|
|
// being useful - and the oldest entry is the one the reader has stopped using.
|
|
const MAX_STARRED_PAGES = 50;
|
|
|
|
// Is this a page address this app can star?
|
|
//
|
|
// A relative path, starting with `/`. Anything else - an absolute URL, a
|
|
// `javascript:` URL, an empty string - is refused rather than cleaned up:
|
|
// storing it would put whatever it is into an `href` the reader clicks.
|
|
function isStarrablePageUrl(url) {
|
|
if (typeof url !== 'string') return false;
|
|
const trimmed = url.trim();
|
|
if (!trimmed.startsWith('/')) return false;
|
|
// `//host/path` is protocol-relative - it leaves the site, and it starts with
|
|
// a slash, so the test above lets it through.
|
|
if (trimmed.startsWith('//')) return false;
|
|
return true;
|
|
}
|
|
|
|
// The stored form: the path, without the origin, and with any trailing slash
|
|
// left alone (a trailing slash is a different address to the router, and
|
|
// second-guessing it here would star a page and highlight another).
|
|
function normalizePageUrl(url) {
|
|
return isStarrablePageUrl(url) ? url.trim() : '';
|
|
}
|
|
|
|
// One stored entry, or null when the page cannot be starred. A title is
|
|
// optional in the sense that a page always has one by the time this is called;
|
|
// an empty one falls back to the URL so a row is never blank.
|
|
function pageEntry(url, title) {
|
|
const href = normalizePageUrl(url);
|
|
if (!href) return null;
|
|
const text = typeof title === 'string' ? title.trim() : '';
|
|
return { url: href, title: text || href };
|
|
}
|
|
|
|
// Entries whose URL survives a round trip. Anything else in the profile - an
|
|
// entry written by an older version, a hand-edited document - is dropped rather
|
|
// than drawn.
|
|
function starredPagesOf(pages) {
|
|
if (!Array.isArray(pages)) return [];
|
|
return pages
|
|
.map(p => (p && typeof p === 'object' ? pageEntry(p.url, p.title) : null))
|
|
.filter(Boolean);
|
|
}
|
|
|
|
function isPageStarred(pages, url) {
|
|
const href = normalizePageUrl(url);
|
|
if (!href) return false;
|
|
return starredPagesOf(pages).some(p => p.url === href);
|
|
}
|
|
|
|
// Star it, or unstar it if it is already starred. One function rather than two,
|
|
// because the button is one button: the reader clicks the star to put the page
|
|
// in the list and clicks it again to take it out.
|
|
//
|
|
// A page that is starred again with a NEW title (the page was renamed, the
|
|
// admin changed the product name) keeps its place in the list and takes the new
|
|
// title - moving it to the end would reorder a list the reader has learned.
|
|
function toggleStarredPage(pages, url, title) {
|
|
const entry = pageEntry(url, title);
|
|
if (!entry) return starredPagesOf(pages);
|
|
|
|
const current = starredPagesOf(pages);
|
|
const at = current.findIndex(p => p.url === entry.url);
|
|
if (at !== -1) {
|
|
return current.filter((_, i) => i !== at);
|
|
}
|
|
// Newest last, so the list reads in the order the reader built it - and the
|
|
// cap drops from the FRONT, which is the entry starred longest ago.
|
|
const next = [...current, entry];
|
|
return next.length > MAX_STARRED_PAGES
|
|
? next.slice(next.length - MAX_STARRED_PAGES)
|
|
: next;
|
|
}
|
|
|
|
// Move a bookmark so it sits where another one is, and shift the rest along.
|
|
//
|
|
// The ORDER is the reader's, and it is one order: the tiles in All Boards /
|
|
// Starred and the rows of the header dropdown are two views of this array, so
|
|
// dragging a tile past another rearranges the menu too. Anything else would be
|
|
// two lists that disagree about the same bookmarks.
|
|
//
|
|
// Both URLs are matched by VALUE rather than by index, because the two views
|
|
// are rendered separately and an index from one of them is a guess about the
|
|
// other. An unknown URL, or a move onto itself, is a no-op.
|
|
function moveStarredPage(pages, url, beforeUrl) {
|
|
const current = starredPagesOf(pages);
|
|
const from = current.findIndex(p => p.url === normalizePageUrl(url));
|
|
if (from === -1) return current;
|
|
|
|
const moved = current[from];
|
|
const without = current.filter((_, i) => i !== from);
|
|
|
|
// No target: the end of the list. Dropping past the last tile is how a
|
|
// bookmark is sent to the back.
|
|
const target = normalizePageUrl(beforeUrl);
|
|
if (!target) return [...without, moved];
|
|
|
|
const to = without.findIndex(p => p.url === target);
|
|
if (to === -1) return current;
|
|
return [...without.slice(0, to), moved, ...without.slice(to)];
|
|
}
|
|
|
|
// The words in the browser tab, and the words the dropdown lists.
|
|
//
|
|
// "Product name - All Boards / Remaining"
|
|
//
|
|
// The product name first, because it is the constant: a row of tabs from one
|
|
// WeKan then lines up under one word, and the part that differs is where the
|
|
// eye is already travelling. When there is no path - a page with nothing to say
|
|
// beyond its own name - the product name is the whole title, which is what it
|
|
// was before.
|
|
function pageDocumentTitle(productName, path) {
|
|
const name = (typeof productName === 'string' ? productName : '').trim();
|
|
const trail = (typeof path === 'string' ? path : '').trim();
|
|
if (!name) return trail;
|
|
if (!trail) return name;
|
|
return `${name} - ${trail}`;
|
|
}
|
|
|
|
module.exports = {
|
|
MAX_STARRED_PAGES,
|
|
isStarrablePageUrl,
|
|
normalizePageUrl,
|
|
pageEntry,
|
|
starredPagesOf,
|
|
isPageStarred,
|
|
toggleStarredPage,
|
|
moveStarredPage,
|
|
pageDocumentTitle,
|
|
};
|