Difference between revisions of "Compact Preview Plugin"

From FusionForge Wiki
Jump to: navigation, search
(Integration with gravatar plugin)
m (Integration with gravatar plugin)
Line 85: Line 85:
=== Integration with gravatar plugin ===
=== Integration with gravatar plugin ===
The gravatar plugin is now supported in the compact preview of users :
The [[Gravatar plugin]] is now supported in the compact preview of users :

Revision as of 06:52, 21 April 2011

OSLC Compact Previews

Specs of OSLC compact previews

A very interesting feature of OSLC is the compact previews which enables the display of resources in a compact way inside UIs.

This part of OSLC is specified here: http://open-services.net/bin/view/Main/OslcCoreUiPreview

Implementation in FusionForge

OSLC-CM_Plugin implements the compact preview OSLC feature. It consists in displaying inside a tooltip a summary of a resource when you hover with the mouse on that resource's link. Currently, compact previews for users and projects are implemented. Other resource types will be added like tracker tickets.

So, displaying a resource compact preview in a tooltip is as simple as "hovering" with the mouse on that resource link.

Here is an explanation of the way it works and how it is integrated with FusionForge.

Three main components needs to be available to create these compact previews:

  • The compact document describing the resource. This document should be identified with a URI.
  • An RDF document containing the compact document URI and describing some of the tooltip properties like width and heigth.
  • A client script that knows how to trigger the tooltip display and loads inside it the compact document describing the ressource.

How it works

Displaying a compact resource preview in a tooltip need the execution of the following steps:

  1. The client script requests the resource page with a specific "Accept" header using a "GET" HTTP request to that resource's page URL in the forge.
  2. Based on a content negociation mechanism, the server responds by delivering the RDF document of the compact ressource.
  3. The client script parses the returned RDF document and gets from it the URI of the compact document describing the resource.
  4. The client scripts loads the compact document inside the tooltip.

A concrete example

Here is a concrete example that helps understanding all that. We will display a user compact preview in a tooltip.

A Special resource link

There should be a user link that points to that user's page. Example, user is 'labbenes':

<a class="resourcePopupTrigger" href="https://fftrunk/users/labbenes/" rel="user,labbenes">labbenes</a>
  • 'class' property of this user link will be used by the client script to build toolTip.
  • 'href' property makes the link points to labbenes's page in FusionForge.
  • 'rel' property contains the params we pass to the client script. In this example, the first part of the param string indicates it is a ressource of type 'user'. The second part gives the resource id which is labbenes in our example.

Usually a user link in FusionForge doesn't contain all these properties. It just links to the user page. We build this kind of links meaning a hook of the OSLC plugin. the hook is named 'user_link_with_tooltip'. Whenever a plugin responds to that hook call and returns such a link, we display it instead of the classic link to user page. This hook call was added to util_display_user() function in 'common/include/utils.php'.

Ajax call by the client script

The client script will now requests the user page through an XMLHTTPRequest with a 'application/x-oslc-compact+xml' as an 'Accept' header.

In the users script of FusionForge (www/users) we have added a content negociation mechanism that makes the difference between requests based on the accept header. When 'Accept' header is 'application/x-oslc-compact+xml', FusionForge user script launches a plugin hook call (hook name is 'content_negociated_user_home') which is intented to return the URL of the RDF document of the compact preview of the user 'labbenes'. In this example the URL of the RDF document will be '/plugins/oslc/compact/user/labbenes'. This is the content of the RDF document of 'labbenes' compact preview:

When a plugin have responded to that hook call by returning an URL, FusionForge will redirects to that URL.

Loading the RDF document of the compact preview

The XMLHTTPRequest triggered by the client script will finally recieve the following RDF Document as XML data object.

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oslc="http://open-services.net/ns/core#">
  <oslc:Compact rdf:about="https://fftrunk/plugins/oslc/compact/user/labbenes">
    <dcterms:title>M. Sabri LABBENE</dcterms:title>
        <oslc:document rdf:ressource="https://fftrunk/plugins/oslc/compact/user/labbenes/type/small"/>

Loading the HTML document of the compact preview

The client script then parses this XML document and gets the 'rdf:resource' attribute's value of the <oslc:document> tag. This value is the url of the compact preview HTML document.

Finally, the script loads this URL inside the toolTip container and we get this final result:

User tooltip.png

With Firebug we can see the sequence of urls requested when we mouseover the user link as in the following figure:

Urls sequence.png
  • The first URL is the one of the user page in the forge which was requested with the 'application/x-oslc-compact+xml' Accept header.
  • The second one is the URL of the RDF document which represents the OSLC compact preview. FusionForge have redirected to that URL since a user page was requested with the special Accept header.
  • The third URL was requested when the client script loaded it inside the tooltip container.

Integration with gravatar plugin

The Gravatar plugin is now supported in the compact preview of users : Gravatar.png

Other resource types covered

This same feature was also made available for project links as the following figure shows:

Project tooltip.png

The same feature will be extended to cover tracker artifacts and will also show a compact preview of the artifact inside a popup.