-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
408 lines (352 loc) · 19.5 KB
/
index.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
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
<!DOCTYPE html>
<html>
<head>
<title>Central - Home</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- Fonts and icons -->
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
<link rel="shortcut icon" href="static/logoicon.ico"/>
<!-- Material Kit CSS -->
<link href="assets/css/material-dashboard.css?v=2.1.2" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="static/mainstyle.css">
<script>
class tag
{
static tags = [];
static htmlBegin = String.raw
`
<button class="btn btn-warning btn-sm" onclick="
`;
static htmlCenter = String.raw
`
">
`;
static htmlEnd = String.raw
`
 <i class="material-icons">close</i></button>
`;
}
function loadSubjects()
{
let query = document.getElementById('search-input').value.toLowerCase();
let newHTML = '';
let baseHTML = String.raw
`
<h4>Year 9</h4>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 English</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 Mathematics</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 Science</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 History</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 Geography</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 Language</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 Digital Technology</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 Art</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 9 Music</button></a>
<br>
<h4>Year 10</h4>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 English</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 Mathematics</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 Science</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 History</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 Geography</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 Language</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 Digital Technology</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 Art</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Year 10 Music</button></a>
<br>
<h4>Year 11</h4>
<a href='explore.html'><button class='btn btn-success btn-lg'>English Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>English Language Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Literature Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Mathematical Methods Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Specialist Mathematics Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Biology Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Chemistry Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Physics Units 1/2</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Computing Units 1/2</button></a>
<br>
<h4>Year 12</h4>
<a href='explore.html'><button class='btn btn-success btn-lg'>English Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>English Language Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Literature Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Mathematical Methods Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Specialist Mathematics Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Biology Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Chemistry Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Physics Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Software Development Units 3/4</button></a>
<a href='explore.html'><button class='btn btn-success btn-lg'>Algorithmics Units 3/4</button></a>
`
let e = document.getElementById('subjects-html');
if (baseHTML === '')
baseHTML = new String(e.innerHTML);
baseHTML.split(/\r?\n/).forEach(element => {
let str = element.trim();
if (!str.includes('btn btn-success btn-lg') || str.toLowerCase().includes(query.trim().toLowerCase()))
{
newHTML += str + '\n';
}
});
e.innerHTML = newHTML;
}
function ImageUpload(){
var DummyButton = document.getElementById("DummyButton");
var UploadButton = document.getElementById("UploadButton");
var ImageName = document.getElementById("customName");
UploadButton.addEventListener("click",function(){
DummyButton.click();
});
DummyButton.addEventListener("change",function(){
if(DummyButton.value){
ImageName.innerHTML = DummyButton.value.match(/[\/\\]([\w\d\s\.\-\(\)]+)$/)[1];
}
else{
ImageName.innerHTML = "<h6>No Image Selected</h6>";
}
});
}
function addTag(tagStr)
{
if (!tag.tags.includes(tagStr))
{
tag.tags.push(tagStr);
updateTags();
}
}
function removeTag(tagStr)
{
tag.tags = tag.tags.filter(item => item !== tagStr);
updateTags();
}
function updateTags()
{
let e = document.getElementById('tags-html');
e.innerHTML = '';
tag.tags.forEach(item => {
e.innerHTML += tag.htmlBegin + `removeTag(\'${item}\')` + tag.htmlCenter + item + tag.htmlEnd;
});
}
function loadPostSection()
{
let postSection = document.getElementById('post-html');
postSection.innerHTML = String.raw
`
<button class="btn btn-danger right-align" onclick="unloadPostSection()"><i class="material-icons">close</i></button>
<br><br><br>
<form class="wide-transition">
<input id="post-author-input" type="text" placeholder="Name..." name="author-name">
<br><br>
<input id="post-subject-input" type="text" placeholder="Subject..." name="subject-name">
</form>
<p></p>
<textarea class="fit post-body-box" id="post-body-input" type="text/img" placeholder="Text..." name="post-body" rows="15"></textarea>
<h6>
<button class="btn btn-primary" onclick="let t = document.getElementById('tag-input').value; if (t !== '') addTag(t)"><i class="material-icons">add</i> Add Tag</button>
<input style="padding: 4px;", id="tag-input", type="text" placeholder="Tag..." name="tag">
<button class="btn btn-info" id="UploadButton" onclick="ImageUpload()""><i class="material-icons">image</i> Add Image</button>
<input type="file" id="DummyButton" hidden="hidden"/>
<span id="customName"> No file selected </span>
<button class="btn btn-success right-align" onclick="postPost()"><i class="material-icons">add</i> Post</button>
<br>
<div id="tags-html">
</div>
</h6>
`
}
function unloadPostSection()
{
let postSection = document.getElementById('post-html');
postSection.innerHTML = String.raw
`
<button class="btn btn-primary" onclick="loadPostSection()"><i class="material-icons">add</i> New Post</button>
`
}
async function postPost()
{
var tagsString = "[ ";
tag.tags.forEach(item => {
tagsString += `\"${item}\", `;
});
tagsString = tagsString.substr(0, tagsString.length - 2);
tagsString += " ]";
console.log(tagsString);
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://sentral2database--dragonfan.repl.co", false);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(String.raw
`
{
"type": "add",
"data":
{
"author": "${document.getElementById('post-author-input').value}",
"subject": "${document.getElementById('post-subject-input').value}",
"tags": ${tagsString},
"content": "${document.getElementById('post-body-input').value}",
"post_time": "${new Date(Date.now()).toISOString()}",
"upvotes": 0
}
}
`);
console.log(xhr.responseText);
tag.tags = [];
let postSection = document.getElementById('post-html');
postSection.innerHTML = String.raw
`
<button class="btn btn-primary" onclick="loadPostSection()"><i class="material-icons">add</i> New Post</button>
<br>
<button class="btn btn-success fit" onclick="unloadPostSection()">Question has been posted!</button>
`
}
function createQString(elementID,topicName){
let button = document.getElementById(elementID);
button.addEventListener("click", function(){
window.document.location = "explore.html" + "?SubjectTag=" + topicName;
});
}
</script>
</head>
<body onload="loadSubjects(); unloadPostSection(); tag.tags = [];">
<div class="sidebar">
<div class="logo"><img src="static/logo.png"></div>
<hr>
<p><a href="index.html"><button class="btn btn-default btn-lg btn-link fit"><i class="material-icons">home</i> Home</button></a></p>
<p><a href="explore.html"><button class="btn btn-default btn-lg btn-link fit"><i class="material-icons">search</i> Explore</button></a></p>
<p><a href="aboutus.html"><button class="btn btn-default btn-lg btn-link fit"><i class="material-icons">group</i> About us</button></a></p>
</div>
<div class="content">
<h1><b>Central</b></h1>
<hr>
<div class="post">
<div id="post-html"></div>
</div>
<br>
<div class="my-subjects">
<h2>My Subjects</h2>
<div class="cards"><div class="row">
<div class="col-sm-3">
<div class="card subject-card">
<div class="card-header card-header-icon card-header-rose">
<div class="card-icon">
<i class="material-icons">book</i>
</div>
</div>
<div class="card-body">
<h2 class="card-title">English Language</h2>
<br>
<p class="category">
Tags:
<a href="#"><button class="btn btn-info btn-sm" id="English">ENGLISH</button></a>
<a href="#"><button class="btn btn-info btn-sm" id="English">Units 3/4</button></a>
</p>
<script>
createQString("English","english language")
</script>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="card subject-card">
<div class="card-header card-header-icon card-header-rose">
<div class="card-icon">
<i class="material-icons">pin</i>
</div>
</div>
<div class="card-body">
<h2 class="card-title">Mathematical Methods</h2>
<br>
<p class="category">
Tags:
<a href="#"><button class="btn btn-info btn-sm" id="MethB">MATHS</button></a>
<a href="#"><button class="btn btn-info btn-sm" id="MethB">Units 3/4</button></a>
</p>
<script>
createQString("MethB","mathematical methods")
</script>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="card subject-card">
<div class="card-header card-header-icon card-header-rose">
<div class="card-icon">
<i class="material-icons">science</i>
</div>
</div>
<div class="card-body">
<h2 class="card-title">Physics</h2>
<br>
<p class="category">
Tags:
<a href="#"><button class="btn btn-info btn-sm" id="PhyB">SCIENCE</button></a>
<a href="#"><button class="btn btn-info btn-sm" id="PhyB">Units 3/4</button></a>
</p>
<script>
createQString("PhyB","Physics")
</script>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="card subject-card">
<div class="card-header card-header-icon card-header-rose">
<div class="card-icon">
<i class="material-icons">science</i>
</div>
</div>
<div class="card-body">
<h2 class="card-title">Specialist Mathematics</h2>
<br>
<p class="category">
Tags:
<a href="#"><button class="btn btn-info btn-sm" id="SpeshB">MATHS</button></a>
<a href="#"><button class="btn btn-info btn-sm" id="SpeshB">Units 3/4</button></a>
</p>
<script>
createQString("SpeshB","Specialist Mathematics")
</script>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="card subject-card">
<div class="card-header card-header-icon card-header-rose">
<div class="card-icon">
<i class="material-icons">computer</i>
</div>
</div>
<div class="card-body">
<h2 class="card-title">Algorithmics</h2>
<br>
<p class="category">
Tags:
<a href="#"><button class="btn btn-info btn-sm" id="AlgoB">COMPUTER SCIENCE</button></a>
<a href="#"><button class="btn btn-info btn-sm" id="AlgoB">Units 3/4</button></a>
</p>
<script>
createQString("AlgoB","Algorithmics")
</script>
</div>
</div>
</div>
</div></div>
<br>
<!-- browse all subjects, maybe i could make this into an alphabetically sorted system? or make a search feature? -->
<div class="all-subjects">
<h2>All Subjects</h2>
<div class="wide-transition">
<input onkeyup="return loadSubjects()" id="search-input" type="text" placeholder="Filter..." name="search">
</div>
<p></p>
<div id="subjects-html">
</div>
<br>
</div>
</div>
</body>
</html>