diff --git a/frontend/src/melodies/MelodyComposer.jsx b/frontend/src/melodies/MelodyComposer.jsx index ed1fa13..00c9ec9 100644 --- a/frontend/src/melodies/MelodyComposer.jsx +++ b/frontend/src/melodies/MelodyComposer.jsx @@ -355,88 +355,91 @@ export default function MelodyComposer() { className="rounded-lg border p-4" style={{ backgroundColor: "var(--bg-card)", borderColor: "var(--border-primary)" }} > -
Create a new archetype from this composer pattern.
diff --git a/frontend/src/melodies/MelodyList.jsx b/frontend/src/melodies/MelodyList.jsx
index cb33413..9f4c1f4 100644
--- a/frontend/src/melodies/MelodyList.jsx
+++ b/frontend/src/melodies/MelodyList.jsx
@@ -1,4 +1,4 @@
-import { useState, useEffect, useRef } from "react";
+import { useState, useEffect, useRef, useMemo } from "react";
import { useNavigate } from "react-router-dom";
import api from "../api/client";
import { useAuth } from "../auth/AuthContext";
@@ -13,16 +13,18 @@ import {
const MELODY_TYPES = ["", "orthodox", "catholic", "all"];
const MELODY_TONES = ["", "normal", "festive", "cheerful", "lamentation"];
+const NOTE_LABELS = "ABCDEFGHIJKLMNOP";
// All available columns with their defaults
const ALL_COLUMNS = [
{ key: "color", label: "Color", defaultOn: true },
- { key: "status", label: "Status", defaultOn: true },
{ key: "name", label: "Name", defaultOn: true, alwaysOn: true },
+ { key: "status", label: "Status", defaultOn: true },
{ key: "description", label: "Description", defaultOn: false },
{ key: "type", label: "Type", defaultOn: true },
{ key: "tone", label: "Tone", defaultOn: true },
{ key: "totalNotes", label: "Total Notes", defaultOn: true },
+ { key: "totalActiveBells", label: "Total Active Bells", defaultOn: true },
{ key: "minSpeed", label: "Min Speed", defaultOn: false },
{ key: "maxSpeed", label: "Max Speed", defaultOn: false },
{ key: "tags", label: "Tags", defaultOn: false },
@@ -32,6 +34,11 @@ const ALL_COLUMNS = [
{ key: "pauseDuration", label: "Pause", defaultOn: false },
{ key: "infiniteLoop", label: "Infinite", defaultOn: false },
{ key: "noteAssignments", label: "Note Assignments", defaultOn: false },
+ { key: "binaryFile", label: "Binary File", defaultOn: false },
+ { key: "dateCreated", label: "Date Created", defaultOn: false },
+ { key: "dateEdited", label: "Date Edited", defaultOn: false },
+ { key: "createdBy", label: "Created By", defaultOn: false },
+ { key: "lastEditedBy", label: "Last Edited By", defaultOn: false },
{ key: "isTrueRing", label: "True Ring", defaultOn: true },
{ key: "docId", label: "Document ID", defaultOn: false },
{ key: "pid", label: "PID", defaultOn: false },
@@ -49,6 +56,43 @@ function getDefaultVisibleColumns() {
return ALL_COLUMNS.filter((c) => c.defaultOn).map((c) => c.key);
}
+function speedBarColor(speedPercent) {
+ const v = Math.max(0, Math.min(100, Number(speedPercent || 0)));
+ const hue = (v / 100) * 120;
+ return `hsl(${hue}, 85%, 46%)`;
+}
+
+function parseDateValue(isoValue) {
+ if (!isoValue) return 0;
+ const time = new Date(isoValue).getTime();
+ return Number.isNaN(time) ? 0 : time;
+}
+
+function getBinaryUrl(row) {
+ const candidate = row?.url;
+ if (!candidate || typeof candidate !== "string") return null;
+ if (candidate.startsWith("http") || candidate.startsWith("/api")) return candidate;
+ if (candidate.startsWith("/")) return `/api${candidate}`;
+ return `/api/${candidate}`;
+}
+
+function getBinaryFilename(row) {
+ const url = getBinaryUrl(row);
+ if (!url) return null;
+
+ try {
+ const parsed = new URL(url, window.location.origin);
+ const path = decodeURIComponent(parsed.pathname || "");
+ const parts = path.split("/");
+ const name = parts[parts.length - 1];
+ if (name && name.toLowerCase().endsWith(".bsm")) return name;
+ } catch {
+ // fallback below
+ }
+
+ return row?.pid ? `${row.pid}.bsm` : "melody.bsm";
+}
+
export default function MelodyList() {
const [melodies, setMelodies] = useState([]);
const [total, setTotal] = useState(0);
@@ -58,6 +102,9 @@ export default function MelodyList() {
const [typeFilter, setTypeFilter] = useState("");
const [toneFilter, setToneFilter] = useState("");
const [statusFilter, setStatusFilter] = useState("");
+ const [createdByFilter, setCreatedByFilter] = useState([]);
+ const [sortBy, setSortBy] = useState("dateCreated");
+ const [sortDir, setSortDir] = useState("desc");
const [displayLang, setDisplayLang] = useState("en");
const [melodySettings, setMelodySettings] = useState(null);
const [deleteTarget, setDeleteTarget] = useState(null);
@@ -65,7 +112,9 @@ export default function MelodyList() {
const [actionLoading, setActionLoading] = useState(null);
const [visibleColumns, setVisibleColumns] = useState(getDefaultVisibleColumns);
const [showColumnPicker, setShowColumnPicker] = useState(false);
+ const [showCreatorPicker, setShowCreatorPicker] = useState(false);
const columnPickerRef = useRef(null);
+ const creatorPickerRef = useRef(null);
const navigate = useNavigate();
const { hasPermission } = useAuth();
const canEdit = hasPermission("melodies", "edit");
@@ -77,18 +126,21 @@ export default function MelodyList() {
});
}, []);
- // Close column picker on outside click
+ // Close dropdowns on outside click
useEffect(() => {
const handleClick = (e) => {
if (columnPickerRef.current && !columnPickerRef.current.contains(e.target)) {
setShowColumnPicker(false);
}
+ if (creatorPickerRef.current && !creatorPickerRef.current.contains(e.target)) {
+ setShowCreatorPicker(false);
+ }
};
- if (showColumnPicker) {
+ if (showColumnPicker || showCreatorPicker) {
document.addEventListener("mousedown", handleClick);
return () => document.removeEventListener("mousedown", handleClick);
}
- }, [showColumnPicker]);
+ }, [showColumnPicker, showCreatorPicker]);
const fetchMelodies = async () => {
setLoading(true);
@@ -101,8 +153,8 @@ export default function MelodyList() {
if (statusFilter) params.set("status", statusFilter);
const qs = params.toString();
const data = await api.get(`/melodies${qs ? `?${qs}` : ""}`);
- setMelodies(data.melodies);
- setTotal(data.total);
+ setMelodies(data.melodies || []);
+ setTotal(data.total || 0);
} catch (err) {
setError(err.message);
} finally {
@@ -153,6 +205,34 @@ export default function MelodyList() {
}
};
+ const downloadBinary = async (e, row) => {
+ e.stopPropagation();
+ const binaryUrl = getBinaryUrl(row);
+ if (!binaryUrl) return;
+
+ try {
+ const token = localStorage.getItem("access_token");
+ let res = await fetch(binaryUrl, {
+ headers: token ? { Authorization: `Bearer ${token}` } : {},
+ });
+
+ if (!res.ok && binaryUrl.startsWith("http")) {
+ res = await fetch(binaryUrl);
+ }
+ if (!res.ok) throw new Error(`Download failed: ${res.statusText}`);
+
+ const blob = await res.blob();
+ const objectUrl = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = objectUrl;
+ a.download = getBinaryFilename(row) || "melody.bsm";
+ a.click();
+ URL.revokeObjectURL(objectUrl);
+ } catch (err) {
+ setError(err.message);
+ }
+ };
+
const toggleColumn = (key) => {
const col = ALL_COLUMNS.find((c) => c.key === key);
if (col?.alwaysOn) return;
@@ -165,22 +245,75 @@ export default function MelodyList() {
});
};
+ const toggleCreator = (creator) => {
+ setCreatedByFilter((prev) =>
+ prev.includes(creator) ? prev.filter((c) => c !== creator) : [...prev, creator]
+ );
+ };
+
const isVisible = (key) => visibleColumns.includes(key);
- const getDisplayName = (nameVal) =>
- getLocalizedValue(nameVal, displayLang, "Untitled");
+ const getDisplayName = (nameVal) => getLocalizedValue(nameVal, displayLang, "Untitled");
+
+ const allCreators = useMemo(() => {
+ const creators = new Set();
+ for (const row of melodies) {
+ const creator = row?.metadata?.createdBy;
+ if (creator) creators.add(creator);
+ }
+ return Array.from(creators).sort((a, b) => a.localeCompare(b));
+ }, [melodies]);
+
+ const getSortValue = (row, key) => {
+ const info = row?.information || {};
+ const metadata = row?.metadata || {};
+
+ switch (key) {
+ case "name":
+ return getDisplayName(info.name).toLowerCase();
+ case "totalBells":
+ return Number(info.totalActiveBells || 0);
+ case "dateEdited":
+ return parseDateValue(metadata.dateEdited);
+ case "dateCreated":
+ default:
+ return parseDateValue(metadata.dateCreated);
+ }
+ };
+
+ const displayRows = useMemo(() => {
+ let rows = melodies;
+
+ if (createdByFilter.length > 0) {
+ rows = rows.filter((row) => createdByFilter.includes(row?.metadata?.createdBy || ""));
+ }
+
+ return [...rows].sort((a, b) => {
+ const av = getSortValue(a, sortBy);
+ const bv = getSortValue(b, sortBy);
+
+ if (typeof av === "string" && typeof bv === "string") {
+ return sortDir === "asc" ? av.localeCompare(bv) : bv.localeCompare(av);
+ }
+
+ return sortDir === "asc" ? av - bv : bv - av;
+ });
+ }, [melodies, createdByFilter, sortBy, sortDir]); // eslint-disable-line react-hooks/exhaustive-deps
const renderCellValue = (key, row) => {
const info = row.information || {};
const ds = row.default_settings || {};
+ const metadata = row.metadata || {};
+
switch (key) {
case "status":
return (
{row.status === "published" ? "Live" : "Draft"}
@@ -196,25 +329,33 @@ export default function MelodyList() {
) : (
);
- case "name":
+ case "name": {
+ const description = getLocalizedValue(info.description, displayLang) || "-";
return (
- {getLocalizedValue(info.description, displayLang) || "-"}
+
+ {description}
No creators found
+ ) : ( + allCreators.map((creator) => ( + + )) + )} + {createdByFilter.length > 0 && ( + + )} +