diff --git a/src/web/files.html b/src/web/files.html index f4dccde1b..0b941f205 100644 --- a/src/web/files.html +++ b/src/web/files.html @@ -11,22 +11,24 @@
(Peeking: ${peekName})`;
} else if (lockedFileViewPath) {
- const lockName = lockedFileViewPath[lockedFileViewPath.length - 1];
- fileHeader.innerHTML = `Files (Selected: ${lockName})`;
+ const lockName = lockedFileViewPath.join('/');
+ fileHeader.innerHTML = `Files (Selected: ${lockName})`;
} else {
- fileHeader.innerHTML = `Files`;
+ const pathName = basePathArray.join('/') || '/';
+ fileHeader.innerHTML = `Files (${pathName})`;
}
if (!node) {
@@ -217,18 +254,21 @@
* @param {HTMLElement} container
* @param {DB} node
* @param {number} currentDepth
- * @param {number} maxDepth
+ * @param {(depth: number, files: number) => boolean} maxDepthFn
* @param {string[]} currentPathArray
+ * @returns {boolean}
*/
- function renderDirTree(container, node, currentDepth, maxDepth, currentPathArray) {
- if (currentDepth >= maxDepth || !node) return;
+ function renderDirTree(container, node, currentDepth, maxDepthFn, currentPathArray) {
+ if (!node) return false;
let dirs = [];
for (const [key, value] of Object.entries(node)) {
if (typeof value === 'object') dirs.push(key);
}
+ if (!maxDepthFn(currentDepth, dirs.length)) {
+ return false;
+ }
dirs.sort();
-
dirs.forEach(dir => {
const dirDiv = document.createElement('div');
dirDiv.className = 'list-item';
@@ -255,6 +295,7 @@
}
dirDiv.innerHTML = `${dir}`;
+ dirDiv.setAttribute('data-path', nextPathArray.join('/'));
dirDiv.addEventListener('mouseenter', () => {
renderFiles(node[dir], nextPathArray, true);
@@ -281,8 +322,12 @@
container.appendChild(dirDiv);
- renderDirTree(container, node[dir], currentDepth + 1, maxDepth, nextPathArray);
+ let rendered = renderDirTree(container, node[dir], currentDepth + 1, maxDepthFn, nextPathArray);
+ if (hasSubDirs) {
+ dirDiv.innerText += rendered ? " .." : " ...";
+ }
});
+ return true;
}
function render() {
@@ -290,15 +335,16 @@
if (!node) {
// reset to root
- pathStack = ["/"];
+ pathStack = [];
historyStack = [];
node = getCurrentNode();
lockedFileViewPath = null;
if (!node) return;
}
- dirHeader.innerText = pathStack.join('/').replace('//', '/');
+ dirHeader.innerText = pathStack.join('/') || '/';
+ let lastScroll = dirPanel.scrollTop;
dirPanel.innerHTML = '';
if (historyStack.length > 0) {
@@ -306,7 +352,7 @@
backDiv.className = 'list-item up-icon';
backDiv.innerHTML = `Back`;
backDiv.onclick = () => {
- pathStack = historyStack.pop() || ['/'];
+ pathStack = historyStack.pop() || [''];
lockedFileViewPath = null;
clearContentPanel();
render();
@@ -314,7 +360,14 @@
dirPanel.appendChild(backDiv);
}
- renderDirTree(dirPanel, node, 0, 3, pathStack);
+ renderDirTree(dirPanel, node, 0, (depth, files) => {
+ switch (depth) {
+ case 0: return true;
+ case 1: return files < 10;
+ case 2: return files < 5;
+ default: return false;
+ }
+ }, pathStack);
if (dirPanel.children.length === 0 || (dirPanel.children.length === 1 && pathStack.length > 1)) {
const emptyMsg = document.createElement('div');
@@ -322,6 +375,8 @@
emptyMsg.style.color = '#777';
emptyMsg.innerText = 'No subdirectories';
dirPanel.appendChild(emptyMsg);
+ } else {
+ dirPanel.scrollTop = lastScroll;
}
renderFiles(node, pathStack, false);
@@ -334,7 +389,7 @@
* @param {string[]} basePathArray
*/
function showFileContent(fileName, packages, basePathArray) {
- const fullPath = (basePathArray.join('/') + '/' + fileName).replace('//', '/');
+ const fullPath = (basePathArray.join('/') + '/' + fileName);
contentHeader.innerText = fileName;
contentPanel.innerHTML = `
${p}`).join(', ')}
+ ${packages.split(',').map(p => `${p}`).join(', ')}
Repository for {target}