-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin.html
More file actions
173 lines (146 loc) · 5.12 KB
/
Copy pathadmin.html
File metadata and controls
173 lines (146 loc) · 5.12 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
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.button-container {
margin: 20px 0;
}
button {
padding: 10px 20px;
margin-right: 10px;
cursor: pointer;
}
.danger {
background-color: #ff4444;
color: white;
border: none;
}
.export {
background-color: #4CAF50;
color: white;
border: none;
}
</style>
</head>
<body>
<h1>Admin Panel</h1>
<div class="button-container">
<button class="danger" id="resetBtn">Reset All Numbers</button>
<button class="export" id="exportBtn">Export to CSV</button>
</div>
<table id="numberTable">
<thead>
<tr>
<th>Number</th>
<th>Name</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.2.0/firebase-app.js";
import { getFirestore, doc, getDoc, setDoc } from "https://www.gstatic.com/firebasejs/11.2.0/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyBSvYwZ5VQ5r42zEXx8aLACkln8HVgjqQE",
authDomain: "yep2025-3f1d9.firebaseapp.com",
projectId: "yep2025-3f1d9",
storageBucket: "yep2025-3f1d9.firebasestorage.app",
messagingSenderId: "482933449467",
appId: "1:482933449467:web:d63d2949359905e13b465e"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
// Update table function
async function updateTable() {
const docRef = doc(db, "default", "numbers");
const docSnap = await getDoc(docRef);
const tbody = document.querySelector('#numberTable tbody');
tbody.innerHTML = '';
if (docSnap.exists()) {
const data = docSnap.data();
const pickedNumbers = data.pickedNumber || {};
Object.entries(pickedNumbers).sort((a, b) => Number(a[0]) - Number(b[0])).forEach(([number, name]) => {
const row = tbody.insertRow();
row.insertCell(0).textContent = number;
row.insertCell(1).textContent = name;
});
}
}
// Reset numbers function
async function resetNumbers() {
if (confirm('Are you sure you want to reset all numbers? This action cannot be undone.')) {
try {
const numbers = Array.from({ length: 99 }, (_, i) => i + 1);
await setDoc(doc(db, "default", "numbers"), {
availableNumbers: numbers,
pickedNumber: {}
});
alert('Numbers reset successfully');
updateTable();
} catch (error) {
alert('Error resetting numbers: ' + error.message);
}
}
}
function exportToCSV() {
const table = document.getElementById('numberTable');
let csv = [];
// Add UTF-8 BOM
const BOM = '\uFEFF';
// Add header
const header = ['Number', 'Name'];
csv.push(header.join(','));
// Add rows
const rows = table.querySelectorAll('tbody tr');
rows.forEach(row => {
const rowData = [];
row.querySelectorAll('td').forEach(cell => {
rowData.push('"' + cell.textContent.replace(/"/g, '""') + '"');
});
csv.push(rowData.join(','));
});
// Create CSV content with BOM
const csvContent = BOM + csv.join('\n');
// Create blob with UTF-8 encoding
const blob = new Blob([csvContent], {
type: 'text/csv;charset=utf-8-sig;'
});
// Download
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
link.setAttribute('href', url);
link.setAttribute('download', 'picked_numbers.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
}
// Event listeners
document.getElementById('resetBtn').addEventListener('click', resetNumbers);
document.getElementById('exportBtn').addEventListener('click', exportToCSV);
// Initial load
updateTable();
// Refresh table every 30 seconds
setInterval(updateTable, 30000);
</script>
</body>
</html>