2017-11-02 10:16:34 +01:00
|
|
|
/* GLOB VAR */
|
2017-11-02 08:41:30 +01:00
|
|
|
var allOrg = [];
|
|
|
|
var datatableTop;
|
2017-11-13 16:02:09 +01:00
|
|
|
var datatableFameQuant;
|
2017-11-06 15:00:51 +01:00
|
|
|
var refresh_speed = min_between_reload*60;
|
2017-11-14 14:56:15 +01:00
|
|
|
var next_effect = new Date();
|
2017-11-06 15:00:51 +01:00
|
|
|
var will_reload = $("#reloadCheckbox").is(':checked');
|
|
|
|
var sec_before_reload = refresh_speed;
|
2017-11-14 14:05:54 +01:00
|
|
|
var plotLineChart;
|
|
|
|
var source_awards;
|
|
|
|
var source_lastContrib;
|
2018-09-24 12:23:04 +02:00
|
|
|
var last_added_contrib;
|
|
|
|
var timeout_last_added_contrib;
|
2017-11-02 10:16:34 +01:00
|
|
|
|
|
|
|
/* CONFIG */
|
|
|
|
var maxRank = 16;
|
|
|
|
var popOverOption = {
|
|
|
|
trigger: "hover",
|
|
|
|
html: true,
|
|
|
|
placement: 'bottom',
|
2017-11-13 15:19:30 +01:00
|
|
|
content: generateRankingSheet(),
|
|
|
|
template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content popoverNoPadding"></div></div>'
|
2017-11-02 10:16:34 +01:00
|
|
|
}
|
2017-11-02 08:41:30 +01:00
|
|
|
var optionsLineChart = {
|
|
|
|
series: {
|
|
|
|
shadowSize: 0 ,
|
|
|
|
lines: {
|
|
|
|
fill: true,
|
|
|
|
fillColor: {
|
|
|
|
colors: [ { opacity: 1 }, { opacity: 0.1 } ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-11-09 10:32:39 +01:00
|
|
|
colors: ["#2F4F4F", "#778899", "#696969", "#A9A9A9", "#D3D3D3", "#337ab7"],
|
2017-11-02 08:41:30 +01:00
|
|
|
points: { show: true },
|
|
|
|
lines: { show: true, fill: true },
|
|
|
|
grid: {
|
|
|
|
tickColor: "#dddddd",
|
|
|
|
borderWidth: 0
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
show: true,
|
|
|
|
position: "nw"
|
2017-11-09 10:32:39 +01:00
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
mode: "time",
|
|
|
|
timeformat: "%m/%d",
|
|
|
|
minTickSize: [1, "day"]
|
2017-11-02 08:41:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var optionDatatable_light = {
|
|
|
|
responsive: true,
|
|
|
|
searching: false,
|
|
|
|
ordering: false,
|
|
|
|
scrollY: '30vh',
|
|
|
|
scrollCollapse: true,
|
|
|
|
paging: false,
|
|
|
|
"language": {
|
|
|
|
"lengthMenu": "",
|
|
|
|
"info": "",
|
|
|
|
"infoFiltered": "",
|
|
|
|
"infoEmpty": "",
|
|
|
|
},
|
|
|
|
"info": false,
|
2017-11-07 12:54:08 +01:00
|
|
|
"columnDefs": [
|
|
|
|
{ className: "centerCellPicOrgRank", "targets": [ 2 ] },
|
2017-11-08 11:29:07 +01:00
|
|
|
{ className: "centerCellPicOrgLogo", "targets": [ 3 ] },
|
|
|
|
{ className: "centerCellPicOrgLogo", "targets": [ 4 ] }
|
2017-11-07 12:54:08 +01:00
|
|
|
]
|
2017-11-02 08:41:30 +01:00
|
|
|
};
|
|
|
|
var optionDatatable_top = jQuery.extend({}, optionDatatable_light)
|
|
|
|
var optionDatatable_last = jQuery.extend({}, optionDatatable_light)
|
2017-11-14 14:05:54 +01:00
|
|
|
optionDatatable_last["ordering"] = true;
|
|
|
|
optionDatatable_last["order"] = [[ 0, "dec" ]];
|
2017-11-06 13:43:55 +01:00
|
|
|
optionDatatable_last.columnDefs = [
|
2017-11-10 10:32:51 +01:00
|
|
|
{ className: "small", "targets": [ 0 ] },
|
|
|
|
{ className: "verticalAlign", "targets": [ 1 ] },
|
|
|
|
{ className: "centerCellPicOrgRank verticalAlign", "targets": [ 2 ] },
|
2017-11-07 12:59:32 +01:00
|
|
|
{ className: "centerCellPicOrgLogo", "targets": [ 3 ] },
|
2017-11-10 10:32:51 +01:00
|
|
|
{ className: "centerCellPicOrgLogo verticalAlign", "targets": [ 4 ] },
|
|
|
|
{ className: "centerCellPicOrgLogo verticalAlign", "targets": [ 5 ] },
|
2017-11-14 14:05:54 +01:00
|
|
|
{ className: "verticalAlign", "targets": [ 6 ] }
|
2017-11-06 13:43:55 +01:00
|
|
|
]
|
2017-12-01 16:02:28 +01:00
|
|
|
var optionDatatable_fameQuant = jQuery.extend({}, optionDatatable_light)
|
|
|
|
var optionDatatable_fameQual = jQuery.extend({}, optionDatatable_light)
|
2017-12-04 11:49:30 +01:00
|
|
|
optionDatatable_fameQual.scrollY = '39vh';
|
2017-11-02 08:41:30 +01:00
|
|
|
|
|
|
|
var optionDatatable_Categ = {
|
|
|
|
responsive: true,
|
|
|
|
searching: true,
|
2017-11-10 09:00:50 +01:00
|
|
|
"order": [[ 0, "desc" ]],
|
2017-11-21 09:53:24 +01:00
|
|
|
scrollY: '35vh',
|
2017-11-02 16:10:40 +01:00
|
|
|
"scrollX": true,
|
2017-11-02 08:41:30 +01:00
|
|
|
scrollCollapse: true,
|
|
|
|
paging: false,
|
|
|
|
"info": false,
|
2017-11-07 12:54:08 +01:00
|
|
|
"columnDefs": [
|
|
|
|
{ className: "centerCellPicOrgRank", "targets": [ 2 ] },
|
2017-11-08 11:29:07 +01:00
|
|
|
{ className: "centerCellPicOrgLogo", "targets": [ 3 ], 'searchable': false, 'sortable': false },
|
|
|
|
{ className: "centerCellPicOrgLogo", "targets": [ 4 ]}
|
2017-11-07 12:54:08 +01:00
|
|
|
]
|
2017-11-02 08:41:30 +01:00
|
|
|
};
|
2017-11-14 09:50:20 +01:00
|
|
|
var optionDatatable_awards = jQuery.extend({}, optionDatatable_light);
|
|
|
|
optionDatatable_awards["ordering"] = true;
|
|
|
|
optionDatatable_awards["order"] = [[ 0, "dec" ]];
|
2017-11-14 14:05:54 +01:00
|
|
|
optionDatatable_awards["scrollX"] = false;
|
2017-11-21 09:53:24 +01:00
|
|
|
optionDatatable_awards["scrollY"] = "40vh";
|
2017-11-13 16:02:09 +01:00
|
|
|
optionDatatable_awards.columnDefs = [
|
2017-11-21 14:53:55 +01:00
|
|
|
{ className: "centerCellPicOrgLogo verticalAlign", "targets": [ 1 ] },
|
|
|
|
{ className: "centerCellPicOrgLogo", "targets": [ 3 ] },
|
2017-11-14 09:50:20 +01:00
|
|
|
];
|
2017-11-02 08:41:30 +01:00
|
|
|
|
|
|
|
var typeaheadOption = {
|
|
|
|
source: function (query, process) {
|
|
|
|
if (allOrg.length == 0) { // caching
|
|
|
|
return $.getJSON(url_getAllOrg, function (data) {
|
|
|
|
allOrg = data;
|
|
|
|
return process(data);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return process(allOrg);
|
|
|
|
}
|
|
|
|
},
|
2017-11-02 10:57:16 +01:00
|
|
|
updater: function(org) {
|
|
|
|
updateProgressHeader(org);
|
2017-11-02 08:41:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FUNCTIONS */
|
2017-11-07 12:54:08 +01:00
|
|
|
function getMonthlyRankIcon(rank, size, header) {
|
2017-11-02 15:14:21 +01:00
|
|
|
if (rank > 16) {
|
2017-11-07 12:54:08 +01:00
|
|
|
var rankLogoPath = url_baseRankMonthlyLogo+0+'.svg';
|
2017-11-02 15:14:21 +01:00
|
|
|
} else {
|
2017-11-07 12:54:08 +01:00
|
|
|
var rankLogoPath = url_baseRankMonthlyLogo+rank+'.svg';
|
2017-11-02 15:14:21 +01:00
|
|
|
}
|
2017-11-02 08:41:30 +01:00
|
|
|
var img = document.createElement('img');
|
|
|
|
img.src = rankLogoPath;
|
|
|
|
if(size == undefined) {
|
|
|
|
img.height = 26;
|
|
|
|
img.width = 26;
|
|
|
|
} else {
|
2017-11-02 10:16:34 +01:00
|
|
|
if (header) {
|
|
|
|
img.height = size;
|
|
|
|
img.width = size;
|
|
|
|
img.style.position = 'absolute';
|
|
|
|
img.style.top = '0';
|
|
|
|
img.style.bottom = '0';
|
|
|
|
img.style.margin = 'auto';
|
|
|
|
img.style.left = '0px';
|
|
|
|
} else {
|
|
|
|
img.height = size;
|
|
|
|
img.width = size;
|
|
|
|
}
|
2017-11-02 08:41:30 +01:00
|
|
|
}
|
|
|
|
return img.outerHTML;
|
|
|
|
}
|
2017-11-06 18:40:44 +01:00
|
|
|
|
2017-11-07 12:54:08 +01:00
|
|
|
function getOrgRankIcon(rank, size) {
|
|
|
|
if (rank > 16) {
|
|
|
|
var rankLogoPath = url_baseOrgRankLogo+0+'.svg';
|
|
|
|
} else {
|
|
|
|
var rankLogoPath = url_baseOrgRankLogo+rank+'.svg';
|
|
|
|
}
|
|
|
|
var obj = document.createElement('img');
|
|
|
|
obj.height = size/2;
|
|
|
|
obj.width = size;
|
|
|
|
obj.src = rankLogoPath;
|
|
|
|
obj.type = "image/svg"
|
|
|
|
obj.title = org_rank_obj[rank];
|
|
|
|
obj.classList.add('orgRankClass')
|
|
|
|
return obj.outerHTML;
|
|
|
|
}
|
|
|
|
|
2017-11-08 11:29:07 +01:00
|
|
|
function createImg(source, size) {
|
2017-11-09 13:43:02 +01:00
|
|
|
var obj = document.createElement('img');
|
2017-11-07 12:54:08 +01:00
|
|
|
obj.height = size;
|
|
|
|
obj.width = size;
|
2017-11-06 18:40:44 +01:00
|
|
|
obj.style.margin = 'auto';
|
2017-11-09 13:43:02 +01:00
|
|
|
obj.src = source;
|
|
|
|
obj.type = "image/png"
|
|
|
|
obj.alt = ""
|
2017-11-06 18:40:44 +01:00
|
|
|
return obj.outerHTML;
|
|
|
|
}
|
|
|
|
|
2017-11-14 14:05:54 +01:00
|
|
|
function createTrophyImg(rank, size, categ) {
|
|
|
|
var obj = document.createElement('img');
|
|
|
|
obj.height = size;
|
|
|
|
obj.width = size;
|
|
|
|
obj.style.margin = 'auto';
|
|
|
|
obj.src = url_baseTrophyLogo+rank+'.png';;
|
|
|
|
obj.title = trophy_title[rank] + " in " + categ;
|
|
|
|
obj.type = "image/png"
|
|
|
|
obj.alt = ""
|
|
|
|
return obj.outerHTML;
|
|
|
|
}
|
|
|
|
|
2017-11-08 11:29:07 +01:00
|
|
|
function createHonorImg(array, size) {
|
|
|
|
size = 32;
|
|
|
|
var div = document.createElement('div');
|
2017-11-10 10:32:51 +01:00
|
|
|
div.style.boxShadow = '0px 0px 5px #00000099';
|
|
|
|
div.style.backgroundColor = '#e1e1e1';
|
2017-11-14 14:05:54 +01:00
|
|
|
if (!Array.isArray(array))
|
|
|
|
array = [array];
|
2017-11-08 11:29:07 +01:00
|
|
|
for (badgeNum of array) {
|
|
|
|
var obj = document.createElement('img');
|
|
|
|
obj.height = size;
|
|
|
|
obj.width = size;
|
|
|
|
obj.style.margin = 'auto';
|
|
|
|
obj.title = org_honor_badge_title[badgeNum];
|
|
|
|
obj.src = url_baseHonorLogo+badgeNum+'.svg';
|
|
|
|
div.appendChild(obj);
|
|
|
|
}
|
2017-11-10 10:32:51 +01:00
|
|
|
div.style.width = 32*array.length+'px';
|
|
|
|
div.style.borderRadius = '15px';
|
2017-11-08 11:29:07 +01:00
|
|
|
return div.outerHTML;
|
|
|
|
}
|
|
|
|
|
2017-11-09 10:32:39 +01:00
|
|
|
function createOrgLink(org) {
|
|
|
|
var a = document.createElement('a');
|
|
|
|
a.innerHTML = org;
|
|
|
|
a.href = "?org="+org;
|
|
|
|
return a.outerHTML;
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:55:03 +01:00
|
|
|
function generateRankingSheet(rank, rankDec, stepPnt, pnt, Rpnt) {
|
2017-11-02 14:44:27 +01:00
|
|
|
var Cpnt = pnt - stepPnt;
|
|
|
|
var Tpnt = Cpnt + Rpnt;
|
2017-11-03 08:55:03 +01:00
|
|
|
var OuterDiv = document.createElement('div');
|
2017-11-02 14:44:27 +01:00
|
|
|
var gdiv = document.createElement('div');
|
2017-11-03 08:55:03 +01:00
|
|
|
gdiv.id = "globalDiv";
|
|
|
|
gdiv.style.float = 'left';
|
2017-11-02 14:44:27 +01:00
|
|
|
//progressBar
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.classList.add('progress');
|
|
|
|
var pb_length = 187;
|
|
|
|
div.style.width = pb_length+'px'; //HARDCODED...
|
|
|
|
div.style.marginBottom = '0px';
|
|
|
|
var div1 = document.createElement('div')
|
|
|
|
div1.classList.add('progress-bar')
|
|
|
|
div1.style.width = 100*(Cpnt)/Tpnt+'%';
|
2017-11-03 08:55:03 +01:00
|
|
|
div1.innerHTML = "<strong>"+Cpnt+"</strong>";
|
2017-11-02 14:44:27 +01:00
|
|
|
div.appendChild(div1);
|
|
|
|
var div1 = document.createElement('div')
|
|
|
|
div1.classList.add('progress-bar', 'progress-bar-warning')
|
|
|
|
div1.style.width = 100*(Rpnt)/Tpnt+'%'
|
2017-11-03 08:55:03 +01:00
|
|
|
div1.innerHTML = "<strong>"+Rpnt+"</strong>";
|
2017-11-02 14:44:27 +01:00
|
|
|
div.appendChild(div1);
|
|
|
|
gdiv.appendChild(div);
|
|
|
|
// table
|
2017-11-02 10:16:34 +01:00
|
|
|
var table = document.createElement('table');
|
|
|
|
table.classList.add('table', 'table-striped');
|
2017-11-03 08:55:03 +01:00
|
|
|
table.style.marginBottom = '5px';
|
2017-11-02 10:16:34 +01:00
|
|
|
//head
|
|
|
|
var thead = document.createElement('thead');
|
|
|
|
var tr = document.createElement('tr');
|
|
|
|
var th = document.createElement('th');
|
2017-11-02 10:57:16 +01:00
|
|
|
th.innerHTML = "Rank";
|
2017-11-02 10:16:34 +01:00
|
|
|
tr.appendChild(th);
|
|
|
|
var th = document.createElement('th');
|
2017-11-02 14:02:54 +01:00
|
|
|
th.innerHTML = "Requirement (CP)";
|
2017-11-02 10:16:34 +01:00
|
|
|
tr.appendChild(th);
|
|
|
|
thead.appendChild(tr);
|
|
|
|
//body
|
|
|
|
var tbody = document.createElement('tbody');
|
|
|
|
for (var i=1; i<=maxRank; i++) {
|
|
|
|
var tr = document.createElement('tr');
|
2017-11-02 15:14:21 +01:00
|
|
|
var td1 = document.createElement('td');
|
2017-11-07 12:54:08 +01:00
|
|
|
td1.innerHTML = getMonthlyRankIcon(i, 40);
|
2017-11-02 15:14:21 +01:00
|
|
|
td1.style.padding = "2px";
|
|
|
|
var td2 = document.createElement('td');
|
|
|
|
td2.innerHTML = Math.floor(Math.pow(rankMultiplier, i));
|
|
|
|
td2.style.padding = "2px";
|
2017-11-02 10:57:16 +01:00
|
|
|
tr.style.textAlign = "center";
|
|
|
|
if (i == rank) { // current org rank
|
2017-11-02 15:14:21 +01:00
|
|
|
tr.style.backgroundColor = "#337ab7";
|
|
|
|
tr.style.color = "white";
|
|
|
|
} else if (i == rank+1) {
|
|
|
|
tr.style.backgroundColor = "#f0ad4e";
|
|
|
|
tr.style.color = "white";
|
2017-11-02 10:57:16 +01:00
|
|
|
}
|
2017-11-02 15:14:21 +01:00
|
|
|
tr.appendChild(td1);
|
|
|
|
tr.appendChild(td2);
|
2017-11-02 10:16:34 +01:00
|
|
|
tbody.appendChild(tr);
|
|
|
|
}
|
|
|
|
table.appendChild(thead);
|
|
|
|
table.appendChild(tbody);
|
2017-11-02 14:44:27 +01:00
|
|
|
gdiv.appendChild(table);
|
2017-11-03 08:55:03 +01:00
|
|
|
OuterDiv.appendChild(gdiv);
|
|
|
|
// Tot nbr points
|
2017-11-06 18:07:10 +01:00
|
|
|
var tableHeight = 720; //HARDCODED...
|
2017-11-03 08:55:03 +01:00
|
|
|
var div = document.createElement('div');
|
|
|
|
div.classList.add('progress');
|
|
|
|
div.style.width = '20px';
|
|
|
|
div.style.height = tableHeight+'px'; //HARDCODED...
|
|
|
|
div.style.display = 'flex'
|
|
|
|
div.style.float = 'left';
|
|
|
|
div.style.marginTop = '56px';
|
|
|
|
div.style.marginBottom = '0px';
|
|
|
|
div.style.marginLeft = '2px';
|
|
|
|
var div1 = document.createElement('div')
|
|
|
|
div1.classList.add('progress-bar', 'progress-bar-success', 'progress-bar-striped')
|
|
|
|
div1.style.height = ((rank+rankDec)*100/16)+'%';
|
|
|
|
div1.style.width = '100%';
|
|
|
|
div.appendChild(div1);
|
|
|
|
OuterDiv.appendChild(div);
|
|
|
|
|
|
|
|
return OuterDiv.outerHTML;
|
2017-11-02 10:16:34 +01:00
|
|
|
}
|
2017-11-02 08:41:30 +01:00
|
|
|
|
|
|
|
function addToTableFromJson(datatable, url) {
|
|
|
|
$.getJSON( url, function( data ) {
|
|
|
|
for (i in data) {
|
|
|
|
var row = data[i];
|
|
|
|
i = parseInt(i);
|
|
|
|
var to_add = [
|
2017-11-06 09:50:28 +01:00
|
|
|
row.pnts,
|
2017-11-07 12:54:08 +01:00
|
|
|
getMonthlyRankIcon(row.rank),
|
|
|
|
getOrgRankIcon(row.orgRank, 60),
|
2017-11-08 11:29:07 +01:00
|
|
|
createHonorImg(row.honorBadge, 20),
|
2017-11-07 12:54:08 +01:00
|
|
|
createImg(row.logo_path, 32),
|
2017-11-09 10:32:39 +01:00
|
|
|
createOrgLink(row.org)
|
2017-11-02 08:41:30 +01:00
|
|
|
];
|
|
|
|
datatable.row.add(to_add);
|
|
|
|
}
|
|
|
|
datatable.draw();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-06 13:43:55 +01:00
|
|
|
function addLastFromJson(datatable, url) {
|
|
|
|
$.getJSON( url, function( data ) {
|
|
|
|
for (i in data) {
|
|
|
|
var row = data[i];
|
|
|
|
i = parseInt(i);
|
|
|
|
addLastContributor(datatable, row);
|
|
|
|
}
|
|
|
|
datatable.draw();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addLastContributor(datatable, data, update) {
|
2018-09-24 12:23:04 +02:00
|
|
|
var org = data.org;
|
|
|
|
if (org == last_added_contrib) {
|
|
|
|
let node = $('#lastTable > tbody tr:eq(0)');
|
|
|
|
node.addClass('higlightRowInTable');
|
|
|
|
update_timeout_last_added_contrib();
|
|
|
|
} else {
|
|
|
|
last_added_contrib = org;
|
|
|
|
var date = new Date(data.epoch*1000);
|
|
|
|
date.toString = function() {return this.toTimeString().slice(0,-15) +' '+ this.toLocaleDateString(); };
|
|
|
|
var to_add = [
|
|
|
|
date,
|
|
|
|
data.pnts,
|
|
|
|
getMonthlyRankIcon(data.rank),
|
|
|
|
getOrgRankIcon(data.orgRank, 60),
|
|
|
|
createHonorImg(data.honorBadge, 20),
|
|
|
|
createImg(data.logo_path, 32),
|
|
|
|
createOrgLink(data.org),
|
|
|
|
];
|
|
|
|
if (update === undefined || update === false) {
|
|
|
|
datatable.row.add(to_add);
|
|
|
|
datatable.draw();
|
|
|
|
} else if(update == true) {
|
|
|
|
datatable.rows().every( function() {
|
|
|
|
if($(this.data()[6])[0].text == data.org) {
|
|
|
|
var node = $(datatable.row( this ).node());
|
|
|
|
datatable.row( this ).data( to_add );
|
2017-11-14 14:56:15 +01:00
|
|
|
node.effect("slide", 500);
|
|
|
|
}
|
2018-09-24 12:23:04 +02:00
|
|
|
datatable.draw();
|
|
|
|
});
|
2017-11-14 14:05:54 +01:00
|
|
|
}
|
2017-11-06 13:43:55 +01:00
|
|
|
}
|
2018-09-24 12:23:04 +02:00
|
|
|
|
2017-11-06 13:43:55 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 14:05:54 +01:00
|
|
|
function addAwards(datatableAwards, json, playAnim) {
|
2017-11-14 09:50:20 +01:00
|
|
|
if(json.award[0] == 'contribution_status') {
|
2017-11-14 14:05:54 +01:00
|
|
|
var award = getOrgRankIcon(json.award[1], 60);
|
2017-11-14 09:50:20 +01:00
|
|
|
} else if (json.award[0] == 'badge') {
|
2017-11-14 14:05:54 +01:00
|
|
|
var award = createHonorImg(json.award[1], 20);
|
2017-11-14 09:50:20 +01:00
|
|
|
} else if (json.award[0] == 'trophy') {
|
2017-11-14 14:05:54 +01:00
|
|
|
var categ = json.award[1][0];
|
|
|
|
var award = createTrophyImg(json.award[1][1], 40, categ);
|
2017-11-14 09:50:20 +01:00
|
|
|
}
|
2017-11-13 16:26:09 +01:00
|
|
|
var date = new Date(json.epoch*1000);
|
2017-11-14 09:50:20 +01:00
|
|
|
date.toString = function() {return this.toTimeString().slice(0,-15) +' '+ this.toLocaleDateString(); };
|
2017-11-13 16:26:09 +01:00
|
|
|
var to_add = [
|
2017-11-14 09:50:20 +01:00
|
|
|
date,
|
2017-11-13 16:26:09 +01:00
|
|
|
createImg(json.logo_path, 32),
|
|
|
|
createOrgLink(json.org),
|
2017-11-14 09:50:20 +01:00
|
|
|
award,
|
2017-11-13 16:26:09 +01:00
|
|
|
];
|
2017-11-14 14:05:54 +01:00
|
|
|
var node = $(datatableAwards.row.add(to_add).draw().node());
|
|
|
|
if(playAnim)
|
|
|
|
node.effect("slide", 700);
|
2017-11-13 16:26:09 +01:00
|
|
|
}
|
|
|
|
|
2017-11-09 16:31:04 +01:00
|
|
|
function updateProgressBar(org) {
|
|
|
|
if(currOrg != org)
|
|
|
|
return;
|
|
|
|
$.getJSON( url_getOrgRank+'?org='+org, function( data ) {
|
|
|
|
var rank = Math.floor(data.rank);
|
|
|
|
var rankDec = data.rank-rank;
|
|
|
|
var popoverRank = $('#btnCurrRank').data('bs.popover');
|
|
|
|
popoverRank.options.content = generateRankingSheet(rank, rankDec, data.stepPts, data.points, data.remainingPts);
|
|
|
|
$('#orgRankDiv').html(getMonthlyRankIcon(rank, 40, true));
|
|
|
|
$('#orgNextRankDiv').html(getMonthlyRankIcon(rank+1, 40, true));
|
|
|
|
if (data.rank > 16){
|
|
|
|
$('#progressBarDiv').width(1*150); //150 is empty bar width
|
|
|
|
} else {
|
|
|
|
$('#progressBarDiv').width((data.rank - rank)*150); //150 is empty bar width
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateOvertakePnts() {
|
|
|
|
var prevOrgName = "";
|
|
|
|
var prevOrgPnts = 0;
|
|
|
|
datatableTop.rows().every( function() {
|
|
|
|
var row = this.node();
|
|
|
|
var orgRowName = $(this.data()[5])[0].text; // contained in <a>
|
|
|
|
var orgRowPnts = this.data()[0]
|
|
|
|
if(orgRowName == currOrg) {
|
|
|
|
if(prevOrgName == ""){ //already first
|
|
|
|
$('#orgToOverTake').text(orgRowName);
|
|
|
|
$('#pntsToOvertakeNext').text(0);
|
|
|
|
} else {
|
|
|
|
$('#orgToOverTake').text(prevOrgName);
|
|
|
|
$('#pntsToOvertakeNext').text(parseInt(prevOrgPnts)-orgRowPnts);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
prevOrgName = orgRowName;
|
|
|
|
prevOrgPnts = orgRowPnts;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-02 10:57:16 +01:00
|
|
|
function updateProgressHeader(org) {
|
2017-11-08 17:37:03 +01:00
|
|
|
currOrg = org;
|
2017-11-02 10:57:16 +01:00
|
|
|
// get Org rank
|
|
|
|
$.getJSON( url_getOrgRank+'?org='+org, function( data ) {
|
2017-11-02 13:13:13 +01:00
|
|
|
datatableTop.draw();
|
2017-11-02 11:36:23 +01:00
|
|
|
var rank = Math.floor(data.rank);
|
2017-11-03 08:55:03 +01:00
|
|
|
var rankDec = data.rank-rank;
|
2017-11-02 10:57:16 +01:00
|
|
|
$('#btnCurrRank').show();
|
|
|
|
$('#orgText').text(data.org);
|
|
|
|
var popoverRank = $('#btnCurrRank').data('bs.popover');
|
2017-11-03 08:55:03 +01:00
|
|
|
popoverRank.options.content = generateRankingSheet(rank, rankDec, data.stepPts, data.points, data.remainingPts);
|
2017-11-07 12:54:08 +01:00
|
|
|
$('#orgRankDiv').html(getMonthlyRankIcon(rank, 40, true));
|
|
|
|
$('#orgNextRankDiv').html(getMonthlyRankIcon(rank+1, 40, true));
|
2017-11-02 15:27:31 +01:00
|
|
|
if (data.rank > 16){
|
|
|
|
$('#progressBarDiv').width(1*150); //150 is empty bar width
|
|
|
|
} else {
|
|
|
|
$('#progressBarDiv').width((data.rank - rank)*150); //150 is empty bar width
|
|
|
|
}
|
2017-11-02 13:13:13 +01:00
|
|
|
// update color in other dataTables
|
|
|
|
datatableTop.rows().every( function() {
|
|
|
|
var row = this.node();
|
2017-11-13 16:02:09 +01:00
|
|
|
var orgRowName = $(this.data()[5])[0].text;
|
|
|
|
if(orgRowName == data.org) { row.classList.add('selectedOrgInTable'); } else { row.classList.remove('selectedOrgInTable'); }
|
2017-11-02 13:13:13 +01:00
|
|
|
});
|
2017-11-13 16:02:09 +01:00
|
|
|
datatableFameQuant.rows().every( function() {
|
2017-11-02 13:13:13 +01:00
|
|
|
var row = this.node();
|
2017-11-13 16:02:09 +01:00
|
|
|
var orgRowName = $(this.data()[5])[0].text;
|
|
|
|
if(orgRowName == data.org) { row.classList.add('selectedOrgInTable'); } else { row.classList.remove('selectedOrgInTable'); }
|
2017-11-02 13:13:13 +01:00
|
|
|
});
|
|
|
|
datatableCateg.rows().every( function() {
|
|
|
|
var row = this.node();
|
2017-11-13 16:02:09 +01:00
|
|
|
var orgRowName = $(this.data()[5])[0].text;
|
|
|
|
if(orgRowName == data.org) { row.classList.add('selectedOrgInTable'); } else { row.classList.remove('selectedOrgInTable'); }
|
2017-11-02 13:13:13 +01:00
|
|
|
});
|
|
|
|
datatableLast.rows().every( function() {
|
|
|
|
var row = this.node();
|
2017-11-13 16:02:09 +01:00
|
|
|
var orgRowName = $(this.data()[6])[0].text;
|
|
|
|
if(orgRowName == data.org) { row.classList.add('selectedOrgInTable'); } else { row.classList.remove('selectedOrgInTable'); }
|
2017-11-02 13:13:13 +01:00
|
|
|
});
|
2017-11-02 10:57:16 +01:00
|
|
|
});
|
2017-11-08 15:34:02 +01:00
|
|
|
|
|
|
|
// colorize row contribution rank help
|
|
|
|
$.getJSON( url_getContributionOrgStatus+'?org='+org, function( data ) {
|
|
|
|
var status = data['status'];
|
|
|
|
var curContributionOrgRank = data['rank'];
|
2017-11-08 16:12:42 +01:00
|
|
|
var totNumPoints = data['totPoints']
|
|
|
|
$('#orgTotNumOfPoint').text(totNumPoints);
|
2017-11-08 15:34:02 +01:00
|
|
|
if (curContributionOrgRank == 0) {
|
|
|
|
$('#orgContributionRank').attr('data', '');
|
|
|
|
} else {
|
|
|
|
$('#orgContributionRank').attr('data', url_baseOrgRankLogo+curContributionOrgRank+'.svg');
|
|
|
|
}
|
|
|
|
for (var row of $('#bodyTablerankingModal')[0].children) {
|
|
|
|
row = $(row);
|
2017-11-09 13:43:02 +01:00
|
|
|
var firstCell = $(row.children()[0]);
|
2017-11-08 15:34:02 +01:00
|
|
|
var rank = row.data('rank');
|
2017-11-08 16:12:42 +01:00
|
|
|
//remove all classes
|
|
|
|
row.removeClass("warning");
|
|
|
|
row.removeClass("danger");
|
|
|
|
row.removeClass("success");
|
2017-11-09 13:43:02 +01:00
|
|
|
firstCell.removeClass("successCell");
|
2017-11-08 16:12:42 +01:00
|
|
|
//add correct class
|
2017-11-08 15:34:02 +01:00
|
|
|
if(status[rank] == 0){
|
|
|
|
row.addClass("danger");
|
2017-11-08 16:12:42 +01:00
|
|
|
} else if(status[rank] == 1) {
|
|
|
|
row.addClass("warning");
|
2017-11-08 15:34:02 +01:00
|
|
|
}
|
2017-11-09 13:43:02 +01:00
|
|
|
if(rank == curContributionOrgRank) {
|
|
|
|
firstCell.addClass("successCell");
|
|
|
|
}
|
2017-11-08 15:34:02 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-08 16:12:42 +01:00
|
|
|
// colorize badge if acquired
|
2017-11-08 15:34:02 +01:00
|
|
|
$.getJSON( url_getHonorBadges+'?org='+org, function( data ) {
|
2017-11-09 16:31:04 +01:00
|
|
|
for(var i=0; i<numberOfBadges; i++) { // remove
|
|
|
|
$('#divBadge_'+(i+1)).removeClass('circlBadgeAcquired');
|
2017-11-13 16:26:09 +01:00
|
|
|
$('#divBadge_'+(i+1)).addClass('circlBadgeNotAcquired');
|
2017-11-08 15:34:02 +01:00
|
|
|
}
|
2017-11-09 16:31:04 +01:00
|
|
|
for(var i=0; i<data.length; i++) { // add
|
2017-11-13 16:26:09 +01:00
|
|
|
$('#divBadge_'+(i+1)).removeClass('circlBadgeNotAcquired');
|
2017-11-09 16:31:04 +01:00
|
|
|
$('#divBadge_'+(data[i])).addClass('circlBadgeAcquired');
|
2017-11-08 17:37:03 +01:00
|
|
|
}
|
|
|
|
});
|
2017-11-09 10:32:39 +01:00
|
|
|
|
2017-11-13 12:57:05 +01:00
|
|
|
// set trophies if acquired
|
|
|
|
$.getJSON( url_getTrophies+'?org='+org, function( data ) {
|
|
|
|
var source = url_baseTrophyLogo+0+'.png'
|
|
|
|
for(var i=0; i<trophy_categ_list.length; i++) { // remove
|
|
|
|
categ = trophy_categ_list[i];
|
|
|
|
$('#trophy_'+categ).attr('src', source);
|
|
|
|
$('#trophy_'+categ).attr('title', "");
|
2017-11-21 11:08:08 +01:00
|
|
|
try { // in case popover not created
|
|
|
|
var pop = $('#trophy_'+categ).data('bs.popover');
|
|
|
|
pop.destroy();
|
|
|
|
} catch(err) {
|
|
|
|
|
|
|
|
}
|
2017-11-13 12:57:05 +01:00
|
|
|
}
|
2017-11-21 11:08:08 +01:00
|
|
|
setTimeout(function() { // avoid race condition with destroy
|
|
|
|
for(var i=0; i<data.length; i++) { // add
|
|
|
|
categ = data[i].categ;
|
|
|
|
rank = data[i].trophy_true_rank;
|
|
|
|
trophy_points = data[i].trophy_points
|
|
|
|
source = url_baseTrophyLogo+rank+'.png'
|
|
|
|
$('#trophy_'+categ).attr('src', source);
|
|
|
|
$('#trophy_'+categ).attr('title', trophy_title[rank]);
|
|
|
|
$('#trophy_'+categ).popover({title: trophy_title[rank], content: 'Level: '+rank+' ('+trophy_points+' points)', trigger: "hover", placement: "bottom"});
|
|
|
|
}
|
|
|
|
}, 300);
|
2017-11-13 12:57:05 +01:00
|
|
|
});
|
|
|
|
|
2017-11-09 16:31:04 +01:00
|
|
|
//update overtake points
|
|
|
|
updateOvertakePnts();
|
2017-11-02 10:57:16 +01:00
|
|
|
}
|
2017-11-02 08:41:30 +01:00
|
|
|
|
2018-09-25 14:48:13 +02:00
|
|
|
function generate_table_ranking_on_category(categ) {
|
|
|
|
$.getJSON( url_getAllOrgsTrophyRanking+'/'+categ, function( data ) {
|
|
|
|
var body = $('#bodyTableThropyAllOrgRankingModal');
|
|
|
|
body.empty();
|
|
|
|
data.forEach(function(arr, i) {
|
|
|
|
var org = arr[0];
|
|
|
|
var points = arr[1];
|
|
|
|
var rank = arr[2];
|
|
|
|
var tr = $('<tr></tr>');
|
|
|
|
tr.append($('<td style="width: 100px;">'+i+'</td>'));
|
|
|
|
tr.append($('<td style="width: 100px;"><img src="'+url_baseTrophyLogo+rank+'.png" width="30" height="30"></td>'));
|
|
|
|
tr.append($('<td style="width: 200px;">'+points+'</td>'));
|
|
|
|
tr.append($('<td><a href="?org='+org+'">'+org+'</a></td>'));
|
|
|
|
if (currOrg == org) {
|
|
|
|
tr.addClass('selectedOrgInTable');
|
|
|
|
}
|
|
|
|
body.append(tr);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-24 12:23:04 +02:00
|
|
|
function update_timeout_last_added_contrib() {
|
|
|
|
clearTimeout(timeout_last_added_contrib);
|
|
|
|
timeout_last_added_contrib = setTimeout(function() {
|
|
|
|
let node = $('#lastTable > tbody tr:eq(0)');
|
|
|
|
node.removeClass('higlightRowInTable');
|
|
|
|
last_added_contrib = null;
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
|
2017-11-02 14:02:54 +01:00
|
|
|
function showOnlyOrg() {
|
|
|
|
datatableCateg.search( $('#orgText').text() ).draw();
|
|
|
|
}
|
|
|
|
|
2017-11-06 15:00:51 +01:00
|
|
|
function timeToString(time) {
|
|
|
|
var min = Math.floor(time / 60);
|
|
|
|
min = (min < 10) ? ("0" + min) : min;
|
|
|
|
var sec = time - 60*min;
|
|
|
|
sec = (sec < 10) ? ("0" + sec) : sec;
|
|
|
|
return min + ":" + sec
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateTimer() {
|
|
|
|
if ($("#reloadCheckbox").is(':checked')) {
|
|
|
|
sec_before_reload--;
|
|
|
|
if (sec_before_reload < 1) {
|
|
|
|
location.reload();
|
|
|
|
} else {
|
|
|
|
$('#labelRemainingTime').text(timeToString(sec_before_reload));
|
|
|
|
setTimeout(function(){ updateTimer(); }, 1000);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sec_before_reload = refresh_speed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(':checkbox').change(function() {
|
|
|
|
if ($("#reloadCheckbox").is(':checked')) { setTimeout(function(){ updateTimer(); }, 1000); }
|
|
|
|
});
|
|
|
|
|
2017-11-02 08:41:30 +01:00
|
|
|
$(document).ready(function() {
|
2017-11-06 15:00:51 +01:00
|
|
|
$('#labelRemainingTime').text(timeToString(sec_before_reload));
|
|
|
|
updateTimer();
|
2017-11-02 10:57:16 +01:00
|
|
|
$('#orgName').typeahead(typeaheadOption);
|
|
|
|
$('#btnCurrRank').popover(popOverOption);
|
2017-11-14 14:56:15 +01:00
|
|
|
|
|
|
|
$(window).on("beforeunload", function() {
|
|
|
|
source_lastContrib.close();
|
|
|
|
source_awards.close();
|
|
|
|
});
|
|
|
|
|
2017-11-02 08:41:30 +01:00
|
|
|
datatableTop = $('#topContribTable').DataTable(optionDatatable_top);
|
2017-12-01 16:02:28 +01:00
|
|
|
datatableFameQuant = $('#fameTableQuantity').DataTable(optionDatatable_fameQuant);
|
|
|
|
datatableFameQual = $('#fameTableQuality').DataTable(optionDatatable_fameQual);
|
2017-11-02 08:41:30 +01:00
|
|
|
datatableCateg = $('#categTable').DataTable(optionDatatable_Categ);
|
|
|
|
datatableLast = $('#lastTable').DataTable(optionDatatable_last);
|
2017-11-13 16:02:09 +01:00
|
|
|
datatableAwards = $('#awardTable').DataTable(optionDatatable_awards);
|
2017-11-02 08:41:30 +01:00
|
|
|
// top contributors
|
2017-11-02 10:16:34 +01:00
|
|
|
addToTableFromJson(datatableTop, url_getTopContributor);
|
2017-11-02 08:41:30 +01:00
|
|
|
// hall of fame
|
2017-11-13 16:02:09 +01:00
|
|
|
addToTableFromJson(datatableFameQuant, url_getFameContributor);
|
2017-11-14 15:44:53 +01:00
|
|
|
addToTableFromJson(datatableFameQual, url_getFameQualContributor);
|
2017-11-02 10:16:34 +01:00
|
|
|
// last contributors
|
2017-11-06 13:43:55 +01:00
|
|
|
addLastFromJson(datatableLast, url_getLastContributor);
|
2017-11-02 10:16:34 +01:00
|
|
|
// category per contributors
|
2017-11-02 08:41:30 +01:00
|
|
|
$.getJSON( url_getCategPerContrib, function( data ) {
|
|
|
|
for (i in data) {
|
|
|
|
var row = data[i];
|
|
|
|
i = parseInt(i);
|
|
|
|
var to_add = [
|
2017-11-06 18:07:10 +01:00
|
|
|
row.pnts,
|
2017-11-07 12:54:08 +01:00
|
|
|
getMonthlyRankIcon(row.rank),
|
|
|
|
getOrgRankIcon(row.orgRank, 44),
|
2017-11-08 11:29:07 +01:00
|
|
|
createHonorImg(row.honorBadge, 20),
|
|
|
|
createImg(row.logo_path, 32),
|
2017-11-09 10:32:39 +01:00
|
|
|
createOrgLink(row.org),
|
2017-11-02 08:41:30 +01:00
|
|
|
];
|
2017-11-02 16:10:40 +01:00
|
|
|
for (categ of categ_list) {
|
|
|
|
to_add.push(row[categ]);
|
|
|
|
}
|
|
|
|
|
2017-11-02 08:41:30 +01:00
|
|
|
datatableCateg.row.add(to_add);
|
|
|
|
}
|
|
|
|
datatableCateg.draw();
|
|
|
|
});
|
2017-11-13 16:02:09 +01:00
|
|
|
// latest awards
|
|
|
|
$.getJSON( url_getLatestAwards, function( data ) {
|
|
|
|
for (i in data) {
|
2017-11-14 14:05:54 +01:00
|
|
|
addAwards(datatableAwards, data[i], false);
|
2017-11-09 10:32:39 +01:00
|
|
|
}
|
2017-11-02 08:41:30 +01:00
|
|
|
});
|
2017-11-13 16:02:09 +01:00
|
|
|
|
2017-11-06 09:58:59 +01:00
|
|
|
if(currOrg != "") // currOrg selected
|
2017-11-06 13:43:55 +01:00
|
|
|
//FIXME: timeout used to wait that all datatables are draw.
|
2017-11-14 14:56:15 +01:00
|
|
|
setTimeout( function() { updateProgressHeader(currOrg); }, 700);
|
2017-11-06 13:43:55 +01:00
|
|
|
|
|
|
|
source_lastContrib = new EventSource(url_eventStreamLastContributor);
|
|
|
|
source_lastContrib.onmessage = function(event) {
|
|
|
|
var json = jQuery.parseJSON( event.data );
|
|
|
|
addLastContributor(datatableLast, json, true);
|
2017-11-09 16:31:04 +01:00
|
|
|
updateProgressBar(json.org);
|
|
|
|
updateOvertakePnts();
|
2017-11-06 15:00:51 +01:00
|
|
|
sec_before_reload = refresh_speed; //reset timer at each contribution
|
2017-11-06 13:43:55 +01:00
|
|
|
};
|
2017-11-13 16:26:09 +01:00
|
|
|
|
|
|
|
source_awards = new EventSource(url_eventStreamAwards);
|
|
|
|
source_awards.onmessage = function(event) {
|
|
|
|
var json = jQuery.parseJSON( event.data );
|
2017-11-14 14:05:54 +01:00
|
|
|
addAwards(datatableAwards, json, true);
|
2017-11-14 14:56:15 +01:00
|
|
|
updateProgressHeader(currOrg);
|
2017-11-13 16:26:09 +01:00
|
|
|
};
|
2018-09-25 14:48:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
$('#bodyTableTrophyModalOrg input').off('click').on('click', function(e) {
|
|
|
|
var categ = $(this).data('category');
|
|
|
|
var tds = $('#bodyTableTrophyModalOrg td');
|
|
|
|
tds.removeClass('success');
|
|
|
|
$(this).parent().addClass('success');
|
|
|
|
generate_table_ranking_on_category(categ);
|
|
|
|
});
|
2017-11-02 08:41:30 +01:00
|
|
|
});
|