Spaces:
Running
Running
File size: 25,994 Bytes
750c8a3 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JobNest Admin</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
.glassmorphism {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.job-card:hover {
transform: translateY(-5px);
transition: all 0.3s ease;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
@media (max-width: 768px) {
.responsive-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body class="bg-gradient-to-br from-indigo-50 to-blue-100 min-h-screen">
<div id="app" class="container mx-auto px-4 py-8">
<!-- Login Section -->
<div id="loginSection" class="max-w-md mx-auto mt-10 glassmorphism rounded-xl p-6 shadow-lg">
<h2 class="text-2xl font-bold text-center text-indigo-800 mb-6">Admin Portal</h2>
<form id="loginForm" class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" id="email" required
class="w-full p-2 rounded-md border border-gray-300 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Password</label>
<input type="password" id="password" required
class="w-full p-2 rounded-md border border-gray-300 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
</div>
<button type="submit"
class="w-full py-2 px-4 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition">
Login
</button>
</form>
</div>
<!-- Admin Dashboard -->
<div id="dashboardSection" class="hidden">
<div class="flex flex-col md:flex-row justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-indigo-900">Dashboard</h1>
<button id="logoutBtn"
class="px-3 py-1.5 bg-red-500 text-white rounded-md hover:bg-red-600 transition flex items-center gap-1 mt-2 md:mt-0">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" />
</svg>
Logout
</button>
</div>
<!-- Stats Cards -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
<div class="glassmorphism rounded-lg p-4 text-center">
<h3 class="text-md font-medium text-indigo-800">Total Jobs</h3>
<p id="totalJobs" class="text-3xl font-bold text-indigo-600 mt-1">0</p>
</div>
<div class="glassmorphism rounded-lg p-4 text-center">
<h3 class="text-md font-medium text-indigo-800">Published</h3>
<p id="publishedJobs" class="text-3xl font-bold text-indigo-600 mt-1">0</p>
</div>
<div class="glassmorphism rounded-lg p-4 text-center">
<h3 class="text-md font-medium text-indigo-800">Drafts</h3>
<p id="draftJobs" class="text-3xl font-bold text-indigo-600 mt-1">0</p>
</div>
</div>
<!-- Banner Management -->
<div class="glassmorphism rounded-lg p-4 mb-6">
<h2 class="text-xl font-semibold text-indigo-800 mb-3">Banner Management</h2>
<div class="space-y-3">
<input type="text" id="bannerTitle" placeholder="Banner Title"
class="w-full p-2 rounded-md border border-gray-300">
<input type="url" id="bannerLink" placeholder="Banner Link (URL)"
class="w-full p-2 rounded-md border border-gray-300">
<input type="file" id="bannerImage" accept="image/*" class="w-full">
<button id="saveBannerBtn"
class="w-full py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition">
Save Banner
</button>
</div>
</div>
<!-- Category Management -->
<div class="glassmorphism rounded-lg p-4 mb-6">
<h2 class="text-xl font-semibold text-indigo-800 mb-3">Category Management</h2>
<div class="space-y-3">
<input type="text" id="categoryName" placeholder="Category Name"
class="w-full p-2 rounded-md border border-gray-300">
<input type="file" id="categoryImage" accept="image/*" class="w-full">
<button id="saveCategoryBtn"
class="w-full py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition">
Save Category
</button>
</div>
</div>
<!-- Job Management -->
<div class="glassmorphism rounded-lg p-4">
<h2 class="text-xl font-semibold text-indigo-800 mb-3">Job Management</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="space-y-3">
<input type="text" id="jobTitle" placeholder="Job Title"
class="w-full p-2 rounded-md border border-gray-300">
<select id="jobCategory" class="w-full p-2 rounded-md border border-gray-300">
<option value="" disabled selected>Select Category</option>
</select>
<textarea id="jobDescription" placeholder="Job Description"
class="w-full p-2 rounded-md border border-gray-300 h-32"></textarea>
<input type="url" id="jobLink" placeholder="Apply Link (URL)"
class="w-full p-2 rounded-md border border-gray-300">
<input type="file" id="jobImage" accept="image/*" class="w-full">
<div class="flex gap-2">
<button id="saveJobBtn"
class="flex-1 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition">
Publish Job
</button>
<button id="saveDraftBtn"
class="flex-1 py-2 bg-gray-500 text-white rounded-md hover:bg-gray-600 transition">
Save Draft
</button>
</div>
</div>
<div>
<div class="flex flex-col md:flex-row justify-between items-center mb-3">
<h3 class="text-lg font-medium text-indigo-800">All Jobs</h3>
<input type="text" id="jobSearch" placeholder="Search jobs..."
class="p-2 rounded-md border border-gray-300 w-full md:w-auto">
</div>
<div id="jobsList" class="space-y-3 max-h-96 overflow-y-auto pr-2"></div>
</div>
</div>
</div>
</div>
</div>
<script>
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDEXAMPLEEXAMPLEEXAMPLE",
authDomain: "your-project.firebaseapp.com",
databaseURL: "https://your-project.firebaseio.com",
projectId: "your-project",
storageBucket: "your-project.appspot.com",
messagingSenderId: "1234567890",
appId: "1:1234567890:web:abcdef1234567890"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
const database = firebase.database();
// DOM Elements
const loginSection = document.getElementById('loginSection');
const dashboardSection = document.getElementById('dashboardSection');
const loginForm = document.getElementById('loginForm');
const logoutBtn = document.getElementById('logoutBtn');
const jobCategorySelect = document.getElementById('jobCategory');
const jobsList = document.getElementById('jobsList');
const jobSearch = document.getElementById('jobSearch');
const totalJobsElement = document.getElementById('totalJobs');
const publishedJobsElement = document.getElementById('publishedJobs');
const draftJobsElement = document.getElementById('draftJobs');
// Login Functionality
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
auth.signInWithEmailAndPassword(email, password)
.then(() => {
loginSection.classList.add('hidden');
dashboardSection.classList.remove('hidden');
loadCategories();
loadJobs();
loadStats();
Swal.fire({
icon: 'success',
title: 'Login Successful',
showConfirmButton: false,
timer: 1500
});
})
.catch((error) => {
Swal.fire({
icon: 'error',
title: 'Login Failed',
text: error.message
});
});
});
// Logout Functionality
logoutBtn.addEventListener('click', () => {
auth.signOut().then(() => {
dashboardSection.classList.add('hidden');
loginSection.classList.remove('hidden');
loginForm.reset();
});
});
// Check Auth State
auth.onAuthStateChanged((user) => {
if (user) {
loginSection.classList.add('hidden');
dashboardSection.classList.remove('hidden');
loadCategories();
loadJobs();
loadStats();
} else {
loginSection.classList.remove('hidden');
dashboardSection.classList.add('hidden');
}
});
// Load Categories
function loadCategories() {
database.ref('categories').on('value', (snapshot) => {
jobCategorySelect.innerHTML = '<option value="" disabled selected>Select Category</option>';
snapshot.forEach((childSnapshot) => {
const category = childSnapshot.val();
const option = document.createElement('option');
option.value = childSnapshot.key;
option.textContent = category.name;
jobCategorySelect.appendChild(option);
});
});
}
// Load Jobs
function loadJobs() {
database.ref('jobs').on('value', (snapshot) => {
jobsList.innerHTML = '';
snapshot.forEach((categorySnapshot) => {
categorySnapshot.forEach((jobSnapshot) => {
const job = jobSnapshot.val();
const jobElement = document.createElement('div');
jobElement.className = 'bg-white p-3 rounded-lg shadow job-card';
jobElement.innerHTML = `
<div class="flex justify-between items-start">
<div>
<h4 class="font-bold">${job.title}</h4>
<p class="text-sm text-gray-500">${job.category}</p>
<p class="text-sm mt-1 text-gray-700">${job.description.substring(0, 80)}...</p>
</div>
<div class="flex gap-1">
<button class="edit-job p-1 bg-blue-500 text-white rounded" data-id="${jobSnapshot.key}" data-cat="${categorySnapshot.key}">
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
</svg>
</button>
<button class="delete-job p-1 bg-red-500 text-white rounded" data-id="${jobSnapshot.key}" data-cat="${categorySnapshot.key}">
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
</div>
</div>
<div class="mt-2 flex justify-between items-center">
<span class="text-xs px-1.5 py-0.5 rounded ${job.status === 'published' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800'}">
${job.status}
</span>
<a href="${job.link}" target="_blank" class="text-blue-500 text-xs hover:underline">View</a>
</div>
`;
jobsList.appendChild(jobElement);
});
});
addJobEventListeners();
});
}
// Add Job Event Listeners
function addJobEventListeners() {
document.querySelectorAll('.edit-job').forEach(btn => {
btn.addEventListener('click', (e) => {
const jobId = e.currentTarget.getAttribute('data-id');
const catId = e.currentTarget.getAttribute('data-cat');
editJob(jobId, catId);
});
});
document.querySelectorAll('.delete-job').forEach(btn => {
btn.addEventListener('click', (e) => {
const jobId = e.currentTarget.getAttribute('data-id');
const catId = e.currentTarget.getAttribute('data-cat');
deleteJob(jobId, catId);
});
});
}
// Edit Job
function editJob(jobId, catId) {
database.ref(`jobs/${catId}/${jobId}`).once('value').then((snapshot) => {
const job = snapshot.val();
document.getElementById('jobTitle').value = job.title;
document.getElementById('jobDescription').value = job.description;
document.getElementById('jobLink').value = job.link;
const select = document.getElementById('jobCategory');
for (let i = 0; i < select.options.length; i++) {
if (select.options[i].value === catId) {
select.selectedIndex = i;
break;
}
}
const saveBtn = document.getElementById('saveJobBtn');
saveBtn.textContent = 'Update Job';
saveBtn.setAttribute('data-id', jobId);
saveBtn.setAttribute('data-cat', catId);
saveBtn.onclick = function() {
updateJob(this.getAttribute('data-id'), this.getAttribute('data-cat'));
};
});
}
// Update Job
function updateJob(jobId, catId) {
const title = document.getElementById('jobTitle').value;
const category = document.getElementById('jobCategory').value;
const description = document.getElementById('jobDescription').value;
const link = document.getElementById('jobLink').value;
if (!title || !category || !description || !link) {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'All fields are required!'
});
return;
}
const updates = {
title,
category,
description,
link,
status: 'published',
updatedAt: firebase.database.ServerValue.TIMESTAMP
};
database.ref(`jobs/${catId}/${jobId}`).update(updates)
.then(() => {
resetJobForm();
Swal.fire({
icon: 'success',
title: 'Success',
text: 'Job updated successfully!'
});
})
.catch((error) => {
Swal.fire({
icon: 'error',
title: 'Error',
text: error.message
});
});
}
// Delete Job
function deleteJob(jobId, catId) {
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
database.ref(`jobs/${catId}/${jobId}`).remove()
.then(() => {
Swal.fire('Deleted!', 'Job has been deleted.', 'success');
})
.catch((error) => {
Swal.fire('Error', error.message, 'error');
});
}
});
}
// Save Job
document.getElementById('saveJobBtn').addEventListener('click', () => {
const title = document.getElementById('jobTitle').value;
const category = document.getElementById('jobCategory').value;
const description = document.getElementById('jobDescription').value;
const link = document.getElementById('jobLink').value;
if (!title || !category || !description || !link) {
Swal.fire('Error', 'All fields are required!', 'error');
return;
}
const newJob = {
title,
category,
description,
link,
status: 'published',
createdAt: firebase.database.ServerValue.TIMESTAMP,
updatedAt: firebase.database.ServerValue.TIMESTAMP
};
const newJobKey = database.ref().child('jobs').child(category).push().key;
const updates = {};
updates[`/jobs/${category}/${newJobKey}`] = newJob;
database.ref().update(updates)
.then(() => {
resetJobForm();
Swal.fire('Success', 'Job published successfully!', 'success');
})
.catch((error) => {
Swal.fire('Error', error.message, 'error');
});
});
// Save as Draft
document.getElementById('saveDraftBtn').addEventListener('click', () => {
const title = document.getElementById('jobTitle').value;
const category = document.getElementById('jobCategory').value;
const description = document.getElementById('jobDescription').value;
const link = document.getElementById('jobLink').value;
if (!title || !category || !description || !link) {
Swal.fire('Error', 'All fields are required!', 'error');
return;
}
const newJob = {
title,
category,
description,
link,
status: 'draft',
createdAt: firebase.database.ServerValue.TIMESTAMP,
updatedAt: firebase.database.ServerValue.TIMESTAMP
};
const newJobKey = database.ref().child('jobs').child(category).push().key;
const updates = {};
updates[`/jobs/${category}/${newJobKey}`] = newJob;
database.ref().update(updates)
.then(() => {
resetJobForm();
Swal.fire('Success', 'Job saved as draft!', 'success');
})
.catch((error) => {
Swal.fire('Error', error.message, 'error');
});
});
// Save Category
document.getElementById('saveCategoryBtn').addEventListener('click', () => {
const name = document.getElementById('categoryName').value;
if (!name) {
Swal.fire('Error', 'Category name is required!', 'error');
return;
}
const newCategory = {
name,
createdAt: firebase.database.ServerValue.TIMESTAMP
};
const newCategoryKey = database.ref().child('categories').push().key;
const updates = {};
updates[`/categories/${newCategoryKey}`] = newCategory;
database.ref().update(updates)
.then(() => {
document.getElementById('categoryName').value = '';
Swal.fire('Success', 'Category added successfully!', 'success');
})
.catch((error) => {
Swal.fire('Error', error.message, 'error');
});
});
// Save Banner
document.getElementById('saveBannerBtn').addEventListener('click', () => {
const title = document.getElementById('bannerTitle').value;
const link = document.getElementById('bannerLink').value;
if (!title || !link) {
Swal.fire('Error', 'Title and link are required!', 'error');
return;
}
const newBanner = {
title,
link,
createdAt: firebase.database.ServerValue.TIMESTAMP
};
const newBannerKey = database.ref().child('banners').push().key;
const updates = {};
updates[`/banners/${newBannerKey}`] = newBanner;
database.ref().update(updates)
.then(() => {
document.getElementById('bannerTitle').value = '';
document.getElementById('bannerLink').value = '';
Swal.fire('Success', 'Banner added successfully!', 'success');
})
.catch((error) => {
Swal.fire('Error', error.message, 'error');
});
});
// Load Stats
function loadStats() {
database.ref('jobs').on('value', (snapshot) => {
let total = 0;
let published = 0;
let draft = 0;
snapshot.forEach((categorySnapshot) => {
categorySnapshot.forEach((jobSnapshot) => {
total++;
if (jobSnapshot.val().status === 'published') {
published++;
} else {
draft++;
}
});
});
totalJobsElement.textContent = total;
publishedJobsElement.textContent = published;
draftJobsElement.textContent = draft;
});
}
// Reset Job Form
function resetJobForm() {
document.getElementById('jobTitle').value = '';
document.getElementById('jobDescription').value = '';
document.getElementById('jobLink').value = '';
document.getElementById('jobImage').value = '';
const saveBtn = document.getElementById('saveJobBtn');
saveBtn.textContent = 'Publish Job';
saveBtn.onclick = function() {
document.getElementById('saveJobBtn').click();
};
}
</script>
</body>
</html> |