-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (47 loc) · 1.29 KB
/
index.js
File metadata and controls
60 lines (47 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const Crawler = require('./lib/crawler');
async function processDashboard(crawler, dashboard, opts) {
await crawler.goToDashboardById(dashboard.id, opts.delay);
const result = {
title: dashboard.name,
};
if (!opts.skipGraphs) {
const graphs = await crawler.gatherSvgsFromDashboard();
result.graphs = graphs;
}
if (!opts.skipTables) {
const tables = await crawler.gatherTablesFromDashboard();
result.tables = tables;
}
return result;
}
class DHIS2Crawler {
constructor(url) {
this.url = url;
}
startup(options) {
this.crawler = new Crawler(options);
this.on = this.crawler.on.bind(this.crawler);
return this.crawler.initialize();
}
login(username, password) {
this.crawler.setCredentials({ username, password });
return this.crawler.login(this.url);
}
// note: dashboards are objects of form [{ name, id }]
async downloadDashboardComponents(dashboards, options = {}) {
const files = [];
// eslint-disable-next-line
for (const board of dashboards) {
// eslint-disable-next-line
files.push(await processDashboard(this.crawler, board, options));
}
return files;
}
shutdown() {
return this.crawler.destroy();
}
panic() {
return this.crawler.destroy(true);
}
}
module.exports = DHIS2Crawler;