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 loader = { |
---|
19 | |
---|
20 | show : function( element ) |
---|
21 | { |
---|
22 | $( element ) |
---|
23 | .addClass( 'loader' ); |
---|
24 | }, |
---|
25 | |
---|
26 | hide : function( element ) |
---|
27 | { |
---|
28 | $( element ) |
---|
29 | .removeClass( 'loader' ); |
---|
30 | } |
---|
31 | |
---|
32 | }; |
---|
33 | |
---|
34 | Number.prototype.esc = function() |
---|
35 | { |
---|
36 | return new String( this ).esc(); |
---|
37 | } |
---|
38 | |
---|
39 | String.prototype.esc = function() |
---|
40 | { |
---|
41 | return this.replace( /</g, '<' ).replace( />/g, '>' ); |
---|
42 | } |
---|
43 | |
---|
44 | SolrDate = function( date ) |
---|
45 | { |
---|
46 | // ["Sat Mar 03 11:00:00 CET 2012", "Sat", "Mar", "03", "11:00:00", "CET", "2012"] |
---|
47 | var parts = date.match( /^(\w+)\s+(\w+)\s+(\d+)\s+(\d+\:\d+\:\d+)\s+(\w+)\s+(\d+)$/ ); |
---|
48 | |
---|
49 | // "Sat Mar 03 2012 10:37:33" |
---|
50 | return new Date( parts[1] + ' ' + parts[2] + ' ' + parts[3] + ' ' + parts[6] + ' ' + parts[4] ); |
---|
51 | } |
---|
52 | |
---|
53 | var sammy = $.sammy |
---|
54 | ( |
---|
55 | function() |
---|
56 | { |
---|
57 | this.bind |
---|
58 | ( |
---|
59 | 'run', |
---|
60 | function( event, config ) |
---|
61 | { |
---|
62 | if( 0 === config.start_url.length ) |
---|
63 | { |
---|
64 | location.href = '#/'; |
---|
65 | return false; |
---|
66 | } |
---|
67 | } |
---|
68 | ); |
---|
69 | |
---|
70 | this.bind |
---|
71 | ( |
---|
72 | 'error', |
---|
73 | function( message, original_error ) |
---|
74 | { |
---|
75 | alert( original_error.message ); |
---|
76 | } |
---|
77 | ); |
---|
78 | |
---|
79 | // activate_core |
---|
80 | this.before |
---|
81 | ( |
---|
82 | {}, |
---|
83 | function( context ) |
---|
84 | { |
---|
85 | if( app.timeout ) |
---|
86 | { |
---|
87 | console.debug( 'Clearing Timeout #' + app.timeout ); |
---|
88 | clearTimeout( app.timeout ); |
---|
89 | } |
---|
90 | |
---|
91 | var menu_wrapper = $( '#menu-wrapper' ); |
---|
92 | |
---|
93 | $( 'li[id].active', menu_wrapper ) |
---|
94 | .removeClass( 'active' ); |
---|
95 | |
---|
96 | $( 'li.active', menu_wrapper ) |
---|
97 | .removeClass( 'active' ); |
---|
98 | |
---|
99 | if( this.params.splat ) |
---|
100 | { |
---|
101 | var selector = '~' === this.params.splat[0][0] |
---|
102 | ? '#' + this.params.splat[0].replace( /^~/, '' ) + '.global' |
---|
103 | : '#menu-selector #' + this.params.splat[0]; |
---|
104 | |
---|
105 | var active_element = $( selector, menu_wrapper ); |
---|
106 | |
---|
107 | if( 0 === active_element.size() ) |
---|
108 | { |
---|
109 | this.app.error( 'There exists no core with name "' + this.params.splat[0] + '"' ); |
---|
110 | return false; |
---|
111 | } |
---|
112 | |
---|
113 | active_element |
---|
114 | .addClass( 'active' ); |
---|
115 | |
---|
116 | if( this.params.splat[1] ) |
---|
117 | { |
---|
118 | $( '.' + this.params.splat[1], active_element ) |
---|
119 | .addClass( 'active' ); |
---|
120 | } |
---|
121 | |
---|
122 | if( !active_element.hasClass( 'global' ) ) |
---|
123 | { |
---|
124 | this.active_core = active_element; |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | ); |
---|
129 | } |
---|
130 | ); |
---|
131 | |
---|
132 | var solr_admin = function( app_config ) |
---|
133 | { |
---|
134 | self = this, |
---|
135 | |
---|
136 | menu_element = null, |
---|
137 | |
---|
138 | is_multicore = null, |
---|
139 | cores_data = null, |
---|
140 | active_core = null, |
---|
141 | environment_basepath = null, |
---|
142 | |
---|
143 | config = app_config, |
---|
144 | params = null, |
---|
145 | dashboard_values = null, |
---|
146 | schema_browser_data = null, |
---|
147 | |
---|
148 | plugin_data = null, |
---|
149 | |
---|
150 | this.menu_element = $( '#menu-selector' ); |
---|
151 | this.config = config; |
---|
152 | |
---|
153 | this.timeout = null; |
---|
154 | |
---|
155 | this.run = function() |
---|
156 | { |
---|
157 | $.ajax |
---|
158 | ( |
---|
159 | { |
---|
160 | url : config.solr_path + config.core_admin_path + '?wt=json', |
---|
161 | dataType : 'json', |
---|
162 | beforeSend : function( arr, form, options ) |
---|
163 | { |
---|
164 | $( '#content' ) |
---|
165 | .html( '<div id="index"><div class="loader">Loading ...</div></div>' ); |
---|
166 | }, |
---|
167 | success : function( response ) |
---|
168 | { |
---|
169 | self.cores_data = response.status; |
---|
170 | |
---|
171 | for( var core_name in response.status ) |
---|
172 | { |
---|
173 | var core_path = config.solr_path + '/' + core_name; |
---|
174 | var schema = response['status'][core_name]['schema']; |
---|
175 | var solrconfig = response['status'][core_name]['config']; |
---|
176 | var classes = []; |
---|
177 | |
---|
178 | if( !environment_basepath ) |
---|
179 | { |
---|
180 | environment_basepath = core_path; |
---|
181 | } |
---|
182 | |
---|
183 | if( response['status'][core_name]['isDefaultCore'] ) |
---|
184 | { |
---|
185 | classes.push( 'default' ); |
---|
186 | } |
---|
187 | |
---|
188 | var core_tpl = '<li id="' + core_name + '" ' |
---|
189 | + ' class="' + classes.join( ' ' ) + '"' |
---|
190 | + ' data-basepath="' + core_path + '"' |
---|
191 | + ' schema="' + schema + '"' |
---|
192 | + ' config="' + solrconfig + '"' |
---|
193 | + '>' + "\n" |
---|
194 | + ' <p><a href="#/' + core_name + '">' + core_name + '</a></p>' + "\n" |
---|
195 | + ' <ul>' + "\n" |
---|
196 | |
---|
197 | + ' <li class="ping"><a rel="' + core_path + '/admin/ping"><span>Ping</span></a></li>' + "\n" |
---|
198 | + ' <li class="query"><a href="#/' + core_name + '/query"><span>Query</span></a></li>' + "\n" |
---|
199 | + ' <li class="schema"><a href="#/' + core_name + '/schema"><span>Schema</span></a></li>' + "\n" |
---|
200 | + ' <li class="config"><a href="#/' + core_name + '/config"><span>Config</span></a></li>' + "\n" |
---|
201 | + ' <li class="replication"><a href="#/' + core_name + '/replication"><span>Replication</span></a></li>' + "\n" |
---|
202 | + ' <li class="analysis"><a href="#/' + core_name + '/analysis"><span>Analysis</span></a></li>' + "\n" |
---|
203 | + ' <li class="schema-browser"><a href="#/' + core_name + '/schema-browser"><span>Schema Browser</span></a></li>' + "\n" |
---|
204 | + ' <li class="plugins"><a href="#/' + core_name + '/plugins"><span>Plugins / Stats</span></a></li>' + "\n" |
---|
205 | + ' <li class="dataimport"><a href="#/' + core_name + '/dataimport"><span>Dataimport</span></a></li>' + "\n" |
---|
206 | |
---|
207 | + ' </ul>' + "\n" |
---|
208 | + '</li>'; |
---|
209 | |
---|
210 | self.menu_element |
---|
211 | .append( core_tpl ); |
---|
212 | } |
---|
213 | |
---|
214 | $.ajax |
---|
215 | ( |
---|
216 | { |
---|
217 | url : environment_basepath + '/admin/system?wt=json', |
---|
218 | dataType : 'json', |
---|
219 | beforeSend : function( arr, form, options ) |
---|
220 | { |
---|
221 | }, |
---|
222 | success : function( response ) |
---|
223 | { |
---|
224 | self.dashboard_values = response; |
---|
225 | |
---|
226 | var environment_args = null; |
---|
227 | var cloud_args = null; |
---|
228 | |
---|
229 | if( response.jvm && response.jvm.jmx && response.jvm.jmx.commandLineArgs ) |
---|
230 | { |
---|
231 | var command_line_args = response.jvm.jmx.commandLineArgs.join( ' | ' ); |
---|
232 | |
---|
233 | environment_args = command_line_args.match( /-Dsolr.environment=((dev|test|prod)?[\w\d]*)/i ); |
---|
234 | cloud_args = command_line_args.match( /-Dzk/i ); |
---|
235 | } |
---|
236 | |
---|
237 | // title |
---|
238 | |
---|
239 | $( 'title', document ) |
---|
240 | .append( ' (' + response.core.host + ')' ); |
---|
241 | |
---|
242 | // environment |
---|
243 | |
---|
244 | var environment_element = $( '#environment' ); |
---|
245 | if( environment_args ) |
---|
246 | { |
---|
247 | environment_element |
---|
248 | .show(); |
---|
249 | |
---|
250 | if( environment_args[1] ) |
---|
251 | { |
---|
252 | environment_element |
---|
253 | .html( environment_args[1] ); |
---|
254 | } |
---|
255 | |
---|
256 | if( environment_args[2] ) |
---|
257 | { |
---|
258 | environment_element |
---|
259 | .addClass( environment_args[2] ); |
---|
260 | } |
---|
261 | } |
---|
262 | else |
---|
263 | { |
---|
264 | environment_element |
---|
265 | .remove(); |
---|
266 | } |
---|
267 | |
---|
268 | // cloud |
---|
269 | |
---|
270 | var cloud_nav_element = $( '#menu #cloud' ); |
---|
271 | if( cloud_args ) |
---|
272 | { |
---|
273 | cloud_nav_element |
---|
274 | .show(); |
---|
275 | } |
---|
276 | |
---|
277 | // sammy |
---|
278 | |
---|
279 | sammy.run( location.hash ); |
---|
280 | }, |
---|
281 | error : function() |
---|
282 | { |
---|
283 | var main = $( '#main' ); |
---|
284 | |
---|
285 | $( 'div[id$="-wrapper"]', main ) |
---|
286 | .remove(); |
---|
287 | |
---|
288 | main |
---|
289 | .addClass( 'error' ) |
---|
290 | .append |
---|
291 | ( |
---|
292 | '<div class="message">This interface requires that you activate the admin request handlers, add the following configuration to your <code>solrconfig.xml:</code></div>' + |
---|
293 | '<div class="code"><pre class="syntax language-xml"><code>' + |
---|
294 | '<!-- Admin Handlers - This will register all the standard admin RequestHandlers. -->'.esc() + "\n" + |
---|
295 | '<requestHandler name="/admin/" class="solr.admin.AdminHandlers" />'.esc() + |
---|
296 | '</code></pre></div>' |
---|
297 | ); |
---|
298 | |
---|
299 | hljs.highlightBlock( $( 'pre', main ).get(0) ); |
---|
300 | }, |
---|
301 | complete : function() |
---|
302 | { |
---|
303 | loader.hide( this ); |
---|
304 | } |
---|
305 | } |
---|
306 | ); |
---|
307 | }, |
---|
308 | error : function() |
---|
309 | { |
---|
310 | }, |
---|
311 | complete : function() |
---|
312 | { |
---|
313 | } |
---|
314 | } |
---|
315 | ); |
---|
316 | } |
---|
317 | |
---|
318 | }; |
---|
319 | |
---|
320 | var app = new solr_admin( app_config ); |
---|