Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions httpd/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,29 @@ <h3 class="history-title">История введенных данных</h3>
// Хранение истории данных
let formHistory = JSON.parse(localStorage.getItem('formHistory')) || [];

const FFCGIResponceHandler = (responce, X, Y, R) => {
const JSONresponce = JSON.parse(responce);

// Сохраняем данные в историю
const formData = {
timestamp: new Date().toISOString(),
X: X,
Y: Y,
R: R,
elapsedTimeNs: JSONresponce.elapsedTimeNs,
isHitted: JSONresponce.result
};

formHistory.push(formData);
localStorage.setItem('formHistory', JSON.stringify(formHistory));

// Обновляем таблицу
refreshHistoryTable();

// Обновляем график
refreshGraph();
}

// Обработчик отправки формы
document.getElementById('graph-test-form').addEventListener('submit', function (e) {
e.preventDefault(); // Отключаем дефолтное поведение
Expand All @@ -643,36 +666,17 @@ <h3 class="history-title">История введенных данных</h3>
const Y = document.getElementById('Y').value;

if (X && R && Y) {
// Stub
sendAJAXGETRequest("/fcgi-bin/", {"x": X, "y": Y, "r": R}, (data) => {console.log(data)});
console.log(`Данные отправлены!\nX: ${X}\nY: ${Y}\nR: ${R}`);

// Сохраняем данные в историю
const formData = {
timestamp: new Date().toISOString(),
X: X,
Y: Y,
R: R,
elapsedTimeMs: 100,
isHitted: true
};

formHistory.push(formData);
localStorage.setItem('formHistory', JSON.stringify(formHistory));

// Обновляем таблицу
refreshHistoryTable();

// Обновляем график
refreshGraph();
sendAJAXGETRequest("/fcgi-bin/", {"x": X, "y": Y, "r": R}, (resp) => {FFCGIResponceHandler(resp, X, Y, R)});

// Очищаем форму
this.reset();

} else {
alert('Пожалуйста, заполните все поля формы')
}
});


// Функция для обновления таблицы истории
// TODO: переделать говнокод!
const refreshHistoryTable = () => {
Expand All @@ -696,7 +700,7 @@ <h3 class="history-title">История введенных данных</h3>

row.innerHTML = `
<td>${new Date(elem.timestamp).toLocaleString('ru-RU')}</td>
<td>${elem.elapsedTimeMs} ms</td>
<td>${elem.elapsedTimeNs} ns</td>
<td>${elem.X}</td>
<td>${elem.Y}</td>
<td>${elem.R}</td>
Expand All @@ -718,9 +722,9 @@ <h3 class="history-title">История введенных данных</h3>
const R = parseFloat(elem.R);

const cx = 20 + (1 + X/R)*80;
const cy = 20 + (1 + Y/R)*80;
const cy = 20 + (1 - Y/R)*80;

if (!container.querySelector(`circle[cx="${cx}"][cy="${cy}"]`) && Math.abs(cx) <= 200 && Math.abs(cy) <= 200) {
if (!container.querySelector(`circle[cx="${cx}"][cy="${cy}"]`) && 0 <= cx <= 200 && 0 <= cy <= 200) {
const point = document.createElementNS(svgns, 'circle');

point.setAttributeNS(null, 'cx', cx);
Expand Down