Menu

Adding more colours for highlighting

Nico
2023-07-28
2023-08-04
  • Nico

    Nico - 2023-07-28

    As descripbed here https://www.itophub.io/wiki/page?id=2_7_0:customization:highlight-critical-objects
    I want to add some more colours to highlight different objects in different colours.
    I did some tests but I cannot find out where the "HIGHLIGHT_CLASS_xxx" and colours are defined.
    Has anybody tried to add some more colours?
    Thanks, best regards,
    Nico

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2023-07-28

    Which iTop version are you currently using?

    Haven't tried it, but it seems quite doable.

     
    • Nico

      Nico - 2023-07-28

      We still use the LTR 2.7.7 since we have a lot of customizations and own extensions.

       
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2023-07-28

        The options are limited.

        https://github.com/Combodo/iTop/blob/a61734a6f858d360cd615063fd744645803df66b/datamodels/2.x/itop-portal-base/portal/templates/bricks/manage/layout-table.html.twig#L280 ( snippet from a newer version, but still. )

        You could consider overriding it with CSS perhaps.

         
        • Nico

          Nico - 2023-07-28

          That link belongs (I think only) to the portal view.
          For the backend/console view the "highlights" are set up differently.
          I think at least at ./application/cmdbabstract.class.inc.php and in addition in some CSS definition.

           
        • Nico

          Nico - 2023-07-28

          Hi,
          I've added some cide snippets and got some results but don't understand yet why only the even rows are coloured. On page reload I can see that all rows are coloured for a short time. The odd ones then fade to grey.
          ./css/light-grey.scss

          .nico {
                  background-color: #ff6000;
                  color: $text-color;
          }
          
          tr.nico_even td, .wizContainer tr.nico_even td {
                  background-color: #db8ed7;
                  color: $white;
          }
          tr.nico td, .wizContainer tr.nico td {
                  background-color: #db8eff;
                  color: $white;
          }
          

          ./application/cmdbabstract.class.inc.php
          26: define('HILIGHT_CLASS_NICO', 'nico');
          3333:

          HILIGHT_CLASS_NICO => HILIGHT_CLASS_NICO,
                          ),
          HILIGHT_CLASS_NICO => array(
                                  HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_NICO,
                                  HILIGHT_CLASS_WARNING => HILIGHT_CLASS_NICO,
                                  HILIGHT_CLASS_OK => HILIGHT_CLASS_NICO,
                                  HILIGHT_CLASS_NONE => HILIGHT_CLASS_NICO,
                  HILIGHT_CLASS_NICO => HILIGHT_CLASS_NICO,
          ),
          

          In addition I had to find out how to make these changes persistent using an extension. But as workaround it would be okay to do it like that.

           
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2023-07-28

    Hi Nico, I would simply add a custom CSS and avoid the highlight stuff altogether as newer iTop versions will always override the existing (edited) files.

     
    • Nico

      Nico - 2023-08-01

      Yes, that would be the perfect way.
      But I still did not find out where is the difference between the odd and even rows.

       
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2023-08-01

        It wouldn't matter anymore if you add a new CSS rule with ´!important´ in the style specification.

         
        • Nico

          Nico - 2023-08-02

          That is working, thanks :-)
          Do you have another hint how to add my Class into that
          protected static $m_highlightComparison = array
          in file cmdbabstract.class.inc.php using an extension?
          Thanks again,
          Nico

           
          • Jeffrey Bostoen

            Jeffrey Bostoen - 2023-08-02

            Mind that this is quite some old code. If you're going to edit iTop's own files, you'll need to do so each time you'll upgrade.

            Why not inject CSS in another way, avoiding this altogether? Or is it related to your logic/condition?

             
            • Nico

              Nico - 2023-08-02

              The CSS code is now injected by the datamodel.
              In a seperate extension I created a new theme where this is included now:

                        <import id="nico">branding/css/nm_hilight.scss</import>
              

              But I need do define the new hilight class to select it in the function GetHilightClass.
              That is needed to colour only results based on an OQL, e.g. tickets with a specific caller:

                public function GetHilightClass($oObject)
                {
                  // Possible return values are:
                  // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
                  if (is_a($oObject, "UserRequest"))
                  {
                    return HILIGHT_CLASS_NICO;
                  }
                  return HILIGHT_CLASS_NONE;
                }
              
               
            • Nico

              Nico - 2023-08-04

              Hi,
              I found a way to edit the file application/cmdbabstract.class.inc.php by running the setup.
              I am using the function AfterDatabaseCreation within ModuleInstallerAPI:

                      public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
                      {
                          // Added own Hilight Class to cmdbabstract.class.inc.php to color results
                          $sFile = APPROOT."application/cmdbabstract.class.inc.php";
                          $sBackupFile = APPROOT."application/cmdbabstract.class.inc.php.backup";
                          $sSearchString = '/protected static \$m_highlightComparison.*\);/msU';
                          $sReplaceString = " protected static \$m_highlightComparison = array(
                          HILIGHT_CLASS_CRITICAL => array(
                              HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_WARNING => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_OK => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_NONE => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_NMvip => HILIGHT_CLASS_CRITICAL,
                          ),
                          HILIGHT_CLASS_WARNING => array(
                              HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_WARNING => HILIGHT_CLASS_WARNING,
                              HILIGHT_CLASS_OK => HILIGHT_CLASS_WARNING,
                              HILIGHT_CLASS_NONE => HILIGHT_CLASS_WARNING,
                              HILIGHT_CLASS_NMvip => HILIGHT_CLASS_WARNING,
                          ),
                          HILIGHT_CLASS_OK => array(
                              HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_WARNING => HILIGHT_CLASS_WARNING,
                              HILIGHT_CLASS_OK => HILIGHT_CLASS_OK,
                              HILIGHT_CLASS_NONE => HILIGHT_CLASS_OK,
                              HILIGHT_CLASS_NMvip => HILIGHT_CLASS_NMvip,
                          ),
                          HILIGHT_CLASS_NONE => array(
                              HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_WARNING => HILIGHT_CLASS_WARNING,
                              HILIGHT_CLASS_OK => HILIGHT_CLASS_OK,
                              HILIGHT_CLASS_NONE => HILIGHT_CLASS_NONE,
                              HILIGHT_CLASS_NMvip => HILIGHT_CLASS_NMvip,
                          ),
                          HILIGHT_CLASS_NMvip => array(
                              HILIGHT_CLASS_CRITICAL => HILIGHT_CLASS_CRITICAL,
                              HILIGHT_CLASS_WARNING => HILIGHT_CLASS_WARNING,
                              HILIGHT_CLASS_OK => HILIGHT_CLASS_NMvip,
                              HILIGHT_CLASS_NONE => HILIGHT_CLASS_NMvip,
                              HILIGHT_CLASS_NMvip => HILIGHT_CLASS_NMvip,
                          ),
                      );
              ";
                          $content = file_get_contents($sFile);
                          copy($sFile, $sBackupFile);
                          file_put_contents($sFile, preg_replace($sSearchString, $sReplaceString, $content));
                      }
              

              The CSS code is injected by another extension.
              My GetHilightClass function now looks like this:

                public function GetHilightClass($oObject)
                {
                  // Possible return values are:
                  // HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
                  if (is_a($oObject, "Ticket"))
                  {
                    $iVIP_TeamID = MetaModel::GetConfig()->GetModuleSetting('my-customization', 'Color_VIP-Team-ID');
                    $iCallerID = $oObject->Get('caller_id');
                    $sOQL = "SELECT lnkPersonToTeam AS lnk
                    WHERE lnk.team_id = $iVIP_TeamID
                    AND lnk.person_id = $iCallerID";
                    $oSearch = DBObjectSearch::FromOQL($sOQL);
                    $oVIP = new CMDBObjectSet($oSearch);
                    if ($oVIP->count() >= 1)
                    {
                      return HILIGHT_CLASS_NMvip;
                    }
                  }
                  return HILIGHT_CLASS_NONE;
                }
              

              Now I can add Persons to that team and all tickets in every list having that person as caller are colored as defined in the CSS.
              I know I must be aware of the risk changing core files.
              Using newer versions always will be tested in lab environment.
              Thanks for the support.

               

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.