From 856e0f134c97c18b7af9b0d98ba5b91b28fc595e Mon Sep 17 00:00:00 2001 From: Ivan-Malgin Date: Tue, 28 Apr 2026 18:41:47 +0500 Subject: [PATCH 1/4] frst --- static/focus.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/static/focus.js b/static/focus.js index 4b43735..5e9e7a1 100644 --- a/static/focus.js +++ b/static/focus.js @@ -5,38 +5,38 @@ const API = { buhForms: "/api3/buh", }; -function run() { - sendRequest(API.organizationList, (orgOgrns) => { - 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); - }); - }); - }); - }); +async function run() { + const orgOgrns = await sendRequest(API.organizationList); + const ogrns = orgOgrns.join(","); + const requisites = await sendRequest(`${API.orgReqs}?ogrn=${ogrns}`); + 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); } run(); -function sendRequest(url, callback) { +async function sendRequest(url, callback) { + return new Promise((resolve) => { const xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.onreadystatechange = function () { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { - callback(JSON.parse(xhr.response)); + + resolve(JSON.parse(xhr.response)); } } }; xhr.send(); } +); +} function reqsToMap(requisites) { return requisites.reduce((acc, item) => { From 239fe6dff571fb1b7cca775a9328e8df7d88a599 Mon Sep 17 00:00:00 2001 From: aleksandraizmaylova Date: Tue, 28 Apr 2026 19:01:00 +0500 Subject: [PATCH 2/4] scnd --- static/focus.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/static/focus.js b/static/focus.js index 5e9e7a1..6fca174 100644 --- a/static/focus.js +++ b/static/focus.js @@ -20,22 +20,11 @@ async function run() { run(); async function sendRequest(url, callback) { - return new Promise((resolve) => { - const xhr = new XMLHttpRequest(); - xhr.open("GET", url, true); - - xhr.onreadystatechange = function () { - if (xhr.readyState === XMLHttpRequest.DONE) { - if (xhr.status === 200) { - - resolve(JSON.parse(xhr.response)); - } + return fetch(url).then((response) => { + if (response.ok) { + return response.json(); } - }; - - xhr.send(); -} -); + }); } function reqsToMap(requisites) { From 98e3c78c4d57509c9a97a72fdda03db6d12b3d15 Mon Sep 17 00:00:00 2001 From: aleksandraizmaylova Date: Tue, 28 Apr 2026 19:20:10 +0500 Subject: [PATCH 3/4] thrd --- static/focus.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/static/focus.js b/static/focus.js index 6fca174..60cb0f3 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", }; @@ -23,6 +23,8 @@ async function sendRequest(url, callback) { return fetch(url).then((response) => { if (response.ok) { return response.json(); + } else { + alert(`${response.status} ${response.statusText}`); } }); } From b15b2e32331954e5e0c1e85a559b211cb04c4759 Mon Sep 17 00:00:00 2001 From: aleksandraizmaylova Date: Tue, 28 Apr 2026 19:38:58 +0500 Subject: [PATCH 4/4] frth --- static/focus.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/static/focus.js b/static/focus.js index 60cb0f3..6cac442 100644 --- a/static/focus.js +++ b/static/focus.js @@ -1,6 +1,6 @@ const API = { organizationList: "/orgsList", - analytics: "/api3/analitics", + analytics: "/api3/analytics", orgReqs: "/api3/reqBase", buhForms: "/api3/buh", }; @@ -8,12 +8,17 @@ const API = { async function run() { const orgOgrns = await sendRequest(API.organizationList); const ogrns = orgOgrns.join(","); - const requisites = await sendRequest(`${API.orgReqs}?ogrn=${ogrns}`); + + const [requisites, analytics, buh] = await Promise.all([ + sendRequest(`${API.orgReqs}?ogrn=${ogrns}`), + sendRequest(`${API.analytics}?ogrn=${ogrns}`), + sendRequest(`${API.buhForms}?ogrn=${ogrns}`) + ]); + 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); }