mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-27 07:44:35 +02:00
Visual Console Refactor: fixed the events history model
Former-commit-id: 9228339af7213996fb969ee631a93a3e972e102a
This commit is contained in:
parent
eb6757e91c
commit
ca4997fd7f
@ -28,6 +28,33 @@ final class EventsHistory extends Item
|
|||||||
protected static $useLinkedVisualConsole = true;
|
protected static $useLinkedVisualConsole = true;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the received data structure to ensure if we can extract the
|
||||||
|
* values required to build the model.
|
||||||
|
*
|
||||||
|
* @param array $data Input data.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException If any input value is considered
|
||||||
|
* invalid.
|
||||||
|
*
|
||||||
|
* @overrides Item::validateData.
|
||||||
|
*/
|
||||||
|
protected function validateData(array $data): void
|
||||||
|
{
|
||||||
|
parent::validateData($data);
|
||||||
|
|
||||||
|
if (static::notEmptyStringOr($data['encodedHtml'], null) === null
|
||||||
|
&& static::notEmptyStringOr($data['html'], null) === null
|
||||||
|
) {
|
||||||
|
throw new \InvalidArgumentException(
|
||||||
|
'the html property is required and should be string'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a valid representation of the model.
|
* Returns a valid representation of the model.
|
||||||
*
|
*
|
||||||
@ -54,7 +81,7 @@ final class EventsHistory extends Item
|
|||||||
*
|
*
|
||||||
* @return mixed The time in seconds of the graph period or null.
|
* @return mixed The time in seconds of the graph period or null.
|
||||||
*/
|
*/
|
||||||
private function extractMaxTime(array $data)
|
private static function extractMaxTime(array $data)
|
||||||
{
|
{
|
||||||
return static::parseIntOr(
|
return static::parseIntOr(
|
||||||
static::issetInArray($data, ['maxTime', 'period']),
|
static::issetInArray($data, ['maxTime', 'period']),
|
||||||
@ -69,15 +96,36 @@ final class EventsHistory extends Item
|
|||||||
* @param array $data Unknown input data structure.
|
* @param array $data Unknown input data structure.
|
||||||
*
|
*
|
||||||
* @return string The HTML representation in base64 encoding.
|
* @return string The HTML representation in base64 encoding.
|
||||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
|
||||||
*/
|
*/
|
||||||
private function extractEncodedHtml(array $data): string
|
private static function extractEncodedHtml(array $data): string
|
||||||
{
|
{
|
||||||
if (isset($data['encodedHtml']) === true) {
|
if (isset($data['encodedHtml']) === true) {
|
||||||
return $data['encodedHtml'];
|
return $data['encodedHtml'];
|
||||||
} else if (isset($data['html']) === true) {
|
} else if (isset($data['html']) === true) {
|
||||||
return \base64_encode($data['html']);
|
return \base64_encode($data['html']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch a vc item data structure from the database using a filter.
|
||||||
|
*
|
||||||
|
* @param array $filter Filter of the Visual Console Item.
|
||||||
|
*
|
||||||
|
* @return array The Visual Console Item data structure stored into the DB.
|
||||||
|
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||||
|
*
|
||||||
|
* @override Item::fetchDataFromDB.
|
||||||
|
*/
|
||||||
|
protected static function fetchDataFromDB(array $filter): array
|
||||||
|
{
|
||||||
|
// Due to this DB call, this function cannot be unit tested without
|
||||||
|
// a proper mock.
|
||||||
|
$data = parent::fetchDataFromDB($filter);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieve extra data.
|
||||||
|
*/
|
||||||
|
|
||||||
// Load side libraries.
|
// Load side libraries.
|
||||||
global $config;
|
global $config;
|
||||||
@ -99,13 +147,15 @@ final class EventsHistory extends Item
|
|||||||
$moduleId,
|
$moduleId,
|
||||||
(int) $data['width'],
|
(int) $data['width'],
|
||||||
(int) $data['height'],
|
(int) $data['height'],
|
||||||
$this->extractMaxTime($data),
|
static::extractMaxTime($data),
|
||||||
'',
|
'',
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
return \base64_encode($html);
|
$data['encodedHtml'] = \base64_encode($html);
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class EventsHistoryTest extends TestCase
|
|||||||
'width' => '600',
|
'width' => '600',
|
||||||
'height' => '500',
|
'height' => '500',
|
||||||
'maxTime' => null,
|
'maxTime' => null,
|
||||||
'data' => [],
|
'html' => '<h1>Foo</h1>',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -37,15 +37,12 @@ class EventsHistoryTest extends TestCase
|
|||||||
EventsHistory::class,
|
EventsHistory::class,
|
||||||
EventsHistory::fromArray(
|
EventsHistory::fromArray(
|
||||||
[
|
[
|
||||||
'id' => 14,
|
'id' => 14,
|
||||||
'type' => AUTO_SLA_GRAPH,
|
'type' => AUTO_SLA_GRAPH,
|
||||||
'width' => '600',
|
'width' => '600',
|
||||||
'height' => '500',
|
'height' => '500',
|
||||||
'maxTime' => 12800,
|
'maxTime' => 12800,
|
||||||
'data' => [
|
'encodedHtml' => 'PGgxPkZvbzwvaDE+',
|
||||||
'data' => '5',
|
|
||||||
'time' => 23456788,
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -60,7 +57,7 @@ class EventsHistoryTest extends TestCase
|
|||||||
public function testContainerIsRepresentedAsJson(): void
|
public function testContainerIsRepresentedAsJson(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":[],"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","maxTime":null,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
'{"aclGroupId":null,"agentId":null,"agentName":null,"encodedHtml":"PGgxPkZvbzwvaDE+","height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","maxTime":null,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||||
(string) EventsHistory::fromArray(
|
(string) EventsHistory::fromArray(
|
||||||
[
|
[
|
||||||
'id' => 7,
|
'id' => 7,
|
||||||
@ -75,13 +72,13 @@ class EventsHistoryTest extends TestCase
|
|||||||
'x' => -666,
|
'x' => -666,
|
||||||
'y' => 76,
|
'y' => 76,
|
||||||
'maxTime' => null,
|
'maxTime' => null,
|
||||||
'data' => [],
|
'html' => '<h1>Foo</h1>',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":{"time":23456789,"data":15},"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","maxTime":12800,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
'{"aclGroupId":null,"agentId":null,"agentName":null,"encodedHtml":"PGgxPkZvbzwvaDE+","height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","maxTime":12800,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||||
(string) EventsHistory::fromArray(
|
(string) EventsHistory::fromArray(
|
||||||
[
|
[
|
||||||
'id' => 7,
|
'id' => 7,
|
||||||
@ -96,16 +93,13 @@ class EventsHistoryTest extends TestCase
|
|||||||
'x' => -666,
|
'x' => -666,
|
||||||
'y' => 76,
|
'y' => 76,
|
||||||
'maxTime' => 12800,
|
'maxTime' => 12800,
|
||||||
'data' => [
|
'encodedHtml' => 'PGgxPkZvbzwvaDE+',
|
||||||
'time' => 23456789,
|
|
||||||
'data' => 15,
|
|
||||||
],
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":[],"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":1,"linkedLayoutStatusType":"default","maxTime":null,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
'{"aclGroupId":null,"agentId":null,"agentName":null,"encodedHtml":"PGgxPkZvbzwvaDE+","height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":1,"linkedLayoutStatusType":"default","maxTime":null,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||||
(string) EventsHistory::fromArray(
|
(string) EventsHistory::fromArray(
|
||||||
[
|
[
|
||||||
'id' => 7,
|
'id' => 7,
|
||||||
@ -120,14 +114,14 @@ class EventsHistoryTest extends TestCase
|
|||||||
'x' => -666,
|
'x' => -666,
|
||||||
'y' => 76,
|
'y' => 76,
|
||||||
'maxTime' => null,
|
'maxTime' => null,
|
||||||
'data' => [],
|
'encodedHtml' => 'PGgxPkZvbzwvaDE+',
|
||||||
'id_layout_linked' => 1,
|
'id_layout_linked' => 1,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":{"time":23456789,"data":15},"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"default","maxTime":12800,"metaconsoleId":5,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
'{"aclGroupId":null,"agentId":null,"agentName":null,"encodedHtml":"PGgxPkZvbzwvaDE+","height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"default","maxTime":12800,"metaconsoleId":5,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||||
(string) EventsHistory::fromArray(
|
(string) EventsHistory::fromArray(
|
||||||
[
|
[
|
||||||
'id' => 7,
|
'id' => 7,
|
||||||
@ -142,10 +136,7 @@ class EventsHistoryTest extends TestCase
|
|||||||
'x' => -666,
|
'x' => -666,
|
||||||
'y' => 76,
|
'y' => 76,
|
||||||
'maxTime' => 12800,
|
'maxTime' => 12800,
|
||||||
'data' => [
|
'encodedHtml' => 'PGgxPkZvbzwvaDE+',
|
||||||
'time' => 23456789,
|
|
||||||
'data' => 15,
|
|
||||||
],
|
|
||||||
'id_metaconsole' => 5,
|
'id_metaconsole' => 5,
|
||||||
'linked_layout_node_id' => 3,
|
'linked_layout_node_id' => 3,
|
||||||
'linkedLayoutId' => 2,
|
'linkedLayoutId' => 2,
|
||||||
@ -154,7 +145,7 @@ class EventsHistoryTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'{"aclGroupId":null,"agentId":21,"agentName":null,"data":{"time":23456789,"data":15},"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":15,"linkedLayoutId":3,"linkedLayoutStatusType":"default","maxTime":12800,"metaconsoleId":2,"moduleId":385,"moduleName":"module_test","parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
'{"aclGroupId":null,"agentId":21,"agentName":null,"encodedHtml":"PGgxPkZvbzwvaDE+","height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":15,"linkedLayoutId":3,"linkedLayoutStatusType":"default","maxTime":12800,"metaconsoleId":2,"moduleId":385,"moduleName":"module_test","parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||||
(string) EventsHistory::fromArray(
|
(string) EventsHistory::fromArray(
|
||||||
[
|
[
|
||||||
'id' => 7,
|
'id' => 7,
|
||||||
@ -169,10 +160,7 @@ class EventsHistoryTest extends TestCase
|
|||||||
'x' => -666,
|
'x' => -666,
|
||||||
'y' => 76,
|
'y' => 76,
|
||||||
'maxTime' => 12800,
|
'maxTime' => 12800,
|
||||||
'data' => [
|
'encodedHtml' => 'PGgxPkZvbzwvaDE+',
|
||||||
'time' => 23456789,
|
|
||||||
'data' => 15,
|
|
||||||
],
|
|
||||||
'id_metaconsole' => 2,
|
'id_metaconsole' => 2,
|
||||||
'linked_layout_node_id' => 15,
|
'linked_layout_node_id' => 15,
|
||||||
'linkedLayoutId' => 3,
|
'linkedLayoutId' => 3,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user