-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenre-test.html
More file actions
180 lines (151 loc) · 5.39 KB
/
genre-test.html
File metadata and controls
180 lines (151 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<title>Genres & Event-Typen Auswahl</title>
<style>
body {
font-family: sans-serif;
background: #fdfcf8;
padding: 1rem;
}
.type-group {
margin-bottom: 1.5rem;
font-size: 0.9em;
}
.type-title {
font-weight: bold;
margin-bottom: 0.5rem;
}
.type-button {
display: inline-block;
padding: 0.4em 0.8em;
margin: 0.2em 0.4em 0.6em 0;
border-radius: 1em;
border: 1px solid #aaa;
background: #fff;
cursor: pointer;
transition: background 0.2s;
}
.type-button.selected {
background-color: #ffdca8;
border-color: #f90;
}
.genre-button {
display: inline-block;
padding: 0.4em 0.8em;
margin: 0.2em;
border-radius: 1em;
border: 1px solid #aaa;
background: #fff;
cursor: pointer;
transition: background 0.2s;
}
.genre-button.selected {
background-color: #ffdca8;
border-color: #f90;
}
.selected-output {
margin-top: 1rem;
font-size: 0.9rem;
color: #444;
white-space: pre-wrap;
background: #fff;
border: 1px solid #eee;
padding: 1rem;
border-radius: 8px;
}
</style>
</head>
<body>
<h2>Event-Typen</h2>
<div id="type-buttons"></div>
<h2>Genres</h2>
<div id="genre-container"></div>
<div class="selected-output">
<strong>Aktive Typen:</strong>
<div id="active-types"></div>
<strong>Ausgewählte Genres:</strong>
<div id="active-genres"></div>
</div>
<script>
const selectedTypes = new Set();
const selectedGenres = new Set();
const genreContainer = document.getElementById("genre-container");
const typeButtonsDiv = document.getElementById("type-buttons");
const activeTypesDiv = document.getElementById("active-types");
const activeGenresDiv = document.getElementById("active-genres");
async function fetchGenres() {
try {
const res = await fetch("http://localhost:9090/api/meta/genres?language=de", { credentials: "include" });
const data = await res.json();
// Group by type_id, preserving original order
const groupedArray = [];
data.forEach(item => {
let group = groupedArray.find(g => g.type_id === item.type_id);
if (!group) {
group = {
type_id: item.type_id,
type_name: item.type_name,
genres: []
};
groupedArray.push(group);
}
group.genres.push(item);
});
// Render type buttons
groupedArray.forEach(group => {
const btn = document.createElement("button");
btn.className = "type-button";
btn.textContent = group.type_name;
btn.addEventListener("click", () => {
btn.classList.toggle("selected");
const isSelected = btn.classList.contains("selected");
if (isSelected) {
selectedTypes.add(group.type_id);
renderGenres(group.type_id, group.genres);
} else {
selectedTypes.delete(group.type_id);
removeGenres(group.type_id);
}
updateOutputs();
});
typeButtonsDiv.appendChild(btn);
});
function renderGenres(typeId, genres) {
const groupDiv = document.createElement("div");
groupDiv.className = "type-group";
groupDiv.dataset.typeId = typeId;
genres.forEach(genre => {
const tag = document.createElement("div");
tag.className = "genre-button";
tag.textContent = genre.genre_name;
tag.dataset.genreId = genre.genre_id;
tag.addEventListener("click", () => {
tag.classList.toggle("selected");
const id = genre.genre_id;
tag.classList.contains("selected")
? selectedGenres.add(id)
: selectedGenres.delete(id);
updateOutputs();
});
groupDiv.appendChild(tag);
});
genreContainer.appendChild(groupDiv);
}
function removeGenres(typeId) {
const groupDiv = genreContainer.querySelector(`.type-group[data-type-id="${typeId}"]`);
if (groupDiv) genreContainer.removeChild(groupDiv);
}
function updateOutputs() {
activeTypesDiv.textContent = JSON.stringify([...selectedTypes], null, 2);
activeGenresDiv.textContent = JSON.stringify([...selectedGenres], null, 2);
}
} catch (err) {
console.error("Fehler beim Laden:", err);
}
}
fetchGenres();
</script>
</body>
</html>