Commits

Don Brown committed a65eca7

Converted it to work with Confluence 4

  • Participants
  • Parent commits 488f46f

Comments (0)

Files changed (5)

             <plugin>
                 <groupId>com.atlassian.maven.plugins</groupId>
                 <artifactId>maven-confluence-plugin</artifactId>
-                <version>3.3-m8</version>
+                <version>3.3</version>
                 <extensions>true</extensions>
                 <configuration>
                     <productVersion>${confluence.version}</productVersion>
                         <pluginArtifact>
                             <groupId>com.atlassian.labs</groupId>
                             <artifactId>speakeasy-plugin</artifactId>
-                            <version>0.5</version>
+                            <version>0.9.1</version>
                         </pluginArtifact>
                     </pluginArtifacts>
                 </configuration>
     </build>
 
     <properties>
-        <confluence.version>3.5-beta1</confluence.version>
+        <confluence.version>4.0-m19</confluence.version>
         <confluence.data.version>3.1</confluence.data.version>
     </properties>
 

File src/main/resources/atlassian-plugin.xml

         <dependency>com.atlassian.labs.speakeasy-plugin:shared</dependency>
     </scoped-modules>
 
+    <scoped-web-item key="link" name="Create CMUP" section="system.user/user-preferences" weight="30">
+        <label>Create CMUP</label>
+        <link linkId="cmup-create">/nopage.action</link>
+    </scoped-web-item>
+
 </atlassian-plugin>

File src/main/resources/modules/cmup/confluence.js

+/**
+ * Executes Confluence remote API methods
+ *
+ * @public
+ */
+var $ = require('speakeasy/jquery').jQuery;
+var ServiceProxy = require('speakeasy/xmlrpc').ServiceProxy;
+var service = new ServiceProxy(contextPath + "/rpc/xmlrpc", {
+                        protocol: "XML-RPC",
+                        methods: ['confluence1.getBlogEntries',
+                                  'confluence2.getBlogEntry',
+                                  'confluence1.getLabelsById']});
+
+
+function getBlogSummaries(spaceKey, callback) {
+    service.confluence1.getBlogEntries({
+        params : [null, spaceKey],
+        onSuccess : function(result) { callback(result); }
+    });
+}
+
+function getBlogEntry(id, callback) {
+    service.confluence2.getBlogEntry({
+        params : [null, id],
+        onSuccess : function(result) { callback(result); }
+    });
+}
+
+function getLabelsById(contentId, callback) {
+    service.confluence1.getLabelsById({
+        params : [null, contentId],
+        onSuccess : function(result) { callback(result); }
+    });
+}
+
+function getBlogsInPeriod(spaceKey, start, end, callback) {
+    getBlogSummaries(spaceKey, function(summaries) {
+        fetchForList(summaries, {
+            shouldRetrieve : function(summary) { return summary.publishDate > start && summary.publishDate < end; },
+            retrieve : function(summary, callback) {
+                getBlogEntry(summary.id, function(blog) {
+                    blog.publishDate = summary.publishDate;
+                    callback(blog);
+                });
+            },
+            success : function(blogs) {
+                blogs.sort(function (a, b) {
+                    return (a.publishDate < b.publishDate) ?  -1 : (a.publishDate > b.publishDate) ? 1 : 0
+                });
+                fetchForList(blogs, {
+                    shouldRetrieve : function(blog) { return true; },
+                    retrieve : function(blog, callback) {
+                        getLabelsById(blog.id, function(labels) {
+                            blog.labels = labels ? labels : [];
+                            callback(blog);
+                        });
+                    },
+                    success : function(blogs) {
+                        callback(blogs);
+                    }
+                });
+            }
+        });
+    });
+}
+
+function fetchForList(list, callbacks) {
+    var retrieved = [];
+    var numToRetrieve = 0;
+    var doneQueuing = false;
+
+    function checkFinished() {
+        if (doneQueuing && retrieved.length == numToRetrieve) {
+            callbacks.success(retrieved);
+        }
+        else {
+            //console.log("Waiting for " + (numToRetrieve - retrieved.length) + " more. " + doneQueuing + " " + numToRetrieve + " " + retrieved.length);
+        }
+    }
+
+    $.each(list, function(id, entry) {
+
+        if (callbacks.shouldRetrieve(entry)) {
+            numToRetrieve++;
+            callbacks.retrieve(entry, function(object) {
+                retrieved.push(object);
+                checkFinished();
+            });
+        }
+    });
+    doneQueuing = true;
+    checkFinished();
+}
+
+/**
+ * Gets a list of <a href="http://confluence.atlassian.com/display/CONFDEV/Remote+API+Specification#RemoteAPISpecification-BlogEntrySummary">BlogEntrySummaries</a>
+ * entries in the space. Parameters:
+ * <ul>
+ *     <li><code>spaceKey</code> - The space key</li>
+ *     <li><code>callback</code> - The function to call when the data is read</li>
+ * </ul>
+ */
+exports.getBlogSummaries = getBlogSummaries;
+/**
+ * Gets a <a href="http://confluence.atlassian.com/display/CONFDEV/Remote+API+Specification#RemoteAPISpecification-BlogEntry">BlogEntry</a>.
+ * Parameters:
+ * <ul>
+ *     <li><code>pageId</code> - The blog (page) id</li>
+ *     <li><code>callback</code> - The function to call when the data is read</li>
+ * </ul>
+ */
+exports.getBlogEntry = getBlogEntry;
+/**
+ * Gets a list of <a href="http://confluence.atlassian.com/display/CONFDEV/Remote+API+Specification#RemoteAPISpecification-BlogEntry">BlogEntry</a>
+ * entries in the space with labels. Parameters:
+ * <ul>
+ *     <li><code>spaceKey</code> - The space key</li>
+ *     <li><code>start</code> - The start date</li>
+ *     <li><code>end</code> - The end date</li>
+ *     <li><code>callback</code> - The function to call when the data is read</li>
+ * </ul>
+ */
+exports.getBlogsInPeriod = getBlogsInPeriod;
+/**
+ * Gets a list of <a href="http://confluence.atlassian.com/display/CONFDEV/Remote+API+Specification#RemoteAPISpecification-Label">Label</a>
+ * entries for the content id. Parameters:
+ * <ul>
+ *     <li><code>contentId</code> - The content id</li>
+ *     <li><code>callback</code> - The function to call when the data is read</li>
+ * </ul>
+ */
+exports.getLabelsById = getLabelsById;

File src/main/resources/modules/cmup/generator.js

 /**
- * @context dashboard
+ * @context atl.general
  */
-var conf = require('speakeasy/confluence');
+var conf = require('./confluence');
 var $ = require('speakeasy/jquery').jQuery;
 
 function createCommonModuleUpgradePack(start) {
             });
         var modules = $.map(blogs, function(val) {
             var props = extractProperties(["Project", "Version", "Difficulty", "Required", "Summary"], val.content);
-            props.Url = val.url;
+            props.id = val.id;
+            props.title = val.title;
+            props.url = val.url;
             return props.Project ? props : null;
         });
 
         });
         form.append($('<input/>').attr({
             type : 'hidden',
-            name : "content",
+            name : "wysiwygContent",
             value : template
         }));
         $('body').append(form);
     return str;
 }
 
-function showPackDialog() {
+function showPackDialog(e) {
+    e.preventDefault();
     var dialog = new AJS.Dialog({width:470, height:400, id:'cmup-dialog'});
     dialog.addHeader("Create Common Module Upgrade Pack");
     dialog.addPanel("Details", require('./input').render({}));
 
 function extractProperties(keys, content) {
     var props = {};
-    $.each(keys, function(index, val) {
-        var matches = content.match('\\|\\|\\s*' + val + '\\s*\\|\\s*([^|]*)\\s*\\|.*');
-        if (matches) {
-            props[val] = matches[1];
-        }
+    var page = $('<page>' + content + '</page>');
+    page.find('th').each(function(index) {
+      var key = $(this).text().trim();
+
+      if ($.inArray(key, keys) > -1) {
+        props[key] =  $(this).next().text().trim();
+      }
     });
     return props;
 }
 
 $(document).ready(function() {
-   var span = $('<span/>').appendTo($('.dashboard-action-button'));
-   $('<a>Create Common Module Upgrade Pack</a>').attr('href', "javascript:void(0)").appendTo(span).click(showPackDialog);
+   $('#cmup-create').click(showPackDialog);
 });

File src/main/resources/modules/cmup/report.mu

-h1. Required
+<h1>Required</h1>
 
-|| Release || Estimated migration difficulty || Summary ||
-{{#Required}}
-| [{{Project}} {{Version}}|{{Url}}] | {{Difficulty}} | {{Summary}} |
-{{/Required}}
-    
-h1. Optional
-            
-|| Release || Estimated migration difficulty || Summary ||
-{{#Optional}}
-| [{{Project}} {{Version}}|{{Url}}] | {{Difficulty}} | {{Summary}} |
-{{/Optional}}
+<table class="confluenceTable">
+    <tbody>
+        <tr>
+            <th class="confluenceTh"><p>Release</p></th>
+            <th class="confluenceTh"><p>Estimated migration difficulty</p></th>
+            <th class="confluenceTh"><p>Summary</p></th>
+        </tr>
+        {{#Required}}
+        <tr>
+            <td class="confluenceTd"><p>
+                <a data-linked-resource-default-alias="{{title}}" data-linked-resource-type="page" data-linked-resource-id="{{id}}" href="{{url}}">
+                    {{Project}} {{Version}}
+                </a>
+            </p></td>
+            <td class="confluenceTd"><p>{{Difficulty}}</p></td>
+            <td class="confluenceTd"><p>{{Summary}}</p></td>
+        </tr>
+        {{/Required}}
+    </tbody>
+</table>
+ 
+<h1>Optional</h1>
+
+<table class="confluenceTable">
+    <tbody>
+        <tr>
+            <th class="confluenceTh"><p>Release</p></th>
+            <th class="confluenceTh"><p>Estimated migration difficulty</p></th>
+            <th class="confluenceTh"><p>Summary</p></th>
+        </tr>
+        {{#Optional}}
+        <tr>
+            <td class="confluenceTd"><p>
+                <a data-linked-resource-default-alias="{{title}}" data-linked-resource-type="page" data-linked-resource-id="{{id}}" href="{{url}}">
+                    {{Project}} {{Version}}
+                </a>
+            </p></td>
+            <td class="confluenceTd"><p>{{Difficulty}}</p></td>
+            <td class="confluenceTd"><p>{{Summary}}</p></td>
+        </tr>
+        {{/Optional}}
+    </tbody>
+</table>
+        
+