1 | /* |
---|
2 | Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | contributor license agreements. See the NOTICE file distributed with |
---|
4 | this work for additional information regarding copyright ownership. |
---|
5 | The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | (the "License"); you may not use this file except in compliance with |
---|
7 | the License. You may obtain a copy of the License at |
---|
8 | |
---|
9 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | |
---|
11 | Unless required by applicable law or agreed to in writing, software |
---|
12 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | See the License for the specific language governing permissions and |
---|
15 | limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | var set_healthcheck_status = function( status ) |
---|
19 | { |
---|
20 | var hc_button = $( '.healthcheck-status' ) |
---|
21 | if ( status == 'enable' ) |
---|
22 | { |
---|
23 | hc_button.parents( 'dd' ) |
---|
24 | .removeClass( 'ico-0' ) |
---|
25 | .addClass( 'ico-1' ); |
---|
26 | hc_button |
---|
27 | .addClass( 'enabled' ) |
---|
28 | .html( 'disable ping' ); |
---|
29 | } else { |
---|
30 | hc_button.parents( 'dd' ) |
---|
31 | .removeClass( 'ico-1') |
---|
32 | .addClass( 'ico-0' ); |
---|
33 | hc_button |
---|
34 | .removeClass( 'enabled' ) |
---|
35 | .html( 'enable ping' ); |
---|
36 | } |
---|
37 | }; |
---|
38 | |
---|
39 | // #/:core |
---|
40 | sammy.get |
---|
41 | ( |
---|
42 | /^#\/([\w\d-]+)$/, |
---|
43 | function( context ) |
---|
44 | { |
---|
45 | var core_basepath = this.active_core.attr( 'data-basepath' ); |
---|
46 | var content_element = $( '#content' ); |
---|
47 | |
---|
48 | content_element |
---|
49 | .removeClass( 'single' ); |
---|
50 | |
---|
51 | var core_menu = this.active_core.closest( 'ul' ); |
---|
52 | if( !core_menu.data( 'admin-extra-loaded' ) ) |
---|
53 | { |
---|
54 | core_menu.data( 'admin-extra-loaded', new Date() ); |
---|
55 | |
---|
56 | $.get |
---|
57 | ( |
---|
58 | core_basepath + '/admin/file/?file=admin-extra.menu-top.html', |
---|
59 | function( menu_extra ) |
---|
60 | { |
---|
61 | core_menu |
---|
62 | .prepend( menu_extra ); |
---|
63 | } |
---|
64 | ); |
---|
65 | |
---|
66 | $.get |
---|
67 | ( |
---|
68 | core_basepath + '/admin/file/?file=admin-extra.menu-bottom.html', |
---|
69 | function( menu_extra ) |
---|
70 | { |
---|
71 | core_menu |
---|
72 | .append( menu_extra ); |
---|
73 | } |
---|
74 | ); |
---|
75 | } |
---|
76 | |
---|
77 | $.get |
---|
78 | ( |
---|
79 | 'tpl/dashboard.html', |
---|
80 | function( template ) |
---|
81 | { |
---|
82 | content_element |
---|
83 | .html( template ); |
---|
84 | |
---|
85 | var dashboard_element = $( '#dashboard' ); |
---|
86 | |
---|
87 | $.ajax |
---|
88 | ( |
---|
89 | { |
---|
90 | url : core_basepath + '/admin/luke?wt=json&show=index&numTerms=0', |
---|
91 | dataType : 'json', |
---|
92 | context : $( '#statistics', dashboard_element ), |
---|
93 | beforeSend : function( xhr, settings ) |
---|
94 | { |
---|
95 | $( 'h2', this ) |
---|
96 | .addClass( 'loader' ); |
---|
97 | |
---|
98 | $( '.message', this ) |
---|
99 | .show() |
---|
100 | .html( 'Loading ...' ); |
---|
101 | |
---|
102 | $( '.content' ) |
---|
103 | .hide(); |
---|
104 | }, |
---|
105 | success : function( response, text_status, xhr ) |
---|
106 | { |
---|
107 | $( '.message', this ) |
---|
108 | .empty() |
---|
109 | .hide(); |
---|
110 | |
---|
111 | $( '.content', this ) |
---|
112 | .show(); |
---|
113 | |
---|
114 | var data = { |
---|
115 | 'index_num-docs' : response['index']['numDocs'], |
---|
116 | 'index_max-doc' : response['index']['maxDoc'], |
---|
117 | 'index_version' : response['index']['version'], |
---|
118 | 'index_segmentCount' : response['index']['segmentCount'], |
---|
119 | 'index_last-modified' : response['index']['lastModified'] |
---|
120 | }; |
---|
121 | |
---|
122 | for( var key in data ) |
---|
123 | { |
---|
124 | $( '.' + key, this ) |
---|
125 | .show(); |
---|
126 | |
---|
127 | $( '.value.' + key, this ) |
---|
128 | .html( data[key] ); |
---|
129 | } |
---|
130 | |
---|
131 | var optimized_element = $( '.value.index_optimized', this ); |
---|
132 | if( !response['index']['hasDeletions'] ) |
---|
133 | { |
---|
134 | optimized_element |
---|
135 | .addClass( 'ico-1' ); |
---|
136 | |
---|
137 | $( 'span', optimized_element ) |
---|
138 | .html( 'yes' ); |
---|
139 | } |
---|
140 | else |
---|
141 | { |
---|
142 | optimized_element |
---|
143 | .addClass( 'ico-0' ); |
---|
144 | |
---|
145 | $( 'span', optimized_element ) |
---|
146 | .html( 'no' ); |
---|
147 | } |
---|
148 | |
---|
149 | var current_element = $( '.value.index_current', this ); |
---|
150 | if( response['index']['current'] ) |
---|
151 | { |
---|
152 | current_element |
---|
153 | .addClass( 'ico-1' ); |
---|
154 | |
---|
155 | $( 'span', current_element ) |
---|
156 | .html( 'yes' ); |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | current_element |
---|
161 | .addClass( 'ico-0' ); |
---|
162 | |
---|
163 | $( 'span', current_element ) |
---|
164 | .html( 'no' ); |
---|
165 | } |
---|
166 | |
---|
167 | $( 'a', optimized_element ) |
---|
168 | .die( 'click' ) |
---|
169 | .live |
---|
170 | ( |
---|
171 | 'click', |
---|
172 | function( event ) |
---|
173 | { |
---|
174 | $.ajax |
---|
175 | ( |
---|
176 | { |
---|
177 | url : core_basepath + '/update?optimize=true&waitFlush=true&wt=json', |
---|
178 | dataType : 'json', |
---|
179 | context : $( this ), |
---|
180 | beforeSend : function( xhr, settings ) |
---|
181 | { |
---|
182 | this |
---|
183 | .addClass( 'loader' ); |
---|
184 | }, |
---|
185 | success : function( response, text_status, xhr ) |
---|
186 | { |
---|
187 | this.parents( 'dd' ) |
---|
188 | .removeClass( 'ico-0' ) |
---|
189 | .addClass( 'ico-1' ); |
---|
190 | }, |
---|
191 | error : function( xhr, text_status, error_thrown) |
---|
192 | { |
---|
193 | console.warn( 'd0h, optimize broken!' ); |
---|
194 | }, |
---|
195 | complete : function( xhr, text_status ) |
---|
196 | { |
---|
197 | this |
---|
198 | .removeClass( 'loader' ); |
---|
199 | } |
---|
200 | } |
---|
201 | ); |
---|
202 | } |
---|
203 | ); |
---|
204 | |
---|
205 | $( '.timeago', this ) |
---|
206 | .timeago(); |
---|
207 | }, |
---|
208 | error : function( xhr, text_status, error_thrown ) |
---|
209 | { |
---|
210 | this |
---|
211 | .addClass( 'disabled' ); |
---|
212 | |
---|
213 | $( '.message', this ) |
---|
214 | .show() |
---|
215 | .html( 'Luke is not configured' ); |
---|
216 | }, |
---|
217 | complete : function( xhr, text_status ) |
---|
218 | { |
---|
219 | $( 'h2', this ) |
---|
220 | .removeClass( 'loader' ); |
---|
221 | } |
---|
222 | } |
---|
223 | ); |
---|
224 | |
---|
225 | $.ajax |
---|
226 | ( |
---|
227 | { |
---|
228 | url : core_basepath + '/replication?command=details&wt=json', |
---|
229 | dataType : 'json', |
---|
230 | context : $( '#replication', dashboard_element ), |
---|
231 | beforeSend : function( xhr, settings ) |
---|
232 | { |
---|
233 | $( 'h2', this ) |
---|
234 | .addClass( 'loader' ); |
---|
235 | |
---|
236 | $( '.message', this ) |
---|
237 | .show() |
---|
238 | .html( 'Loading' ); |
---|
239 | |
---|
240 | $( '.content', this ) |
---|
241 | .hide(); |
---|
242 | }, |
---|
243 | success : function( response, text_status, xhr ) |
---|
244 | { |
---|
245 | $( '.message', this ) |
---|
246 | .empty() |
---|
247 | .hide(); |
---|
248 | |
---|
249 | $( '.content', this ) |
---|
250 | .show(); |
---|
251 | |
---|
252 | $( '.replication', context.active_core ) |
---|
253 | .show(); |
---|
254 | |
---|
255 | var data = response.details; |
---|
256 | var is_slave = 'undefined' !== typeof( data.slave ); |
---|
257 | var headline = $( 'h2 span', this ); |
---|
258 | var details_element = $( '#details', this ); |
---|
259 | var current_type_element = $( ( is_slave ? '.slave' : '.master' ), this ); |
---|
260 | |
---|
261 | if( is_slave ) |
---|
262 | { |
---|
263 | this |
---|
264 | .addClass( 'slave' ); |
---|
265 | |
---|
266 | headline |
---|
267 | .html( headline.html() + ' (Slave)' ); |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | this |
---|
272 | .addClass( 'master' ); |
---|
273 | |
---|
274 | headline |
---|
275 | .html( headline.html() + ' (Master)' ); |
---|
276 | } |
---|
277 | |
---|
278 | $( '.version div', current_type_element ) |
---|
279 | .html( data.indexVersion ); |
---|
280 | $( '.generation div', current_type_element ) |
---|
281 | .html( data.generation ); |
---|
282 | $( '.size div', current_type_element ) |
---|
283 | .html( data.indexSize ); |
---|
284 | |
---|
285 | if( is_slave ) |
---|
286 | { |
---|
287 | var master_element = $( '.master', details_element ); |
---|
288 | $( '.version div', master_element ) |
---|
289 | .html( data.slave.masterDetails.indexVersion ); |
---|
290 | $( '.generation div', master_element ) |
---|
291 | .html( data.slave.masterDetails.generation ); |
---|
292 | $( '.size div', master_element ) |
---|
293 | .html( data.slave.masterDetails.indexSize ); |
---|
294 | |
---|
295 | if( data.indexVersion !== data.slave.masterDetails.indexVersion ) |
---|
296 | { |
---|
297 | $( '.version', details_element ) |
---|
298 | .addClass( 'diff' ); |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | $( '.version', details_element ) |
---|
303 | .removeClass( 'diff' ); |
---|
304 | } |
---|
305 | |
---|
306 | if( data.generation !== data.slave.masterDetails.generation ) |
---|
307 | { |
---|
308 | $( '.generation', details_element ) |
---|
309 | .addClass( 'diff' ); |
---|
310 | } |
---|
311 | else |
---|
312 | { |
---|
313 | $( '.generation', details_element ) |
---|
314 | .removeClass( 'diff' ); |
---|
315 | } |
---|
316 | } |
---|
317 | }, |
---|
318 | error : function( xhr, text_status, error_thrown) |
---|
319 | { |
---|
320 | this |
---|
321 | .addClass( 'disabled' ); |
---|
322 | |
---|
323 | $( '.message', this ) |
---|
324 | .show() |
---|
325 | .html( 'Replication is not configured' ); |
---|
326 | }, |
---|
327 | complete : function( xhr, text_status ) |
---|
328 | { |
---|
329 | $( 'h2', this ) |
---|
330 | .removeClass( 'loader' ); |
---|
331 | } |
---|
332 | } |
---|
333 | ); |
---|
334 | |
---|
335 | $.ajax |
---|
336 | ( |
---|
337 | { |
---|
338 | url : core_basepath + '/dataimport?command=details&wt=json', |
---|
339 | dataType : 'json', |
---|
340 | context : $( '#dataimport', dashboard_element ), |
---|
341 | beforeSend : function( xhr, settings ) |
---|
342 | { |
---|
343 | $( 'h2', this ) |
---|
344 | .addClass( 'loader' ); |
---|
345 | |
---|
346 | $( '.message', this ) |
---|
347 | .show() |
---|
348 | .html( 'Loading' ); |
---|
349 | }, |
---|
350 | success : function( response, text_status, xhr ) |
---|
351 | { |
---|
352 | $( '.message', this ) |
---|
353 | .empty() |
---|
354 | .hide(); |
---|
355 | |
---|
356 | $( 'dl', this ) |
---|
357 | .show(); |
---|
358 | |
---|
359 | var data = { |
---|
360 | 'status' : response['status'], |
---|
361 | 'info' : response['statusMessages'][''] |
---|
362 | }; |
---|
363 | |
---|
364 | for( var key in data ) |
---|
365 | { |
---|
366 | $( '.' + key, this ) |
---|
367 | .show(); |
---|
368 | |
---|
369 | $( '.value.' + key, this ) |
---|
370 | .html( data[key] ); |
---|
371 | } |
---|
372 | }, |
---|
373 | error : function( xhr, text_status, error_thrown) |
---|
374 | { |
---|
375 | this |
---|
376 | .addClass( 'disabled' ); |
---|
377 | |
---|
378 | $( '.message', this ) |
---|
379 | .show() |
---|
380 | .html( 'Dataimport is not configured' ); |
---|
381 | }, |
---|
382 | complete : function( xhr, text_status ) |
---|
383 | { |
---|
384 | $( 'h2', this ) |
---|
385 | .removeClass( 'loader' ); |
---|
386 | } |
---|
387 | } |
---|
388 | ); |
---|
389 | |
---|
390 | $.ajax |
---|
391 | ( |
---|
392 | { |
---|
393 | url : core_basepath + '/admin/file/?file=admin-extra.html', |
---|
394 | dataType : 'html', |
---|
395 | context : $( '#admin-extra', dashboard_element ), |
---|
396 | beforeSend : function( xhr, settings ) |
---|
397 | { |
---|
398 | $( 'h2', this ) |
---|
399 | .addClass( 'loader' ); |
---|
400 | |
---|
401 | $( '.message', this ) |
---|
402 | .show() |
---|
403 | .html( 'Loading' ); |
---|
404 | |
---|
405 | $( '.content', this ) |
---|
406 | .hide(); |
---|
407 | }, |
---|
408 | success : function( response, text_status, xhr ) |
---|
409 | { |
---|
410 | $( '.message', this ) |
---|
411 | .hide() |
---|
412 | .empty(); |
---|
413 | |
---|
414 | $( '.content', this ) |
---|
415 | .show() |
---|
416 | .html( response ); |
---|
417 | }, |
---|
418 | error : function( xhr, text_status, error_thrown) |
---|
419 | { |
---|
420 | this |
---|
421 | .addClass( 'disabled' ); |
---|
422 | |
---|
423 | $( '.message', this ) |
---|
424 | .show() |
---|
425 | .html( 'We found no "admin-extra.html" file.' ); |
---|
426 | }, |
---|
427 | complete : function( xhr, text_status ) |
---|
428 | { |
---|
429 | $( 'h2', this ) |
---|
430 | .removeClass( 'loader' ); |
---|
431 | } |
---|
432 | } |
---|
433 | ); |
---|
434 | |
---|
435 | $.ajax |
---|
436 | ( |
---|
437 | { |
---|
438 | url : core_basepath + '/admin/ping?action=status&wt=json', |
---|
439 | dataType : 'json', |
---|
440 | context : $( '#healthcheck', dashboard_element ), |
---|
441 | beforeSend : function( xhr, settings ) |
---|
442 | { |
---|
443 | $( 'h2', this ) |
---|
444 | .addClass( 'loader' ); |
---|
445 | |
---|
446 | $( '.message', this ) |
---|
447 | .show() |
---|
448 | .html( 'Loading' ); |
---|
449 | |
---|
450 | $( '.content', this ) |
---|
451 | .hide(); |
---|
452 | }, |
---|
453 | success : function( response, text_status, xhr ) |
---|
454 | { |
---|
455 | $( '.message', this ) |
---|
456 | .empty() |
---|
457 | .hide(); |
---|
458 | |
---|
459 | $( '.content', this ) |
---|
460 | .show(); |
---|
461 | |
---|
462 | var status_element = $( '.value.status', this ); |
---|
463 | var toggle_button = $( '.healthcheck-status', this ); |
---|
464 | var status = response['status']; |
---|
465 | $( 'span', status_element ).html( status ); |
---|
466 | |
---|
467 | var action = ( response['status'] == 'enabled' ) ? 'enable' : 'disable'; |
---|
468 | set_healthcheck_status(action); |
---|
469 | |
---|
470 | if( response['status'] == 'enabled' ) |
---|
471 | { |
---|
472 | status_element |
---|
473 | .addClass( 'ico-1' ); |
---|
474 | toggle_button |
---|
475 | .addClass( 'enabled' ); |
---|
476 | } |
---|
477 | else |
---|
478 | { |
---|
479 | status_element |
---|
480 | .addClass( 'ico-0' ); |
---|
481 | } |
---|
482 | |
---|
483 | $( '.healthcheck-status', status_element ) |
---|
484 | .die( 'click' ) |
---|
485 | .live |
---|
486 | ( |
---|
487 | 'click', |
---|
488 | function( event ) |
---|
489 | { |
---|
490 | var action = $(this).hasClass( 'enabled' ) ? 'disable' : 'enable'; |
---|
491 | $.ajax |
---|
492 | ( |
---|
493 | { |
---|
494 | url : core_basepath + '/admin/ping?action=' + action + '&wt=json', |
---|
495 | dataType : 'json', |
---|
496 | context : $( this ), |
---|
497 | beforeSend : function( xhr, settings ) |
---|
498 | { |
---|
499 | this |
---|
500 | .addClass( 'loader' ); |
---|
501 | }, |
---|
502 | success : function( response, text_status, xhr ) |
---|
503 | { |
---|
504 | set_healthcheck_status(action); |
---|
505 | }, |
---|
506 | error : function( xhr, text_status, error_thrown) |
---|
507 | { |
---|
508 | console.warn( 'd0h, enable broken!' ); |
---|
509 | }, |
---|
510 | complete : function( xhr, text_status ) |
---|
511 | { |
---|
512 | this |
---|
513 | .removeClass( 'loader' ); |
---|
514 | } |
---|
515 | } |
---|
516 | ); |
---|
517 | } |
---|
518 | ); |
---|
519 | }, |
---|
520 | error : function( xhr, text_status, error_thrown) |
---|
521 | { |
---|
522 | this |
---|
523 | .addClass( 'disabled' ); |
---|
524 | |
---|
525 | $( '.message', this ) |
---|
526 | .show() |
---|
527 | .html( 'Ping request handler is not configured with a healthcheck file.' ); |
---|
528 | }, |
---|
529 | complete : function( xhr, text_status ) |
---|
530 | { |
---|
531 | $( 'h2', this ) |
---|
532 | .removeClass( 'loader' ); |
---|
533 | } |
---|
534 | } |
---|
535 | ); |
---|
536 | |
---|
537 | } |
---|
538 | ); |
---|
539 | } |
---|
540 | ); |
---|