-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalog.js
95 lines (82 loc) · 2.73 KB
/
catalog.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Generated by CoffeeScript 1.10.0
(function() {
var CATALOG, Promise, add_children, get_featured, get_table_featured, get_table_themes, get_tables, get_theme_tree, get_themes, read_odata, utils;
utils = require("./utils");
Promise = require("promise");
CATALOG = "https://opendata.cbs.nl/ODataCatalog";
read_odata = require("./utils").read_odata;
get_tables = function(filter, select, callback) {
var url;
url = CATALOG + "/Tables";
return read_odata(url, filter, select).nodeify(callback);
};
get_themes = function(filter, select, callback) {
var url;
url = CATALOG + "/Themes";
return read_odata(url, filter, select).nodeify(callback);
};
get_featured = function(filter, select, callback) {
var url;
url = CATALOG + "/Featured";
return read_odata(url, filter, select).nodeify(callback);
};
get_table_featured = function(filter, select, callback) {
var url;
url = CATALOG + "/Table_Featured";
return read_odata(url, filter, select).nodeify(callback);
};
get_table_themes = function(filter, select, callback) {
var url;
url = CATALOG + "/Tables_Themes";
return read_odata(url, filter, select).nodeify(callback);
};
add_children = function(themes, tables, table_themes) {
var i, j, k, l, len, len1, len2, len3, parent, roots, ta, table_idx, th, theme_idx, tt;
theme_idx = {};
table_idx = {};
roots = [];
for (i = 0, len = themes.length; i < len; i++) {
th = themes[i];
th.Children = [];
theme_idx[th.ID] = th;
}
for (j = 0, len1 = tables.length; j < len1; j++) {
ta = tables[j];
table_idx[ta.ID] = ta;
}
for (k = 0, len2 = table_themes.length; k < len2; k++) {
tt = table_themes[k];
th = theme_idx[tt.ThemeID];
if (th != null) {
th.Children.push(table_idx[tt.TableID]);
}
}
for (l = 0, len3 = themes.length; l < len3; l++) {
th = themes[l];
parent = theme_idx[th.ParentID];
if (parent) {
parent.Children.push(th);
} else {
roots.push(th);
}
}
return roots;
};
get_theme_tree = function(filter, select, callback) {
var table_themes, tables, themes;
themes = get_themes(filter, select);
tables = get_tables(filter, ["ShortTitle", "ID", "Identifier"]);
table_themes = get_table_themes();
return Promise.all([themes, tables, table_themes]).then(function(info) {
themes = info[0], tables = info[1], table_themes = info[2];
return add_children(themes, tables, table_themes);
});
};
module.exports = {
get_tables: get_tables,
get_themes: get_themes,
get_table_featured: get_table_featured,
get_featured: get_featured,
get_table_themes: get_table_themes
};
}).call(this);