dockered
This commit is contained in:
20
django/frontend/static/js/utils/formUtils.js
Normal file
20
django/frontend/static/js/utils/formUtils.js
Normal file
@ -0,0 +1,20 @@
|
||||
export function clearIds(property_name, elements_id)
|
||||
{
|
||||
elements_id.forEach(element_id => {
|
||||
let element = document.getElementById(element_id);
|
||||
element[property_name] = "";
|
||||
});
|
||||
}
|
||||
|
||||
export function clearElements(prop, elements) {
|
||||
elements.forEach(element => element[prop] = '');
|
||||
}
|
||||
|
||||
export function fill_errors(errors, property_name)
|
||||
{
|
||||
Object.keys(errors).forEach(error_field =>
|
||||
{
|
||||
let element = document.getElementById(error_field);
|
||||
element[property_name] = errors[error_field];
|
||||
});
|
||||
}
|
61
django/frontend/static/js/utils/graph.js
Normal file
61
django/frontend/static/js/utils/graph.js
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
export function generateRandomColor()
|
||||
{
|
||||
return `#${Math.floor(Math.random()*16777215).toString(16)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {[Number]} data
|
||||
*/
|
||||
export function transformData(data)
|
||||
{
|
||||
let newData = [];
|
||||
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
newData.push({x: Math.round(data[index] / 1000),
|
||||
y: index + 1});
|
||||
}
|
||||
|
||||
return newData;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export function range(start, stop, step = 1)
|
||||
{
|
||||
if (stop === undefined)
|
||||
{
|
||||
stop = start;
|
||||
start = 0;
|
||||
}
|
||||
let newArr = [];
|
||||
for (let i = start; i <= stop; i += step)
|
||||
newArr.push(i);
|
||||
|
||||
return newArr;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {[Object]} dataset
|
||||
*/
|
||||
export function get_labels(dataset)
|
||||
{
|
||||
let labelsSet = new Set();
|
||||
|
||||
dataset.forEach(player_data => {
|
||||
player_data.data.forEach(data => {
|
||||
labelsSet.add(data.x);
|
||||
});
|
||||
});
|
||||
|
||||
let labels = Array.from(labelsSet);
|
||||
|
||||
labels.sort(function(a, b){return b - a;});
|
||||
|
||||
labels.reverse();
|
||||
|
||||
return labels;
|
||||
}
|
18
django/frontend/static/js/utils/noticeUtils.js
Normal file
18
django/frontend/static/js/utils/noticeUtils.js
Normal file
@ -0,0 +1,18 @@
|
||||
export function createNotification(title = 'New notification', content, delay = 3000) {
|
||||
|
||||
const toastElement = document.createElement('div');
|
||||
toastElement.classList.add('toast');
|
||||
toastElement.role = 'alert';
|
||||
toastElement.setAttribute('data-bs-delay', delay);
|
||||
toastElement.innerHTML =
|
||||
`<div class='toast-header'>
|
||||
<strong class='me-auto'>${title}</strong>
|
||||
<button type='button' class='btn-close' data-bs-dismiss='toast'></button>
|
||||
</div>
|
||||
<div class='toast-body'>${content}</div>`
|
||||
toastElement.addEventListener('hidden.bs.toast', e => e.target.remove());
|
||||
new bootstrap.Toast(toastElement).show();
|
||||
|
||||
const toastContainer = document.getElementById('toastContainer');
|
||||
toastContainer.insertBefore(toastElement, toastContainer.firstChild);
|
||||
}
|
6
django/frontend/static/js/utils/sleep.js
Normal file
6
django/frontend/static/js/utils/sleep.js
Normal file
@ -0,0 +1,6 @@
|
||||
function sleep(ms)
|
||||
{
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export {sleep}
|
Reference in New Issue
Block a user