Merge branch 'ent-10324-sistema-de-favoritos' into 'develop'

Ent 10324 sistema de favoritos

See merge request artica/pandorafms!5559
This commit is contained in:
Matias Didier 2023-03-14 10:38:39 +00:00
commit 27beea7319
26 changed files with 476 additions and 27 deletions

View File

@ -155,4 +155,13 @@ INSERT INTO `twelcome_tip_file` (`twelcome_tip_file`, `filename`, `path`) VALUES
(20, 'zoom_en_graficas.png', 'images/tips/'),
(22, 'politica_de_pass.png', 'images/tips/');
CREATE TABLE IF NOT EXISTS `tfavmenu_user` (
`id` INT NOT NULL AUTO_INCREMENT,
`id_user` VARCHAR(255) NOT NULL,
`id_element` TEXT,
`url` TEXT NOT NULL,
`label` VARCHAR(255) NOT NULL,
`section` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`));
COMMIT;

View File

@ -827,6 +827,12 @@ if ($id_agente) {
'link' => '',
'label' => $tab_name,
],
],
[
'id_element' => $id_agente,
'url' => 'godmode/agentes/configurar_agente&tab=main&id_agente='.$id_agente,
'label' => agents_get_alias($id_agente),
'section' => 'Agents',
]
);
}

View File

@ -59,6 +59,14 @@ if ($delete) {
}
if ($result !== false) {
db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $id_filter,
'section' => 'Events',
'id_user' => $config['id_user'],
]
);
$result = true;
} else {
$result = false;

View File

@ -714,6 +714,14 @@ if ($is_management_allowed === true
);
if ($result && (!$usedGroup['return'])) {
db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $id_group,
'section' => 'Tactic_group',
'id_user' => $config['id_user'],
]
);
ui_print_success_message(__('Group successfully deleted'));
} else {
ui_print_error_message(

View File

@ -74,6 +74,12 @@ if (is_metaconsole() === false) {
'link' => '',
'label' => __('Tactic group'),
],
],
[
'id_element' => $id_group,
'url' => 'gagent&sec2=godmode/groups/tactical&id_group='.$id_group,
'label' => groups_get_name($id_group),
'section' => 'Tactic_group',
]
);
}

View File

@ -189,6 +189,14 @@ if ($delete_layout || $copy_layout) {
'tlayout',
['id' => $id_layout]
);
db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $id_layout,
'section' => 'Visual_Console',
'id_user' => $config['id_user'],
]
);
$auditMessage = ((bool) $result === true) ? 'Delete visual console' : 'Fail try to delete visual console';
db_pandora_audit(

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 61.2 (89653) - https://sketch.com -->
<title>Dark / 20 / star@svg</title>
<desc>Created with Sketch.</desc>
<g id="Dark-/-20-/-star" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path d="M10,16.5 L5.32783438,18.9563028 C4.83898979,19.2133036 4.23436264,19.0253571 3.97736183,18.5365125 C3.87502276,18.3418521 3.83970808,18.118884 3.87688493,17.9021263 L4.76918916,12.6995935 L4.76918916,12.6995935 L0.989327772,9.01513923 C0.593844194,8.62963801 0.585751887,7.99652475 0.971253099,7.60104117 C1.1247617,7.44355754 1.32590411,7.34107036 1.54354115,7.30944585 L6.76718111,6.55040653 L6.76718111,6.55040653 L9.10326392,1.81698575 C9.34768622,1.32173209 9.94731205,1.11839309 10.4425657,1.36281539 C10.6397783,1.46014562 10.7994058,1.61977315 10.8967361,1.81698575 L13.2328189,6.55040653 L13.2328189,6.55040653 L18.4564589,7.30944585 C19.0030037,7.38886347 19.3816852,7.89630632 19.3022676,8.44285118 C19.270643,8.66048821 19.1681559,8.86163062 19.0106722,9.01513923 L15.2308108,12.6995935 L15.2308108,12.6995935 L16.1231151,17.9021263 C16.2164761,18.4464628 15.8508883,18.9634187 15.3065518,19.0567797 C15.0897942,19.0939566 14.8668261,19.0586419 14.6721656,18.9563028 L10,16.5 L10,16.5 Z" id="Star" fill="#a6adb2"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

View File

@ -0,0 +1,82 @@
<?php
/**
* Fav menu
*
* @category Ajax library.
* @package Pandora FMS
* @subpackage Modules.
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
global $config;
// Login check
check_login();
if (is_ajax() === false) {
exit;
}
$id_element = get_parameter('id_element', '');
$url = io_safe_output(get_parameter('url', ''));
$label = get_parameter('label', '');
$section = get_parameter('section', '');
$id_user = $config['id_user'];
$exist = db_get_row_filter(
'tfavmenu_user',
[
'url' => $url,
'id_user' => $config['id_user'],
],
['*']
);
$res = false;
$action = '';
if ($exist !== false) {
$res = db_process_sql_delete(
'tfavmenu_user',
[
'url' => $url,
'id_user' => $config['id_user'],
]
);
$action = 'delete';
} else {
$res = db_process_sql_insert(
'tfavmenu_user',
[
'id_element' => $id_element,
'url' => $url,
'label' => $label,
'section' => $section,
'id_user' => $id_user,
]
);
$action = 'create';
}
if ($res !== false) {
echo json_encode(['success' => true, 'action' => $action]);
} else {
echo json_encode(['success' => false, 'action' => $action]);
}

View File

@ -2044,6 +2044,14 @@ if (check_login()) {
if ($monitor_filters === false) {
echo 'error';
} else {
db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $id,
'section' => 'Modules',
'id_user' => $config['id_user'],
]
);
echo 'ok';
}
}

View File

@ -2769,6 +2769,16 @@ function agents_delete_agent($id_agents, $disableACL=false)
enterprise_include_once('include/functions_agents.php');
enterprise_hook('agent_delete_from_cache', [$id_agent]);
// Delete agent from fav menu.
db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $id_agent,
'section' => 'Agents',
'id_user' => $config['id_user'],
]
);
// Break the loop on error.
if ((bool) $error === true) {
break;

View File

@ -221,6 +221,8 @@ function reports_update_report($id_report, $values)
*/
function reports_delete_report($id_report)
{
global $config;
$id_report = safe_int($id_report);
if (empty($id_report)) {
return false;
@ -231,6 +233,16 @@ function reports_delete_report($id_report)
return false;
}
// Delete report from fav menu.
db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $id_report,
'section' => 'Reporting',
'id_user' => $config['id_user'],
]
);
@db_process_sql_delete('treport_content', ['id_report' => $id_report]);
return @db_process_sql_delete('treport', ['id_report' => $id_report]);
}

View File

@ -4996,7 +4996,8 @@ function ui_print_standard_header(
string $help='',
bool $godmode=false,
array $options=[],
array $breadcrumbs=[]
array $breadcrumbs=[],
array $fav_menu_config=[]
) {
// For standard breadcrumbs.
ui_require_css_file('discovery');
@ -5040,7 +5041,9 @@ function ui_print_standard_header(
'',
GENERIC_SIZE_TEXT,
'',
$headerInformation->printHeader(true)
$headerInformation->printHeader(true),
false,
$fav_menu_config
);
// }
if ($return !== true) {
@ -5081,7 +5084,8 @@ function ui_print_page_header(
$numChars=GENERIC_SIZE_TEXT,
$alias='',
$breadcrumbs='',
$hide_left_small=false
$hide_left_small=false,
$fav_menu_config=[]
) {
global $config;
@ -5145,6 +5149,17 @@ function ui_print_page_header(
}
}
if (is_array($fav_menu_config) === true && is_metaconsole() === false) {
if (count($fav_menu_config) > 0) {
$buffer .= ui_print_fav_menu(
$fav_menu_config['id_element'],
$fav_menu_config['url'],
$fav_menu_config['label'],
$fav_menu_config['section']
);
}
}
$buffer .= '</span>';
if (is_metaconsole() === true) {
@ -7786,4 +7801,48 @@ function ui_print_status_div($status)
}
return $return;
}
function ui_print_fav_menu($id_element, $url, $label, $section)
{
global $config;
$label = io_safe_output($label);
if (strlen($label) > 18) {
$label = io_safe_input(substr($label, 0, 18).'...');
}
$fav = db_get_row_filter(
'tfavmenu_user',
[
'url' => $url,
'id_user' => $config['id_user'],
],
['*']
);
$config_fav_menu = [
'id_element' => $id_element,
'url' => $url,
'label' => $label,
'section' => $section,
];
$output = '<span class="fav-menu">';
$output .= html_print_input_image(
'fav-menu-action',
(($fav !== false) ? 'images/star_fav_menu.png' : 'images/star_dark.png'),
base64_encode(json_encode($config_fav_menu)),
'',
true,
[
'onclick' => 'favMenuAction(this)',
'class' => (($fav !== false) ? 'active' : ''),
]
);
$output .= '</span>';
$output .= '<div id="dialog-fav-menu">';
$output .= '<p><b>'.__('Title').'</b></p>';
$output .= html_print_input_text('label_fav_menu', '', '', 25, 255, true, false, true);
$output .= '</div>';
return $output;
}

View File

@ -834,3 +834,55 @@ function unblockSubmit(button) {
expireCookie("downloadReady");
attempts = 30;
}
function favMenuAction(e) {
var data = JSON.parse(atob(e.value));
if (data.label === "" && $(e).hasClass("active") === false) {
$("#dialog-fav-menu").dialog({
title: "Please choose a title",
width: 330,
buttons: [
{
class:
"ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-next",
text: "Confirm",
click: function() {
data.label = $("#text-label_fav_menu").val();
if (data.label.length > 18) {
data.label = data.label.slice(0, 18) + "...";
}
$(e).val(btoa(JSON.stringify(data)));
favMenuAction(e);
$(this).dialog("close");
$("input[name='label_fav_menu']").val("");
}
}
]
});
return;
}
$.ajax({
method: "POST",
url: "ajax.php",
dataType: "json",
data: {
page: "include/ajax/fav_menu.ajax",
id_element: data["id_element"],
url: data["url"],
label: data["label"],
section: data["section"]
},
success: function(res) {
if (res.success) {
if (res.action === "create") {
$("#image-fav-menu-action1").attr("src", "images/star_fav_menu.png");
$("#image-fav-menu-action1").addClass("active");
} else {
$("#image-fav-menu-action1").attr("src", "images/star_dark.png");
$("#image-fav-menu-action1").removeClass("active");
}
}
}
});
}

View File

@ -568,6 +568,16 @@ class Manager implements PublicLogin
'tdashboard',
['id' => $this->dashboardId]
);
// Delete dashboard from fav menu.
\db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $this->dashboardId,
'section' => 'Dashboard_',
'id_user' => $config['id_user'],
]
);
}
// Audit.

View File

@ -315,3 +315,15 @@ div.ui-tooltip.ui-corner-all.ui-widget-shadow.ui-widget.ui-widget-content.uitool
bottom: -20px;
top: auto;
}
#dialog-fav-menu {
display: none;
}
#dialog-fav-menu p {
margin: 0px;
padding-top: 40px;
}
.fav-menu input {
padding: 0px;
max-width: 20px !important;
max-height: 20px;
}

View File

@ -248,6 +248,10 @@
background: url(../../images/menu/events.svg) no-repeat 50% 50%;
background-size: 18px;
}
.icon_fav-menu {
background: url(../../images/menu/fav_menu_gray.svg) no-repeat 50% 50%;
background-size: 18px;
}
/* users */
.icon_oper-users {
@ -700,3 +704,7 @@ ul li {
width: 215px !important;
height: auto !important;
}
.fav-menu {
margin-left: 9px;
}

View File

@ -548,6 +548,15 @@ else if ($update_networkmap || $copy_networkmap || $delete) {
$result = networkmap_delete_networkmap($id);
// Delete network map from fav menu.
db_process_sql_delete(
'tfavmenu_user',
[
'id_element' => $id,
'section' => 'Network_map',
'id_user' => $config['id_user'],
]
);
$result_txt = ui_print_result_message(
$result,
__('Succesfully deleted'),

View File

@ -2412,6 +2412,12 @@ if ($networkmap === false) {
'link' => '',
'label' => __('Network maps'),
],
],
[
'id_element' => $networkmap['id'],
'url' => 'operation/agentes/pandora_networkmap&tab=view&id_networkmap='.$networkmap['id'],
'label' => $networkmap['name'],
'section' => 'Network_map',
]
);
}

View File

@ -93,27 +93,6 @@ if (is_metaconsole() === false) {
}
}
// Header.
ui_print_standard_header(
__('Monitor detail').$subpage,
'images/agent.png',
false,
'',
true,
$buttons,
[
[
'link' => '',
'label' => __('Monitoring'),
],
[
'link' => '',
'label' => __('Views'),
],
]
);
if (is_metaconsole() === false) {
if ($section == 'fields') {
include_once $config['homedir'].'/godmode/agentes/status_monitor_custom_fields.php';
@ -285,8 +264,79 @@ if ($loaded_filter['id_filter'] > 0) {
$ag_custom_fields = json_decode(io_safe_output($ag_custom_fields), true);
}
}
// Fav menu.
$fav_menu = [
'id_element' => $loaded_filter['id_filter'],
'url' => 'operation/agentes/status_monitor&pure=&load_filter=1&filter_id='.$loaded_filter['id_filter'],
'label' => $loaded_filter['id_name'],
'section' => 'Modules',
];
}
if (is_metaconsole() === false) {
$section = (string) get_parameter('section', 'view');
$buttons['fields'] = [
'active' => false,
'text' => '<a href="index.php?sec=view&sec2=operation/agentes/status_monitor&section=fields">'.html_print_image(
'images/edit_columns@svg.svg',
true,
[
'title' => __('Custom fields'),
'class' => 'invert_filter main_menu_icon',
]
).'</a>',
'operation' => true,
];
$buttons['view'] = [
'active' => false,
'text' => '<a href="index.php?sec=view&sec2=operation/agentes/status_monitor">'.html_print_image(
'images/logs@svg.svg',
true,
[
'title' => __('View'),
'class' => 'invert_filter main_menu_icon',
]
).'</a>',
'operation' => true,
];
switch ($section) {
case 'fields':
$buttons['fields']['active'] = true;
$subpage = ' &raquo; '.__('Custom fields');
break;
default:
$buttons['view']['active'] = true;
break;
}
}
// Header.
ui_print_standard_header(
__('Monitor detail').$subpage,
'images/agent.png',
false,
'',
true,
$buttons,
[
[
'link' => '',
'label' => __('Monitoring'),
],
[
'link' => '',
'label' => __('Views'),
],
],
(empty($fav_menu) === true) ? [] : $fav_menu
);
$all_groups = [];
// Agent group selector.
@ -2464,4 +2514,4 @@ if( value_swtich != "") {
}else {
chkbox.checked = false;
}
</script>
</script>

View File

@ -1071,7 +1071,7 @@ if (is_ajax() === true) {
*/
$load_filter_id = (int) get_parameter('filter_id', 0);
$fav_menu = [];
if ($load_filter_id === 0) {
// Load user filter.
$loaded_filter = db_get_row_sql(
@ -1093,6 +1093,14 @@ if ($load_filter_id === 0) {
'id_filter',
$load_filter_id
);
// Fav menu
$fav_menu = [
'id_element' => $load_filter_id,
'url' => 'operation/events/events&pure=&load_filter=1&filter_id='.$load_filter_id,
'label' => $loaded_filter['id_name'],
'section' => 'Events',
];
}
// Do not load the user filter if we come from the 24h event graph.
@ -1583,7 +1591,8 @@ if ($pure) {
'link' => '',
'label' => __('Events'),
],
]
],
$fav_menu
);
}

View File

@ -606,6 +606,44 @@ if ($access_console_node === true) {
}
}
$favorite_menu = db_get_all_rows_sql(
sprintf(
'SELECT id_element, url, label, section
FROM tfavmenu_user
WHERE id_user = "%s"
ORDER BY section DESC',
$config['id_user']
)
);
// Favorite.
if ($favorite_menu !== false) {
$menu_operation['favorite']['text'] = __('Favorite');
$menu_operation['favorite']['id'] = 'fav-menu';
$section = '';
$sub = [];
$sub2 = [];
foreach ($favorite_menu as $key => $row) {
if ($row['section'] !== $section) {
$section = $row['section'];
$sub2 = [];
}
$sub[$section]['text'] = __(str_replace('_', ' ', $section));
$sub[$section]['type'] = 'direct';
$sub[$section]['subtype'] = 'nolink';
$sub[$section]['id'] = $row['section'];
$sub2[$row['url']]['text'] = io_safe_output($row['label']);
$sub[$section]['sub2'] = $sub2;
}
$menu_operation['favorite']['sub'] = $sub;
}
// Workspace.
$menu_operation['workspace']['text'] = __('Workspace');
$menu_operation['workspace']['sec2'] = 'operation/users/user_edit';

View File

@ -221,6 +221,12 @@ ui_print_standard_header(
'link' => '',
'label' => __('Custom reports'),
],
],
[
'id_element' => $id_report,
'url' => 'operation/reporting/reporting_viewer&id='.$id_report,
'label' => reporting_get_name($id_report),
'section' => 'Reporting',
]
);

View File

@ -240,6 +240,12 @@ if (!$config['pure']) {
'link' => '',
'label' => __('Visual console'),
],
],
[
'id_element' => $visualConsoleId,
'url' => 'operation/visual_console/render_view&id='.$visualConsoleId,
'label' => $visualConsoleName,
'section' => 'Visual_Console',
]
);
}

View File

@ -4246,3 +4246,15 @@ CREATE TABLE IF NOT EXISTS `twelcome_tip_file` (
REFERENCES `twelcome_tip` (`id`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------
-- Table `tfavmenu_user`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tfavmenu_user` (
`id` INT NOT NULL AUTO_INCREMENT,
`id_user` VARCHAR(255) NOT NULL,
`id_element` TEXT,
`url` TEXT NOT NULL,
`label` VARCHAR(255) NOT NULL,
`section` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`));

View File

@ -296,6 +296,12 @@ if ($publicLink === false) {
'link' => '',
'label' => __('Dashboard'),
],
],
[
'id_element' => $dashboardId,
'url' => 'operation/dashboard/dashboard&dashboardId='.$dashboardId,
'label' => $dashboardName,
'section' => 'Dashboard_',
]
);
} else {