forked from Swapnil887/incompetent-coil-1138
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_man.html
More file actions
176 lines (141 loc) · 4.95 KB
/
admin_man.html
File metadata and controls
176 lines (141 loc) · 4.95 KB
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
<!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>Document</title>
<link rel="stylesheet" type="text/css" href="CSS/admin._panel.css" />
<link
rel="icon"
type="image/png"
sizes="32x32"
href="https://i.postimg.cc/Fsp8J7LR/20221213-201414.jpg"
/>
</head>
<body>
<div id="navBar">
<div class="image"><img style=" width:100% ;padding-top: 5px" src="images/logo_new.png" alt=""></div>
<div id="left_section">
<div class="left">
<a href="admin_panel.html"><h3> All Product</h3></a>
</div>
<div class="left">
<a href="admin_man.html"><h3> Manage Product</h3></a>
</div>
<div class="left">
<a href="admin_dashbord.html"><h3> Dashboard</h3></a>
</div>
<div class="left">
<a href="a.notif.html"><h3>See Stocks</h3></a>
</div>
</div>
<div id="right_section">
<div class="right">Add Offers</div>
<div class="right">Your Profile</div>
<div class="right">Resolve Help?</div>
</div>
</div>
<h1 id="mh">Manage All Products</h1>
<div class="update">
<div class="add_new">
<h1 class="hea">ADD PRODUCT</h1>
<form id="new_product">
<h1 class="hadd">ENTER IMAGE URL</label>
<input id="img_url" placeholder="Enter Image url"type="url">
<h1 class="hadd">ENTER PRODUCT NAME</label>
<input id="name" placeholder="Enter Product Name"type="text">
<h1 class="hadd">ENTER PRODUCT PRICE</label>
<input id="price" placeholder="Enter Product Price" type="number">
<h1 class="hadd">ENTER PRODUCT DESCRIPTION</label>
<input id="des" placeholder="Enter Product Description"type="text">
<input type="submit" id="add" value="Add Product" >
</form>
</div>
<div class="delete">
<h1 class="hea">DELETE PRODUCT</h1>
<form id="dlt_product">
<h1 class="hadd">ENTER ID</h1>
<input id="delete_id" placeholder="Enter Product id" type="number">
<input type="submit" id="delete" value="Delete ">
</form>
</div>
</div>
<h1 id="mh">SEE ALL PRODUCT</h1>
<div class="main">
</div>
</body>
</html>
<script >
console.log("app start")
async function getData(){
var x = await fetch("https://6398c52b29930e2bb3c190fa.mockapi.io/sw/products");
var data = await x.json();
renderCardList(data);
}
getData()
let add_btn=document.getElementById("new_product")
add_btn.addEventListener("submit",function(event){
event.preventDefault()
let add_img=document.querySelector("#img_url").value
let add_name=document.querySelector("#name").value
let add_price=document.querySelector("#price").value
let add_des=document.querySelector("#des").value
var obj = {
name: add_name,
description: add_des,
avatar: add_img,
price: add_price,
}
addData(obj)
alert('This Product Added Successfully ')
window.location.href = "admin_man.html";
})
async function addData(obj){
var x = await fetch(`https://6398c52b29930e2bb3c190fa.mockapi.io/sw/products`,{
method:"POST",
headers:{"Content-Type":"application/json"}
,body:JSON.stringify(obj)
})
}
let main =document.querySelector(".main")
function renderCardList(cardData) {
main.innerHTML=`
${cardData
.map((item) => {
let imageURL = `${item.avatar}`;
let name = `${item.name}`;
let description = `${item.description}`;
let id=`${item.id}`;
let price=`${item.price}`
return getAsCard(imageURL, name, description,id,price );
})
.join("")}
`;
}
function getAsCard(imageURL, name, description, id,price) {
return `
<div class="show_products">
<div> <img src=${imageURL} alt="img"></div>
<h3>${name}</h3>
<h3>${price}</h3>
<p>${description}</p>
<h3>PRODUCT ID:${id}</h3>
<button class="mdlt" data-id=${id} >Delete</button>
</div>
`;
}
async function delData(id){
var x = await fetch(`https://6398c52b29930e2bb3c190fa.mockapi.io/sw/products/${id}`,{
method:"DELETE"
});
}
let dlt_btn=document.getElementById("delete")
dlt_btn.addEventListener("click",function(event){
event.preventDefault()
let p_id=document.querySelector("#delete_id").value
delData(p_id)
alert('This Product Successfully Deleted ')
window.location.href = "admin_man.html";
})
</script>