-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.html
More file actions
195 lines (158 loc) · 6.67 KB
/
profile.html
File metadata and controls
195 lines (158 loc) · 6.67 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!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>My Profile</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<style>
.text-muted{
color: rgb(0, 201, 0) !important
}
.cardd{
margin: 10px !important;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="main.html">MyCups</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="add.html">Add cup</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="profile.html">My profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="cart.html">Cart</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col">
<div class="cardd mb-3" style="max-width: 840px;">
<div class="row g-0">
<div class="col-md-4">
<img src="" class="img-fluid rounded-start" alt="user.png" id="photo">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title" id="name">Name</h5>
<p class="card-text" id="contacts">Contacts</p>
<p class="card-text" id="description">Description</p>
<p class="card-text"><small class="text-muted">Verified vendor</small></p>
<button class="btn btn-danger" id="logOut">Log out</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<h1 class="col"><span class="badge" style="background-color: #adb5bd">My cups</span><button class="btn btn-primary col" style="margin-left: 5px !important;" id="add">Add Cup</button></h1>
</div>
<div class="row main" id="allMyCups">
</div>
</div>
</body>
<script src="main.js"></script>
<script>
let isIn = localStorage.getItem('IsIn')
if(isIn==null || isIn == "false"){
document.body.innerHTML = "Log In First"
}else{
//Профіль
let name = document.getElementById('name')
let contacts = document.getElementById('contacts')
let photo = document.getElementById('photo')
let description = document.getElementById('description')
let logOut = document.getElementById('logOut')
let me = GetCurrentUser();
name.innerText = me.name + " " + me.secondName
contacts.innerText = "phone: " + me.phone + "\n" + "email: " + me.email
description.innerText = me.description
photo.setAttribute('src', me.photo)
logOut.addEventListener('click', function(){
localStorage.setItem('CurrentUser', 0)
localStorage.setItem('IsIn', false)
window.location.href = 'logIn.html';
})
//Кружки
let row = document.getElementById('allMyCups')
let MyCups = me.cups;
document.getElementById('add').addEventListener('click', function(){
window.location.href = 'add.html';
})
for(i in MyCups){
row.innerHTML += `
<div class="card" style="width: 18rem; margin-left: 10px">
<img src="`+ MyCups[i].photo +`" class="card-img-top" alt="cup.webp" style="margin-top: 20px">
<div class="card-body">
<h5 class="card-title">`+ MyCups[i].name + `</h5>
<p class="card-text">`+ MyCups[i].description + `</p>
<h5 class="card-title">`+ MyCups[i].price + `$</h5>
</div>
<ul class="list-group list-group-flush" id="`+MyCups[i].id+`">
<button class="btn btn-warning edit" style="margin-bottom: 5px;">Edit</button>
<button class="btn btn-danger delete">Delete</button>
</ul>
</div>
`
}
let AllCups = JSON.parse(localStorage.getItem('cups'))
//Видалення
let allDelete = document.querySelectorAll('.delete')
for(i of allDelete){
i.addEventListener('click', function(e){
let curId = e.target.parentNode.id
Delete(curId)
})
}
function Delete(curId){
//Видалення в user
//Знаходимо айді володаря кружки
var temp = AllCups.filter(elem => elem.id==curId)
let UserId = temp[0].ownerId
//Знаходимо володаря кружки по його айді
let Allusers = JSON.parse(localStorage.getItem('users'))
neededUser = Allusers.filter(elem => elem.id==UserId)
//Тимчасово видаляємо його з списку
Allusers = Allusers.filter(elem => elem.id!=UserId)
//Видаляємо з списку кружок ту, яку виділено
neededUser[0].cups = neededUser[0].cups.filter(elem => elem.id!=curId)
//Переписуємо Юзера
Allusers.push(neededUser[0])
localStorage.setItem('users', JSON.stringify(Allusers))
//Видалення в cups
var newMas = AllCups.filter(elem => elem.id!=curId)
localStorage.setItem('cups', JSON.stringify(newMas))
me = GetCurrentUser()
window.location.reload(true);
}
//Редагування
let allEdit = document.querySelectorAll(".edit")
for(i of allEdit){
console.log("ihh")
i.addEventListener('click', function(e) {
let temp = AllCups.filter(elem => elem.id == e.target.parentNode.id)
Delete(e.target.parentNode.id)
let newMas = [true, temp[0]]
console.log(newMas)
localStorage.setItem('toEdit', JSON.stringify(newMas))
window.location.href = 'add.html'
})
}
}
</script>
</html>