Merge branch 'ent-12571-arreglar-interfaz-de-definicion-de-graficas-combinadas' into 'develop'

Ent 12571 Arreglar interfaz de definicion de graficas combinadas

See merge request artica/pandorafms!6767
This commit is contained in:
Diego Muñoz-Reja 2024-01-18 11:32:59 +00:00
commit d1855569dc
6 changed files with 237 additions and 159 deletions

View File

@ -30,7 +30,7 @@ if (!$report_w && !$report_m) {
require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_modules.php';
require_once $config['homedir'].'/include/functions_groups.php';
ui_require_css_file('custom_graph');
$editGraph = (bool) get_parameter('edit_graph', 0);
$action = get_parameter('action', '');
@ -41,113 +41,6 @@ if (isset($_GET['get_agent'])) {
}
}
switch ($action) {
case 'sort_items':
$resultOperationDB = null;
$position_to_sort = (int) get_parameter('position_to_sort', 1);
$ids_serialize = (string) get_parameter('ids_items_to_sort', '');
$move_to = (string) get_parameter('move_to', 'after');
$countItems = db_get_sql(
'
SELECT COUNT(id_gs)
FROM tgraph_source
WHERE id_graph = '.$id_graph
);
if (($countItems < $position_to_sort) || ($position_to_sort < 1)) {
$resultOperationDB = false;
} else if (!empty($ids_serialize)) {
$ids = explode('|', $ids_serialize);
$items = db_get_all_rows_sql(
'SELECT id_gs, `field_order`
FROM tgraph_source
WHERE id_graph = '.$id_graph.'
ORDER BY `field_order`'
);
if ($items === false) {
$items = [];
}
// Clean the repeated order values.
$order_temp = 1;
foreach ($items as $item) {
db_process_sql_update(
'tgraph_source',
['`field_order`' => $order_temp],
['id_gs' => $item['id_rc']]
);
$order_temp++;
}
$items = db_get_all_rows_sql(
'SELECT id_gs, `field_order`
FROM tgraph_source
WHERE id_graph = '.$id_graph.'
ORDER BY `field_order`'
);
if ($items === false) {
$items = [];
}
$temp = [];
$temp = [];
foreach ($items as $item) {
// Remove the contents from the block to sort.
if (array_search($item['id_gs'], $ids) === false) {
$temp[$item['field_order']] = $item['id_gs'];
}
}
$items = $temp;
$sorted_items = [];
foreach ($items as $pos => $id_unsort) {
if ($pos == $position_to_sort) {
if ($move_to == 'after') {
$sorted_items[] = $id_unsort;
}
foreach ($ids as $id) {
$sorted_items[] = $id;
}
if ($move_to != 'after') {
$sorted_items[] = $id_unsort;
}
} else {
$sorted_items[] = $id_unsort;
}
}
$items = $sorted_items;
foreach ($items as $order => $id) {
db_process_sql_update(
'tgraph_source',
['`field_order`' => ($order + 1)],
['id_gs' => $id]
);
}
$resultOperationDB = true;
} else {
$resultOperationDB = false;
}
break;
}
if ($editGraph) {
$graphRows = db_get_all_rows_sql(
'SELECT t1.*,
@ -257,41 +150,6 @@ $table->data[0][1] = html_print_label_input_block(
);
$SortItems = "<form action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&tab=graph_editor&edit_graph=1&id=".$id_graph."' method='post' onsubmit='return added_ids_sorted_items_to_hidden_input();'>";
$SortItems .= html_print_table($table, true);
$SortItems .= html_print_input_hidden('action', 'sort_items', true);
$SortItems .= html_print_div(
[
'class' => 'action-buttons',
'content' => html_print_submit_button(
__('Sort'),
'srcbutton',
false,
[
'class' => 'mini',
'icon' => 'search',
'mode' => 'secondary',
],
true
),
],
true
);
$SortItems .= '</form>';
ui_toggle(
$SortItems,
'<span class="subsection_header_title">'.__('Sort items').'</span>',
'',
'',
false,
false,
'',
'white-box-content no_border',
'filter-datatable-main box-flat white_table_graph max_floating_element_size'
);
// Configuration form.
echo '<span id ="none_text" class="invisible">'.__('None').'</span>';
echo "<form id='agentmodules' method='post' action='index.php?sec=reporting&sec2=godmode/reporting/graph_builder&tab=graph_editor&add_module=1&edit_graph=1&id=".$id_graph."'>";
@ -300,10 +158,11 @@ echo "<table width='100%' cellpadding='4' cellpadding='4' class='databox filters
echo '<tr>';
echo '<td class="w50p pdd_50px" id="select_multiple_modules_filtered">'.html_print_input(
[
'type' => 'select_multiple_modules_filtered',
'uniqId' => 'modules',
'class' => 'flex flex-row',
'searchBar' => true,
'type' => 'select_multiple_modules_filtered',
'uniqId' => 'modules',
'class' => 'flex flex-row',
'searchBar' => false,
'placeholderAgents' => __('Search agent name'),
]
).'</td>';
echo '</tr><tr>';
@ -340,6 +199,7 @@ echo '</form>';
// Modules table.
if ($count_module_array > 0) {
echo "<table width='100%' cellpadding=4 cellpadding=4 class='databox filters info_table'>";
echo '<thead>';
echo '<tr>
<th>'.__('P.').'</th>
<th>'.__('Agent').'</th>
@ -348,6 +208,8 @@ if ($count_module_array > 0) {
<th>'.__('Weight').'</th>
<th>'.__('Delete').'</th>
<th>'.__('Sort').'</th>';
echo '</thead>';
echo '<tbody>';
$color = 0;
for ($a = 0; $a < $count_module_array; $a++) {
// Calculate table line color.
@ -359,7 +221,7 @@ if ($count_module_array > 0) {
$color = 1;
}
echo "<tr><td class='$tdcolor'>$position_array[$a]</td>";
echo "<tr><td class='position $tdcolor'>$position_array[$a]</td>";
echo "<td class='$tdcolor'>".$agent_array[$a].'</td>';
echo "<td class='$tdcolor'>";
echo modules_get_agentmodule_name($module_array[$a]).'</td>';
@ -410,9 +272,30 @@ if ($count_module_array > 0) {
echo '</td>';
echo '<td>';
echo '<td style="display: grid;">';
echo html_print_checkbox_extended('sorted_items[]', $idgs_array[$a], false, false, '', 'class="selected_check"', true);
echo html_print_input_image(
'up',
'images/arrow-up-white.png',
'up',
($config['style'] !== 'pandora_black') ? 'filter: invert(100%)' : '',
true,
[
'class' => 'invert_filter main_menu_icon',
'onclick' => 'reorder(\'up\', \''.$idgs_array[$a].'\', this)',
],
);
echo html_print_input_image(
'down',
'images/arrow-down-white.png',
'down',
($config['style'] !== 'pandora_black') ? 'filter: invert(100%)' : '',
true,
[
'class' => 'invert_filter main_menu_icon',
'onclick' => 'reorder(\'down\', \''.$idgs_array[$a].'\', this)',
]
);
echo '</td>';
@ -420,6 +303,8 @@ if ($count_module_array > 0) {
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}
@ -482,4 +367,65 @@ function added_ids_sorted_items_to_hidden_input() {
return true;
}
}
function reorder(action, idElement, element) {
var tr = $(element).parent().parent();
switch (action) {
case "up":
changePosition(action, idElement)
.then((data) => {
if(data.success) {
$(tr).find('.position').html(parseInt($(tr).find('.position').html()) - 1);
$($(tr).prev()).find('.position').html(parseInt($($(tr).prev()).find('.position').html()) + 1);
$(tr).prev().insertAfter(tr);
}
})
.catch((err) => {
console.log(err);
})
break;
case "down":
changePosition(action, idElement)
.then((data) => {
if(data.success) {
$(tr).find('.position').html(parseInt($(tr).find('.position').html()) + 1);
$($(tr).next()).find('.position').html(parseInt(($(tr).next()).find('.position').html()) - 1);
$(tr).next().insertBefore(tr);
}
})
.catch((err) => {
console.log(err);
})
break;
default:
break;
}
}
function changePosition(order, idElement) {
return new Promise(function(resolve, reject) {
$.ajax({
method: "POST",
url: "<?php echo ui_get_full_url('ajax.php'); ?>",
dataType: "json",
data: {
page: "include/ajax/graph.ajax",
sort_items: 1,
order,
id_graph: <?php echo $id_graph; ?>,
id: idElement
},
success: function(data) {
resolve(data);
},
error: function(error) {
reject(error);
}
});
});
}
</script>

View File

@ -247,7 +247,7 @@ if ($add_module === true) {
$id_agent_modules = db_get_all_rows_sql($sql);
if (count($id_agent_modules) > 0 && $id_agent_modules != '') {
if (is_array($id_agent_modules) === true && count($id_agent_modules) > 0 && $id_agent_modules != '') {
$sql_order = sprintf(
'SELECT `field_order`
FROM tgraph_source

View File

@ -17,6 +17,8 @@ $save_custom_graph = (bool) get_parameter('save_custom_graph');
$print_custom_graph = (bool) get_parameter('print_custom_graph', false);
$print_sparse_graph = (bool) get_parameter('print_sparse_graph');
$get_graphs = (bool) get_parameter('get_graphs_container');
$sort_items = (bool) get_parameter('sort_items');
$width = get_parameter('width', 0);
$height = get_parameter('height', 0);
@ -337,3 +339,104 @@ if ($get_graphs) {
return;
}
}
if ($sort_items === true) {
$order = (string) get_parameter('order');
$id = (string) get_parameter('id', '');
$idGraph = (string) get_parameter('id_graph', '');
$total = db_get_num_rows('SELECT * FROM tgraph_source WHERE id_graph = '.$idGraph.'');
$item = db_get_row_sql(
'SELECT id_gs, field_order
FROM tgraph_source
WHERE id_gs = '.$id.'
ORDER BY field_order'
);
switch ($order) {
case 'up':
if (($item['field_order'] - 1) < 1) {
echo json_encode(['success' => false]);
return;
}
$prevItem = db_get_row_sql(
'SELECT id_gs, field_order
FROM tgraph_source
WHERE id_graph = '.$idGraph.'
AND field_order = '.($item['field_order'] - 1).'
ORDER BY field_order'
);
db_process_sql_begin();
$resultItem = db_process_sql_update(
'tgraph_source',
['field_order' => ($item['field_order'] - 1)],
['id_gs' => $item['id_gs']],
false
);
$resultPrevItem = db_process_sql_update(
'tgraph_source',
['field_order' => ($prevItem['field_order'] + 1)],
['id_gs' => $prevItem['id_gs']],
false
);
if ($resultItem !== false && $resultPrevItem !== false) {
db_process_sql_commit();
echo json_encode(['success' => true]);
return;
} else {
db_process_sql_rollback();
echo json_encode(['success' => false]);
return;
}
break;
case 'down':
if (($item['field_order'] + 1) > $total) {
echo json_encode(['success' => false]);
return;
}
$nextItem = db_get_row_sql(
'SELECT id_gs, field_order
FROM tgraph_source
WHERE id_graph = '.$idGraph.'
AND field_order = '.($item['field_order'] + 1).'
ORDER BY field_order'
);
db_process_sql_begin();
$resultItem = db_process_sql_update(
'tgraph_source',
['field_order' => ($item['field_order'] + 1)],
['id_gs' => $item['id_gs']],
false
);
$resultNextItem = db_process_sql_update(
'tgraph_source',
['field_order' => ($nextItem['field_order'] - 1)],
['id_gs' => $nextItem['id_gs']],
false
);
if ($resultItem !== false && $resultNextItem !== false) {
db_process_sql_commit();
echo json_encode(['success' => true]);
return;
} else {
db_process_sql_rollback();
echo json_encode(['success' => false]);
return;
}
break;
default:
echo json_encode(['success' => false]);
break;
}
}

View File

@ -774,7 +774,8 @@ function html_print_select(
$select2_multiple_enable_all=false,
$form='',
$order=false,
$custom_id=null
$custom_id=null,
$placeholder='',
) {
$output = "\n";
@ -1013,7 +1014,8 @@ function html_print_select(
$output .= '<script type="text/javascript">';
$output .= '$("#'.$id.'").select2({
closeOnSelect: '.(($select2_multiple_enable === true) ? 'false' : 'true').'
closeOnSelect: '.(($select2_multiple_enable === true) ? 'false' : 'true').',
placeholder: "'.$placeholder.'",
});';
if ($required !== false) {
@ -1758,6 +1760,7 @@ function html_print_select_multiple_modules_filtered(array $data):string
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
'placeholder' => (isset($data['placeholderAgents']) === true) ? $data['placeholderAgents'] : '',
]
);
} else {
@ -1773,6 +1776,7 @@ function html_print_select_multiple_modules_filtered(array $data):string
'multiple' => true,
'style' => 'min-width: 200px;max-width:200px;',
'script' => 'fmModuleChange(\''.$uniqId.'\', '.(int) is_metaconsole().')',
'placeholder' => (isset($data['placeholderAgents']) === true) ? $data['placeholderAgents'] : '',
]
);
}
@ -1888,7 +1892,8 @@ function html_print_select_from_sql(
$size=false,
$truncate_size=GENERIC_SIZE_TEXT,
$class='',
$required=false
$required=false,
$placeholder='',
) {
global $config;
@ -1931,7 +1936,12 @@ function html_print_select_from_sql(
$required,
$truncate_size,
true,
true
true,
false,
'',
false,
null,
$placeholder
);
}
@ -5680,7 +5690,9 @@ function html_print_input($data, $wrapper='div', $input_only=false)
((isset($data['select2_multiple_enable']) === true) ? $data['select2_multiple_enable'] : false),
((isset($data['select2_multiple_enable_all']) === true) ? $data['select2_multiple_enable_all'] : false),
((isset($data['form']) === true) ? $data['form'] : ''),
((isset($data['order']) === true) ? $data['order'] : false)
((isset($data['order']) === true) ? $data['order'] : false),
((isset($data['custom_id']) === true) ? $data['custom_id'] : null),
((isset($data['placeholder']) === true) ? $data['placeholder'] : null),
);
break;
@ -5700,7 +5712,8 @@ function html_print_input($data, $wrapper='div', $input_only=false)
((isset($data['size']) === true) ? $data['size'] : false),
((isset($data['trucate_size']) === true) ? $data['trucate_size'] : GENERIC_SIZE_TEXT),
((isset($data['class']) === true) ? $data['class'] : ''),
((isset($data['required']) === true) ? $data['required'] : false)
((isset($data['required']) === true) ? $data['required'] : false),
((isset($data['placeholder']) === true) ? $data['placeholder'] : null),
);
break;

View File

@ -0,0 +1,16 @@
#div-filtered-module-group-modules,
#div-filtered-module-module-group-modules,
#div-filtered-module-agents-modules,
#div-filtered-module-modules-modules {
width: 37% !important;
}
#div-filtered-module-modules-modules select {
width: 100% !important;
max-width: 100% !important;
}
#select_multiple_modules_filtered > div > div > .select2 {
width: 100% !important;
}
#select_multiple_modules_filtered > div {
flex-wrap: nowrap !important;
}

View File

@ -130,8 +130,8 @@
</div>
<div style='padding-bottom: 50px'>
<?php
$version = '7.0NG.775';
$build = '240118';
$version = '7.0NG.774';
$build = '231213';
$banner = "v$version Build $build";
error_reporting(0);