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

Former-commit-id: cae1d1fbf8efb664d5042877d63584c4699801ab
This commit is contained in:
Alejandro Gallardo Escobar 2019-04-04 17:07:15 +02:00
commit eb1e505a79
6 changed files with 43 additions and 18 deletions

View File

@ -158,8 +158,8 @@ class Item extends Model
// The item uses HTML output. // The item uses HTML output.
if (static::$useHtmlOutput === true) { if (static::$useHtmlOutput === true) {
if (static::notEmptyStringOr($data['encodedHtml'], null) === null if (static::notEmptyStringOr(static::issetInArray($data, ['encodedHtml']), null) === null
&& static::notEmptyStringOr($data['html'], null) === null && static::notEmptyStringOr(static::issetInArray($data, ['html']), null) === null
) { ) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'the html property is required and should be a not empty string' 'the html property is required and should be a not empty string'

View File

@ -44,7 +44,7 @@ final class ColorCloud extends Item
$decodedData['label'] = null; $decodedData['label'] = null;
$decodedData['defaultColor'] = static::extractDefaultColor($data); $decodedData['defaultColor'] = static::extractDefaultColor($data);
$decodedData['colorRanges'] = static::extractColorRanges($data); $decodedData['colorRanges'] = static::extractColorRanges($data);
$decodedData['color'] = static::notEmptyStringOr($data['color'], null); $decodedData['color'] = static::notEmptyStringOr(static::issetInArray($data, ['color']), null);
return $decodedData; return $decodedData;
} }

View File

@ -36,7 +36,7 @@ final class Label extends Item
protected function validateData(array $data): void protected function validateData(array $data): void
{ {
parent::validateData($data); parent::validateData($data);
if (static::notEmptyStringOr($data['label'], null) === null) { if (static::notEmptyStringOr(static::issetInArray($data, ['label']), null) === null) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'the label property is required and should be a not empty string' 'the label property is required and should be a not empty string'
); );

View File

@ -43,16 +43,22 @@ final class Percentile extends Item
$return['type'] = PERCENTILE_BAR; $return['type'] = PERCENTILE_BAR;
$return['percentileType'] = static::extractPercentileType($data); $return['percentileType'] = static::extractPercentileType($data);
$return['valueType'] = static::extractValueType($data); $return['valueType'] = static::extractValueType($data);
$return['minValue'] = static::parseFloatOr($data['minValue'], null); $return['minValue'] = static::parseFloatOr(
static::issetInArray($data, ['minValue']),
null
);
$return['maxValue'] = static::parseFloatOr( $return['maxValue'] = static::parseFloatOr(
static::issetInArray($data, ['maxValue', 'height']), static::issetInArray($data, ['maxValue', 'height']),
null null
); );
$return['color'] = static::extractColor($data); $return['color'] = static::extractColor($data);
$return['labelColor'] = static::extractLabelColor($data); $return['labelColor'] = static::extractLabelColor($data);
$return['value'] = static::parseFloatOr($data['value'], null); $return['value'] = static::parseFloatOr(
$return['displayValue'] = static::notEmptyStringOr( static::issetInArray($data, ['value']),
$data['displayValue'], null
);
$return['unit'] = static::notEmptyStringOr(
static::issetInArray($data, ['unit']),
null null
); );
return $return; return $return;

View File

@ -86,6 +86,7 @@ final class SimpleValue extends Item
*/ */
private static function extractProcessValue(array $data): string private static function extractProcessValue(array $data): string
{ {
if (isset($data['processValue'])) {
switch ($data['processValue']) { switch ($data['processValue']) {
case 'none': case 'none':
case 'avg': case 'avg':
@ -96,6 +97,21 @@ final class SimpleValue extends Item
default: default:
return 'none'; return 'none';
} }
} else {
switch ($data['type']) {
case SIMPLE_VALUE_MAX:
return 'max';
case SIMPLE_VALUE_MIN:
return 'min';
case SIMPLE_VALUE_AVG:
return 'avg';
default:
return 'none';
}
}
} }
@ -108,7 +124,10 @@ final class SimpleValue extends Item
*/ */
private static function extractPeriod(array $data): int private static function extractPeriod(array $data): int
{ {
$period = static::parseIntOr($data['period'], 0); $period = static::parseIntOr(
static::issetInArray($data, ['period']),
0
);
return ($period >= 0) ? $period : 0; return ($period >= 0) ? $period : 0;
} }

View File

@ -44,7 +44,7 @@ final class StaticGraph extends Item
$return['imageSrc'] = $this->extractImageSrc($data); $return['imageSrc'] = $this->extractImageSrc($data);
$return['showLastValueTooltip'] = $this->extractShowLastValueTooltip($data); $return['showLastValueTooltip'] = $this->extractShowLastValueTooltip($data);
$return['statusImageSrc'] = static::notEmptyStringOr( $return['statusImageSrc'] = static::notEmptyStringOr(
$data['statusImageSrc'], static::issetInArray($data, ['statusImageSrc']),
null null
); );