-
Notifications
You must be signed in to change notification settings - Fork 3
/
itemjs-script.js
88 lines (80 loc) · 1.82 KB
/
itemjs-script.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
var configuration = {
searchableFields: ['workLabel', 'topics', 'date', 'places', 'authors', 'editors', 'authorstrings'],
sortings: {
name_asc: {
field: 'workLabel',
order: 'asc'
}
},
aggregations: {
topics: {
title: 'Topics',
size: 10
}, //, for more just add them via their attribute name
objects: {
title: 'Individual seals',
size: 10
},
places: {
title: 'Places',
size: 10
}
}
}
// the rows comes from external resources
// https://github.com/itemsapi/itemsapi-example-data/blob/master/jsfiddle/imdb.js
//with json: var as = JSON.parse(jstring);
itemsjs = itemsjs(literature, configuration);
Vue.component('paginate', VuejsPaginate)
var vm = new Vue({
el: '#el',
data: function () {
// making it more generic
var filters = {};
Object.keys(configuration.aggregations).map(function(v) {
filters[v] = [];
})
// adding pagination variables
var page = this.page || 1;
var per_page = this.per_page || 12;
return {
query: '',
// initializing filters with empty arrays
filters: filters,
// setting pagination variables
page: page,
per_page: per_page,
}
},
methods: {
reset: function () {
var filters = {};
Object.keys(configuration.aggregations).map(function(v) {
filters[v] = [];
})
this.filters = filters;
this.page = 1;
this.query = '';
},
goToPage: function (page) {
this.page = page;
return page;
},
},
watch: {
query: function () {
this.page = 1;
}
},
computed: {
searchResult: function () {
var result = itemsjs.search({
query: this.query,
page: this.page,
per_page: 10,
filters: this.filters
})
return result
}
}
});