-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
599 lines (548 loc) · 25.7 KB
/
Copy pathadmin.html
File metadata and controls
599 lines (548 loc) · 25.7 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<!DOCTYPE html>
<html lang="en-IE">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - PressWire.ie</title>
<meta name="robots" content="noindex, nofollow">
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<style>
* { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
</style>
</head>
<body class="bg-gray-50">
<!-- Navigation -->
<nav class="bg-white border-b">
<div class="max-w-7xl mx-auto px-6">
<div class="flex items-center justify-between h-16">
<div class="flex items-center space-x-3">
<div class="w-8 h-8 bg-red-600 rounded flex items-center justify-center">
<span class="text-white font-bold text-sm">A</span>
</div>
<div>
<div class="font-semibold text-sm">Admin Panel</div>
<div class="text-xs text-gray-500">PressWire.ie Management</div>
</div>
</div>
<button onclick="logout()" class="text-sm text-red-600 hover:text-red-800">Logout</button>
</div>
</div>
</nav>
<!-- Login Form (shown when not authenticated) -->
<div id="loginForm" class="min-h-screen flex items-center justify-center px-6">
<div class="max-w-md w-full">
<div class="bg-white rounded-lg shadow-sm border p-8">
<h1 class="text-2xl font-bold mb-6">Admin Login</h1>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium mb-2">Admin Token</label>
<input type="password" id="adminToken"
class="w-full p-3 border rounded-md focus:ring-2 focus:ring-red-500 focus:border-red-500"
placeholder="Enter admin token">
</div>
<button onclick="login()"
class="w-full bg-red-600 text-white py-3 rounded-md font-medium hover:bg-red-700">
Login
</button>
</div>
</div>
</div>
</div>
<!-- Admin Dashboard (hidden initially) -->
<div id="adminDashboard" class="hidden">
<div class="max-w-7xl mx-auto px-6 py-8">
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
<div class="bg-white rounded-lg shadow-sm border p-6">
<div class="text-sm text-gray-500 mb-2">Total Tokens</div>
<div class="text-2xl font-bold" id="statTotalTokens">0</div>
</div>
<div class="bg-white rounded-lg shadow-sm border p-6">
<div class="text-sm text-gray-500 mb-2">Active Tokens</div>
<div class="text-2xl font-bold text-green-600" id="statActiveTokens">0</div>
</div>
<div class="bg-white rounded-lg shadow-sm border p-6">
<div class="text-sm text-gray-500 mb-2">Used Tokens</div>
<div class="text-2xl font-bold text-blue-600" id="statUsedTokens">0</div>
</div>
<div class="bg-white rounded-lg shadow-sm border p-6">
<div class="text-sm text-gray-500 mb-2">Total Discount Value</div>
<div class="text-2xl font-bold text-purple-600" id="statDiscountValue">€0</div>
</div>
</div>
<!-- Tabs -->
<div class="bg-white rounded-lg shadow-sm border">
<div class="border-b">
<nav class="flex">
<button onclick="showTab('generate')" id="tabGenerate"
class="px-6 py-4 text-sm font-medium border-b-2 border-red-600 text-red-600">
Generate Tokens
</button>
<button onclick="showTab('list')" id="tabList"
class="px-6 py-4 text-sm font-medium text-gray-600 hover:text-black">
Active Tokens
</button>
<button onclick="showTab('pr')" id="tabPR"
class="px-6 py-4 text-sm font-medium text-gray-600 hover:text-black">
Free PR Generation
</button>
<button onclick="showTab('manage')" id="tabManage"
class="px-6 py-4 text-sm font-medium text-gray-600 hover:text-black">
Manage All PRs
</button>
</nav>
</div>
<!-- Generate Token Tab -->
<div id="generateTab" class="p-6">
<h2 class="text-xl font-bold mb-6">Generate Discount Token</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-medium mb-2">Discount Percentage</label>
<select id="discountPercent" class="w-full p-3 border rounded-md">
<option value="10">10% off</option>
<option value="25">25% off</option>
<option value="50">50% off</option>
<option value="100">100% off (Free)</option>
</select>
</div>
<div>
<label class="block text-sm font-medium mb-2">Valid Days</label>
<input type="number" id="validDays" value="30" min="1" max="365"
class="w-full p-3 border rounded-md">
</div>
<div>
<label class="block text-sm font-medium mb-2">Max Uses</label>
<input type="number" id="maxUses" value="1" min="1" max="100"
class="w-full p-3 border rounded-md">
</div>
<div>
<label class="block text-sm font-medium mb-2">Description (optional)</label>
<input type="text" id="description" placeholder="e.g., Launch promotion"
class="w-full p-3 border rounded-md">
</div>
</div>
<button onclick="generateToken()"
class="mt-6 bg-red-600 text-white px-6 py-3 rounded-md font-medium hover:bg-red-700">
Generate Token
</button>
<div id="generatedToken" class="hidden mt-6 p-4 bg-green-50 border border-green-200 rounded-lg">
<div class="font-semibold text-green-800 mb-2">Token Generated Successfully!</div>
<div class="text-2xl font-mono" id="tokenCode"></div>
<button onclick="copyToken()" class="mt-2 text-sm text-green-600 hover:text-green-800">
Copy to clipboard
</button>
</div>
</div>
<!-- List Tokens Tab -->
<div id="listTab" class="hidden p-6">
<h2 class="text-xl font-bold mb-6">Active Discount Tokens</h2>
<div class="overflow-x-auto">
<table class="w-full">
<thead>
<tr class="border-b">
<th class="text-left py-3 px-4">Code</th>
<th class="text-left py-3 px-4">Discount</th>
<th class="text-left py-3 px-4">Used/Max</th>
<th class="text-left py-3 px-4">Expires</th>
<th class="text-left py-3 px-4">Description</th>
<th class="text-left py-3 px-4">Action</th>
</tr>
</thead>
<tbody id="tokensList">
<tr>
<td colspan="6" class="text-center py-8 text-gray-500">Loading...</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Free PR Tab -->
<div id="prTab" class="hidden p-6">
<h2 class="text-xl font-bold mb-6">Generate Free Press Release</h2>
<p class="text-gray-600 mb-6">
Generate a press release without payment for testing or special clients.
</p>
<button onclick="generateAdminPRToken()"
class="bg-black text-white px-6 py-3 rounded-md font-medium hover:bg-gray-900">
Generate Admin PR Token
</button>
<div id="adminPRToken" class="hidden mt-6 p-4 bg-blue-50 border border-blue-200 rounded-lg">
<div class="font-semibold text-blue-800 mb-2">Admin PR Token Generated!</div>
<div class="text-sm font-mono mb-4" id="prTokenValue"></div>
<p class="text-sm text-blue-600">
Use this token in the Authorization header when calling the PR generation API.
Valid for 1 hour, single use only.
</p>
<button onclick="copyPRToken()" class="mt-2 text-sm text-blue-600 hover:text-blue-800">
Copy token
</button>
<a href="/generate.html?admin=true" target="_blank"
class="ml-4 text-sm text-blue-600 hover:text-blue-800">
Open PR Generator →
</a>
</div>
</div>
<!-- Manage PRs Tab -->
<div id="manageTab" class="hidden p-6">
<h2 class="text-xl font-bold mb-6">Manage All Press Releases</h2>
<div class="mb-6">
<button onclick="loadAllPRs()"
class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700">
Refresh PR List
</button>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead>
<tr class="border-b bg-gray-50">
<th class="text-left py-3 px-4">Company</th>
<th class="text-left py-3 px-4">Headline</th>
<th class="text-left py-3 px-4">Published</th>
<th class="text-left py-3 px-4">Views</th>
<th class="text-left py-3 px-4">Status</th>
<th class="text-left py-3 px-4">Actions</th>
</tr>
</thead>
<tbody id="prsList">
<tr>
<td colspan="6" class="text-center py-8 text-gray-500">
Click "Refresh PR List" to load press releases
</td>
</tr>
</tbody>
</table>
</div>
<!-- PR Details Modal -->
<div id="prModal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div class="bg-white rounded-lg p-6 max-w-2xl w-full max-h-[80vh] overflow-y-auto">
<div class="flex justify-between items-start mb-4">
<h3 class="text-xl font-bold">PR Details</h3>
<button onclick="closePRModal()" class="text-gray-500 hover:text-black">✕</button>
</div>
<div id="prModalContent">
<!-- PR details will be loaded here -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Admin token from localStorage
let adminToken = localStorage.getItem('adminToken');
// Check authentication on load
window.onload = function() {
if (adminToken) {
showDashboard();
loadStats();
}
};
function login() {
const token = document.getElementById('adminToken').value;
if (!token) {
alert('Please enter admin token');
return;
}
// Store token and verify it works
adminToken = token;
// Test the token
fetch('/api/admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ action: 'get-stats' })
})
.then(response => {
if (!response.ok) throw new Error('Invalid token');
return response.json();
})
.then(data => {
localStorage.setItem('adminToken', token);
showDashboard();
loadStats();
})
.catch(error => {
alert('Invalid admin token');
adminToken = null;
});
}
function logout() {
localStorage.removeItem('adminToken');
adminToken = null;
document.getElementById('loginForm').classList.remove('hidden');
document.getElementById('adminDashboard').classList.add('hidden');
}
function showDashboard() {
document.getElementById('loginForm').classList.add('hidden');
document.getElementById('adminDashboard').classList.remove('hidden');
}
function showTab(tab) {
// Hide all tabs
document.getElementById('generateTab').classList.add('hidden');
document.getElementById('listTab').classList.add('hidden');
document.getElementById('prTab').classList.add('hidden');
document.getElementById('manageTab').classList.add('hidden');
// Remove active class from all tab buttons
document.querySelectorAll('[id^="tab"]').forEach(btn => {
btn.classList.remove('border-b-2', 'border-red-600', 'text-red-600');
btn.classList.add('text-gray-600');
});
// Show selected tab
document.getElementById(tab + 'Tab').classList.remove('hidden');
// Mark tab button as active
const tabBtn = document.getElementById('tab' + tab.charAt(0).toUpperCase() + tab.slice(1));
tabBtn.classList.add('border-b-2', 'border-red-600', 'text-red-600');
tabBtn.classList.remove('text-gray-600');
// Load data for the tab
if (tab === 'list') {
loadTokens();
} else if (tab === 'manage') {
loadAllPRs();
}
}
function loadStats() {
fetch('/api/admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({ action: 'get-stats' })
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('statTotalTokens').textContent = data.stats.totalTokensCreated;
document.getElementById('statActiveTokens').textContent = data.stats.activeTokens;
document.getElementById('statUsedTokens').textContent = data.stats.usedTokens;
document.getElementById('statDiscountValue').textContent = data.stats.totalDiscountValue;
}
});
}
function generateToken() {
const data = {
discountPercent: parseInt(document.getElementById('discountPercent').value),
validDays: parseInt(document.getElementById('validDays').value),
maxUses: parseInt(document.getElementById('maxUses').value),
description: document.getElementById('description').value
};
fetch('/api/admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({ action: 'generate-discount', data })
})
.then(response => response.json())
.then(result => {
if (result.success) {
document.getElementById('tokenCode').textContent = result.token.code;
document.getElementById('generatedToken').classList.remove('hidden');
loadStats();
} else {
alert('Error: ' + result.error);
}
});
}
function copyToken() {
const code = document.getElementById('tokenCode').textContent;
navigator.clipboard.writeText(code);
alert('Token copied to clipboard!');
}
function loadTokens() {
fetch('/api/admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({ action: 'list-tokens' })
})
.then(response => response.json())
.then(data => {
if (data.success) {
const tbody = document.getElementById('tokensList');
if (data.tokens.length === 0) {
tbody.innerHTML = '<tr><td colspan="6" class="text-center py-8 text-gray-500">No active tokens</td></tr>';
return;
}
tbody.innerHTML = data.tokens.map(token => `
<tr class="border-b">
<td class="py-3 px-4 font-mono">${token.code}</td>
<td class="py-3 px-4">${token.discountPercent}%</td>
<td class="py-3 px-4">${token.usedCount}/${token.maxUses}</td>
<td class="py-3 px-4">${new Date(token.expiresAt).toLocaleDateString()}</td>
<td class="py-3 px-4">${token.description || '-'}</td>
<td class="py-3 px-4">
<button onclick="revokeToken('${token.code}')"
class="text-red-600 hover:text-red-800 text-sm">
Revoke
</button>
</td>
</tr>
`).join('');
}
});
}
function revokeToken(code) {
if (!confirm(`Revoke token ${code}?`)) return;
fetch('/api/admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({ action: 'revoke-token', data: { code } })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Token revoked');
loadTokens();
loadStats();
}
});
}
function generateAdminPRToken() {
fetch('/api/admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({ action: 'generate-admin-pr-token' })
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('prTokenValue').textContent = data.token;
document.getElementById('adminPRToken').classList.remove('hidden');
// Store token for PR generator
sessionStorage.setItem('adminPRToken', data.token);
}
});
}
function copyPRToken() {
const token = document.getElementById('prTokenValue').textContent;
navigator.clipboard.writeText(token);
alert('PR token copied to clipboard!');
}
// PR Management Functions
async function loadAllPRs() {
try {
// Get analytics summary
const response = await fetch('/api/analytics', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'get-summary' })
});
const data = await response.json();
if (data.success) {
displayPRList(data.summary);
}
} catch (error) {
console.error('Failed to load PRs:', error);
// For demo, show sample data
displayPRList({
topPRs: [
{ slug: 'demo-pr-1', views: 156, uniqueVisitors: 89, lastView: new Date().toISOString() },
{ slug: 'demo-pr-2', views: 234, uniqueVisitors: 145, lastView: new Date().toISOString() }
]
});
}
}
function displayPRList(summary) {
const tbody = document.getElementById('prsList');
const prs = summary.topPRs || [];
if (prs.length === 0) {
tbody.innerHTML = '<tr><td colspan="6" class="text-center py-8 text-gray-500">No press releases found</td></tr>';
return;
}
tbody.innerHTML = prs.map(pr => {
const company = pr.slug.split('-')[0] || 'Unknown';
const date = pr.lastView ? new Date(pr.lastView).toLocaleDateString() : 'N/A';
return `
<tr class="border-b hover:bg-gray-50">
<td class="py-3 px-4">${company}</td>
<td class="py-3 px-4">
<div class="max-w-xs truncate">${pr.slug}</div>
</td>
<td class="py-3 px-4">${date}</td>
<td class="py-3 px-4">${pr.views || 0}</td>
<td class="py-3 px-4">
<span class="px-2 py-1 bg-green-100 text-green-800 text-xs rounded">Published</span>
</td>
<td class="py-3 px-4">
<button onclick="viewPRDetails('${pr.slug}')"
class="text-blue-600 hover:text-blue-800 text-sm mr-2">
View
</button>
<button onclick="editPRAsAdmin('${pr.slug}')"
class="text-green-600 hover:text-green-800 text-sm mr-2">
Edit
</button>
<button onclick="unpublishPR('${pr.slug}')"
class="text-red-600 hover:text-red-800 text-sm">
Unpublish
</button>
</td>
</tr>
`;
}).join('');
}
function viewPRDetails(slug) {
// Show modal with PR details
const modal = document.getElementById('prModal');
const content = document.getElementById('prModalContent');
content.innerHTML = `
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700">Slug</label>
<p class="mt-1">${slug}</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">URL</label>
<a href="https://presswire.ie/news/${slug}.html" target="_blank"
class="text-blue-600 hover:text-blue-800">
https://presswire.ie/news/${slug}.html
</a>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Management Link</label>
<p class="text-sm text-gray-600">Contact support for management link recovery</p>
</div>
<div class="flex gap-2">
<button onclick="window.open('https://presswire.ie/news/${slug}.html', '_blank')"
class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">
View PR
</button>
<button onclick="closePRModal()"
class="border px-4 py-2 rounded hover:bg-gray-50">
Close
</button>
</div>
</div>
`;
modal.classList.remove('hidden');
}
function closePRModal() {
document.getElementById('prModal').classList.add('hidden');
}
function editPRAsAdmin(slug) {
// Generate admin token and redirect to management page
generateAdminPRToken();
alert(`Admin editing for ${slug} - use the generated token to access management page`);
}
function unpublishPR(slug) {
if (!confirm(`Are you sure you want to unpublish ${slug}?`)) return;
alert(`To unpublish ${slug}, use the management dashboard with admin token.`);
// In production, this would call the manage-pr API with admin privileges
}
</script>
</body>
</html>