Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da00d95786 |
No files matched your search
+6
-173
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { uploadCSVAction } from "./actions";
|
import { uploadCSVAction } from "./actions";
|
||||||
import { JSXElementConstructor, Key, ReactElement, ReactNode, ReactPortal, useEffect, useState } from "react";
|
import { 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,20 +13,6 @@ 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("");
|
||||||
@@ -39,9 +25,6 @@ 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);
|
||||||
@@ -53,27 +36,6 @@ 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 {
|
||||||
@@ -117,57 +79,6 @@ 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!");
|
||||||
@@ -197,7 +108,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 space-y-6">
|
<div className="max-w-6xl mx-auto">
|
||||||
|
|
||||||
{/* HEADER */}
|
{/* HEADER */}
|
||||||
|
|
||||||
@@ -278,7 +189,7 @@ export default function AdminPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card title="CSV-Massenimport">
|
<Card title="CSV-Massenimport">
|
||||||
<form action={handleCSVUpload} className="flex flex-col justify-between">
|
<form action={handleCSVUpload} className="h-full 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>
|
||||||
@@ -322,89 +233,11 @@ 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) => setSelectedSong(song)}
|
onSelectSong={(song) => console.log(song)}
|
||||||
className=""
|
className=""
|
||||||
/>
|
/>
|
||||||
<Card title="Ausgewähltes Lied">
|
<Card title="Lied zu Liederbuch hinzufügen">
|
||||||
<Input.Text value={selectedSong ? selectedSong.title : ""} disabled></Input.Text>
|
<Input.Text 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>
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
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 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
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 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
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 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-2
@@ -26,6 +26,5 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
margin-bottom: 50px;
|
margin-bottom: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
+2
-2
@@ -15,8 +15,8 @@ const geistMono = Geist_Mono({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "PsalmTafel",
|
title: "Create Next App",
|
||||||
description: "Liedernummer-Anzeige für den Chor ",
|
description: "Generated by create next app",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
|
|||||||
+2
-67
@@ -1,4 +1,5 @@
|
|||||||
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");
|
||||||
@@ -68,32 +69,6 @@ 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(() => {
|
||||||
@@ -120,46 +95,6 @@ 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();
|
||||||
@@ -169,7 +104,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-tafel",
|
"name": "psalm-talel",
|
||||||
"version": "0.0.5.1",
|
"version": "0.0.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
Reference in new issue
Block a user