Skip to content
Snippets Groups Projects
Commit e85aeb7b authored by dmz39's avatar dmz39
Browse files

Manage Orders page framework completed

parent 8887f604
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,10 @@ package edu.drexel.TrainDemo.controllers.users;
import edu.drexel.TrainDemo.Utils;
import edu.drexel.TrainDemo.configuration.LoggerConfiguration;
import edu.drexel.TrainDemo.models.sales.Order;
import edu.drexel.TrainDemo.models.users.Group;
import edu.drexel.TrainDemo.models.users.UserEntity;
import edu.drexel.TrainDemo.services.sales.OrderService;
import edu.drexel.TrainDemo.services.users.GroupService;
import edu.drexel.TrainDemo.services.users.UserService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -15,7 +17,9 @@ import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class AdminController {
......@@ -26,6 +30,9 @@ public class AdminController {
@Autowired
GroupService groupService;
@Autowired
OrderService orderService;
@GetMapping("/admin/dashboard")
String adminDashboard(@AuthenticationPrincipal OAuth2User principal) {
UserEntity currentUser = this.userService.getUser(principal);
......@@ -77,4 +84,21 @@ public class AdminController {
return "admin/access_denied";
}
}
@GetMapping("admin/orders")
String manageOrders(@AuthenticationPrincipal OAuth2User principal, Model model) {
UserEntity currentUser = this.userService.getUser(principal);
if (currentUser != null && this.userService.isAllowedAdminPanel(currentUser)) {
List<Order> orders = this.orderService.getAllOrders();
Map<Long, String> userMap = new HashMap<>();
for (UserEntity user : this.userService.getUsers()) {
userMap.put(user.getId(), user.getFirstName() + " " + user.getLastName());
}
model.addAttribute("orders", orders);
model.addAttribute("userMap", userMap);
return "admin/orders";
} else {
return "admin/access_denied";
}
}
}
<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:replace="base::header"/>
<link href="//cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" rel="stylesheet">
<script src="//cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/js/admin.js"></script>
</head>
<body>
<th:block th:replace="base::navbar"/>
<main role="main">
<div class="jumbotron">
<div class="container">
<h1>Admin Panel</h1>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<button hidden type="button" class="btn btn-primary" onclick="showModal('newGroupModal')">New Group</button>
</div>
</div>
<div class="row">
<a class="text">Manage Orders:</a><br>
</div>
<div class="row">
<div class="col">
<table id="groupsTable" class="table table-striped table-bordered table-sm" cellspacing="0" width="100%">
<thead>
<tr>
<th class="th-sm">Order ID</th>
<th class="th-sm">Customer ID</th>
<th class="th-sm">Customer Name</th>
<th class="th-sm">Order Total</th>
<th class="th-sm">Details</th>
<th class="th-sm">Delete</th>
</tr>
</thead>
<tbody>
<tr th:each="order : ${orders}">
<td th:text="${order.getId()}"></td>
<td th:text="${order.getUserId()}"></td>
<td th:text="${userMap.get(order.getUserId())}"></td>
<td th:text="${order.getPrice()}"></td>
<td><button class="btn btn-primary" th:type="button">Details</button></td>
<td><button class="btn btn-primary" th:type="button">&times;</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="newGroupModal">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="newGroupModalLongTitle">New Group</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="modal-body">
<p>Please enter the information for the new group:</p>
<form>
<div class="form-group ">
<label for="gname">Group Name: </label>
<input type="text" class="form-control" id="gname">
</div>
<div class="form-group">
<label for="gtype">Group Type:</label>
<select type="name" class="form-control" id="gtype">
<option value="">-- Type --</option>
<option value="ADMIN">ADMIN</option>
<option value="EMPLOYEE">EMPLOYEE</option>
<option value="CUSTOMER">CUSTOMER</option>
</select>
</div>
<div class="form-group">
<button onclick="addGroup()">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment