diff --git a/inc/example.class.php b/inc/example.class.php index 1eef777..514f208 100644 --- a/inc/example.class.php +++ b/inc/example.class.php @@ -500,4 +500,116 @@ class PluginExampleExample extends CommonDBTM { return parent::generateLinkContents($link, $item); } + + static function dashboardTypes() { + return [ + 'example' => [ + 'label' => __("Plugin Example", 'example'), + 'function' => "PluginExampleExample::cardWidget", + 'image' => "https://via.placeholder.com/100x86?text=example", + ], + 'example_static' => [ + 'label' => __("Plugin Example (static)", 'example'), + 'function' => "PluginExampleExample::cardWidgetWithoutProvider", + 'image' => "https://via.placeholder.com/100x86?text=example+static", + ], + ]; + } + + + static function dashboardCards() { + return [ + 'plugin_example_card' => [ + 'widgettype' => ["example"], + 'label' => __("Plugin Example card"), + 'provider' => "PluginExampleExample::cardDataProvider", + ], + 'plugin_example_card_without_provider' => [ + 'widgettype' => ["example_static"], + 'label' => __("Plugin Example card without provider"), + ], + 'plugin_example_card_with_core_widget' => [ + 'widgettype' => ["bigNumber"], + 'label' => __("Plugin Example card with core provider"), + 'provider' => "PluginExampleExample::cardBigNumberProvider", + ], + ]; + } + + + static function cardWidget(array $params = []) { + $default = [ + 'data' => [], + 'title' => '', + // this property is "pretty" mandatory, + // as it contains the colors selected when adding widget on the grid send + // without it, your card will be transparent + 'color' => '', + ]; + $p = array_merge($default, $params); + + // you need to encapsulate your html in div.card to benefit core style + $html = "
"; + $html.= "

{$p['title']}

"; + $html.= ""; + $html.= "
"; + + return $html; + } + + static function cardDataProvider(array $params = []) { + $default_params = [ + 'label' => null, + 'icon' => "fas fa-smile-wink", + ]; + $params = array_merge($default_params, $params); + + return [ + 'title' => $params['label'], + 'icon' => $params['icon'], + 'data' => [ + 'test1', + 'test2', + 'test3', + ] + ]; + } + + static function cardWidgetWithoutProvider(array $params = []) { + $default = [ + // this property is "pretty" mandatory, + // as it contains the colors selected when adding widget on the grid send + // without it, your card will be transparent + 'color' => '', + ]; + $p = array_merge($default, $params); + + // you need to encapsulate your html in div.card to benefit core style + $html = "
+ static html (+optional javascript) as card is not matched with a data provider + + +
"; + + return $html; + } + + static function cardBigNumberProvider(array $params = []) { + $default_params = [ + 'label' => null, + 'icon' => null, + ]; + $params = array_merge($default_params, $params); + + return [ + 'number' => rand(), + 'url' => "https://www.linux.org/", + 'label' => "plugin example - some text", + 'icon' => "fab fa-linux", // font awesome icon + ]; + } } diff --git a/setup.php b/setup.php index 0e32dd6..fff1c24 100755 --- a/setup.php +++ b/setup.php @@ -219,6 +219,9 @@ function plugin_init_example() { $PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['example'] = "plugin_example_filter_actors"; + // add new cards to dashboard grid + $PLUGIN_HOOKS['dashboard_types']['example'] = ['PluginExampleExample', 'dashboardTypes']; + $PLUGIN_HOOKS['dashboard_cards']['example'] = ['PluginExampleExample', 'dashboardCards']; }