taarhissian commited on
Commit
d0d482a
·
verified ·
1 Parent(s): 8c9013b

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +5 -10
  2. index.html +281 -0
README.md CHANGED
@@ -1,13 +1,8 @@
1
  ---
2
- title: Prfcadmin
3
- emoji: 🏢
4
- colorFrom: green
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 6.28.0
8
- python_version: '3.13'
9
- app_file: app.py
10
  pinned: false
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Parkside Rollers Admin
3
+ emoji: ⚽
4
+ colorFrom: red
5
+ colorTo: gray
6
+ sdk: static
 
 
 
7
  pinned: false
8
  ---
 
 
index.html ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Park Side Rollers — Admin</title>
7
+ <style>
8
+ :root{
9
+ --bg:#0f1720; --panel:#16202b; --panel2:#1c2733; --text:#e8edf2; --muted:#8c9aab;
10
+ --accent:#e6472a; --border:#2a3644; --ok:#3ecf8e;
11
+ }
12
+ *{box-sizing:border-box}
13
+ html,body{margin:0;height:100%}
14
+ body{background:var(--bg);color:var(--text);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;}
15
+ header{display:flex;align-items:center;justify-content:space-between;padding:14px 20px;background:var(--panel);border-bottom:1px solid var(--border);position:sticky;top:0;z-index:5}
16
+ header h1{font-size:16px;margin:0;letter-spacing:.02em}
17
+ header h1 span{color:var(--accent)}
18
+ #status{font-size:12px;color:var(--muted)}
19
+ #logoutBtn{background:none;border:1px solid var(--border);color:var(--muted);padding:6px 12px;border-radius:6px;cursor:pointer;font-size:12px}
20
+ #logoutBtn:hover{color:var(--text);border-color:var(--muted)}
21
+ .layout{display:flex;min-height:calc(100vh - 53px)}
22
+ nav{width:190px;flex:none;background:var(--panel);border-right:1px solid var(--border);padding:14px 0}
23
+ nav button{display:block;width:100%;text-align:left;background:none;border:none;color:var(--muted);padding:10px 20px;font-size:14px;cursor:pointer}
24
+ nav button:hover{color:var(--text);background:var(--panel2)}
25
+ nav button.active{color:var(--accent);background:var(--panel2);border-left:3px solid var(--accent)}
26
+ main{flex:1;padding:24px;max-width:900px}
27
+ .card{background:var(--panel);border:1px solid var(--border);border-radius:10px;padding:20px;margin-bottom:16px}
28
+ .card h2{margin:0 0 4px;font-size:18px}
29
+ .muted{color:var(--muted);font-size:13px}
30
+ input,textarea{width:100%;background:var(--panel2);border:1px solid var(--border);color:var(--text);padding:9px 10px;border-radius:6px;font-size:14px;margin-top:4px;font-family:inherit}
31
+ textarea{min-height:110px;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12.5px}
32
+ label{font-size:12px;color:var(--muted);display:block;margin-top:10px}
33
+ button.primary{background:var(--accent);color:#fff;border:none;padding:9px 16px;border-radius:6px;cursor:pointer;font-size:14px;margin-top:14px}
34
+ button.primary:hover{opacity:.9}
35
+ button.secondary{background:none;border:1px solid var(--border);color:var(--text);padding:9px 16px;border-radius:6px;cursor:pointer;font-size:14px;margin-top:14px;margin-left:8px}
36
+ .item{background:var(--panel2);border:1px solid var(--border);border-radius:8px;padding:12px 14px;margin-bottom:10px}
37
+ .item pre{white-space:pre-wrap;word-break:break-all;margin:0 0 8px;font-size:12.5px;color:var(--text)}
38
+ .item .row{display:flex;gap:8px}
39
+ .item button{font-size:12px;padding:5px 10px;border-radius:5px;border:1px solid var(--border);background:var(--panel);color:var(--muted);cursor:pointer}
40
+ .item button:hover{color:var(--text)}
41
+ .item button.danger:hover{color:#ff6b5b;border-color:#ff6b5b}
42
+ .error{color:#ff6b5b;font-size:13px;margin-top:8px}
43
+ .ok{color:var(--ok);font-size:13px;margin-top:8px}
44
+ #authScreen{max-width:420px;margin:60px auto;padding:0 20px}
45
+ .hidden{display:none !important}
46
+ </style>
47
+ </head>
48
+ <body>
49
+
50
+ <header>
51
+ <h1>Park Side Rollers <span>Admin</span></h1>
52
+ <div style="display:flex;align-items:center;gap:12px">
53
+ <span id="status" class="muted"></span>
54
+ <button id="logoutBtn" class="hidden">Sign out</button>
55
+ </div>
56
+ </header>
57
+
58
+ <div id="authScreen" class="hidden">
59
+ <div class="card">
60
+ <h2 id="authTitle">Sign in</h2>
61
+ <p class="muted" id="authSub">Enter admin credentials.</p>
62
+ <label>Email</label>
63
+ <input id="authEmail" type="email" placeholder="admin@parksiderollers.com">
64
+ <label>Username</label>
65
+ <input id="authUsername" type="text" placeholder="admin">
66
+ <label>Password</label>
67
+ <input id="authPassword" type="password" placeholder="••••••••">
68
+ <button class="primary" id="authSubmit">Continue</button>
69
+ <div id="authMsg"></div>
70
+ </div>
71
+ </div>
72
+
73
+ <div class="layout hidden" id="appLayout">
74
+ <nav id="nav"></nav>
75
+ <main id="main"></main>
76
+ </div>
77
+
78
+ <script>
79
+ const API = 'https://taarhissian-parkside-rollers-backend.hf.space';
80
+ let token = localStorage.getItem('psr_token') || '';
81
+
82
+ const SECTIONS = [
83
+ {key:'players', label:'Players', list:'/api/v1/players', create:'/api/v1/players', update:id=>'/api/v1/players/'+id, del:id=>'/api/v1/players/'+id},
84
+ {key:'teams', label:'Teams', list:'/api/v1/teams/', create:'/api/v1/teams/'},
85
+ {key:'coaches', label:'Coaches', list:'/api/v1/coaches/', create:'/api/v1/coaches/'},
86
+ {key:'matches', label:'Matches & Results', list:'/api/v1/matches/', create:'/api/v1/matches/'},
87
+ {key:'news', label:'News', list:'/api/v1/news/', create:'/api/v1/news/'},
88
+ {key:'announcements', label:'Announcements', list:'/api/v1/announcements/', create:'/api/v1/announcements/'},
89
+ {key:'coaching-resources', label:'Coaching Resources', list:'/api/v1/coaching-resources/', create:'/api/v1/coaching-resources/'},
90
+ ];
91
+
92
+ async function api(path, opts={}){
93
+ const headers = Object.assign({'Content-Type':'application/json'}, opts.headers||{});
94
+ if(token) headers['Authorization'] = 'Bearer '+token;
95
+ const res = await fetch(API+path, Object.assign({}, opts, {headers}));
96
+ let data=null; try{ data = await res.json(); }catch(e){}
97
+ if(!res.ok) throw new Error((data && (data.detail ? JSON.stringify(data.detail) : JSON.stringify(data))) || res.statusText);
98
+ return data;
99
+ }
100
+
101
+ function setToken(t){
102
+ token = t;
103
+ try{ localStorage.setItem('psr_token', t); }catch(e){}
104
+ }
105
+ function clearToken(){
106
+ token = '';
107
+ try{ localStorage.removeItem('psr_token'); }catch(e){}
108
+ }
109
+
110
+ const authScreen = document.getElementById('authScreen');
111
+ const appLayout = document.getElementById('appLayout');
112
+ const statusEl = document.getElementById('status');
113
+ const logoutBtn = document.getElementById('logoutBtn');
114
+
115
+ logoutBtn.onclick = () => { clearToken(); location.reload(); };
116
+
117
+ async function boot(){
118
+ if(token){
119
+ try{
120
+ const me = await api('/api/v1/auth/me');
121
+ statusEl.textContent = 'Signed in as ' + (me.username || me.email || 'admin');
122
+ logoutBtn.classList.remove('hidden');
123
+ showApp();
124
+ return;
125
+ }catch(e){ clearToken(); }
126
+ }
127
+ showAuth();
128
+ }
129
+
130
+ async function showAuth(){
131
+ authScreen.classList.remove('hidden');
132
+ appLayout.classList.add('hidden');
133
+ let setupNeeded = true;
134
+ try{
135
+ const check = await api('/api/v1/auth/check-setup');
136
+ setupNeeded = !!(check.setup_required ?? !check.admin_exists ?? true);
137
+ }catch(e){}
138
+
139
+ const title = document.getElementById('authTitle');
140
+ const sub = document.getElementById('authSub');
141
+ const userField = document.getElementById('authUsername');
142
+ const msg = document.getElementById('authMsg');
143
+
144
+ if(setupNeeded){
145
+ title.textContent = 'Create the admin account';
146
+ sub.textContent = 'This runs once. After this, the page signs you in automatically on this browser — no login screen.';
147
+ userField.parentElement.classList.remove('hidden');
148
+ } else {
149
+ title.textContent = 'Sign in';
150
+ sub.textContent = 'This browser doesn\'t have a saved session yet.';
151
+ userField.parentElement.classList.add('hidden');
152
+ }
153
+
154
+ document.getElementById('authSubmit').onclick = async () => {
155
+ msg.textContent = '';
156
+ const email = document.getElementById('authEmail').value.trim();
157
+ const username = userField.value.trim();
158
+ const password = document.getElementById('authPassword').value;
159
+ try{
160
+ let result;
161
+ if(setupNeeded){
162
+ result = await api('/api/v1/auth/setup-admin', {method:'POST', body: JSON.stringify({email, username, password})});
163
+ } else {
164
+ result = await api('/api/v1/auth/login', {method:'POST', body: JSON.stringify({email, password})});
165
+ }
166
+ setToken(result.access_token || result.token);
167
+ msg.innerHTML = '<div class="ok">Success — loading admin panel…</div>';
168
+ setTimeout(boot, 400);
169
+ }catch(e){
170
+ msg.innerHTML = '<div class="error">'+e.message+'</div>';
171
+ }
172
+ };
173
+ }
174
+
175
+ function showApp(){
176
+ authScreen.classList.add('hidden');
177
+ appLayout.classList.remove('hidden');
178
+ const nav = document.getElementById('nav');
179
+ nav.innerHTML = '';
180
+ SECTIONS.forEach((s, i) => {
181
+ const b = document.createElement('button');
182
+ b.textContent = s.label;
183
+ b.onclick = () => selectSection(s.key);
184
+ b.dataset.key = s.key;
185
+ nav.appendChild(b);
186
+ });
187
+ selectSection(SECTIONS[0].key);
188
+ }
189
+
190
+ async function selectSection(key){
191
+ document.querySelectorAll('#nav button').forEach(b => b.classList.toggle('active', b.dataset.key===key));
192
+ const section = SECTIONS.find(s=>s.key===key);
193
+ const main = document.getElementById('main');
194
+ main.innerHTML = '<div class="card"><h2>'+section.label+'</h2><p class="muted">Loading…</p></div>';
195
+
196
+ main.innerHTML = `
197
+ <div class="card">
198
+ <h2>${section.label}</h2>
199
+ <p class="muted">${section.update ? 'Add, edit, or delete items.' : 'View and add items (edit/delete not yet exposed by the API for this section).'}</p>
200
+ <button class="primary" id="addBtn">+ Add new</button>
201
+ <div id="formArea"></div>
202
+ </div>
203
+ <div id="listArea"></div>
204
+ `;
205
+ document.getElementById('addBtn').onclick = () => openForm(section, null);
206
+ await loadList(section);
207
+ }
208
+
209
+ async function loadList(section){
210
+ const listArea = document.getElementById('listArea');
211
+ try{
212
+ const items = await api(section.list);
213
+ if(!items || !items.length){
214
+ listArea.innerHTML = '<p class="muted">No items yet.</p>';
215
+ return;
216
+ }
217
+ listArea.innerHTML = items.map(it => {
218
+ const id = it.id || it._id || it.player_id;
219
+ return `<div class="item">
220
+ <pre>${escapeHtml(JSON.stringify(it, null, 2))}</pre>
221
+ <div class="row">
222
+ ${section.update ? `<button data-edit='${encodeURIComponent(JSON.stringify(it))}'>Edit</button>` : ''}
223
+ ${section.del && id ? `<button class="danger" data-del="${id}">Delete</button>` : ''}
224
+ </div>
225
+ </div>`;
226
+ }).join('');
227
+ listArea.querySelectorAll('[data-edit]').forEach(btn => {
228
+ btn.onclick = () => openForm(section, JSON.parse(decodeURIComponent(btn.dataset.edit)));
229
+ });
230
+ listArea.querySelectorAll('[data-del]').forEach(btn => {
231
+ btn.onclick = async () => {
232
+ if(!confirm('Delete this item?')) return;
233
+ try{ await api(section.del(btn.dataset.del), {method:'DELETE'}); loadList(section); }
234
+ catch(e){ alert('Delete failed: '+e.message); }
235
+ };
236
+ });
237
+ }catch(e){
238
+ listArea.innerHTML = '<p class="error">Failed to load: '+e.message+'</p>';
239
+ }
240
+ }
241
+
242
+ function openForm(section, existing){
243
+ const formArea = document.getElementById('formArea');
244
+ const id = existing ? (existing.id || existing._id || existing.player_id) : null;
245
+ formArea.innerHTML = `
246
+ <label>${existing ? 'Edit JSON' : 'New item — JSON body'}</label>
247
+ <textarea id="jsonBody">${escapeHtml(JSON.stringify(existing || {}, null, 2))}</textarea>
248
+ <div>
249
+ <button class="primary" id="saveBtn">${existing ? 'Save changes' : 'Create'}</button>
250
+ <button class="secondary" id="cancelBtn">Cancel</button>
251
+ </div>
252
+ <div id="formMsg"></div>
253
+ `;
254
+ document.getElementById('cancelBtn').onclick = () => { formArea.innerHTML=''; };
255
+ document.getElementById('saveBtn').onclick = async () => {
256
+ const msg = document.getElementById('formMsg');
257
+ let body;
258
+ try{ body = JSON.parse(document.getElementById('jsonBody').value); }
259
+ catch(e){ msg.innerHTML = '<div class="error">Invalid JSON</div>'; return; }
260
+ try{
261
+ if(existing && section.update){
262
+ await api(section.update(id), {method:'PUT', body: JSON.stringify(body)});
263
+ } else {
264
+ await api(section.create, {method:'POST', body: JSON.stringify(body)});
265
+ }
266
+ formArea.innerHTML = '';
267
+ loadList(section);
268
+ }catch(e){
269
+ msg.innerHTML = '<div class="error">'+e.message+'</div>';
270
+ }
271
+ };
272
+ }
273
+
274
+ function escapeHtml(s){
275
+ return s.replace(/[&<>]/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;'}[c]));
276
+ }
277
+
278
+ boot();
279
+ </script>
280
+ </body>
281
+ </html>