-
Notifications
You must be signed in to change notification settings - Fork 5
/
widget.6.js
94 lines (74 loc) · 2.41 KB
/
widget.6.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
const PANEL_FILTER_DIMENSION = 'Filter Dimension';
prism.registerWidget('wiserFilterWidget', {
name: 'wiserFilterWidget',
family: 'wiser',
title: 'Filter',
priority: 0,
iconSmall: '/plugins/wiserFilterWidget/images/wiser-widget-24.png',
style: {
ignoreDashboardFilter: true,
multipleSelect: true
},
styleEditorTemplate: '/plugins/WiserFilterWidget/style-editor/template.html',
hideNoResults: true,
directive: 'wiser-filter-widget',
data: {
panels: [
{
name: PANEL_FILTER_DIMENSION,
type: 'visible',
allowedDataTypes: 'text',
metadata: { types: ['dimensions'], maxitems: 1 }
},
{
name: 'filters',
type: 'filters',
metadata: { types: ['dimensions'], maxitems: -1 }
}
],
// allocatePanel ??
// isSupported ??
// rankMetadata ??
// populateMetdata ??
buildQuery(widget) {
let query = {
datasource: widget.datasource,
metadata: []
};
let dimensionPanel = widget.metadata.panel(PANEL_FILTER_DIMENSION);
query.metadata.push(dimensionPanel.items[0]);
widget.metadata.panel('filters').items.forEach(function (item) {
let queryItem = $$.object.clone(item, true);
queryItem.panel = 'scope';
query.metadata.push(queryItem);
});
return query;
},
processResult(widget, queryResult) {
return _.map(queryResult.rows(), (row) => row[0]);
}
},
// Before the final query gets sent, omit any filter which filters on our
// current dimension to avoid self-filtering
beforequery(widget, event) {
if (!event.query.metadata.length) { return; }
if (!widget.style.ignoreDashboardFilter) { return; }
let dimensionPanel = widget.metadata.panel(PANEL_FILTER_DIMENSION);
let widgetFilterDimension = dimensionPanel.items[0].jaql.dim;
let filterPanel = widget.metadata.panel('filters');
let filterDimensions = filterPanel.items.map((item) => item.jaql.dim);
event.query.metadata = _.reject(event.query.metadata, function(metadatum) {
let isFilter = metadatum.panel === 'scope';
let isWidgetFilter = filterDimensions.indexOf(metadatum.jaql.dim) === -1;
let matchesDimension = metadatum.jaql.dim === widgetFilterDimension;
return isFilter && isWidgetFilter && matchesDimension;
});
},
// ready ??
// mask ??
// options?
sizing: {
minHeight: 73,
height: 76
}
});