Compare commits

..
27 Commits
Author SHA1 Message Date
robin 96370fa97a Merge pull request 'Feat dashboard' (#13) from feat-dashboard into main
Deploy Next.js via Docker / deploy (push) Successful in 36s
Reviewed-on: Schanbro/PsalmTafel#13
2026-07-29 11:15:47 +00:00
robin 08b667113b update version number 2026-07-29 13:15:18 +02:00
robin abb451fa47 refactor: update metadata 2026-07-29 12:56:31 +02:00
robin b259f0fbcf Merge pull request 'Main' (#21) from main into feat-dashboard
Reviewed-on: Schanbro/PsalmTafel#21
2026-07-29 10:48:34 +00:00
robin f4c4898c06 Merge pull request 'Feat/admin options' (#14) from feat/admin-options into main
Deploy Next.js via Docker / deploy (push) Successful in 37s
Reviewed-on: Schanbro/PsalmTafel#14
2026-07-28 15:05:03 +00:00
robin cf78d7cea2 feat: add ability to remove song from songbook 2026-07-28 17:03:28 +02:00
robin dc75753f41 feat: add api for removeSongFromSongbook 2026-07-28 16:29:44 +02:00
robin 57ea3907b6 feat: add removeSongFromSongbook to db managing.ts 2026-07-28 16:27:25 +02:00
robin 297b4a9664 Merge branch 'feat/admin-options' of https://git.schamagusa.de/Schanbro/PsalmTafel into feat/admin-options 2026-07-28 16:18:22 +02:00
robin f312217b7c fix: fix typo in admin page 2026-07-28 16:17:20 +02:00
robin fc37aa6e1e Merge branch 'main' into feat/admin-options 2026-07-28 14:16:40 +00:00
robin d8f2235de7 Merge pull request 'Ui-corrections' (#19) from ui-corrections into main
Deploy Next.js via Docker / deploy (push) Successful in 39s
Reviewed-on: Schanbro/PsalmTafel#19
2026-07-28 14:00:39 +00:00
robin e3115df0bd feat: add abilty to attach song to songbook 2026-07-28 15:53:51 +02:00
robin 001a0d6ef8 feat: add API for attachSongToSongbook 2026-07-28 15:40:33 +02:00
robin 8910a1ff05 feat: add attachSongToSongbook to db managing.ts 2026-07-28 15:32:48 +02:00
robin d871bddc99 feat: add api for getSongInfos
feat: show song informations of selected song
2026-07-28 15:00:48 +02:00
robin d6fb6ec16d feat: add getSongInfos to db managing.ts 2026-07-28 14:48:28 +02:00
robin 011f1b6e0b style: rearranged content 2026-07-27 18:50:12 +02:00
robin 5799eee961 style: - 2026-07-27 18:46:36 +02:00
robin f68d9cd9e5 feat: show raw informations about selected song 2026-07-27 18:39:26 +02:00
robin 9b73ce99e7 style: fix margin issue 2026-07-27 18:32:29 +02:00
robin 089a7fd76b fix: filled children (unimportant) 2026-07-27 17:51:01 +02:00
robin cb1f70e90d Merge pull request 'Main' (#18) from main into feat/admin-options
Reviewed-on: Schanbro/PsalmTafel#18
2026-07-27 15:01:48 +00:00
robin d769273f43 Merge pull request 'Ui corrections' (#17) from ui-corrections into main
Deploy Next.js via Docker / deploy (push) Successful in 32s
Reviewed-on: Schanbro/PsalmTafel#17
2026-07-27 15:01:06 +00:00
robin 3064112595 style: changed arrangement of elements in admin 2026-07-27 16:39:00 +02:00
robin 154b5ee0a1 feat: add ability to select a song 2026-07-27 16:35:28 +02:00
robin 65edd735f1 Merge pull request 'Main' (#16) from main into feat/admin-options
Reviewed-on: Schanbro/PsalmTafel#16
2026-07-27 14:28:04 +00:00
8 changed files with 345 additions and 13 deletions

No files matched your search

+173 -6
View File
@@ -1,7 +1,7 @@
"use client";
import { uploadCSVAction } from "./actions";
import { useEffect, useState } from "react";
import { JSXElementConstructor, Key, ReactElement, ReactNode, ReactPortal, useEffect, useState } from "react";
import Card from "@/components/Card"
import { Input } from "@/components/FormElements";
@@ -13,6 +13,20 @@ interface Songbook {
language: string;
}
interface Song {
song_id: number;
songbook_id: number;
song_number: string;
title: string;
}
interface SongInfo {
songbook_id: number;
songbook_name: string;
song_number: string;
title: string;
}
export default function AdminPage() {
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
const [selectedSongbookId, setSelectedSongbookId] = useState("");
@@ -25,6 +39,9 @@ export default function AdminPage() {
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
const [songInfos, setSongInfos] = useState<SongInfo[]>([])
async function handleCSVUpload(formData: FormData) {
setUploadStatus("Verarbeite...");
const result = await uploadCSVAction(formData);
@@ -36,6 +53,27 @@ export default function AdminPage() {
}
}
useEffect(() => {
if (!selectedSong) {
setSongInfos([]);
return;
}
async function fetchSongInfos() {
try {
const res = await fetch(`/api/songs/${selectedSong?.song_id}`);
if (res.ok) {
const data = await res.json();
setSongInfos(data);
}
} catch (error) {
console.error("Fehler beim Laden der Songinfos:", error);
}
}
fetchSongInfos();
}, [selectedSong]);
useEffect(() => {
async function loadSongbooks() {
try {
@@ -79,6 +117,57 @@ export default function AdminPage() {
}
};
const attachSong = async () => {
if (!selectedSongbookId || !number || !selectedSong) {
alert("Alle Felder ausfüllen!");
return;
}
try {
const res = await fetch("/api/songs/attach", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
songbookId: selectedSongbookId,
songId: selectedSong.song_id,
number: number,
})
});
if (res.ok) {
alert("Lied erfolgreich zum Liederbuch hinzugefügt!");
} else {
alert("Fehler beim Senden.");
}
} catch (error) {
console.error("Failed sending current songID:", error);
}
}
const removeSong = async () => {
if (!selectedSongbookId || !selectedSong) {
alert("Alle Felder ausfüllen!");
return;
}
try {
const res = await fetch("/api/songs/remove", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
songbookId: selectedSongbookId,
songId: selectedSong.song_id
})
});
if (res.ok) {
alert("Lied erfolgreich aus dem Liederbuch gelöscht!");
} else {
alert("Fehler beim Senden.");
}
} catch (error) {
console.error("Failed sending current songID:", error);
}
}
const addSongbook = async () => {
if (!newBookName) {
alert("Der Name des Liederbuches darf nicht leer sein!");
@@ -108,7 +197,7 @@ export default function AdminPage() {
return (
<div className="font-sans p-4 sm:p-6 lg:p-8">
<div className="max-w-6xl mx-auto">
<div className="max-w-6xl mx-auto space-y-6">
{/* HEADER */}
@@ -189,7 +278,7 @@ export default function AdminPage() {
</Card>
<Card title="CSV-Massenimport">
<form action={handleCSVUpload} className="h-full flex flex-col justify-between">
<form action={handleCSVUpload} className="flex flex-col justify-between">
<input type="hidden" name="songbookId" value={selectedSongbookId} />
<div className="space-y-4">
<div>
@@ -233,11 +322,89 @@ export default function AdminPage() {
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
<Screens.Songs
actionName="Auswählen"
onSelectSong={(song) => console.log(song)}
onSelectSong={(song) => setSelectedSong(song)}
className=""
/>
<Card title="Lied zu Liederbuch hinzufügen">
<Input.Text disabled></Input.Text>
<Card title="Ausgewähltes Lied">
<Input.Text value={selectedSong ? selectedSong.title : ""} disabled></Input.Text>
<Card title="Informationen" className="mt-4">
<div className="text-sm space-y-1">
<p><span className="font-semibold">Lied-ID:</span> {selectedSong?.song_id ?? "-"}</p>
<p><span className="font-semibold">In Liederbüchern:</span></p>
{songInfos.length > 0 ? (
<ul className="list-disc list-inside pl-2 text-xs text-neutral-400">
{songInfos.map((info) => (
<li key={info.songbook_id}>
{info.songbook_name} (Nr. {info.song_number})
</li>
))}
</ul>
) : (
<p className="text-xs text-neutral-500">Keine Daten geladen</p>
)}
</div>
</Card>
<Card title="Aktionen">
<Card title="Zu Liederbuch hinzufügen">
<div className="space-y-4">
<div>
<Input.Label>Ziel-Liederbuch</Input.Label>
<Input.Select
value={selectedSongbookId}
onChange={(e) => setSelectedSongbookId(e.target.value)}
>
<option value="">-- Bitte wählen --</option>
{songbooks.map((book) => (
<option key={book.id} value={String(book.id)}>
{book.name}{book.language ? ` (${book.language})` : ""}
</option>
))}
</Input.Select>
</div>
<div>
<Input.Label>Nummer</Input.Label>
<Input.Text
type="text"
placeholder="12a"
value={number}
onChange={(e) => setNumber(e.target.value)}
/>
</div>
<Input.Button
onClick={attachSong}
className="w-full mt-6 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm"
>
Lied hinzufügen
</Input.Button>
</div>
</Card>
<Card title="Aus Liederbuch löschen">
<div className="space-y-4">
<div>
<Input.Label>Ziel-Liederbuch</Input.Label>
<Input.Select
value={selectedSongbookId}
onChange={(e) => setSelectedSongbookId(e.target.value)}
>
<option value="">-- Bitte wählen --</option>
{songInfos.length > 0 ? (
songInfos.map((info) => (
<option key={info.songbook_id} value={String(info.songbook_id)}>
{info.songbook_name} (Nr. {info.song_number})
</option>
))
): ""}
</Input.Select>
</div>
<Input.Button
onClick={removeSong}
className="w-full mt-6 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm"
>
Lied aus Liederbuch löschen
</Input.Button>
</div>
</Card>
</Card>
</Card>
</div>
</div>
+20
View File
@@ -0,0 +1,20 @@
import { NextResponse } from "next/server";
import { getSongInfos } from "@/lib/db/managing";
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const songInfos = await getSongInfos(id);
return NextResponse.json(songInfos || []);
} catch (error) {
console.error("API Error:", error);
return NextResponse.json(
{ error: "Fehler beim Laden der Songinfos" },
{ status: 500 }
);
}
}
+40
View File
@@ -0,0 +1,40 @@
import { NextResponse } from "next/server";
import { attachSongToSongbook } from "@/lib/db/managing";
export async function POST(request: Request) {
try {
const body = await request.json();
const { songId, songbookId, number } = body;
if (isNaN(songId) || isNaN(songbookId) || !number) {
return NextResponse.json(
{ error: "Ungültige IDs oder fehlende Nummer." },
{ status: 400 }
);
}
const result = await attachSongToSongbook(
Number(songId),
Number(songbookId),
String(number)
);
if (result.success) {
return NextResponse.json(
{ message: "Lied erfolgreich verknüpft!" },
{ status: 200 }
);
} else {
return NextResponse.json(
{ error: "Fehler beim Verknüpfen in der Datenbank." },
{ status: 500 }
);
}
} catch (error) {
console.error("API Error in /api/songs/attach:", error);
return NextResponse.json(
{ error: "Ungültiges JSON oder Serverfehler." },
{ status: 500 }
);
}
}
+39
View File
@@ -0,0 +1,39 @@
import { NextResponse } from "next/server";
import { removeSongfromSongbook } from "@/lib/db/managing";
export async function POST(request: Request) {
try {
const body = await request.json();
const { songId, songbookId } = body;
if (isNaN(songId) || isNaN(songbookId)) {
return NextResponse.json(
{ error: "Ungültige IDs." },
{ status: 400 }
);
}
const result = await removeSongfromSongbook(
Number(songId),
Number(songbookId)
);
if (result.success) {
return NextResponse.json(
{ message: "Lied erfolgreich aus dem Liederbuch gelöscht!" },
{ status: 200 }
);
} else {
return NextResponse.json(
{ error: "Fehler beim Löschen aus dem Liederbuch." },
{ status: 500 }
);
}
} catch (error) {
console.error("API Error in /api/songs/remove:", error);
return NextResponse.json(
{ error: "Ungültiges JSON oder Serverfehler." },
{ status: 500 }
);
}
}
+3 -2
View File
@@ -26,5 +26,6 @@ body {
}
section {
margin-bottom: 25px;
}
margin-bottom: 50px;
}
+2 -2
View File
@@ -15,8 +15,8 @@ const geistMono = Geist_Mono({
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
title: "PsalmTafel",
description: "Liedernummer-Anzeige für den Chor ",
};
export default function RootLayout({
+67 -2
View File
@@ -1,5 +1,4 @@
import Database from "better-sqlite3";
import { Noto_Sans_Tamil_Supplement } from "next/font/google";
import path from "path";
const dbPath = path.join(process.cwd(), "songs.db");
@@ -69,6 +68,32 @@ export async function getSong(songbookId: number, songId: string) {
}
}
export async function getSongInfos(songId: string) {
try {
const songRecords = db.prepare(`
SELECT
ss.songbook_id,
sb.name AS songbook_name,
ss.song_number,
s.title
FROM songbook_songs ss
JOIN songbooks sb ON ss.songbook_id = sb.id
JOIN songs s ON ss.song_id = s.id
WHERE s.id = ?
`).all(songId) as {
songbook_id: number;
songbook_name: string;
song_number: string;
title: string;
}[] | undefined
return songRecords || null;
} catch (error) {
console.error("Fehler in getSong:", error);
return null;
}
}
export async function addSongToSongbook(title:string, songbookId:number, number:string) {
try {
const runTransaction = db.transaction(() => {
@@ -95,6 +120,46 @@ export async function addSongToSongbook(title:string, songbookId:number, number:
}
}
export async function attachSongToSongbook(songId: number, songbookId: number, number: string) {
try {
const songExists = db.prepare("SELECT id FROM songs WHERE id = ?").get(songId);
if (!songExists) {
console.error(`Song mit ID ${songId} existiert nicht in DB.`);
return { success: false, error: "Song nicht gefunden." };
}
const bookExists = db.prepare("SELECT id FROM songbooks WHERE id = ?").get(songbookId);
if (!bookExists) {
console.error(`Songbook mit ID ${songbookId} existiert nicht in DB.`);
return { success: false, error: "Liederbuch nicht gefunden." };
}
db.prepare(`
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
VALUES (?, ?, ?)
`).run(songbookId, songId, number);
return { success: true };
} catch (error) {
console.error("Error in attachSongToSongbook:", error);
return { success: false };
}
}
export async function removeSongfromSongbook(songId: number, songbookId: number) {
try {
const info = db.prepare(`
DELETE FROM songbook_songs
WHERE songbook_id = ? AND song_id = ?
`).run(songbookId, songId);
return { success: info.changes > 0 };
} catch (error) {
console.error("Error in removeSongfromSongbook:", error);
return { success: false };
}
}
export async function getSongbooks() {
try {
const songbooks = db.prepare('SELECT id, name, language FROM songbooks ORDER BY name ASC').all();
@@ -104,7 +169,7 @@ export async function getSongbooks() {
}
}
export async function addSongbook(name:String, language:String) {
export async function addSongbook(name: string, language: string) {
try {
const info = db.prepare(`
INSERT INTO songbooks (name, language)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "psalm-talel",
"version": "0.0.4",
"version": "0.0.5",
"private": true,
"scripts": {
"dev": "next dev",