diff --git a/docs/openapi.yaml b/docs/openapi.yaml index a5e95a1..2dde410 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 info: title: "WebProg Lab1" - version: 0.0.2 + version: 0.1.0 description: | Сервак из говна и палок @@ -11,11 +11,11 @@ servers: description: FastCGI API paths: - /: + /test: get: summary: Тест попадания в область tags: - - General + - Test hit parameters: - in: query name: x @@ -55,6 +55,58 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" + + /journal: + get: + summary: Получение истории + tags: + - Journal + responses: + 200: + description: Responce with data + content: + application/json: + schema: + type: array + description: Нужные для получения поля профиля пользователя + items: + type: object + properties: + timestamp: + type: integer + description: "Timestamp в милисекундах" + example: 1000000 + elapsedTimeNs: + type: integer + description: "Затраченное на обработку время в наносекундах" + example: 100 + x: + type: integer + example: 0 + y: + type: integer + example: 0 + r: + type: integer + example: 0 + isInsideArea: + type: boolean + example: true + delete: + summary: Удаление истории + tags: + - Journal + responses: + 200: + description: Responce + content: + application/json: + schema: + type: object + properties: + result: + type: string + example: "Completed!" components: schemas: x: diff --git a/httpd/static/index.html b/httpd/static/index.html index 6f4ebe2..eb91965 100644 --- a/httpd/static/index.html +++ b/httpd/static/index.html @@ -3,9 +3,14 @@ - Web lab1 - + Web lab1 + + + + + + @@ -671,167 +676,93 @@

История введенных данных

diff --git a/httpd/static/js/ajax.js b/httpd/static/js/ajax.js deleted file mode 100644 index 9975aa8..0000000 --- a/httpd/static/js/ajax.js +++ /dev/null @@ -1,22 +0,0 @@ -const sendAJAXGETRequest = (url, data, callback) => { - // encode url - const query = []; - for (const key in data) { - query.push(String(key) + '=' + String(data[key])); - } - - // creating AJAX req object - const xhr = new XMLHttpRequest(); - // enable CORS support - xhr.withCredentials = true; - - xhr.open("GET", url+(query.length ? '?' + query.join('&') : '')); - - xhr.onreadystatechange = () => { - if (xhr.readyState == 4) { // status of finished request - callback(xhr.responseText) - } - }; - - xhr.send(data) -}; \ No newline at end of file diff --git a/httpd/static/js/error.js b/httpd/static/js/error.js new file mode 100644 index 0000000..d7384b2 --- /dev/null +++ b/httpd/static/js/error.js @@ -0,0 +1,31 @@ +class ErrorFactory { + #errorBlockClassName + + constructor(errorBlockClassName){ + this.#errorBlockClassName = errorBlockClassName; + } + + #clearErrors(){ + let existingErrors = document.querySelectorAll(this.#errorBlockClassName); + existingErrors.forEach(error => error.remove()); + } + + showError(message, showTimeMs = 5000){ + this.#clearErrors(); + + // Слздаём элемент + const errorDiv = document.createElement('div'); + errorDiv.className = this.#errorBlockClassName; + errorDiv.textContent = message; + + // Вставка + document.body.appendChild(errorDiv); + + // Убираем по прошествии времени + setTimeout(() => { + if (errorDiv.parentNode) { + errorDiv.parentNode.removeChild(errorDiv); + } + }, showTimeMs); + } +} \ No newline at end of file diff --git a/httpd/static/js/historyTable.js b/httpd/static/js/historyTable.js new file mode 100644 index 0000000..a43dd29 --- /dev/null +++ b/httpd/static/js/historyTable.js @@ -0,0 +1,47 @@ +class HistoryTable { + #tableElem; + #emptyHistoryElem; + + constructor(tableId, emptyHistoryBlockId) { + this.#tableElem = document.getElementById(tableId); + + this.#emptyHistoryElem = new EmptyBlock(emptyHistoryBlockId); + this.#emptyHistoryElem.setVisibility(true); + } + + addHistoryItem(timestamp, elapsedTime, x, y, r, isHitted) { + this.#emptyHistoryElem.setVisibility(false); + + const row = document.createElement('tr'); + + row.innerHTML = ` + ${new Date(timestamp).toLocaleString('ru-RU')} + ${elapsedTime} ns + ${x} + ${y} + ${r} + ${isHitted ? 'HIT' : 'MISS'} + `; + + this.#tableElem.prepend(row); + } + + clear() { + this.#tableElem.querySelectorAll('tr').forEach((elem) => { + elem.remove(); + }); + this.#emptyHistoryElem.setVisibility(true); + } +} + +class EmptyBlock { + #emptyHistoryElem; + + constructor(emptyHistoryBlockId) { + this.#emptyHistoryElem = document.getElementById(emptyHistoryBlockId); + } + + setVisibility(isVisible) { + emptyHistory.style.display = isVisible ? 'block' : 'none'; + } +} \ No newline at end of file diff --git a/httpd/static/js/net/ajax.js b/httpd/static/js/net/ajax.js new file mode 100644 index 0000000..c326b6b --- /dev/null +++ b/httpd/static/js/net/ajax.js @@ -0,0 +1,34 @@ +const sendAJAXRequest = (method, url, data) => { + return new Promise((resolve, reject) => { + // encode url + const query = []; + for (const key in data) { + query.push(String(key) + '=' + String(data[key])); + } + + // creating AJAX req object + const xhr = new XMLHttpRequest(); + // enable CORS support + xhr.withCredentials = true; + + xhr.open(method, url + (query.length ? '?' + query.join('&') : '')); + + xhr.onreadystatechange = () => { + if (xhr.readyState === 4) { + if (xhr.status >= 200 && xhr.status < 300) { + resolve({ + status: xhr.status, + response: xhr.responseText + }); + } else { + reject({ + status: xhr.status, + response: xhr.responseText + }); + } + } + }; + + xhr.send(); + }); +}; \ No newline at end of file diff --git a/httpd/static/js/plot.js b/httpd/static/js/plot.js new file mode 100644 index 0000000..2206469 --- /dev/null +++ b/httpd/static/js/plot.js @@ -0,0 +1,37 @@ +const convertInputCordsToSvgCords = ( + X, Y, R, + paddingX = 20, + paddingY = 20, + XAxisSize = 160, + YAxisSize = 160 +) => { + return [paddingX + (1 + X/R)*XAxisSize/2, paddingY + (1 - Y/R)*YAxisSize/2]; +} + + +class Plot { + #svgNamespace = "http://www.w3.org/2000/svg"; + #container; + + constructor(svgId) { + this.#container = document.getElementById(svgId); + } + + addPoint(cx, cy, radius, styleClass) { + const point = document.createElementNS(this.#svgNamespace, 'circle'); + + point.setAttributeNS(null, 'cx', cx); + point.setAttributeNS(null, 'cy', cy); + point.setAttributeNS(null, 'r', radius); + point.setAttributeNS(null, 'class', styleClass); + + this.#container.appendChild(point); + } + + clear() { + this.#container.querySelectorAll('circle').forEach((elem) => { + elem.remove(); + }); + } + +} \ No newline at end of file diff --git a/server/.idea/runConfigurations/Main.xml b/server/.idea/runConfigurations/Application.xml similarity index 72% rename from server/.idea/runConfigurations/Main.xml rename to server/.idea/runConfigurations/Application.xml index 2e1a7a7..b9e984c 100644 --- a/server/.idea/runConfigurations/Main.xml +++ b/server/.idea/runConfigurations/Application.xml @@ -1,8 +1,8 @@ - +