-
Notifications
You must be signed in to change notification settings - Fork 13
/
datasets.js
108 lines (86 loc) · 2.87 KB
/
datasets.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
96
97
98
99
100
101
102
103
104
105
106
107
108
$(document).ready(function() {
Tabletop.init({
key: "1lv74SigFdFMJvza_dc2tBVd37r9E4-CPeY9YkRSaBxA",
callback: showInfo,
parseNumbers: true
});
});
var allRows = [];
function showInfo(data, tabletop) {
allRows = _.sortBy(tabletop.sheets("Completed Detailed Data").all(), "Department");
var uri = new URI();
var params = uri.search(true);
if (params) {
var filters = [];
filters.push(buildDepartmentFilter(params["department"]));
filters.push(buildDatatypeFilter(params["datatype"]));
updateCards(allRows, _.compact(filters));
} else {
updateCards(allRows);
}
}
function updateCards(rows, filters) {
var filters = filters || [];
var source = $("#card-template").html();
var template = Handlebars.compile(source);
_.chain(rows)
.filter(function(row) {
return _.all(filters, function(filter) {
return filter(row);
});
})
.map(function(row) {
row.free = row["Data is freely available online"];
row.machine = row["Data is machine readable"];
row.context = row["Context is provided"];
row.bulk = row["Available in bulk"];
row.fresh = row["Up-to-date"];
row.incident = row["Incident-level data"];
row.freeCaption = captions.free[row.free];
row.machineCaption = captions.machine[row.machine];
row.contextCaption = captions.context[row.context];
row.bulkCaption = captions.bulk[row.bulk];
row.freshCaption = captions.fresh[row.fresh];
row.incidentCaption = captions.incident[row.incident];
var html = template(row);
$("#cards").append(html);
$('[data-toggle="tooltip"]').tooltip();
});
}
function buildDepartmentFilter(department) {
if (!department) {
return false;
}
return function(row) {
return row["Department"] === department;
}
}
function buildDatatypeFilter(datatype) {
if (!datatype) {
return false;
}
return function(row) {
return row["Type of Data"] === datatype;
}
}
function clearCards() {
$("#cards").empty();
}
function filterByDepartment(department) {
clearCards();
updateCards(allRows, [buildDepartmentFilter(department)]);
}
function resetSearch() {
clearCards();
updateCards(allRows);
}
function filterByDatatype(datatype) {
clearCards();
updateCards(allRows, [buildDatatypeFilter(datatype)]);
}
function filterByMachineReadable(machineReadable) {
clearCards();
updateCards(_.filter(allRows, function(row) {
return machineReadable ? row["Data is machine readable"] === "Yes" : row["Data is machine readable"] === "No";
}))
}