-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
281 lines (241 loc) · 9.24 KB
/
dashboard.html
File metadata and controls
281 lines (241 loc) · 9.24 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html>
<head>
<style>
.emby-collapsible-button {
background: linear-gradient(to bottom, #4CAF50, #45a049);
color: white;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.form-group { margin-bottom: 15px; }
.emby-select { padding: 5px; margin-right: 10px; }
.emby-button { padding: 8px 16px; margin-right: 10px; }
.status { margin-top: 10px; font-weight: bold; }
#tablewrap { margin-top: 20px; }
table { width: 100%; border-collapse: collapse; }
table th, table td { border: 1px solid #ddd; padding: 8px; text-align: left; }
table th { background-color: #f2f2f2; }
.streaming { background-color: #e8f5e8; }
.traditional { background-color: #f5f5f5; }
.logo { width: 50px; height: 30px; object-fit: contain; }
</style>
</head>
<body>
<div data-role="page" id="studioDashboardPage" class="page libraryPage" data-require="emby-checkbox,emby-collapse,emby-input,emby-select">
<div data-role="content">
<div class="content-primary">
<div class="form-group">
<label>
<span>Suche:</span>
<input type="text" id="search" class="emby-input" placeholder="Studio filtern...">
</label>
<label>
<span>Sortierung:</span>
<select id="sort" class="emby-select">
<option value="name">Name</option>
<option value="count" selected>Anzahl</option>
</select>
</label>
<label>
<span>Anzahl:</span>
<select id="topn" class="emby-select">
<option value="">Alle</option>
<option value="10">Top 10</option>
<option value="20">Top 20</option>
<option value="50">Top 50</option>
</select>
</label>
<label>
<span>Filter:</span>
<select id="filterType" class="emby-select">
<option value="all">Alle</option>
<option value="streaming">Nur Streaming-Services</option>
<option value="traditional">Nur traditionelle Studios</option>
</select>
</label>
<button id="reload" class="emby-button">Neu laden</button>
<button id="syncCollections" class="emby-button">Sammlungen synchronisieren</button>
</div>
<div class="form-group">
<button id="exportJson" class="emby-button">JSON exportieren</button>
<button id="exportCsv" class="emby-button">CSV exportieren</button>
<button id="saveJson" class="emby-button">JSON speichern</button>
<button id="saveCsv" class="emby-button">CSV speichern</button>
</div>
<div id="status" class="status">Bereit</div>
<div id="tablewrap">Lade Daten…</div>
</div>
</div>
</div>
<script>
(function () {
const page = document.getElementById('studioDashboardPage');
const table = page.querySelector('#tablewrap');
const search = page.querySelector('#search');
const sortEl = page.querySelector('#sort');
const topEl = page.querySelector('#topn');
const filterEl = page.querySelector('#filterType');
const reload = page.querySelector('#reload');
const status = page.querySelector('#status');
const syncBtn = page.querySelector('#syncCollections');
const btnExportJson = page.querySelector('#exportJson');
const btnExportCsv = page.querySelector('#exportCsv');
const btnSaveJson = page.querySelector('#saveJson');
const btnSaveCsv = page.querySelector('#saveCsv');
let raw = [];
function setStatus(text) { status.textContent = text; }
function getCurrentFilteredData() {
let data = [...raw];
const searchTerm = search.value.toLowerCase().trim();
const filterType = filterEl.value;
const sortBy = sortEl.value;
const topN = parseInt(topEl.value) || 0;
if (searchTerm) {
data = data.filter(x => x.Studio && x.Studio.toLowerCase().includes(searchTerm));
}
if (filterType && filterType !== 'all') {
if (filterType === 'streaming') {
data = data.filter(x => x.IsStreamingService);
} else if (filterType === 'traditional') {
data = data.filter(x => !x.IsStreamingService);
}
}
if (sortBy === 'count') {
data.sort((a, b) => (b.Count || 0) - (a.Count || 0));
} else {
data.sort((a, b) => (a.Studio || '').localeCompare(b.Studio || ''));
}
if (topN > 0) {
data = data.slice(0, topN);
}
return data;
}
function apply() {
try {
const data = getCurrentFilteredData();
if (!data.length) {
table.innerHTML = 'Keine Studios gefunden.';
setStatus(`Keine Ergebnisse (${raw.length} total)`);
return;
}
let html = '<table><thead><tr><th>Logo</th><th>Studio</th><th>Typ</th><th>Anzahl</th></tr></thead><tbody>';
for (const item of data) {
const rowClass = item.IsStreamingService ? 'streaming' : 'traditional';
const logoHtml = item.LogoUrl ?
`<img src="${item.LogoUrl}" alt="${item.Studio}" class="logo" onerror="this.style.display='none'">` :
'';
html += `<tr class="${rowClass}">
<td>${logoHtml}</td>
<td>${item.Studio || 'Unbekannt'}</td>
<td>${item.IsStreamingService ? 'Streaming' : 'Traditional'}</td>
<td>${item.Count || 0}</td>
</tr>`;
}
html += '</tbody></table>';
table.innerHTML = html;
setStatus(`${data.length} Studios angezeigt (${raw.length} total)`);
} catch (e) {
console.error('Apply error:', e);
table.innerHTML = 'Fehler beim Anzeigen: ' + (e.message || e);
setStatus('Anzeigefehler');
}
}
async function load() {
try {
setStatus('Lade…');
table.textContent = 'Lade Daten…';
// First, test if the API is working at all
try {
const testUrl = ApiClient.getUrl('StudioDashboard/Test');
const testResult = await ApiClient.getJSON(testUrl);
console.log('StudioDashboard API Test:', testResult);
} catch (testError) {
console.error('StudioDashboard API Test failed:', testError);
table.innerHTML = 'API Test Fehler: ' + (testError.message || testError);
setStatus('API nicht erreichbar');
return;
}
const url = ApiClient.getUrl('StudioDashboard/StudiosWithLogos');
console.log('Calling StudioDashboard API:', url);
raw = await ApiClient.getJSON(url);
console.log('Received data:', raw);
apply();
} catch (e) {
console.error('Load error:', e);
table.innerHTML = 'Fehler beim Laden: ' + (e && e.message ? e.message : e);
setStatus('Fehler');
}
}
function exportToJson() {
const data = getCurrentFilteredData();
const json = JSON.stringify(data, null, 2);
const blob = new Blob([json], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'studios.json';
a.click();
URL.revokeObjectURL(url);
}
function exportToCsv() {
const data = getCurrentFilteredData();
let csv = 'Studio,Typ,Anzahl,LogoURL\n';
for (const item of data) {
const studio = (item.Studio || '').replace(/"/g, '""');
const typ = item.IsStreamingService ? 'Streaming' : 'Traditional';
const anzahl = item.Count || 0;
const logoUrl = (item.LogoUrl || '').replace(/"/g, '""');
csv += `"${studio}","${typ}","${anzahl}","${logoUrl}"\n`;
}
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'studios.csv';
a.click();
URL.revokeObjectURL(url);
}
async function saveToServer(format) {
try {
const data = getCurrentFilteredData();
const payload = format === 'json' ? JSON.stringify(data, null, 2) : null;
// Note: This would require a corresponding API endpoint
setStatus(`${format.toUpperCase()} Speichern nicht implementiert`);
} catch (e) {
console.error('Save error:', e);
setStatus('Speicherfehler');
}
}
async function syncCollections() {
try {
setStatus('Synchronisiere Sammlungen...');
const url = ApiClient.getUrl('StudioDashboard/SyncCollections');
console.log('Syncing collections:', url);
const result = await ApiClient.getJSON(url);
console.log('Sync result:', result);
setStatus('Sammlungen synchronisiert: ' + (result.message || 'OK'));
} catch (e) {
console.error('Sync error:', e);
setStatus('Synchronisierungsfehler: ' + (e.message || e));
}
}
// Event listeners
search.addEventListener('input', apply);
sortEl.addEventListener('change', apply);
topEl.addEventListener('change', apply);
filterEl.addEventListener('change', apply);
reload.addEventListener('click', load);
syncBtn.addEventListener('click', syncCollections);
btnExportJson.addEventListener('click', exportToJson);
btnExportCsv.addEventListener('click', exportToCsv);
btnSaveJson.addEventListener('click', () => saveToServer('json'));
btnSaveCsv.addEventListener('click', () => saveToServer('csv'));
// Initialize
load();
})();
</script>
</body>
</html>