generated from CodeChefVIT/template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
244 lines (220 loc) · 9.18 KB
/
app.js
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
const base = 'https://devsoc-api.codechefvit.com'
// index
function load (token) {
const xhr1 = new XMLHttpRequest()
xhr1.withCredentials = false
xhr1.responseType = 'json'
xhr1.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
console.log(this.response.teams)
const teamlist = this.response.teams
window.localStorage.setItem('teams', JSON.stringify(teamlist))
document.getElementById('count').innerHTML = teamlist.length
let htmlString = ''
let i
for (i = 0; i < teamlist.length; i++) {
let memlist = ''
let j
for (j = 0; j < teamlist[i].users.length; j++) {
memlist = memlist + ' | ' + teamlist[i].users[j].name
}
const id = teamlist[i].leader._id
htmlString = htmlString +
`
<div class="summary">
<div class="text">
<h1 class="team">Team ${teamlist[i].name}</h1>
<h1 class="members"> Members - ${teamlist[i].users.length} </h1>
<h1 class="submitted"> ${teamlist[i].submission.status}</h1>
</div>
<p class="names">${memlist}</p>
<div class="lrow">
<div class="lrow1">
<select name="qualifiedstatus" class="dropdown" onchange="patch1(this.value,'${teamlist[i]._id}')">
<option value="" disabled selected>Select Status</option>
<option value="Shortlisted For DEVSOC'21">Shortlisted For DEVSOC'21</option>
<option value="Not Shortlisted For DEVSOC'21">Not Shortlisted For DEVSOC'21</option>
<option value="Shortlisted For Round 2">Shortlisted For Round 2</option>
<option value="Not Shortlisted For Round 2">Not Shortlisted For Round 2</option>
<option value="Selected For Final Round">Selected For Final Round</option>
</select>
<!--<button type="submit" class="zip">
<img src="zip.png" alt="Save icon" />
</button>-->
</div>
<a class="submit1" onclick="myfunction('${teamlist[i]._id}')">Submission details > </a>
</div>
</div>
`
}
document.getElementsByClassName('cont')[0].innerHTML = htmlString
}
})
xhr1.open('GET', 'https://devsoc-api.codechefvit.com/admin/all')
xhr1.setRequestHeader('Authorization', 'Bearer ' + token)
xhr1.send()
}
function patch1 (a, b) {
console.log('yes')
const jwttoken = window.localStorage.getItem('jwttoken')
const data = JSON.stringify({
teamId: b,
status: a
})
const xhr = new XMLHttpRequest()
xhr.withCredentials = false
xhr.responseType = 'json'
xhr.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
console.log(this.response)
}
})
xhr.open('PATCH', 'https://devsoc-api.codechefvit.com/admin/status')
xhr.setRequestHeader('Authorization', 'Bearer ' + jwttoken)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(data)
}
function display (teamlist) {
document.getElementById('count').innerHTML = teamlist.length
let htmlString = ''
let i
for (i = 0; i < teamlist.length; i++) {
let memlist = ''
let j
for (j = 0; j < teamlist[i].users.length; j++) {
memlist = memlist + ' | ' + teamlist[i].users[j].name
}
const id = teamlist[i].leader._id
htmlString = htmlString +
`
<div class="summary">
<div class="text">
<h1 class="team">Team ${teamlist[i].name}</h1>
<h1 class="members"> Members - ${teamlist[i].users.length} </h1>
<h1 class="submitted"> ${teamlist[i].submission.status}</h1>
</div>
<p class="names">${memlist}</p>
<div class="lrow">
<div class="lrow1">
<select name="qualifiedstatus" class="dropdown" onchange="patch1(this.value,'${teamlist[i]._id}')">
<option value="" disabled selected>Select Status</option>
<option value="Shortlisted For DEVSOC'21">Shortlisted For DEVSOC'21</option>
<option value="Not Shortlisted For DEVSOC'21">Not Shortlisted For DEVSOC'21</option>
<option value="Shortlisted For Round 2">Shortlisted For Round 2</option>
<option value="Not Shortlisted For Round 2">Not Shortlisted For Round 2</option>
<option value="Selected For Final Round">Selected For Final Round</option>
</select>
<!--<button type="submit" class="zip">
<img src="zip.png" alt="Save icon" />
</button>-->
</div>
<a class="submit1" onclick="myfunction('${teamlist[i]._id}')">Submission details > </a>
</div>
</div>
`
}
document.getElementsByClassName('cont')[0].innerHTML = htmlString
}
// index
const searchBar = document.getElementById('search')
searchBar.addEventListener('keyup', (e) => {
document.getElementById('filterteams').selectedIndex = 0
const teamnames = JSON.parse(window.localStorage.getItem('teams'))
const searchString = e.target.value.toLowerCase()
const filteredCharacters = teamnames.filter((character) => {
return (
character.name.toLowerCase().includes(searchString)
)
})
if (filteredCharacters.length === 0) {
document.getElementsByClassName('cont')[0].innerHTML = 'No Results Found'
} else {
document.getElementsByClassName('cont')[0].innerHTML = ''
display(filteredCharacters)
}
})
// team_details
function myfunction (a) {
const jwttoken = window.localStorage.getItem('jwttoken')
const xhr = new XMLHttpRequest()
xhr.withCredentials = false
xhr.responseType = 'json'
xhr.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
console.log(this.response.team)
window.localStorage.setItem('teaminfo', JSON.stringify(this.response.team))
const newWindow = window.open('team_details.html')
const teaminfo = JSON.parse(window.localStorage.getItem('teaminfo'))
newWindow.onload = function () {
newWindow.console.log(teaminfo)
newWindow.document.getElementById('team').innerHTML = 'Team ' + teaminfo.name
let i
let memname = ''
for (i = 0; i < teaminfo.users.length; i++) {
memname += teaminfo.users[i].name + ' | '
}
newWindow.document.getElementById('options').innerHTML =
`
<select name="qualifiedstatus" class="dropdown" id="updatestat" onchange="patch1(this.value,'${teaminfo._id}')">
<option value="" disabled selected>Select Status</option>
<option value="Shortlisted For DEVSOC'21">Shortlisted For DEVSOC'21</option>
<option value="Not Shortlisted For DEVSOC'21">Not Shortlisted For DEVSOC'21</option>
<option value="Shortlisted For Round 2">Shortlisted For Round 2</option>
<option value="Not Shortlisted For Round 2">Not Shortlisted For Round 2</option>
<option value="Selected For Final Round">Selected For Final Round</option>
</select>
`
let ii
for(ii=1;ii<6;ii++){
if(newWindow.document.getElementById('updatestat').options[ii].value==teaminfo.submission.status){
newWindow.document.getElementById('updatestat').options[ii].setAttribute('selected', true);
}
}
newWindow.document.getElementById('names').innerHTML = memname
newWindow.document.getElementById('submitted').innerHTML = '| ' + teaminfo.submission.status
newWindow.document.getElementById('members').innerHTML = '| Members- ' + teaminfo.users.length
if (teaminfo.submission.status != 'Not Submitted') {
newWindow.document.getElementById('name').value = teaminfo.submission.name
newWindow.document.getElementById('msg').value = teaminfo.submission.videolink
newWindow.document.getElementById('repolink').value = teaminfo.submission.githubLink
let clean = window.DOMPurify.sanitize(marked(teaminfo.submission.description))
const reg = /script/ig
/* |iframe|form|object|embed|link|head|meta */
const scripts = ['script', 'iframe', 'form', 'object', 'embed', 'link', 'head', 'meta', 'alert', 'style', 'img', 'body', 'html']
for (let k = 0; k < scripts.length; k++) {
clean = clean.replaceAll(scripts[k], '')
}
newWindow.console.log(clean)
// let clean = DOMPurify.sanitize( marked(teaminfo.submission.description) , {USE_PROFILES: {html: true}} )
newWindow.document.getElementById('projdesc').innerHTML = clean
}
}
}
})
xhr.open('GET', 'https://devsoc-api.codechefvit.com/admin/team/' + a.toString())
xhr.setRequestHeader('Authorization', 'Bearer ' + jwttoken)
xhr.send()
}
// index
const a = document.getElementById('filterteams')
a.addEventListener('click', function () {
const teamnames = JSON.parse(window.localStorage.getItem('teams'))
const optiontext = a.options[a.selectedIndex].text
const filteredCharacters = teamnames.filter((character) => {
return (
character.submission.status == optiontext
)
})
if (filteredCharacters.length === 0 && optiontext != 'All') {
document.getElementsByClassName('cont')[0].innerHTML = 'No Results Found'
} else if (filteredCharacters.length === 0 && optiontext == 'All') {
display(teamnames)
} else {
document.getElementsByClassName('cont')[0].innerHTML = ''
display(filteredCharacters)
}
})
function logoutFunctn () {
localStorage.clear()
window.location.assign('index.html')
}