|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>API Request</title> |
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/notyf/notyf.min.css"> |
|
<style> |
|
body { |
|
font-family: Arial, sans-serif; |
|
text-align: center; |
|
background-color: #f0f0f0; |
|
margin: 0; |
|
padding: 0; |
|
} |
|
h1 { |
|
background-color: #4CAF50; |
|
color: white; |
|
padding: 20px; |
|
margin: 0; |
|
border-bottom: 2px solid #388E3C; |
|
font-size: 28px; |
|
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); |
|
} |
|
.container { |
|
display: flex; |
|
justify-content: space-around; |
|
margin-top: 20px; |
|
} |
|
.block { |
|
width: 45%; |
|
text-align: left; |
|
background-color: white; |
|
padding: 20px; |
|
border-radius: 10px; |
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); |
|
} |
|
.form-group { |
|
margin: 20px 0; |
|
} |
|
.form-group label { |
|
display: block; |
|
margin-bottom: 8px; |
|
font-size: 16px; |
|
} |
|
.form-group input, |
|
.form-group select { |
|
width: 100%; |
|
padding: 12px; |
|
font-size: 16px; |
|
border: 1px solid #ccc; |
|
border-radius: 5px; |
|
box-sizing: border-box; |
|
} |
|
button { |
|
display: block; |
|
margin: 20px auto; |
|
color: white; |
|
background-color: #4CAF50; |
|
border: none; |
|
cursor: pointer; |
|
padding: 12px 24px; |
|
font-size: 16px; |
|
border-radius: 5px; |
|
transition: background-color 0.3s ease; |
|
} |
|
button:hover { |
|
background-color: #388E3C; |
|
} |
|
.input-row { |
|
display: flex; |
|
justify-content: center; |
|
gap: 10px; |
|
margin-top: 20px; |
|
} |
|
.input-row input[type="file"] { |
|
padding: 10px; |
|
font-size: 16px; |
|
border: 1px solid #ccc; |
|
border-radius: 5px; |
|
} |
|
.input-row input[type="checkbox"] { |
|
margin-top: 5px; |
|
} |
|
.input-row label { |
|
display: flex; |
|
align-items: center; |
|
color: #4CAF50; |
|
font-size: 16px; |
|
} |
|
#uploadButton { |
|
color: white; |
|
background-color: #4CAF50; |
|
border: none; |
|
cursor: pointer; |
|
padding: 10px 20px; |
|
font-size: 16px; |
|
border-radius: 5px; |
|
margin-top: 20px; |
|
display: block; |
|
margin-left: auto; |
|
margin-right: auto; |
|
} |
|
#uploadButton:hover { |
|
background-color: #388E3C; |
|
} |
|
|
|
#dropdown-container select { |
|
width: 100%; |
|
padding: 12px; |
|
font-size: 16px; |
|
border: 1px solid #ccc; |
|
border-radius: 5px; |
|
box-sizing: border-box; |
|
background-color: white; |
|
appearance: none; |
|
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5z"/></svg>'); |
|
background-repeat: no-repeat; |
|
background-position: right 10px center; |
|
background-size: 16px; |
|
} |
|
|
|
.block h2 { |
|
text-align: center; |
|
} |
|
|
|
|
|
#spinner { |
|
position: fixed; |
|
top: 50%; |
|
left: 50%; |
|
transform: translate(-50%, -50%); |
|
display: none; |
|
} |
|
</style> |
|
</head> |
|
<body> |
|
<h1>WhatsMasterGRM - Принудительное обновление базы</h1> |
|
|
|
<div class="container"> |
|
<div class="block"> |
|
<h2>Тильда - Таблица CSV</h2> |
|
<form id="uploadForm" enctype="multipart/form-data" method="post"> |
|
<div class="input-row"> |
|
<input type="file" name="file" accept=".csv"> |
|
</div> |
|
<div class="input-row"> |
|
<label> |
|
<input type="checkbox" name="verify_phone" value="1"> Наличие WhatsApp |
|
</label> |
|
<label> |
|
<input type="checkbox" name="add_curator" value="1"> Добавлять менеджера |
|
</label> |
|
</div> |
|
<input id="uploadButton" type="submit" value="Загрузить пользователей"> |
|
</form> |
|
<div id="result"></div> |
|
</div> |
|
|
|
<div class="block"> |
|
<h2>Бизон 365 - API</h2> |
|
<div class="form-group"> |
|
<label for="tokenInput">API-токен администратора Бизон 365:</label> |
|
<input type="text" id="tokenInput" placeholder="Введите токен"> |
|
</div> |
|
<div class="form-group"> |
|
<label for="dateSelect">Выбор даты:</label> |
|
<select id="dateSelect"> |
|
<option value="2021-01-01T00:00:00">2021-01-01</option> |
|
<option value="2022-01-01T00:00:00">2022-01-01</option> |
|
<option value="2023-01-01T00:00:00">2023-01-01</option> |
|
<option value="2024-01-01T00:00:00">2024-01-01</option> |
|
</select> |
|
</div> |
|
<div class="form-group"> |
|
<label for="typeSelect">Выбор формата вебинара:</label> |
|
<select id="typeSelect"> |
|
<option value="AutoWebinars">Автовебинарные комнаты</option> |
|
<option value="LiveWebinars">Вебинарные комнаты</option> |
|
</select> |
|
</div> |
|
<button id="sendRequestButton">Получить список комнат Бизон 365</button> |
|
<div id="dropdown-container"></div> |
|
<button id="sendGetRequestButton">Обновить базу пользователей WhatCRM</button> |
|
</div> |
|
</div> |
|
|
|
|
|
<div id="spinner"> |
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 115 115"> |
|
<path fill="none" stroke="rgba(0, 0, 0, 0.05)" stroke-width="3" d="M 85 85 C -5 16 -39 127 78 30 C 126 -9 57 -16 85 85 C 94 123 124 111 85 85 Z" /> |
|
<path id="el" fill="none" stroke-dasharray="60 310" stroke-dashoffset="445" stroke-linecap="round" stroke-width="3" d="M 85 85 C -5 16 -39 127 78 30 C 126 -9 57 -16 85 85 C 94 123 124 111 85 85 Z" /> |
|
</svg> |
|
</div> |
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/notyf/notyf.min.js"></script> |
|
<script> |
|
document.getElementById('uploadForm').addEventListener('submit', function(event) { |
|
event.preventDefault(); |
|
const form = new FormData(this); |
|
const notyf = new Notyf({ |
|
duration: 5000, |
|
position: { |
|
x: 'right', |
|
y: 'top' |
|
}, |
|
types: [ |
|
{ |
|
type: 'info', |
|
background: 'green', |
|
icon: { |
|
className: 'notyf__icon--info', |
|
tagName: 'span', |
|
text: '' |
|
} |
|
} |
|
] |
|
}); |
|
notyf.open({ |
|
type: 'info', |
|
message: 'Загрузка началась, пожалуйста, подождите' |
|
}); |
|
fetch('/upload_csv', { |
|
method: 'POST', |
|
body: form |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
notyf.open({ |
|
type: 'success', |
|
message: data.message |
|
}); |
|
}) |
|
.catch(error => { |
|
console.error('Error:', error); |
|
notyf.open({ |
|
type: 'error', |
|
message: 'An error occurred while uploading the file.' |
|
}); |
|
}); |
|
}); |
|
|
|
const notyf = new Notyf({ |
|
duration: 5000, |
|
position: { |
|
x: 'right', |
|
y: 'top', |
|
}, |
|
}); |
|
let requestButtonClicked = false; |
|
document.getElementById('sendRequestButton').addEventListener('click', function() { |
|
if (requestButtonClicked) return; |
|
requestButtonClicked = true; |
|
const token = document.getElementById('tokenInput').value; |
|
const minDate = document.getElementById('dateSelect').value; |
|
const type = document.getElementById('typeSelect').value; |
|
const url = '/send_request'; |
|
|
|
|
|
document.getElementById('spinner').style.display = 'block'; |
|
|
|
fetch(url, { |
|
method: 'POST', |
|
headers: { |
|
'Content-Type': 'application/x-www-form-urlencoded' |
|
}, |
|
body: 'token=' + encodeURIComponent(token) + '&minDate=' + encodeURIComponent(minDate) + '&type=' + encodeURIComponent(type) |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
console.log('JSON Response:', data); |
|
createDropdown(data); |
|
|
|
|
|
document.getElementById('spinner').style.display = 'none'; |
|
}) |
|
.catch(error => { |
|
console.error('Error:', error); |
|
notyf.error('Error: ' + error.message); |
|
|
|
|
|
document.getElementById('spinner').style.display = 'none'; |
|
}) |
|
.finally(() => { |
|
requestButtonClicked = false; |
|
}); |
|
}); |
|
function createDropdown(data) { |
|
const container = document.getElementById('dropdown-container'); |
|
container.innerHTML = ''; |
|
const select = document.createElement('select'); |
|
select.id = 'dropdown'; |
|
select.classList.add('form-group'); |
|
data.forEach(item => { |
|
const option = document.createElement('option'); |
|
option.value = item; |
|
option.text = item; |
|
select.appendChild(option); |
|
}); |
|
container.appendChild(select); |
|
const sendGetRequestButton = document.getElementById('sendGetRequestButton'); |
|
sendGetRequestButton.removeEventListener('click', handleGetRequest); |
|
sendGetRequestButton.addEventListener('click', handleGetRequest); |
|
} |
|
function handleGetRequest() { |
|
const selectedValue = document.getElementById('dropdown').value; |
|
const token = document.getElementById('tokenInput').value; |
|
const getUrl = '/send_get_request?token=' + encodeURIComponent(token) + '&webinarId=' + encodeURIComponent(selectedValue); |
|
fetch(getUrl, { |
|
method: 'GET' |
|
}) |
|
.then(response => response.json()) |
|
.then(data => { |
|
console.log('GET Response:', data); |
|
notyf.success('Пользователи добавлены в базу данных WhatsGRM'); |
|
}) |
|
.catch(error => { |
|
console.error('Error:', error); |
|
notyf.error('Error: ' + error.message); |
|
}); |
|
} |
|
|
|
|
|
const colorTable = [ |
|
|
|
[0.0, 0xf15a31], |
|
[0.2, 0xffd31b], |
|
[0.33, 0xa6ce42], |
|
[0.4, 0x007ac1], |
|
[0.45, 0x007ac1], |
|
|
|
[0.55, 0x007ac1], |
|
[0.6, 0x007ac1], |
|
[0.67, 0xa6ce42], |
|
[0.8, 0xffd31b], |
|
[1.0, 0xf15a31] |
|
]; |
|
|
|
function lerp(x, x0, x1, y0, y1) { |
|
const t = (x - x0) / (x1 - x0); |
|
return y0 + t * (y1 - y0); |
|
} |
|
|
|
function lerpStroke(t) { |
|
return lerpTable(1, t, colorTable, false, lerpColor); |
|
} |
|
|
|
function lerpOffset(min, max, t) { |
|
return (max - min) * t + min; |
|
} |
|
|
|
function lerpColor(x, x0, x1, y0, y1) { |
|
const b0 = y0 & 0xff; |
|
const g0 = (y0 & 0xff00) >> 8; |
|
const r0 = (y0 & 0xff0000) >> 16; |
|
|
|
const b1 = y1 & 0xff; |
|
const g1 = (y1 & 0xff00) >> 8; |
|
const r1 = (y1 & 0xff0000) >> 16; |
|
|
|
const r = Math.floor(lerp(x, x0, x1, r0, r1)); |
|
const g = Math.floor(lerp(x, x0, x1, g0, g1)); |
|
const b = Math.floor(lerp(x, x0, x1, b0, b1)); |
|
|
|
return "#" + ((r << 16) | ( return "#" + ((r << 16) | (g << 8) | b).toString(16).padStart(6, "0"); |
|
} |
|
|
|
function lerpTable(vIndex, tValue, table, canExtrapolate, lerpFunc = lerp) { |
|
const rowCount = table.length; |
|
|
|
for (let i = 0; i < rowCount; ++i) { |
|
const a = table[i][0]; |
|
|
|
if (i === 0 && tValue < a) { |
|
if (canExtrapolate) { |
|
return lerpFunc( |
|
tValue, |
|
a, |
|
table[i + 1][0], |
|
table[i][vIndex], |
|
table[i + 1][vIndex] |
|
); |
|
} |
|
return table[i][vIndex]; |
|
} |
|
|
|
if (i === rowCount - 1 && tValue >= a) { |
|
if (canExtrapolate) { |
|
return lerpFunc( |
|
tValue, |
|
table[i - 1][0], |
|
a, |
|
table[i - 1][vIndex], |
|
table[i][vIndex] |
|
); |
|
} |
|
return table[i][vIndex]; |
|
} |
|
|
|
if (tValue >= a && tValue <= table[i + 1][0]) { |
|
return lerpFunc( |
|
tValue, |
|
a, |
|
table[i + 1][0], |
|
table[i][vIndex], |
|
table[i + 1][vIndex] |
|
); |
|
} |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
const el = document.getElementById("el"); |
|
|
|
const speed = 2; |
|
const speedDashoffset = 7600 / speed; |
|
const speedStroke = 6000 / speed; |
|
const pathWidth = 372; |
|
let startTime; |
|
let animationFrameId; |
|
|
|
const tick = (now) => { |
|
const dtOffset = ((now - startTime) % speedDashoffset) / speedDashoffset; |
|
const dtStroke = ((now - startTime) % speedStroke) / speedStroke; |
|
|
|
const stroke = lerpStroke(dtStroke); |
|
const offset = lerpOffset(pathWidth / 2, -pathWidth / 2, dtOffset); |
|
|
|
el.style.cssText = `stroke-dashoffset: ${offset}; stroke: ${stroke};`; |
|
|
|
animationFrameId = requestAnimationFrame(tick); |
|
}; |
|
|
|
document.getElementById('sendRequestButton').addEventListener('click', function() { |
|
|
|
document.getElementById('spinner').style.display = 'block'; |
|
startTime = performance.now(); |
|
tick(startTime); |
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
document.getElementById('spinner').style.display = 'none'; |
|
cancelAnimationFrame(animationFrameId); |
|
}, 3000); |
|
}); |
|
</script> |
|
</body> |
|
</html> |