@@ -133,6 +133,16 @@ function elasticsearch_connector_menu() {
133
133
'type' => MENU_LOCAL_ACTION,
134
134
);
135
135
136
+ $items[$settings_path . '/clusters/%elasticsearch_connector_cluster/indices/%elasticsearch_connector_index/edit'] = array(
137
+ 'title' => 'Elasticsearch cluster indices',
138
+ 'description' => 'Elasticsearch cluster indices',
139
+ 'page callback' => 'drupal_get_form',
140
+ 'page arguments' => array('elasticsearch_connector_cluster_indices_add', 4, 6),
141
+ 'access arguments' => array('adminiser elasticsearch connector'),
142
+ 'load arguments' => array('%map', '%index'),
143
+ 'file' => 'elasticsearch_connector.admin.inc',
144
+ );
145
+
136
146
$items[$settings_path . '/clusters/%elasticsearch_connector_cluster/indices/%elasticsearch_connector_index_valid/aliases'] = array(
137
147
'title' => 'Elasticsearch cluster indices',
138
148
'description' => 'Elasticsearch cluster indices',
@@ -211,6 +221,30 @@ function _elasticsearch_connector_ec_clusters_process($element, &$form_state, $f
211
221
return $element;
212
222
}
213
223
224
+ /**
225
+ * Check if the index is valid and compare it with the indexes comming from Elasticsearch.
226
+ *
227
+ * @param string $index_name
228
+ * @param array $map_array
229
+ * @param int $index
230
+ * @return string|boolean
231
+ */
232
+ function elasticsearch_connector_index_load($index_name, $map_array, $index) {
233
+ if (elasticsearch_connector_index_valid_load($index_name)) {
234
+ $cluster = $map_array[4];
235
+ $client = elasticsearch_connector_load_library($cluster);
236
+ if (!empty($client)) {
237
+ $indices = $client->indices()->stats();
238
+ if (isset($indices['indices'][$index_name])) {
239
+ return $index_name;
240
+ }
241
+ else {
242
+ return FALSE;
243
+ }
244
+ }
245
+ }
246
+ }
247
+
214
248
/**
215
249
* Attach required javascript for the ec_index element.
216
250
* @return array
@@ -290,24 +324,32 @@ function _elasticsearch_connector_ec_index_process($element, &$form_state, $form
290
324
291
325
// TODO: Add icon if the cluster is OK or not.
292
326
293
- $element['cluster_id'] = array(
294
- '#type' => 'select',
295
- '#id' => $element_id . '-cluster-id',
296
- '#title' => t('Select cluster'),
297
- '#required' => $element['#required'],
298
- '#default_value' => isset($element['#default_value'])
299
- && is_array($element['#default_value'])
300
- && isset($element['#default_value']['cluster_id'])
301
- ? $element['#default_value']['cluster_id'] : '',
302
- // TODO: Allow this option to be overwritten and #value if we had such.
303
- '#description' => t('Select the cluster.'),
304
- '#ajax' => array(
305
- 'callback' => '_elasticsearch_connector_ec_index_ajax',
306
- 'wrapper' => $wrapper_id,
307
- 'method' => 'replace',
308
- 'effect' => 'fade',
309
- )
310
- );
327
+ if (empty($element['#cluster_id'])) {
328
+ $element['cluster_id'] = array(
329
+ '#type' => 'select',
330
+ '#id' => $element_id . '-cluster-id',
331
+ '#title' => t('Select cluster'),
332
+ '#required' => $element['#required'],
333
+ '#default_value' => isset($element['#default_value'])
334
+ && is_array($element['#default_value'])
335
+ && isset($element['#default_value']['cluster_id'])
336
+ ? $element['#default_value']['cluster_id'] : '',
337
+ // TODO: Allow this option to be overwritten and #value if we had such.
338
+ '#description' => t('Select the cluster.'),
339
+ '#ajax' => array(
340
+ 'callback' => '_elasticsearch_connector_ec_index_ajax',
341
+ 'wrapper' => $wrapper_id,
342
+ 'method' => 'replace',
343
+ 'effect' => 'fade',
344
+ )
345
+ );
346
+ }
347
+ else {
348
+ $element['cluster_id'] = array(
349
+ '#type' => 'value',
350
+ '#value' => $element['#cluster_id']
351
+ );
352
+ }
311
353
312
354
if (!isset($element['cluster_id']['#current_path'])) {
313
355
$element['cluster_id']['#current_path'] = current_path();
@@ -321,12 +363,13 @@ function _elasticsearch_connector_ec_index_process($element, &$form_state, $form
321
363
}
322
364
323
365
// TODO: We need to handle the incomming tree name if such.
324
- $links = array();
366
+ $links = $manage_indices = array();
325
367
$index_options = array('' => t('Select index'));
326
- if (is_array($element['#value']) && !empty($element['#value']['cluster_id'])) {
368
+ if ((is_array($element['#value']) && !empty($element['#value']['cluster_id'])) || !empty($element['#cluster_id'])) {
369
+ $cluster_id = (is_array($element['#value']) && !empty($element['#value']['cluster_id'])) ? $element['#value']['cluster_id'] : $element['#cluster_id'];
327
370
$index_options = array();
328
371
try {
329
- $index_options = elasticsearch_connector_get_indices_options($element['#value'][' cluster_id'] , TRUE);
372
+ $index_options = elasticsearch_connector_get_indices_options($cluster_id, TRUE);
330
373
}
331
374
catch (Exception $e) {
332
375
if (!empty($element['#throw_exp'])) {
@@ -335,8 +378,35 @@ function _elasticsearch_connector_ec_index_process($element, &$form_state, $form
335
378
}
336
379
$links[] = array(
337
380
'title' => t('Add index'),
338
- 'href' => 'admin/config/elasticsearch-connector/clusters/' . $element['#value']['cluster_id'] . '/indices/add',
339
- 'attributes' => array('target' => '_blank', 'class' => 'ec-index-dialog'),
381
+ 'href' => 'admin/config/elasticsearch-connector/clusters/' .$cluster_id . '/indices/add',
382
+ 'attributes' => array('target' => '_blank', 'class' => 'ec-index-dialog ec-index-dialog-add'),
383
+ 'query' => array(
384
+ 'render' => 'elasticsearch-connector-dialog',
385
+ 'index_element_id' => $element_id . '-index',
386
+ 'cluster_element_id' => $element_id . '-cluster-id'
387
+ )
388
+ );
389
+
390
+ $manage_indices = array(
391
+ 'title' => t('Manage indices'),
392
+ 'href' => 'admin/config/elasticsearch-connector/clusters/' .$cluster_id . '/indices',
393
+ 'attributes' => array('target' => '_blank', 'class' => 'manage-indices'),
394
+ );
395
+ }
396
+
397
+ $index = '';
398
+ if (isset($element['#value']) && is_array($element['#value']) && isset($element['#value']['index'])) {
399
+ $index = $element['#value']['index'];
400
+ }
401
+ elseif (isset($element['#default_value']) && is_array($element['#default_value']) && isset($element['#default_value']['index'])) {
402
+ $index = $element['#default_value']['index'];
403
+ }
404
+
405
+ if (!empty($index)) {
406
+ $links[] = array(
407
+ 'title' => t('Edit @index index', array('@index' => $index)),
408
+ 'href' => 'admin/config/elasticsearch-connector/clusters/' .$cluster_id . '/indices/' . $index . '/edit',
409
+ 'attributes' => array('target' => '_blank', 'class' => 'ec-index-dialog ec-index-dialog-edit'),
340
410
'query' => array(
341
411
'render' => 'elasticsearch-connector-dialog',
342
412
'index_element_id' => $element_id . '-index',
@@ -345,6 +415,10 @@ function _elasticsearch_connector_ec_index_process($element, &$form_state, $form
345
415
);
346
416
}
347
417
418
+ if (!empty($manage_indices)) {
419
+ $links[] = $manage_indices;
420
+ }
421
+
348
422
$element['index'] = array(
349
423
'#type' => 'select',
350
424
'#title' => t('Select index'),
@@ -356,8 +430,14 @@ function _elasticsearch_connector_ec_index_process($element, &$form_state, $form
356
430
? $element['#default_value']['index'] : '',
357
431
'#description' => t('Select the index.'),
358
432
'#options' => $index_options,
433
+ '#ajax' => array(
434
+ 'callback' => '_elasticsearch_connector_ec_index_links_ajax',
435
+ 'wrapper' => $element['#id'] . '-dialog-links',
436
+ 'method' => 'replace',
437
+ 'effect' => 'fade',
438
+ ),
359
439
'#prefix' => '<div id="' . $wrapper_id . '">',
360
- '#suffix' =>'<div class="dialog-links ' . $element['#id'] . '">'
440
+ '#suffix' =>'<div id="' . $element['#id'] . '-dialog-links" class="dialog-links ' . $element['#id'] . '">'
361
441
. theme('links__es_index_links', array(
362
442
'links' => $links,
363
443
'attributes' => array('class' => 'index-dialog-links')
@@ -462,6 +542,14 @@ function _elasticsearch_connector_ec_index_ajax($form, $form_state) {
462
542
return $index_element;
463
543
}
464
544
545
+ function _elasticsearch_connector_ec_index_links_ajax($form, $form_state) {
546
+ $element_name = $form_state['triggering_element']['#name'];
547
+ $parents = $form_state['triggering_element']['#parents'];
548
+ $index_element = drupal_array_get_nested_value($form, $parents);
549
+
550
+ return $index_element['#suffix'];
551
+ }
552
+
465
553
/**
466
554
* Return the main path of the elasticsearch connector module.
467
555
* @return string
0 commit comments