-
Notifications
You must be signed in to change notification settings - Fork 3
/
addProduct.html
286 lines (224 loc) · 5.82 KB
/
addProduct.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!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>Add product Admin page</title>
<style>
* {
box-sizing: border-box;
}
#main {
display: flex;
justify-content: space-between;
margin: auto;
}
#adminform {
width: 50%;
position: sticky;
top: 85px;
height: 70vh;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
text-align: center;
}
#adminform h3 {
font-weight: 900;
margin-bottom: 2rem;
}
#adminform input {
width: 60%;
margin-bottom: 1rem;
text-align: center;
}
#adminform button {
background-color: black;
color: white;
border: 0px;
font-size: 17px;
font-weight: 600;
padding: 5px 10px;
width: 60%;
height: 10vh;
}
input {
height: 5vh;
border-radius: 10px;
}
#adminform button:hover {
background-color: #003380;
}
#second {
margin: auto;
width: 46%;
position: relative;
}
#cards>div {
width: 100%;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
margin: auto;
}
#cards img {
width: 100%;
}
@media screen and (max-width: 700px) {
#main {
display: block;
margin: auto;
}
#cards>div {
width: 100%;
display: grid;
grid-template-columns: repeat(1, 1fr);
gap: 5px;
margin: auto;
}
#adminform {
width: 50%;
position: relative;
top: 85px;
left: 150px;
height: 60vh;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
text-align: center;
}
#second {
margin: auto;
width: 46%;
margin-top: 100px;
position: relative;
}
}
</style>
</head>
<body>
<div id="main">
<div id="adminform">
<h2>Add New Products On Website</h2>
<form action="">
<input type="text" placeholder="Enter The Image Address" id="productimage"><br>
<input type="text" placeholder="Enter The Product Title" id="producttitle"><br>
<input type="text" placeholder="Enter The Category " id="productcategory"><br>
<input type="number" placeholder="Enter The Price" id="productmrp"><br>
<button id="publishdata">Publish Product On Website</button>
</form>
</div>
<div id="second">
<h1>ALL PRODUCTS (<span id="count"></span>)</h1>
<div id="cards">
</div>
</div>
</div>
</body>
<script>
let length = document.getElementById("count")
let card = document.getElementById("cards")
let updateproductimg = document.getElementById("productimage")
let updateproductname = document.getElementById("producttitle")
let updateproductcategory = document.getElementById("productcategory")
let updateproductprice = document.getElementById("productmrp")
let publishbtn = document.getElementById("publishdata");
window.addEventListener("load", () => {
dispalyData()
})
function dispalyData() {
fetch(`https://upset-red-outfit.cyclic.app/Mens`)
.then((res) => res.json())
.then((data) => {
console.log(data)
let proData = data.map((item, i) => ({
id: item.id,
title: item.name,
price: item.price
,
description: "Rs. " + item.price
,
linkText: "Edit",
linkUrl: "./Adminupdate.html",
// imageUrl:[item.images[0],item.images[1]||item.images[0],item.images[2]||item.images[0]]
imageUrl: item.images,
}))
console.log(proData)
renderData(proData)
length.innerText = proData.length
})
}
publishbtn.addEventListener("click", () => {
let image = updateproductimg.value;
let name = updateproductname.value;
let category = updateproductcategory.value;
let price = updateproductprice.value;
//console.log(name, image, dept, salary);
addpro(name, image, category, price)
alert("product added")
dispalyData()
});
async function addpro(name, image, category, price) {
// let obj = {
// image: image,
// name: name,
// category: category,
// price:price,
// };
fetch(`https://upset-red-outfit.cyclic.app/Mens`, {
method: "POST",
body: JSON.stringify({
images: [image],
name: name,
category: category,
price: price,
}),
headers: {
'content-type': 'application/json',
}
})
.then(res => res.json())
.then((data) => {
console.log(data)
// dispalyData();
})
.catch((err) => {
console.log(err)
})
}
function renderData(cardData) {
let cardList = `
<div class="card-list">
${cardData
.map((item) =>
getCard(
item.id,
item.title,
item.description,
item.linkText,
item.linkUrl,
item.imageUrl
)
)
.join("")}
</div>
`;
card.innerHTML = cardList;
}
function getCard(id, title, desc, linkText, linkUrl, imageUrl) {
let card = `
<div class="card" data-id=${id} >
<div class="card__img" style="overflow:hidden;">
<img style="aspect-ratio: 2/3; object-fit:contain" src=${imageUrl} alt="food" />
</div>
<div class="card__body">
<h6>${id}</h6>
<h3 class="card_item card_title">${title}</h3>
<div class="card_item card_description">
${desc}
</div>
<a href=${linkUrl} data-id=${id} class="card_item card_link">${linkText}</a>
</div>
</div>
`;
return card;
}
</script>
</html>