From d4db194b12dceb4a56762664906e51cc86f042ce Mon Sep 17 00:00:00 2001 From: mayle Date: Tue, 28 Apr 2026 17:55:48 +0500 Subject: [PATCH 1/2] Task 1-2 done --- static/focus.js | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/static/focus.js b/static/focus.js index 4b43735..fb92c7d 100644 --- a/static/focus.js +++ b/static/focus.js @@ -5,37 +5,33 @@ const API = { buhForms: "/api3/buh", }; -function run() { - sendRequest(API.organizationList, (orgOgrns) => { +async function run() { + try { + const orgOgrns = await sendRequest(API.organizationList); const ogrns = orgOgrns.join(","); - sendRequest(`${API.orgReqs}?ogrn=${ogrns}`, (requisites) => { - const orgsMap = reqsToMap(requisites); - sendRequest(`${API.analytics}?ogrn=${ogrns}`, (analytics) => { - addInOrgsMap(orgsMap, analytics, "analytics"); - sendRequest(`${API.buhForms}?ogrn=${ogrns}`, (buh) => { - addInOrgsMap(orgsMap, buh, "buhForms"); - render(orgsMap, orgOgrns); - }); - }); - }); - }); -} -run(); + const requisites = await sendRequest(`${API.orgReqs}?ogrn=${ogrns}`); + const orgsMap = reqsToMap(requisites); + + const analytics = await sendRequest(`${API.analytics}?ogrn=${ogrns}`); + addInOrgsMap(orgsMap, analytics, "analytics"); -function sendRequest(url, callback) { - const xhr = new XMLHttpRequest(); - xhr.open("GET", url, true); + const buh = await sendRequest(`${API.buhForms}?ogrn=${ogrns}`); + addInOrgsMap(orgsMap, buh, "buhForms"); + render(orgsMap, orgOgrns); + } catch (error) { + console.error("Ошибка при выполнении запросов:", error); + } +} - xhr.onreadystatechange = function () { - if (xhr.readyState === XMLHttpRequest.DONE) { - if (xhr.status === 200) { - callback(JSON.parse(xhr.response)); - } - } - }; +run(); - xhr.send(); +async function sendRequest(url) { + const response = await fetch(url); + if (!response.ok) { + throw new Error(`Ошибка HTTP: ${response.status}`); + } + return await response.json(); } function reqsToMap(requisites) { From a59a1ea68c674a584435952663fd1d36bd7b2652 Mon Sep 17 00:00:00 2001 From: Felesia302 Date: Tue, 28 Apr 2026 18:03:48 +0500 Subject: [PATCH 2/2] 3, 4 --- static/focus.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/static/focus.js b/static/focus.js index fb92c7d..41c2514 100644 --- a/static/focus.js +++ b/static/focus.js @@ -1,6 +1,6 @@ const API = { organizationList: "/orgsList", - analytics: "/api3/analytics", + analytics: "/api3/analitics", orgReqs: "/api3/reqBase", buhForms: "/api3/buh", }; @@ -8,29 +8,37 @@ const API = { async function run() { try { const orgOgrns = await sendRequest(API.organizationList); - const ogrns = orgOgrns.join(","); + if (!orgOgrns) return; - const requisites = await sendRequest(`${API.orgReqs}?ogrn=${ogrns}`); + const ogrns = orgOgrns.join(","); + const [requisites, analytics, buh] = await Promise.all([ + sendRequest(`${API.orgReqs}?ogrn=${ogrns}`), + sendRequest(`${API.analytics}?ogrn=${ogrns}`), + sendRequest(`${API.buhForms}?ogrn=${ogrns}`) + ]); + + if (!requisites || !analytics || !buh) { + return; + } + const orgsMap = reqsToMap(requisites); - - const analytics = await sendRequest(`${API.analytics}?ogrn=${ogrns}`); addInOrgsMap(orgsMap, analytics, "analytics"); - - const buh = await sendRequest(`${API.buhForms}?ogrn=${ogrns}`); addInOrgsMap(orgsMap, buh, "buhForms"); + render(orgsMap, orgOgrns); } catch (error) { - console.error("Ошибка при выполнении запросов:", error); + console.error("Произошла критическая ошибка:", error); } } -run(); async function sendRequest(url) { const response = await fetch(url); if (!response.ok) { - throw new Error(`Ошибка HTTP: ${response.status}`); + alert(`Ошибка: ${response.status} ${response.statusText}`); + return null; } + return await response.json(); }