-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.ejs
More file actions
617 lines (572 loc) · 25.1 KB
/
project.ejs
File metadata and controls
617 lines (572 loc) · 25.1 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
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
<!DOCTYPE html>
<html>
<head>
<title>No Project!</title>
<link rel="icon" type="image/x-icon" href="/Coco Icon/Old Coco Icon.ico">
<link href="/CSS/homepage.css" rel="stylesheet">
<link href="/CSS/header.css" rel="stylesheet">
<link href="https://vjs.zencdn.net/8.16.1/video-js.css" rel="stylesheet" />
<!--<script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script>-->
<link href="/CSS/general.css" rel="stylesheet">
<link href="/CSS/general.css" rel="stylesheet">
<link href="/CSS/header.css" rel="stylesheet">
<link href="/CSS/teapot.css" rel="stylesheet">
<link href="/CSS/download.css" rel="stylesheet">
<style>
body {
background-color: grey;
font-family: Arial, Helvetica, sans-serif;
background-image: url("/Images/Background Dark.png") !important;
}
#webpage {
position: absolute;
margin-top: 50px;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
}
.products {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
row-gap: 12px;
column-gap: 12px;
margin-top: 30px;
margin-left: 12px;
margin-right: 12px;
bottom: 0;
}
/*#header {}*/
.header {
display: flex;
flex: 1;
height: 44px;
position: fixed;
z-index: 100;
margin-bottom: 50px;
background-color: lightgrey;
top: 0;
right: 0;
left: 0;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.418);
padding-top: 12px;
padding-left: 12px;
padding-bottom: 12px;
padding-right: 12px;
}
.box-product {
background-color: rgb(247, 243, 243);
white-space: nowrap;
/* grid-template-columns: 100px 1fr; */
/* width: 300px;
height: 300px; */
padding: 30px 3px 30px 40px;
/* display: grid; */
height: 100%;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.418);
}
#Coco {
z-index: 101;
height: 38px;
padding-bottom: -20px;
padding-right: -100px;
opacity: 1;
transition: opacity 1.0s;
transition: height 1.0s;
}
#Coco:hover {
opacity: 0.10;
cursor: pointer;
height: 50px;
transition: opacity 1.0s;
transition: height 1.0s;
}
.product-img {
height: 120px;
width: 120px;
margin-left: 40px;
max-width: 100%;
}
.Announcement {
background-color: wheat;
margin-top: 100px;
margin-bottom: 50px;
}
#user-box {
display: block;
}
#user-info {
display: grid;
grid-template-columns: 1fr 3fr;
column-gap: 15px;
background-color: #ddd;
}
.user-box {
display: block;
background: rgb(175, 175, 175);
padding: 5px;
border-radius: 5px;
border: 2px solid rgb(211, 211, 211);
border-top-left-radius: 0px;
border-top-right-radius: 0px;
}
.user-box-head {
border-radius: 7px;
border: 2px solid rgb(230, 230, 230);
background-color: rgb(199, 199, 199);
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
padding: 2px 10px;
color: rgb(128, 128, 128);
}
.user-box-head h3,
.user-box-head input {
color: rgb(128, 128, 128);
}
#project-name {
font-size: 25px;
font-weight: bold;
outline: none;
border: none;
padding: 8px;
}
#project-name-edit {
font-size: 25px;
padding: 5px;
font-weight: bold;
outline: none;
background-color: rgb(230, 230, 230);
border-radius: 10px;
border: darkgray 3px dotted;
}
#project-description-edit {
padding: 5px;
outline: none;
background-color: rgb(230, 230, 230);
border-radius: 10px;
border: darkgray 3px dotted;
width: 208px !important;
min-height: 470px !important;
white-space: wrap !important;
word-break: normal !important;
}
#project-description {
outline: none;
border: none;
max-width: 208px !important;
min-height: 470px !important;
word-break: break-word !important;
}
#project-name {
max-height: 20px !important;
overflow-x: hidden !important;
overflow-y: hidden !important;
white-space: nowrap !important;
}
.box-push-into-left {
--pericles-word-background: rgba(9, 46, 140, 0.92);
--pericles-section-background: rgba(255, 254, 219, 1.54);
text-shadow: 0 1px #5f5f5f;
font-family: Arial, Helvetica, sans-serif;
background-color: rgb(43, 43, 43);
margin: 12px;
/*box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.418);*/
overflow-y: scroll;
overflow-x: hidden;
padding: 0px !important;
margin: -3px;
color: white;
height: 450px;
}
</style>
</head>
<body style="background-image: url(/Images/Background.png);">
<div id="webpage">
<div id="header">
<header class="header">
<!--<button onclick="cocoSound();">Test</button>-->
<a href="/CocoBox/" style="margin-right: 5px !important;"><img id="Coco" src="/Stickers/CocoBox.svg" onmouseover="const audio = new Audio(`/Coco.wav`); audio.play()"></a>
<div class="left-header">
<% if (false) { %>
<div></div>
<a class="content-only-a" href="/Games/">
<button class="special-button">Games</button>
</a>
<button class="special-button">Productivity</button>
<button class="special-button">Creation</button>
<button class="special-button">Develop</button>
<% } else { %>
<a class="content-only-a" href="/users/new/project/">
<button class="special-button">Create New</button>
</a>
<a class="content-only-a" href="/CocoBox/featured/">
<button class="special-button">Featured</button>
</a>
<a class="content-only-a" href="/Search/?type=project&date=now&tags=all">
<button class="special-button">Search</button>
</a>
<% } %>
</div>
<div id="user-controls" class="right-header">
<% if (user !=null && user !=="" ) { %>
<ul style="align-items: center; justify-content: center; color: goldenrod;">
Welcome back <a href="/users/<%= user.username %>">
<%= user.username %>
</a>!
</ul>
<a class="content-only-a" href="/manage">
<button class="special-button header-right">Manage account</button>
</a>
<% if (user.role==="Admin" ) { %>
<a class="content-only-a" href="/admin/">
<button class="special-button">Open Admin Panel</button>
</a>
<% } %>
<% } else { %>
<a class="content-only-a" href="/login/">
<button id="sign-in" class="special-button header-right">Sign In</button>
</a>
<a class="content-only-a" href="/register/">
<button class="special-button">Create Account</button>
</a>
<% } %>
</div>
</header>
</div>
<div id="container">
<div id="user-box">
<div class="user-box-head">
<h3 style="display: flex; flex-direction: row;">
<span id="project-name" style="flex: 1;" class>No Project!</span>
<input id="project-name-edit" style="flex: 1;" value="No Project!" class="hide">
<span style="float: right;">
<button id="like-button" class="special-button" onclick="toggleLike();" style="justify-items: center; justify-content: center; margin: 30px 20px;">Like <img class="sticker" src="/Images/Like project.png" style="margin: 0px; margin-left: 5px; margin-bottom: -5px;"></button>
<button id="favorite-button" class="special-button" onclick="toggleFavorite();" style="justify-items: center; justify-content: center;">Add to Favorites <img class="sticker" src="/Images/AddToFavorites.png" style="margin: 0px; margin-left: 10px; margin-bottom: -5px;"></button>
</span>
</h3>
<p id="project-owner"></p>
<p id="project-creators"></p>
<span style="margin-top: 20px; display: block;">
<span id="project-type" style="display: block; padding: 10px; border-radius: 3px; background-color: gray; position: static;" height="50px">
No type!
</span>
</span>
</div>
<div class="user-box" id="user-info">
<div>
<div class="box-push-into-left" style="padding: 10px !important;" style="width: 260px !important;">
<p style="font-size: 21px;">Project description:</p>
<br>
<textarea id="project-description-edit" class="hide"></textarea>
<p id="project-description">
This Project Is Null And Void!
</p>
</div>
<div id="sharing-options"></div>
</div>
<div style=" display: flex;
flex-direction: column !important;
height: 100%;">
<% if (isEditable) { %>
<button class="special-button" onclick="window.document.getElementById('edit-menu').classList.toggle('hide')">Edit project: </button>
<div id="edit-menu" class="hide">
<button class="special-button" onclick="uploadFile();">Upload project file</button>
<button class="special-button" onclick="uploadThumbnailFile();">Upload thumbnail file (Does not work on picture projects!)</button>
<div>
<h4>Change project type:</h4>
<select id="new-type-input">
<option>CocoScript</option>
<option>Video</option>
<option>Picture</option>
<option>Audio</option>
</select>
<button onclick="changeType();">Change</button>
</div>
<div class="hide">
<div style="width: 100%; height: 100%; background-color: #57575791; top: 0; left: 0; right: 0; bottom: 0; position: fixed; z-index: 100000 !important;">
<div class="user-box-head">
<h3>Add or remove creators. <button style="float: right !important;">X</button></h3>
</div>
<div>
<ul id="creators-list">
<li style="background-color: #5f5f5f; color: white; text-decoration: none;">
{username}
<hr>
{status}
</li>
</ul>
</div>
</div>
</div>
<script>
function uploadFile() {
const projectIndex = getProjectId();
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.onchange = () => {
const formData = new FormData();
formData.append("file", fileInput.files[0]);
document.getElementById("project-container").innerHTML = '<h1>Uploading file... <img height="50px" alt="Loading" src="/Images/loading.gif"></h1>';
fetch(`/api/projects/${projectIndex}/upload`, {
method: "POST",
body: formData
})
.then(res => {
if (!res.ok) {
if (res.status === 502) {
console.error("Upload error: Server returned 502 Bad Gateway");
alert("Upload failed: Server returned 502 Bad Gateway. This means the server is currently unavailable. Please try again later. (The file may be too large, and the server timed out or ran out of memory. Or the server is down.)");
document.getElementById("project-container").innerHTML = '<h1>Bad Gateway. Server is down, or it is updating.</h1>';
} else if (res.status === 413) {
console.error("Upload error: File too large");
alert("Upload failed: File too large. Max 50MB. Try file compression.");
document.getElementById("project-container").innerHTML = '<h1>Upload failed. File too large.</h1>';
} else {
console.error("Upload error: Server returned status", res.status);
alert(`Upload failed: Server returned status ${res.status}.`);
}
} else {
return res.json();
}
})
.then(uploadRes => {
console.log("Upload response:", uploadRes);
alert(uploadRes.status);
document.getElementById("project-container").innerHTML = '<h1>Uploaded. Refresh page to see changes. <button onclick="window.location.href = window.location.href;">Refresh</button></h1>';
}).catch(err => {
console.error("Upload error:", err);
alert("An error occurred during file upload.");
document.getElementById("project-container").innerHTML = '<h1>An Error occurred while uploading. Refresh page to go back. <button onclick="window.location.href = window.location.href;">Refresh</button></h1>'
});
};
fileInput.click(); // open file picker
}
function uploadThumbnailFile() {
const projectIndex = getProjectId();
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = "image/*";
fileInput.onchange = () => {
const formData = new FormData();
formData.append("file", fileInput.files[0]);
fetch(`/api/projects/${projectIndex}/uploadThumbs`, {
method: "POST",
body: formData
})
.then(res => {
if (!res.ok) {
if (res.status === 502) {
console.error("Upload error: Server returned 502 Bad Gateway");
alert("Upload failed: Server returned 502 Bad Gateway. This means the server is currently unavailable. Please try again later. (The file may be too large, and the server timed out or ran out of memory. Or the server is down.)");
} else if (res.status === 413) {
console.error("Upload error: File too large");
alert("Upload failed: File too large. Max 2MB. Try file compression.");
document.getElementById("project-container").innerHTML = '<h1>Upload failed. File too large.</h1>';
} else {
console.error("Upload error: Server returned status", res.status);
alert(`Upload failed: Server returned status ${res.status}.`);
}
} else {
return res.json();
}
})
.then(uploadRes => {
console.log("Upload response:", uploadRes);
alert(`Upload response: ${uploadRes}`);
document.getElementById("project-container").innerHTML = '<h1>Uploaded. Refresh page to see changes. <button onclick="window.location.href = window.location.href;">Refresh</button></h1>';
}).catch(err => {
console.error("Upload error:", err);
alert("An error occurred during thumbnail upload.");
document.getElementById("project-container").innerHTML = '<h1>An Error occurred while uploading. Refresh page to go back. <button onclick="window.location.href = window.location.href;">Refresh</button></h1>'
});
};
fileInput.click(); // open file picker
}
async function changeType() {
const newType = document.getElementById("new-type-input").value;
if ((newType !== "CocoScript") && (newType !== "Video") && (newType !== "Picture") && (newType !== "Audio")) {
alert("Invalid type!");
return;
}
const response = await fetch(`/api/projects/${getProjectId()}/change/type/${newType}/`, {
method: "POST"
});
if (response.status === 200) {
alert("Successfully changed the project type!");
} else {
alert("Failed to change the project type!");
}
}
</script>
</div>
<% } %>
<div style="display: flex;
gap: 1rem;
padding: 1rem;
/* Critical: allow inner flex items to shrink so scrolling works */
min-height: 0;
/* Stretch between header and footer */
flex: 1;
flex-direction: row !important;
">
<div id="project-container" style="border: black 2px solid !important; /* Stretch in the remaining horizontal space */
flex: 1;
overflow: none !important;
/* Critical: allow the scrolling area to shrink within the flex container */
min-height: 0;
/* Optional styling */
background: rgb(184, 184, 184);
border: 1px solid #ddd;
padding: 0px !important;
height: 350px;
justify-content: center; /* Centers horizontally */
align-items: center; /* Centers vertically */
display: flex;
">
<h1>Loading Project... <img height="50px" alt="Loading" src="/Images/loading.gif"></h1>
</div>
</div>
<% if (user && !isOwner) { %>
<button onclick="report('project', getProjectId());" class="report">Report this project.</button>
<% } %>
<% if (isOwner) { %>
<div>
Allow downloads: <label for="allowDownloads">
<input type="checkbox" id="allowDownloads" name="allowDownloads" <% if (downloadAllowed) { %> checked <% } %> onchange="fetch(`/api/projects/change/canDownload/${getProjectId()}/${document.getElementById('allowDownloads').checked}/`, {method: 'POST', body: JSON.stringify({canDownload: document.getElementById('allowDownloads').checked})});">
</label>
</div>
<% } %>
<div style="display: flex; column-gap: 10px; height: 50px;">
<% if (canDownload || isEditable) { %>
<a id="export-project-download" class="content-only-a" href=""><button>Download Project</button></a>
<script>
addEventListener("DOMContentLoaded", function(...args) {
document.getElementById("export-project-download").setAttribute("href", `/api/projects/process/export/?id=${getProjectId()}`);
});
</script>
<% } %>
<% if (isOwner) { %>
<button id="share-button" onclick="shareProject()">Share Project</button>
<button id="unshare-button" class="hide" onclick="unshareProject()">Unshare Project</button>
<% } else if (isEditable) { %>
<p>Only the project owner can share projects</p>
<% } %>
</div>
<% if (isOwner) { %>
<div id="share-project-confirm" class="hide">
Are you sure you want to share your project with everyone?:
<button onclick="shareProjectWithEveryone()">Yes</button>
<button class="special-button" onclick="document.getElementById('share-project-confirm').classList.add('hide');">No</button>
</div>
<div id="unshare-project-confirm" class="hide">
Are you sure you want to unshare (hide your project from everyone)?:
<button onclick="hideProjectFromEveryone()">Yes</button>
<button class="special-button" onclick="document.getElementById('unshare-project-confirm').classList.add('hide');">No</button>
</div>
<div id="share-status"></div>
<script>
function toggleDownload(allowed) {
fetch(`/api/projects/change/canDownload/${getProjectId()}/${allowed}`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
canDownload: allowed
})
});
}
function shareProject() {
document.getElementById("share-project-confirm").classList.toggle("hide");
}
function unshareProject() {
document.getElementById("unshare-project-confirm").classList.toggle("hide");
}
async function shareProjectWithEveryone() {
const response = await fetch(`/api/projects/${getProjectId()}/share/true/`, {
method: "POST"
});
const data = await response.json();
document.getElementById("share-status").innerHTML = data.status;
document.getElementById("share-project-confirm").classList.add("hide");
document.getElementById("unshare-project-confirm").classList.add("hide");
if (response.status === 200) {
document.getElementById("share-button").classList.add("hide");
document.getElementById("unshare-button").classList.remove("hide");
}
setTimeout(() => document.getElementById("share-status").innerHTML = "", 10000);
}
async function hideProjectFromEveryone() {
const response = await fetch(`/api/projects/${getProjectId()}/share/false/`, {
method: "POST"
});
const data = await response.json();
document.getElementById("share-status").innerHTML = data.status;
document.getElementById("share-project-confirm").classList.add("hide");
document.getElementById("unshare-project-confirm").classList.add("hide");
if (response.status === 200) {
document.getElementById("share-button").classList.remove("hide");
document.getElementById("unshare-button").classList.add("hide");
}
setTimeout(() => document.getElementById("share-status").innerHTML = "", 10000);
}
</script>
<% } %>
<p>Views: <span id="views-count">0</span>, Likes: <span id="likes-count">0</span>, Favorites: <span id="favorites-count">0</span>, Comments: <span id="comments-count">0</span></p>
<div style="margin-bottom: 20px !important; margin-top: -40px;">
<ul>
<p class="Welcome-text" style="display: block !important; float: none !important;">Comments</p>
</ul>
<div>
<% if (isOwner) { %>
<div>
Allow Comments: <label for="allow-comments">
<input type="checkbox" id="allow-comments" name="allow-comments" <% if (canComment) { %> checked <% } %> onchange="fetch(`/api/projects/${getProjectId()}/allowComments/${document.getElementById('allow-comments').checked}/`, {method: 'POST'});">
</label>
</div>
<% } %>
<ul>
<textarea id="comment-text" style="max-width: 747px; width: 435px; height: 133px;"></textarea>
<br>
<button id="post-comment" class="special-button">Post</button>
<button id="cancel-comment">Cancel</button>
<div id="comment-server-response"></div>
</ul>
<ul id="comments">
</ul>
</div>
</div>
</div>
<div id="main-nav-box" class="navigation-box">
</div>
<div id="error-container" class="error-container-hide">
<!--Some Scripts Have Probably Crashed-->
<div id="e" class="error big-box"></div>
</div>
</div>
</div>
<% if (user) { %>
<script>
const username = "<%= user.username %>";
</script>
<% } else { %>
<script>
const username = "";
</script>
<% } %>
<% if (user) { %>
<script>
localStorage.setItem("poopUsername", "<%= user.username %>");
</script>
<% } %>
<script src="/JS/CocoScript Engine/CocoScript.js"></script>
<script src="/Scripts/user.js"></script>
<script src="/Ambler.mp3Sound.js"></script>
<!-- Initialize @.js -->
<script src="/JS/@.js"></script>
<script src="https://vjs.zencdn.net/8.23.4/video.min.js"></script>
<script src="/JS/project.js"></script>
<script src="/JS/global.js"></script>
</body>
</html>