You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
8.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3. <html xmlns:th="http://www.thymeleaf.org">
  4. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  5. <style>
  6. body {
  7. background-color: #f8f9fa;
  8. }
  9. .header {
  10. font-size: 22px;
  11. font-weight: bold;
  12. margin-bottom: 20px;
  13. }
  14. .table {
  15. border: 1px solid #dee2e6;
  16. }
  17. .table th,
  18. .table td {
  19. border: 1px solid #dee2e6;
  20. padding: 10px;
  21. }
  22. .section-title {
  23. font-size: 18px;
  24. font-weight: bold;
  25. margin-top: 20px;
  26. border-bottom: 2px solid #007bff;
  27. padding-bottom: 5px;
  28. }
  29. .form-group {
  30. margin-top: 15px;
  31. }
  32. .radio-group {
  33. display: flex;
  34. gap: 20px;
  35. margin-top: 10px;
  36. }
  37. /* 🆕 Added Styles for Better Layout */
  38. .card {
  39. padding: 20px;
  40. border-radius: 10px;
  41. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  42. margin-bottom: 20px;
  43. background-color: white;
  44. }
  45. .card .row {
  46. margin-top: 10px;
  47. }
  48. .card .col-md-3 {
  49. margin-bottom: 15px;
  50. }
  51. .form-control {
  52. border-radius: 5px;
  53. }
  54. /* 🆕 Centering the Filter Button */
  55. .text-center {
  56. text-align: center;
  57. }
  58. </style>
  59. <body>
  60. <div class="wrapper">
  61. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  62. <div class="page-wrap">
  63. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  64. <div class="main-content">
  65. <div class="container">
  66. <div class="header">School Module - Dashboard</div>
  67. <hr style="border: 1px solid #ccc; margin-top: 10px; margin-bottom: 20px;">
  68. <!-- Card 1: School Information -->
  69. <div class="col-md-12">
  70. <div class="card">
  71. <div class="row">
  72. <div class="col-md-3">
  73. <label>Search with UDISE Number</label>
  74. <select class="form-control" id="udiseDropdown">
  75. <option value="">Select UDISE Number</option>
  76. </select>
  77. </div>
  78. <div class="col-md-3">
  79. <label>Category</label>
  80. <select class="form-control" id="categoryDropdown">
  81. <option value="">Select Category</option>
  82. </select>
  83. </div>
  84. <div class="col-md-3">
  85. <label>Zone</label>
  86. <select class="form-control" id="zoneDropdown">
  87. <option value="">Select Zone</option>
  88. </select>
  89. </div>
  90. <div class="col-md-3">
  91. <label>Ward</label>
  92. <select class="form-control" id="wardDropdown">
  93. <option value="">Select Ward</option>
  94. </select>
  95. </div>
  96. </div> <!-- Row End -->
  97. <!-- Centered Filter Button -->
  98. <div class="row mt-3">
  99. <div class="col-12 text-center">
  100. <button id="filterButton" class="btn btn-primary " style="background-color: #0D587B;">Filter</button>
  101. <button id="resetButton" class="btn btn-secondary">Reset</button>
  102. </div>
  103. </div>
  104. </div> <!-- Card End -->
  105. </div> <!-- Col-md-12 End -->
  106. <!-- 🆕 DataTable -->
  107. <div class="card">
  108. <div class="table-responsive">
  109. <input type="hidden" id="loggedUserId" th:value="${user_id}">
  110. <table id="schoolTable" class="table table-bordered table-striped">
  111. <thead class="thead-dark">
  112. <tr>
  113. <th>S.No</th>
  114. <th>UDISE Number</th>
  115. <th>Name</th>
  116. <th>Category</th>
  117. <th>Zone</th>
  118. <th>Ward</th>
  119. <th>Address</th>
  120. </tr>
  121. </thead>
  122. <tbody id="schoolTableBody">
  123. <!-- Rows will be populated by JS -->
  124. </tbody>
  125. </table>
  126. </div>
  127. </div> <!-- DataTable Card End -->
  128. </div> <!-- Container End -->
  129. </div> <!-- Main Content End -->
  130. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  131. </div>
  132. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  133. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  134. <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
  135. <script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap5.min.js"></script>
  136. <!-- 🆕 DataTable Initialization Script -->
  137. <script>
  138. $(document).ready(function () {
  139. $('#schoolTable').DataTable({
  140. paging: true,
  141. responsive: false,
  142. searching: true,
  143. select: false,
  144. processing: false,
  145. ordering: true,
  146. info: true,
  147. language: {
  148. zeroRecords: "No schools found for this user.",
  149. emptyTable: "No data available in table"
  150. }
  151. });
  152. });
  153. function loadDropdown(userId, type, dropdownId, placeholderText) {
  154. $.ajax({
  155. url: "/gcc/api/gccschool/dropdown/getAllDropdownValues",
  156. method: "GET",
  157. data: { user_id: userId, type: type },
  158. success: function (response) {
  159. console.log(`Dropdown (${type}) response:`, response);
  160. let dropdown = $(`#${dropdownId}`);
  161. dropdown.empty().append(`<option value="">${placeholderText}</option>`);
  162. if (response[0].Message === "Success" && response[0].Data.length > 0) {
  163. response[0].Data.forEach(item => {
  164. dropdown.append(`<option value="${item}">${item}</option>`);
  165. });
  166. }
  167. },
  168. error: function () {
  169. alert(`Failed to load ${type} dropdown`);
  170. }
  171. });
  172. }
  173. $('#filterButton').click(function () {
  174. const userId = $('#loggedUserId').val();
  175. const udise = $('#udiseDropdown').val();
  176. const category = $('#categoryDropdown').val();
  177. const zone = $('#zoneDropdown').val();
  178. const ward = $('#wardDropdown').val();
  179. $.ajax({
  180. url: '/gcc/api/gccschool/schoolproperty/filterSchools',
  181. method: 'GET',
  182. data: {
  183. user_id: userId,
  184. udise: udise,
  185. category: category,
  186. zone: zone,
  187. ward: ward
  188. },
  189. success: function (response) {
  190. const table = $('#schoolTable').DataTable();
  191. table.clear();
  192. if (response.length > 0 && response[0].Message === "Success" && response[0].Data.length > 0) {
  193. let schoolList = response[0].Data;
  194. schoolList.forEach((school, index) => {
  195. table.row.add([
  196. index + 1,
  197. school.udise || '',
  198. school.school_name || '',
  199. school.category || '',
  200. school.zone || '',
  201. school.division || '',
  202. school.address || ''
  203. ]);
  204. });
  205. }
  206. table.draw(); // Draw table whether data exists or not
  207. },
  208. error: function () {
  209. alert("Error fetching filtered school data.");
  210. }
  211. });
  212. });
  213. $('#filterButton').click(function () {
  214. filterSchools(); // Call the function on button click
  215. });
  216. function loadSchoolsForUser(userId) {
  217. $.ajax({
  218. url: "/gcc/api/gccschool/schoolproperty/getLoginDetails",
  219. method: "GET",
  220. data: { user_id: userId },
  221. success: function (response) {
  222. if (response.length > 0 && response[0].Message === "Success") {
  223. let schoolList = response[0].Data;
  224. // Destroy and reinitialize the DataTable with createdRow
  225. if ($.fn.DataTable.isDataTable('#schoolTable')) {
  226. $('#schoolTable').DataTable().destroy();
  227. }
  228. const table = $('#schoolTable').DataTable({
  229. createdRow: function (row, data, dataIndex) {
  230. $(row).attr("onclick", `redirectToDetails(${schoolList[dataIndex].id})`);
  231. }
  232. });
  233. table.clear();
  234. schoolList.forEach((school, index) => {
  235. table.row.add([
  236. index + 1,
  237. school.udise || '',
  238. school.school_name || '',
  239. school.category || '',
  240. school.zone || '',
  241. school.division || '',
  242. school.address || ''
  243. ]);
  244. });
  245. table.draw();
  246. } else {
  247. alert("No schools found for this user.");
  248. }
  249. },
  250. error: function () {
  251. alert("Failed to load schools.");
  252. }
  253. });
  254. }
  255. // ⏬ Call this on page load with the logged-in user's ID
  256. $(document).ready(function () {
  257. const userId = $('#loggedUserId').val();
  258. loadSchoolsForUser(userId);
  259. loadDropdown(userId, 'udise', 'udiseDropdown', 'Select UDISE Number');
  260. loadDropdown(userId, 'category', 'categoryDropdown', 'Select Category');
  261. loadDropdown(userId, 'zone', 'zoneDropdown', 'Select Zone');
  262. loadDropdown(userId, 'ward', 'wardDropdown', 'Select Ward');
  263. // $('#schoolTable').DataTable();
  264. });
  265. function redirectToDetails(schoolId) {
  266. window.location.href = "/gcc/school/otherdetails?schoolId=" + schoolId;
  267. }
  268. $('#resetButton').click(function () {
  269. location.reload(); // This will reload the entire page
  270. });
  271. </script>
  272. </body>
  273. </html>