Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
670c966868 | ||
|
|
e7e73d6882 | ||
|
|
d2488922e8 | ||
|
|
96370fa97a | ||
|
|
08b667113b | ||
|
|
abb451fa47 | ||
|
|
b259f0fbcf | ||
|
|
f4c4898c06 | ||
|
|
cf78d7cea2 | ||
|
|
dc75753f41 | ||
|
|
57ea3907b6 | ||
|
|
297b4a9664 | ||
|
|
f312217b7c | ||
|
|
fc37aa6e1e | ||
|
|
d8f2235de7 | ||
|
|
e3115df0bd | ||
|
|
001a0d6ef8 | ||
|
|
8910a1ff05 | ||
|
|
d871bddc99 | ||
|
|
d6fb6ec16d | ||
|
|
011f1b6e0b | ||
|
|
5799eee961 | ||
|
|
f68d9cd9e5 | ||
|
|
9b73ce99e7 | ||
|
|
089a7fd76b | ||
|
|
cb1f70e90d | ||
|
|
d769273f43 | ||
|
|
3064112595 | ||
|
|
154b5ee0a1 | ||
|
|
65edd735f1 |
No files matched your search
+173
-6
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { uploadCSVAction } from "./actions";
|
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 Card from "@/components/Card"
|
||||||
import { Input } from "@/components/FormElements";
|
import { Input } from "@/components/FormElements";
|
||||||
@@ -13,6 +13,20 @@ interface Songbook {
|
|||||||
language: string;
|
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() {
|
export default function AdminPage() {
|
||||||
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
||||||
const [selectedSongbookId, setSelectedSongbookId] = useState("");
|
const [selectedSongbookId, setSelectedSongbookId] = useState("");
|
||||||
@@ -25,6 +39,9 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
||||||
|
const [songInfos, setSongInfos] = useState<SongInfo[]>([])
|
||||||
|
|
||||||
async function handleCSVUpload(formData: FormData) {
|
async function handleCSVUpload(formData: FormData) {
|
||||||
setUploadStatus("Verarbeite...");
|
setUploadStatus("Verarbeite...");
|
||||||
const result = await uploadCSVAction(formData);
|
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(() => {
|
useEffect(() => {
|
||||||
async function loadSongbooks() {
|
async function loadSongbooks() {
|
||||||
try {
|
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 () => {
|
const addSongbook = async () => {
|
||||||
if (!newBookName) {
|
if (!newBookName) {
|
||||||
alert("Der Name des Liederbuches darf nicht leer sein!");
|
alert("Der Name des Liederbuches darf nicht leer sein!");
|
||||||
@@ -108,7 +197,7 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="font-sans p-4 sm:p-6 lg:p-8">
|
<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 */}
|
{/* HEADER */}
|
||||||
|
|
||||||
@@ -189,7 +278,7 @@ export default function AdminPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card title="CSV-Massenimport">
|
<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} />
|
<input type="hidden" name="songbookId" value={selectedSongbookId} />
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
@@ -233,11 +322,89 @@ export default function AdminPage() {
|
|||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
<Screens.Songs
|
<Screens.Songs
|
||||||
actionName="Auswählen"
|
actionName="Auswählen"
|
||||||
onSelectSong={(song) => console.log(song)}
|
onSelectSong={(song) => setSelectedSong(song)}
|
||||||
className=""
|
className=""
|
||||||
/>
|
/>
|
||||||
<Card title="Lied zu Liederbuch hinzufügen">
|
<Card title="Ausgewähltes Lied">
|
||||||
<Input.Text disabled></Input.Text>
|
<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>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
@@ -26,5 +26,6 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
margin-bottom: 25px;
|
margin-bottom: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
+2
-2
@@ -15,8 +15,8 @@ const geistMono = Geist_Mono({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Create Next App",
|
title: "PsalmTafel",
|
||||||
description: "Generated by create next app",
|
description: "Liedernummer-Anzeige für den Chor ",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
|
|||||||
+67
-2
@@ -1,5 +1,4 @@
|
|||||||
import Database from "better-sqlite3";
|
import Database from "better-sqlite3";
|
||||||
import { Noto_Sans_Tamil_Supplement } from "next/font/google";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const dbPath = path.join(process.cwd(), "songs.db");
|
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) {
|
export async function addSongToSongbook(title:string, songbookId:number, number:string) {
|
||||||
try {
|
try {
|
||||||
const runTransaction = db.transaction(() => {
|
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() {
|
export async function getSongbooks() {
|
||||||
try {
|
try {
|
||||||
const songbooks = db.prepare('SELECT id, name, language FROM songbooks ORDER BY name ASC').all();
|
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 {
|
try {
|
||||||
const info = db.prepare(`
|
const info = db.prepare(`
|
||||||
INSERT INTO songbooks (name, language)
|
INSERT INTO songbooks (name, language)
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "psalm-talel",
|
"name": "psalm-tafel",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
Reference in new issue
Block a user