Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ФТ-202 Южанин Арсений Иванов Станислав #115

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add 1 punkt
  • Loading branch information
StasanSas committed Apr 23, 2024
commit 5ce64fd0931cd79846456b03634cd04919af6b6f
59 changes: 33 additions & 26 deletions static/focus.js
Original file line number Diff line number Diff line change
@@ -5,39 +5,46 @@ 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) {
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));
function sendRequest(url) {
return new Promise((resolve, reject) => {
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));
} else {
reject(new Error(`Request failed with status ${xhr.status}`));
}
}
}
};
};

xhr.send();
xhr.send();
});
}


function reqsToMap(requisites) {
return requisites.reduce((acc, item) => {
acc[item.ogrn] = item;
@@ -86,7 +93,7 @@ function renderOrganization(orgInfo, template, container) {
orgInfo.buhForms[orgInfo.buhForms.length - 1].form2[0] &&
orgInfo.buhForms[orgInfo.buhForms.length - 1].form2[0]
.endValue) ||
0
0
);
} else {
money.textContent = "—";
@@ -131,4 +138,4 @@ function createAddress(address) {
function createAddressItem(key) {
return `${address[key].topoShortName}. ${address[key].topoValue}`;
}
}
}