Browse Source

added new files to hide the urls dynamically getting pages without switch case

master
AJITHKUMAR12 11 months ago
parent
commit
22711ce3f6
  1. 369
      src/main/java/com/gcc/coworkspace/controller/controller.java
  2. 13
      src/main/resources/templates/caretaker/login.html
  3. 20
      src/main/resources/templates/user/book-Conferance.html
  4. 28
      src/main/resources/templates/user/book-reading.html
  5. 1758
      src/main/resources/templates/user/book-workdesk.html
  6. 74
      src/main/resources/templates/user/home.html
  7. 41
      src/main/resources/templates/user/workspacelist.html

369
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<Map<String, Object>> 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<Map<String, Object>> pricingDetails = (cid != null)
? homeService.getPricingDetailsByCid(cid)
: List.of();*/
List<Map<String, Object>> readingZoneDetails = homeService.getPricingDetailsByCid(cid);
List<Map<String, Object>> deskSpaceDetails = homeService.getPricingDetailsByCid(cid);
List<Map<String, Object>> conferenceHallDetails = homeService.getPricingDetailsByCid(cid);
// ✅ Get category images for this category
List<Map<String, Object>> homeImg = (cid != null)
? homeService.getImgByCid(cid)
: List.of();
// ✅ Identify the selected space
Map<String, Object> 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<Map<String, Object>> 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<Map<String, Object>> pricingDetails = (cid != null)
// ? homeService.getPricingDetailsByCid(cid)
// : List.of();*/
// List<Map<String, Object>> readingZoneDetails = homeService.getPricingDetailsByCid(cid);
// List<Map<String, Object>> deskSpaceDetails = homeService.getPricingDetailsByCid(cid);
// List<Map<String, Object>> conferenceHallDetails = homeService.getPricingDetailsByCid(cid);
// // ✅ Get category images for this category
// List<Map<String, Object>> homeImg = (cid != null)
// ? homeService.getImgByCid(cid)
// : List.of();
// // ✅ Identify the selected space
// Map<String, Object> 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<Map<String, Object>> 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<Map<String, Object>> readingZoneDetails = homeService.getPricingDetailsByCid(cid);
List<Map<String, Object>> deskSpaceDetails = homeService.getPricingDetailsByCid(cid);
List<Map<String, Object>> conferenceHallDetails = homeService.getPricingDetailsByCid(cid);
// Images
List<Map<String, Object>> homeImg = (cid != null)
? homeService.getImgByCid(cid)
: List.of();
// Selected category
Map<String, Object> 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<Map<String, Object>> buildingCategoryDetails =
// buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId);
// //System.out.println("buildingCategoryDetails:" + buildingCategoryDetails);
// model.addAttribute("homeImg", homeService.getImgByCid(categoryId));
// if (!buildingCategoryDetails.isEmpty()) {
// Map<String, Object> 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<Map<String, Object>> buildingCategoryDetails =
buildingSer.getBuildingCategoryDetailsById(buildingId, categoryId);
//System.out.println("buildingCategoryDetails:" + buildingCategoryDetails);
model.addAttribute("homeImg", homeService.getImgByCid(categoryId));
String displayName = null;
if (!buildingCategoryDetails.isEmpty()) {
Map<String, Object> 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;
}

13
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);
}
}
}*/
</script>
</body>

20
src/main/resources/templates/user/book-Conferance.html

@ -273,7 +273,9 @@
<button type="button" id="viewBuildingBtn" class="btn btn-primary">Change</button>
</div>
<input type="hidden" id="buildingId" th:value="${buildingId}">
<input type="hidden" id="categoryId" th:value="${categoryId}">
<input type="hidden" id="subId" th:value="${subId}">
<!-- Date Picker -->
<div class="row mb-3">
<label style="font-weight:bold;" for="selectDate" class="col-sm-4 col-form-label text-end">Select Date :</label>
@ -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();

28
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 () {

1758
src/main/resources/templates/user/book-workdesk.html
File diff suppressed because it is too large
View File

74
src/main/resources/templates/user/home.html

@ -1155,7 +1155,10 @@
class="custom-tab-btn"
th:data-cid="${space.cid}"
th:data-bid="${space.bid}"
th:classappend="${space.cid} == cid ? ' active' "
th:classappend="${
(bid == 1 and space.cid == 1) or
(bid == 2 and space.cid == 4)
} ? ' active' : ''"
th:text="${space.display_name}">
</a>
</th:block>
@ -1673,14 +1676,73 @@ document.addEventListener('DOMContentLoaded', () => {
// window.location.href = "/muthalvarpadaippagam/book?buildingId=" + bid + "&categoryId=" + categoryId;
// }
function gotoBooking(bid, categoryId, subId) {
// console.log("bid",bid);
// function gotoBooking(bid, categoryId, subId) {
// // console.log("bid",bid);
// Construct the URL with all three parameters
const url = `/muthalvarpadaippagam/book?buildingId=${bid}&categoryId=${categoryId}&subId=${subId}`;
window.location.href = url;
// // Construct the URL with all three parameters
// const url = `/muthalvarpadaippagam/book?buildingId=${bid}&categoryId=${categoryId}&subId=${subId}`;
// window.location.href = url;
// }
// function gotoBooking(bid, categoryId, subId) {
// const form = document.createElement("form");
// form.method = "POST";
// form.action = "/muthalvarpadaippagam/book";
// // buildingId
// const b = document.createElement("input");
// b.type = "hidden";
// b.name = "buildingId";
// b.value = bid;
// form.appendChild(b);
// // categoryId
// const c = document.createElement("input");
// c.type = "hidden";
// c.name = "categoryId";
// c.value = categoryId;
// form.appendChild(c);
// // subId
// const s = document.createElement("input");
// s.type = "hidden";
// s.name = "subId";
// s.value = subId;
// form.appendChild(s);
// document.body.appendChild(form);
// form.submit();
// }
function gotoBooking(bid, categoryId, subId) {
const form = document.createElement("form");
form.method = "POST";
form.action = "/muthalvarpadaippagam/book";
form.appendChild(hidden("buildingId", bid));
form.appendChild(hidden("categoryId", categoryId));
form.appendChild(hidden("subId", subId));
document.body.appendChild(form);
form.submit();
}
function hidden(name, value) {
const input = document.createElement("input");
input.type = "hidden";
input.name = name;
input.value = value;
return input;
}
//to scroll down the content
function scrollToContainer() {

41
src/main/resources/templates/user/workspacelist.html

@ -1739,10 +1739,17 @@ function loadBuildings() {
</p>
</div>
<button class="btn btn-primary w-100 mt-auto fw-semibold"
<!--<button class="btn btn-primary w-100 mt-auto fw-semibold"
onclick="showSpaceTabs(${b.bid}, ${b.cid})">
View Details
</button>
</button>-->
<button class="btn w-100 mt-auto fw-semibold"
style="background-color:#15455D; color:white; border:none;"
onmouseover="this.style.backgroundColor='#0F3447'"
onmouseout="this.style.backgroundColor='#15455D'"
onclick="showSpaceTabs(${b.bid}, ${b.cid})">
View Details
</button>
</div>
</div>
@ -1758,12 +1765,38 @@ function loadBuildings() {
}
// function showSpaceTabs(bid, cid) {
// //console.log("Redirecting with bid:", bid, "and cid:", cid);
// window.location.href = `/muthalvarpadaippagam/home?bid=${bid}&cid=${cid}`;
// }
function showSpaceTabs(bid, cid) {
//console.log("Redirecting with bid:", bid, "and cid:", cid);
window.location.href = `/muthalvarpadaippagam/home?bid=${bid}&cid=${cid}`;
const form = document.createElement("form");
form.method = "POST";
form.action = "/muthalvarpadaippagam/home";
form.appendChild(hidden("bid", bid));
form.appendChild(hidden("cid", cid));
document.body.appendChild(form);
form.submit();
}
function hidden(name, value) {
const input = document.createElement("input");
input.type = "hidden";
input.name = name;
input.value = value;
return input;
}
// ✅ Redirect function
// function showSpaceTabs(bid, cid = 2) {
// console.log("Redirecting with bid:", bid, "and cid:", cid);

Loading…
Cancel
Save