Collapsible locations tree, sorting mode, and drag selection fix

The Locations page now shows only top-level locations by default; rows
with children get a caret that reveals sub-locations inline, indented
under their parent in the same table style.

Rearranging is gated behind a new "Sorting mode" toggle next to "Show
removed locations": when enabled, rows can be dragged onto another
location (or a drop strip to move to top level). The same toggle
appears on container array pages and gates drawer drag-to-swap. The
state persists across reloads so it survives post-move refreshes.

Dragging no longer selects text: drawer trays and draggable cards get
user-select: none, the drawer drag suppresses selection globally for
its duration, and mousedown on a tray prevents native selection.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-06-10 22:47:08 -07:00
1 parent fa78bb02d4
commit 20c982755a
9 files changed
+273 -19

No files matched your search

+2 -2
View File
@@ -4,8 +4,8 @@
{
"name": "solis",
"runtimeExecutable": "go",
"runtimeArgs": ["run", "."],
"port": 8889
"runtimeArgs": ["run", ".", "-c", "config-preview.toml"],
"port": 8899
}
]
}
+1
View File
@@ -18,3 +18,4 @@ Thumbs.db
# Config files (if you want to ignore actual config but keep example)
config.toml
config-preview.toml
+4 -1
View File
@@ -169,9 +169,12 @@
"locations.grid_cols": "Columns",
"locations.grid_dims": "rows × columns (max 20×20)",
"locations.container_array_hint": "Turns this location into a drawer cabinet. Open it from the folder view to add, color, and rearrange drawers.",
"locations.sorting_mode": "Sorting mode",
"locations.move_to_root": "Drop a location here to move it to the top level",
"locations.toggle_children": "Show or hide sub-locations",
"drawer.section_title": "Drawers",
"drawer.hint": "Hover or tap a drawer to peek inside. Drag (or touch and hold) a drawer to swap it with another slot. Click an empty slot to add a drawer.",
"drawer.hint": "Hover or tap a drawer to peek inside. Click an empty slot to add a drawer. Enable sorting mode to drag (or touch and hold) drawers and swap them around.",
"drawer.items": "item(s)",
"drawer.empty_contents": "This drawer is empty.",
"drawer.open": "Open",
+4 -1
View File
@@ -169,9 +169,12 @@
"locations.grid_cols": "列数",
"locations.grid_dims": "行 × 列(最大 20×20)",
"locations.container_array_hint": "将此位置变为抽屉柜。在文件夹视图中打开它即可添加、着色和重新排列抽屉。",
"locations.sorting_mode": "排序模式",
"locations.move_to_root": "将位置拖放到此处可移至顶层",
"locations.toggle_children": "显示或隐藏子位置",
"drawer.section_title": "抽屉",
"drawer.hint": "悬停或轻触抽屉可预览内容。拖动(或长按)抽屉可与其他格子交换位置。点击空格子可添加抽屉。",
"drawer.hint": "悬停或轻触抽屉可预览内容。点击空格子可添加抽屉。启用排序模式后,可拖动(或长按)抽屉交换位置。",
"drawer.items": "件物品",
"drawer.empty_contents": "此抽屉是空的。",
"drawer.open": "打开",
+50
View File
@@ -56,6 +56,7 @@ type PageData struct {
Breadcrumbs []db.Location
ChildLocations []db.Location
DrawerGrid [][]DrawerCell
LocationTree []LocationTreeRow
}
// DrawerCell is one slot of a container array grid; Drawer is nil for empty slots.
@@ -65,6 +66,54 @@ type DrawerCell struct {
Drawer *db.Drawer
}
// LocationTreeRow is a location flattened from the hierarchy in pre-order,
// carrying its nesting depth for the collapsible Locations table.
type LocationTreeRow struct {
db.Location
Depth int
Indent int // indentation in px for the name cell
HasChildren bool
}
// buildLocationTree flattens locations into pre-order rows. Locations whose
// parent is absent from the list (e.g. hidden removed parents) surface at the
// top level so they stay reachable.
func buildLocationTree(locations []db.Location) []LocationTreeRow {
inList := make(map[int64]bool, len(locations))
for _, l := range locations {
inList[l.ID] = true
}
childrenOf := map[int64][]db.Location{}
var roots []db.Location
for _, l := range locations {
if l.ParentID.Valid && l.ParentID.Int64 != l.ID && inList[l.ParentID.Int64] {
childrenOf[l.ParentID.Int64] = append(childrenOf[l.ParentID.Int64], l)
} else {
roots = append(roots, l)
}
}
rows := make([]LocationTreeRow, 0, len(locations))
visited := map[int64]bool{}
var walk func(l db.Location, depth int)
walk = func(l db.Location, depth int) {
if visited[l.ID] {
return
}
visited[l.ID] = true
kids := childrenOf[l.ID]
rows = append(rows, LocationTreeRow{Location: l, Depth: depth, Indent: depth * 22, HasChildren: len(kids) > 0})
for _, k := range kids {
walk(k, depth+1)
}
}
for _, r := range roots {
walk(r, 0)
}
return rows
}
// ==========================================
// 1. PUBLIC SHORT URL REDIRECT HANDLER
@@ -742,6 +791,7 @@ func (s *Server) handleAdminLocations(w http.ResponseWriter, r *http.Request) {
CSRFToken: csrf,
ActiveNav: "locations",
Locations: locations,
LocationTree: buildLocationTree(locations),
EditingLocation: editLoc,
ShowRemoved: showRemoved,
Toast: r.URL.Query().Get("toast"),
+102 -1
View File
@@ -1498,7 +1498,7 @@ tr:last-child .actions-dropdown-menu {
inset: 0;
transform-style: preserve-3d;
transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
cursor: grab;
cursor: pointer;
touch-action: pan-y;
}
@@ -1706,6 +1706,107 @@ tr:last-child .actions-dropdown-menu {
border-color: #b91c1c;
}
/* ==========================================
Locations tree table & sorting mode
========================================== */
.loc-name-cell {
display: flex;
align-items: center;
gap: 0.35rem;
}
.loc-caret {
display: inline-flex;
align-items: center;
justify-content: center;
width: 1.4rem;
height: 1.4rem;
border: none;
background: none;
color: var(--color-text-muted);
cursor: pointer;
border-radius: 4px;
padding: 0;
flex-shrink: 0;
transition: transform 0.18s ease, background-color 0.15s ease;
}
.loc-caret:hover {
background: var(--color-bg-base);
color: var(--color-brand-primary);
}
.loc-caret.expanded {
transform: rotate(90deg);
}
.loc-caret-spacer {
display: inline-block;
width: 1.4rem;
flex-shrink: 0;
}
.loc-grid-badge {
font-size: 0.68rem;
font-weight: 700;
color: var(--color-brand-primary);
background: var(--color-brand-light);
border: 1px solid var(--color-border-warm);
border-radius: 4px;
padding: 0.05rem 0.3rem;
margin-left: 0.35rem;
white-space: nowrap;
}
/* Root drop strip, shown only while sorting */
.sort-root-dropzone {
display: none;
align-items: center;
justify-content: center;
gap: 0.5rem;
margin-bottom: 1rem;
padding: 0.75rem;
border: 2px dashed var(--color-border-warm);
border-radius: 10px;
color: var(--color-brand-primary);
font-size: 0.9rem;
font-weight: 600;
background: var(--color-bg-surface);
}
body.sorting-mode .sort-root-dropzone {
display: flex;
}
body.sorting-mode .loc-row[draggable="true"] {
cursor: grab;
}
body.sorting-mode .drawer-tray {
cursor: grab;
}
body.sorting-mode .drawer-cabinet {
outline: 2px dashed var(--color-brand-accent);
outline-offset: 4px;
}
/* Keep drags from selecting text */
.folder-card[draggable="true"],
.item-card[draggable="true"],
.loc-row[draggable="true"],
.drawer-tray {
user-select: none;
-webkit-user-select: none;
}
body.drag-no-select,
body.drag-no-select * {
user-select: none !important;
-webkit-user-select: none !important;
}
/* 404 Not Found page */
.notfound-container {
display: flex;
+42 -5
View File
@@ -21,10 +21,32 @@ document.addEventListener("DOMContentLoaded", () => {
// 5. Mobile sidebar drawer interactions
initMobileSidebar();
// 6. Container array drawer grid (3D view)
// 6. Sorting mode (drag rearranging) toggle state
initSortingMode();
// 7. Container array drawer grid (3D view)
initDrawerArray();
});
// Sorting mode gates all drag-to-rearrange interactions; persisted so it
// survives the page reloads triggered after each successful move.
function sortingModeEnabled() {
return document.body.classList.contains("sorting-mode");
}
function initSortingMode() {
let enabled = false;
try { enabled = localStorage.getItem("solisSortingMode") === "1"; } catch (e) { /* private mode */ }
document.body.classList.toggle("sorting-mode", enabled);
document.querySelectorAll(".sorting-mode-toggle").forEach(cb => { cb.checked = enabled; });
}
function toggleSortingMode(checkbox) {
document.body.classList.toggle("sorting-mode", checkbox.checked);
document.querySelectorAll(".sorting-mode-toggle").forEach(cb => { cb.checked = checkbox.checked; });
try { localStorage.setItem("solisSortingMode", checkbox.checked ? "1" : "0"); } catch (e) { /* private mode */ }
}
// Mobile off-canvas sidebar drawer
function toggleSidebar() {
const sidebar = document.getElementById("sidebar");
@@ -174,6 +196,11 @@ function initDragAndDrop() {
draggables.forEach(draggable => {
draggable.addEventListener("dragstart", (e) => {
// Elements marked sort-gated only drag while sorting mode is on
if (draggable.classList.contains("sort-gated") && !sortingModeEnabled()) {
e.preventDefault();
return;
}
draggedElement = draggable;
draggable.classList.add("dragging");
@@ -397,6 +424,11 @@ function initDrawerArray() {
cell.classList.add("drag-source");
hidePeek();
// Suppress text selection for the duration of the drag
document.body.classList.add("drag-no-select");
const selection = window.getSelection();
if (selection) selection.removeAllRanges();
const front = cell.querySelector(".drawer-front");
const rect = front.getBoundingClientRect();
const ghost = front.cloneNode(true);
@@ -442,6 +474,7 @@ function initDrawerArray() {
dragState.suppressClick = true;
setTimeout(() => { dragState.suppressClick = false; }, 50);
document.body.classList.remove("drag-no-select");
cell.classList.remove("drag-source");
if (ghost) ghost.remove();
if (target) target.classList.remove("drop-target");
@@ -480,14 +513,17 @@ function initDrawerArray() {
cells.forEach(cell => {
const tray = cell.querySelector(".drawer-tray");
// Mouse: drag starts after a small movement threshold; plain click navigates
// Mouse: in sorting mode, drag starts after a small movement threshold;
// plain click navigates either way
tray.addEventListener("mousedown", (e) => {
if (e.button !== 0) return;
// Avoid native text selection from a press-and-move on the drawer
e.preventDefault();
const startX = e.clientX, startY = e.clientY;
let started = false;
const onMove = (ev) => {
if (!started && Math.hypot(ev.clientX - startX, ev.clientY - startY) > 6) {
if (!started && sortingModeEnabled() && Math.hypot(ev.clientX - startX, ev.clientY - startY) > 6) {
started = true;
startDrag(cell, ev.clientX, ev.clientY);
}
@@ -502,13 +538,14 @@ function initDrawerArray() {
document.addEventListener("mouseup", onUp);
});
// Touch: long-press (450ms) starts drag; quick tap toggles the peek
// Touch: in sorting mode, long-press (450ms) starts drag; quick tap
// toggles the peek either way
tray.addEventListener("touchstart", (e) => {
const touch = e.touches[0];
const startX = touch.clientX, startY = touch.clientY;
let pressTimer = setTimeout(() => {
pressTimer = null;
startDrag(cell, startX, startY);
if (sortingModeEnabled()) startDrag(cell, startX, startY);
}, 450);
const onTouchMove = (ev) => {
@@ -30,11 +30,17 @@
<div class="folder-controls" style="margin-top: 1rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem;">
{{if .IsAuthenticated}}
<div style="display: flex; gap: 0.5rem; align-items: center;">
<div style="display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap;">
<label class="checkbox-container" style="display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; color: var(--color-text-muted); cursor: pointer;">
<input type="checkbox" id="toggle-removed-checkbox" {{if .ShowRemoved}}checked{{end}} onchange="toggleShowRemoved(this)" style="accent-color: var(--color-brand-primary); cursor: pointer;">
{{T "folder.show_removed"}}
</label>
{{if .DrawerGrid}}
<label class="checkbox-container" style="display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; color: var(--color-text-muted); cursor: pointer;">
<input type="checkbox" class="sorting-mode-toggle" onchange="toggleSortingMode(this)" style="accent-color: var(--color-brand-primary); cursor: pointer;">
{{T "locations.sorting_mode"}}
</label>
{{end}}
</div>
{{end}}
+61 -8
View File
@@ -8,7 +8,7 @@
</div>
</div>
<form action="/admin/locations" method="GET" class="filter-bar" style="margin-bottom: 1.5rem; justify-content: flex-end;">
<form action="/admin/locations" method="GET" class="filter-bar" style="margin-bottom: 1.5rem; justify-content: flex-end; gap: 1.25rem;">
{{if .EditingLocation}}
<input type="hidden" name="edit" value="{{.EditingLocation.ID}}">
{{end}}
@@ -16,8 +16,19 @@
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
{{T "locations.show_removed"}}
</label>
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap;">
<input type="checkbox" class="sorting-mode-toggle" onchange="toggleSortingMode(this)" style="accent-color: var(--color-brand-primary);">
{{T "locations.sorting_mode"}}
</label>
</form>
<div class="sort-root-dropzone dropzone" data-location-id="0" data-type="location">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width: 18px; height: 18px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 19.5v-15m0 0l-6.75 6.75M12 4.5l6.75 6.75" />
</svg>
<span>{{T "locations.move_to_root"}}</span>
</div>
<div class="detail-grid">
<!-- Left Column: Locations List -->
@@ -34,14 +45,34 @@
</tr>
</thead>
<tbody>
{{if .Locations}}
{{range .Locations}}
<tr class="{{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}">
{{if .LocationTree}}
{{range .LocationTree}}
<tr class="loc-row sort-gated dropzone {{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}"
data-location-id="{{.ID}}"
data-type="location"
data-tree-parent="{{if .ParentID.Valid}}{{.ParentID.Int64}}{{else}}0{{end}}"
data-depth="{{.Depth}}"
{{if ne .ID 1}}draggable="true"{{end}}
{{if gt .Depth 0}}style="display: none;"{{end}}>
<td data-label="{{T "locations.col.name"}}" style="font-weight: 600;">
<a href="/{{.Slug}}" style="color: var(--color-brand-primary); text-decoration: none;">{{.Name}}</a>
{{if eq .LifecycleState "archived"}}
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">{{T "common.archived"}}</span>
{{end}}
<div class="loc-name-cell" style="padding-left: {{.Indent}}px;">
{{if .HasChildren}}
<button type="button" class="loc-caret" onclick="toggleLocChildren(this, '{{.ID}}')" aria-expanded="false" aria-label="{{T "locations.toggle_children"}}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" style="width: 13px; height: 13px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
</svg>
</button>
{{else}}
<span class="loc-caret-spacer"></span>
{{end}}
<a href="/{{.Slug}}" style="color: var(--color-brand-primary); text-decoration: none;">{{.Name}}</a>
{{if gt .GridRows 0}}
<span class="loc-grid-badge">{{.GridRows}}&times;{{.GridCols}}</span>
{{end}}
{{if eq .LifecycleState "archived"}}
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">{{T "common.archived"}}</span>
{{end}}
</div>
</td>
<td data-label="{{T "locations.col.parent"}}">
{{if .ParentName.Valid}}
@@ -224,5 +255,27 @@
const fields = checkbox.closest(".form-group").querySelector(".grid-size-fields");
if (fields) fields.hidden = !checkbox.checked;
}
function toggleLocChildren(btn, id) {
const expanded = btn.classList.toggle("expanded");
btn.setAttribute("aria-expanded", expanded ? "true" : "false");
document.querySelectorAll('.loc-row[data-tree-parent="' + id + '"]').forEach(row => {
if (expanded) {
row.style.display = "";
} else {
collapseLocRow(row);
}
});
}
function collapseLocRow(row) {
row.style.display = "none";
const caret = row.querySelector(".loc-caret");
if (caret) {
caret.classList.remove("expanded");
caret.setAttribute("aria-expanded", "false");
}
document.querySelectorAll('.loc-row[data-tree-parent="' + row.dataset.locationId + '"]').forEach(collapseLocRow);
}
</script>
{{end}}