-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tilepage.html
381 lines (346 loc) · 12.3 KB
/
Tilepage.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="Tilepage.css">
<title>Files</title>
<!-- Boxicons CDN Link -->
<link href='https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css' rel='stylesheet'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src= "https://kit.fontawesome.com/ece23478c9.js"></script>
<link rel="icon" href="images/favicon.png" type="image/svg+xml">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap" rel="stylesheet">
</head>
<body>
<!--SIDENAV BAR-->
<div class="sidebar">
<div class="logo_content">
<div class="logo">
<img src ="images/logo (2).png" class="drive logo" alt="">
</div>
<i class='bx bx-menu' id="btn" ></i>
</div>
<ul class="nav_list" style="margin-left: -40px;">
<li>
<a href="Tilepage.html">
<i class='bx bx-home' ></i>
<span class="links_name">My Files</span>
</a>
<span class="tooltip">My Files</span>
</li>
<!-- <li>
<a href="#">
<i class='bx bx-lock-alt' ></i>
<span class="links_name">Encrypted</span>
</a>
<span class="tooltip">Encrypted</span>
</li>
<li>
<a href="#">
<i class='bx bx-history' ></i>
<span class="links_name">Recent</span>
</a>
<span class="tooltip">Recent</span>
</li> -->
<!-- <li>
<a href="#">
<i class='bx bx-share' ></i>
<span class="links_name">Shared with me</span>
</a>
<span class="tooltip">Shared with me</span>
</li> -->
<li>
<a href="#">
<i class='bx bx-heart' id='show_favorite'></i>
<span class="links_name">Favourites</span>
</a>
<span class="tooltip">Favourites</span>
</li>
<li>
<a href="Accountpage.html">
<i class='bx bx-cog' ></i>
<span class="links_name">Settings</span>
</a>
<span class="tooltip">Settings</span>
</li>
</ul>
<div class="profile_content">
<div class="profile">
<centre>
<img src="images/Illustration 1.png" class="upgrade image" alt="" width="100" height="100">
</centre>
</div>
</div>
</div>
<!--TOP SEARCH BAR AND RIGHT BUTTONS-->
<div class="main-content" >
<div class="row">
<!-- <div class="searchbar">
<div class="searchbtn">
<i class="fas fa-search"></i>
</div>
<input type="text" class="input_search" placeholder="Search">
</div> -->
<div class="filedropdown">
<div class="filebtn">
<button id="filebtn" class="filebtns" style="margin-left: 46px;" ><img src="images/user.png" alt="" class="fileimg">Profile</button>
</div>
<ul class="active" id="filemenu">
<li id="account" class="trn-bg divider"><a href="Accountpage.html"><i class="fas fa-user-cog"></i><span class="setting">Account Settings</span></a></li>
<li id="account" class="trn-bg divider"><i class="fas fa-sign-out-alt"></i><span class="setting" id="logout"> Logout</span></li>
</ul>
</div>
</div>
<div class="row">
<h2 class="tiles">The Vault</h2>
<form action="/files/upload" method="POST" id="filesupload" enctype="multipart/form-data">
<div class="file-input">
<input type="file" id="add-file" class="add-file">
<label for="add-file" id="addfilebtn" >Add New Files</label>
</div>
</form>
</div>
<hr class="cont">
<div id="preview" class="container"></div>
<!--LOGOUT POPUP-->
<div class="bg-modal1">
<div class="modal-content1">
<h1>Logout</h1>
<hr style="margin-top: 13px;">
<h5>Are you sure you want to logout?</h5>
<form method="DELETE" id="logout_account">
<div class="popupbtn">
<button type="submit" class="popup-del" id="log_acc">Logout</button>
<button class="popup-cancel" id="popupbtn1" onclick="closepopup1()">Cancel</button>
</div>
</form>
</div>
</div> <!--POPUP ENDS-->
</div>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script type="text/javascript">
$(document).off('click', '.photos').on('click', '.photos', function(e) {
e.preventDefault();
e.stopPropagation();
window.open($(this).attr('src'), '_blank');
});
$(document).off('click', '.pdfs').on('click', '.pdfs', function(e) {
e.preventDefault();
e.stopPropagation();
// $('#pdf_anchor').remove();
});
const generateFilePreview = function(file) {
}
const renderFiles = function(file) {
fetch('https://gccstorage.herokuapp.com/files/view/file', {
method: 'POST',
credentials: "include",
headers: {
'Content-Type': "application/x-www-form-urlencoded"
},
body: new URLSearchParams({
filename: file.filename
})
})
.then(response => response.arrayBuffer())
.then(data => {
var bytes = new Uint8Array(data);
var blob = new Blob([bytes.buffer]);
var url = URL.createObjectURL(blob);
let fav_class = 'far fa-heart';
if (file.fav) {
fav_class = 'fa fa-heart';
}
let html = "<div style='background: white; height: 180px; width: 280px; margin-bottom: 50px' class='floatingDiv " + (file.fav ? "favorite_file" : "") + "'>";
if (file.contentType == 'application/pdf') {
html +=
"<div class='tooltip'>" +
"<img class='pdfs' src='" +
"https://play-lh.googleusercontent.com/nufRXPpDI9XP8mPdAvOoJULuBIH_OK4YbZZVu8i_-eDPulZpgb-Xp-EmI8Z53AlXHpqX" +
"' style='width: 250px; border: 1px solid black; padding: 10px; margin: 10px; height: 177px;' data-pdf-url=" +
url + "' data-file='" + file.filename +
"'> <span class='tooltiptext'> " + file.filename + " </span> </div> <i style='float: right; margin-right: 20px' class='" + fav_class + ` favorite data-file=' ${file.filename}'></i> <i style='float: right; margin-right: 10px' class='fas fa-trash-alt delete-file' data-file=' ` + file.filename + "'></i>";
} else {
html +=
"<div class='tooltip'>" +
"<img class='photos' src='" +
url +
"' style='width: 250px; border: 1px solid black; padding: 10px; margin: 10px; height: 177px; text-align: center'>" +
"<span class='tooltiptext'> " + file.filename + " </span> </div> <i style='float: right; margin-right: 20px' class='" + fav_class + " favorite' data-file='" + file.filename + "'>" +
"</i> <i style='float: right; margin-right: 10px' class='fas fa-trash-alt delete-file' data-file='" + file.filename + "'></i>";
}
html += "</div";
$('#preview').append(html);
})
.catch((error) => {
console.error('Error:', error);
});
}
$(document).off('click', '.delete-file').on('click', '.delete-file', function() {
let conf = confirm("Are you sure you want to delete?");
if (!conf) {
return;
}
let filename = $(this).data('file');
fetch('https://gccstorage.herokuapp.com/files/delete/file', {
method: 'DELETE',
credentials: "include",
headers: {
'Content-Type': "application/x-www-form-urlencoded"
},
body: new URLSearchParams({
filename: filename
})
})
.then(response => response.json())
.then(data => {
if (data.success == true) {
alert("file deleted successfully");
window.location.reload();
} else {
alert("unable to delete file");
}
})
.catch((error) => {
console.error('Error:', error);
})
})
$(document).on('click', '.favorite', function() {
let is_favorite = $(this).hasClass('far fa-heart');
let filename = $(this).data('file');
let that = $(this);
var urlencoded = new URLSearchParams();
urlencoded.append("action", "set");
urlencoded.append("filename", filename);
var requestOptions = {
method: 'POST',
body: urlencoded,
redirect: 'follow',
credentials: "include"
};
fetch("https://gccstorage.herokuapp.com/profile/fav", requestOptions)
.then(response => response.json())
.then(result => {
if (result.success == true) {
if (is_favorite) {
$(that).closest('span').addClass('favorite_file');
alert("favorite added");
that.removeClass('far fa-heart favorite');
that.addClass('fa fa-heart favorite');
} else {
$(that).closest('span').removeClass('favorite_file');
alert("favorite removed");
that.removeClass('fa fa-heart favorite');
that.addClass('far fa-heart favorite');
}
}
}
)
.catch(error => console.log('error', error));
})
$(document).on('click', '#show_favorite', function() {
$('#preview').children().each(function(i, v) {
if(!$(this).hasClass('favorite_file')) {
$(this).hide();
}
})
})
// DROPDOWN
$(document).ready(function(){
$('.filebtns').click(function(){
$('ul').toggleClass('active');
});
fetch('https://gccstorage.herokuapp.com/files/viewall', {
method: 'POST',
credentials: "include",
})
.then(response => response.json())
.then(data => {
data.forEach(function(item) {
renderFiles(item);
console.log(item);
})
})
.catch((error) => {
console.error('Error:', error);
})
})
// SIDE BAR OPEN AND CLOSE
let btn = document.querySelector("#btn");
let sidebar = document.querySelector(".sidebar");
btn.onclick = function() {
sidebar.classList.toggle("active");
if(btn.classList.contains("bx-menu")){
btn.classList.replace("bx-menu" , "bx-menu-alt-right");
}else{
btn.classList.replace("bx-menu-alt-right", "bx-menu");
}
}
</script>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
// LOGOUT BUTTON POPUP JS
var logout= document.getElementById('logout');
var close= document.getElementById('popupbtn1');
function openpopup1(){
document.querySelector('.bg-modal1').style.display="flex";
document.querySelector("body").style.overflow="hidden";
};
logout.onclick=openpopup1;
function closepopup1(){
document.querySelector('.bg-modal1').style.display="none";
document.querySelector("body").style.overflow="visible";
};
close.onclick=closepopup1;
// LOGOUT FETCH
var logout_account = document.getElementById("logout_account");
logout_account.addEventListener("submit",function(e){
e.preventDefault();
var log_acc = document.getElementById("log_acc").value;
fetch('https://gccstorage.herokuapp.com/logout', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
credentials: "include",
body: JSON.stringify({}),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
if(data.status == "ok"){
window.location.href="/index.html";
}
})
.catch((error) => {
console.error('Error:', error);
});
});
// UPLOAD FILES JS
function getImagePreview(event){
let file = event.target.files[0];
var image=URL.createObjectURL(file);
let formData = new FormData();
formData.append("file", file, file.name);
fetch('https://gccstorage.herokuapp.com/files/upload', {
method: 'POST',
body: formData,
credentials: "include"
})
.then(response => response.json())
.then(data => {
if (data.status == 'ok') {
alert("Uploaded successfully");
window.location.reload();
} else {
alert("Upload unsuccessfull");
}
})
.catch((error) => {
console.error('Error:', error);
});
}
document.getElementById("add-file").addEventListener("change", getImagePreview);
</script>
</html>