-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclearfilters.js
More file actions
82 lines (77 loc) · 3.02 KB
/
Copy pathclearfilters.js
File metadata and controls
82 lines (77 loc) · 3.02 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
let dashboard, parameter, dataSource;
$(document).ready(function() {
tableau.extensions.initializeAsync({ 'configure': configure }).then(() => {
console.log(tableau.extensions.settings.getAll());
dashboard = tableau.extensions.dashboardContent.dashboard;
let configured = tableau.extensions.settings.get('configured');
if (configured != 'true') {
configure();
} else {
show();
}
});
});
// Pops open the configure page
function configure(payload) {
const popupUrl = `${window.location.origin}/Clear-Filters/config.html`
tableau.extensions.ui.displayDialogAsync(popupUrl, payload, { height: 350, width: 450 }).then((closePayload) => {
console.log("Dialog was closed.");
console.log(closePayload);
show();
}).catch((error) => {
switch (error.errorCode) {
case tableau.ErrorCodes.DialogClosedByUser:
console.log("Dialog was closed by user.");
break;
default:
console.error(error.message);
}
});
}
// Shows or hides buttons based on settings
function show() {
document.body.style.backgroundColor = tableau.extensions.settings.get('bg');
if (tableau.extensions.settings.get('showClear') == 'true') {
document.getElementById('clearbutton').style.display = 'inline';
} else {
document.getElementById('clearbutton').style.display = 'none';
}
if (tableau.extensions.settings.get('showReset') == 'true') {
document.getElementById('resetbutton').style.display = 'inline';
} else {
document.getElementById('resetbutton').style.display = 'none';
}
}
// Clears all filters on a dashboard
function clearFilters() {
dashboard.worksheets.forEach(function(worksheet) {
worksheet.getFiltersAsync().then(function(filtersForWorksheet) {
let filterClearPromises = [];
filtersForWorksheet.forEach(function(filter) {
filterClearPromises.push(worksheet.clearFilterAsync(filter.fieldName));
});
});
});
}
// Resets al filters on dashboard to defaults
function resetFilters() {
if (tableau.extensions.settings.get('defaults_set') == 'true') {
defaults = JSON.parse(tableau.extensions.settings.get('defaults'));
console.log(defaults);
dashboard.worksheets.forEach(function(worksheet) {
for (d of defaults) {
if (worksheet.name == d['worksheetName']) {
// Categorical filters
if (d['filterType'] == 'categorical') {
worksheet.applyFilterAsync(d['fieldName'], d['appliedValues'], d['updateType'], { isExcludeMode: d['isExcludeMode'] });
}
if (d['filterType'] == 'range') {
worksheet.applyRangeFilterAsync(d['fieldName'], { min: d['min'], max: d['max'] });
}
}
}
});
} else {
configure('No default filters set');
}
}