From 22711ce3f659ddc0b54742288aa2dd5c6993343b Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 Date: Tue, 18 Nov 2025 16:36:25 +0530 Subject: [PATCH] added new files to hide the urls dynamically getting pages without switch case --- .../coworkspace/controller/controller.java | 369 +++- .../resources/templates/caretaker/login.html | 13 +- .../templates/user/book-Conferance.html | 20 +- .../templates/user/book-reading.html | 28 +- .../templates/user/book-workdesk.html | 1758 +++++++++-------- src/main/resources/templates/user/home.html | 74 +- .../templates/user/workspacelist.html | 41 +- 7 files changed, 1372 insertions(+), 931 deletions(-) diff --git a/src/main/java/com/gcc/coworkspace/controller/controller.java b/src/main/java/com/gcc/coworkspace/controller/controller.java index 06a852f..ff41a3f 100644 --- a/src/main/java/com/gcc/coworkspace/controller/controller.java +++ b/src/main/java/com/gcc/coworkspace/controller/controller.java @@ -11,6 +11,7 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @@ -180,70 +181,146 @@ public String viewWorkspaceList(Model model) { // } - @GetMapping("/home") -public String viewHome(@RequestParam int bid, - @RequestParam(value = "cid", required = false) Integer cidParam, - Model model) { - // ✅ Get coworking spaces for this building - List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); +@GetMapping("/home") +public String viewHomeGet(@RequestParam(value = "bid", required = false) Integer bid, + @RequestParam(value = "cid", required = false) Integer cidParam, + Model model) { + if (bid == null) { + return "redirect:/muthalvarpadaippagam"; // or show error page + } + + return loadHomePage(bid, cidParam, model); +} + // POST – used by hidden form (no URL params visible!) + @PostMapping("/home") + public String viewHomePost(@RequestParam int bid, + @RequestParam(value = "cid", required = false) Integer cidParam, + Model model) { + return loadHomePage(bid, cidParam, model); + } - //System.out.println("home inside:" + spaces); - - // Remove duplicate category rows (keep first per cid) -spaces = spaces.stream() - .collect(Collectors.toMap( - m -> (Integer) m.get("cid"), - m -> m, - (existing, replacement) -> existing - )) - .values() - .stream() - .toList(); - // ✅ Default CID → first space of that building - Integer cid = (cidParam != null) - ? cidParam - : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); - - // ✅ Get subcategory (pricing/capacity) details for this category - /*List> pricingDetails = (cid != null) - ? homeService.getPricingDetailsByCid(cid) - : List.of();*/ - List> readingZoneDetails = homeService.getPricingDetailsByCid(cid); - List> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); - List> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); - - // ✅ Get category images for this category - List> homeImg = (cid != null) - ? homeService.getImgByCid(cid) - : List.of(); - - // ✅ Identify the selected space - Map selectedSpace = spaces.stream() - .filter(space -> cid != null && cid.equals(space.get("cid"))) - .findFirst() - .orElse(null); - //ak + + +// previously used +// @GetMapping("/home") +// public String viewHome(@RequestParam int bid, +// @RequestParam(value = "cid", required = false) Integer cidParam, +// Model model) { + +// // ✅ Get coworking spaces for this building +// List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); + + +// //System.out.println("home inside:" + spaces); + +// // Remove duplicate category rows (keep first per cid) +// spaces = spaces.stream() +// .collect(Collectors.toMap( +// m -> (Integer) m.get("cid"), +// m -> m, +// (existing, replacement) -> existing +// )) +// .values() +// .stream() +// .toList(); +// // ✅ Default CID → first space of that building +// Integer cid = (cidParam != null) +// ? cidParam +// : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); + +// // ✅ Get subcategory (pricing/capacity) details for this category +// /*List> pricingDetails = (cid != null) +// ? homeService.getPricingDetailsByCid(cid) +// : List.of();*/ +// List> readingZoneDetails = homeService.getPricingDetailsByCid(cid); +// List> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); +// List> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); + +// // ✅ Get category images for this category +// List> homeImg = (cid != null) +// ? homeService.getImgByCid(cid) +// : List.of(); + +// // ✅ Identify the selected space +// Map selectedSpace = spaces.stream() +// .filter(space -> cid != null && cid.equals(space.get("cid"))) +// .findFirst() +// .orElse(null); +// //ak - // ✅ Add everything to model - model.addAttribute("bid", bid); - model.addAttribute("cid", cid); - model.addAttribute("spaces", spaces); - System.out.println("spaces:" + spaces); - model.addAttribute("selectedSpace", selectedSpace); - //model.addAttribute("pricingDetails", pricingDetails); - model.addAttribute("readingZoneDetails", readingZoneDetails); - model.addAttribute("deskSpaceDetails", deskSpaceDetails); - model.addAttribute("conferenceHallDetails", conferenceHallDetails); - model.addAttribute("homeImg", homeImg); +// // ✅ Add everything to model +// model.addAttribute("bid", bid); +// model.addAttribute("cid", cid); +// model.addAttribute("spaces", spaces); +// System.out.println("spaces:" + spaces); +// model.addAttribute("selectedSpace", selectedSpace); +// //model.addAttribute("pricingDetails", pricingDetails); +// model.addAttribute("readingZoneDetails", readingZoneDetails); +// model.addAttribute("deskSpaceDetails", deskSpaceDetails); +// model.addAttribute("conferenceHallDetails", conferenceHallDetails); +// model.addAttribute("homeImg", homeImg); - return "user/home"; -} +// return "user/home"; +// } + + + + // 🔥 Reusable method + private String loadHomePage(int bid, Integer cidParam, Model model) { + + // Get coworking spaces for this building + List> spaces = homeService.getActiveCoWorkingSpacesByBuilding(bid); + + // Remove duplicate CIDs + spaces = spaces.stream() + .collect(Collectors.toMap( + m -> (Integer) m.get("cid"), + m -> m, + (existing, replacement) -> existing + )) + .values() + .stream() + .toList(); + + // Default CID + Integer cid = (cidParam != null) + ? cidParam + : (spaces.isEmpty() ? null : (Integer) spaces.get(0).get("cid")); + + // Pricing details + List> readingZoneDetails = homeService.getPricingDetailsByCid(cid); + List> deskSpaceDetails = homeService.getPricingDetailsByCid(cid); + List> conferenceHallDetails = homeService.getPricingDetailsByCid(cid); + + // Images + List> homeImg = (cid != null) + ? homeService.getImgByCid(cid) + : List.of(); + + // Selected category + Map selectedSpace = spaces.stream() + .filter(space -> cid != null && cid.equals(space.get("cid"))) + .findFirst() + .orElse(null); + + // Add to model + model.addAttribute("bid", bid); + model.addAttribute("cid", cid); + model.addAttribute("spaces", spaces); + model.addAttribute("selectedSpace", selectedSpace); + model.addAttribute("readingZoneDetails", readingZoneDetails); + model.addAttribute("deskSpaceDetails", deskSpaceDetails); + model.addAttribute("conferenceHallDetails", conferenceHallDetails); + model.addAttribute("homeImg", homeImg); + + return "user/home"; // Thymeleaf view + } //ak @GetMapping("/api/pricing") @@ -529,59 +606,183 @@ public String getSpaceFragment(@RequestParam("cid") Integer cid, - @GetMapping("/book") -public String showCategoryPage(@RequestParam int buildingId, - @RequestParam int categoryId, +//////////existing code for /book with subId handling + +// @GetMapping("/book") +// public String getCategoryPageGet(@RequestParam(value = "buildingId", required = false) Integer buildingId, +// @RequestParam(value = "categoryId", required = false) Integer categoryId, +// @RequestParam(value = "subId", required = false) Integer subId, +// Model model) { + +// // Validate required fields +// if (buildingId == null || categoryId == null) { +// return "redirect:/muthalvarpadaippagam"; // Return home safely +// } + +// return showCategoryPage(buildingId, categoryId, subId, model); +// } + + +// //added by yogi +// @PostMapping("/book") +// public String showCategoryPagePost(@RequestParam int buildingId, +// @RequestParam int categoryId, +// @RequestParam(required = false) Integer subId, +// Model model) { + +// return showCategoryPage(buildingId, categoryId, subId, model); +// } + + + + + + + +// @GetMapping("/book") +// public String showCategoryPage(@RequestParam int buildingId, +// @RequestParam int categoryId, +// @RequestParam(required = false) Integer subId, +// Model model) { +// // System.out.println("buildingId:" + buildingId); +// // System.out.println("categoryId:" + categoryId); + +// List> buildingCategoryDetails = +// buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); +// //System.out.println("buildingCategoryDetails:" + buildingCategoryDetails); + +// model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); + +// if (!buildingCategoryDetails.isEmpty()) { +// Map firstRecord = buildingCategoryDetails.get(0); +// model.addAttribute("details", firstRecord); +// //ak +// Object buildingName = firstRecord.get("Building_Name"); +// Object buildingAddress = firstRecord.get("Address"); +// Object latitude = firstRecord.get("Latitude"); +// Object longitude = firstRecord.get("Longitude"); + +// model.addAttribute("buildingName", buildingName); +// model.addAttribute("buildingAddress", buildingAddress); +// model.addAttribute("latitude", latitude); +// model.addAttribute("longitude", longitude); + +// // ✅ Prefer URL parameter subId, else fallback from DB +// if (subId == null) { +// Object scidObj = firstRecord.get("scid"); +// subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; +// } + +// model.addAttribute("subId", subId); +// System.out.println("SubId: " + subId); +// } + +// model.addAttribute("buildingId", buildingId); +// model.addAttribute("categoryId", categoryId); + +// String url = switch (categoryId) { +// case 1 -> "user/book-reading"; +// case 2 -> "user/book-workdesk"; +// case 3 -> "user/book-Conferance"; +// case 4 -> "user/book-reading"; +// default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); +// }; + +// return url; +// } + + +// --------------------- GET : Visible URL --------------------- +@GetMapping("/book") +public String getCategoryPage(@RequestParam(value = "buildingId" ,required = false) Integer buildingId, + @RequestParam(value = "categoryId", required = false) Integer categoryId, + @RequestParam(value = "subId", required = false) Integer subId, Model model) { + + // Validate required fields + if (buildingId == null || categoryId == null) { + return "redirect:/muthalvarpadaippagam"; + } + + return showCategoryPage(buildingId, categoryId, subId, model); +} + + + +// --------------------- POST : Hidden Form (no URL params) --------------------- +@PostMapping("/book") +public String postCategoryPage(@RequestParam Integer buildingId, + @RequestParam Integer categoryId, @RequestParam(required = false) Integer subId, Model model) { - // System.out.println("buildingId:" + buildingId); - // System.out.println("categoryId:" + categoryId); + + return showCategoryPage(buildingId, categoryId, subId, model); +} + + + + +// --------------------- COMMON LOADING METHOD --------------------- +private String showCategoryPage(int buildingId, + int categoryId, + Integer subId, + Model model) { List> buildingCategoryDetails = buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId); - //System.out.println("buildingCategoryDetails:" + buildingCategoryDetails); model.addAttribute("homeImg", homeService.getImgByCid(categoryId)); + String displayName = null; + + if (!buildingCategoryDetails.isEmpty()) { + + Map firstRecord = buildingCategoryDetails.get(0); + displayName = (String) firstRecord.get("Category_Display_Name"); + model.addAttribute("details", firstRecord); - //ak - Object buildingName = firstRecord.get("Building_Name"); - Object buildingAddress = firstRecord.get("Address"); - Object latitude = firstRecord.get("Latitude"); - Object longitude = firstRecord.get("Longitude"); - - model.addAttribute("buildingName", buildingName); - model.addAttribute("buildingAddress", buildingAddress); - model.addAttribute("latitude", latitude); - model.addAttribute("longitude", longitude); - - // ✅ Prefer URL parameter subId, else fallback from DB + + model.addAttribute("buildingName", firstRecord.get("Building_Name")); + model.addAttribute("buildingAddress", firstRecord.get("Address")); + model.addAttribute("latitude", firstRecord.get("Latitude")); + model.addAttribute("longitude", firstRecord.get("Longitude")); + + // If subId is not passed, get from DB if (subId == null) { Object scidObj = firstRecord.get("scid"); subId = (scidObj != null) ? Integer.parseInt(scidObj.toString()) : 0; } - model.addAttribute("subId", subId); - System.out.println("SubId: " + subId); } model.addAttribute("buildingId", buildingId); model.addAttribute("categoryId", categoryId); - String url = switch (categoryId) { - case 1 -> "user/book-reading"; - case 2 -> "user/book-workdesk"; - case 3 -> "user/book-Conferance"; - case 4 -> "user/book-reading"; - default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); - }; + // Select page by category + // return switch (categoryId) { + // case 1 -> "user/book-reading"; + // case 2 -> "user/book-workdesk"; + // case 3 -> "user/book-Conferance"; + // case 4 -> "user/book-reading"; + // default -> throw new IllegalArgumentException("Invalid category ID: " + categoryId); + // }; - return url; -} + if (displayName == null) { + throw new IllegalArgumentException("Category name not found"); + } + + String url = switch (displayName.trim()) { + case "Meeting Rooms" -> "user/book-Conferance"; + case "Learning Centre" -> "user/book-reading"; + case "Desk Space" -> "user/book-workdesk"; + default -> throw new IllegalArgumentException("Unknown Category Name: " + displayName); + }; + + return url; +} diff --git a/src/main/resources/templates/caretaker/login.html b/src/main/resources/templates/caretaker/login.html index 20bd548..7cd3c5a 100644 --- a/src/main/resources/templates/caretaker/login.html +++ b/src/main/resources/templates/caretaker/login.html @@ -139,7 +139,8 @@ function login() { } else { // If login is successful, redirect //redirectToDashboard(response); - redirectToDashboard(response.user_name, response.bid); + // redirectToDashboard(response.user_name, response.bid); + window.location.href = "/muthalvarpadaippagam/Dashboard"; } }).fail(function (jqXHR) { // Handle AJAX errors based on status @@ -148,9 +149,9 @@ function login() { } else if (jqXHR.status === 417) { // Show SweetAlert for unexpected errors Swal.fire({ - icon: 'error', - title: 'Error', - text: jqXHR.responseText, + icon: 'info', + title: 'info', + text: 'Invalid Username or Password. Please enter the correct details!', }); } else { console.error(jqXHR); @@ -176,7 +177,7 @@ function login() { // added by yogi - function redirectToDashboard(userName, bid) { + /* function redirectToDashboard(userName, bid) { //console.log("Logged in user:", userName); //console.log("User BID:", bid); @@ -190,7 +191,7 @@ function login() { default: console.error("Invalid user:", userName); } -} +}*/ diff --git a/src/main/resources/templates/user/book-Conferance.html b/src/main/resources/templates/user/book-Conferance.html index 99346c5..094faa2 100644 --- a/src/main/resources/templates/user/book-Conferance.html +++ b/src/main/resources/templates/user/book-Conferance.html @@ -273,7 +273,9 @@ - + + +
@@ -521,10 +523,15 @@ const bookedSlots = ['9:00 AM', '6:00 PM', '8:00 PM']; // Sample booked slots, will show in red - const urlParams = new URLSearchParams(window.location.search); - const catId = urlParams.get('categoryId'); - const buildId = urlParams.get('buildingId'); - const subId = urlParams.get('subId'); +// const urlParams = new URLSearchParams(window.location.search); +// const catId = urlParams.get('categoryId'); +// const buildId = urlParams.get('buildingId'); +// const subId = urlParams.get('subId'); + + +const buildId = document.getElementById("#buildingId") +const catId = document.getElementById("#categoryId") +let subId = document.getElementById("#subId") // console.log("Category ID:", catId); // console.log("Building ID:", buildId); @@ -723,6 +730,9 @@ let name = $('#personName').val(); let phone = $('#personPhone').val(); let fromDate = $('#selectDate').val(); // Ensure this is a different element + let subId = $('#subId').val(); + let buildId = $('#buildingId').val(); + let catId = $('#categoryId').val(); let toDate = $('#selectDate').val(); // Ensure this is a different element let selectedSlot = $('#selectedSlot').val(); let noOfPeople = $('#numSeats').val(); diff --git a/src/main/resources/templates/user/book-reading.html b/src/main/resources/templates/user/book-reading.html index 54d678e..45bf107 100644 --- a/src/main/resources/templates/user/book-reading.html +++ b/src/main/resources/templates/user/book-reading.html @@ -472,14 +472,17 @@ // Read URL parameters - const urlParams = new URLSearchParams(window.location.search); - const catId = urlParams.get('categoryId'); - const buildId = urlParams.get('buildingId'); - let subId = urlParams.get('subId'); - -// console.log("Category ID:", catId); -// console.log("Building ID:", buildId); -// console.log("Sub ID:", subId); +// const urlParams = new URLSearchParams(window.location.search); +// const catId = urlParams.get('categoryId'); +// const buildId = urlParams.get('buildingId'); +// let subId = urlParams.get('subId'); + + + const buildId = document.getElementById("#buildingId") + const catId = document.getElementById("#categoryId") + let subId = document.getElementById("#subId") + + let slots =[]; @@ -641,6 +644,7 @@ function loadTimeSlots(selectedDate) { } return isValid; } + function saveBooking() { // console.log(catId); @@ -667,6 +671,9 @@ function loadTimeSlots(selectedDate) { let name = $('#personName').val(); let phone = $('#personPhone').val(); let fromDate = $('#selectDate').val(); // Ensure this is a different element + let subId = $('#subId').val(); + let buildId = $('#buildingId').val(); + let catId = $('#categoryId').val(); let toDate = $('#selectDate').val(); // Ensure this is a different element let selectedSlot = $('#selectedSlot').val(); let noOfPeople = $('#numSeats').val(); @@ -722,6 +729,11 @@ function loadTimeSlots(selectedDate) { }); } + + + + + //date valisdation /* $(document).ready(function () { diff --git a/src/main/resources/templates/user/book-workdesk.html b/src/main/resources/templates/user/book-workdesk.html index 8edabbf..b92d9d9 100644 --- a/src/main/resources/templates/user/book-workdesk.html +++ b/src/main/resources/templates/user/book-workdesk.html @@ -1,42 +1,44 @@ +
+ - -
- -
-
- - - -
- -
-
- -
-
-
- -