From da01883902b4acfb16baf0f174f3309a44356f68 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 7 Jan 2020 18:07:07 +0100 Subject: [PATCH] Fixed items vc line --- .../javascript/pandora_visual_console.js | 4 - .../rest-api/models/VisualConsole/Item.php | 87 ++++++++++++++++++- .../models/VisualConsole/Items/Line.php | 33 +++++++ .../rest-api/models/VisualConsole/View.php | 14 ++- 4 files changed, 128 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/javascript/pandora_visual_console.js b/pandora_console/include/javascript/pandora_visual_console.js index 7073191383..1163a2ccb2 100755 --- a/pandora_console/include/javascript/pandora_visual_console.js +++ b/pandora_console/include/javascript/pandora_visual_console.js @@ -1408,10 +1408,6 @@ function createOrUpdateVisualConsoleItem( name: "itemId", value: item.itemProps.id ? item.itemProps.id : 0 } - /*{ - name: "elementsVc", - value: elementsVc - }*/ ], onshow: { page: "include/rest-api/index", diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index cf375082c0..daa26ede98 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Models\VisualConsole; +use Models\VisualConsole\Container as VC; use Models\CachedModel; /** @@ -2003,9 +2004,91 @@ class Item extends CachedModel ]; // Parent. - // TODO:XXX - $fields = get_parameter('elementsVc', []); + // Check groups can access user. + $aclUserGroups = []; + if (!\users_can_manage_group_all('AR')) { + $aclUserGroups = array_keys( + \users_get_groups(false, 'AR') + ); + } + + $vcItems = VC::getItemsFromDB( + $values['vCId'], + $aclUserGroups + ); + + $fields = []; $fields[0] = __('None'); + foreach ($vcItems as $key => $value) { + $data = $value->toArray(); + switch ($data['type']) { + case STATIC_GRAPH: + $text = __('Static graph'); + $text .= ' - '; + $text .= $data['imageSrc']; + break; + + case MODULE_GRAPH: + $text = __('Module graph'); + break; + + case CLOCK: + $text = __('Clock'); + break; + + case BARS_GRAPH: + $text = __('Bars graph'); + break; + + case AUTO_SLA_GRAPH: + $text = __('Auto SLA Graph'); + break; + + case PERCENTILE_BAR: + $text = __('Percentile bar'); + break; + + case CIRCULAR_PROGRESS_BAR: + $text = __('Circular progress bar'); + break; + + case CIRCULAR_INTERIOR_PROGRESS_BAR: + $text = __('Circular progress bar (interior)'); + break; + + case SIMPLE_VALUE: + $text = __('Simple Value'); + break; + + case LABEL: + $text = __('Label'); + break; + + case GROUP_ITEM: + $text = __('Group'); + break; + + case COLOR_CLOUD: + $text = __('Color cloud'); + break; + + case ICON: + $text = __('Icon'); + break; + + default: + $text = __('Item'); + break; + } + + if (isset($data['agentAlias']) === true + && empty($data['agentAlias']) === false + ) { + $text .= ' ('.$data['agentAlias'].')'; + } + + $fields[$data['id']] = $text; + } $inputs[] = [ 'label' => __('Parent'), diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/Line.php b/pandora_console/include/rest-api/models/VisualConsole/Items/Line.php index 0342a43aec..76841db53b 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/Line.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/Line.php @@ -431,4 +431,37 @@ final class Line extends Model } + /** + * Generates inputs for form (global, common). + * + * @param array $values Default values. + * + * @return array Of inputs. + */ + public static function getFormInputs(array $values): array + { + $inputs = []; + + switch ($values['tabSelected']) { + // Position. + case 'label': + // Label. + // TODO tinyMCE. + $inputs[] = [ + 'label' => __('Label'), + 'id' => 'div-label', + 'arguments' => [ + 'name' => 'label', + 'type' => 'text', + 'value' => $values['label'], + 'return' => true, + ], + ]; + break; + } + + return $inputs; + } + + } diff --git a/pandora_console/include/rest-api/models/VisualConsole/View.php b/pandora_console/include/rest-api/models/VisualConsole/View.php index 6ff2f456c3..84859cb786 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/View.php +++ b/pandora_console/include/rest-api/models/VisualConsole/View.php @@ -41,13 +41,17 @@ class View extends \HTML { + /** + * Tabs. + * + * @return string + */ public function loadTabs() { $type = (int) \get_parameter('type', 0); $itemId = (int) \get_parameter('itemId', 0); $vCId = (int) \get_parameter('vCId', 0); - // TODO:XXX; - // $elementsVc = io_safe_output(\get_parameter('elementsVc')); + $url = ui_get_full_url(false, false, false, false); $url .= 'ajax.php?page=include/rest-api/index'; $url .= '&loadtabs=2'; @@ -138,12 +142,14 @@ class View extends \HTML $itemClass = VisualConsole::getItemClass($type); - if (!isset($itemClass)) { + if (isset($itemClass) === false) { throw new \Exception(__('Item type not valid ['.$type.']')); } if (\method_exists($itemClass, 'getFormInputs') === false) { - throw new \Exception(__('Item type has no getFormInputs method ['.$type.']')); + throw new \Exception( + __('Item type has no getFormInputs method ['.$type.']') + ); } $form = [