Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new dashboard cards and filter #152

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bessantoy
Copy link
Contributor

Hello,

We would like the Credit plugin to integrate new cards for the dashboards :

  • Initial Credit: bigNumber - Represents the initial quantity of credit.
  • Used Credit: bigNumber - Represents the amount of credit used.
  • Remaining Credits: bigNumber - Represents the number of remaining credits.
  • Percentage of Remaining Credits: bigNumber - Represents the percentage of remaining credits.
  • Percentage of Used Credits: bigNumber - Represents the percentage of used credits.
  • Contract End Date: bigNumber - Represents the end date of the contract.
  • Credit Consumption by Ticket: bars - Represents the credit consumption per ticket.
  • Evolutions of Credit Consumption: lines, bars, areas - Represents the evolution of credit consumption over a period.

capture_widgetcredit1

In addition, we would like to add a new “credit type” filter to the dashboards which can take effect on the cards mentioned above.

We have already developed a plugin that allows you to add these new cards and this new filter but it would be great if this is directly integrated into the Credit plugin. Please let us know if this is possible.

Anthony from IT Gouvernance.

@stonebuzz
Copy link
Contributor

Hi @bessantoy can you fix CI ?

@bessantoy
Copy link
Contributor Author

Hi @bessantoy can you fix CI ?

Hi @stonebuzz i just fixed CI


return [
'number' => $nb_items,
'url' => '',
Copy link
Contributor

@Rom1-B Rom1-B Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A URL is required for the card to be clickable and open the corresponding search.

To be done on other cards too.

Copy link
Contributor

@stonebuzz stonebuzz Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A URL is required for the card to be clickable and open the corresponding search.

To be done on other cards too.

after further research, an empty URL means that the widget is not clickable

And this is legitimate in certain cases

image

this one is clickable

image

@stonebuzz
Copy link
Contributor

@bessantoy

I have a problem with the credit filter

image

If I choose a credit in particular, the widgets in the plugin are correctly reloaded, but the ‘native’ GLPI widgets drop to 0, as if the credit criterion had also been assigned to them.

image

Comment on lines +52 to +53
global $DB;
return $DB->fieldExists($table, self::FIELD);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is always applied on all table (because id field always exist in table)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just updated the FIELD constant to "plugin_credit_types_id" so that the filter only applies to new cards linked to credits
3dde920

use Session;
use Glpi\Dashboard\Provider;

class PluginCreditDashboardCards extends CommonDBTM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a list of credits (2 on the root entity and one on the Subentity entity)

image

In the root tree view,

image

I should see 32 Initial quantity of credit, but from dashbaord sub entity are not take into account

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when the recursion on the entity is active we must recursively take into account the credits on the sub-entities of the active entity.

I thought about using the function PluginCreditEntity::getAllForEntity(...) but it does not return the credits on the sub-entities.
image
Entité racine :
image

So I think that a function like :

     /**
     * Get all sub entities ID's of an entity
     * @param mixed $entityId
     * @return array
     */
    private static function getSubEntities($entityId): array
    {
        /** @var \DBmysql $DB */
        global $DB;

        $subEntities = [];

        $fetchSubEntities = function($parentId) use (&$fetchSubEntities, &$subEntities, $DB) {
            $query = "SELECT id FROM glpi_entities WHERE entities_id = $parentId";
            foreach ($DB->request($query) as $row) {
                $subEntities[] = $row['id'];
                $fetchSubEntities($row['id']);
            }
        };

        $fetchSubEntities($entityId);

        return $subEntities;
    }

in dashboardcards.class.php can be useful to retrieve the IDs of the sub-entities and use them in the query.

In addition, I imagine that we must on a sub-entity recursively take into account the credits of the parent entity if on these credits "Child entities" is set to "yes" ? And besides, this is the behavior of the function PluginCreditEntity::getAllForEntity(...)
SubEntity :
image

*
* @return array
*/
public static function getCreditsConsumption(array $params = []): array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this widget

image

we need to go further in data representation

on ticket 116 I have

2 credit used for "Assistance" and 3 for "Bug"

image

I should therefore have 2 columns for ticket 116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants