-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard_broken.html
More file actions
256 lines (218 loc) · 9.9 KB
/
dashboard_broken.html
File metadata and controls
256 lines (218 loc) · 9.9 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
<!-- Emby plugin configuration page (fragment) -->
<div data-role="page" class="type-interior pluginConfigurationPage" id="studioDashboardPage">
<div data-role="content">
<h2>🎬 Studio Dashboard - Streaming Services</h2>
<div class="inputContainer">
<h3>Plugin-Einstellungen</h3>
<div class="fieldDescription">
Konfigurieren Sie die Anzeige der Streaming Services auf der Emby-Startseite.
</div>
</div>
<div class="inputContainer">
<button is="emby-button" type="button" id="syncCollections" class="raised button-submit">
🔄 Studio-Collections synchronisieren
</button>
<div class="fieldDescription">
Erstellt/aktualisiert automatisch Collections für alle Studios, damit sie auf der Startseite erscheinen.
</div>
</div>
<div class="inputContainer">
<input is="emby-input" id="search" type="text" label="Suche Studio…" />
</div>
<div class="inputContainer">
<select is="emby-select" id="sort" label="Sortieren">
<option value="count_desc" selected>Anzahl ↓</option>
<option value="count_asc">Anzahl ↑</option>
<option value="name_asc">Name A–Z</option>
<option value="name_desc">Name Z–A</option>
</select>
</div>
<div class="inputContainer">
<select is="emby-select" id="topn" label="Top">
<option value="0" selected>Alle</option>
<option value="10">Top 10</option>
<option value="20">Top 20</option>
<option value="50">Top 50</option>
</select>
</div>
<div class="inputContainer">
<select is="emby-select" id="filterType" label="Filter">
<option value="all" selected>Alle Studios</option>
<option value="streaming">Nur Streaming-Dienste</option>
<option value="traditional">Traditionelle Studios</option>
</select>
</div>
<div class="inputContainer">
<button is="emby-button" type="button" id="reload" class="raised button-submit">Neu laden</button>
</div>
<div class="inputContainer">
<button is="emby-button" type="button" id="exportJson" class="raised">Export JSON (Download)</button>
<button is="emby-button" type="button" id="exportCsv" class="raised">Export CSV (Download)</button>
</div>
<div class="inputContainer">
<button is="emby-button" type="button" id="saveJson" class="raised">Auf Server speichern (JSON)</button>
<button is="emby-button" type="button" id="saveCsv" class="raised">Auf Server speichern (CSV)</button>
</div>
<div class="fieldDescription" id="status">Bereit</div>
<div class="verticalSection">
<div class="sectionTitle">Streaming Studios</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 = [];
let currentSort = \'count_desc\';
function setStatus(msg){ status.textContent = msg || \'\'; }
function sortData(arr, key) {
const data = arr.slice();
switch (key) {
case \'count_desc\': data.sort((a,b) => (b.Count - a.Count) || a.Studio.localeCompare(b.Studio)); break;
case \'count_asc\': data.sort((a,b) => (a.Count - b.Count) || a.Studio.localeCompare(b.Studio)); break;
case \'name_asc\': data.sort((a,b) => a.Studio.localeCompare(b.Studio)); break;
case \'name_desc\': data.sort((a,b) => b.Studio.localeCompare(a.Studio)); break;
}
return data;
}
function render(arr) {
if (!Array.isArray(arr) || arr.length === 0) {
table.innerHTML = \'<div class="fieldDescription">Keine Studios gefunden.</div>\';
return;
}
let html = \'<table class="detailTable"><thead><tr><th data-k="name">Studio</th><th data-k="count">Anzahl</th><th data-k="type">Typ</th><th data-k="logo">Logo</th></tr></thead><tbody>\';
arr.forEach(s => {
const typeIcon = s.IsStreamingService ? \'📺\' : \'🎬\';
const typeText = s.IsStreamingService ? \'Streaming\' : \'Traditional\';
const logoIndicator = s.LogoUrl ? \'✅\' : \'❌\';
html += `<tr>
<td><strong>${s.Studio}</strong></td>
<td>${s.Count}</td>
<td>${typeIcon} ${typeText}</td>
<td>${logoIndicator}</td>
</tr>`;
});
html += \'</tbody></table>\';
table.innerHTML = html;
const thName = table.querySelector(\'th[data-k="name"]\');
const thCount = table.querySelector(\'th[data-k="count"]\');
thName.addEventListener(\'click\', () => { sortEl.value = (currentSort === \'name_asc\' ? \'name_desc\' : \'name_asc\'); apply(); });
thCount.addEventListener(\'click\', () => { sortEl.value = (currentSort === \'count_desc\' ? \'count_asc\' : \'count_desc\'); apply(); });
}
function apply() {
const q = (search.value || \'\').trim().toLowerCase();
const filter = filterEl.value || \'all\';
currentSort = sortEl.value;
const top = parseInt(topEl.value || \'0\', 10);
let filtered = raw.filter(x => {
if (q && (!x.Studio || !x.Studio.toLowerCase().includes(q))) return false;
if (filter === \'streaming\' && !x.IsStreamingService) return false;
if (filter === \'traditional\' && x.IsStreamingService) return false;
return true;
});
filtered = sortData(filtered, currentSort);
const view = top > 0 ? filtered.slice(0, top) : filtered;
render(view);
const streamingCount = filtered.filter(x => x.IsStreamingService).length;
const traditionalCount = filtered.filter(x => !x.IsStreamingService).length;
setStatus(`${filtered.length} Studios (${streamingCount} Streaming, ${traditionalCount} Traditional)`);
}
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');
}
}
async function syncCollections() {
try {
setStatus(\'Synchronisiere Collections…\');
syncBtn.disabled = true;
syncBtn.textContent = \'⏳ Synchronisiere…\';
const url = ApiClient.getUrl(\'StudioDashboard/SyncCollections\');
const result = await ApiClient.ajax({ url, type: \'POST\' });
setStatus(\'Collections synchronisiert! Die Studios sollten jetzt auf der Startseite erscheinen.\');
} catch (e) {
setStatus(\'Fehler beim Synchronisieren: \' + (e && e.message ? e.message : e));
} finally {
syncBtn.disabled = false;
syncBtn.textContent = \'🔄 Studio-Collections synchronisieren\';
}
}
function download(filename, mimetype, content) {
const blob = new Blob([content], { type: mimetype });
const a = document.createElement(\'a\');
a.href = URL.createObjectURL(blob);
a.download = filename;
a.click();
setTimeout(() => URL.revokeObjectURL(a.href), 2000);
}
btnExportJson.addEventListener(\'click\', async () => {
const url = ApiClient.getUrl(\'StudioDashboard/ExportJson\');
const data = await ApiClient.getJSON(url);
download(`studios-${new Date().toISOString().slice(0,19).replace(/[:T]/g,\'\')}.json`, \'application/json\', JSON.stringify(data, null, 2));
});
btnExportCsv.addEventListener(\'click\', async () => {
const url = ApiClient.getUrl(\'StudioDashboard/ExportCsv\');
const csv = await ApiClient.ajax({ url, type: \'GET\', dataType: \'text\' });
download(`studios-${new Date().toISOString().slice(0,19).replace(/[:T]/g,\'\')}.csv`, \'text/csv\', csv);
});
btnSaveJson.addEventListener(\'click\', async () => {
try {
const url = ApiClient.getUrl(\'StudioDashboard/SaveExport\', { Format: \'json\' });
const res = await ApiClient.ajax({ url, type: \'POST\' });
setStatus(res && res.Path ? (\'Gespeichert: \' + res.Path) : \'Gespeichert.\');
} catch (e) {
setStatus(\'Fehler beim Speichern (JSON)\');
}
});
btnSaveCsv.addEventListener(\'click\', async () => {
try {
const url = ApiClient.getUrl(\'StudioDashboard/SaveExport\', { Format: \'csv\' });
const res = await ApiClient.ajax({ url, type: \'POST\' });
setStatus(res && res.Path ? (\'Gespeichert: \' + res.Path) : \'Gespeichert.\');
} catch (e) {
setStatus(\'Fehler beim Speichern (CSV)\');
}
});
page.addEventListener(\'viewshow\', load);
search.addEventListener(\'input\', apply);
sortEl.addEventListener('change', apply);
topEl.addEventListener('change', apply);
filterEl.addEventListener('change', apply);
reload.addEventListener('click', load);
syncBtn.addEventListener('click', syncCollections);
})();
</script>