From 442337a22b28861292f4b1dd68cd077f6300f304 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sun, 29 Oct 2023 22:10:44 +0100 Subject: [PATCH] Fix file listing and download for admin shell `node.parents` is not returning the parent nodes in a fixed order. Hence, we cannot use it but must travers the tree ourselves. --- app/assets/javascripts/shell.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/shell.js b/app/assets/javascripts/shell.js index a1d1c822..0da9b354 100644 --- a/app/assets/javascripts/shell.js +++ b/app/assets/javascripts/shell.js @@ -148,7 +148,7 @@ $(document).on('turbolinks:load', function () { } // We build the path to the file by concatenating the paths of all parent nodes. - let file_path = node.parents.reverse().map(function (id) { + let file_path = getParents(jstree, node.parent).map(function (id) { return jstree.get_text(id); }).filter(function (text) { return text !== false; @@ -157,6 +157,15 @@ $(document).on('turbolinks:load', function () { return `${node.parent !== '#' ? '/' : ''}${file_path}${node.original.path}`; } + const getParents = function (jstree, node_id) { + debugger; + if (node_id === '#') { + return ['#']; + } + + return getParents(jstree, jstree.get_parent(node_id)).concat([node_id]); + } + const shell = $('#shell'); if (!shell.isPresent()) {