🌐 AI搜索 & 代理 主页
Skip to content

Commit 51a01ef

Browse files
committed
make left nave recursive
1 parent 082e942 commit 51a01ef

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

pgml-dashboard/src/components/left_nav_menu/left-nav-menu.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ export default class extends Controller {
2020
setLeftNavToLocation() {
2121
this.removeAllActive();
2222

23-
// Get the first 3 parts of the pathname to match the left nav href
24-
let path = window.location.pathname.split("/").slice(0, 3).join("/");
25-
let tag = 'a[href="' + path + '"]';
26-
27-
let element = this.element.querySelector(tag);
28-
29-
if (element) {
30-
element.classList.add("active");
23+
let tab = this.findTab();
24+
if( tab ) {
25+
tab.classList.add("active");
3126
}
3227
}
3328

@@ -38,6 +33,24 @@ export default class extends Controller {
3833
}
3934
}
4035

36+
// Recursive function to find the tab that matches the current window
37+
findTab(level=1, tag="a[href='/']") {
38+
let element = this.element.querySelectorAll(tag);
39+
if( element.length == 1 ) {
40+
return element[0];
41+
} else {
42+
let path_vec = window.location.pathname.split("/");
43+
if( level > path_vec.length ) {
44+
return;
45+
}
46+
47+
let path = path_vec.slice(0, level).join("/");
48+
let tag = 'a[href="' + path + '"]';
49+
50+
return this.findTab(level + 1, tag)
51+
}
52+
}
53+
4154
// Remove event listener when controller is disconnected
4255
disconnect() {
4356
document.removeEventListener("turbo:load", this.callback);

pgml-dashboard/src/components/left_nav_menu/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<nav data-controller="left-nav-menu">
1+
<nav data-controller="left-nav-menu" class="overflow-hidden">
22
<ul class="nav flex-column justify-content-end">
33
<% for link in nav.links { %>
44
<% if !link.hide_for_lg_screens { %>

pgml-dashboard/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async fn main() {
100100
site_search_copy.build().await.expect("Error building site search");
101101
});
102102

103-
pgml_dashboard::migrate(guards::Cluster::default(None).pool())
103+
pgml_dashboard::migrate(guards::Cluster::default().pool())
104104
.await
105105
.unwrap();
106106

0 commit comments

Comments
 (0)