Menu

Homepage Custom PHP Code

Kevin
2024-01-12
2024-01-17
  • Kevin

    Kevin - 2024-01-12

    Hello to all,

    First, wishing everyone a happy and healthy new year !

    I added some integer information on contract object.
    I want to display them as a gauge on the home page but I don't find clue about adding custom PHP code on page.

    If it is possible, could you help me to do it?

    Kind regards,

     

    Last edit: Kevin 2024-01-12
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2024-01-12

    Can you show a screenshot of the page where you'd want to show it, exactly?

     
  • Kevin

    Kevin - 2024-01-12

    I would like to add it on the home page, on the tile I added (in the red box for example)

     
  • Kevin

    Kevin - 2024-01-12

    Or on the brick I added, replacing the two list columns for example

     
  • Guillaume Lajarige

    Hello Kevin,

    Is that a custom type of brick that you made? If so, you can overload the TileAction() of your controller to return any HTML you'll like.

    If that's a native manage brick, then you can take a look at the various "tile display mode" to see if it helps. Check this page, in the Bricks > ManagerBrick > display_modes > tile section.

    Otherwise, you can't really do it natively. The only way would be to go for the first option I described.

     
  • Kevin

    Kevin - 2024-01-12

    Thanks for your answer
    It is a native ManageBrick, so I will look for display mode.

    I see pie-chart but can I precise fields to use as data?

    Kind regards,

     
  • Guillaume Lajarige

    I don't think so, it only count on the grouping (tabs) of the manage bricks :/

    We could try to help you make your own custom brick which would derive from the native ManageBrick. Can you make a mock of what you are trying to do?

    I saw in the previous screenshot that you pointed 2 columns, you would like the sum (for all objects) of these 2 columns to be displayed in the tile in the home page?

     
  • Kevin

    Kevin - 2024-01-15

    Hello,

    Thanks for your help.
    I would like to create a gauge that display the usage of the units.
    So the "Unités d'oeuvre totales" is the maximum amount and "Unités d'oeuvre consommées" is the current value.

    If possible like on the attachment

    Kind regards,

     
  • Guillaume Lajarige

    Thanks for the details.

    In the screenshot of your second post (https://sourceforge.net/p/itop/discussion/customizing-itop/thread/f8fd7536e9/3899/attachment/contracts.png/thumb) there is a list of objects. So the gauge should be the sum of "UE consommées" / the sum of "UE totales" ?

     
  • Kevin

    Kevin - 2024-01-15

    No, I want a gauge for each contract found, one line by contract and one gauge with values as is for each.

     
  • Guillaume Lajarige

    You can't really put a custom display in these lists.

    But you could add a custom AttributePercentage to your class and update its value when the object is updated through the ComputeValues method.

    This won't require a custom portal brick, just to alter the datamodel to add your attribute to the class and to display it in the portal.

     
  • Kevin

    Kevin - 2024-01-15

    OK Thanks :) Can I display this percentage with a gauge?
    Or can I just add a custom page with my own PHP code?

     

    Last edit: Kevin 2024-01-15
  • Guillaume Lajarige

    Kinda, it will be an horizontal gauge, but you can't display it as an "arc" like in your screenshot.

     
  • Kevin

    Kevin - 2024-01-15

    Find for me :) Gauge was the "best" but bar will be okay ;)
    Thank you for your help :)

     
  • Guillaume Lajarige

    Great, hope you make it work :)

     
  • Kevin

    Kevin - 2024-01-15

    So, I try this solution with this :

    <field id="total_work_units" xsi:type="AttributeInteger" _delta="define">
      <sql>total_work_units</sql>
      <default_value>0</default_value>
      <is_null_allowed>false</is_null_allowed>
    </field>
    <field id="used_work_units" xsi:type="AttributeInteger" _delta="define">
      <sql>used_work_units</sql>
      <default_value>0</default_value>
      <is_null_allowed>false</is_null_allowed>
    </field>
    <field id="consumed_work_units" xsi:type="AttributePercentage" _delta="define">
      <sql>consumed_work_units</sql>
      <default_value>0</default_value>
      <is_null_allowed>false</is_null_allowed>
      <dependencies>
        <attribute id="used_work_units" />
      </dependencies>
    </field>
    

    and this :

    <methods>
        <method id="ComputeValues">
          <static>false</static>
          <access>public</access>
          <type>Overload-DBObject</type>
          <code>
            <![CDATA[   public function ComputeValues()
              {
                $nTotalUnits = parseInt($this->Get('total_work_units'));
                $nUsedUnits = parseInt($this->Get('used_work_units'));
                $nConsumedUnits = (($nUsedUnits * 100) / $nTotalUnits).toFixed(2);
    
                $this->Set('consumed_work_units', $nConsumedUnits);
    
                return parent::ComputeValues();
              }
            ]]>
          </code>
        </method>
    </methods>
    

    Problem is that the consumed_work_units does not update when I change the used_work_units...
    Did I do something wrong?

     

    Last edit: Kevin 2024-01-15
  • Kevin

    Kevin - 2024-01-16

    Good news, it works, I just forgot to add the define delta :)

     
  • Guillaume Lajarige

    Great! Glad to see you made it works :)
    Could you share a screenshot to inspire others?

     
  • Guillaume Lajarige

    Great, thanks for sharing the results!

    Take care,
    Guillaume

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.