-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·86 lines (70 loc) · 2.84 KB
/
Copy pathmain.js
File metadata and controls
executable file
·86 lines (70 loc) · 2.84 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
// =============================================================================
// Parallel Scripts
// =============================================================================
import '../../node_modules/babel-polyfill/dist/polyfill';
import getUser from './user';
import getChallenge from './challenge';
import '../../node_modules/@johmun/vue-tags-input/dist/vue-tags-input';
function removeStudent(id, index, level) {
if (window.confirm('Are you sure you want to remove this student?')) {
return fetch('/remove-student', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({id})
}).then((response) => {
if (!response.ok) return alert('Something went wrong. Please try again!');
const table = document.querySelector(`.dashboard-table[data-level='${level}']`);
table.querySelector(`.dashboard-names tr[data-index='${index}']`).remove();
table.querySelector(`.dashboard-data tr[data-index='${index}']`).remove();
});
}
}
function getRowValue(row, i) {
if (i === 0) return -row[0].dataset.index;
return +row[1].childNodes[i - 1].dataset.value;
}
function sortTable(i, level) {
const $table = document.querySelector(`.dashboard-table[data-level="${level}"]`);
const $active = $table.querySelector('.dashboard-active');
if ($active) $active.classList.remove('dashboard-active');
const $labels = $table.querySelectorAll('th');
$labels[i].classList.add('dashboard-active');
const $namesBox = $table.querySelector('.dashboard-names tbody');
const $rowsBox = $table.querySelector('.dashboard-data tbody');
const $names = $namesBox.childNodes;
const rows = Array.from($rowsBox.childNodes).map(($r, i) => [$names[i], $r]);
const ordered = rows.sort((a, b) => getRowValue(b, i) - getRowValue(a, i));
for (let row of ordered) {
$namesBox.appendChild(row[0]);
$rowsBox.appendChild(row[1]);
}
}
// Disables scroll on number inputs to avoid accidental changes
document.addEventListener("wheel", function(event){
if(document.activeElement.type === "number"){
document.activeElement.blur();
}
});
document.addEventListener('DOMContentLoaded', function() {
firebase.initializeApp({
apiKey: "AIzaSyDk4_ME-Uy1D3Yjg94Af7Gzhg3I1xNYWp8",
projectId: "parallel-beta-31dc4",
authDomain: "parallel-beta-31dc4.firebaseapp.com",
});
const user = getUser();
const challenge = window.PARALLELOGRAM ? getChallenge() : null;
Vue.component('v-style', {
render: function (createElement) {
return createElement('style', this.$slots.default)
}
});
if (window.self !== window.top) {
document.body.className = 'insideIframe'
}
window.app = new Vue({
el: '#vue',
components: {VueTagsInput: window.vueTagsInput.default},
data: {showSidebar: false, showWelcomeMsg: true, user, c: challenge,
removeStudent, sortTable}
});
});