File size: 80,542 Bytes
086c7f7 | 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 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DHT Unit Job Tracking</title>
<!-- Google Fonts (Inter) -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(to bottom, #E5E7EB, #F3F4F6);
margin: 0;
}
nav {
background-color: #F3F4F6;
padding: 0.5rem 1rem;
margin: 0; /* Remove all margins */
}
.container {
max-width: 1200px;
margin-left: auto;
margin-right: auto;
}
nav .container {
display: flex;
justify-content: space-between;
align-items: center;
}
.form-container {
background-color: #F9FAFB;
border: none;
box-shadow: 0 10px 20px rgba(0,0,0,0.1), 0 6px 6px rgba(0,0,0,0.1);
border-radius: 12px;
padding: 1rem;
transition: transform 0.2s ease;
}
.form-container:hover {
transform: scale(1.01);
}
.form-row {
display: grid;
grid-template-columns: 2fr 1.5fr 1fr 1fr 1fr 2fr;
gap: 1rem;
}
.date-input {
max-width: 160px;
}
.job-textarea, .remark-textarea {
height: 100px;
}
.narrow-field {
max-width: 400px;
}
.department-field {
max-width: 400px;
}
.input-field {
transition: all 0.2s ease;
}
.input-field:hover {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.select-placeholder {
color: #9CA3AF;
}
.completed-row {
background-color: #DCFCE7 !important;
}
.nav-ribbon {
background-color: #F3F4F6;
padding: 0.5rem 1rem; /* Match nav padding */
margin: 0; /* Remove all margins */
display: flex;
justify-content: flex-end;
align-items: center;
}
.nav-ribbon a {
padding: 0.5rem 1rem; /* Match nav link padding */
font-size: 1rem; /* Match nav link font size */
color: #374151;
text-decoration: none;
cursor: pointer;
}
.nav-ribbon a:hover {
color: #059669;
text-decoration: underline;
}
.nav-ribbon a.active {
color: #2DD4BF;
font-weight: 600;
text-decoration: underline;
background-color: #FFFFFF;
border-bottom: 2px solid #2DD4BF;
}
#reportsContent {
margin: 0; /* Remove margins */
padding-top: 0; /* Remove top padding */
}
#reportsContent header {
display: none; /* Hide Reports header to eliminate gap */
}
/* Table Styling for Both Homepage and Reports */
#jobTable, #reportTable {
table-layout: fixed;
width: 100%;
}
#jobTable tr, #reportTable tr {
height: 3rem;
max-height: 3rem;
overflow: hidden;
}
#jobTable th, #jobTable td, #reportTable th, #reportTable td {
padding: 0.75rem 0.5rem;
vertical-align: middle;
box-sizing: border-box;
}
#jobTable th, #reportTable th {
white-space: normal;
line-height: 1.5;
overflow: hidden;
text-overflow: ellipsis;
}
/* Column Widths for Homepage Table (8 columns) */
#jobTable th:nth-child(1), #jobTable td:nth-child(1) { width: 8%; }
#jobTable th:nth-child(2), #jobTable td:nth-child(2) { width: 21%; }
#jobTable th:nth-child(3), #jobTable td:nth-child(3) { width: 10%; }
#jobTable th:nth-child(4), #jobTable td:nth-child(4) { width: 8%; }
#jobTable th:nth-child(5), #jobTable td:nth-child(5) { width: 10%; }
#jobTable th:nth-child(6), #jobTable td:nth-child(6) { width: 10%; }
#jobTable th:nth-child(7), #jobTable td:nth-child(7) { width: 10%; }
#jobTable th:nth-child(8), #jobTable td:nth-child(8) { width: 11%; }
/* Column Widths for Reports Table (9 columns) */
#reportTable th:nth-child(1), #reportTable td:nth-child(1) { width: 10%; }
#reportTable th:nth-child(2), #reportTable td:nth-child(2) { width: 25%; }
#reportTable th:nth-child(3), #reportTable td:nth-child(3) { width: 8%; }
#reportTable th:nth-child(4), #reportTable td:nth-child(4) { width: 8%; }
#reportTable th:nth-child(5), #reportTable td:nth-child(5) { width: 10%; }
#reportTable th:nth-child(6), #reportTable td:nth-child(6) { width: 15%; }
#reportTable th:nth-child(7), #reportTable td:nth-child(7) { width: 8%; }
#reportTable th:nth-child(8), #reportTable td:nth-child(8) { width: 11%; }
#reportTable th:nth-child(9), #reportTable td:nth-child(9) { width: 5%; }
/* Text Wrapping for Long Content */
#jobTable td:nth-child(2), #jobTable td:nth-child(7),
#reportTable td:nth-child(2), #reportTable td:nth-child(6) {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-height: 2.25rem;
line-height: 1.125rem;
cursor: pointer;
}
/* Adjust Status Dropdown and Save Button */
#reportTable select {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
width: 100%;
}
.save-btn {
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
width: 100%;
}
.sortable {
cursor: pointer;
position: relative;
}
.sortable:hover {
background-color: #E5E7EB;
}
.sort-arrow {
display: inline-block;
margin-left: 0.25rem;
font-size: 0.75rem;
}
.filter-row {
display: flex;
gap: 0.75rem;
margin-bottom: 1rem;
flex-wrap: wrap;
align-items: flex-end;
max-width: 100%; /* Ensure it doesn't exceed container */
}
.filter-item {
flex: 0 0 auto;
min-width: 0; /* Allow shrinking */
}
.filter-search {
width: 100px;
}
.filter-narrow {
width: 90px;
}
#filterDepartment, #filterPriority, #filterJobType, #reportPriority, #reportJobType, #reportDepartment {
width: 100px;
}
@media (max-width: 640px) {
#filterDepartment, #filterPriority, #filterJobType, #reportPriority, #reportJobType, #reportDepartment {
width: 100% !important;
}
}
.filter-button {
width: 60px;
padding: 0.75rem 0.75rem;
line-height: 1rem;
font-size: 0.875rem;
border-radius: 9999px;
transition: all 0.2s ease;
}
.filter-button:hover {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.filter-item:last-child {
margin-right: 0;
}
.pagination {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 1rem;
flex-wrap: wrap;
gap: 0.5rem;
}
#toast.show {
opacity: 1;
display: block;
}
#toast {
opacity: 0;
display: none;
}
@media (max-width: 640px) {
#toast {
top: 2rem;
right: 1rem;
left: 1rem;
margin: 0 auto;
max-width: 90%;
}
}
.pagination button {
padding: 0.5rem 1rem;
border-radius: 4px;
font-size: 0.875rem;
}
.pagination button:disabled {
background-color: #D1D5DB;
cursor: not-allowed;
}
.pagination .page-number {
padding: 0.5rem 0.75rem;
border-radius: 4px;
cursor: pointer;
}
.pagination .page-number.active {
background-color: #2DD4BF;
color: white;
}
.pagination .page-number:hover:not(.active) {
background-color: #E5E7EB;
}
#homeContent, #reportsContent {
transition: opacity 0.3s ease;
}
#homeContent.hidden, #reportsContent.hidden {
display: none;
opacity: 0;
}
.jobs-per-page {
max-width: 120px;
font-size: 0.875rem;
}
@media (min-width: 1024px) {
.filter-row {
flex-wrap: nowrap;
}
}
@media (max-width: 640px) {
.form-row {
grid-template-columns: 1fr;
}
.date-input, .narrow-field, .department-field {
max-width: 100%;
}
.filter-row {
flex-wrap: wrap;
align-items: stretch;
}
.filter-item {
width: 100%;
}
.filter-search, .filter-narrow, .filter-button {
width: 100%;
}
.filter-item:last-child {
margin-right: 0;
}
.header {
padding: 0.5rem 0.75rem;
}
.header h1 {
font-size: 1.5rem;
}
#jobTable th, #jobTable td, #reportTable th, #reportTable td {
padding: 0.5rem 0.25rem;
font-size: 0.875rem;
}
#jobTable tr, #reportTable tr {
height: 4rem;
max-height: 4rem;
}
#jobTable td:nth-child(2), #jobTable td:nth-child(7),
#reportTable td:nth-child(2), #reportTable td:nth-child(6) {
max-height: 3rem;
line-height: 1.5rem;
}
.action-buttons {
flex-direction: column;
gap: 0.25rem;
}
.edit-btn, .delete-btn, .save-btn {
width: 100%;
}
.form-buttons {
flex-direction: column;
gap: 0.5rem;
}
.pagination {
flex-direction: column;
align-items: flex-start;
}
.pagination button, .pagination .page-number {
padding: 0.5rem;
font-size: 0.75rem;
}
.nav-ribbon {
justify-content: center; /* Center tabs on mobile */
padding: 0.25rem 0.5rem; /* Reduced padding for mobile */
}
.nav-ribbon a {
padding: 0.25rem 0.5rem; /* Reduced padding for mobile */
font-size: 0.875rem; /* Smaller font for mobile */
}
.jobs-per-page {
max-width: 100%;
}
.filter-item {
width: 100%;
max-width: 100%;
}
.filter-narrow {
width: 100% !important; /* Override inline max-width on mobile */
}
#filterNotificationNo {
max-width: 100% !important; /* Allow full width on mobile */
}
#reportPagination, #historyPagination {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 1rem;
flex-wrap: wrap;
gap: 0.5rem;
}
}
</style>
</head>
<body class="flex flex-col items-center min-h-screen">
<header class="w-full bg-blue-600 py-4 text-white text-center shadow-md">
<h1 class="text-2xl font-bold">DHT Unit Job Tracking</h1>
</header>
<nav class="container mx-auto px-4 nav-ribbon">
<a id="homeLink" class="active" href="#">Home</a>
<a id="reportsLink" href="#">Reports</a>
</nav>
<main class="container mx-auto mt-2 p-4">
<!-- Home Page Content -->
<div id="homeContent">
<!-- Form in 3D Box -->
<div class="form-container mb-10">
<form id="jobForm">
<div class="mb-2">
<label for="jobDate" class="block text-base font-medium text-gray-800 mb-2">Date</label>
<input type="date" id="jobDate" name="jobDate" class="input-field mt-1 block date-input rounded bg-white py-2 px-3 text-base placeholder-gray-400 focus:ring-2 focus:ring-teal-400 hover:shadow-sm" readonly required>
</div>
<div class="form-row">
<div>
<label for="job" class="block text-base font-semibold text-gray-800 mb-2">Job description</label>
<textarea id="job" name="job" class="input-field mt-1 block w-full job-textarea rounded bg-white py-2 px-3 text-base placeholder-gray-400 focus:ring-2 focus:ring-teal-400 hover:shadow-sm" placeholder="Enter job description" required></textarea>
</div>
<div class="department-field">
<label for="department" class="block text-base font-semibold text-gray-800 mb-2">Concern Department</label>
<select id="department" name="department" class="input-field mt-1 block w-full rounded bg-white py-2 px-3 text-base focus:ring-2 focus:ring-teal-400 hover:shadow-sm" required>
<option value="" class="select-placeholder">Select department</option>
<option value="Static">Static</option>
<option value="Electrical">Electrical</option>
<option value="Rotary">Rotary</option>
<option value="Instruments">Instruments</option>
<option value="Analyzers">Analyzers</option>
<option value="EED">EED</option>
<option value="Civil">Civil</option>
<option value="Other">Other</option>
</select>
</div>
<div class="narrow-field">
<label for="priority" class="block text-base font-semibold text-gray-800 mb-2">Priority</label>
<select id="priority" name="priority" class="input-field mt-1 block w-full rounded bg-white py-2 px-3 text-base focus:ring-2 focus:ring-teal-400 hover:shadow-sm" required>
<option value="" class="select-placeholder">Select priority</option>
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low">Low</option>
</select>
</div>
<div class="narrow-field">
<label for="jobType" class="block text-base font-semibold text-gray-800 mb-2">Job Type</label>
<select id="jobType" name="jobType" class="input-field mt-1 block w-full rounded bg-white py-2 px-3 text-base focus:ring-2 focus:ring-teal-400 hover:shadow-sm" required>
<option value="" class="select-placeholder">Select type</option>
<option value="Regular Job">Regular Job</option>
<option value="Shutdown Job">Shutdown Job</option>
</select>
</div>
<div class="narrow-field">
<label for="notificationNo" class="block text-base font-semibold text-gray-800 mb-1">Notification No</label>
<input type="text" id="notificationNo" name="notificationNo" class="input-field mt-0 block w-full rounded bg-white py-2 px-3 text-base placeholder-gray-400 focus:ring-2 focus:ring-teal-400 hover:shadow-sm" placeholder="Enter notification number" required>
</div>
<div>
<label for="remark" class="block text-base font-semibold text-gray-800 mb-1">Remark</label>
<textarea id="remark" name="remark" class="input-field mt-1 block w-full remark-textarea rounded bg-white py-2 px-3 text-base placeholder-gray-400 focus:ring-2 focus:ring-teal-400 hover:shadow-sm" placeholder="Enter remark"></textarea>
</div>
</div>
<div class="mt-4 flex justify-center form-buttons gap-4">
<button type="submit" id="submitButton" class="bg-blue-600 text-white py-3 px-6 rounded-lg hover:bg-blue-700 hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-teal-400 active:bg-blue-600 transition-all duration-200 hover:scale-105" aria-label="Add or update job">Add Job</button>
<button type="button" id="cancelButton" class="hidden bg-gray-500 text-white py-3 px-6 rounded hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-teal-400 transition-all duration-200 hover:scale-105" aria-label="Cancel edit">Cancel</button>
</div>
</form>
</div>
<!-- Filters -->
<!-- Filters -->
<!-- Filters -->
<div class="filter-row">
<div class="filter-item">
<label for="filterStartDate" class="block text-sm font-semibold text-gray-800 mb-1">Start Date</label>
<input type="date" id="filterStartDate" class="input-field mt-1 filter-narrow block w-full px-3 py-2 rounded bg-white py-2 px-3 text-sm focus:ring-2 focus:ring-blue-400 hover:shadow-sm">
</div>
<div class="filter-item">
<label for="filterEndDate" class="block text-sm font-semibold text-gray-800 mb-1">End Date</label>
<input type="date" id="filterEndDate" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm focus:ring-blue-400 hover:shadow-sm" min="">
<div id="dateError" class="text-red-600 text-sm mt-1 hidden">End Date must be on or after Start Date.</div>
</div>
<div class="filter-item">
<label for="filterSearch" class="block text-sm font-semibold text-gray-800 mb-1">Search</label>
<input type="text" id="filterSearch" class="input-field mt-1 filter-search block w-full rounded bg-white py-2 px-3 text-sm placeholder-gray-500 focus:ring-blue-400 hover:shadow-sm" placeholder="Job or Remark">
</div>
<div class="filter-item">
<label for="filterDepartment" class="block text-sm font-semibold text-gray-800 mb-1">Department</label>
<select id="filterDepartment" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm focus:ring-2 focus:ring-blue-400 hover:shadow-sm">
<option value="">All</option>
<option value="Static">Static</option>
<option value="Electrical">Electrical</option>
<option value="Rotary">Rotary</option>
<option value="Instruments">Instruments</option>
<option value="Analyzers">Analyzers</option>
<option value="EED">EED</option>
<option value="Civil">Civil</option>
<option value="Other">Other</option>
</select>
</div>
<div class="filter-item">
<label for="filterPriority" class="block text-sm font-semibold text-gray-800 mb-1">Priority</label>
<select id="filterPriority" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm focus:ring-blue-400 hover:shadow-sm">
<option value="">All</option>
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low">Low</option>
</select>
</div>
<div class="filter-item">
<label for="filterJobType" class="block text-sm font-semibold text-gray-800 mb-1">Job Type</label>
<select id="filterJobType" class="input-field mt-1 filter-narrow w-full rounded bg-white py-2 px-3 text-sm focus:ring-blue-400 hover:shadow-sm">
<option value="">All</option>
<option value="Regular Job">Regular</option>
<option value="Shutdown Job">Shutdown</option>
</select>
</div>
<div class="filter-item">
<label for="filterNotificationNo" class="block text-sm font-semibold text-gray-800 mb-1">Notification</label>
<input type="text" id="filterNotificationNo" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm placeholder-gray-400 focus:ring-blue-400 hover:shadow-sm" style="max-width: 80px;" placeholder="No">
</div>
<div class="filter-item">
<button id="exportJobsHome" class="bg-green-500 text-white filter-button hover:bg-green-600" aria-label="Export filtered jobs">Export</button>
</div>
<div class="filter-item">
<button id="clearFilters" class="bg-gray-500 text-white filter-button hover:bg-gray-600">Clear</button>
</div>
</div>
<!-- Table -->
<div class="bg-white rounded-lg shadow">
<table id="jobTable" class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="date">Date <span class="sort-arrow"></span></th>
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider">Job Description</th>
<th class="sortable px-4 py-3 text-left text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="department">Department <span class="sort-arrow"></span></th>
<th class="sortable px-4 py-3 text-left text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="priority">Priority <span class="sort-arrow"></span></th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="jobType">Job Type <span class="sort-arrow"></span></th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-id="notificationNo">Notification No <span class="sort-arrow"></span></th>
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider">Remark</th>
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="jobTableBody" class="divide-y divide-gray-200">
<!-- Job entries will be added here -->
</tbody>
</table>
</div>
<!-- Pagination -->
<div id="pagination" class="pagination">
<div class="flex items-center gap-4 text-sm text-gray-600">
<div>
<label for="jobsPerPage" class="mr-2">Jobs per page:</label>
<select id="jobsPerPage" class="jobs-per-page input-field rounded bg-white py-1 px-2 focus:ring-2 focus:ring-teal-400 hover:shadow-sm">
<option value="10">10</option>
<option value="15" selected>15</option>
<option value="25">25</option>
</select>
</div>
<div id="paginationRange"></div>
</div>
</div>
</div>
<!-- Reports Page Content -->
<div id="reportsContent" class="hidden">
<div class="container mx-auto p-4">
<!-- Department Tabs -->
<nav class="nav-ribbon bg-gray-100 rounded-t-lg border-b border-gray-200 mb-4">
<a id="tabStatic" class="tab-link" href="#" data-department="Static" aria-label="View Static department jobs">Static</a>
<a id="tabElectrical" class="tab-link" href="#" data-department="Electrical" aria-label="View Electrical department jobs">Electrical</a>
<a id="tabRotary" class="tab-link" href="#" data-department="Rotary" aria-label="View Rotary department jobs">Rotary</a>
<a id="tabInstruments" class="tab-link" href="#" data-department="Instruments" aria-label="View Instruments department jobs">Instruments</a>
<a id="tabAnalyzers" class="tab-link" href="#" data-department="Analyzers" aria-label="View Analyzers department jobs">Analyzers</a>
<a id="tabEED" class="tab-link" href="#" data-department="EED" aria-label="View EED department jobs">EED</a>
<a id="tabCivil" class="tab-link" href="#" data-department="Civil" aria-label="View Civil department jobs">Civil</a>
<a id="tabOther" class="tab-link" href="#" data-department="Other" aria-label="View Other department jobs">Other</a>
<a id="tabHistory" class="tab-link" href="#" data-department="History" aria-label="View completed job history">History</a>
</nav>
<!-- Filters -->
<!-- Filters (Reports Page) -->
<div class="filter-row mb-6">
<div class="filter-item">
<label for="reportStartDate" class="block text-sm font-semibold text-gray-800 mb-1">Start Date</label>
<input type="date" id="reportStartDate" class="input-field mt-1 filter-narrow block w-full px-3 py-2 rounded bg-white text-sm focus:ring-2 focus:ring-blue-400 hover:shadow-sm">
</div>
<div class="filter-item">
<label for="reportEndDate" class="block text-sm font-semibold text-gray-800 mb-1">End Date</label>
<input type="date" id="reportEndDate" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm focus:ring-blue-400 hover:shadow-sm" min="">
<div id="reportDateError" class="text-red-600 text-sm mt-1 hidden">End Date must be on or after Start Date.</div>
</div>
<div class="filter-item" id="reportPriorityFilter">
<label for="reportPriority" class="block text-sm font-semibold text-gray-800 mb-1">Priority</label>
<select id="reportPriority" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm focus:ring-2 focus:ring-blue-400 hover:shadow-sm">
<option value="">All Priorities</option>
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low">Low</option>
</select>
</div>
<div class="filter-item">
<label for="reportJobType" class="block text-sm font-semibold text-gray-800 mb-1">Job Type</label>
<select id="reportJobType" class="input-field mt-1 filter-narrow w-full rounded bg-white py-2 px-3 text-sm focus:ring-blue-400 hover:shadow-sm">
<option value="">All Job Types</option>
<option value="Regular Job">Regular Jobs</option>
<option value="Shutdown Job">Shutdown Jobs</option>
</select>
</div>
<div class="filter-item">
<label for="reportSearch" class="block text-sm font-semibold text-gray-800 mb-1">Search</label>
<input type="text" id="reportSearch" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm placeholder-gray-500 focus:ring-blue-400 hover:shadow-sm" placeholder="Search Job or Remark">
</div>
<div class="filter-item" id="reportStatusFilter">
<label for="reportStatus" class="block text-sm font-semibold text-gray-800 mb-1">Status</label>
<select id="reportStatus" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm focus:ring-2 focus:ring-blue-400 hover:shadow-sm">
<option value="">All Statuses</option>
<option value="Pending">Pending</option>
<option value="Completed">Completed</option>
</select>
</div>
<div class="filter-item hidden" id="reportDepartmentFilter">
<label for="reportDepartment" class="block text-sm font-semibold text-gray-800 mb-1">Department</label>
<select id="reportDepartment" class="input-field mt-1 filter-narrow block w-full rounded bg-white py-2 px-3 text-sm focus:ring-2 focus:ring-blue-400 hover:shadow-sm">
<option value="">All Departments</option>
<option value="Static">Static</option>
<option value="Electrical">Electrical</option>
<option value="Rotary">Rotary</option>
<option value="Instruments">Instruments</option>
<option value="Analyzers">Analyzers</option>
<option value="EED">EED</option>
<option value="Civil">Civil</option>
<option value="Other">Other</option>
</select>
</div>
<div class="filter-item">
<button id="exportJobs" class="bg-teal-500 text-white filter-button hover:bg-teal-600" aria-label="Export filtered jobs">Export</button>
</div>
<div class="filter-item">
<button id="clearReportFilters" class="bg-gray-500 text-white filter-button hover:bg-gray-600" aria-label="Clear all report filters">Clear</button>
</div>
</div>
<!-- Report Table -->
<div class="bg-white rounded-lg shadow">
<table id="reportTable" class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="date">Date <span class="sort-arrow"></span></th>
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider">Job Description</th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="priority">Priority <span class="sort-arrow"></span></th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="jobType">Job Type <span class="sort-arrow"></span></th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="notificationNo">Notification No <span class="sort-arrow"></span></th>
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider">Remark</th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="completedDate">Completion Date <span class="sort-arrow"></span></th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="status">Status <span class="sort-arrow"></span></th>
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody id="reportTableBody" class="divide-y divide-gray-200"></tbody>
</table>
</div>
<!-- History Table -->
<div id="historyTableContainer" class="bg-white rounded-lg shadow hidden">
<table id="historyTable" class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="date">Date <span class="sort-arrow"></span></th>
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider">Job Description</th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="department">Department <span class="sort-arrow"></span></th>
<th class="sortable px-4 py-3 text-left text-sm font-semibold text-gray-800 uppercase tracking-wider" data-sort="completedDate">Completed Date <span class="sort-arrow"></span></th>
</tr>
</thead>
<tbody id="historyTableBody"></tbody>
</table>
</div>
<!-- Pagination -->
<div id="reportPagination" class="pagination"></div>
<!-- Add this after the reportPagination div at line 673 -->
<div id="historyPagination" class="pagination hidden"></div>
</div>
</div>
</main>
<script>
// Show toast notification
function showToast(message, duration = 3000) {
const toast = document.getElementById('toast');
const toastMessage = document.getElementById('toastMessage');
toastMessage.textContent = message;
toast.classList.remove('hidden');
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
toast.classList.add('hidden');
}, duration);
}
// Easter egg for header click
let headerClickCount = 0;
document.querySelector('header h1').addEventListener('click', () => {
headerClickCount++;
if (headerClickCount === 10) {
showToast('Created by Vinod Rangi, June 2025');
headerClickCount = 0; // Reset counter
}
});
// State management
let jobs = JSON.parse(localStorage.getItem('jobs')) || [];
// Initialize status for existing jobs
jobs = jobs.map(job => ({
...job,
status: job.status || 'Pending'
}));
localStorage.setItem('jobs', JSON.stringify(jobs));
localStorage.removeItem('completedJobs'); // Clean up unused storage
let sortColumn = 'date';
let sortDirection = 'desc';
let filters = { startDate: '', endDate: '', department: '', priority: '', jobType: '', notificationNo: '', search: '' };
let editIndex = null;
let currentPage = 1;
let jobsPerPage = 15;
let currentView = 'home';
let reportFilters = { startDate: '', endDate: '', priority: '', jobType: '', search: '', status: '', department: '' };
let reportSortColumn = 'date';
let reportSortDirection = 'desc';
let reportJobsPerPage = 15;
let historyJobsPerPage = 15;
let reportCurrentPage = 1;
let historyCurrentPage = 1;
let historySortColumn = 'completedDate';
let historySortDirection = 'desc';
let activeDepartment = 'Static';
// DOM elements
const homeLink = document.getElementById('homeLink');
const reportsLink = document.getElementById('reportsLink');
const homeContent = document.getElementById('homeContent');
const reportsContent = document.getElementById('reportsContent');
const tableBody = document.getElementById('jobTableBody');
// Filter jobs by expiration (remove Completed jobs older than 7 days)
function filterExpiredJobs() {
const now = new Date();
jobs = jobs.filter(job => {
if (job.status === 'Completed' && job.completedDate) {
const completedDate = new Date(job.completedDate);
const daysDiff = (now - completedDate) / (1000 * 60 * 60 * 24);
return daysDiff <= 7;
}
return true;
});
localStorage.setItem('jobs', JSON.stringify(jobs));
}
// Navigation handling
function showHome(e) {
e.preventDefault();
currentView = 'home';
homeContent.classList.remove('hidden');
reportsContent.classList.add('hidden');
homeLink.classList.add('active');
reportsLink.classList.remove('active');
document.getElementById('jobDate').value = new Date().toISOString().split('T')[0];
renderJobs();
}
function showReports(e) {
e.preventDefault();
currentView = 'reports';
homeContent.classList.add('hidden');
reportsContent.classList.remove('hidden');
homeLink.classList.remove('active');
reportsLink.classList.add('active');
document.querySelectorAll('.tab-link').forEach(t => t.classList.remove('active'));
document.getElementById('tabStatic').classList.add('active');
activeDepartment = 'Static';
renderReports();
}
homeLink.addEventListener('click', showHome);
reportsLink.addEventListener('click', showReports);
// Reset form
function resetForm() {
document.getElementById('jobForm').reset();
document.getElementById('submitButton').textContent = 'Add Job';
document.getElementById('cancelButton').classList.add('hidden');
document.getElementById('jobDate').value = new Date().toISOString().split('T')[0];
editIndex = null;
}
// Scroll to form
function scrollToForm() {
const formContainer = document.querySelector('.form-container');
formContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
// Show/hide date error
function showDateError(show) {
const dateError = document.getElementById('dateError');
dateError.classList.toggle('hidden', !show);
}
// Render pagination (Homepage)
function renderPagination(totalJobs) {
const pagination = document.getElementById('pagination');
const totalPages = Math.ceil(totalJobs / jobsPerPage);
currentPage = Math.min(currentPage, totalPages || 1);
const startJob = (currentPage - 1) * jobsPerPage + 1;
const endJob = Math.min(currentPage * jobsPerPage, totalJobs);
let html = `
<div class="flex items-center gap-4 text-sm text-gray-600">
<div>
<label for="jobsPerPage" class="mr-2">Jobs per page:</label>
<select id="jobsPerPage" class="jobs-per-page input-field rounded bg-white py-1 px-2 focus:ring-2 focus:ring-teal-400 hover:shadow-sm">
<option value="10" ${jobsPerPage === 10 ? 'selected' : ''}>10</option>
<option value="15" ${jobsPerPage === 15 ? 'selected' : ''}>15</option>
<option value="25" ${jobsPerPage === 25 ? 'selected' : ''}>25</option>
</select>
</div>
<div id="paginationRange">
Showing ${totalJobs > 0 ? startJob : 0} to ${endJob} of ${totalJobs} jobs
</div>
</div>
<div class="flex gap-2 flex-wrap">
<button id="prevPage" class="bg-teal-500 text-white hover:bg-teal-600 disabled:bg-gray-300" ${currentPage === 1 ? 'disabled' : ''}>Previous</button>
<div class="flex gap-1">
`;
const maxPagesToShow = 5;
let startPage = Math.max(1, currentPage - Math.floor(maxPagesToShow / 2));
let endPage = Math.min(totalPages, startPage + maxPagesToShow - 1);
if (endPage - startPage + 1 < maxPagesToShow) {
startPage = Math.max(1, endPage - maxPagesToShow + 1);
}
if (startPage > 1) {
html += `<span class="page-number" data-page="1">1</span>`;
if (startPage > 2) html += `<span class="px-2">...</span>`;
}
for (let i = startPage; i <= endPage; i++) {
html += `<span class="page-number ${i === currentPage ? 'active' : ''}" data-page="${i}">${i}</span>`;
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) html += `<span class="px-2">...</span>`;
html += `<span class="page-number" data-page="${totalPages}">${totalPages}</span>`;
}
html += `
</div>
<button id="nextPage" class="bg-teal-500 text-white hover:bg-teal-600 disabled:bg-gray-300" ${currentPage === totalPages ? 'disabled' : ''}>Next</button>
</div>
`;
pagination.innerHTML = html;
document.getElementById('prevPage')?.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
renderJobs();
}
});
document.getElementById('nextPage')?.addEventListener('click', () => {
if (currentPage < totalPages) {
currentPage++;
renderJobs();
}
});
document.querySelectorAll('.page-number').forEach(btn => {
btn.addEventListener('click', () => {
currentPage = parseInt(btn.dataset.page);
renderJobs();
});
});
document.getElementById('jobsPerPage').addEventListener('change', (e) => {
jobsPerPage = parseInt(e.target.value);
currentPage = 1;
renderJobs();
});
}
// Render jobs (Homepage)
function renderJobs() {
if (currentView !== 'home') {
if (currentView === 'reports') renderReports();
return;
}
filterExpiredJobs();
tableBody.innerHTML = '';
function sanitizeTooltip(text) {
const div = document.createElement('div');
div.textContent = text || '';
return div.innerHTML.replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
}
let filteredJobs = jobs.map((job, originalIndex) => ({ job, originalIndex }))
.filter(({ job }) => {
const jobDate = new Date(job.date);
const startDate = filters.startDate ? new Date(filters.startDate) : null;
const endDate = filters.endDate ? new Date(filters.endDate) : null;
const jobMatches = !filters.search ||
job.job.toLowerCase().includes(filters.search.toLowerCase()) ||
(job.remark && job.remark.toLowerCase().includes(filters.search.toLowerCase()));
return (
(!startDate || jobDate >= startDate) &&
(!endDate || jobDate <= endDate) &&
jobMatches &&
(!filters.department || job.department === filters.department) &&
(!filters.priority || job.priority === filters.priority) &&
(!filters.jobType || job.jobType === filters.jobType) &&
(!filters.notificationNo || job.notificationNo.toLowerCase().includes(filters.notificationNo.toLowerCase()))
);
});
filteredJobs.sort((a, b) => {
let valA = a.job[sortColumn];
let valB = b.job[sortColumn];
if (sortColumn === 'date') {
valA = new Date(valA);
valB = new Date(valB);
}
if (valA < valB) return sortDirection === 'asc' ? -1 : 1;
if (valA > valB) return sortDirection === 'asc' ? 1 : -1;
return 0;
});
const startIndex = (currentPage - 1) * jobsPerPage;
const endIndex = startIndex + jobsPerPage;
const paginatedJobs = filteredJobs.slice(startIndex, endIndex);
if (paginatedJobs.length === 0) {
tableBody.innerHTML = '<tr><td colspan="8" class="px-6 py-4 text-center text-sm font-semibold text-gray-600">No jobs found. Try adjusting filters or adding a new job.</td></tr>';
} else {
paginatedJobs.forEach(({ job, originalIndex }, rowIndex) => {
const row = document.createElement('tr');
row.className = `even:bg-gray-50 ${job.status === 'Completed' ? 'completed-row' : ''}`;
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.date}</td>
<td class="px-6 py-4 text-sm text-gray-800" title="${sanitizeTooltip(job.job)}">${job.job}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.department}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.priority}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.jobType}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.notificationNo}</td>
<td class="px-6 py-4 text-sm text-gray-800" title="${sanitizeTooltip(job.remark)}">${job.remark || '-'}</td>
<td class="px-6 py-4 text-sm text-gray-800">
<div class="action-buttons">
<button class="edit-btn bg-blue-500 text-white px-1.5 py-0.5 rounded hover:bg-blue-600 text-[10px]" data-index="${originalIndex}" aria-label="Edit job">Edit</button>
<button class="delete-btn bg-red-500 text-white px-1.5 py-0.5 rounded hover:bg-red-600 text-[10px]" data-index="${originalIndex}" aria-label="Delete job">Delete</button>
</div>
</td>
`;
row.style.opacity = '0';
row.style.transition = 'opacity 0.3s ease';
tableBody.appendChild(row);
setTimeout(() => { row.style.opacity = '1'; }, 10);
});
}
renderPagination(filteredJobs.length);
document.querySelectorAll('#jobTable .sort-arrow').forEach(arrow => {
arrow.innerHTML = '';
});
const activeArrow = document.querySelector(`#jobTable th[data-sort="${sortColumn}"] .sort-arrow`);
if (activeArrow) {
activeArrow.innerHTML = sortDirection === 'asc' ? '↑' : '↓';
}
}
// Event delegation for table actions (Homepage)
tableBody.addEventListener('click', (e) => {
if (e.target.classList.contains('edit-btn')) {
const index = parseInt(e.target.dataset.index);
const job = jobs[index];
editIndex = index;
const jobDateInput = document.getElementById('jobDate');
jobDateInput.value = job.date;
jobDateInput.readOnly = true;
document.getElementById('job').value = job.job;
document.getElementById('department').value = job.department;
document.getElementById('priority').value = job.priority;
document.getElementById('jobType').value = job.jobType;
document.getElementById('notificationNo').value = job.notificationNo;
document.getElementById('remark').value = job.remark || '';
document.getElementById('submitButton').textContent = 'Update Job';
document.getElementById('cancelButton').classList.remove('hidden');
scrollToForm();
} else if (e.target.classList.contains('delete-btn')) {
const index = parseInt(e.target.dataset.index);
if (confirm('Are you sure you want to delete this job?')) {
jobs.splice(index, 1);
localStorage.setItem('jobs', JSON.stringify(jobs));
if (jobs.length <= (currentPage - 1) * jobsPerPage && currentPage > 1) {
currentPage--;
}
renderJobs();
showToast('Job Deleted Successfully');
}
}
});
// Form submission (Homepage)
document.getElementById('jobForm').addEventListener('submit', (e) => {
e.preventDefault();
const jobDate = new Date(document.getElementById('jobDate').value);
if (isNaN(jobDate)) {
alert('Invalid date format');
return;
}
const job = {
date: jobDate.toISOString().split('T')[0],
job: document.getElementById('job').value,
department: document.getElementById('department').value,
priority: document.getElementById('priority').value,
jobType: document.getElementById('jobType').value,
notificationNo: document.getElementById('notificationNo').value,
remark: document.getElementById('remark').value || '',
status: 'Pending'
};
if (editIndex !== null) {
job.status = jobs[editIndex].status || 'Pending';
job.completedDate = jobs[editIndex].completedDate;
jobs[editIndex] = job;
localStorage.setItem('jobs', JSON.stringify(jobs));
currentPage = 1;
renderJobs();
resetForm();
showToast('Job Updated Successfully');
} else {
jobs.push(job);
localStorage.setItem('jobs', JSON.stringify(jobs));
currentPage = 1;
renderJobs();
resetForm();
showToast('Job Saved Successfully');
}
});
// Cancel button
document.getElementById('cancelButton').addEventListener('click', () => {
resetForm();
});
// Date filter validation (Homepage)
document.getElementById('filterStartDate').addEventListener('change', (e) => {
filters.startDate = e.target.value;
document.getElementById('filterEndDate').min = e.target.value;
if (filters.endDate && filters.endDate < e.target.value) {
filters.endDate = '';
document.getElementById('filterEndDate').value = '';
showDateError(false);
}
currentPage = 1;
renderJobs();
});
document.getElementById('filterEndDate').addEventListener('change', (e) => {
filters.endDate = e.target.value;
if (filters.startDate && e.target.value < filters.startDate) {
showDateError(true);
e.target.value = filters.startDate;
filters.endDate = filters.startDate;
} else {
showDateError(false);
}
currentPage = 1;
renderJobs();
});
// Other filters (Homepage)
let debounceTimeout;
document.getElementById('filterSearch').addEventListener('input', (e) => {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
filters.search = e.target.value;
currentPage = 1;
renderJobs();
}, 300);
});
document.getElementById('filterDepartment').addEventListener('change', (e) => {
filters.department = e.target.value;
currentPage = 1;
renderJobs();
});
document.getElementById('filterPriority').addEventListener('change', (e) => {
filters.priority = e.target.value;
currentPage = 1;
renderJobs();
});
document.getElementById('filterJobType').addEventListener('change', (e) => {
filters.jobType = e.target.value;
currentPage = 1;
renderJobs();
});
document.getElementById('filterNotificationNo').addEventListener('change', (e) => {
filters.notificationNo = e.target.value;
currentPage = 1;
renderJobs();
});
document.getElementById('clearFilters').addEventListener('click', () => {
filters = { startDate: '', endDate: '', department: '', priority: '', jobType: '', notificationNo: '', search: '' };
document.getElementById('filterStartDate').value = '';
document.getElementById('filterEndDate').value = '';
document.getElementById('filterEndDate').min = '';
document.getElementById('filterDepartment').value = '';
document.getElementById('filterPriority').value = '';
document.getElementById('filterJobType').value = '';
document.getElementById('filterNotificationNo').value = '';
document.getElementById('filterSearch').value = '';
showDateError(false);
currentPage = 1;
renderJobs();
});
// Sorting (Homepage)
document.querySelectorAll('#jobTable .sortable').forEach(header => {
header.addEventListener('click', () => {
const column = header.dataset.sort;
if (sortColumn === column) {
sortDirection = sortDirection === 'asc' ? 'desc' : 'asc';
} else {
sortColumn = column;
sortDirection = 'asc';
}
currentPage = 1;
renderJobs();
});
});
// Render reports (Reports page)
function renderReports() {
if (currentView !== 'reports') return;
filterExpiredJobs();
const reportTableBody = document.getElementById('reportTableBody');
function sanitizeTooltip(text) {
const div = document.createElement('div');
div.textContent = text || '';
return div.innerHTML.replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
}
let filteredJobs = jobs.map((job, originalIndex) => ({ job, originalIndex }))
.filter(({ job }) => {
const jobDate = new Date(job.date);
const startDate = reportFilters.startDate ? new Date(reportFilters.startDate) : null;
const endDate = reportFilters.endDate ? new Date(reportFilters.endDate) : null;
const searchMatch = !reportFilters.search ||
job.job.toLowerCase().includes(reportFilters.search.toLowerCase()) ||
(job.remark && job.remark.toLowerCase().includes(reportFilters.search.toLowerCase()));
const departmentMatch = job.department === activeDepartment;
return (
departmentMatch &&
(!startDate || jobDate >= startDate) &&
(!endDate || jobDate <= endDate) &&
(!reportFilters.priority || job.priority === reportFilters.priority) &&
(!reportFilters.jobType || job.jobType === reportFilters.jobType) &&
searchMatch &&
(!reportFilters.status || job.status === reportFilters.status)
);
});
filteredJobs.sort((a, b) => {
let valA = a.job[reportSortColumn];
let valB = b.job[reportSortColumn];
if (reportSortColumn === 'date') {
valA = new Date(valA);
valB = new Date(valB);
} else if (reportSortColumn === 'completedDate') {
valA = valA ? new Date(valA) : null;
valB = valB ? new Date(valB) : null;
if (!valA && !valB) return 0;
if (!valA) return 1;
if (!valB) return -1;
} else if (reportSortColumn === 'status') {
valA = valA || 'Pending';
valB = valB || 'Pending';
const statusOrder = { 'Pending': 1, 'Completed': 0 };
valA = statusOrder[valA];
valB = statusOrder[valB];
}
if (valA < valB) return reportSortDirection === 'asc' ? -1 : 1;
if (valA > valB) return reportSortDirection === 'asc' ? 1 : -1;
return 0;
});
const startIndex = (reportCurrentPage - 1) * reportJobsPerPage;
const endIndex = startIndex + reportJobsPerPage;
const paginatedJobs = filteredJobs.slice(startIndex, endIndex);
reportTableBody.innerHTML = paginatedJobs.length === 0
? `<tr><td colspan="9" class="px-6 py-4 text-center text-sm font-semibold text-gray-600">No jobs found for ${activeDepartment} department.</td></tr>`
: paginatedJobs.map(({ job, originalIndex }) => `
<tr class="even:bg-gray-50 ${job.status === 'Completed' ? 'completed-row' : ''}">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.date}</td>
<td class="px-6 py-4 text-sm text-gray-800" title="${sanitizeTooltip(job.job)}">${job.job}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.priority}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.jobType}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.notificationNo}</td>
<td class="px-6 py-4 text-sm text-gray-800" title="${sanitizeTooltip(job.remark || '')}">${job.remark || '-'}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.completedDate || '-'}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">
<select class="status-select input-field rounded bg-white py-1 px-2 text-sm focus:ring-2 focus:ring-blue-400" data-index="${originalIndex}">
<option value="Pending" ${job.status === 'Pending' ? 'selected' : ''}>Pending</option>
<option value="Completed" ${job.status === 'Completed' ? 'selected' : ''}>Completed</option>
</select>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">
<button class="save-btn bg-blue-500 text-white px-1.5 py-0.5 rounded hover:bg-blue-600 text-[10px]" data-index="${originalIndex}" aria-label="Save job status">Save</button>
</td>
</tr>
`).join('');
renderReportPagination(filteredJobs.length);
document.querySelectorAll('#reportTable .sortable').forEach(header => {
const arrow = header.querySelector('.sort-arrow');
arrow.innerHTML = '';
header.setAttribute('aria-sort', header.dataset.sort === reportSortColumn ? (reportSortDirection === 'asc' ? 'ascending' : 'descending') : 'none');
});
const activeArrow = document.querySelector(`#reportTable th[data-sort="${reportSortColumn}"] .sort-arrow`);
if (activeArrow) activeArrow.innerHTML = reportSortDirection === 'asc' ? '↑' : '↓';
}
// Render report pagination (Reports page)
function renderReportPagination(totalJobs) {
const pagination = document.getElementById('reportPagination');
const totalPages = Math.ceil(totalJobs / reportJobsPerPage);
reportCurrentPage = Math.min(reportCurrentPage, totalPages || 1);
const startJob = (reportCurrentPage - 1) * reportJobsPerPage + 1;
const endJob = Math.min(reportCurrentPage * reportJobsPerPage, totalJobs);
let html = `
<div class="flex items-center gap-4 text-sm text-gray-600">
<div>
<label for="reportJobsPerPage" class="mr-2">Jobs per page:</label>
<select id="reportJobsPerPage" class="jobs-per-page input-field rounded bg-white py-1 px-2 focus:ring-2 focus:ring-teal-400 hover:shadow-sm">
<option value="10" ${reportJobsPerPage === 10 ? 'selected' : ''}>10</option>
<option value="15" ${reportJobsPerPage === 15 ? 'selected' : ''}>15</option>
<option value="25" ${reportJobsPerPage === 25 ? 'selected' : ''}>25</option>
</select>
</div>
<div id="reportPaginationRange">
Showing ${totalJobs > 0 ? startJob : 0} to ${endJob} of ${totalJobs} jobs
</div>
</div>
<div class="flex gap-2 flex-wrap">
<button id="reportPrevPage" class="bg-teal-500 text-white hover:bg-teal-600 disabled:bg-gray-300" ${reportCurrentPage === 1 ? 'disabled' : ''}>Previous</button>
<div class="flex gap-1">
`;
const maxPagesToShow = 5;
let startPage = Math.max(1, reportCurrentPage - Math.floor(maxPagesToShow / 2));
let endPage = Math.min(totalPages, startPage + maxPagesToShow - 1);
if (endPage - startPage + 1 < maxPagesToShow) {
startPage = Math.max(1, endPage - maxPagesToShow + 1);
}
if (startPage > 1) {
html += `<span class="page-number" data-page="1">1</span>`;
if (startPage > 2) html += `<span class="px-2">...</span>`;
}
for (let i = startPage; i <= endPage; i++) {
html += `<span class="page-number ${i === reportCurrentPage ? 'active' : ''}" data-page="${i}">${i}</span>`;
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) html += `<span class="px-2">...</span>`;
html += `<span class="page-number" data-page="${totalPages}">${totalPages}</span>`;
}
html += `
</div>
<button id="reportNextPage" class="bg-teal-500 text-white hover:bg-teal-600 disabled:bg-gray-300" ${reportCurrentPage === totalPages ? 'disabled' : ''}>Next</button>
</div>
`;
pagination.innerHTML = html;
document.getElementById('reportPrevPage')?.addEventListener('click', () => {
if (reportCurrentPage > 1) {
reportCurrentPage--;
renderReports();
}
});
document.getElementById('reportNextPage')?.addEventListener('click', () => {
if (reportCurrentPage < totalPages) {
reportCurrentPage++;
renderReports();
}
});
document.querySelectorAll('#reportPagination .page-number').forEach(btn => {
btn.addEventListener('click', () => {
reportCurrentPage = parseInt(btn.dataset.page);
renderReports();
});
});
document.getElementById('reportJobsPerPage').addEventListener('change', (e) => {
reportJobsPerPage = parseInt(e.target.value);
reportCurrentPage = 1;
renderReports();
});
}
// Render history pagination (History tab)
function renderHistoryPagination(totalJobs) {
const pagination = document.getElementById('historyPagination');
const totalPages = Math.ceil(totalJobs / historyJobsPerPage);
historyCurrentPage = Math.min(historyCurrentPage, totalPages || 1);
const startJob = (historyCurrentPage - 1) * historyJobsPerPage + 1;
const endJob = Math.min(historyCurrentPage * historyJobsPerPage, totalJobs);
let html = `
<div class="flex items-center gap-4 text-sm text-gray-600">
<div>
<label for="historyJobsPerPage" class="mr-2">Jobs per page:</label>
<select id="historyJobsPerPage" class="jobs-per-page input-field rounded bg-white py-1 px-2 focus:ring-2 focus:ring-teal-400 hover:shadow-sm">
<option value="10" ${historyJobsPerPage === 10 ? 'selected' : ''}>10</option>
<option value="15" ${historyJobsPerPage === 15 ? 'selected' : ''}>15</option>
<option value="25" ${historyJobsPerPage === 25 ? 'selected' : ''}>25</option>
</select>
</div>
<div id="historyPaginationRange">
Showing ${totalJobs > 0 ? startJob : 0} to ${endJob} of ${totalJobs} jobs
</div>
</div>
<div class="flex gap-2 flex-wrap">
<button id="historyPrevPage" class="bg-teal-500 text-white hover:bg-teal-600 disabled:bg-gray-300" ${historyCurrentPage === 1 ? 'disabled' : ''} aria-label="Previous page">Previous</button>
<div class="flex gap-1">
`;
const maxPagesToShow = 5;
let startPage = Math.max(1, historyCurrentPage - Math.floor(maxPagesToShow / 2));
let endPage = Math.min(totalPages, startPage + maxPagesToShow - 1);
if (endPage - startPage + 1 < maxPagesToShow) {
startPage = Math.max(1, endPage - maxPagesToShow + 1);
}
if (startPage > 1) {
html += `<span class="page-number" data-page="1">1</span>`;
if (startPage > 2) html += `<span class="px-2">...</span>`;
}
for (let i = startPage; i <= endPage; i++) {
html += `<span class="page-number ${i === historyCurrentPage ? 'active' : ''}" data-page="${i}">${i}</span>`;
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) html += `<span class="px-2">...</span>`;
html += `<span class="page-number" data-page="${totalPages}">${totalPages}</span>`;
}
html += `
</div>
<button id="historyNextPage" class="bg-teal-500 text-white hover:bg-teal-600 disabled:bg-gray-300" ${historyCurrentPage === totalPages ? 'disabled' : ''} aria-label="Next page">Next</button>
</div>
`;
pagination.innerHTML = html;
document.getElementById('historyPrevPage')?.addEventListener('click', () => {
if (historyCurrentPage > 1) {
historyCurrentPage--;
renderHistory();
}
});
document.getElementById('historyNextPage')?.addEventListener('click', () => {
if (historyCurrentPage < totalPages) {
historyCurrentPage++;
renderHistory();
}
});
document.querySelectorAll('#historyPagination .page-number').forEach(btn => {
btn.addEventListener('click', () => {
historyCurrentPage = parseInt(btn.dataset.page);
renderHistory();
});
});
document.getElementById('historyJobsPerPage').addEventListener('change', (e) => {
historyJobsPerPage = parseInt(e.target.value);
historyCurrentPage = 1;
renderHistory();
});
}
// Render history (History tab)
function renderHistory() {
const historyTableBody = document.getElementById('historyTableBody');
function sanitizeTooltip(text) {
const div = document.createElement('div');
div.textContent = text || '';
return div.innerHTML.replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
}
let filteredHistory = jobs.filter(job =>
job.status === 'Completed' &&
(!reportFilters.startDate || new Date(job.completedDate) >= new Date(reportFilters.startDate)) &&
(!reportFilters.endDate || new Date(job.completedDate) <= new Date(reportFilters.endDate)) &&
(!reportFilters.search ||
job.job.toLowerCase().includes(reportFilters.search.toLowerCase()) ||
(job.remark && job.remark.toLowerCase().includes(reportFilters.search.toLowerCase()))) &&
(!reportFilters.department || job.department === reportFilters.department)
);
filteredHistory.sort((a, b) => {
let valA = a[historySortColumn];
let valB = b[historySortColumn];
if (historySortColumn === 'date' || historySortColumn === 'completedDate') {
valA = valA ? new Date(valA) : null;
valB = valB ? new Date(valB) : null;
if (!valA && !valB) return 0;
if (!valA) return 1;
if (!valB) return -1;
}
if (valA < valB) return historySortDirection === 'asc' ? -1 : 1;
if (valA > valB) return historySortDirection === 'asc' ? 1 : -1;
return 0;
});
const startIndex = (historyCurrentPage - 1) * historyJobsPerPage;
const endIndex = startIndex + historyJobsPerPage;
const paginatedHistory = filteredHistory.slice(startIndex, endIndex);
historyTableBody.innerHTML = paginatedHistory.length === 0
? '<tr><td colspan="4" class="px-6 py-4 text-center text-sm font-semibold text-gray-600">No completed jobs found.</td></tr>'
: paginatedHistory.map(job => `
<tr class="even:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.date}</td>
<td class="px-6 py-4 text-sm text-gray-800" title="${sanitizeTooltip(job.job)}">${job.job}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.department}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">${job.completedDate || '-'}</td>
</tr>
`).join('');
document.querySelectorAll('#historyTable .sortable').forEach(header => {
const arrow = header.querySelector('.sort-arrow');
arrow.innerHTML = '';
header.setAttribute('aria-sort', header.dataset.sort === historySortColumn ? (historySortDirection === 'asc' ? 'ascending' : 'descending') : 'none');
});
const activeArrow = document.querySelector(`#historyTable th[data-sort="${historySortColumn}"] .sort-arrow`);
if (activeArrow) activeArrow.innerHTML = historySortDirection === 'asc' ? '↑' : '↓';
renderHistoryPagination(filteredHistory.length);
}
// Tab switching (Reports page)
document.querySelectorAll('.tab-link').forEach(tab => {
tab.addEventListener('click', (e) => {
e.preventDefault();
document.querySelectorAll('.tab-link').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
activeDepartment = tab.dataset.department;
const isHistoryTab = activeDepartment === 'History';
document.getElementById('reportTable').classList.toggle('hidden', isHistoryTab);
document.getElementById('historyTableContainer').classList.toggle('hidden', !isHistoryTab);
document.getElementById('reportDepartmentFilter').classList.toggle('hidden', !isHistoryTab);
document.getElementById('reportPriorityFilter').classList.toggle('hidden', isHistoryTab);
document.getElementById('reportStatusFilter').classList.toggle('hidden', isHistoryTab);
if (isHistoryTab) {
reportFilters.status = 'Completed';
reportFilters.priority = '';
document.getElementById('reportStatus').value = 'Completed';
document.getElementById('reportPriority').value = '';
document.getElementById('reportPagination').classList.add('hidden');
document.getElementById('historyPagination').classList.remove('hidden');
historyCurrentPage = 1;
historyJobsPerPage = 15;
renderHistory();
} else {
reportFilters.status = '';
reportFilters.department = '';
document.getElementById('reportStatus').value = '';
document.getElementById('reportDepartment').value = '';
document.getElementById('reportPagination').classList.remove('hidden');
document.getElementById('historyPagination').classList.add('hidden');
reportCurrentPage = 1;
renderReports();
}
});
});
// Save status (Reports page)
document.getElementById('reportTableBody').addEventListener('click', (e) => {
if (e.target.classList.contains('save-btn')) {
const index = parseInt(e.target.dataset.index);
console.log('Save button clicked for index:', index);
const select = document.querySelector(`#reportTableBody select[data-index="${index}"]`);
if (!select) {
console.error('Status select not found for index:', index);
return;
}
const newStatus = select.value;
console.log('New status:', newStatus);
jobs[index].status = newStatus;
if (newStatus === 'Completed') {
const today = new Date().toISOString().split('T')[0];
jobs[index].completedDate = today;
console.log('Set completedDate to:', today);
} else {
delete jobs[index].completedDate;
console.log('Cleared completedDate for index:', index);
}
console.log('Updated job:', jobs[index]);
localStorage.setItem('jobs', JSON.stringify(jobs));
console.log('Saved to localStorage:', jobs);
renderReports();
renderJobs();
showToast('Status Updated Successfully');
}
});
// Date filter validation (Reports page)
document.getElementById('reportStartDate').addEventListener('change', (e) => {
reportFilters.startDate = e.target.value;
document.getElementById('reportEndDate').min = e.target.value;
if (reportFilters.endDate && reportFilters.endDate < e.target.value) {
reportFilters.endDate = '';
document.getElementById('reportEndDate').value = '';
document.getElementById('reportDateError').classList.add('hidden');
}
reportCurrentPage = 1;
if (activeDepartment === 'History') {
renderHistory();
} else {
renderReports();
}
});
document.getElementById('reportEndDate').addEventListener('change', (e) => {
reportFilters.endDate = e.target.value;
if (reportFilters.startDate && e.target.value < reportFilters.startDate) {
e.target.value = reportFilters.startDate;
reportFilters.endDate = reportFilters.startDate;
document.getElementById('reportDateError').classList.remove('hidden');
} else {
document.getElementById('reportDateError').classList.add('hidden');
}
reportCurrentPage = 1;
if (activeDepartment === 'History') {
renderHistory();
} else {
renderReports();
}
});
document.getElementById('reportPriority').addEventListener('change', (e) => {
reportFilters.priority = e.target.value;
reportCurrentPage = 1;
if (activeDepartment !== 'History') {
renderReports();
}
});
document.getElementById('reportJobType').addEventListener('change', (e) => {
reportFilters.jobType = e.target.value;
reportCurrentPage = 1;
if (activeDepartment === 'History') {
renderHistory();
} else {
renderReports();
}
});
document.getElementById('reportSearch').addEventListener('input', (e) => {
clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(() => {
reportFilters.search = e.target.value;
if (activeDepartment === 'History') {
historyCurrentPage = 1;
renderHistory();
} else {
reportCurrentPage = 1;
renderReports();
}
}, 300);
});
document.getElementById('reportStatus').addEventListener('change', (e) => {
reportFilters.status = e.target.value;
reportCurrentPage = 1;
if (activeDepartment !== 'History') {
renderReports();
}
});
document.getElementById('reportDepartment').addEventListener('change', (e) => {
reportFilters.department = e.target.value;
reportCurrentPage = 1;
if (activeDepartment === 'History') {
renderHistory();
}
});
document.getElementById('clearReportFilters').addEventListener('click', () => {
reportFilters = { startDate: '', endDate: '', priority: '', jobType: '', search: '', status: '', department: '' };
document.getElementById('reportStartDate').value = '';
document.getElementById('reportEndDate').value = '';
document.getElementById('reportEndDate').min = '';
document.getElementById('reportPriority').value = '';
document.getElementById('reportJobType').value = '';
document.getElementById('reportSearch').value = '';
document.getElementById('reportStatus').value = '';
document.getElementById('reportDepartment').value = '';
document.getElementById('reportDateError').classList.add('hidden');
reportCurrentPage = 1;
if (activeDepartment === 'History') {
renderHistory();
} else {
renderReports();
}
});
// Export jobs from Home page
document.getElementById('exportJobsHome').addEventListener('click', () => {
const filteredJobs = jobs.map((job, originalIndex) => ({ job, originalIndex }))
.filter(({ job }) => {
const jobDate = new Date(job.date);
const startDate = filters.startDate ? new Date(filters.startDate) : null;
const endDate = filters.endDate ? new Date(filters.endDate) : null;
const jobMatches = !filters.search ||
job.job.toLowerCase().includes(filters.search.toLowerCase()) ||
(job.remark && job.remark.toLowerCase().includes(filters.search.toLowerCase()));
return (
(!startDate || jobDate >= startDate) &&
(!endDate || jobDate <= endDate) &&
jobMatches &&
(!filters.department || job.department === filters.department) &&
(!filters.priority || job.priority === filters.priority) &&
(!filters.jobType || job.jobType === filters.jobType) &&
(!filters.notificationNo || job.notificationNo.toLowerCase().includes(filters.notificationNo.toLowerCase()))
);
});
const headers = ['Date', 'Job Description', 'Department', 'Priority', 'Job Type', 'Notification No', 'Remark', 'Status', 'Completion Date'];
const csvRows = [
headers.join(','),
...filteredJobs.map(({ job }) => [
`"${job.date}"`,
`"${job.job.replace(/"/g, '""')}"`,
`"${job.department}"`,
`"${job.priority}"`,
`"${job.jobType}"`,
`"${job.notificationNo}"`,
`"${(job.remark || '').replace(/"/g, '""')}"`,
`"${job.status}"`,
`"${job.completedDate || ''}"`
].join(','))
].join('\n');
const blob = new Blob([csvRows], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `jobs_home_${new Date().toISOString().split('T')[0]}.csv`;
a.click();
window.URL.revokeObjectURL(url);
});
// Export jobs from Reports page
document.getElementById('exportJobs').addEventListener('click', () => {
let filteredJobs;
let headers;
if (activeDepartment === 'History') {
filteredJobs = jobs.filter(job =>
job.status === 'Completed' &&
(!reportFilters.startDate || new Date(job.completedDate) >= new Date(reportFilters.startDate)) &&
(!reportFilters.endDate || new Date(job.completedDate) <= new Date(reportFilters.endDate)) &&
(!reportFilters.search ||
job.job.toLowerCase().includes(reportFilters.search.toLowerCase()) ||
(job.remark && job.remark.toLowerCase().includes(reportFilters.search.toLowerCase()))) &&
(!reportFilters.department || job.department === reportFilters.department)
);
headers = ['Date', 'Job Description', 'Department', 'Completion Date'];
} else {
filteredJobs = jobs.filter(job => {
const jobDate = new Date(job.date);
const startDate = reportFilters.startDate ? new Date(reportFilters.startDate) : null;
const endDate = reportFilters.endDate ? new Date(reportFilters.endDate) : null;
const searchMatch = !reportFilters.search ||
job.job.toLowerCase().includes(reportFilters.search.toLowerCase()) ||
(job.remark && job.remark.toLowerCase().includes(reportFilters.search.toLowerCase()));
return (
job.department === activeDepartment &&
(!startDate || jobDate >= startDate) &&
(!endDate || jobDate <= endDate) &&
(!reportFilters.priority || job.priority === reportFilters.priority) &&
(!reportFilters.jobType || job.jobType === reportFilters.jobType) &&
searchMatch &&
(!reportFilters.status || job.status === reportFilters.status)
);
});
headers = ['Date', 'Job Description', 'Priority', 'Job Type', 'Notification No', 'Remark', 'Completion Date', 'Status', 'Department'];
}
const csvRows = [
headers.join(','),
...filteredJobs.map(job => {
const row = [
`"${job.date}"`,
`"${job.job.replace(/"/g, '""')}"`
];
if (activeDepartment === 'History') {
row.push(`"${job.department}"`, `"${job.completedDate || ''}"`);
} else {
row.push(
`"${job.priority}"`,
`"${job.jobType}"`,
`"${job.notificationNo}"`,
`"${(job.remark || '').replace(/"/g, '""')}"`,
`"${job.completedDate || ''}"`,
`"${job.status}"`,
`"${job.department}"`
);
}
return row.join(',');
})
].join('\n');
const blob = new Blob([csvRows], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `jobs_${activeDepartment}_${new Date().toISOString().split('T')[0]}.csv`;
a.click();
window.URL.revokeObjectURL(url);
});
// Sorting for History table
document.querySelectorAll('#historyTable .sortable').forEach(header => {
header.addEventListener('click', () => {
const column = header.dataset.sort;
if (historySortColumn === column) {
historySortDirection = historySortDirection === 'asc' ? 'desc' : 'asc';
} else {
historySortColumn = column;
historySortDirection = 'asc';
}
historyCurrentPage = 1;
renderHistory();
});
});
// Sorting for Reports table
document.querySelectorAll('#reportTable .sortable').forEach(header => {
header.addEventListener('click', () => {
const column = header.dataset.sort;
if (reportSortColumn === column) {
reportSortDirection = reportSortDirection === 'asc' ? 'desc' : 'asc';
} else {
reportSortColumn = column;
reportSortDirection = 'asc';
}
reportCurrentPage = 1;
renderReports();
});
});
// Initial render
if (currentView === 'reports') {
renderReports();
} else {
resetForm();
renderJobs();
}
</script>
<!-- Toast Notification -->
<div id="toast" class="fixed top-4 right-4 z-50 hidden bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg transition-opacity duration-300">
<span id="toastMessage"></span>
</div>
</body>
</html>
<!-- Created by Vinod Rangi, DHT Unit Job Tracking v1.0, June 2025 --> |