|
1
|
|
|
/* |
|
2
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
|
3
|
|
|
* |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. See the COPYING file. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Maxence Lange <[email protected]> |
|
8
|
|
|
* @copyright 2018 |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** global: OCA */ |
|
28
|
|
|
/** global: _ */ |
|
29
|
|
|
|
|
30
|
|
|
const \ |
|
|
|
|
|
|
31
|
|
|
fullTextSearch = OCA.FullTextSearch.api; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
var elements = { |
|
35
|
|
|
searchTimeout: null, |
|
36
|
|
|
search_input: null, |
|
37
|
|
|
search_submit: null, |
|
38
|
|
|
search_json: null |
|
39
|
|
|
}; |
|
40
|
|
|
|
|
41
|
|
|
const Navigate = function () { |
|
|
|
|
|
|
42
|
|
|
this.init(); |
|
43
|
|
|
}; |
|
44
|
|
|
|
|
45
|
|
|
Navigate.prototype = { |
|
46
|
|
|
|
|
47
|
|
|
init: function () { |
|
48
|
|
|
var self = this; |
|
49
|
|
|
|
|
50
|
|
|
fullTextSearch.setEntryTemplate($('#template_entry'), self); |
|
51
|
|
|
fullTextSearch.setResultContainer($('#search_result')); |
|
52
|
|
|
|
|
53
|
|
|
elements.search_input = $('#search_input'); |
|
54
|
|
|
elements.search_submit = $('#search_submit'); |
|
55
|
|
|
elements.search_panels = $('#search_navigation'); |
|
56
|
|
|
// elements.search_json = $('#search_json'); |
|
57
|
|
|
elements.divHeader = $('#search_header'); |
|
58
|
|
|
|
|
59
|
|
|
elements.search_input.on('input', function () { |
|
60
|
|
|
self.resetSearch(); |
|
61
|
|
|
if (elements.searchTimeout === null && self.initSearch(false)) { |
|
62
|
|
|
elements.searchTimeout = _.delay(function () { |
|
63
|
|
|
self.initSearch(false); |
|
64
|
|
|
elements.searchTimeout = null; |
|
65
|
|
|
}, 3000); |
|
66
|
|
|
} |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
// |
|
70
|
|
|
// $(document).keypress(function (e) { |
|
71
|
|
|
// if (e.which === 13) { |
|
72
|
|
|
// self.initSearch(true); |
|
73
|
|
|
// } |
|
74
|
|
|
// }); |
|
75
|
|
|
|
|
76
|
|
|
self.initPanels(); |
|
77
|
|
|
}, |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
initPanels: function () { |
|
81
|
|
|
var res = {status: -1}; |
|
82
|
|
|
var self = this; |
|
83
|
|
|
|
|
84
|
|
|
$.ajax({ |
|
85
|
|
|
method: 'GET', |
|
86
|
|
|
url: OC.generateUrl('/apps/fulltextsearch/navigation/panels') |
|
87
|
|
|
}).done(function (res) { |
|
88
|
|
|
self.displayPanels(res); |
|
89
|
|
|
}); |
|
90
|
|
|
}, |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
displayPanels: function (data) { |
|
94
|
|
|
|
|
95
|
|
|
var ak = Object.keys(data); |
|
96
|
|
|
for (var i = 0; i < ak.length; i++) { |
|
97
|
|
|
var title = data[ak[i]]['title']; |
|
|
|
|
|
|
98
|
|
|
var nav = data[ak[i]]['navigation']; |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
var li = $('<li>', {class: (nav.options !== undefined) ? 'collapsible open' : ''}); |
|
101
|
|
|
var aIcon = $('<a>', { |
|
102
|
|
|
href: '#', |
|
103
|
|
|
class: 'search_icon' |
|
104
|
|
|
}); |
|
105
|
|
|
aIcon.text(title); |
|
106
|
|
|
|
|
107
|
|
|
var ul = $('<ul>'); |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
if (nav.options !== undefined) { |
|
111
|
|
|
// var button = $('<button>', {class: 'collapse'}); |
|
112
|
|
|
// li.append(button); |
|
113
|
|
|
|
|
114
|
|
|
for (var j = 0; j < nav.options.length; j++) { |
|
115
|
|
|
var sub = nav.options[j]; |
|
116
|
|
|
|
|
117
|
|
|
console.log('sub: ' + JSON.stringify(sub)); |
|
118
|
|
|
var subA = $('<a>', { |
|
119
|
|
|
href: '#', |
|
120
|
|
|
text: sub.title |
|
121
|
|
|
}); |
|
122
|
|
|
|
|
123
|
|
|
if (sub.type === 'checkbox') { |
|
124
|
|
|
ul.append($('<li>').append(subA).append($('<input>', { |
|
125
|
|
|
class: 'search_checkbox_sub', |
|
126
|
|
|
type: 'checkbox' |
|
127
|
|
|
}))); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
li.append(aIcon); |
|
133
|
|
|
li.append($('<input>', { |
|
134
|
|
|
class: 'search_checkbox', |
|
135
|
|
|
type: 'checkbox' |
|
136
|
|
|
})); |
|
137
|
|
|
li.append(ul); |
|
138
|
|
|
|
|
139
|
|
|
elements.search_panels.append(li); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
}, |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
initSearch: function (force) { |
|
146
|
|
|
var search = elements.search_input.val(); |
|
147
|
|
|
|
|
148
|
|
|
if (!force && search.length < 3) { |
|
149
|
|
|
return false; |
|
150
|
|
|
} |
|
151
|
|
|
var request = { |
|
152
|
|
|
providers: 'all', |
|
153
|
|
|
search: search, |
|
154
|
|
|
page: curr.page |
|
155
|
|
|
}; |
|
156
|
|
|
|
|
157
|
|
|
fullTextSearch.search(request, this.searchResult); |
|
158
|
|
|
|
|
159
|
|
|
return true; |
|
160
|
|
|
}, |
|
161
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
resetSearch: function () { |
|
164
|
|
|
// if (elements.search_input.val() !== '') { |
|
165
|
|
|
// return; |
|
166
|
|
|
// } |
|
167
|
|
|
}, |
|
168
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
searchResult: function (result) { |
|
171
|
|
|
|
|
172
|
|
|
if (elements.search_json !== null) { |
|
173
|
|
|
elements.search_json.text(JSON.stringify(result)); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
// console.log(JSON.stringify(result)); |
|
177
|
|
|
// OCA.notification.onFail('Search returned no result'); |
|
178
|
|
|
// OCA.notification.onSuccess('Search returned ' + res.meta.size + ' result(s)'); |
|
179
|
|
|
|
|
180
|
|
|
}, |
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
onEntryGenerated: function (entry) { |
|
184
|
|
|
this.deleteEmptyDiv(entry, '#line1'); |
|
185
|
|
|
this.deleteEmptyDiv(entry, '#line2'); |
|
186
|
|
|
}, |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
deleteEmptyDiv: function (entry, divId) { |
|
190
|
|
|
var div = entry.find(divId); |
|
191
|
|
|
if (div.text() === '') { |
|
192
|
|
|
div.remove(); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
}; |
|
196
|
|
|
|
|
197
|
|
|
OCA.FullTextSearch.Example = Navigate; |
|
198
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
$(document).ready(function () { |
|
201
|
|
|
OCA.FullTextSearch.example = new Navigate(); |
|
202
|
|
|
}); |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
|