Merge branch 'ent-10983-selector-de-rango-de-fechas-para-multiples-elementos-a-la-vez-en-dashboards' into 'develop'
Ent 10983 Selector de rango de fechas para múltiples elementos a la vez en dashboards See merge request artica/pandorafms!6413
This commit is contained in:
commit
98d414f262
|
@ -23,5 +23,9 @@ INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` (`id_task`, `macro`, `type`, `
|
|||
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` (`id_task`, `macro`, `type`, `value`, `temp_conf`) SELECT id_rt, '_clientPath_', 'custom', '', 0 FROM `trecon_task` WHERE `id_app` = @id_app;
|
||||
UPDATE `trecon_task` SET `setup_complete` = 1 WHERE `id_app` = @id_app;
|
||||
|
||||
ALTER TABLE `tdashboard`
|
||||
ADD COLUMN `date_range` TINYINT NOT NULL DEFAULT 0 AFTER `cells_slideshow`,
|
||||
ADD COLUMN `date_from` INT NOT NULL DEFAULT 0 AFTER `date_range`,
|
||||
ADD COLUMN `date_to` INT NOT NULL DEFAULT 0 AFTER `date_from`;
|
||||
|
||||
COMMIT;
|
||||
|
|
|
@ -990,6 +990,70 @@ function get_parameter($name, $default='')
|
|||
}
|
||||
|
||||
|
||||
function get_parameter_date($name, $default='', $date_format='Y/m/d')
|
||||
{
|
||||
$date_end = get_parameter('date_end', 0);
|
||||
$time_end = get_parameter('time_end');
|
||||
$datetime_end = strtotime($date_end.' '.$time_end);
|
||||
|
||||
$custom_date = get_parameter('custom_date', 0);
|
||||
$range = get_parameter('range', SECONDS_1DAY);
|
||||
$date_text = get_parameter('range_text', SECONDS_1DAY);
|
||||
$date_init_less = (strtotime(date('Y/m/d')) - SECONDS_1DAY);
|
||||
$date_init = get_parameter('date_init', date(DATE_FORMAT, $date_init_less));
|
||||
$time_init = get_parameter('time_init', date(TIME_FORMAT, $date_init_less));
|
||||
$datetime_init = strtotime($date_init.' '.$time_init);
|
||||
if ($custom_date === '1') {
|
||||
if ($datetime_init >= $datetime_end) {
|
||||
$datetime_init = $date_init_less;
|
||||
}
|
||||
|
||||
$date_init = date('Y/m/d H:i:s', $datetime_init);
|
||||
$date_end = date('Y/m/d H:i:s', $datetime_end);
|
||||
$period = ($datetime_end - $datetime_init);
|
||||
} else if ($custom_date === '2') {
|
||||
$date_units = get_parameter('range_units');
|
||||
$date_end = date('Y/m/d H:i:s');
|
||||
$date_init = date('Y/m/d H:i:s', (strtotime($date_end) - ((int) $date_text * (int) $date_units)));
|
||||
$period = (strtotime($date_end) - strtotime($date_init));
|
||||
} else if (in_array($range, ['this_week', 'this_month', 'past_week', 'past_month'])) {
|
||||
if ($range === 'this_week') {
|
||||
$monday = date('Y/m/d', strtotime('last monday'));
|
||||
|
||||
$sunday = date('Y/m/d', strtotime($monday.' +6 days'));
|
||||
$period = (strtotime($sunday) - strtotime($monday));
|
||||
$date_init = $monday;
|
||||
$date_end = $sunday;
|
||||
} else if ($range === 'this_month') {
|
||||
$date_end = date('Y/m/d', strtotime('last day of this month'));
|
||||
$first_of_month = date('Y/m/d', strtotime('first day of this month'));
|
||||
$date_init = $first_of_month;
|
||||
$period = (strtotime($date_end) - strtotime($first_of_month));
|
||||
} else if ($range === 'past_month') {
|
||||
$date_end = date('Y/m/d', strtotime('last day of previous month'));
|
||||
$first_of_month = date('Y/m/d', strtotime('first day of previous month'));
|
||||
$date_init = $first_of_month;
|
||||
$period = (strtotime($date_end) - strtotime($first_of_month));
|
||||
} else if ($range === 'past_week') {
|
||||
$date_end = date('Y/m/d', strtotime('sunday', strtotime('last week')));
|
||||
$first_of_week = date('Y/m/d', strtotime('monday', strtotime('last week')));
|
||||
$date_init = $first_of_week;
|
||||
$period = (strtotime($date_end) - strtotime($first_of_week));
|
||||
}
|
||||
} else {
|
||||
$date_end = date('Y/m/d H:i:s');
|
||||
$date_init = date('Y/m/d H:i:s', (strtotime($date_end) - $range));
|
||||
$period = (strtotime($date_end) - strtotime($date_init));
|
||||
}
|
||||
|
||||
return [
|
||||
'date_init' => date($date_format, strtotime($date_init)),
|
||||
'date_end' => date($date_format, strtotime($date_end)),
|
||||
'period' => $period,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a parameter from a get request.
|
||||
*
|
||||
|
|
|
@ -458,6 +458,12 @@ class Manager implements PublicLogin
|
|||
$this->publicLink
|
||||
);
|
||||
|
||||
if ((bool) $this->dashboardFields['date_range'] === true) {
|
||||
$dateFrom = $this->dashboardFields['date_from'];
|
||||
$dateTo = $this->dashboardFields['date_to'];
|
||||
$instance->setDateRange($dateFrom, $dateTo);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
|
@ -1041,6 +1047,8 @@ class Manager implements PublicLogin
|
|||
$id_group = \get_parameter('id_group');
|
||||
$slideshow = \get_parameter_switch('slideshow');
|
||||
$favourite = \get_parameter_switch('favourite');
|
||||
$dateRange = \get_parameter_switch('date_range');
|
||||
$dateData = \get_parameter_date('range', '', 'U');
|
||||
|
||||
$id_user = (empty($private) === false) ? $config['id_user'] : '';
|
||||
|
||||
|
@ -1050,6 +1058,9 @@ class Manager implements PublicLogin
|
|||
'id_group' => $id_group,
|
||||
'cells_slideshow' => $slideshow,
|
||||
'active' => $favourite,
|
||||
'date_range' => $dateRange,
|
||||
'date_from' => $dateData['date_init'],
|
||||
'date_to' => $dateData['date_end'],
|
||||
];
|
||||
|
||||
if ($this->dashboardId === 0) {
|
||||
|
|
|
@ -51,6 +51,20 @@ class Widget
|
|||
*/
|
||||
private $showSelectNodeMeta;
|
||||
|
||||
/**
|
||||
* Date from init for filter widget.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $dateFrom;
|
||||
|
||||
/**
|
||||
* Date from end for filter widget.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $dateTo;
|
||||
|
||||
|
||||
/**
|
||||
* Contructor widget.
|
||||
|
@ -824,4 +838,41 @@ class Widget
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the date range of parent configuration.
|
||||
*
|
||||
* @param integer $dateFrom Date from init for filter widget.
|
||||
* @param integer $dateTo Date from end for filter widget.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDateRange(int $dateFrom, int $dateTo)
|
||||
{
|
||||
$this->dateFrom = $dateFrom;
|
||||
$this->dateTo = $dateTo;
|
||||
}
|
||||
|
||||
|
||||
public function getDateFrom()
|
||||
{
|
||||
return $this->dateFrom;
|
||||
}
|
||||
|
||||
|
||||
public function getDateTo()
|
||||
{
|
||||
return $this->dateTo;
|
||||
}
|
||||
|
||||
|
||||
public function getPeriod():mixed
|
||||
{
|
||||
if (empty($this->dateFrom) === false && empty($this->dateTo) === false) {
|
||||
return ($this->dateTo - $this->dateFrom);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -637,6 +637,10 @@ class BasicChart extends Widget
|
|||
$color_status = $this->values['colorValue'];
|
||||
}
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
$params = [
|
||||
'agent_module_id' => $this->values['moduleId'],
|
||||
'period' => $this->values['period'],
|
||||
|
|
|
@ -520,6 +520,9 @@ class BlockHistogram extends Widget
|
|||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
// Desactive scroll bars only this item.
|
||||
$id_agent = $data['agent_id'];
|
||||
|
|
|
@ -473,6 +473,10 @@ class DataMatrix extends Widget
|
|||
return $output;
|
||||
}
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
if (is_metaconsole() === true) {
|
||||
$modules_nodes = array_reduce(
|
||||
$this->values['moduleDataMatrix'],
|
||||
|
|
|
@ -472,6 +472,10 @@ class CustomGraphWidget extends Widget
|
|||
|
||||
$size = parent::getSize();
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
switch ($this->values['type']) {
|
||||
case CUSTOM_GRAPH_STACKED_LINE:
|
||||
case CUSTOM_GRAPH_STACKED_AREA:
|
||||
|
|
|
@ -302,6 +302,10 @@ class GraphModuleHistogramWidget extends Widget
|
|||
$values['period'] = SECONDS_1DAY;
|
||||
}
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
if (isset($values['sizeLabel']) === false) {
|
||||
$values['sizeLabel'] = 30;
|
||||
}
|
||||
|
|
|
@ -309,6 +309,12 @@ class Netflow extends Widget
|
|||
|
||||
$start_date = (time() - $this->values['period']);
|
||||
$end_date = time();
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$start_date = parent::getDateFrom();
|
||||
$end_date = parent::getDateTo();
|
||||
}
|
||||
|
||||
if ($this->values['chart_type'] === 'usage_map') {
|
||||
$map_data = netflow_build_map_data(
|
||||
$start_date,
|
||||
|
|
|
@ -135,8 +135,6 @@ class SecurityHardening extends Widget
|
|||
// Includes.
|
||||
include_once ENTERPRISE_DIR.'/include/functions_security_hardening.php';
|
||||
include_once $config['homedir'].'/include/graphs/fgraph.php';
|
||||
include_once $config['homedir'].'/include/functions_graph.php';
|
||||
|
||||
// WARNING: Do not edit. This chunk must be in the constructor.
|
||||
parent::__construct(
|
||||
$cellId,
|
||||
|
@ -328,6 +326,11 @@ class SecurityHardening extends Widget
|
|||
$id_groups = $this->checkAcl($values['group']);
|
||||
$output .= '<b>'.$this->elements[$data_type].'</b>';
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$values['date_init'] = parent::getDateFrom();
|
||||
$values['date_end'] = parent::getDateTo();
|
||||
}
|
||||
|
||||
switch ($data_type) {
|
||||
case 'top_n_agents_sh':
|
||||
$output .= $this->loadTopNAgentsSh($id_groups, $values['limit']);
|
||||
|
|
|
@ -440,6 +440,10 @@ class SingleGraphWidget extends Widget
|
|||
$module_name = \modules_get_agentmodule_name($this->values['moduleId']);
|
||||
$units_name = \modules_get_unit($this->values['moduleId']);
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
$trickHight = 0;
|
||||
if ($this->values['showLegend'] === 1) {
|
||||
// Needed for legend.
|
||||
|
|
|
@ -459,6 +459,9 @@ class SLAPercentWidget extends Widget
|
|||
global $config;
|
||||
|
||||
$size = parent::getSize();
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
$output .= '';
|
||||
$id_agent = $this->values['agentId'];
|
||||
|
|
|
@ -374,6 +374,10 @@ class TopNWidget extends Widget
|
|||
|
||||
$size = parent::getSize();
|
||||
|
||||
if (empty(parent::getPeriod()) === false) {
|
||||
$this->values['period'] = parent::getPeriod();
|
||||
}
|
||||
|
||||
$quantity = $this->values['quantity'];
|
||||
$period = $this->values['period'];
|
||||
|
||||
|
|
|
@ -2640,6 +2640,9 @@ CREATE TABLE IF NOT EXISTS `tdashboard` (
|
|||
`active` TINYINT NOT NULL DEFAULT 0,
|
||||
`cells` INT UNSIGNED DEFAULT 0,
|
||||
`cells_slideshow` TINYINT NOT NULL DEFAULT 0,
|
||||
`date_range` TINYINT NOT NULL DEFAULT 0,
|
||||
`date_from` INT NOT NULL DEFAULT 0,
|
||||
`date_to` INT NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
|
|
|
@ -102,6 +102,31 @@ $inputs = [
|
|||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'label' => __('Date range'),
|
||||
'arguments' => [
|
||||
'name' => 'date_range',
|
||||
'id' => 'date_range',
|
||||
'type' => 'switch',
|
||||
'value' => $arrayDashboard['date_range'],
|
||||
'onchange' => 'handle_date_range(this)',
|
||||
],
|
||||
],
|
||||
[
|
||||
'label' => __('Select range'),
|
||||
'style' => 'display: none;',
|
||||
'class' => 'row_date_range',
|
||||
'arguments' => [
|
||||
'name' => 'range',
|
||||
'id' => 'range',
|
||||
'selected' => ($arrayDashboard['date_from'] === '0' && $arrayDashboard['date_to'] === '0') ? 300 : 'chose_range',
|
||||
'type' => 'date_range',
|
||||
'date_init' => date('Y/m/d', $arrayDashboard['date_from']),
|
||||
'time_init' => date('H:i:s', $arrayDashboard['date_from']),
|
||||
'date_end' => date('Y/m/d', $arrayDashboard['date_to']),
|
||||
'time_end' => date('H:i:s', $arrayDashboard['date_to']),
|
||||
],
|
||||
],
|
||||
[
|
||||
'block_id' => 'private',
|
||||
'direct' => 1,
|
||||
|
@ -135,3 +160,30 @@ HTML::printForm(
|
|||
'inputs' => $inputs,
|
||||
]
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
<script>
|
||||
function handle_date_range(element){
|
||||
if(element.checked) {
|
||||
$(".row_date_range").show();
|
||||
var def_state_range = $('#range_range').is(':visible');
|
||||
var def_state_default = $('#range_default').is(':visible');
|
||||
var def_state_extend = $('#range_extend').is(':visible');
|
||||
if (
|
||||
def_state_range === false
|
||||
&& def_state_default === false
|
||||
&& def_state_extend === false
|
||||
&& $('#range').val() !== 'chose_range'
|
||||
) {
|
||||
$('#range_default').show();
|
||||
} else if ($('#range').val() === 'chose_range') {
|
||||
$('#range_range').show();
|
||||
}
|
||||
} else {
|
||||
$(".row_date_range").hide();
|
||||
}
|
||||
}
|
||||
var date_range = $("#date_range")[0];
|
||||
handle_date_range(date_range);
|
||||
</script>
|
Loading…
Reference in New Issue