Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/async.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions static/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +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, o=>o);
const ogrns = orgOgrns.join(",");

const [requisites, analytics, buh]
= await Promise.all([
sendRequest(`${API.orgReqs}?ogrn=${ogrns}`, o=>o),
sendRequest(`${API.analytics}?ogrn=${ogrns}`, o=>o),
sendRequest(`${API.buhForms}?ogrn=${ogrns}`, o=>o)]
);
const orgsMap = reqsToMap(requisites);
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));
return fetch(url)
.then(res => {
if (!res.ok) {
throw new Error(`${res.status} ${res.statusText}`);
} else {
return res.json().then(data => callback(data));
}
}
};
}).catch(error => alert(error));

xhr.send();
}


function reqsToMap(requisites) {
return requisites.reduce((acc, item) => {
acc[item.ogrn] = item;
Expand Down Expand Up @@ -86,7 +85,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 = "—";
Expand Down