-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample4.js
132 lines (115 loc) · 4.34 KB
/
example4.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
var example = {};
example.active = {}
example.init = function(params) {
let selector = params.selector;
let index = params.index;
example.active[selector] = edges.newEdge({
selector: selector,
template: example.newExampleTemplate(),
search_url: index + "doaj-journal/doc/_search",
components : [
edges.newRefiningANDTermSelector({
id: "journal_license",
category: "side",
field: "index.license.exact",
display: "Journal License",
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: true,
togglable: true
})
}),
example.newExampleComponent({
id: "stats",
category: "side",
renderer: example.newExampleRenderer()
}),
edges.newResultsDisplay({
id: "results",
category: "main",
renderer: edges.bs3.newResultsFieldsByRowRenderer({
rowDisplay : [
[{ field: "bibjson.title" }],
[{
"pre" : "<strong>Editor Group</strong>: ",
"field" : "admin.editor_group"
}]
]
})
})
],
});
}
example.newExampleComponent = function(params) {
return edges.instantiate(example.ExampleComponent, params, edges.newComponent)
}
example.ExampleComponent = function (params) {
this.count = false;
this.min = false;
this.max = false;
this.avg = false;
this.contrib = function(query) {
query.addAggregation(es.newStatsAggregation({"name" : "stats", "field" : "bibjson.apc.max.price"}))
}
this.synchronise = function() {
this.count = false;
this.min = false;
this.max = false;
this.avg = false;
if (!this.edge.result) {
return
}
let agg = this.edge.result.aggregation("stats");
this.count = agg.count;
this.min = agg.min;
this.max = agg.max;
this.avg = agg.avg;
}
}
example.newExampleRenderer = function(params) {
return edges.instantiate(example.ExampleRenderer, params, edges.newRenderer)
}
example.ExampleRenderer = function(params) {
this.namespace = "example"
this.draw = function() {
if (!this.component.count) {
this.component.context.html("");
return;
}
let containerClass = edges.css_classes(this.namespace, "container", this);
let labelClass = edges.css_classes(this.namespace, "label", this);
let numberClass = edges.css_classes(this.namespace, "number", this);
let frag = `<div class="row ` + containerClass + `">
<div class="col-xs-12">
<span class="` + labelClass + `">Count</span> <span class="` + numberClass + `">` + this.component.count + `</span><br>
<span class="` + labelClass + `">Min</span> <span class="` + numberClass + `">` + this.component.min + `</span><br>
<span class="` + labelClass + `">Max</span> <span class="` + numberClass + `">` + this.component.max + `</span><br>
<span class="` + labelClass + `">Avg</span> <span class="` + numberClass + `">` + this.component.avg + `</span><br>
</div>
</div>`
this.component.context.html(frag);
}
}
example.newExampleTemplate = function(params) {
return edges.instantiate(example.ExampleTemplate, params, edges.newTemplate)
}
example.ExampleTemplate = function(params) {
this.draw = function(edge) {
this.edge = edge;
let main = "";
let mainComponents = edge.category("main");
for (let i = 0; i < mainComponents.length; i++) {
main += `<div id="` + mainComponents[i].id + `"></div>`;
}
let side = "";
let sideComponents = edge.category("side");
for (let i = 0; i < sideComponents.length; i++) {
side += `<div id="` + sideComponents[i].id + `"></div>`;
}
let frag = `<div class="row">
<div class="col-md-9">` + main + `</div>
<div class="col-md-3">` + side + `</div>
</div>`
this.edge.context.html(frag);
}
}