Menu

conditional fields in xml definition

schirrms
2019-10-17
2019-11-18
  • schirrms

    schirrms - 2019-10-17

    Hi,

    I plan to create an extension, and in that extension, I wish to add a presentation field if another extension is already present, but if possible, without having to deal with two versions of the module.

    How I'm able to do that to my knowledge :
    Version A doesn't add the presentation field at all
    Version B with a dependency to the other module and adding every time the presentation field.

    I don't see in the different delta="..." values a solution for this external dependencies.
    That would be a _delta="define if 'ClassA' exists"

    OTOH, I imagine (but never tested it) that if my new module has to extend another optional complementary module (implementting the class "ClassA"), I could write in the ModuleB definition :

    <class id="ClassA" _delta="if_exists">
    ....
       <field id="externalLinktoModuleB" _delta="define">
           ....
           </field>
     </class>
    

    What did I miss ?

    Thanks,

    Pascal

     

    Last edit: schirrms 2019-10-17
  • Pierre Goiffon

    Pierre Goiffon - 2019-10-23

    Hello,
    _delta="if_exists" on the right node (not the class but lower) would fit the need I think. Can you explain which presentation field you want to override ? We need to see if it's really applicable (host node need to have an id attribute)

     
  • schirrms

    schirrms - 2019-10-23

    Hi Pierre,

    OK, I'll write a more precise sample, let me think of the good way of doing this.

    Thanks,

    Pascal

     
  • schirrms

    schirrms - 2019-10-30

    Hi Pierre,

    I can't see an "easier sample" to explain my quest.

    Say I am creating a whole new device witch is rackable.
    but I'm also a fan of molkobain's datacenterview.
    So I wish to propose the 'vertical_u' option in my device presentation if the molkobain-datacenter extension is present.

    In pseudo-code, that could give something like that in the xml file :

    <class id="myOwnDevice" delta="define">
    ...
    <presentation>
       <details>
           <items>
              <item id="name>
                   <rank>10</rank>
               </item>
               <item id="vertical_u" _delta="define_if_molkobains_datacenter_is_here">
                    <rank>20</rank>
                </item>
              </items>
              </detail>
            </presentation>
            ......
        </class>
    

    by not having this option (I think !) I only see two solutions :
    1) two differents versions of the same package (ugly)
    2) One version of the package, + a delta package depending on my package and on molkobain's.

    Multiply that situation by 5 or 6 possibles extensions... That create an interesting plan of installation/update :)

    Thanks,

    Pascal

     
    • Pierre Goiffon

      Pierre Goiffon - 2019-11-08

      Many thanks for this comprehensive example.
      That was read by lots of people at Combodo, from product team and dev.
      We don't have an answer right now of course but this is a very interesting use case that we need to address.

       
      👍
      1
      • schirrms

        schirrms - 2019-11-08

        Hi Pierre,

        Thanks for pushing our ideas inside Combodo. I really like the fact that the Combodo team try to stay in touch with the users.

        Thanks,

        Pascal

         
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2019-11-08

        We've had the same thing; and did end up with an additional package which adds more specific changes upon a generic extension :)

         
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2019-10-30

    There's at least one other option, Pascal.

    3) One version but with a lot more PHP programming rather than XML. Actually playing with that myself to add a brand new attribute type to Person.

     
  • schirrms

    schirrms - 2019-10-31

    Hi Jeffrey,

    Sounds interresting !

    Can you somewhat explains a little bit more the way for doing that ?

    Thanks,

    Pascal

     
    • Jeffrey Bostoen

      Jeffrey Bostoen - 2019-10-31

      Not much yet, still experimenting myself with it to see if there are any other unwanted consequences.

       
  • Molkobain

    Molkobain - 2019-11-09

    Hello Pascal, I hope you are well!

    May I propose another approch? Using the auto-select feature of a module.

    If you look at the itop-full-itil module in iTop, you will see that it is selected/installed automatically when both itop-request-mgmt-itil and itop-incident-mgmt-itil are selected/installed.

    File datamodels/2.x/itop-full-itil/module.itop-full-itil.php:

    SetupWebPage::AddModule(
        __FILE__,
        'itop-full-itil/2.6.2',
        array(
            ...
            'auto_select' => 'SetupInfo::ModuleIsSelected("itop-request-mgmt-itil") && SetupInfo::ModuleIsSelected("itop-incident-mgmt-itil")',
            ...
        )
    );
    

    The condition HAS to be a PHP expression.

    The same could be done with your case maybe? You could make a separate module including only datamodel changes relative to the molkobain-datacenter-view and put a similar condition.

    In the end, you will have to different modules, but you won't have to worry about the presence of the datacenter view one, making it more flexible and robust.

    Note: For info on how to package several modules as one extension, take a look a this folder and post your questions here if necessary.

    Hope this helps! 😊
    Guillaume

     
    👍
    3

    Last edit: Molkobain 2019-11-10
    • Jeffrey Bostoen

      Jeffrey Bostoen - 2019-11-10

      Thanks for pointing this one out, it seems interesting! :)

       
    • schirrms

      schirrms - 2019-11-15

      Hi Guillaume,

      Glad to see you here again :)

      I'll try this solution this WE, hopefuly :) Still, an embedded 'define if exists classs' delta would be much simpler :)

      I'll let you know.

      Thanks,

      Pascal

       
      • schirrms

        schirrms - 2019-11-15

        Hi,

        unfortunatelly, this doesnn't seems to work (at least to my understanding).

        What i did :
        I created à new (empty at this time) extension named schirrms-generic-connection-to-Datacenter-view
        Here is the module file :

        SetupWebPage::AddModule(
            __FILE__, // Path to the current file, all other file names are relative to the directory containing this file
            'schirrms-generic-connection-to-Datacenter-view/0.1.0',
            array(
                // Identification
                //
                'label' => 'Extensions for integrating Schirrms-Generic-Connection to Molkobain-Datacenter-View',
                'category' => 'business',
        
                // Setup
                //
                'dependencies' => array(
                    //'schirrms-generic-connection/0.7.2',
                    //'molkobain-datacenter-view/1.5.1'
                ),
                'mandatory' => false,
                'visible' => true,
                'auto_select' => 'SetupInfo::ModuleIsSelected("schirrms-generic-connection") && SetupInfo::ModuleIsSelected("molkobain-datacenter-view")',
                // Components
                //
                ....
        

        With that and my existing extension, I built an 'extension bundle' (can we call it this way ?)

        Usinf itop-full-itil as an example, at first try, I add the two components as needed dependencies, and I tried an installtion on a system without molkobain-datacenter-view.

        I ran the setup, and got that :

        The following modules have unmet dependencies: Extensions for integrating Schirrms-Generic-Connection to Molkobain-Datacenter-View (id: schirrms-generic-connection-to-Datacenter-view/0.1.0) depends on schirrms-generic-connection/0.7.2 + molkobain-datacenter-view/1.5.1
        

        Then I commented the dependencies and the installtion went fine, but, in the iTop information for the support, I see that in the --Actual Modules installed ---

        InstalledModule/schirrms-generic-connection-to-Datacenter-view: 0.1.0
        InstalledModule/schirrms-generic-connection: 0.7.2
        

        So I believe this doesn't work

        Other informations about my installation :

        iTopVersion: 2.6.1
        iTopBuild: 4463
        iTopBuildDate: 2019-03-25 16:49:30
        DataModelVersion: 2.6.1
        MySQLVersion: 10.3.8-MariaDB
        PHPVersion: 7.1.24
        OSVersion: Linux
        WebServerVersion: Apache
        

        Thanks,

        Pascal

         
        • schirrms

          schirrms - 2019-11-15

          OK, trying to go a little urther, I put some little thing in the extension.

          First, the toolkit complaints because of a dependencies on my main extension (witch wad bad itself , as I tougth that the 'auto_select( funct will block the installtion because of one missing dependency)
          Then, after repositionneing the dependency, the toolkit complains loudly :

          Class GenericCommDevice
          Unknown attribute code 'position_v' from ZList 'details' (Expecting a value in {name, description, org_id,
          ...
          iosversion_id_friendlyname})
          

          Any ideas ?

          Not such a big deal, I'll just deliver the two extensions separately. But it's a little annoying :)

          Thanks,

          Pascal

           
  • Guillaume Lajarige

    Hello Pascal,

    Did you managed to deal with this?

     
    • schirrms

      schirrms - 2019-11-18

      Hi Guillaume,

      I gave up :)

      I made another extension to deal with the (two !) display fields that I wanted to add in my case, but didn't finf time to test it (Week-End was already full of iTop !)

      Not very nice, indeed... But should do the work. I have so many other points until 'my' iTop is complete. (That is maybe the biggest strength of iTop being so much customizable, but it's also a weakness : It can be a never ending story!)

      Pascal

       
      • Guillaume Lajarige

        I totally understand you when you are saying that iTop can be time consumming on your spare time... 😇

         
        👍
        1

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.