forked from Lakshmiguru12/lensmart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminOrders.js
187 lines (179 loc) · 6.68 KB
/
adminOrders.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
let userAuthToken = localStorage.getItem("accestoken");
let head = document.querySelector("head");
let body = document.querySelector("body");
if(!userAuthToken){
let style = document.createElement("style");
style.innerHTML = `body {
background-color: #2F3242;
}
svg {
position: absolute;
top: 50%;
left: 50%;
margin-top: -250px;
margin-left: -400px;
}
.message-box {
height: 200px;
width: 380px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: 50px;
color: #FFF;
font-family: Roboto;
font-weight: 300;
}
.message-box h1 {
font-size: 60px;
line-height: 46px;
margin-bottom: 40px;
}
.buttons-con .action-link-wrap {
margin-top: 40px;
}
.buttons-con .action-link-wrap a {
background: #68c950;
padding: 8px 25px;
border-radius: 4px;
color: #FFF;
font-weight: bold;
font-size: 14px;
transition: all 0.3s linear;
cursor: pointer;
text-decoration: none;
margin-right: 10px
}
.buttons-con .action-link-wrap a:hover {
background: #5A5C6C;
color: #fff;
}
#Polygon-1 , #Polygon-2 , #Polygon-3 , #Polygon-4 , #Polygon-4, #Polygon-5 {
animation: float 1s infinite ease-in-out alternate;
}
#Polygon-2 {
animation-delay: .2s;
}
#Polygon-3 {
animation-delay: .4s;
}
#Polygon-4 {
animation-delay: .6s;
}
#Polygon-5 {
animation-delay: .8s;
}
@keyframes float {
100% {
transform: translateY(20px);
}
}
@media (max-width: 450px) {
svg {
position: absolute;
top: 50%;
left: 50%;
margin-top: -250px;
margin-left: -190px;
}
.message-box {
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -190px;
text-align: center;
}
}`;
head.append(style);
body.innerHTML = `
<svg width="380px" height="500px" viewBox="0 0 837 1045" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<path d="M353,9 L626.664028,170 L626.664028,487 L353,642 L79.3359724,487 L79.3359724,170 L353,9 Z" id="Polygon-1" stroke="#007FB2" stroke-width="6" sketch:type="MSShapeGroup"></path>
<path d="M78.5,529 L147,569.186414 L147,648.311216 L78.5,687 L10,648.311216 L10,569.186414 L78.5,529 Z" id="Polygon-2" stroke="#EF4A5B" stroke-width="6" sketch:type="MSShapeGroup"></path>
<path d="M773,186 L827,217.538705 L827,279.636651 L773,310 L719,279.636651 L719,217.538705 L773,186 Z" id="Polygon-3" stroke="#795D9C" stroke-width="6" sketch:type="MSShapeGroup"></path>
<path d="M639,529 L773,607.846761 L773,763.091627 L639,839 L505,763.091627 L505,607.846761 L639,529 Z" id="Polygon-4" stroke="#F2773F" stroke-width="6" sketch:type="MSShapeGroup"></path>
<path d="M281,801 L383,861.025276 L383,979.21169 L281,1037 L179,979.21169 L179,861.025276 L281,801 Z" id="Polygon-5" stroke="#36B455" stroke-width="6" sketch:type="MSShapeGroup"></path>
</g>
</svg>
<div class="message-box">
<h1>403</h1>
<p>Forbidden</p>
<p>It seems like you are not authorized to acces this page</p>
<div class="buttons-con">
<div class="action-link-wrap">
<a onclick="history.back(-1)" class="link-button link-back-button">Go Back</a>
<a href="./index.html" class="link-button">Go to Home Page</a>
</div>
</div>
</div>`
// document.getAnim
}
// dynamic headers
let change = document.getElementsByClassName("card-single");
let changes = [...change];
changes.forEach((ele,index)=>{
ele.addEventListener("click",()=>{
if(index===0){
window.location.replace("./adminUsers.html");
}
else if(index===1){
window.location.replace("./adminOrders.html");
}
else if(index===2){
window.location.replace("./adminProducts.html");
}else if(index ===3){
window.location.replace("./admin.html")
}
})
})
let userTable = document.querySelector(".table-responsive>table>tbody");
fetchdata();
function fetchdata(){
fetch(`https://lensmart-backend3-0.onrender.com/product_status`)
.then((res)=>res.json())
.then((res)=>{
console.log(res)
render(res);
})
}
function render(data){
let out = data.map((ele)=>{
let a = createtbody(ele.frameImg,ele.discountedPrice,ele.brandName,ele.id,ele.password,ele.username);
return a;
})
userTable.innerHTML = out.join("");
let delBTN = document.getElementsByClassName("delete");
let deleteBTN = [...delBTN];
deleteBTN.forEach((ele,index)=>{
ele.addEventListener("click",()=>{
fetch(`https://lensmart-backend3-0.onrender.com/product_status/${data[index].id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
})
.then((res)=>{
res.json()
})
.then((res)=>{
console.log(res);
alert("Cancelled succesfully");
fetchdata();
})
});
})
}
// create cards
function createtbody(avatar,discountedPrice,brand,id,password,username){
let td = `<tr>
<td><img src="${avatar || `./images/profileimage.jpg`}" alt="profile image"></td>
<td>${username}</td>
<td>${brand}</td>
<td>₹ ${discountedPrice}</td>
<td>${password}</td>
<td>${id}</td>
<td><button class="delete">Cancel</button></td>
</tr>`
return td;
}