Merge branch 'visual-console-refactor' of https://brutus.artica.lan:8081/artica/pandorafms into visual-console-refactor

Former-commit-id: a97cbb6723fb51b583c98af381bfd92f1a1413f2
This commit is contained in:
Daniel Maya 2019-04-02 17:26:27 +02:00
commit 5670157e06
2 changed files with 53 additions and 29 deletions

View File

@ -70,7 +70,7 @@ class Item extends Model
|| $data['width'] < 0 || $data['width'] < 0
) { ) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'the width property is required and should be greater than 0' 'the width property is required and should be equal or greater than 0'
); );
} }
@ -79,7 +79,7 @@ class Item extends Model
|| $data['height'] < 0 || $data['height'] < 0
) { ) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'the height property is required and should be greater than 0' 'the height property is required and should be equal or greater than 0'
); );
} }
@ -357,7 +357,7 @@ class Item extends Model
* 'agentName' => null, * 'agentName' => null,
* ] * ]
*/ */
private function extractLinkedAgent(array $data): array protected function extractLinkedAgent(array $data): array
{ {
$agentData = []; $agentData = [];
@ -420,7 +420,7 @@ class Item extends Model
* 'moduleName' => null, * 'moduleName' => null,
* ] * ]
*/ */
private function extractLinkedModule(array $data): array protected function extractLinkedModule(array $data): array
{ {
// Initialize the data with the agent data and then expand it. // Initialize the data with the agent data and then expand it.
$moduleData = static::extractLinkedAgent($data); $moduleData = static::extractLinkedAgent($data);

View File

@ -4,22 +4,13 @@ declare(strict_types=1);
namespace Models\VisualConsole\Items; namespace Models\VisualConsole\Items;
use Models\VisualConsole\Item; use Models\VisualConsole\Item;
use Models\Model;
/** /**
* Model of a group item of the Visual Console. * Model of a events history item of the Visual Console.
*/ */
final class EventsHistory extends Item final class EventsHistory extends Item
{ {
/**
* Used to enable the fetching, validation and extraction of information
* about the linked visual console.
*
* @var boolean
*/
protected static $useLinkedVisualConsole = true;
/** /**
* Used to enable the fetching, validation and extraction of information * Used to enable the fetching, validation and extraction of information
* about the linked module. * about the linked module.
@ -28,6 +19,14 @@ final class EventsHistory extends Item
*/ */
protected static $useLinkedModule = true; protected static $useLinkedModule = true;
/**
* Used to enable the fetching, validation and extraction of information
* about the linked visual console.
*
* @var boolean
*/
protected static $useLinkedVisualConsole = true;
/** /**
* Returns a valid representation of the model. * Returns a valid representation of the model.
@ -43,45 +42,70 @@ final class EventsHistory extends Item
$return = parent::decode($data); $return = parent::decode($data);
$return['type'] = AUTO_SLA_GRAPH; $return['type'] = AUTO_SLA_GRAPH;
$return['maxTime'] = $this->extractMaxTime($data); $return['maxTime'] = $this->extractMaxTime($data);
$return['data'] = $this->extractData($data); $return['encodedHtml'] = $this->extractEncodedHtml($data);
return $return; return $return;
} }
/** /**
* Extract the value of maxTime and * Extract a graph period value.
* return a integer or null.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return mixed * @return mixed The time in seconds of the graph period or null.
*/ */
private function extractMaxTime(array $data) private function extractMaxTime(array $data)
{ {
$maxTime = Model::parseIntOr( return static::parseIntOr(
Model::issetInArray($data, ['maxTime', 'period']), static::issetInArray($data, ['maxTime', 'period']),
null null
); );
return $maxTime;
} }
/** /**
* Extract the value of data and * Extract a encoded HTML representation of the item.
* return an array.
* *
* @param array $data Unknown input data structure. * @param array $data Unknown input data structure.
* *
* @return array * @return string The HTML representation in base64 encoding.
* @throws \InvalidArgumentException When an agent Id cannot be found.
*/ */
private function extractData(array $data): array private function extractEncodedHtml(array $data): string
{ {
$array = []; if (isset($data['encodedHtml']) === true) {
if (isset($data['data']) && \is_array($data['data'])) { return $data['encodedHtml'];
$array = $data['data']; } else if (isset($data['html']) === true) {
return \base64_encode($data['html']);
} }
return $array; // Load side libraries.
global $config;
include_once $config['homedir'].'/include/functions_graph.php';
// Get the linked agent and module Ids.
$linkedModule = $this->extractLinkedModule($data);
$agentId = static::parseIntOr($linkedModule['agentId'], null);
$moduleId = static::parseIntOr($linkedModule['moduleId'], null);
if ($agentId === null) {
throw new \InvalidArgumentException('missing agent Id');
}
// Use the same HTML output as the old VC.
$html = '<div style="width:500px;">';
$html .= \graph_graphic_moduleevents(
$agentId,
$moduleId,
(int) $data['width'],
(int) $data['height'],
$this->extractMaxTime($data),
'',
true
);
$html .= '</div>';
return \base64_encode($html);
} }