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

Джевелло Алексей, Лапшин Евгений, Сыч Эрнест, ФТ-201 #124

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
50 changes: 25 additions & 25 deletions static/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ 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);
});
});
});
});
const requisitesPromise = sendRequest(`${API.orgReqs}?ogrn=${ogrns}`);
const analyticsPromise = sendRequest(`${API.analytics}?ogrn=${ogrns}`);
const buhPromise = sendRequest(`${API.buhForms}?ogrn=${ogrns}`);
const [requisites, analytics, buh] = await Promise.all([requisitesPromise, analyticsPromise, buhPromise]);
const orgsMap = reqsToMap(requisites);
addInOrgsMap(orgsMap, analytics, "analytics");
addInOrgsMap(orgsMap, buh, "buhForms");
render(orgsMap, orgOgrns);
}
catch (err){
alert(err.message);
}
}

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 fetch(url)
//.then(response => response)
.then(response => {
if (response.status >= 300){
throw new Error(`status invalid - ${response.status}`);
}
}
};

xhr.send();
return response.json();
});
//.catch(reason => {});
}

function reqsToMap(requisites) {
Expand Down