glpi icon indicating copy to clipboard operation
glpi copied to clipboard

New hook : enable choosing the icon of an item in impact analysis

Open ArthurMinfotel opened this issue 1 year ago • 8 comments

Add a new hook to enable changing the icon of an item in the impact anlysis.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets

ArthurMinfotel avatar May 17 '24 08:05 ArthurMinfotel

Why not just completing/altering $CFG_GLPI["default_impact_asset_types"] ? I'm not sure a hook is necessary here

It would be possible to change it in the plugin setup.php file by getting the request parameters, however I feel like having a dedicated hook make things clearer. Adding to that, I was thinking of modifying ajax/impact.php & impact.js so that the icons shown in the search result sidebar go through the same treatment, so that the search preview would match the actual icons which will be loaded.

ArthurMinfotel avatar May 17 '24 08:05 ArthurMinfotel

Why not just completing/altering $CFG_GLPI["default_impact_asset_types"] ? I'm not sure a hook is necessary here

Hello Alexandre. This hook permets to define icons for specific types (example : Firewall, Router, Wifi access point) and not only define icons for an global itemtype (as picture for models of objects)

tsmr avatar May 30 '24 08:05 tsmr

Why not just completing/altering $CFG_GLPI["default_impact_asset_types"] ? I'm not sure a hook is necessary here

Hello Alexandre. This hook permets to define icons for specific types (example : Firewall, Router, Wifi access point) and not only define icons for an global itemtype (as picture for models of objects)

Indeed, it may permit to define a specific icon for each different item. As it introduces extra queries (each displayed item is loaded, and impact graph may contains many items, it would be preferable to pass the itemtype and the items_id of the item to the hook instead of loading it. Indeed, it is probable that in most cases, the loading of the item by the plugin would be required only on specific cases (also, the plugin may use a caching system to improve the performances).

cedric-anne avatar May 30 '24 09:05 cedric-anne

I changed the target to main branch, as it introduces a new feature.

cedric-anne avatar May 30 '24 09:05 cedric-anne

Why not just completing/altering $CFG_GLPI["default_impact_asset_types"] ? I'm not sure a hook is necessary here

Hello Alexandre. This hook permets to define icons for specific types (example : Firewall, Router, Wifi access point) and not only define icons for an global itemtype (as picture for models of objects)

Indeed, it may permit to define a specific icon for each different item. As it introduces extra queries (each displayed item is loaded, and impact graph may contains many items, it would be preferable to pass the itemtype and the items_id of the item to the hook instead of loading it. Indeed, it is probable that in most cases, the loading of the item by the plugin would be required only on specific cases (also, the plugin may use a caching system to improve the performances).

Updated the code accordingly : the hook is moved with the ones expecting an array as parameters, and the array contains the keys 'itemtype' and 'items_id' (0 in case of the default icon for the sidebar).

ArthurMinfotel avatar May 30 '24 09:05 ArthurMinfotel

Nevermind, OK for me.

Can you add a test ?

What kind of test would you like to be added ? Check the type of the image value (string) and detailed content (valid filepath) ?

ArthurMinfotel avatar Jun 21 '24 14:06 ArthurMinfotel

Nevermind, OK for me. Can you add a test ?

What kind of test would you like to be added ? Check the type of the image value (string) and detailed content (valid filepath) ?

I take a look on the code and it seems that adding a test for this hook in the test suite is a bit complicated.

I will try to validate this new hook ASAP.

cedric-anne avatar Jun 24 '24 06:06 cedric-anne

Tested with https://github.com/pluginsGLPI/example/pull/55.

cedric-anne avatar Jul 01 '24 14:07 cedric-anne