-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscounts.html
139 lines (122 loc) · 4.83 KB
/
discounts.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GoR Admin</title>
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<script>
var jwt = localStorage.getItem("JWT");
if (jwt == ""){
window.location.replace("login.html");
}
</script>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="index.html">GoR Admin</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="discounts.html">Discounts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="orders.html">Orders and Statistics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="categories.html">Categories</a>
</li>
</ul>
<form class="d-flex" method="GET" action="/index.html">
<input class="form-control me-2" type="search" placeholder="Search Products" aria-label="Search" name="search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
<a class="nav-link float-right link-light" id="logout" href="#" tabindex="-1" aria-disabled="true">Log out</a>
</div>
</nav>
<div class="container mt-5">
<div class="row" id="discount-row">
<div class="col-12">
<table class="table table-hover" id="discount-table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">image</th>
<th scope="col">Product Name</th>
<th scope="col"># in stock</th>
<th scope="col">Price</th>
<th scope="col">discount</th>
<th scope="col"></th>
</tr>
</thead>
<tbody id = "discount-body">
</tbody>
</table>
</div>
</div>
</div>
<script src="js/logout.js"></script>
<script>
const proxy = "https://fast-sea-38093.herokuapp.com/";
const url = "https://grocery-on-rails.herokuapp.com";
async function getDiscount(){
const options = {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + jwt
}
};
const response = await fetch(url + "/home", options);
const data = await response.json();
return data.content[0].content;
}
function productRow(i, product){
if (product.stock == 0){
row = '<tr class="table-danger">';
}else if (product.stock < 10){
row = '<tr class="table-warning">';
}else{
row = '<tr class="table-success">';
}
return row + `<th scope="row">${i}</th>\
<td><img src="${product.image}" height="50"></td>
<td>${product.name}</td>\
<td>${product.stock}</td>\
<td>AED${product.price}</td>\
<td>AED${product.discount}</td>\
<td><a class="btn btn-primary" href="product.html?id=${product._id.$oid}" role="button">Edit</a></td>\
</tr>`;
}
function buildTable(data){
let body = "";
let i = 1;
for (let product of data){
body += productRow(i, product);
i++;
}
return body;
}
function printDiscount(data)
{
body = buildTable(data);
document.getElementById("discount-body").innerHTML = body;
}
async function prepare(){
const data = await getDiscount();
printDiscount(data);
}
prepare();
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>