-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- @RequestMapping("/admin/product") - add new product - get list of products - jsp template changes
- Loading branch information
Showing
7 changed files
with
120 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,77 @@ | ||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||
pageEncoding="ISO-8859-1"%> | ||
pageEncoding="ISO-8859-1" %> | ||
<footer class="footer fixed-bottom py-3 bg-dark text-center"> | ||
<div class="container"> | ||
<span class="text-muted">Copyright Reserver © 2020</span> | ||
</div> | ||
<div class="container"> | ||
<span class="text-muted">Copyright Reserver © 2020</span> | ||
</div> | ||
</footer> | ||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> | ||
|
||
<script> | ||
//Get the button: | ||
mybutton = document.getElementById("myBtn"); | ||
// When the user scrolls down 20px from the top of the document, show the button | ||
window.onscroll = function() {scrollFunction()}; | ||
function scrollFunction() { | ||
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | ||
mybutton.style.display = "block"; | ||
} else { | ||
mybutton.style.display = "none"; | ||
} | ||
} | ||
// When the user clicks on the button, scroll to the top of the document | ||
function topFunction() { | ||
document.body.scrollTop = 0; // For Safari | ||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||
} | ||
</script> | ||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" | ||
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" | ||
crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" | ||
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" | ||
crossorigin="anonymous"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" | ||
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" | ||
crossorigin="anonymous"></script> | ||
|
||
<script type="text/javascript"> | ||
//Get the button: | ||
mybutton = document.getElementById("myBtn"); | ||
// When the user scrolls down 20px from the top of the document, show the button | ||
window.onscroll = function () { | ||
scrollFunction() | ||
}; | ||
function scrollFunction() { | ||
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { | ||
mybutton.style.display = "block"; | ||
} else { | ||
mybutton.style.display = "none"; | ||
} | ||
} | ||
// When the user clicks on the button, scroll to the top of the document | ||
function topFunction() { | ||
document.body.scrollTop = 0; // For Safari | ||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||
} | ||
function renderProducts(products) { | ||
const container = document.getElementById("products"); | ||
products.forEach(product => { | ||
container.innerHTML += productTemplate(product); | ||
}); | ||
} | ||
function productTemplate(product) { | ||
return ` | ||
<tr> | ||
<th scope="row">`+product.productId+`</th> | ||
<td>`+product.productName+`</td> | ||
<td>`+product.productPrice+`</td> | ||
<td>`+product.productQty+`</td> | ||
<td> | ||
<a href='#' class="btn btn-success" onclick="">Edit</a> | ||
<a href='#' class="btn btn-danger" onclick="">Delete</a> | ||
</td> | ||
</tr>`; | ||
} | ||
function loadProducts() { | ||
const request = new XMLHttpRequest(); | ||
const url = "/admin/product/list" | ||
request.open('GET', url, true); | ||
console.log("Calling home..."); | ||
request.send(); | ||
request.onreadystatechange = () => { | ||
if (request.readyState === 4 && request.status === 200) { | ||
console.log(JSON.parse(request.response)); | ||
renderProducts(JSON.parse(request.response)); | ||
} | ||
} | ||
} | ||
loadProducts(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
<%@ page import="java.util.Arrays" %> | ||
<%@ page import="java.util.stream.Collectors" %> | ||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" | ||
pageEncoding="ISO-8859-1"%> | ||
pageEncoding="ISO-8859-1"%> | ||
<% | ||
if(request.getAttribute("msg") != null) { | ||
out.write("<div class='alert "+request.getAttribute("class")+"'>"+request.getAttribute("msg")+"</div>"); | ||
} | ||
%> | ||
if(Arrays.stream(request.getCookies()).anyMatch(cookie -> "msg".equals(cookie.getName()))) { | ||
String message = Arrays.stream(request.getCookies()) | ||
.filter(cookie -> "msg".equals(cookie.getName())) | ||
.collect(Collectors.toList()) | ||
.get(0).toString(); | ||
String messageClass = Arrays.stream(request.getCookies()) | ||
.filter(cookie -> "msgClass".equals(cookie.getName())) | ||
.collect(Collectors.toList()) | ||
.get(0).toString(); | ||
out.write("<div class='alert "+messageClass+"'>"+message+"</div>"); | ||
} | ||
%> |