diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..ab1f416
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,10 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Ignored default folder with query files
+/queries/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/async.iml b/.idea/async.iml
new file mode 100644
index 0000000..c956989
--- /dev/null
+++ b/.idea/async.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..7eaaa98
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/static/focus.js b/static/focus.js
index 4b43735..bfcc04c 100644
--- a/static/focus.js
+++ b/static/focus.js
@@ -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;
@@ -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 = "—";