Allow repository admins to hide specific folders from the code browser for non-admin users. Hidden folders are shown dimmed to admins but completely hidden from regular users. Includes database migration, settings UI, tree filtering logic, and frontend support for toggling visibility.
27 lines
769 B
TypeScript
27 lines
769 B
TypeScript
import {POST} from '../modules/fetch.ts';
|
|
|
|
export function initRepoHiddenFolderToggle() {
|
|
const table = document.querySelector<HTMLElement>('#repo-files-table');
|
|
if (!table) return;
|
|
|
|
const toggleUrl = table.getAttribute('data-toggle-url');
|
|
if (!toggleUrl) return;
|
|
|
|
for (const btn of table.querySelectorAll<HTMLButtonElement>('.hidden-folder-toggle')) {
|
|
btn.addEventListener('click', async (e) => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
const folderPath = btn.getAttribute('data-folder-path');
|
|
if (!folderPath) return;
|
|
|
|
const data = new FormData();
|
|
data.append('folder_path', folderPath);
|
|
|
|
const resp = await POST(toggleUrl, {data});
|
|
if (resp.ok) {
|
|
window.location.reload();
|
|
}
|
|
});
|
|
}
|
|
}
|