mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
Implement dashboards hooks
This commit is contained in:
parent
3fa4e67698
commit
0b61ae3bdd
@ -500,4 +500,116 @@ class PluginExampleExample extends CommonDBTM {
|
|||||||
return parent::generateLinkContents($link, $item);
|
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 = "<div class='card' style='background-color: {$p["color"]};'>";
|
||||||
|
$html.= "<h2>{$p['title']}</h2>";
|
||||||
|
$html.= "<ul>";
|
||||||
|
foreach ($p['data'] as $line) {
|
||||||
|
$html.= "<li>$line</li>";
|
||||||
|
}
|
||||||
|
$html.= "</ul>";
|
||||||
|
$html.= "</div>";
|
||||||
|
|
||||||
|
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 = "<div class='card' style='background-color: {$p["color"]};'>
|
||||||
|
static html (+optional javascript) as card is not matched with a data provider
|
||||||
|
|
||||||
|
<img src='https://www.linux.org/images/logo.png'>
|
||||||
|
</div>";
|
||||||
|
|
||||||
|
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
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,6 +219,9 @@ function plugin_init_example() {
|
|||||||
|
|
||||||
$PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['example'] = "plugin_example_filter_actors";
|
$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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user