KEMBAR78
No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluence - Atlassian Summit 2010 | PDF
1
No coding necessary
Building user macros and dynamic reports inside Confluence



       Charles Hall
       Wiki Project Manager
       Astrium




                                                            2
Who we are




             Europe’s leading satellite manufacturer, number 3
                                worldwide.


                           www.astrium.eads.net




                                                                 3
Agenda

• What is a user macro?

• Worked example – colored tables

• Worked example – watermark for wiki pages

• Showcase




                                              4
User macros

• What is a user macro?
   • Added functionality
   • Removes complexity for authors
   • Facilitates re-use


• Restrictions
   • Used by users but…
   • …installed by system admins




                                      5
User macros

• Where can they be used?
  • Pages
  • Templates
  • In other user macros

   But not…
  • Custom HTML (administration screen)


• What do they consist of?
  •   HTML
  •   Javascript
  •   Velocity Template Language (VTL)
  •   References to Confluence objects

                                          6
Complexity vs Functionality
 High                                             Effort
                                                                  Capability




Functionality




                                     Complexity
                                                                               High
 Low
           Standard Wiki   {html}    User              Custom plugins
              markup                macros



                                                                                      7
An example

A performance testing tool – {response-time}




See your cheat sheet for details of this macro



                                                 8
Introducing jQuery

“I thought you said no coding?”

• A Javascript library for simplifying HTML document traversal, event handling, and adding
  AJAX support easily
• Already used by Confluence
• Minimizes Javascript coding




                                                                                             9
Worked example 1 – colored tables

No more boring tables!




                                    10
Worked example 1 – colored tables
      Listing 2

      ##   Macro name: color-table
      ##   Macro has a body: N
      ##   Body format: n/a
      ##   Output: HTML
      ##                                          Comment header
      ##   Developed by: Charles Hall
      ##   Developed for: All users
      ##   Date created: 23/02/2010
      ##   Installed by: Charles Hall

      ## Apply coloring to alternate rows of tables.

      <script type="text/javascript" defer="defer">
        jQuery(document).ready(function()
        {
          jQuery("tr:even").css("background-color", "#318db6");
          jQuery("tr:odd").css("background-color", "#f86a46");
        });
      </script>




                                                                   11
Worked example 1 – side effects

Test, test then test some more!




                                  12
Firebug to the rescue



                           Pinpoint the table(s) we
                             want to modify




           Point & Click




                                                      13
Worked example 1 – revised version
      Listing 2

      ##   Macro name: color-table
      ##   Macro has a body: N
      ##   Body format: n/a
      ##   Output: HTML
      ##
      ##   Developed by: Charles Hall
      ##   Developed for: All users
      ##   Date created: 23/02/2010
      ##   Installed by: Charles Hall

      ## Apply coloring to alternate rows of any tables with the class of
        confluenceTable.

      <script type="text/javascript" defer="defer">
        jQuery(document).ready(function()                            element.class
        {
           jQuery("table.confluenceTable tr:nth-child (odd)").css("background-color",
        "#f86a46");
           jQuery("table.confluenceTable tr:nth-child (even)").css("background-color",
        "#318db6");
        });
      </script>



                                                                                         14
Worked example 1 – Accepting parameters


                   {color-table:A2C1D5|BFEBEF}




                                                 15
Worked example 1 – Accepting parameters

       Listing 2

       ## Apply coloring to alternate rows of any tables with the
         class of confluenceTable.

       #set($oddcolor= $param0)
       #set($evencolor= $param1)

       ## Check for valid odd color, otherwise use default
       #if (!$oddcolor)
         #set ($oddcolor="ffffff")
       #end

       ## Check for valid even color, otherwise use default
       #if (!$evencolor)
         #set ($evencolor="ededed")
       #end




                                                                    16
Worked Example 2 - Using Confluence objects




                                             17
Worked example 2 – Referencing the image
{watermark:draft.gif|no-repeat|1000}
             Listing 3

             #set($image= $param0)
             #set($repeat = $param1)
             #set($minheight= $param2)

             <script type="text/javascript" defer="defer">
             jQuery(document).ready(function()
             {
             jQuery('#mainViewPane').css('background-image',
               'url($config.getBaseUrl()
               $content.getAttachmentNamed("$image").getDownloadPath())');
             …

                                                 2 strings joined together



                                                                             18
Worked example 2 – Setting the repeat behaviour


         Listing 3

         #set($repeat = $param1)
         …

         ## Add the specified repeat behaviour
         #if ($repeat)
           jQuery('#mainViewPane').css('background-repeat', '$repeat');
         #end

         …




                                                                          19
Worked example 2 – Specifying a minimum height



          Listing 3

          #set($minheight = $param2)
          …

          ## Check for a specified minimum height
          #if ($minheight)
            jQuery('#mainViewPane').css('height', '$minheight');
          #end

          …




                                                                   20
Worked example 2 – reusing

How about defining some standard watermarks to help users?
  • Draft
  • Company logo


Could we make the syntax easier too?

  • {draft-watermark}
  • {company-watermark}




                                                            21
Worked example 2 – reusing
      Listing 3

      …


      ## Check for full image path or attachment name
      #if($image.startsWith("http",0))
      #set($url=$image)
      #else
      #set($url=$config.getBaseUrl()+
       $content.getAttachmentNamed("$image").getDownloadPath())
      #end
      …




                                                                  22
Worked example 2 – reusing
      Listing 4

      ##   Macro name: draft-watermark
      ##   Macro has a body: N
      ##   Body format: n/a
      ##   Output: HTML
      ##
      ##   Developed by: Charles Hall
      ##   Developed for: Astrium wiki                             Calling the existing user macro
      ##   Date created: 19/04/2010
      ##   Installed by: Charles Hall


      ## N.B. Calls the watermark user macro
      ## draft.gif must reside in "company" space


      #set($url="http://globalcorp.com/confluence/download/attachments/74416134/draft.gif")


      $action.getHelper().renderConfluenceMacro("{watermark:$url|no-repeat|1000}")




                                                                                                     23
Showcase




           24
Gradient background




                      25
Page theme




             26
Client-side RSS feed reader




                              27
Tweaking another plug-in




                           28
Tweaking a standard feature
In summary

• Add real functionality
• Users can control behaviour
• Access to some Confluence objects
• Can perform useful UI tweaks
• Can be re-used in other macros

Useful resources
• See your cheat sheet




                                     30
Building Awesome
   Dashboards
     with Confluence



  Jim Severino, Atlassian
Confluence
        Free Plugins
+         Your Data
    =     Awesome
JDBC
Plugins For Reporting:
     1. SQL
     2. Chart
     3. Run
     4. Scripting
Plugin: SQL

{sql}             Wiki

        JDBC


        DB
Plugin: SQL

{sql}                 Table

            JDBC


           DB
Plugin: Chart
                    {chart}

{sql}           Table



        DB
Plugin: Chart
                    {chart}

{sql}           Table



        DB
https://confluence.foo.com
    /FOO/Sales+Report?
run_1_category=motorcycles
        &run_1=run
https://confluence.foo.com/FOO/Sales+Report




?run_1_category=motorcycles

        Other Parameters!
     &run_1_foo=...&run_1_bar=...
Plugin: Run
{run}                         {chart}

        {sql}             Table



                DB
Scripting
Text
       Image (c) United
        Feature Comics
Rule #1:
Macro Security
Recommendation:
       Use the
Macro Security Plugin.
Rule #2:
Datasource Security
Rule #3:
Summary Databases
Recommendation:
Run Reports off a
Summary Database
Plugins For Reporting:
     1. SQL
     2. Chart
     3. Run
     4. Scripting
http://bit.ly/
howto-report

No Coding Necessary: Building User Macros and Dynamic Reports Inside Confluence - Atlassian Summit 2010

  • 1.
  • 2.
    No coding necessary Buildinguser macros and dynamic reports inside Confluence Charles Hall Wiki Project Manager Astrium 2
  • 3.
    Who we are Europe’s leading satellite manufacturer, number 3 worldwide. www.astrium.eads.net 3
  • 4.
    Agenda • What isa user macro? • Worked example – colored tables • Worked example – watermark for wiki pages • Showcase 4
  • 5.
    User macros • Whatis a user macro? • Added functionality • Removes complexity for authors • Facilitates re-use • Restrictions • Used by users but… • …installed by system admins 5
  • 6.
    User macros • Wherecan they be used? • Pages • Templates • In other user macros But not… • Custom HTML (administration screen) • What do they consist of? • HTML • Javascript • Velocity Template Language (VTL) • References to Confluence objects 6
  • 7.
    Complexity vs Functionality High Effort Capability Functionality Complexity High Low Standard Wiki {html} User Custom plugins markup macros 7
  • 8.
    An example A performancetesting tool – {response-time} See your cheat sheet for details of this macro 8
  • 9.
    Introducing jQuery “I thoughtyou said no coding?” • A Javascript library for simplifying HTML document traversal, event handling, and adding AJAX support easily • Already used by Confluence • Minimizes Javascript coding 9
  • 10.
    Worked example 1– colored tables No more boring tables! 10
  • 11.
    Worked example 1– colored tables Listing 2 ## Macro name: color-table ## Macro has a body: N ## Body format: n/a ## Output: HTML ## Comment header ## Developed by: Charles Hall ## Developed for: All users ## Date created: 23/02/2010 ## Installed by: Charles Hall ## Apply coloring to alternate rows of tables. <script type="text/javascript" defer="defer"> jQuery(document).ready(function() { jQuery("tr:even").css("background-color", "#318db6"); jQuery("tr:odd").css("background-color", "#f86a46"); }); </script> 11
  • 12.
    Worked example 1– side effects Test, test then test some more! 12
  • 13.
    Firebug to therescue Pinpoint the table(s) we want to modify Point & Click 13
  • 14.
    Worked example 1– revised version Listing 2 ## Macro name: color-table ## Macro has a body: N ## Body format: n/a ## Output: HTML ## ## Developed by: Charles Hall ## Developed for: All users ## Date created: 23/02/2010 ## Installed by: Charles Hall ## Apply coloring to alternate rows of any tables with the class of confluenceTable. <script type="text/javascript" defer="defer"> jQuery(document).ready(function() element.class { jQuery("table.confluenceTable tr:nth-child (odd)").css("background-color", "#f86a46"); jQuery("table.confluenceTable tr:nth-child (even)").css("background-color", "#318db6"); }); </script> 14
  • 15.
    Worked example 1– Accepting parameters {color-table:A2C1D5|BFEBEF} 15
  • 16.
    Worked example 1– Accepting parameters Listing 2 ## Apply coloring to alternate rows of any tables with the class of confluenceTable. #set($oddcolor= $param0) #set($evencolor= $param1) ## Check for valid odd color, otherwise use default #if (!$oddcolor) #set ($oddcolor="ffffff") #end ## Check for valid even color, otherwise use default #if (!$evencolor) #set ($evencolor="ededed") #end 16
  • 17.
    Worked Example 2- Using Confluence objects 17
  • 18.
    Worked example 2– Referencing the image {watermark:draft.gif|no-repeat|1000} Listing 3 #set($image= $param0) #set($repeat = $param1) #set($minheight= $param2) <script type="text/javascript" defer="defer"> jQuery(document).ready(function() { jQuery('#mainViewPane').css('background-image', 'url($config.getBaseUrl() $content.getAttachmentNamed("$image").getDownloadPath())'); … 2 strings joined together 18
  • 19.
    Worked example 2– Setting the repeat behaviour Listing 3 #set($repeat = $param1) … ## Add the specified repeat behaviour #if ($repeat) jQuery('#mainViewPane').css('background-repeat', '$repeat'); #end … 19
  • 20.
    Worked example 2– Specifying a minimum height Listing 3 #set($minheight = $param2) … ## Check for a specified minimum height #if ($minheight) jQuery('#mainViewPane').css('height', '$minheight'); #end … 20
  • 21.
    Worked example 2– reusing How about defining some standard watermarks to help users? • Draft • Company logo Could we make the syntax easier too? • {draft-watermark} • {company-watermark} 21
  • 22.
    Worked example 2– reusing Listing 3 … ## Check for full image path or attachment name #if($image.startsWith("http",0)) #set($url=$image) #else #set($url=$config.getBaseUrl()+ $content.getAttachmentNamed("$image").getDownloadPath()) #end … 22
  • 23.
    Worked example 2– reusing Listing 4 ## Macro name: draft-watermark ## Macro has a body: N ## Body format: n/a ## Output: HTML ## ## Developed by: Charles Hall ## Developed for: Astrium wiki Calling the existing user macro ## Date created: 19/04/2010 ## Installed by: Charles Hall ## N.B. Calls the watermark user macro ## draft.gif must reside in "company" space #set($url="http://globalcorp.com/confluence/download/attachments/74416134/draft.gif") $action.getHelper().renderConfluenceMacro("{watermark:$url|no-repeat|1000}") 23
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
    In summary • Addreal functionality • Users can control behaviour • Access to some Confluence objects • Can perform useful UI tweaks • Can be re-used in other macros Useful resources • See your cheat sheet 30
  • 31.
    Building Awesome Dashboards with Confluence Jim Severino, Atlassian
  • 42.
    Confluence Free Plugins + Your Data = Awesome
  • 43.
  • 44.
    Plugins For Reporting: 1. SQL 2. Chart 3. Run 4. Scripting
  • 45.
    Plugin: SQL {sql} Wiki JDBC DB
  • 47.
    Plugin: SQL {sql} Table JDBC DB
  • 50.
    Plugin: Chart {chart} {sql} Table DB
  • 53.
    Plugin: Chart {chart} {sql} Table DB
  • 61.
    https://confluence.foo.com /FOO/Sales+Report? run_1_category=motorcycles &run_1=run
  • 62.
  • 67.
    Plugin: Run {run} {chart} {sql} Table DB
  • 68.
  • 70.
    Text Image (c) United Feature Comics
  • 71.
  • 72.
    Recommendation: Use the Macro Security Plugin.
  • 73.
  • 75.
  • 76.
  • 78.
    Plugins For Reporting: 1. SQL 2. Chart 3. Run 4. Scripting
  • 84.