Search code examples
fiware-wirecloud

How could include javascript libraries on a wirecloud operator


I am trying to develop a wirecloud operator but I don't know how to include a javascript library (i.e. jquery) on the config.xml except the main.js file. I tried to include the jquery library on the config.xml just like the main.js way, using different wire:index, but it did not work.

Is there any way to include a second JS library?


Solution

  • Yes, you can have more than one javascript file in operators. I think your problem is related to the RDF syntax that is a bit weird. Anyway, the following snippet is an example of how to include jquery and a main.js file using RDF/XML:

    <usdl:utilizedResource>
      <usdl:Resource rdf:about="js/jquery.min.js">
        <wire:index>0</wire:index>
      </usdl:Resource>
    </usdl:utilizedResource>
    <usdl:utilizedResource>
      <usdl:Resource rdf:about="js/main.js">
        <wire:index>1</wire:index>
      </usdl:Resource>
    </usdl:utilizedResource>
    

    Alternatively, if you are using the Mashup portal at FIWARE Lab, you can make use of the new XML format that is going to be available on WireCloud 0.7.0 (currently the Mashup portal is running release candidate of that version). This is an example of the new format:

    <?xml version='1.0' encoding='UTF-8'?>
    <operator xmlns="http://wirecloud.conwet.fi.upm.es/ns/macdescription/1" vendor="CoNWeT" name="ngsi-source" version="3.0">
        <details>
            <title>NGSI source</title>
            <homepage>https://github.com/wirecloud-fiware/ngsi-source</homepage>
            <authors>Álvaro Arranz García &lt;aarranz@conwet.com&gt;</authors>
            <email>aarranz@conwet.com</email>
            <image>images/catalogue.png</image>
            <description>Retrieve Orion Context Broker entities and their updates in real time.</description>
            <longdescription>DESCRIPTION.md</longdescription>
            <license>AGPLv3+ w/linking exception</license>
            <licenseurl>http://www.gnu.org/licenses/agpl-3.0.html</licenseurl>
            <doc>doc/userguide.md</doc>
            <changelog>doc/changelog.md</changelog>
        </details>
        <requirements>
            <feature name="NGSI"/>
        </requirements>
        <preferences>
            <preference name="ngsi_server" type="text" label="NGSI server URL" description="URL of the Orion Context Broker to use for retrieving entity information" default="http://orion.lab.fi-ware.org:10026/"/>
            <preference name="ngsi_proxy" type="text" label="NGSI proxy URL" description="URL of the Orion Context Broker proxy to use for receiving notifications about changes" default="http://mashup.lab.fi-ware.org:3000/"/>
            <preference name="ngsi_entities" type="text" label="NGSI entity types" description="A comma separated list of entity types to use for filtering entities from the Orion Context broker. Thies field cannot be empty." default="Node, AMMS, Regulator"/>
            <preference name="ngsi_id_filter" type="text" label="Id pattern" description="Id pattern for filtering entities. This preference can be empty, in that case, entities won't be filtered by id." default=""/>
            <preference name="ngsi_update_attributes" type="text" label="Monitored NGSI Attributes" description="Attributes to monitor for updates. Currently, the Orion Context Broker requires a list of attributes to monitor for changes, so this field cannot be empty." default="Latitud, Longitud, presence, batteryCharge, illuminance, ActivePower, ReactivePower, electricPotential, electricalCurrent"/>
        </preferences>
        <wiring>
            <outputendpoint name="entityOutput" type="text" label="Provide entity" description="Every change over each entity fires an event" friendcode="entity"/>
        </wiring>
        <scripts>
            <script src="js/other.dependency.js"/>
            <script src="js/main.js"/>
        </scripts>
    
    </operator>
    

    You can found more documentation about this new format at this link.