Update Welcome.jsp
This commit is contained in:
parent
859f0b8898
commit
e926900dd5
276
Welcome.jsp
276
Welcome.jsp
@ -1,136 +1,150 @@
|
||||
<!-- filepath: /webapp/assignCapabilities.jsp -->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Assign Capabilities</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Assign Capabilities to User</h1>
|
||||
<form action="assignCapabilities" method="post">
|
||||
<label for="userId">User ID:</label>
|
||||
<input type="text" id="userId" name="userId" required><br><br>
|
||||
|
||||
<label for="roleId">Role:</label>
|
||||
<select id="roleId" name="roleId" required>
|
||||
<option value="Teller">Teller</option>
|
||||
<option value="Manager">Manager</option>
|
||||
<option value="Supervisor">Supervisor</option>
|
||||
<option value="CMO">CMO</option>
|
||||
<option value="CMD">CMD</option>
|
||||
</select><br><br>
|
||||
|
||||
<label for="screenIds">Screens:</label><br>
|
||||
<button type="button" onclick="openScreenSelectionPopup()">Select Screens</button>
|
||||
<div id="selectedScreens">
|
||||
<!-- Selected screens will be displayed here -->
|
||||
</div>
|
||||
|
||||
<script>
|
||||
window.onload = function () {
|
||||
fetchUserData();
|
||||
async function fetchAndDisplayScreens() {
|
||||
// Fetch screen names from the database
|
||||
const response = await fetch('/getScreens');
|
||||
const screens = await response.json();
|
||||
|
||||
// Display the screens as checkboxes directly on the page
|
||||
const screenContainer = document.createElement('div');
|
||||
screenContainer.id = 'screenContainer';
|
||||
|
||||
screenContainer.innerHTML = `
|
||||
<h3>Select Screens</h3>
|
||||
${screens.map(screen => `
|
||||
<label><input type="checkbox" value="${screen.id}"> ${screen.name}</label><br>
|
||||
`).join('')}
|
||||
<br>
|
||||
<button id="saveScreens">Save</button>
|
||||
`;
|
||||
|
||||
// Append the screen container to the selectedScreens div
|
||||
const selectedScreensDiv = document.getElementById('selectedScreens');
|
||||
selectedScreensDiv.innerHTML = ''; // Clear any previous content
|
||||
selectedScreensDiv.appendChild(screenContainer);
|
||||
|
||||
// Add event listener to save selected screens
|
||||
document.getElementById('saveScreens').onclick = function () {
|
||||
const selectedScreens = [];
|
||||
const checkboxes = screenContainer.querySelectorAll('input[type="checkbox"]:checked');
|
||||
checkboxes.forEach(checkbox => {
|
||||
selectedScreens.push(checkbox.value);
|
||||
});
|
||||
|
||||
// Display selected screens in the div
|
||||
selectedScreensDiv.innerHTML = selectedScreens.map(screen => `<p>${screen}</p>`).join('');
|
||||
};
|
||||
|
||||
function fetchUserData() {
|
||||
$.ajax({
|
||||
url: "/IFSS/TicketServlet",
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
populateUserDropdown(data);
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error fetching data: " + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function populateUserDropdown(users) {
|
||||
let dropdown = document.getElementById("userDropdown");
|
||||
users.forEach(user => {
|
||||
let option = document.createElement("option");
|
||||
option.value = user.user_id;
|
||||
option.textContent = "User_" + user.user_id;
|
||||
dropdown.appendChild(option);
|
||||
});
|
||||
|
||||
// Add event listener for dropdown change
|
||||
dropdown.addEventListener("change", function () {
|
||||
let selectedUserId = this.value;
|
||||
let selectedUser = users.find(user => user.user_id == selectedUserId);
|
||||
displayUserCharts(selectedUser);
|
||||
});
|
||||
}
|
||||
|
||||
function displayUserCharts(user) {
|
||||
let container = document.getElementById("userDashboard");
|
||||
container.innerHTML = ""; // Clear previous charts
|
||||
|
||||
// Create doughnut chart container
|
||||
let doughnutChartContainer = document.createElement("div");
|
||||
doughnutChartContainer.classList.add("chart-container");
|
||||
|
||||
let doughnutTitle = document.createElement("h3");
|
||||
doughnutTitle.textContent = "User_" + user.user_id + " - Doughnut Chart";
|
||||
|
||||
let doughnutCanvas = document.createElement("canvas");
|
||||
doughnutCanvas.id = "doughnut_chart_" + user.user_id;
|
||||
|
||||
// Append elements for doughnut chart
|
||||
doughnutChartContainer.appendChild(doughnutTitle);
|
||||
doughnutChartContainer.appendChild(doughnutCanvas);
|
||||
container.appendChild(doughnutChartContainer);
|
||||
|
||||
// Create bar chart container
|
||||
let barChartContainer = document.createElement("div");
|
||||
barChartContainer.classList.add("chart-container");
|
||||
|
||||
let barTitle = document.createElement("h3");
|
||||
barTitle.textContent = "User_" + user.user_id + " - Bar Chart";
|
||||
|
||||
let barCanvas = document.createElement("canvas");
|
||||
barCanvas.id = "bar_chart_" + user.user_id;
|
||||
|
||||
// Append elements for bar chart
|
||||
barChartContainer.appendChild(barTitle);
|
||||
barChartContainer.appendChild(barCanvas);
|
||||
container.appendChild(barChartContainer);
|
||||
|
||||
setTimeout(() => {
|
||||
// Doughnut chart
|
||||
let doughnutCtx = doughnutCanvas.getContext("2d");
|
||||
if (!doughnutCtx) {
|
||||
console.error(`Failed to get 2D context for canvas '${doughnutCanvas.id}'`);
|
||||
return;
|
||||
}
|
||||
|
||||
new Chart(doughnutCtx, {
|
||||
type: 'doughnut',
|
||||
data: {
|
||||
labels: ["unclaimed", "Overdue", "kyc", "SI"],
|
||||
datasets: [{
|
||||
data: [user.unclaimed, user.Loan_overdue, user.kyc_status, user.si_status],
|
||||
backgroundColor: ["#36A2EB", "#FF6384", "#4BC0C0", "#FFCE56"],
|
||||
hoverOffset: 8
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
cutout: '70%', // Inner empty circle
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'right'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Bar chart
|
||||
let barCtx = barCanvas.getContext("2d");
|
||||
if (!barCtx) {
|
||||
console.error(`Failed to get 2D context for canvas '${barCanvas.id}'`);
|
||||
return;
|
||||
}
|
||||
|
||||
new Chart(barCtx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ["unclaimed", "Overdue", "kyc", "SI"],
|
||||
datasets: [{
|
||||
label: 'User Data',
|
||||
data: [user.unclaimed, user.Loan_overdue, user.kyc_status, user.si_status],
|
||||
backgroundColor: ["#36A2EB", "#FF6384", "#4BC0C0", "#FFCE56"]
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
legend: {
|
||||
display: true,
|
||||
position: 'top'
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
// Call the function to fetch and display screens
|
||||
fetchAndDisplayScreens();
|
||||
</script>
|
||||
<br>
|
||||
|
||||
<button type="submit">Assign</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
package com.example;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
// Screen class to represent a screen object
|
||||
class Screen {
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public Screen(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@WebServlet("/getScreens")
|
||||
public class GetScreensServlet extends HttpServlet {
|
||||
private static final String DB_URL = "jdbc:oracle:thin:@localhost:1521:xe";
|
||||
private static final String DB_USER = "your_db_user";
|
||||
private static final String DB_PASSWORD = "your_db_password";
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
||||
List<Screen> screens = new ArrayList<>();
|
||||
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD)) {
|
||||
String sql = "SELECT SCREEN_ID, SCREEN_NAME FROM SCREENS";
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
String id = rs.getString("SCREEN_ID");
|
||||
String name = rs.getString("SCREEN_NAME");
|
||||
screens.add(new Screen(id, name));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Convert the list of screens to JSON
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(screens);
|
||||
|
||||
// Write the JSON response
|
||||
PrintWriter out = response.getWriter();
|
||||
out.print(json);
|
||||
out.flush();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user