Skip to content
Open
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
45 changes: 20 additions & 25 deletions static/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,32 @@ const API = {
buhForms: "/api3/buh",
};

function run() {
sendRequest(API.organizationList, (orgOgrns) => {
const ogrns = orgOgrns.join(",");
sendRequest(`${API.orgReqs}?ogrn=${ogrns}`, (requisites) => {
async function run() {
let orgOgrns = await sendRequest(API.organizationList)
let ogrns = orgOgrns.join(",");

Promise.all([
sendRequest(`${API.orgReqs}?ogrn=${ogrns}`),
sendRequest(`${API.analytics}?ogrn=${ogrns}`),
sendRequest(`${API.buhForms}?ogrn=${ogrns}`)
])
.then(([requisites, analytics, buh]) => {
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);
});
});
addInOrgsMap(orgsMap, analytics, "analytics");
addInOrgsMap(orgsMap, buh, "buhForms");
render(orgsMap, orgOgrns);
});
});
}

run();

function sendRequest(url, callback) {
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));
}
}
};

xhr.send();
async function sendRequest(url, callback) {
let fetchURL = await fetch(url);
if (fetchURL.ok) {
return await fetchURL.json();
} else {
throw new Error("Ошибка HTTP: " + fetchURL.status)
}
}

function reqsToMap(requisites) {
Expand Down