-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-scores.js
80 lines (64 loc) · 1.96 KB
/
test-scores.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
let config = {
apiKey: "AIzaSyDusGUpsFfhJmRnmB2cgfetwR3ZR2otqe4",
authDomain: "fantasycivics.firebaseapp.com",
databaseURL: "https://fantasycivics.firebaseio.com",
storageBucket: "fantasycivics.appspot.com",
messagingSenderId: "245596715039"
};
let DatabaseFirebase = firebase.initializeApp(config, 'Fantasy Civics Database');
let DatabaseInstance = DatabaseFirebase.database();
let ss = document.getElementsByClassName('select-system');
for(let s = 0; s < ss.length; s++){
let selector = ss[s];
SCORING_SYSTEMS.forEach((system, sidx) => {
let option = document.createElement('option');
option.value = sidx;
option.innerText = system.name;
selector.appendChild(option);
});
selector.addEventListener('change', e => {
let id = e.target.dataset.holder;
window.dispatchEvent(new CustomEvent('score-roster', {
detail: {
id: id,
system: e.target.value
}
}));
});
}
let displayScoredRoster = (id, module, system) => {
let out = document.getElementById(id);
out.innerHTML = '';
let h = document.getElementById('h-' + id);
let scores = module.scoreByFunction(system);
h.innerText = system.name;
let table = RosterView(scores, {
clickRow: system.clickRow,
module: module
});
out.appendChild(table);
Sortable.initTable(table);
}
let sm = ScoringModule({
database: DatabaseInstance,
datasets: SOCRATA_DATASETS,
players: PLAYER_MAP,
range: {
from: new Date('4/1/2017').getTime(),
to: new Date('4/30/2017').getTime()
}
});
sm.init().then(playerMap => {
//console.log(playerMap);
window.playerMap = playerMap;
var loadingScreen = document.getElementById('loading');
loadingScreen.style.display = 'none';
displayScoredRoster('roster1', sm, SCORING_SYSTEMS[0]);
displayScoredRoster('roster2', sm, SCORING_SYSTEMS[1]);
window.addEventListener('score-roster', e => {
let sidx = parseInt(e.detail.system);
let system = SCORING_SYSTEMS[sidx];
let id = e.detail.id;
displayScoredRoster(id, sm, system);
});
}).catch(console.error);